Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
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.fxa.authenticator; |
michael@0 | 6 | |
michael@0 | 7 | import org.mozilla.gecko.background.common.log.Logger; |
michael@0 | 8 | import org.mozilla.gecko.fxa.FxAccountConstants; |
michael@0 | 9 | import org.mozilla.gecko.fxa.activities.FxAccountGetStartedActivity; |
michael@0 | 10 | |
michael@0 | 11 | import android.accounts.AbstractAccountAuthenticator; |
michael@0 | 12 | import android.accounts.Account; |
michael@0 | 13 | import android.accounts.AccountAuthenticatorResponse; |
michael@0 | 14 | import android.accounts.AccountManager; |
michael@0 | 15 | import android.accounts.NetworkErrorException; |
michael@0 | 16 | import android.content.Context; |
michael@0 | 17 | import android.content.Intent; |
michael@0 | 18 | import android.os.Bundle; |
michael@0 | 19 | |
michael@0 | 20 | public class FxAccountAuthenticator extends AbstractAccountAuthenticator { |
michael@0 | 21 | public static final String LOG_TAG = FxAccountAuthenticator.class.getSimpleName(); |
michael@0 | 22 | |
michael@0 | 23 | protected final Context context; |
michael@0 | 24 | protected final AccountManager accountManager; |
michael@0 | 25 | |
michael@0 | 26 | public FxAccountAuthenticator(Context context) { |
michael@0 | 27 | super(context); |
michael@0 | 28 | this.context = context; |
michael@0 | 29 | this.accountManager = AccountManager.get(context); |
michael@0 | 30 | } |
michael@0 | 31 | |
michael@0 | 32 | @Override |
michael@0 | 33 | public Bundle addAccount(AccountAuthenticatorResponse response, |
michael@0 | 34 | String accountType, String authTokenType, String[] requiredFeatures, |
michael@0 | 35 | Bundle options) |
michael@0 | 36 | throws NetworkErrorException { |
michael@0 | 37 | Logger.debug(LOG_TAG, "addAccount"); |
michael@0 | 38 | |
michael@0 | 39 | final Bundle res = new Bundle(); |
michael@0 | 40 | |
michael@0 | 41 | if (!FxAccountConstants.ACCOUNT_TYPE.equals(accountType)) { |
michael@0 | 42 | res.putInt(AccountManager.KEY_ERROR_CODE, -1); |
michael@0 | 43 | res.putString(AccountManager.KEY_ERROR_MESSAGE, "Not adding unknown account type."); |
michael@0 | 44 | return res; |
michael@0 | 45 | } |
michael@0 | 46 | |
michael@0 | 47 | Intent intent = new Intent(context, FxAccountGetStartedActivity.class); |
michael@0 | 48 | res.putParcelable(AccountManager.KEY_INTENT, intent); |
michael@0 | 49 | return res; |
michael@0 | 50 | } |
michael@0 | 51 | |
michael@0 | 52 | @Override |
michael@0 | 53 | public Bundle confirmCredentials(AccountAuthenticatorResponse response, Account account, Bundle options) |
michael@0 | 54 | throws NetworkErrorException { |
michael@0 | 55 | Logger.debug(LOG_TAG, "confirmCredentials"); |
michael@0 | 56 | |
michael@0 | 57 | return null; |
michael@0 | 58 | } |
michael@0 | 59 | |
michael@0 | 60 | @Override |
michael@0 | 61 | public Bundle editProperties(AccountAuthenticatorResponse response, String accountType) { |
michael@0 | 62 | Logger.debug(LOG_TAG, "editProperties"); |
michael@0 | 63 | |
michael@0 | 64 | return null; |
michael@0 | 65 | } |
michael@0 | 66 | |
michael@0 | 67 | @Override |
michael@0 | 68 | public Bundle getAuthToken(final AccountAuthenticatorResponse response, |
michael@0 | 69 | final Account account, final String authTokenType, final Bundle options) |
michael@0 | 70 | throws NetworkErrorException { |
michael@0 | 71 | Logger.debug(LOG_TAG, "getAuthToken"); |
michael@0 | 72 | |
michael@0 | 73 | Logger.warn(LOG_TAG, "Returning null bundle for getAuthToken."); |
michael@0 | 74 | |
michael@0 | 75 | return null; |
michael@0 | 76 | } |
michael@0 | 77 | |
michael@0 | 78 | @Override |
michael@0 | 79 | public String getAuthTokenLabel(String authTokenType) { |
michael@0 | 80 | Logger.debug(LOG_TAG, "getAuthTokenLabel"); |
michael@0 | 81 | |
michael@0 | 82 | return null; |
michael@0 | 83 | } |
michael@0 | 84 | |
michael@0 | 85 | @Override |
michael@0 | 86 | public Bundle hasFeatures(AccountAuthenticatorResponse response, |
michael@0 | 87 | Account account, String[] features) throws NetworkErrorException { |
michael@0 | 88 | Logger.debug(LOG_TAG, "hasFeatures"); |
michael@0 | 89 | |
michael@0 | 90 | return null; |
michael@0 | 91 | } |
michael@0 | 92 | |
michael@0 | 93 | @Override |
michael@0 | 94 | public Bundle updateCredentials(AccountAuthenticatorResponse response, |
michael@0 | 95 | Account account, String authTokenType, Bundle options) |
michael@0 | 96 | throws NetworkErrorException { |
michael@0 | 97 | Logger.debug(LOG_TAG, "updateCredentials"); |
michael@0 | 98 | |
michael@0 | 99 | return null; |
michael@0 | 100 | } |
michael@0 | 101 | |
michael@0 | 102 | /** |
michael@0 | 103 | * If the account is going to be removed, broadcast an "account deleted" |
michael@0 | 104 | * intent. This allows us to clean up the account. |
michael@0 | 105 | * <p> |
michael@0 | 106 | * It is preferable to receive Android's LOGIN_ACCOUNTS_CHANGED_ACTION broadcast |
michael@0 | 107 | * than to create our own hacky broadcast here, but that doesn't include enough |
michael@0 | 108 | * information about which Accounts changed to correctly identify whether a Sync |
michael@0 | 109 | * account has been removed (when some Firefox channels are installed on the SD |
michael@0 | 110 | * card). We can work around this by storing additional state but it's both messy |
michael@0 | 111 | * and expensive because the broadcast is noisy. |
michael@0 | 112 | * <p> |
michael@0 | 113 | * Note that this is <b>not</b> called when an Android Account is blown away |
michael@0 | 114 | * due to the SD card being unmounted. |
michael@0 | 115 | */ |
michael@0 | 116 | @Override |
michael@0 | 117 | public Bundle getAccountRemovalAllowed(final AccountAuthenticatorResponse response, Account account) |
michael@0 | 118 | throws NetworkErrorException { |
michael@0 | 119 | Bundle result = super.getAccountRemovalAllowed(response, account); |
michael@0 | 120 | |
michael@0 | 121 | if (result == null || |
michael@0 | 122 | !result.containsKey(AccountManager.KEY_BOOLEAN_RESULT) || |
michael@0 | 123 | result.containsKey(AccountManager.KEY_INTENT)) { |
michael@0 | 124 | return result; |
michael@0 | 125 | } |
michael@0 | 126 | |
michael@0 | 127 | final boolean removalAllowed = result.getBoolean(AccountManager.KEY_BOOLEAN_RESULT); |
michael@0 | 128 | if (!removalAllowed) { |
michael@0 | 129 | return result; |
michael@0 | 130 | } |
michael@0 | 131 | |
michael@0 | 132 | // Broadcast a message to all Firefox channels sharing this Android |
michael@0 | 133 | // Account type telling that this Firefox account has been deleted. |
michael@0 | 134 | // |
michael@0 | 135 | // Broadcast intents protected with permissions are secure, so it's okay |
michael@0 | 136 | // to include private information such as a password. |
michael@0 | 137 | final Intent intent = AndroidFxAccount.makeDeletedAccountIntent(context, account); |
michael@0 | 138 | Logger.info(LOG_TAG, "Account named " + account.name + " being removed; " + |
michael@0 | 139 | "broadcasting secure intent " + intent.getAction() + "."); |
michael@0 | 140 | context.sendBroadcast(intent, FxAccountConstants.PER_ACCOUNT_TYPE_PERMISSION); |
michael@0 | 141 | |
michael@0 | 142 | return result; |
michael@0 | 143 | } |
michael@0 | 144 | } |