/* This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ package org.mozilla.goanna.fxa.receivers; import java.util.LinkedList; import java.util.List; import java.util.concurrent.Executor; import java.util.concurrent.Executors; import org.mozilla.goanna.background.common.log.Logger; import org.mozilla.goanna.background.fxa.FxAccountUtils; import org.mozilla.goanna.fxa.FirefoxAccounts; import org.mozilla.goanna.fxa.FxAccountConstants; import org.mozilla.goanna.fxa.authenticator.AndroidFxAccount; import org.mozilla.goanna.fxa.login.State; import org.mozilla.goanna.fxa.login.State.StateLabel; import org.mozilla.goanna.sync.Utils; import android.accounts.Account; import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent; /** * A receiver that takes action when our Android package is upgraded (replaced). */ public class FxAccountUpgradeReceiver extends BroadcastReceiver { private static final String LOG_TAG = FxAccountUpgradeReceiver.class.getSimpleName(); /** * Produce a list of Runnable instances to be executed sequentially on * upgrade. *
* Each Runnable will be executed sequentially on a background thread. Any
* unchecked Exception thrown will be caught and ignored.
*
* @param context Android context.
* @return list of Runnable instances.
*/
protected List
* This is our main deprecation-and-upgrade mechanism: in some way, the
* Account gets moved to the Doghouse state. If possible, an upgraded version
* of the package advances to Separated, prompting the user to re-connect the
* Account.
*/
protected static class AdvanceFromDoghouseRunnable implements Runnable {
protected final Context context;
public AdvanceFromDoghouseRunnable(Context context) {
this.context = context;
}
@Override
public void run() {
final Account[] accounts = FirefoxAccounts.getFirefoxAccounts(context);
Logger.info(LOG_TAG, "Trying to advance " + accounts.length + " existing Firefox Accounts from the Doghouse to Separated (if necessary).");
for (Account account : accounts) {
try {
final AndroidFxAccount fxAccount = new AndroidFxAccount(context, account);
// For great debugging.
if (FxAccountUtils.LOG_PERSONAL_INFORMATION) {
fxAccount.dump();
}
State state = fxAccount.getState();
if (state == null || state.getStateLabel() != StateLabel.Doghouse) {
Logger.debug(LOG_TAG, "Account named like " + Utils.obfuscateEmail(account.name) + " is not in the Doghouse; skipping.");
continue;
}
Logger.debug(LOG_TAG, "Account named like " + Utils.obfuscateEmail(account.name) + " is in the Doghouse; advancing to Separated.");
fxAccount.setState(state.makeSeparatedState());
} catch (Exception e) {
Logger.warn(LOG_TAG, "Got exception trying to advance account named like " + Utils.obfuscateEmail(account.name) +
" from Doghouse to Separated state; ignoring.", e);
}
}
}
}
}