diff --git a/res/values/strings.xml b/res/values/strings.xml index 3b49c035c2..cb70da17b1 100644 --- a/res/values/strings.xml +++ b/res/values/strings.xml @@ -1647,5 +1647,8 @@ Edit device name Unlink device + + Device unlinked + This device has been successfully unlinked. diff --git a/src/org/thoughtcrime/securesms/ApplicationContext.java b/src/org/thoughtcrime/securesms/ApplicationContext.java index 716d66a865..b2d9aa9cd8 100644 --- a/src/org/thoughtcrime/securesms/ApplicationContext.java +++ b/src/org/thoughtcrime/securesms/ApplicationContext.java @@ -607,12 +607,12 @@ public class ApplicationContext extends MultiDexApplication implements Dependenc if (TextSecurePreferences.resetDatabase(this)) { boolean wasUnlinked = TextSecurePreferences.databaseResetFromUnpair(this); TextSecurePreferences.clearAll(this); + TextSecurePreferences.setDatabaseResetFromUnpair(this, wasUnlinked); // Loki - Re-set the preference so we can use it in the starting screen to determine whether device was unlinked or not MasterSecretUtil.clear(this); if (this.deleteDatabase("signal.db")) { Log.d("Loki", "Deleted database"); } - // Loki - Re-set the preference so we can use it in the starting screen to determine whether device was unlinked or not - TextSecurePreferences.setDatabaseResetFromUnpair(this, wasUnlinked); + } } diff --git a/src/org/thoughtcrime/securesms/jobs/PushDecryptJob.java b/src/org/thoughtcrime/securesms/jobs/PushDecryptJob.java index 419b7b7c97..9e2fad2f15 100644 --- a/src/org/thoughtcrime/securesms/jobs/PushDecryptJob.java +++ b/src/org/thoughtcrime/securesms/jobs/PushDecryptJob.java @@ -335,6 +335,7 @@ public class PushDecryptJob extends BaseJob implements InjectableType { // Make sure we got the request from our primary device String ourPrimaryDevice = TextSecurePreferences.getMasterHexEncodedPublicKey(context); if (ourPrimaryDevice != null && ourPrimaryDevice.equals(content.getSender())) { + TextSecurePreferences.setDatabaseResetFromUnpair(context, true); MultiDeviceUtilities.checkForRevocation(context); } } else { diff --git a/src/org/thoughtcrime/securesms/loki/MultiDeviceUtilities.kt b/src/org/thoughtcrime/securesms/loki/MultiDeviceUtilities.kt index 9b35ffe88b..e4f7550ad3 100644 --- a/src/org/thoughtcrime/securesms/loki/MultiDeviceUtilities.kt +++ b/src/org/thoughtcrime/securesms/loki/MultiDeviceUtilities.kt @@ -24,6 +24,7 @@ import org.whispersystems.signalservice.api.push.SignalServiceAddress import org.whispersystems.signalservice.loki.api.LokiStorageAPI import org.whispersystems.signalservice.loki.api.PairingAuthorisation import org.whispersystems.signalservice.loki.messaging.LokiThreadFriendRequestStatus +import org.whispersystems.signalservice.loki.utilities.Analytics import org.whispersystems.signalservice.loki.utilities.recover import org.whispersystems.signalservice.loki.utilities.retryIfNeeded import java.util.* @@ -40,6 +41,7 @@ fun checkForRevocation(context: Context) { DatabaseFactory.getLokiAPIDatabase(context).removePairingAuthorisations(ourDevice) LokiStorageAPI.shared.updateUserDeviceMappings() }.successUi { + Analytics.shared.track("Secondary Device Unlinked") TextSecurePreferences.setNeedsRevocationCheck(context, false) ApplicationContext.getInstance(context).clearData() }.fail { error -> diff --git a/src/org/thoughtcrime/securesms/registration/WelcomeActivity.java b/src/org/thoughtcrime/securesms/registration/WelcomeActivity.java index 5cd036f29c..83247f5371 100644 --- a/src/org/thoughtcrime/securesms/registration/WelcomeActivity.java +++ b/src/org/thoughtcrime/securesms/registration/WelcomeActivity.java @@ -1,6 +1,8 @@ package org.thoughtcrime.securesms.registration; import android.Manifest; +import android.app.AlertDialog; +import android.content.DialogInterface; import android.content.Intent; import android.os.Bundle; import android.support.annotation.NonNull; @@ -8,6 +10,7 @@ import android.support.annotation.NonNull; import org.thoughtcrime.securesms.BaseActionBarActivity; import org.thoughtcrime.securesms.permissions.Permissions; import org.thoughtcrime.securesms.util.CommunicationActions; +import org.thoughtcrime.securesms.util.TextSecurePreferences; import org.whispersystems.signalservice.loki.utilities.Analytics; import network.loki.messenger.R; @@ -23,6 +26,24 @@ public class WelcomeActivity extends BaseActionBarActivity { Analytics.Companion.getShared().track("Landing Screen Viewed"); } + @Override + protected void onResume() { + super.onResume(); + if (TextSecurePreferences.databaseResetFromUnpair(this)) { + AlertDialog.Builder builder = new AlertDialog.Builder(this); + builder.setTitle(R.string.dialog_device_unlink_title); + builder.setMessage(R.string.dialog_device_unlink_message); + builder.setPositiveButton(R.string.ok, null); + builder.setOnDismissListener(new DialogInterface.OnDismissListener() { + @Override + public void onDismiss(DialogInterface dialog) { + TextSecurePreferences.setDatabaseResetFromUnpair(getBaseContext(), false); + } + }); + builder.show(); + } + } + @Override public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) { Permissions.onRequestPermissionsResult(this, requestCode, permissions, grantResults);