diff --git a/app/src/main/java/org/thoughtcrime/securesms/crypto/IdentityKeyUtil.java b/app/src/main/java/org/thoughtcrime/securesms/crypto/IdentityKeyUtil.java index 2ca215c894..a5333ef5d4 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/crypto/IdentityKeyUtil.java +++ b/app/src/main/java/org/thoughtcrime/securesms/crypto/IdentityKeyUtil.java @@ -55,31 +55,32 @@ public class IdentityKeyUtil { public static final String LOKI_SEED = "loki_seed"; public static final String HAS_MIGRATED_KEY = "has_migrated_keys"; - public static boolean hasIdentityKey(Context context) { - SharedPreferences preferences = context.getSharedPreferences(MASTER_SECRET_UTIL_PREFERENCES_NAME, 0); + private static SharedPreferences getSharedPreferences(Context context) { + return context.getSharedPreferences(MASTER_SECRET_UTIL_PREFERENCES_NAME, 0); + } - boolean hasIdentityKey = (preferences.contains(IDENTITY_PUBLIC_KEY_PREF) && + public static boolean hasIdentityKey(Context context) { + SharedPreferences preferences = getSharedPreferences(context); + + return (preferences.contains(IDENTITY_PUBLIC_KEY_PREF) && preferences.contains(IDENTITY_PRIVATE_KEY_PREF)) || (preferences.contains(IDENTITY_PUBLIC_KEY_PREF+ENCRYPTED_SUFFIX) && preferences.contains(IDENTITY_PRIVATE_KEY_PREF+ENCRYPTED_SUFFIX)); - - // check if any keys are not migrated - if (hasIdentityKey && !preferences.getBoolean(HAS_MIGRATED_KEY, false)) { - // this will retrieve and force upgrade if possible - checkUpdate(context); - preferences.edit().putBoolean(HAS_MIGRATED_KEY, true).apply(); - } - - return hasIdentityKey; } - private static void checkUpdate(Context context) { - // retrieve will force upgrade if available - retrieve(context,IDENTITY_PUBLIC_KEY_PREF); - retrieve(context,IDENTITY_PRIVATE_KEY_PREF); - retrieve(context,ED25519_PUBLIC_KEY); - retrieve(context,ED25519_SECRET_KEY); - retrieve(context,LOKI_SEED); + public static void checkUpdate(Context context) { + SharedPreferences preferences = getSharedPreferences(context); + // check if any keys are not migrated + if (hasIdentityKey(context) && !preferences.getBoolean(HAS_MIGRATED_KEY, false)) { + // this will retrieve and force upgrade if possible + // retrieve will force upgrade if available + retrieve(context,IDENTITY_PUBLIC_KEY_PREF); + retrieve(context,IDENTITY_PRIVATE_KEY_PREF); + retrieve(context,ED25519_PUBLIC_KEY); + retrieve(context,ED25519_SECRET_KEY); + retrieve(context,LOKI_SEED); + preferences.edit().putBoolean(HAS_MIGRATED_KEY, true).apply(); + } } public static @NonNull IdentityKey getIdentityKey(@NonNull Context context) { diff --git a/app/src/main/java/org/thoughtcrime/securesms/loki/activities/HomeActivity.kt b/app/src/main/java/org/thoughtcrime/securesms/loki/activities/HomeActivity.kt index 54cf2f8d7c..f65b00538d 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/loki/activities/HomeActivity.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/loki/activities/HomeActivity.kt @@ -29,15 +29,14 @@ import org.greenrobot.eventbus.EventBus import org.greenrobot.eventbus.Subscribe import org.greenrobot.eventbus.ThreadMode import org.session.libsession.messaging.jobs.JobQueue -import org.session.libsession.messaging.mentions.MentionsManager import org.session.libsession.messaging.sending_receiving.MessageSender -import org.session.libsession.messaging.sending_receiving.pollers.OpenGroupPollerV2 import org.session.libsession.utilities.* -import org.session.libsignal.utilities.toHexString import org.session.libsignal.utilities.ThreadUtils +import org.session.libsignal.utilities.toHexString import org.thoughtcrime.securesms.ApplicationContext import org.thoughtcrime.securesms.PassphraseRequiredActionBarActivity import org.thoughtcrime.securesms.conversation.ConversationActivity +import org.thoughtcrime.securesms.crypto.IdentityKeyUtil import org.thoughtcrime.securesms.database.DatabaseFactory import org.thoughtcrime.securesms.database.model.ThreadRecord import org.thoughtcrime.securesms.loki.api.OpenGroupManager @@ -155,8 +154,8 @@ class HomeActivity : PassphraseRequiredActionBarActivity(), ConversationClickLis override fun onResume() { super.onResume() - if (TextSecurePreferences.getLocalNumber(this) == null) { - return; } // This can be the case after a secondary device is auto-cleared + if (TextSecurePreferences.getLocalNumber(this) == null) { return; } // This can be the case after a secondary device is auto-cleared + IdentityKeyUtil.checkUpdate(this) profileButton.recycle() // clear cached image before update tje profilePictureView profileButton.update() val hasViewedSeed = TextSecurePreferences.getHasViewedSeed(this)