Reregister GCM on every app start

Fixes #5531
// FREEBIE
This commit is contained in:
Moxie Marlinspike
2017-03-06 11:50:51 -08:00
parent bdcfabf1ee
commit b110c8a2cb
2 changed files with 15 additions and 31 deletions

View File

@@ -62,27 +62,23 @@ public class GcmRefreshJob extends ContextJob implements InjectableType {
public void onRun() throws Exception {
if (TextSecurePreferences.isGcmDisabled(context)) return;
String registrationId = TextSecurePreferences.getGcmRegistrationId(context);
Log.w(TAG, "Reregistering GCM...");
int result = GooglePlayServicesUtil.isGooglePlayServicesAvailable(context);
if (registrationId == null) {
Log.w(TAG, "GCM registrationId expired, reregistering...");
int result = GooglePlayServicesUtil.isGooglePlayServicesAvailable(context);
if (result != ConnectionResult.SUCCESS) {
notifyGcmFailure();
} else {
String gcmId = GoogleCloudMessaging.getInstance(context).register(REGISTRATION_ID);
textSecureAccountManager.setGcmId(Optional.of(gcmId));
if (result != ConnectionResult.SUCCESS) {
notifyGcmFailure();
} else {
String gcmId = GoogleCloudMessaging.getInstance(context).register(REGISTRATION_ID);
textSecureAccountManager.setGcmId(Optional.of(gcmId));
try {
redPhoneAccountManager.setGcmId(Optional.of(gcmId));
} catch (UnauthorizedException e) {
Log.w(TAG, e);
}
TextSecurePreferences.setGcmRegistrationId(context, gcmId);
TextSecurePreferences.setWebsocketRegistered(context, true);
try {
redPhoneAccountManager.setGcmId(Optional.of(gcmId));
} catch (UnauthorizedException e) {
Log.w(TAG, e);
}
TextSecurePreferences.setGcmRegistrationId(context, gcmId);
TextSecurePreferences.setWebsocketRegistered(context, true);
}
}