--- 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
@@ -195,17 +195,17 @@ public class FxAccountSyncAdapter extend
// Note to future maintainers: while there are reasons, other than 'backoff', this method
// might be called, in practice that _is_ the only reason it gets called at the moment of
// writing this. If this changes, please do expand this telemetry handling.
this.telemetryCollector.setError(TelemetryCollector.KEY_ERROR_INTERNAL, "backoff");
recordTelemetry();
}
private void recordTelemetry() {
- telemetryCollector.setFinished(SystemClock.elapsedRealtime());
+ telemetryCollector.setFinished(now());
final Intent telemetryIntent = new Intent();
telemetryIntent.setAction(ACTION_BACKGROUND_TELEMETRY);
telemetryIntent.putExtra(TelemetryContract.KEY_TYPE, TelemetryContract.KEY_TYPE_SYNC);
telemetryIntent.putExtra(TelemetryContract.KEY_TELEMETRY, this.telemetryCollector.build());
localBroadcastManager.sendBroadcast(telemetryIntent);
}
}
@@ -472,17 +472,17 @@ public class FxAccountSyncAdapter extend
// value for token server scheduling.
tokenBackoffHandler.setEarliestNextRequest(delay(backoffSeconds * 1000));
}
private long delay(long delay) {
return System.currentTimeMillis() + delay;
}
};
- telemetryCollector.setStarted(SystemClock.elapsedRealtime());
+ telemetryCollector.setStarted(now());
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
@@ -516,35 +516,33 @@ public class FxAccountSyncAdapter extend
@Override
public void onPerformSync(final Account account, final Bundle extras, final String authority, ContentProviderClient provider, final SyncResult syncResult) {
Logger.setThreadLogTag(FxAccountConstants.GLOBAL_LOG_TAG);
Logger.resetLogging();
final Context context = getContext();
final AndroidFxAccount fxAccount = new AndroidFxAccount(context, account);
- // NB: we use elapsedRealtime which is time since boot, to ensure our clock is monotonic and isn't
- // paused while CPU is in the power-saving mode.
- final long syncDeadline = SystemClock.elapsedRealtime() + SYNC_DEADLINE_DELTA_MILLIS;
+ final long syncDeadline = now() + SYNC_DEADLINE_DELTA_MILLIS;
Logger.info(LOG_TAG, "Syncing FxAccount" +
" account named like " + Utils.obfuscateEmail(account.name) +
" for authority " + authority +
" with instance " + this + ".");
Logger.info(LOG_TAG, "Account last synced at: " + fxAccount.getLastSyncedTimestamp());
if (FxAccountUtils.LOG_PERSONAL_INFORMATION) {
fxAccount.dump();
}
FirefoxAccounts.logSyncOptions(extras);
if (this.lastSyncRealtimeMillis > 0L &&
- (this.lastSyncRealtimeMillis + MINIMUM_SYNC_DELAY_MILLIS) > SystemClock.elapsedRealtime() &&
+ (this.lastSyncRealtimeMillis + MINIMUM_SYNC_DELAY_MILLIS) > now() &&
!extras.getBoolean(ContentResolver.SYNC_EXTRAS_IGNORE_BACKOFF, false)) {
Logger.info(LOG_TAG, "Not syncing FxAccount " + Utils.obfuscateEmail(account.name) +
": minimum interval not met.");
return;
}
// Pickle in a background thread to avoid strict mode warnings.
ThreadPool.run(new Runnable() {
@@ -701,17 +699,17 @@ public class FxAccountSyncAdapter extend
offeredResult = latch.take();
} catch (Exception e) {
Logger.error(LOG_TAG, "Got error syncing.", e);
syncDelegate.handleError(e);
} finally {
fxAccount.releaseSharedAccountStateLock();
}
- lastSyncRealtimeMillis = SystemClock.elapsedRealtime();
+ lastSyncRealtimeMillis = now();
// We got to this point without being offered a result, and so it's unwise to proceed with
// trying to sync stages again. Nothing else we can do but log an error.
if (offeredResult == null) {
Logger.error(LOG_TAG, "Did not receive a sync result from the delegate.");
return;
}
@@ -741,9 +739,15 @@ public class FxAccountSyncAdapter extend
Logger.info(LOG_TAG, "Syncing done.");
return;
}
// If there are any other stages marked as incomplete, request that they're synced again.
Logger.info(LOG_TAG, "Syncing done. Requesting an immediate follow-up sync.");
fxAccount.requestImmediateSync(stagesToSyncAgain, null);
}
+
+ private static long now() {
+ // NB: we use elapsedRealtime which is time since boot, to ensure our clock is monotonic and isn't
+ // paused while CPU is in the power-saving mode.
+ return SystemClock.elapsedRealtime();
+ }
}