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

@ -78,7 +78,6 @@ public class ApplicationContext extends MultiDexApplication implements Dependenc
@Override @Override
public void onCreate() { public void onCreate() {
super.onCreate(); super.onCreate();
initializeDeveloperBuild();
initializeRandomNumberFix(); initializeRandomNumberFix();
initializeLogging(); initializeLogging();
initializeDependencyInjection(); initializeDependencyInjection();
@ -109,15 +108,6 @@ public class ApplicationContext extends MultiDexApplication implements Dependenc
return expiringMessageManager; return expiringMessageManager;
} }
private void initializeDeveloperBuild() {
if (BuildConfig.DEV_BUILD) {
StrictMode.setThreadPolicy(new ThreadPolicy.Builder().detectAll()
.penaltyLog()
.build());
StrictMode.setVmPolicy(new VmPolicy.Builder().detectAll().penaltyLog().build());
}
}
private void initializeRandomNumberFix() { private void initializeRandomNumberFix() {
PRNGFixes.apply(); PRNGFixes.apply();
} }
@ -150,9 +140,7 @@ public class ApplicationContext extends MultiDexApplication implements Dependenc
} }
private void initializeGcmCheck() { private void initializeGcmCheck() {
if (TextSecurePreferences.isPushRegistered(this) && if (TextSecurePreferences.isPushRegistered(this)) {
TextSecurePreferences.getGcmRegistrationId(this) == null)
{
this.jobManager.add(new GcmRefreshJob(this)); this.jobManager.add(new GcmRefreshJob(this));
} }
} }

View File

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