Bug 1404124 - Pickle account right after it's created r=eoger
This is a relative of
Bug 988605, with an exception that instead of going the whole way
and ensuring pickled data is kept up-to-date as Nick proposed, this patch simply ensures that
we pickle as soon as possible, with a goal of eliminating pickle races. The end goal is to kill
off pickling entirely, and so the assumption here is that this workaround is good enough
in the meantime.
MozReview-Commit-ID: 7IjRH7KE2Z9
--- 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
@@ -36,16 +36,17 @@ import org.mozilla.gecko.db.BrowserContr
import org.mozilla.gecko.fxa.FirefoxAccounts;
import org.mozilla.gecko.fxa.FxAccountConstants;
import org.mozilla.gecko.fxa.login.State;
import org.mozilla.gecko.fxa.login.State.StateLabel;
import org.mozilla.gecko.fxa.login.StateFactory;
import org.mozilla.gecko.fxa.sync.FxAccountProfileService;
import org.mozilla.gecko.sync.ExtendedJSONObject;
import org.mozilla.gecko.sync.NonObjectJSONException;
+import org.mozilla.gecko.sync.ThreadPool;
import org.mozilla.gecko.sync.Utils;
import org.mozilla.gecko.sync.setup.Constants;
import org.mozilla.gecko.util.ThreadUtils;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.net.URISyntaxException;
import java.security.GeneralSecurityException;
@@ -583,20 +584,36 @@ public class AndroidFxAccount {
// http://stackoverflow.com/a/11698139. What happens is that tests that
// delete and re-create the same account frequently will find the account
// missing all or some of the userdata bundle, possibly due to an Android
// AccountManager caching bug.
for (String key : userdata.keySet()) {
accountManager.setUserData(account, key, userdata.getString(key));
}
- AndroidFxAccount fxAccount = new AndroidFxAccount(context, account);
+ final AndroidFxAccount fxAccount = new AndroidFxAccount(context, account);
if (!fromPickle) {
fxAccount.clearSyncPrefs();
+
+ // We can nearly eliminate various pickle races by pickling the account right after creation.
+ // These races are an unfortunate by-product of Bug 1368147. The long-term solution is to stop
+ // pickling entirely, but for now we just ensure we'll have a pickle file as soon as possible.
+ // Pickle in a background thread to avoid strict mode warnings.
+ ThreadPool.run(new Runnable() {
+ @Override
+ public void run() {
+ try {
+ AccountPickler.pickle(fxAccount, FxAccountConstants.ACCOUNT_PICKLE_FILENAME);
+ } catch (Exception e) {
+ // Should never happen, but we really don't want to die in a background thread.
+ Logger.warn(LOG_TAG, "Got exception pickling current account details; ignoring.", e);
+ }
+ }
+ });
}
fxAccount.setAuthoritiesToSyncAutomaticallyMap(authoritiesToSyncAutomaticallyMap);
return fxAccount;
}
private void clearSyncPrefs() throws UnsupportedEncodingException, GeneralSecurityException {