mirror of
https://github.com/oxen-io/session-android.git
synced 2024-12-25 01:07:47 +00:00
Clear database on unpair.
This commit is contained in:
parent
f753dd1ea9
commit
733ab06e70
@ -70,6 +70,7 @@ import org.thoughtcrime.securesms.loki.LokiAPIDatabase;
|
||||
import org.thoughtcrime.securesms.loki.LokiPublicChatManager;
|
||||
import org.thoughtcrime.securesms.loki.LokiRSSFeedPoller;
|
||||
import org.thoughtcrime.securesms.loki.LokiUserDatabase;
|
||||
import org.thoughtcrime.securesms.loki.MultiDeviceUtilities;
|
||||
import org.thoughtcrime.securesms.notifications.MessageNotifier;
|
||||
import org.thoughtcrime.securesms.notifications.NotificationChannels;
|
||||
import org.thoughtcrime.securesms.providers.BlobProvider;
|
||||
@ -202,6 +203,9 @@ public class ApplicationContext extends MultiDexApplication implements Dependenc
|
||||
// Loki - Update device mappings
|
||||
if (setUpStorageAPIIfNeeded()) {
|
||||
LokiStorageAPI.Companion.getShared().updateUserDeviceMappings();
|
||||
if (TextSecurePreferences.needsRevocationCheck(this)) {
|
||||
checkNeedsRevocation();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -595,13 +599,20 @@ public class ApplicationContext extends MultiDexApplication implements Dependenc
|
||||
}
|
||||
// endregion
|
||||
|
||||
public void checkNeedsRevocation() {
|
||||
MultiDeviceUtilities.checkForRevocation(this);
|
||||
}
|
||||
|
||||
public void checkNeedsDatabaseReset() {
|
||||
if (TextSecurePreferences.resetDatabase(this)) {
|
||||
PreferenceManager.getDefaultSharedPreferences(this).edit().clear().commit();
|
||||
boolean wasUnlinked = TextSecurePreferences.databaseResetFromUnpair(this);
|
||||
TextSecurePreferences.clearAll(this);
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -331,7 +331,7 @@ public class PushDecryptJob extends BaseJob implements InjectableType {
|
||||
SignalServiceDataMessage message = content.getDataMessage().get();
|
||||
boolean isMediaMessage = message.getAttachments().isPresent() || message.getQuote().isPresent() || message.getSharedContacts().isPresent() || message.getPreviews().isPresent() || message.getSticker().isPresent();
|
||||
|
||||
if (message.isUnpairingRequest()) {
|
||||
if (!envelope.isFriendRequest() && message.isUnpairingRequest()) {
|
||||
// Make sure we got the request from our primary device
|
||||
String ourPrimaryDevice = TextSecurePreferences.getMasterHexEncodedPublicKey(context);
|
||||
if (ourPrimaryDevice != null && ourPrimaryDevice.equals(content.getSender())) {
|
||||
|
@ -8,6 +8,7 @@ import nl.komponents.kovenant.functional.bind
|
||||
import nl.komponents.kovenant.functional.map
|
||||
import nl.komponents.kovenant.then
|
||||
import nl.komponents.kovenant.toFailVoid
|
||||
import nl.komponents.kovenant.ui.successUi
|
||||
import org.thoughtcrime.securesms.ApplicationContext
|
||||
import org.thoughtcrime.securesms.crypto.IdentityKeyUtil
|
||||
import org.thoughtcrime.securesms.database.Address
|
||||
@ -35,13 +36,15 @@ fun checkForRevocation(context: Context) {
|
||||
LokiStorageAPI.shared.fetchDeviceMappings(primaryDevice).bind { mappings ->
|
||||
val ourMapping = mappings.find { it.secondaryDevicePublicKey == ourDevice }
|
||||
if (ourMapping != null) throw Error("Device has not been revoked")
|
||||
// remove pairing auths for our device
|
||||
// remove pairing authorisations for our device
|
||||
DatabaseFactory.getLokiAPIDatabase(context).removePairingAuthorisations(ourDevice)
|
||||
LokiStorageAPI.shared.updateUserDeviceMappings()
|
||||
}.success {
|
||||
// TODO: Revoke here
|
||||
}.successUi {
|
||||
TextSecurePreferences.setNeedsRevocationCheck(context, false)
|
||||
ApplicationContext.getInstance(context).clearData()
|
||||
}.fail { error ->
|
||||
Log.d("Loki", "Revocation check failed: $error")
|
||||
TextSecurePreferences.setNeedsRevocationCheck(context, true)
|
||||
Log.d("Loki", "Revocation check failed: ${error.message ?: error}")
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1187,11 +1187,33 @@ public class TextSecurePreferences {
|
||||
}
|
||||
|
||||
public static void setResetDatabase(Context context, boolean resetDatabase) {
|
||||
// We do it this way so that it gets persisted in storage straight away
|
||||
PreferenceManager.getDefaultSharedPreferences(context).edit().putBoolean("database_reset", resetDatabase).commit();
|
||||
}
|
||||
|
||||
public static boolean resetDatabase(Context context) {
|
||||
return getBooleanPreference(context, "database_reset", false);
|
||||
}
|
||||
|
||||
public static void setDatabaseResetFromUnpair(Context context, boolean value) {
|
||||
// We do it this way so that it gets persisted in storage straight away
|
||||
PreferenceManager.getDefaultSharedPreferences(context).edit().putBoolean("database_reset_unpair", value).commit();
|
||||
}
|
||||
|
||||
public static boolean databaseResetFromUnpair(Context context) {
|
||||
return getBooleanPreference(context, "database_reset_unpair", false);
|
||||
}
|
||||
|
||||
public static void setNeedsRevocationCheck(Context context, boolean needsCheck) {
|
||||
setBooleanPreference(context, "needs_revocation", needsCheck);
|
||||
}
|
||||
|
||||
public static boolean needsRevocationCheck(Context context) {
|
||||
return getBooleanPreference(context, "needs_revocation", false);
|
||||
}
|
||||
// endregion
|
||||
|
||||
public static void clearAll(Context context) {
|
||||
PreferenceManager.getDefaultSharedPreferences(context).edit().clear().commit();
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user