From 397ff33d165c6567631c2dd6548fda9610884f6a Mon Sep 17 00:00:00 2001 From: Nick Alexander Date: Wed, 25 Apr 2018 12:17:05 -0700 Subject: [PATCH] Bug 1456487 - Update Firefox Account's first run UUID when re-connecting. r=rnewman The behaviour of Android Firefox Account instances recently changed in the face of system "Clear data" commands. To align more closely with common Apps like Dropbox and Whatsapp (which generally don't use Android Account instances), after a "Clear data" a Firefox Account is moved to the Separated state, requiring the user to re-connect them with a password challenge. To achieve this, newly created accounts include a first run UUID; after a "Clear data", the App is killed and restarted, Sync sees a different first run UUID, and the Account is moved to the Separated state. (I honestly don't know what happens if the Sync code never sees a different first run UUID, but that's for another day.) If the user then, in the same first run session, re-connects the Firefox Account... the Sync code will again see the different first run UUID and move the Account to the Separated state. This patch updates the first run UUID when the Account is re-connected, breaking that cycle. MozReview-Commit-ID: 9jcO9Ym54an --HG-- extra : rebase_source : be92a7ab0f36563e7b3af69f42095dc2b244bdd2 --- .../java/org/mozilla/gecko/AccountsHelper.java | 1 + .../gecko/fxa/authenticator/AndroidFxAccount.java | 14 ++++++++++++++ 2 files changed, 15 insertions(+) diff --git a/mobile/android/base/java/org/mozilla/gecko/AccountsHelper.java b/mobile/android/base/java/org/mozilla/gecko/AccountsHelper.java index 1936351d154e..438ee445bc5d 100644 --- a/mobile/android/base/java/org/mozilla/gecko/AccountsHelper.java +++ b/mobile/android/base/java/org/mozilla/gecko/AccountsHelper.java @@ -192,6 +192,7 @@ public class AccountsHelper implements BundleEventListener { final AndroidFxAccount fxAccount = new AndroidFxAccount(mContext, account); fxAccount.setState(state); + fxAccount.updateFirstRunScope(mContext); if (callback != null) { callback.sendSuccess(true); diff --git a/mobile/android/services/src/main/java/org/mozilla/gecko/fxa/authenticator/AndroidFxAccount.java b/mobile/android/services/src/main/java/org/mozilla/gecko/fxa/authenticator/AndroidFxAccount.java index 45dd60417afb..eaf619068fdc 100644 --- a/mobile/android/services/src/main/java/org/mozilla/gecko/fxa/authenticator/AndroidFxAccount.java +++ b/mobile/android/services/src/main/java/org/mozilla/gecko/fxa/authenticator/AndroidFxAccount.java @@ -645,6 +645,20 @@ public class AndroidFxAccount { } } + /** + * If there's an active First Run session, tag the given account with it. If + * there's no active First Run session, remove any existing tag. We do this + * in order to reliably determine if an account was created during the current + * "first run"; this allows us to re-connect an account that was not created + * during the current "first run". + * + * See {@link FirefoxAccounts#optionallySeparateAccountsDuringFirstRun} for details. + */ + public void updateFirstRunScope(final Context context) { + String firstRunUUID = EnvironmentUtils.firstRunUUID(context); + accountManager.setUserData(account, ACCOUNT_KEY_FIRST_RUN_SCOPE, firstRunUUID); + } + private void clearSyncPrefs() throws UnsupportedEncodingException, GeneralSecurityException { getSyncPrefs().edit().clear().apply(); }