diff --git a/CHANGES.rst b/CHANGES.rst index 35940fa500..5ea03e3faa 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -11,7 +11,7 @@ Other changes: - Bugfix: - - + - Fix issue on vanished favorite and low priority room (#2413) Translations: - diff --git a/vector/src/main/java/im/vector/activity/SplashActivity.java b/vector/src/main/java/im/vector/activity/SplashActivity.java index 6c299fe96b..85e8d4ab95 100755 --- a/vector/src/main/java/im/vector/activity/SplashActivity.java +++ b/vector/src/main/java/im/vector/activity/SplashActivity.java @@ -18,7 +18,9 @@ package im.vector.activity; import android.content.Intent; +import android.os.Build; import android.os.Bundle; +import android.preference.PreferenceManager; import org.jetbrains.annotations.NotNull; import org.matrix.androidsdk.MXSession; @@ -39,6 +41,7 @@ import im.vector.gcm.GcmRegistrationManager; import im.vector.receiver.VectorUniversalLinkReceiver; import im.vector.services.EventStreamService; +import im.vector.util.PreferencesManager; import kotlin.Pair; /** @@ -50,11 +53,13 @@ public class SplashActivity extends MXCActionBarActivity { public static final String EXTRA_MATRIX_ID = "EXTRA_MATRIX_ID"; public static final String EXTRA_ROOM_ID = "EXTRA_ROOM_ID"; - private Map mListeners; - private Map mDoneListeners; + private Map mListeners = new HashMap<>(); + private Map mDoneListeners = new HashMap<>(); private final long mLaunchTime = System.currentTimeMillis(); + private static final String NEED_TO_CLEAR_CACHE_BEFORE_81200 = "NEED_TO_CLEAR_CACHE_BEFORE_81200"; + /** * @return true if a store is corrupted. */ @@ -133,8 +138,22 @@ public void initUiAndData() { return; } - mListeners = new HashMap<>(); - mDoneListeners = new HashMap<>(); + // Check if store is corrupted, due to change of type of some maps from HashMap to Map in Serialized objects + // Only on Android 7.1+ + // Only if previous versionCode of the installation is < 81200 + // Only once + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N_MR1 + && PreferenceManager.getDefaultSharedPreferences(this).getInt(PreferencesManager.VERSION_BUILD, 0) < 81200 + && PreferenceManager.getDefaultSharedPreferences(this).getBoolean(NEED_TO_CLEAR_CACHE_BEFORE_81200, true)) { + PreferenceManager.getDefaultSharedPreferences(this) + .edit() + .putBoolean(NEED_TO_CLEAR_CACHE_BEFORE_81200, false) + .apply(); + + // Force a clear cache + Matrix.getInstance(this).reloadSessions(this); + return; + } List matrixIds = new ArrayList<>(); diff --git a/vector/src/main/java/im/vector/activity/VectorHomeActivity.java b/vector/src/main/java/im/vector/activity/VectorHomeActivity.java index 76b1e91d62..643b94b5c9 100644 --- a/vector/src/main/java/im/vector/activity/VectorHomeActivity.java +++ b/vector/src/main/java/im/vector/activity/VectorHomeActivity.java @@ -321,16 +321,15 @@ public void initUiAndData() { // track if the application update SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this); - int version = preferences.getInt("VERSION_BUILD", 0); + int version = preferences.getInt(PreferencesManager.VERSION_BUILD, 0); if (version != VectorApp.VERSION_BUILD) { Log.d(LOG_TAG, "The application has been updated from version " + version + " to version " + VectorApp.VERSION_BUILD); // TODO add some dedicated actions here - preferences - .edit() - .putInt("VERSION_BUILD", VectorApp.VERSION_BUILD) + preferences.edit() + .putInt(PreferencesManager.VERSION_BUILD, VectorApp.VERSION_BUILD) .apply(); } diff --git a/vector/src/main/java/im/vector/util/PreferencesManager.java b/vector/src/main/java/im/vector/util/PreferencesManager.java index 009e670cb6..0bde4203ce 100755 --- a/vector/src/main/java/im/vector/util/PreferencesManager.java +++ b/vector/src/main/java/im/vector/util/PreferencesManager.java @@ -44,6 +44,8 @@ public class PreferencesManager { private static final String LOG_TAG = PreferencesManager.class.getSimpleName(); + public static final String VERSION_BUILD = "VERSION_BUILD"; + public static final String SETTINGS_MESSAGES_SENT_BY_BOT_PREFERENCE_KEY = "SETTINGS_MESSAGES_SENT_BY_BOT_PREFERENCE_KEY_2"; public static final String SETTINGS_CHANGE_PASSWORD_PREFERENCE_KEY = "SETTINGS_CHANGE_PASSWORD_PREFERENCE_KEY"; public static final String SETTINGS_VERSION_PREFERENCE_KEY = "SETTINGS_VERSION_PREFERENCE_KEY";