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
This commit is contained in:
Nick Alexander 2018-04-25 12:17:05 -07:00
Родитель d3b8b75e8c
Коммит 397ff33d16
2 изменённых файлов: 15 добавлений и 0 удалений

Просмотреть файл

@ -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);

Просмотреть файл

@ -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();
}