Skip to content

Commit

Permalink
Add flag to force FCM token refresh when locked
Browse files Browse the repository at this point in the history
  • Loading branch information
valldrac committed Oct 14, 2024
1 parent 6513f14 commit 00497b1
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -525,6 +525,12 @@ private void initializeFcmCheck() {
long nextSetTime = lastSetTime + TimeUnit.HOURS.toMillis(6);
long now = System.currentTimeMillis();

// MOLLY: Token may have been invalidated while the app was locked
if (TextSecurePreferences.shouldRefreshFcmToken(this)) {
TextSecurePreferences.setShouldRefreshFcmToken(this, false);
nextSetTime = now;
}

if (SignalStore.account().getFcmToken() == null || nextSetTime <= now || lastSetTime > now) {
AppDependencies.getJobManager().add(new FcmRefreshJob());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ public void onNewToken(@NonNull String token) {
Log.i(TAG, "onNewToken()");

if (KeyCachingService.isLocked()) {
TextSecurePreferences.setShouldRefreshFcmToken(AppDependencies.getApplication(), true);
return;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ private static SharedPreferences createSecurePreferences(Context context) {
case TextSecurePreferences.FIRST_INSTALL_VERSION:
case TextSecurePreferences.SYSTEM_EMOJI_PREF:
case TextSecurePreferences.DIRECTORY_FRESH_TIME_PREF:
case TextSecurePreferences.REFRESH_FCM_TOKEN_PREF:
case TextSecurePreferences.NAVBAR_SHOW_CALLS:
case KeyboardAwareLinearLayout.KEYBOARD_HEIGHT_LANDSCAPE:
case KeyboardAwareLinearLayout.KEYBOARD_HEIGHT_PORTRAIT:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ public class TextSecurePreferences {
private static final String PROMPTED_PUSH_REGISTRATION_PREF = "pref_prompted_push_registration";
private static final String PROMPTED_OPTIMIZE_DOZE_PREF = "pref_prompted_optimize_doze";
public static final String DIRECTORY_FRESH_TIME_PREF = "pref_directory_refresh_time";
public static final String REFRESH_FCM_TOKEN_PREF = "pref_refresh_fcm_token";
public static final String UPDATE_APK_ENABLED = "pref_update_apk_enabled";
public static final String UPDATE_APK_INCLUDE_BETA = "pref_update_apk_include_beta";
private static final String UPDATE_APK_REFRESH_TIME_PREF = "pref_update_apk_refresh_time";
Expand Down Expand Up @@ -713,6 +714,14 @@ public static void setDirectoryRefreshTime(Context context, long value) {
setLongPreference(context, DIRECTORY_FRESH_TIME_PREF, value);
}

public static boolean shouldRefreshFcmToken(Context context) {
return getBooleanPreference(context, REFRESH_FCM_TOKEN_PREF, false);
}

public static void setShouldRefreshFcmToken(Context context, boolean value) {
setBooleanPreference(context, REFRESH_FCM_TOKEN_PREF, value);
}

public static void removeDirectoryRefreshTime(Context context) {
removePreference(context, DIRECTORY_FRESH_TIME_PREF);
}
Expand Down

0 comments on commit 00497b1

Please sign in to comment.