mirror of
https://github.com/oxen-io/session-android.git
synced 2025-02-19 19:18:27 +00:00
Lets limit GCM refresh to every 6hrs, and only retry once
// FREEBIE
This commit is contained in:
parent
deb96646a3
commit
0d11b3dd26
@ -48,6 +48,8 @@ import org.whispersystems.jobqueue.requirements.NetworkRequirementProvider;
|
||||
import org.whispersystems.libsignal.logging.SignalProtocolLoggerProvider;
|
||||
import org.whispersystems.libsignal.util.AndroidSignalProtocolLogger;
|
||||
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import dagger.ObjectGraph;
|
||||
|
||||
/**
|
||||
@ -138,7 +140,11 @@ public class ApplicationContext extends MultiDexApplication implements Dependenc
|
||||
|
||||
private void initializeGcmCheck() {
|
||||
if (TextSecurePreferences.isPushRegistered(this)) {
|
||||
this.jobManager.add(new GcmRefreshJob(this));
|
||||
long nextSetTime = TextSecurePreferences.getGcmRegistrationIdLastSetTime(this) + TimeUnit.HOURS.toMillis(6);
|
||||
|
||||
if (TextSecurePreferences.getGcmRegistrationId(this) == null || nextSetTime <= System.currentTimeMillis()) {
|
||||
this.jobManager.add(new GcmRefreshJob(this));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -49,7 +49,10 @@ public class GcmRefreshJob extends ContextJob implements InjectableType {
|
||||
@Inject transient SignalServiceAccountManager textSecureAccountManager;
|
||||
|
||||
public GcmRefreshJob(Context context) {
|
||||
super(context, JobParameters.newBuilder().withRequirement(new NetworkRequirement(context)).create());
|
||||
super(context, JobParameters.newBuilder()
|
||||
.withRequirement(new NetworkRequirement(context))
|
||||
.withRetryCount(1)
|
||||
.create());
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -69,6 +72,7 @@ public class GcmRefreshJob extends ContextJob implements InjectableType {
|
||||
textSecureAccountManager.setGcmId(Optional.of(gcmId));
|
||||
|
||||
TextSecurePreferences.setGcmRegistrationId(context, gcmId);
|
||||
TextSecurePreferences.setGcmRegistrationIdLastSetTime(context, System.currentTimeMillis());
|
||||
TextSecurePreferences.setWebsocketRegistered(context, true);
|
||||
}
|
||||
}
|
||||
|
@ -87,6 +87,7 @@ public class TextSecurePreferences {
|
||||
private static final String GCM_DISABLED_PREF = "pref_gcm_disabled";
|
||||
private static final String GCM_REGISTRATION_ID_PREF = "pref_gcm_registration_id";
|
||||
private static final String GCM_REGISTRATION_ID_VERSION_PREF = "pref_gcm_registration_id_version";
|
||||
private static final String GCM_REGISTRATION_ID_TIME_PREF = "pref_gcm_registration_id_last_set_time";
|
||||
private static final String WEBSOCKET_REGISTERED_PREF = "pref_websocket_registered";
|
||||
private static final String RATING_LATER_PREF = "pref_rating_later";
|
||||
private static final String RATING_ENABLED_PREF = "pref_rating_enabled";
|
||||
@ -231,6 +232,14 @@ public class TextSecurePreferences {
|
||||
}
|
||||
}
|
||||
|
||||
public static long getGcmRegistrationIdLastSetTime(Context context) {
|
||||
return getLongPreference(context, GCM_REGISTRATION_ID_TIME_PREF, 0);
|
||||
}
|
||||
|
||||
public static void setGcmRegistrationIdLastSetTime(Context context, long timestamp) {
|
||||
setLongPreference(context, GCM_REGISTRATION_ID_TIME_PREF, timestamp);
|
||||
}
|
||||
|
||||
public static boolean isSmsEnabled(Context context) {
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
|
||||
return Util.isDefaultSmsProvider(context);
|
||||
|
Loading…
x
Reference in New Issue
Block a user