Skip to content

Commit

Permalink
Check to see if FCM is available at app launch.
Browse files Browse the repository at this point in the history
  • Loading branch information
greyson-signal committed Apr 22, 2020
1 parent 3f7d068 commit eea7174
Showing 1 changed file with 18 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
import org.thoughtcrime.securesms.jobs.FcmRefreshJob;
import org.thoughtcrime.securesms.jobs.MultiDeviceContactUpdateJob;
import org.thoughtcrime.securesms.jobs.PushNotificationReceiveJob;
import org.thoughtcrime.securesms.jobs.RefreshAttributesJob;
import org.thoughtcrime.securesms.jobs.RefreshPreKeysJob;
import org.thoughtcrime.securesms.logging.AndroidLogger;
import org.thoughtcrime.securesms.logging.CustomSignalProtocolLogger;
Expand All @@ -67,6 +68,7 @@
import org.thoughtcrime.securesms.service.UpdateApkRefreshListener;
import org.thoughtcrime.securesms.storage.StorageSyncHelper;
import org.thoughtcrime.securesms.util.FeatureFlags;
import org.thoughtcrime.securesms.util.PlayServicesUtil;
import org.thoughtcrime.securesms.util.TextSecurePreferences;
import org.thoughtcrime.securesms.util.concurrent.SignalExecutors;
import org.thoughtcrime.securesms.util.dynamiclanguage.DynamicLanguageContextWrapper;
Expand Down Expand Up @@ -127,6 +129,7 @@ public void onCreate() {
initializePendingMessages();
initializeBlobProvider();
initializeCleanup();
initializePlayServicesCheck();

FeatureFlags.init();
NotificationChannels.create(this);
Expand Down Expand Up @@ -375,6 +378,21 @@ private void initializeCleanup() {
});
}

private void initializePlayServicesCheck() {
if (TextSecurePreferences.isFcmDisabled(this)) {
PlayServicesUtil.PlayServicesStatus status = PlayServicesUtil.getPlayServicesStatus(this);

if (status == PlayServicesUtil.PlayServicesStatus.SUCCESS) {
Log.i(TAG, "Play Services are newly-available. Updating to use FCM.");

TextSecurePreferences.setFcmDisabled(this, false);
ApplicationDependencies.getJobManager().startChain(new FcmRefreshJob())
.then(new RefreshAttributesJob())
.enqueue();
}
}
}

@Override
protected void attachBaseContext(Context base) {
super.attachBaseContext(DynamicLanguageContextWrapper.updateContext(base, TextSecurePreferences.getLanguage(base)));
Expand Down

2 comments on commit eea7174

@johanw666
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why only switch in one direction? If someone removes the Play services the app could switch to WebSockets.

@greyson-signal
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Was looking to fix one specific problem, didn't have the bandwidth to test stuff going the other way.

Please sign in to comment.