mirror of
https://github.com/oxen-io/session-android.git
synced 2024-12-23 16:37:30 +00:00
Better support for local storage with passphrase disabled.
1) Never get into a state where messages aren't displayed unencrypted. 2) Fix bug where locked DB required launching twice.
This commit is contained in:
parent
81ee9e31c5
commit
8ea4db03db
@ -9,9 +9,6 @@ import org.thoughtcrime.securesms.recipients.RecipientFactory;
|
||||
import org.thoughtcrime.securesms.recipients.RecipientFormattingException;
|
||||
import org.thoughtcrime.securesms.recipients.Recipients;
|
||||
import org.thoughtcrime.securesms.service.ApplicationMigrationService;
|
||||
import org.thoughtcrime.securesms.service.DirectoryRefreshListener;
|
||||
import org.thoughtcrime.securesms.service.DirectoryRefreshService;
|
||||
import org.thoughtcrime.securesms.util.DirectoryHelper;
|
||||
import org.thoughtcrime.securesms.util.TextSecurePreferences;
|
||||
import org.whispersystems.textsecure.crypto.MasterSecret;
|
||||
|
||||
@ -24,18 +21,27 @@ public class RoutingActivity extends PassphraseRequiredSherlockActivity {
|
||||
private static final int STATE_UPGRADE_DATABASE = 5;
|
||||
private static final int STATE_PROMPT_PUSH_REGISTRATION = 6;
|
||||
|
||||
private MasterSecret masterSecret = null;
|
||||
private boolean isVisible = false;
|
||||
private MasterSecret masterSecret = null;
|
||||
private boolean isVisible = false;
|
||||
private boolean canceledResult = false;
|
||||
private boolean newIntent = false;
|
||||
|
||||
@Override
|
||||
public void onNewIntent(Intent intent) {
|
||||
super.onNewIntent(intent);
|
||||
setIntent(intent);
|
||||
this.newIntent = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onResume() {
|
||||
this.isVisible = true;
|
||||
if (this.canceledResult && !this.newIntent) {
|
||||
finish();
|
||||
}
|
||||
|
||||
this.newIntent = false;
|
||||
this.canceledResult = false;
|
||||
this.isVisible = true;
|
||||
super.onResume();
|
||||
}
|
||||
|
||||
@ -65,8 +71,9 @@ public class RoutingActivity extends PassphraseRequiredSherlockActivity {
|
||||
|
||||
@Override
|
||||
public void onActivityResult(int requestCode, int resultCode, Intent data) {
|
||||
if (resultCode == RESULT_CANCELED)
|
||||
finish();
|
||||
if (resultCode == RESULT_CANCELED) {
|
||||
canceledResult = true;
|
||||
}
|
||||
}
|
||||
|
||||
private void routeApplicationState() {
|
||||
|
@ -281,8 +281,8 @@ public class PushReceiver {
|
||||
}
|
||||
|
||||
private Pair<Long, Long> insertMessagePlaceholder(MasterSecret masterSecret,
|
||||
IncomingPushMessage message,
|
||||
boolean secure)
|
||||
IncomingPushMessage message,
|
||||
boolean secure)
|
||||
{
|
||||
IncomingTextMessage placeholder = new IncomingTextMessage(message, "", null);
|
||||
|
||||
|
@ -29,7 +29,10 @@ import android.os.Message;
|
||||
import android.util.Log;
|
||||
import android.widget.Toast;
|
||||
|
||||
import org.thoughtcrime.securesms.crypto.InvalidPassphraseException;
|
||||
import org.thoughtcrime.securesms.crypto.MasterSecretUtil;
|
||||
import org.thoughtcrime.securesms.database.CanonicalSessionMigrator;
|
||||
import org.thoughtcrime.securesms.util.TextSecurePreferences;
|
||||
import org.thoughtcrime.securesms.util.WorkerThread;
|
||||
import org.whispersystems.textsecure.crypto.MasterSecret;
|
||||
|
||||
@ -185,6 +188,7 @@ public class SendReceiveService extends Service {
|
||||
registerReceiver(clearKeyReceiver, clearKeyFilter, KeyCachingService.KEY_PERMISSION, null);
|
||||
|
||||
Intent bindIntent = new Intent(this, KeyCachingService.class);
|
||||
startService(bindIntent);
|
||||
bindService(bindIntent, serviceConnection, Context.BIND_AUTO_CREATE);
|
||||
}
|
||||
|
||||
@ -242,6 +246,12 @@ public class SendReceiveService extends Service {
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
MasterSecret masterSecret = SendReceiveService.this.masterSecret;
|
||||
|
||||
if (masterSecret == null && TextSecurePreferences.isPasswordDisabled(SendReceiveService.this)) {
|
||||
masterSecret = getPlaceholderSecret();
|
||||
}
|
||||
|
||||
switch (what) {
|
||||
case RECEIVE_SMS: smsReceiver.process(masterSecret, intent); return;
|
||||
case SEND_SMS: smsSender.process(masterSecret, intent); return;
|
||||
@ -254,6 +264,16 @@ public class SendReceiveService extends Service {
|
||||
case DOWNLOAD_AVATAR: avatarDownloader.process(masterSecret, intent); return;
|
||||
}
|
||||
}
|
||||
|
||||
private MasterSecret getPlaceholderSecret() {
|
||||
try {
|
||||
return MasterSecretUtil.getMasterSecret(SendReceiveService.this,
|
||||
MasterSecretUtil.UNENCRYPTED_PASSPHRASE);
|
||||
} catch (InvalidPassphraseException e) {
|
||||
Log.w("SendReceiveService", e);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public class ToastHandler extends Handler {
|
||||
|
Loading…
x
Reference in New Issue
Block a user