Wed, 31 Dec 2014 07:22:50 +0100
Correct previous dual key logic pending first delivery installment.
michael@0 | 1 | /* This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 2 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 3 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 4 | |
michael@0 | 5 | package org.mozilla.gecko.sync.receivers; |
michael@0 | 6 | |
michael@0 | 7 | import org.mozilla.gecko.sync.CredentialException; |
michael@0 | 8 | import org.mozilla.gecko.background.common.GlobalConstants; |
michael@0 | 9 | import org.mozilla.gecko.background.common.log.Logger; |
michael@0 | 10 | import org.mozilla.gecko.sync.SyncConfiguration; |
michael@0 | 11 | import org.mozilla.gecko.sync.ThreadPool; |
michael@0 | 12 | import org.mozilla.gecko.sync.Utils; |
michael@0 | 13 | import org.mozilla.gecko.sync.config.ConfigurationMigrator; |
michael@0 | 14 | import org.mozilla.gecko.sync.setup.Constants; |
michael@0 | 15 | import org.mozilla.gecko.sync.setup.SyncAccounts; |
michael@0 | 16 | import org.mozilla.gecko.sync.setup.SyncAccounts.SyncAccountParameters; |
michael@0 | 17 | |
michael@0 | 18 | import android.accounts.Account; |
michael@0 | 19 | import android.accounts.AccountManager; |
michael@0 | 20 | import android.content.BroadcastReceiver; |
michael@0 | 21 | import android.content.Context; |
michael@0 | 22 | import android.content.Intent; |
michael@0 | 23 | |
michael@0 | 24 | public class UpgradeReceiver extends BroadcastReceiver { |
michael@0 | 25 | private static final String LOG_TAG = "UpgradeReceiver"; |
michael@0 | 26 | |
michael@0 | 27 | @Override |
michael@0 | 28 | public void onReceive(final Context context, Intent intent) { |
michael@0 | 29 | Logger.debug(LOG_TAG, "Broadcast received."); |
michael@0 | 30 | // Should filter for specific MY_PACKAGE_REPLACED intent, but Android does |
michael@0 | 31 | // not expose it. |
michael@0 | 32 | ThreadPool.run(new Runnable() { |
michael@0 | 33 | @Override |
michael@0 | 34 | public void run() { |
michael@0 | 35 | final AccountManager accountManager = AccountManager.get(context); |
michael@0 | 36 | final Account[] accounts = SyncAccounts.syncAccounts(context); |
michael@0 | 37 | |
michael@0 | 38 | for (Account a : accounts) { |
michael@0 | 39 | if ("1".equals(accountManager.getUserData(a, Constants.DATA_ENABLE_ON_UPGRADE))) { |
michael@0 | 40 | SyncAccounts.setSyncAutomatically(a, true); |
michael@0 | 41 | accountManager.setUserData(a, Constants.DATA_ENABLE_ON_UPGRADE, "0"); |
michael@0 | 42 | } |
michael@0 | 43 | } |
michael@0 | 44 | } |
michael@0 | 45 | }); |
michael@0 | 46 | |
michael@0 | 47 | /** |
michael@0 | 48 | * Bug 761682: migrate preferences forward. |
michael@0 | 49 | */ |
michael@0 | 50 | ThreadPool.run(new Runnable() { |
michael@0 | 51 | @Override |
michael@0 | 52 | public void run() { |
michael@0 | 53 | AccountManager accountManager = AccountManager.get(context); |
michael@0 | 54 | final Account[] accounts = SyncAccounts.syncAccounts(context); |
michael@0 | 55 | |
michael@0 | 56 | for (Account account : accounts) { |
michael@0 | 57 | Logger.info(LOG_TAG, "Migrating preferences on upgrade for Android account named " + Utils.obfuscateEmail(account.name) + "."); |
michael@0 | 58 | |
michael@0 | 59 | SyncAccountParameters params; |
michael@0 | 60 | try { |
michael@0 | 61 | params = SyncAccounts.blockingFromAndroidAccountV0(context, accountManager, account); |
michael@0 | 62 | } catch (CredentialException e) { |
michael@0 | 63 | Logger.warn(LOG_TAG, "Caught exception fetching account parameters while trying to migrate preferences; ignoring.", e); |
michael@0 | 64 | continue; |
michael@0 | 65 | } |
michael@0 | 66 | |
michael@0 | 67 | final String product = GlobalConstants.BROWSER_INTENT_PACKAGE; |
michael@0 | 68 | final String username = params.username; |
michael@0 | 69 | final String serverURL = params.serverURL; |
michael@0 | 70 | final String profile = "default"; |
michael@0 | 71 | try { |
michael@0 | 72 | ConfigurationMigrator.ensurePrefsAreVersion(SyncConfiguration.CURRENT_PREFS_VERSION, context, accountManager, account, |
michael@0 | 73 | product, username, serverURL, profile); |
michael@0 | 74 | } catch (Exception e) { |
michael@0 | 75 | Logger.warn(LOG_TAG, "Caught exception trying to migrate preferences; ignoring.", e); |
michael@0 | 76 | continue; |
michael@0 | 77 | } |
michael@0 | 78 | } |
michael@0 | 79 | } |
michael@0 | 80 | }); |
michael@0 | 81 | } |
michael@0 | 82 | } |