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:
Greyson Parrelli
2018-07-06 17:28:58 -07:00
parent 7960a5785d
commit bf692e8da3
5 changed files with 89 additions and 6 deletions

View File

@@ -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();
}