--- a/mobile/android/services/src/main/java/org/mozilla/gecko/fxa/sync/FxAccountSyncAdapter.java
+++ b/mobile/android/services/src/main/java/org/mozilla/gecko/fxa/sync/FxAccountSyncAdapter.java
@@ -399,16 +399,32 @@ public class FxAccountSyncAdapter extend
return System.currentTimeMillis() + delay;
}
};
TokenServerClient tokenServerclient = new TokenServerClient(tokenServerEndpointURI, executor);
tokenServerclient.getTokenFromBrowserIDAssertion(assertion, true, clientState, delegate);
}
+ public void maybeRegisterDevice(Context context, AndroidFxAccount fxAccount) {
+ // Register the device if necessary (asynchronous, in another thread).
+ // As part of device registration, we obtain a PushSubscription, register our push endpoint
+ // with FxA, and update account data with fxaDeviceId, which is part of our synced
+ // clients record.
+ if (fxAccount.getDeviceRegistrationVersion() != FxAccountDeviceRegistrator.DEVICE_REGISTRATION_VERSION
+ || TextUtils.isEmpty(fxAccount.getDeviceId())) {
+ FxAccountDeviceRegistrator.register(context);
+ // We might need to re-register periodically to ensure our FxA push subscription is valid.
+ // This involves unsubscribing, subscribing and updating remote FxA device record with
+ // new push subscription information.
+ } else if (FxAccountDeviceRegistrator.needToRenewRegistration(fxAccount.getDeviceRegistrationTimestamp())) {
+ FxAccountDeviceRegistrator.renewRegistration(context);
+ }
+ }
+
/**
* A trivial Sync implementation that does not cache client keys,
* certificates, or tokens.
*
* This should be replaced with a full {@link FxAccountAuthenticator}-based
* token implementation.
*/
@Override
@@ -525,16 +541,19 @@ public class FxAccountSyncAdapter extend
final FxAccountLoginStateMachine stateMachine = new FxAccountLoginStateMachine();
stateMachine.advance(state, StateLabel.Married, new FxADefaultLoginStateMachineDelegate(context, fxAccount) {
@Override
public void handleNotMarried(State notMarried) {
Logger.info(LOG_TAG, "handleNotMarried: in " + notMarried.getStateLabel());
schedulePolicy.onHandleFinal(notMarried.getNeededAction());
syncDelegate.handleCannotSync(notMarried);
+ if (notMarried.getStateLabel() == StateLabel.Engaged) {
+ maybeRegisterDevice(context, fxAccount);
+ }
}
private boolean shouldRequestToken(final BackoffHandler tokenBackoffHandler, final Bundle extras) {
return shouldPerformSync(tokenBackoffHandler, "token", extras);
}
@Override
public void handleMarried(Married married) {
@@ -573,29 +592,17 @@ public class FxAccountSyncAdapter extend
final SessionCallback sessionCallback = new SessionCallback(syncDelegate, schedulePolicy);
final KeyBundle syncKeyBundle = married.getSyncKeyBundle();
final String clientState = married.getClientState();
syncWithAssertion(
assertion, tokenServerEndpointURI, tokenBackoffHandler, sharedPrefs,
syncKeyBundle, clientState, sessionCallback, extras, fxAccount, syncDeadline);
- // Register the device if necessary (asynchronous, in another thread).
- // As part of device registration, we obtain a PushSubscription, register our push endpoint
- // with FxA, and update account data with fxaDeviceId, which is part of our synced
- // clients record.
- if (fxAccount.getDeviceRegistrationVersion() != FxAccountDeviceRegistrator.DEVICE_REGISTRATION_VERSION
- || TextUtils.isEmpty(fxAccount.getDeviceId())) {
- FxAccountDeviceRegistrator.register(context);
- // We might need to re-register periodically to ensure our FxA push subscription is valid.
- // This involves unsubscribing, subscribing and updating remote FxA device record with
- // new push subscription information.
- } else if (FxAccountDeviceRegistrator.needToRenewRegistration(fxAccount.getDeviceRegistrationTimestamp())) {
- FxAccountDeviceRegistrator.renewRegistration(context);
- }
+ maybeRegisterDevice(context, fxAccount);
// Force fetch the profile avatar information. (asynchronous, in another thread)
Logger.info(LOG_TAG, "Fetching profile avatar information.");
fxAccount.fetchProfileJSON();
} catch (Exception e) {
syncDelegate.handleError(e);
return;
}