Commit 874fd637 authored by Valere's avatar Valere

Infinite restart loop after expired token error

Fixes #3249
parent 219b14fb
......@@ -316,39 +316,34 @@ public class CommonActivityUtils {
private static boolean isRecoveringFromInvalidatedToken = false;
public static void recoverInvalidatedToken() {
Log.e(LOG_TAG, "## recoverInvalidatedToken: Start Recover ");
if (isRecoveringFromInvalidatedToken) {
//ignore, we are doing it
Log.e(LOG_TAG, "## recoverInvalidatedToken: ignore, we are doing it");
return;
}
isRecoveringFromInvalidatedToken = true;
Context context = VectorApp.getCurrentActivity() != null ? VectorApp.getCurrentActivity() : VectorApp.getInstance();
try {
// Clear the credentials
Matrix.getInstance(context).getLoginStorage().clear() ;
VectorApp.getInstance().getNotificationDrawerManager().clearAllEvents();
EventStreamServiceX.Companion.onLogout(context);
// stopEventStream(context);
EventStreamServiceX.Companion.onApplicationStopped(context);
BadgeProxy.INSTANCE.updateBadgeCount(context, 0);
MXSession session = Matrix.getInstance(context).getDefaultSession();
// Publish to the server that we're now offline
MyPresenceManager.getInstance(context, session).advertiseOffline();
MyPresenceManager.remove(session);
// clear the preferences
PreferencesManager.clearPreferences(context);
// reset the FCM
Matrix.getInstance(context).getPushManager().resetFCMRegistration();
// clear the preferences
Matrix.getInstance(context).getPushManager().clearPreferences();
// Clear the credentials
Matrix.getInstance(context).getLoginStorage().clear();
// clear the tmp store list
Matrix.getInstance(context).clearTmpStoresList();
......@@ -358,20 +353,11 @@ public class CommonActivityUtils {
MXMediaCache.clearThumbnailsCache(context);
Matrix.getInstance(context).clearSessions(context, true, new SimpleApiCallback<Void>() {
@Override
public void onSuccess(Void info) {
}
});
session.clear(context);
} catch (Exception e) {
Log.e(LOG_TAG, "## recoverInvalidatedToken: Error while cleaning: ", e);
} finally {
// go to login page
CommonActivityUtils.restartApp(context, true);
isRecoveringFromInvalidatedToken = false;
CommonActivityUtils.restartApp(context, true);
}
}
......
......@@ -199,6 +199,6 @@ public class LoginStorage {
SharedPreferences prefs = mContext.getSharedPreferences(PREFS_LOGIN, Context.MODE_PRIVATE);
SharedPreferences.Editor editor = prefs.edit();
editor.remove(PREFS_KEY_CONNECTION_CONFIGS);
editor.apply();
editor.commit();
}
}
\ No newline at end of file
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment