mirror of
https://github.com/oxen-io/session-android.git
synced 2025-10-23 20:03:47 +00:00
Throttle background contact syncs to once every 6 hours.
Unfortunately, there's apps out there that trigger contact changes very frequently. Because we listen to the system for contact changes to tell us when to sync, that could result in us sending an abundance of contact syncs to linked desktop instances. This throttles contact sync requests using the following methodology: - By default, throttle contact syncs to 6 hrs while the app is backgrounded. - If a sync is throttled in the background, we set a dirty flag and will execute the sync the next time the app is foregrounded. - Syncs explicitly requested by desktop are never throttled.
This commit is contained in:
@@ -154,6 +154,9 @@ public class TextSecurePreferences {
|
||||
private static final String SERVICE_OUTAGE = "pref_service_outage";
|
||||
private static final String LAST_OUTAGE_CHECK_TIME = "pref_last_outage_check_time";
|
||||
|
||||
private static final String LAST_FULL_CONTACT_SYNC_TIME = "pref_last_full_contact_sync_time";
|
||||
private static final String NEEDS_FULL_CONTACT_SYNC = "pref_needs_full_contact_sync";
|
||||
|
||||
public static boolean isScreenLockEnabled(@NonNull Context context) {
|
||||
return getBooleanPreference(context, SCREEN_LOCK, false);
|
||||
}
|
||||
@@ -923,6 +926,22 @@ public class TextSecurePreferences {
|
||||
return getBooleanPreference(context, SERVICE_OUTAGE, false);
|
||||
}
|
||||
|
||||
public static long getLastFullContactSyncTime(Context context) {
|
||||
return getLongPreference(context, LAST_FULL_CONTACT_SYNC_TIME, 0);
|
||||
}
|
||||
|
||||
public static void setLastFullContactSyncTime(Context context, long timestamp) {
|
||||
setLongPreference(context, LAST_FULL_CONTACT_SYNC_TIME, timestamp);
|
||||
}
|
||||
|
||||
public static boolean needsFullContactSync(Context context) {
|
||||
return getBooleanPreference(context, NEEDS_FULL_CONTACT_SYNC, false);
|
||||
}
|
||||
|
||||
public static void setNeedsFullContactSync(Context context, boolean needsSync) {
|
||||
setBooleanPreference(context, NEEDS_FULL_CONTACT_SYNC, needsSync);
|
||||
}
|
||||
|
||||
public static void setBooleanPreference(Context context, String key, boolean value) {
|
||||
PreferenceManager.getDefaultSharedPreferences(context).edit().putBoolean(key, value).apply();
|
||||
}
|
||||
|
Reference in New Issue
Block a user