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