Fred Quintana | 6030734 | 2009-03-24 22:48:12 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2009 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | package android.accounts; |
| 18 | |
Fred Quintana | d4a1d2e | 2009-07-16 16:36:38 -0700 | [diff] [blame] | 19 | import android.Manifest; |
Sandra Kwan | a578d11 | 2015-12-16 16:01:43 -0800 | [diff] [blame] | 20 | import android.annotation.SystemApi; |
Sandra Kwan | 390c9d2 | 2016-01-12 14:13:37 -0800 | [diff] [blame] | 21 | import android.content.Context; |
| 22 | import android.content.Intent; |
| 23 | import android.content.pm.PackageManager; |
| 24 | import android.os.Binder; |
| 25 | import android.os.Bundle; |
| 26 | import android.os.IBinder; |
| 27 | import android.os.RemoteException; |
| 28 | import android.text.TextUtils; |
Fred Quintana | f0fd843 | 2010-03-08 12:48:05 -0800 | [diff] [blame] | 29 | import android.util.Log; |
| 30 | |
| 31 | import java.util.Arrays; |
Fred Quintana | 6030734 | 2009-03-24 22:48:12 -0700 | [diff] [blame] | 32 | |
| 33 | /** |
Fred Quintana | 756b735 | 2009-10-21 13:43:10 -0700 | [diff] [blame] | 34 | * Abstract base class for creating AccountAuthenticators. |
| 35 | * In order to be an authenticator one must extend this class, provider implementations for the |
| 36 | * abstract methods and write a service that returns the result of {@link #getIBinder()} |
| 37 | * in the service's {@link android.app.Service#onBind(android.content.Intent)} when invoked |
| 38 | * with an intent with action {@link AccountManager#ACTION_AUTHENTICATOR_INTENT}. This service |
| 39 | * must specify the following intent filter and metadata tags in its AndroidManifest.xml file |
| 40 | * <pre> |
| 41 | * <intent-filter> |
| 42 | * <action android:name="android.accounts.AccountAuthenticator" /> |
| 43 | * </intent-filter> |
| 44 | * <meta-data android:name="android.accounts.AccountAuthenticator" |
| 45 | * android:resource="@xml/authenticator" /> |
| 46 | * </pre> |
| 47 | * The <code>android:resource</code> attribute must point to a resource that looks like: |
| 48 | * <pre> |
| 49 | * <account-authenticator xmlns:android="http://schemas.android.com/apk/res/android" |
| 50 | * android:accountType="typeOfAuthenticator" |
| 51 | * android:icon="@drawable/icon" |
| 52 | * android:smallIcon="@drawable/miniIcon" |
| 53 | * android:label="@string/label" |
| 54 | * android:accountPreferences="@xml/account_preferences" |
| 55 | * /> |
| 56 | * </pre> |
| 57 | * Replace the icons and labels with your own resources. The <code>android:accountType</code> |
| 58 | * attribute must be a string that uniquely identifies your authenticator and will be the same |
| 59 | * string that user will use when making calls on the {@link AccountManager} and it also |
| 60 | * corresponds to {@link Account#type} for your accounts. One user of the android:icon is the |
| 61 | * "Account & Sync" settings page and one user of the android:smallIcon is the Contact Application's |
| 62 | * tab panels. |
| 63 | * <p> |
Ken Wakasa | f76a50c | 2012-03-09 19:56:35 +0900 | [diff] [blame] | 64 | * The preferences attribute points to a PreferenceScreen xml hierarchy that contains |
Fred Quintana | 756b735 | 2009-10-21 13:43:10 -0700 | [diff] [blame] | 65 | * a list of PreferenceScreens that can be invoked to manage the authenticator. An example is: |
| 66 | * <pre> |
| 67 | * <PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"> |
| 68 | * <PreferenceCategory android:title="@string/title_fmt" /> |
| 69 | * <PreferenceScreen |
| 70 | * android:key="key1" |
| 71 | * android:title="@string/key1_action" |
| 72 | * android:summary="@string/key1_summary"> |
| 73 | * <intent |
| 74 | * android:action="key1.ACTION" |
| 75 | * android:targetPackage="key1.package" |
| 76 | * android:targetClass="key1.class" /> |
| 77 | * </PreferenceScreen> |
| 78 | * </PreferenceScreen> |
| 79 | * </pre> |
| 80 | * |
| 81 | * <p> |
| 82 | * The standard pattern for implementing any of the abstract methods is the following: |
| 83 | * <ul> |
| 84 | * <li> If the supplied arguments are enough for the authenticator to fully satisfy the request |
| 85 | * then it will do so and return a {@link Bundle} that contains the results. |
| 86 | * <li> If the authenticator needs information from the user to satisfy the request then it |
| 87 | * will create an {@link Intent} to an activity that will prompt the user for the information |
| 88 | * and then carry out the request. This intent must be returned in a Bundle as key |
| 89 | * {@link AccountManager#KEY_INTENT}. |
| 90 | * <p> |
| 91 | * The activity needs to return the final result when it is complete so the Intent should contain |
| 92 | * the {@link AccountAuthenticatorResponse} as {@link AccountManager#KEY_ACCOUNT_MANAGER_RESPONSE}. |
| 93 | * The activity must then call {@link AccountAuthenticatorResponse#onResult} or |
| 94 | * {@link AccountAuthenticatorResponse#onError} when it is complete. |
Fred Quintana | 31957f1 | 2009-10-21 13:43:10 -0700 | [diff] [blame] | 95 | * <li> If the authenticator cannot synchronously process the request and return a result then it |
Ed Heyl | d6f158b | 2009-10-29 10:18:45 -0700 | [diff] [blame] | 96 | * may choose to return null and then use the AccountManagerResponse to send the result |
Fred Quintana | 31957f1 | 2009-10-21 13:43:10 -0700 | [diff] [blame] | 97 | * when it has completed the request. |
Fred Quintana | 756b735 | 2009-10-21 13:43:10 -0700 | [diff] [blame] | 98 | * </ul> |
| 99 | * <p> |
| 100 | * The following descriptions of each of the abstract authenticator methods will not describe the |
| 101 | * possible asynchronous nature of the request handling and will instead just describe the input |
| 102 | * parameters and the expected result. |
| 103 | * <p> |
| 104 | * When writing an activity to satisfy these requests one must pass in the AccountManagerResponse |
| 105 | * and return the result via that response when the activity finishes (or whenever else the |
| 106 | * activity author deems it is the correct time to respond). |
| 107 | * The {@link AccountAuthenticatorActivity} handles this, so one may wish to extend that when |
| 108 | * writing activities to handle these requests. |
Fred Quintana | 6030734 | 2009-03-24 22:48:12 -0700 | [diff] [blame] | 109 | */ |
| 110 | public abstract class AbstractAccountAuthenticator { |
Fred Quintana | f0fd843 | 2010-03-08 12:48:05 -0800 | [diff] [blame] | 111 | private static final String TAG = "AccountAuthenticator"; |
| 112 | |
Carlos Valdivia | 91979be | 2015-05-22 14:11:35 -0700 | [diff] [blame] | 113 | /** |
| 114 | * Bundle key used for the {@code long} expiration time (in millis from the unix epoch) of the |
| 115 | * associated auth token. |
| 116 | * |
| 117 | * @see #getAuthToken |
| 118 | */ |
| 119 | public static final String KEY_CUSTOM_TOKEN_EXPIRY = "android.accounts.expiry"; |
| 120 | |
Sandra Kwan | 7881228 | 2015-11-04 11:19:47 -0800 | [diff] [blame] | 121 | /** |
| 122 | * Bundle key used for the {@link String} account type in session bundle. |
| 123 | * This is used in the default implementation of |
Sandra Kwan | e68c37e | 2015-11-12 17:11:49 -0800 | [diff] [blame] | 124 | * {@link #startAddAccountSession} and {@link startUpdateCredentialsSession}. |
Sandra Kwan | 7881228 | 2015-11-04 11:19:47 -0800 | [diff] [blame] | 125 | */ |
Sandra Kwan | 920f6ef | 2015-11-10 14:13:29 -0800 | [diff] [blame] | 126 | private static final String KEY_AUTH_TOKEN_TYPE = |
| 127 | "android.accounts.AbstractAccountAuthenticato.KEY_AUTH_TOKEN_TYPE"; |
Sandra Kwan | 7881228 | 2015-11-04 11:19:47 -0800 | [diff] [blame] | 128 | /** |
| 129 | * Bundle key used for the {@link String} array of required features in |
| 130 | * session bundle. This is used in the default implementation of |
Sandra Kwan | e68c37e | 2015-11-12 17:11:49 -0800 | [diff] [blame] | 131 | * {@link #startAddAccountSession} and {@link startUpdateCredentialsSession}. |
Sandra Kwan | 7881228 | 2015-11-04 11:19:47 -0800 | [diff] [blame] | 132 | */ |
Sandra Kwan | 920f6ef | 2015-11-10 14:13:29 -0800 | [diff] [blame] | 133 | private static final String KEY_REQUIRED_FEATURES = |
| 134 | "android.accounts.AbstractAccountAuthenticator.KEY_REQUIRED_FEATURES"; |
Sandra Kwan | 7881228 | 2015-11-04 11:19:47 -0800 | [diff] [blame] | 135 | /** |
| 136 | * Bundle key used for the {@link Bundle} options in session bundle. This is |
Sandra Kwan | e68c37e | 2015-11-12 17:11:49 -0800 | [diff] [blame] | 137 | * used in default implementation of {@link #startAddAccountSession} and |
| 138 | * {@link startUpdateCredentialsSession}. |
Sandra Kwan | 7881228 | 2015-11-04 11:19:47 -0800 | [diff] [blame] | 139 | */ |
Sandra Kwan | 920f6ef | 2015-11-10 14:13:29 -0800 | [diff] [blame] | 140 | private static final String KEY_OPTIONS = |
| 141 | "android.accounts.AbstractAccountAuthenticator.KEY_OPTIONS"; |
Sandra Kwan | e68c37e | 2015-11-12 17:11:49 -0800 | [diff] [blame] | 142 | /** |
| 143 | * Bundle key used for the {@link Account} account in session bundle. This is used |
| 144 | * used in default implementation of {@link startUpdateCredentialsSession}. |
| 145 | */ |
Sandra Kwan | 920f6ef | 2015-11-10 14:13:29 -0800 | [diff] [blame] | 146 | private static final String KEY_ACCOUNT = |
| 147 | "android.accounts.AbstractAccountAuthenticator.KEY_ACCOUNT"; |
Sandra Kwan | 7881228 | 2015-11-04 11:19:47 -0800 | [diff] [blame] | 148 | |
Fred Quintana | d4a1d2e | 2009-07-16 16:36:38 -0700 | [diff] [blame] | 149 | private final Context mContext; |
| 150 | |
| 151 | public AbstractAccountAuthenticator(Context context) { |
| 152 | mContext = context; |
| 153 | } |
| 154 | |
Fred Quintana | f7ae77c | 2009-10-02 17:19:31 -0700 | [diff] [blame] | 155 | private class Transport extends IAccountAuthenticator.Stub { |
Carlos Valdivia | 91979be | 2015-05-22 14:11:35 -0700 | [diff] [blame] | 156 | @Override |
Fred Quintana | a698f42 | 2009-04-08 19:14:54 -0700 | [diff] [blame] | 157 | public void addAccount(IAccountAuthenticatorResponse response, String accountType, |
Fred Quintana | f0fd843 | 2010-03-08 12:48:05 -0800 | [diff] [blame] | 158 | String authTokenType, String[] features, Bundle options) |
Fred Quintana | 6030734 | 2009-03-24 22:48:12 -0700 | [diff] [blame] | 159 | throws RemoteException { |
Fred Quintana | f0fd843 | 2010-03-08 12:48:05 -0800 | [diff] [blame] | 160 | if (Log.isLoggable(TAG, Log.VERBOSE)) { |
| 161 | Log.v(TAG, "addAccount: accountType " + accountType |
| 162 | + ", authTokenType " + authTokenType |
| 163 | + ", features " + (features == null ? "[]" : Arrays.toString(features))); |
| 164 | } |
Fred Quintana | d4a1d2e | 2009-07-16 16:36:38 -0700 | [diff] [blame] | 165 | checkBinderPermission(); |
Fred Quintana | a698f42 | 2009-04-08 19:14:54 -0700 | [diff] [blame] | 166 | try { |
Fred Quintana | 31957f1 | 2009-10-21 13:43:10 -0700 | [diff] [blame] | 167 | final Bundle result = AbstractAccountAuthenticator.this.addAccount( |
Fred Quintana | a698f42 | 2009-04-08 19:14:54 -0700 | [diff] [blame] | 168 | new AccountAuthenticatorResponse(response), |
Fred Quintana | f0fd843 | 2010-03-08 12:48:05 -0800 | [diff] [blame] | 169 | accountType, authTokenType, features, options); |
| 170 | if (Log.isLoggable(TAG, Log.VERBOSE)) { |
Ian Pedowitz | 6cc066d | 2015-08-05 14:23:43 +0000 | [diff] [blame] | 171 | if (result != null) { |
| 172 | result.keySet(); // force it to be unparcelled |
| 173 | } |
Fred Quintana | f0fd843 | 2010-03-08 12:48:05 -0800 | [diff] [blame] | 174 | Log.v(TAG, "addAccount: result " + AccountManager.sanitizeResult(result)); |
| 175 | } |
Fred Quintana | 31957f1 | 2009-10-21 13:43:10 -0700 | [diff] [blame] | 176 | if (result != null) { |
| 177 | response.onResult(result); |
tiansiming | f58793c | 2017-09-03 16:48:34 +0800 | [diff] [blame] | 178 | } else { |
| 179 | response.onError(AccountManager.ERROR_CODE_INVALID_RESPONSE, |
| 180 | "null bundle returned"); |
Fred Quintana | 31957f1 | 2009-10-21 13:43:10 -0700 | [diff] [blame] | 181 | } |
Fred Quintana | 5d1a0c3 | 2011-06-23 16:37:58 -0700 | [diff] [blame] | 182 | } catch (Exception e) { |
| 183 | handleException(response, "addAccount", accountType, e); |
Fred Quintana | a698f42 | 2009-04-08 19:14:54 -0700 | [diff] [blame] | 184 | } |
Fred Quintana | 6030734 | 2009-03-24 22:48:12 -0700 | [diff] [blame] | 185 | } |
| 186 | |
Carlos Valdivia | 91979be | 2015-05-22 14:11:35 -0700 | [diff] [blame] | 187 | @Override |
Fred Quintana | a698f42 | 2009-04-08 19:14:54 -0700 | [diff] [blame] | 188 | public void confirmCredentials(IAccountAuthenticatorResponse response, |
Fred Quintana | f7ae77c | 2009-10-02 17:19:31 -0700 | [diff] [blame] | 189 | Account account, Bundle options) throws RemoteException { |
Fred Quintana | f0fd843 | 2010-03-08 12:48:05 -0800 | [diff] [blame] | 190 | if (Log.isLoggable(TAG, Log.VERBOSE)) { |
| 191 | Log.v(TAG, "confirmCredentials: " + account); |
| 192 | } |
Fred Quintana | d4a1d2e | 2009-07-16 16:36:38 -0700 | [diff] [blame] | 193 | checkBinderPermission(); |
Fred Quintana | a698f42 | 2009-04-08 19:14:54 -0700 | [diff] [blame] | 194 | try { |
Fred Quintana | 31957f1 | 2009-10-21 13:43:10 -0700 | [diff] [blame] | 195 | final Bundle result = AbstractAccountAuthenticator.this.confirmCredentials( |
Fred Quintana | f7ae77c | 2009-10-02 17:19:31 -0700 | [diff] [blame] | 196 | new AccountAuthenticatorResponse(response), account, options); |
Fred Quintana | f0fd843 | 2010-03-08 12:48:05 -0800 | [diff] [blame] | 197 | if (Log.isLoggable(TAG, Log.VERBOSE)) { |
Ian Pedowitz | 6cc066d | 2015-08-05 14:23:43 +0000 | [diff] [blame] | 198 | if (result != null) { |
| 199 | result.keySet(); // force it to be unparcelled |
| 200 | } |
Fred Quintana | f0fd843 | 2010-03-08 12:48:05 -0800 | [diff] [blame] | 201 | Log.v(TAG, "confirmCredentials: result " |
| 202 | + AccountManager.sanitizeResult(result)); |
| 203 | } |
Fred Quintana | 31957f1 | 2009-10-21 13:43:10 -0700 | [diff] [blame] | 204 | if (result != null) { |
| 205 | response.onResult(result); |
| 206 | } |
Fred Quintana | 5d1a0c3 | 2011-06-23 16:37:58 -0700 | [diff] [blame] | 207 | } catch (Exception e) { |
| 208 | handleException(response, "confirmCredentials", account.toString(), e); |
Fred Quintana | a698f42 | 2009-04-08 19:14:54 -0700 | [diff] [blame] | 209 | } |
Fred Quintana | 6030734 | 2009-03-24 22:48:12 -0700 | [diff] [blame] | 210 | } |
| 211 | |
Carlos Valdivia | 91979be | 2015-05-22 14:11:35 -0700 | [diff] [blame] | 212 | @Override |
Fred Quintana | d4a1d2e | 2009-07-16 16:36:38 -0700 | [diff] [blame] | 213 | public void getAuthTokenLabel(IAccountAuthenticatorResponse response, |
| 214 | String authTokenType) |
| 215 | throws RemoteException { |
Fred Quintana | f0fd843 | 2010-03-08 12:48:05 -0800 | [diff] [blame] | 216 | if (Log.isLoggable(TAG, Log.VERBOSE)) { |
| 217 | Log.v(TAG, "getAuthTokenLabel: authTokenType " + authTokenType); |
| 218 | } |
Fred Quintana | d4a1d2e | 2009-07-16 16:36:38 -0700 | [diff] [blame] | 219 | checkBinderPermission(); |
| 220 | try { |
| 221 | Bundle result = new Bundle(); |
Fred Quintana | f7ae77c | 2009-10-02 17:19:31 -0700 | [diff] [blame] | 222 | result.putString(AccountManager.KEY_AUTH_TOKEN_LABEL, |
Fred Quintana | d4a1d2e | 2009-07-16 16:36:38 -0700 | [diff] [blame] | 223 | AbstractAccountAuthenticator.this.getAuthTokenLabel(authTokenType)); |
Fred Quintana | f0fd843 | 2010-03-08 12:48:05 -0800 | [diff] [blame] | 224 | if (Log.isLoggable(TAG, Log.VERBOSE)) { |
Ian Pedowitz | 6cc066d | 2015-08-05 14:23:43 +0000 | [diff] [blame] | 225 | if (result != null) { |
| 226 | result.keySet(); // force it to be unparcelled |
| 227 | } |
Fred Quintana | f0fd843 | 2010-03-08 12:48:05 -0800 | [diff] [blame] | 228 | Log.v(TAG, "getAuthTokenLabel: result " |
| 229 | + AccountManager.sanitizeResult(result)); |
| 230 | } |
Fred Quintana | 5d1a0c3 | 2011-06-23 16:37:58 -0700 | [diff] [blame] | 231 | response.onResult(result); |
| 232 | } catch (Exception e) { |
| 233 | handleException(response, "getAuthTokenLabel", authTokenType, e); |
Fred Quintana | d4a1d2e | 2009-07-16 16:36:38 -0700 | [diff] [blame] | 234 | } |
| 235 | } |
| 236 | |
Carlos Valdivia | 91979be | 2015-05-22 14:11:35 -0700 | [diff] [blame] | 237 | @Override |
Fred Quintana | 6030734 | 2009-03-24 22:48:12 -0700 | [diff] [blame] | 238 | public void getAuthToken(IAccountAuthenticatorResponse response, |
Fred Quintana | a698f42 | 2009-04-08 19:14:54 -0700 | [diff] [blame] | 239 | Account account, String authTokenType, Bundle loginOptions) |
Fred Quintana | 6030734 | 2009-03-24 22:48:12 -0700 | [diff] [blame] | 240 | throws RemoteException { |
Fred Quintana | f0fd843 | 2010-03-08 12:48:05 -0800 | [diff] [blame] | 241 | if (Log.isLoggable(TAG, Log.VERBOSE)) { |
| 242 | Log.v(TAG, "getAuthToken: " + account |
| 243 | + ", authTokenType " + authTokenType); |
| 244 | } |
Fred Quintana | d4a1d2e | 2009-07-16 16:36:38 -0700 | [diff] [blame] | 245 | checkBinderPermission(); |
Fred Quintana | a698f42 | 2009-04-08 19:14:54 -0700 | [diff] [blame] | 246 | try { |
| 247 | final Bundle result = AbstractAccountAuthenticator.this.getAuthToken( |
| 248 | new AccountAuthenticatorResponse(response), account, |
| 249 | authTokenType, loginOptions); |
Fred Quintana | f0fd843 | 2010-03-08 12:48:05 -0800 | [diff] [blame] | 250 | if (Log.isLoggable(TAG, Log.VERBOSE)) { |
Ian Pedowitz | 6cc066d | 2015-08-05 14:23:43 +0000 | [diff] [blame] | 251 | if (result != null) { |
| 252 | result.keySet(); // force it to be unparcelled |
| 253 | } |
Fred Quintana | f0fd843 | 2010-03-08 12:48:05 -0800 | [diff] [blame] | 254 | Log.v(TAG, "getAuthToken: result " + AccountManager.sanitizeResult(result)); |
| 255 | } |
Fred Quintana | a698f42 | 2009-04-08 19:14:54 -0700 | [diff] [blame] | 256 | if (result != null) { |
| 257 | response.onResult(result); |
| 258 | } |
Fred Quintana | 5d1a0c3 | 2011-06-23 16:37:58 -0700 | [diff] [blame] | 259 | } catch (Exception e) { |
| 260 | handleException(response, "getAuthToken", |
| 261 | account.toString() + "," + authTokenType, e); |
Fred Quintana | a698f42 | 2009-04-08 19:14:54 -0700 | [diff] [blame] | 262 | } |
Fred Quintana | 6030734 | 2009-03-24 22:48:12 -0700 | [diff] [blame] | 263 | } |
| 264 | |
Carlos Valdivia | 91979be | 2015-05-22 14:11:35 -0700 | [diff] [blame] | 265 | @Override |
Fred Quintana | a698f42 | 2009-04-08 19:14:54 -0700 | [diff] [blame] | 266 | public void updateCredentials(IAccountAuthenticatorResponse response, Account account, |
| 267 | String authTokenType, Bundle loginOptions) throws RemoteException { |
Fred Quintana | f0fd843 | 2010-03-08 12:48:05 -0800 | [diff] [blame] | 268 | if (Log.isLoggable(TAG, Log.VERBOSE)) { |
| 269 | Log.v(TAG, "updateCredentials: " + account |
| 270 | + ", authTokenType " + authTokenType); |
| 271 | } |
Fred Quintana | d4a1d2e | 2009-07-16 16:36:38 -0700 | [diff] [blame] | 272 | checkBinderPermission(); |
Fred Quintana | a698f42 | 2009-04-08 19:14:54 -0700 | [diff] [blame] | 273 | try { |
Fred Quintana | 31957f1 | 2009-10-21 13:43:10 -0700 | [diff] [blame] | 274 | final Bundle result = AbstractAccountAuthenticator.this.updateCredentials( |
Fred Quintana | a698f42 | 2009-04-08 19:14:54 -0700 | [diff] [blame] | 275 | new AccountAuthenticatorResponse(response), account, |
| 276 | authTokenType, loginOptions); |
Fred Quintana | f0fd843 | 2010-03-08 12:48:05 -0800 | [diff] [blame] | 277 | if (Log.isLoggable(TAG, Log.VERBOSE)) { |
Ian Pedowitz | 6cc066d | 2015-08-05 14:23:43 +0000 | [diff] [blame] | 278 | // Result may be null. |
| 279 | if (result != null) { |
| 280 | result.keySet(); // force it to be unparcelled |
| 281 | } |
Fred Quintana | f0fd843 | 2010-03-08 12:48:05 -0800 | [diff] [blame] | 282 | Log.v(TAG, "updateCredentials: result " |
| 283 | + AccountManager.sanitizeResult(result)); |
| 284 | } |
Fred Quintana | 31957f1 | 2009-10-21 13:43:10 -0700 | [diff] [blame] | 285 | if (result != null) { |
| 286 | response.onResult(result); |
| 287 | } |
Fred Quintana | 5d1a0c3 | 2011-06-23 16:37:58 -0700 | [diff] [blame] | 288 | } catch (Exception e) { |
| 289 | handleException(response, "updateCredentials", |
| 290 | account.toString() + "," + authTokenType, e); |
Fred Quintana | a698f42 | 2009-04-08 19:14:54 -0700 | [diff] [blame] | 291 | } |
Fred Quintana | 6030734 | 2009-03-24 22:48:12 -0700 | [diff] [blame] | 292 | } |
| 293 | |
Carlos Valdivia | 91979be | 2015-05-22 14:11:35 -0700 | [diff] [blame] | 294 | @Override |
Fred Quintana | a698f42 | 2009-04-08 19:14:54 -0700 | [diff] [blame] | 295 | public void editProperties(IAccountAuthenticatorResponse response, |
| 296 | String accountType) throws RemoteException { |
Fred Quintana | d4a1d2e | 2009-07-16 16:36:38 -0700 | [diff] [blame] | 297 | checkBinderPermission(); |
Fred Quintana | a698f42 | 2009-04-08 19:14:54 -0700 | [diff] [blame] | 298 | try { |
Fred Quintana | 31957f1 | 2009-10-21 13:43:10 -0700 | [diff] [blame] | 299 | final Bundle result = AbstractAccountAuthenticator.this.editProperties( |
Fred Quintana | 6030734 | 2009-03-24 22:48:12 -0700 | [diff] [blame] | 300 | new AccountAuthenticatorResponse(response), accountType); |
Fred Quintana | 31957f1 | 2009-10-21 13:43:10 -0700 | [diff] [blame] | 301 | if (result != null) { |
| 302 | response.onResult(result); |
| 303 | } |
Fred Quintana | 5d1a0c3 | 2011-06-23 16:37:58 -0700 | [diff] [blame] | 304 | } catch (Exception e) { |
| 305 | handleException(response, "editProperties", accountType, e); |
Fred Quintana | a698f42 | 2009-04-08 19:14:54 -0700 | [diff] [blame] | 306 | } |
Fred Quintana | 6030734 | 2009-03-24 22:48:12 -0700 | [diff] [blame] | 307 | } |
Fred Quintana | 3326920 | 2009-04-20 16:05:10 -0700 | [diff] [blame] | 308 | |
Carlos Valdivia | 91979be | 2015-05-22 14:11:35 -0700 | [diff] [blame] | 309 | @Override |
Fred Quintana | 3326920 | 2009-04-20 16:05:10 -0700 | [diff] [blame] | 310 | public void hasFeatures(IAccountAuthenticatorResponse response, |
| 311 | Account account, String[] features) throws RemoteException { |
Fred Quintana | d4a1d2e | 2009-07-16 16:36:38 -0700 | [diff] [blame] | 312 | checkBinderPermission(); |
Fred Quintana | 3326920 | 2009-04-20 16:05:10 -0700 | [diff] [blame] | 313 | try { |
Fred Quintana | 31957f1 | 2009-10-21 13:43:10 -0700 | [diff] [blame] | 314 | final Bundle result = AbstractAccountAuthenticator.this.hasFeatures( |
Fred Quintana | 3326920 | 2009-04-20 16:05:10 -0700 | [diff] [blame] | 315 | new AccountAuthenticatorResponse(response), account, features); |
Fred Quintana | 31957f1 | 2009-10-21 13:43:10 -0700 | [diff] [blame] | 316 | if (result != null) { |
| 317 | response.onResult(result); |
| 318 | } |
Fred Quintana | 5d1a0c3 | 2011-06-23 16:37:58 -0700 | [diff] [blame] | 319 | } catch (Exception e) { |
| 320 | handleException(response, "hasFeatures", account.toString(), e); |
Fred Quintana | 3326920 | 2009-04-20 16:05:10 -0700 | [diff] [blame] | 321 | } |
| 322 | } |
Fred Quintana | ffd0cb04 | 2009-08-15 21:45:26 -0700 | [diff] [blame] | 323 | |
Carlos Valdivia | 91979be | 2015-05-22 14:11:35 -0700 | [diff] [blame] | 324 | @Override |
Fred Quintana | ffd0cb04 | 2009-08-15 21:45:26 -0700 | [diff] [blame] | 325 | public void getAccountRemovalAllowed(IAccountAuthenticatorResponse response, |
| 326 | Account account) throws RemoteException { |
| 327 | checkBinderPermission(); |
| 328 | try { |
| 329 | final Bundle result = AbstractAccountAuthenticator.this.getAccountRemovalAllowed( |
| 330 | new AccountAuthenticatorResponse(response), account); |
| 331 | if (result != null) { |
| 332 | response.onResult(result); |
| 333 | } |
Fred Quintana | 5d1a0c3 | 2011-06-23 16:37:58 -0700 | [diff] [blame] | 334 | } catch (Exception e) { |
| 335 | handleException(response, "getAccountRemovalAllowed", account.toString(), e); |
Fred Quintana | ffd0cb04 | 2009-08-15 21:45:26 -0700 | [diff] [blame] | 336 | } |
| 337 | } |
Amith Yamasani | 67df64b | 2012-12-14 12:09:36 -0800 | [diff] [blame] | 338 | |
Carlos Valdivia | 91979be | 2015-05-22 14:11:35 -0700 | [diff] [blame] | 339 | @Override |
Amith Yamasani | 67df64b | 2012-12-14 12:09:36 -0800 | [diff] [blame] | 340 | public void getAccountCredentialsForCloning(IAccountAuthenticatorResponse response, |
| 341 | Account account) throws RemoteException { |
| 342 | checkBinderPermission(); |
| 343 | try { |
| 344 | final Bundle result = |
| 345 | AbstractAccountAuthenticator.this.getAccountCredentialsForCloning( |
| 346 | new AccountAuthenticatorResponse(response), account); |
| 347 | if (result != null) { |
| 348 | response.onResult(result); |
| 349 | } |
| 350 | } catch (Exception e) { |
| 351 | handleException(response, "getAccountCredentialsForCloning", account.toString(), e); |
| 352 | } |
| 353 | } |
| 354 | |
Carlos Valdivia | 91979be | 2015-05-22 14:11:35 -0700 | [diff] [blame] | 355 | @Override |
Amith Yamasani | 67df64b | 2012-12-14 12:09:36 -0800 | [diff] [blame] | 356 | public void addAccountFromCredentials(IAccountAuthenticatorResponse response, |
| 357 | Account account, |
| 358 | Bundle accountCredentials) throws RemoteException { |
| 359 | checkBinderPermission(); |
| 360 | try { |
| 361 | final Bundle result = |
| 362 | AbstractAccountAuthenticator.this.addAccountFromCredentials( |
| 363 | new AccountAuthenticatorResponse(response), account, |
| 364 | accountCredentials); |
| 365 | if (result != null) { |
| 366 | response.onResult(result); |
| 367 | } |
| 368 | } catch (Exception e) { |
| 369 | handleException(response, "addAccountFromCredentials", account.toString(), e); |
| 370 | } |
| 371 | } |
Sandra Kwan | 7881228 | 2015-11-04 11:19:47 -0800 | [diff] [blame] | 372 | |
| 373 | @Override |
| 374 | public void startAddAccountSession(IAccountAuthenticatorResponse response, |
| 375 | String accountType, String authTokenType, String[] features, Bundle options) |
| 376 | throws RemoteException { |
| 377 | if (Log.isLoggable(TAG, Log.VERBOSE)) { |
| 378 | Log.v(TAG, |
| 379 | "startAddAccountSession: accountType " + accountType |
| 380 | + ", authTokenType " + authTokenType |
| 381 | + ", features " + (features == null ? "[]" : Arrays.toString(features))); |
| 382 | } |
| 383 | checkBinderPermission(); |
| 384 | try { |
| 385 | final Bundle result = AbstractAccountAuthenticator.this.startAddAccountSession( |
| 386 | new AccountAuthenticatorResponse(response), accountType, authTokenType, |
| 387 | features, options); |
| 388 | if (Log.isLoggable(TAG, Log.VERBOSE)) { |
| 389 | if (result != null) { |
| 390 | result.keySet(); // force it to be unparcelled |
| 391 | } |
| 392 | Log.v(TAG, "startAddAccountSession: result " |
| 393 | + AccountManager.sanitizeResult(result)); |
| 394 | } |
| 395 | if (result != null) { |
| 396 | response.onResult(result); |
| 397 | } |
| 398 | } catch (Exception e) { |
| 399 | handleException(response, "startAddAccountSession", accountType, e); |
| 400 | } |
| 401 | } |
Sandra Kwan | e68c37e | 2015-11-12 17:11:49 -0800 | [diff] [blame] | 402 | |
| 403 | @Override |
| 404 | public void startUpdateCredentialsSession( |
| 405 | IAccountAuthenticatorResponse response, |
| 406 | Account account, |
| 407 | String authTokenType, |
| 408 | Bundle loginOptions) throws RemoteException { |
| 409 | if (Log.isLoggable(TAG, Log.VERBOSE)) { |
| 410 | Log.v(TAG, "startUpdateCredentialsSession: " |
| 411 | + account |
| 412 | + ", authTokenType " |
| 413 | + authTokenType); |
| 414 | } |
| 415 | checkBinderPermission(); |
| 416 | try { |
| 417 | final Bundle result = AbstractAccountAuthenticator.this |
| 418 | .startUpdateCredentialsSession( |
| 419 | new AccountAuthenticatorResponse(response), |
| 420 | account, |
| 421 | authTokenType, |
| 422 | loginOptions); |
| 423 | if (Log.isLoggable(TAG, Log.VERBOSE)) { |
| 424 | // Result may be null. |
| 425 | if (result != null) { |
| 426 | result.keySet(); // force it to be unparcelled |
| 427 | } |
| 428 | Log.v(TAG, "startUpdateCredentialsSession: result " |
| 429 | + AccountManager.sanitizeResult(result)); |
Sandra Kwan | 920f6ef | 2015-11-10 14:13:29 -0800 | [diff] [blame] | 430 | |
Sandra Kwan | e68c37e | 2015-11-12 17:11:49 -0800 | [diff] [blame] | 431 | } |
| 432 | if (result != null) { |
| 433 | response.onResult(result); |
| 434 | } |
| 435 | } catch (Exception e) { |
| 436 | handleException(response, "startUpdateCredentialsSession", |
| 437 | account.toString() + "," + authTokenType, e); |
Sandra Kwan | 920f6ef | 2015-11-10 14:13:29 -0800 | [diff] [blame] | 438 | |
| 439 | } |
| 440 | } |
| 441 | |
Sandra Kwan | 390c9d2 | 2016-01-12 14:13:37 -0800 | [diff] [blame] | 442 | @Override |
Sandra Kwan | 920f6ef | 2015-11-10 14:13:29 -0800 | [diff] [blame] | 443 | public void finishSession( |
| 444 | IAccountAuthenticatorResponse response, |
| 445 | String accountType, |
| 446 | Bundle sessionBundle) throws RemoteException { |
| 447 | if (Log.isLoggable(TAG, Log.VERBOSE)) { |
| 448 | Log.v(TAG, "finishSession: accountType " + accountType); |
| 449 | } |
| 450 | checkBinderPermission(); |
| 451 | try { |
| 452 | final Bundle result = AbstractAccountAuthenticator.this.finishSession( |
| 453 | new AccountAuthenticatorResponse(response), accountType, sessionBundle); |
| 454 | if (result != null) { |
| 455 | result.keySet(); // force it to be unparcelled |
| 456 | } |
| 457 | if (Log.isLoggable(TAG, Log.VERBOSE)) { |
| 458 | Log.v(TAG, "finishSession: result " + AccountManager.sanitizeResult(result)); |
| 459 | } |
| 460 | if (result != null) { |
| 461 | response.onResult(result); |
| 462 | } |
| 463 | } catch (Exception e) { |
| 464 | handleException(response, "finishSession", accountType, e); |
| 465 | |
Sandra Kwan | e68c37e | 2015-11-12 17:11:49 -0800 | [diff] [blame] | 466 | } |
| 467 | } |
Sandra Kwan | 390c9d2 | 2016-01-12 14:13:37 -0800 | [diff] [blame] | 468 | |
| 469 | @Override |
| 470 | public void isCredentialsUpdateSuggested( |
| 471 | IAccountAuthenticatorResponse response, |
| 472 | Account account, |
| 473 | String statusToken) throws RemoteException { |
| 474 | checkBinderPermission(); |
| 475 | try { |
| 476 | final Bundle result = AbstractAccountAuthenticator.this |
| 477 | .isCredentialsUpdateSuggested( |
| 478 | new AccountAuthenticatorResponse(response), account, statusToken); |
| 479 | if (result != null) { |
| 480 | response.onResult(result); |
| 481 | } |
| 482 | } catch (Exception e) { |
| 483 | handleException(response, "isCredentialsUpdateSuggested", account.toString(), e); |
| 484 | } |
| 485 | } |
Fred Quintana | 6030734 | 2009-03-24 22:48:12 -0700 | [diff] [blame] | 486 | } |
| 487 | |
Fred Quintana | 5d1a0c3 | 2011-06-23 16:37:58 -0700 | [diff] [blame] | 488 | private void handleException(IAccountAuthenticatorResponse response, String method, |
| 489 | String data, Exception e) throws RemoteException { |
| 490 | if (e instanceof NetworkErrorException) { |
| 491 | if (Log.isLoggable(TAG, Log.VERBOSE)) { |
| 492 | Log.v(TAG, method + "(" + data + ")", e); |
| 493 | } |
| 494 | response.onError(AccountManager.ERROR_CODE_NETWORK_ERROR, e.getMessage()); |
| 495 | } else if (e instanceof UnsupportedOperationException) { |
| 496 | if (Log.isLoggable(TAG, Log.VERBOSE)) { |
| 497 | Log.v(TAG, method + "(" + data + ")", e); |
| 498 | } |
| 499 | response.onError(AccountManager.ERROR_CODE_UNSUPPORTED_OPERATION, |
| 500 | method + " not supported"); |
| 501 | } else if (e instanceof IllegalArgumentException) { |
| 502 | if (Log.isLoggable(TAG, Log.VERBOSE)) { |
| 503 | Log.v(TAG, method + "(" + data + ")", e); |
| 504 | } |
| 505 | response.onError(AccountManager.ERROR_CODE_BAD_ARGUMENTS, |
| 506 | method + " not supported"); |
| 507 | } else { |
| 508 | Log.w(TAG, method + "(" + data + ")", e); |
| 509 | response.onError(AccountManager.ERROR_CODE_REMOTE_EXCEPTION, |
| 510 | method + " failed"); |
| 511 | } |
| 512 | } |
| 513 | |
Fred Quintana | d4a1d2e | 2009-07-16 16:36:38 -0700 | [diff] [blame] | 514 | private void checkBinderPermission() { |
| 515 | final int uid = Binder.getCallingUid(); |
Fred Quintana | f7ae77c | 2009-10-02 17:19:31 -0700 | [diff] [blame] | 516 | final String perm = Manifest.permission.ACCOUNT_MANAGER; |
Fred Quintana | d4a1d2e | 2009-07-16 16:36:38 -0700 | [diff] [blame] | 517 | if (mContext.checkCallingOrSelfPermission(perm) != PackageManager.PERMISSION_GRANTED) { |
| 518 | throw new SecurityException("caller uid " + uid + " lacks " + perm); |
| 519 | } |
| 520 | } |
| 521 | |
Fred Quintana | f7ae77c | 2009-10-02 17:19:31 -0700 | [diff] [blame] | 522 | private Transport mTransport = new Transport(); |
Fred Quintana | 6030734 | 2009-03-24 22:48:12 -0700 | [diff] [blame] | 523 | |
| 524 | /** |
Fred Quintana | f7ae77c | 2009-10-02 17:19:31 -0700 | [diff] [blame] | 525 | * @return the IBinder for the AccountAuthenticator |
Fred Quintana | 6030734 | 2009-03-24 22:48:12 -0700 | [diff] [blame] | 526 | */ |
Fred Quintana | f7ae77c | 2009-10-02 17:19:31 -0700 | [diff] [blame] | 527 | public final IBinder getIBinder() { |
| 528 | return mTransport.asBinder(); |
Fred Quintana | 6030734 | 2009-03-24 22:48:12 -0700 | [diff] [blame] | 529 | } |
| 530 | |
| 531 | /** |
Fred Quintana | a698f42 | 2009-04-08 19:14:54 -0700 | [diff] [blame] | 532 | * Returns a Bundle that contains the Intent of the activity that can be used to edit the |
| 533 | * properties. In order to indicate success the activity should call response.setResult() |
| 534 | * with a non-null Bundle. |
| 535 | * @param response used to set the result for the request. If the Constants.INTENT_KEY |
| 536 | * is set in the bundle then this response field is to be used for sending future |
| 537 | * results if and when the Intent is started. |
| 538 | * @param accountType the AccountType whose properties are to be edited. |
| 539 | * @return a Bundle containing the result or the Intent to start to continue the request. |
| 540 | * If this is null then the request is considered to still be active and the result should |
| 541 | * sent later using response. |
Fred Quintana | 6030734 | 2009-03-24 22:48:12 -0700 | [diff] [blame] | 542 | */ |
Fred Quintana | a698f42 | 2009-04-08 19:14:54 -0700 | [diff] [blame] | 543 | public abstract Bundle editProperties(AccountAuthenticatorResponse response, |
| 544 | String accountType); |
Fred Quintana | 756b735 | 2009-10-21 13:43:10 -0700 | [diff] [blame] | 545 | |
| 546 | /** |
| 547 | * Adds an account of the specified accountType. |
| 548 | * @param response to send the result back to the AccountManager, will never be null |
| 549 | * @param accountType the type of account to add, will never be null |
| 550 | * @param authTokenType the type of auth token to retrieve after adding the account, may be null |
| 551 | * @param requiredFeatures a String array of authenticator-specific features that the added |
| 552 | * account must support, may be null |
sunjian | 87d0c3c | 2017-07-14 11:54:46 -0700 | [diff] [blame] | 553 | * @param options a Bundle of authenticator-specific options. It always contains |
| 554 | * {@link AccountManager#KEY_CALLER_PID} and {@link AccountManager#KEY_CALLER_UID} |
| 555 | * fields which will let authenticator know the identity of the caller. |
Fred Quintana | 756b735 | 2009-10-21 13:43:10 -0700 | [diff] [blame] | 556 | * @return a Bundle result or null if the result is to be returned via the response. The result |
| 557 | * will contain either: |
| 558 | * <ul> |
| 559 | * <li> {@link AccountManager#KEY_INTENT}, or |
| 560 | * <li> {@link AccountManager#KEY_ACCOUNT_NAME} and {@link AccountManager#KEY_ACCOUNT_TYPE} of |
Fred Quintana | 8570f74 | 2010-02-18 10:32:54 -0800 | [diff] [blame] | 561 | * the account that was added, or |
Fred Quintana | 756b735 | 2009-10-21 13:43:10 -0700 | [diff] [blame] | 562 | * <li> {@link AccountManager#KEY_ERROR_CODE} and {@link AccountManager#KEY_ERROR_MESSAGE} to |
| 563 | * indicate an error |
| 564 | * </ul> |
| 565 | * @throws NetworkErrorException if the authenticator could not honor the request due to a |
| 566 | * network error |
| 567 | */ |
Fred Quintana | a698f42 | 2009-04-08 19:14:54 -0700 | [diff] [blame] | 568 | public abstract Bundle addAccount(AccountAuthenticatorResponse response, String accountType, |
Fred Quintana | 3326920 | 2009-04-20 16:05:10 -0700 | [diff] [blame] | 569 | String authTokenType, String[] requiredFeatures, Bundle options) |
| 570 | throws NetworkErrorException; |
Fred Quintana | 756b735 | 2009-10-21 13:43:10 -0700 | [diff] [blame] | 571 | |
| 572 | /** |
| 573 | * Checks that the user knows the credentials of an account. |
| 574 | * @param response to send the result back to the AccountManager, will never be null |
| 575 | * @param account the account whose credentials are to be checked, will never be null |
| 576 | * @param options a Bundle of authenticator-specific options, may be null |
| 577 | * @return a Bundle result or null if the result is to be returned via the response. The result |
| 578 | * will contain either: |
| 579 | * <ul> |
| 580 | * <li> {@link AccountManager#KEY_INTENT}, or |
| 581 | * <li> {@link AccountManager#KEY_BOOLEAN_RESULT}, true if the check succeeded, false otherwise |
| 582 | * <li> {@link AccountManager#KEY_ERROR_CODE} and {@link AccountManager#KEY_ERROR_MESSAGE} to |
| 583 | * indicate an error |
| 584 | * </ul> |
Fred Quintana | 31957f1 | 2009-10-21 13:43:10 -0700 | [diff] [blame] | 585 | * @throws NetworkErrorException if the authenticator could not honor the request due to a |
| 586 | * network error |
Fred Quintana | 756b735 | 2009-10-21 13:43:10 -0700 | [diff] [blame] | 587 | */ |
Fred Quintana | a698f42 | 2009-04-08 19:14:54 -0700 | [diff] [blame] | 588 | public abstract Bundle confirmCredentials(AccountAuthenticatorResponse response, |
Fred Quintana | 31957f1 | 2009-10-21 13:43:10 -0700 | [diff] [blame] | 589 | Account account, Bundle options) |
| 590 | throws NetworkErrorException; |
Carlos Valdivia | 91979be | 2015-05-22 14:11:35 -0700 | [diff] [blame] | 591 | |
Fred Quintana | 756b735 | 2009-10-21 13:43:10 -0700 | [diff] [blame] | 592 | /** |
Carlos Valdivia | 91979be | 2015-05-22 14:11:35 -0700 | [diff] [blame] | 593 | * Gets an authtoken for an account. |
| 594 | * |
| 595 | * If not {@code null}, the resultant {@link Bundle} will contain different sets of keys |
| 596 | * depending on whether a token was successfully issued and, if not, whether one |
| 597 | * could be issued via some {@link android.app.Activity}. |
| 598 | * <p> |
| 599 | * If a token cannot be provided without some additional activity, the Bundle should contain |
| 600 | * {@link AccountManager#KEY_INTENT} with an associated {@link Intent}. On the other hand, if |
| 601 | * there is no such activity, then a Bundle containing |
| 602 | * {@link AccountManager#KEY_ERROR_CODE} and {@link AccountManager#KEY_ERROR_MESSAGE} should be |
| 603 | * returned. |
| 604 | * <p> |
| 605 | * If a token can be successfully issued, the implementation should return the |
| 606 | * {@link AccountManager#KEY_ACCOUNT_NAME} and {@link AccountManager#KEY_ACCOUNT_TYPE} of the |
| 607 | * account associated with the token as well as the {@link AccountManager#KEY_AUTHTOKEN}. In |
| 608 | * addition {@link AbstractAccountAuthenticator} implementations that declare themselves |
| 609 | * {@code android:customTokens=true} may also provide a non-negative {@link |
| 610 | * #KEY_CUSTOM_TOKEN_EXPIRY} long value containing the expiration timestamp of the expiration |
sunjian | 87d0c3c | 2017-07-14 11:54:46 -0700 | [diff] [blame] | 611 | * time (in millis since the unix epoch), tokens will be cached in memory based on |
| 612 | * application's packageName/signature for however long that was specified. |
Carlos Valdivia | 91979be | 2015-05-22 14:11:35 -0700 | [diff] [blame] | 613 | * <p> |
| 614 | * Implementers should assume that tokens will be cached on the basis of account and |
| 615 | * authTokenType. The system may ignore the contents of the supplied options Bundle when |
| 616 | * determining to re-use a cached token. Furthermore, implementers should assume a supplied |
| 617 | * expiration time will be treated as non-binding advice. |
| 618 | * <p> |
sunjian | 87d0c3c | 2017-07-14 11:54:46 -0700 | [diff] [blame] | 619 | * Finally, note that for {@code android:customTokens=false} authenticators, tokens are cached |
Carlos Valdivia | 91979be | 2015-05-22 14:11:35 -0700 | [diff] [blame] | 620 | * indefinitely until some client calls {@link |
| 621 | * AccountManager#invalidateAuthToken(String,String)}. |
| 622 | * |
Fred Quintana | 756b735 | 2009-10-21 13:43:10 -0700 | [diff] [blame] | 623 | * @param response to send the result back to the AccountManager, will never be null |
| 624 | * @param account the account whose credentials are to be retrieved, will never be null |
| 625 | * @param authTokenType the type of auth token to retrieve, will never be null |
sunjian | 87d0c3c | 2017-07-14 11:54:46 -0700 | [diff] [blame] | 626 | * @param options a Bundle of authenticator-specific options. It always contains |
| 627 | * {@link AccountManager#KEY_CALLER_PID} and {@link AccountManager#KEY_CALLER_UID} |
| 628 | * fields which will let authenticator know the identity of the caller. |
Carlos Valdivia | 91979be | 2015-05-22 14:11:35 -0700 | [diff] [blame] | 629 | * @return a Bundle result or null if the result is to be returned via the response. |
Fred Quintana | 756b735 | 2009-10-21 13:43:10 -0700 | [diff] [blame] | 630 | * @throws NetworkErrorException if the authenticator could not honor the request due to a |
| 631 | * network error |
| 632 | */ |
Fred Quintana | a698f42 | 2009-04-08 19:14:54 -0700 | [diff] [blame] | 633 | public abstract Bundle getAuthToken(AccountAuthenticatorResponse response, |
Fred Quintana | 31957f1 | 2009-10-21 13:43:10 -0700 | [diff] [blame] | 634 | Account account, String authTokenType, Bundle options) |
Fred Quintana | a698f42 | 2009-04-08 19:14:54 -0700 | [diff] [blame] | 635 | throws NetworkErrorException; |
Fred Quintana | 756b735 | 2009-10-21 13:43:10 -0700 | [diff] [blame] | 636 | |
| 637 | /** |
| 638 | * Ask the authenticator for a localized label for the given authTokenType. |
| 639 | * @param authTokenType the authTokenType whose label is to be returned, will never be null |
| 640 | * @return the localized label of the auth token type, may be null if the type isn't known |
| 641 | */ |
Fred Quintana | d4a1d2e | 2009-07-16 16:36:38 -0700 | [diff] [blame] | 642 | public abstract String getAuthTokenLabel(String authTokenType); |
Fred Quintana | 756b735 | 2009-10-21 13:43:10 -0700 | [diff] [blame] | 643 | |
| 644 | /** |
| 645 | * Update the locally stored credentials for an account. |
| 646 | * @param response to send the result back to the AccountManager, will never be null |
| 647 | * @param account the account whose credentials are to be updated, will never be null |
| 648 | * @param authTokenType the type of auth token to retrieve after updating the credentials, |
| 649 | * may be null |
Fred Quintana | 31957f1 | 2009-10-21 13:43:10 -0700 | [diff] [blame] | 650 | * @param options a Bundle of authenticator-specific options, may be null |
Fred Quintana | 756b735 | 2009-10-21 13:43:10 -0700 | [diff] [blame] | 651 | * @return a Bundle result or null if the result is to be returned via the response. The result |
| 652 | * will contain either: |
| 653 | * <ul> |
| 654 | * <li> {@link AccountManager#KEY_INTENT}, or |
| 655 | * <li> {@link AccountManager#KEY_ACCOUNT_NAME} and {@link AccountManager#KEY_ACCOUNT_TYPE} of |
Ian Pedowitz | 6cc066d | 2015-08-05 14:23:43 +0000 | [diff] [blame] | 656 | * the account whose credentials were updated, or |
Fred Quintana | 756b735 | 2009-10-21 13:43:10 -0700 | [diff] [blame] | 657 | * <li> {@link AccountManager#KEY_ERROR_CODE} and {@link AccountManager#KEY_ERROR_MESSAGE} to |
| 658 | * indicate an error |
| 659 | * </ul> |
Fred Quintana | 31957f1 | 2009-10-21 13:43:10 -0700 | [diff] [blame] | 660 | * @throws NetworkErrorException if the authenticator could not honor the request due to a |
| 661 | * network error |
Fred Quintana | 756b735 | 2009-10-21 13:43:10 -0700 | [diff] [blame] | 662 | */ |
Fred Quintana | a698f42 | 2009-04-08 19:14:54 -0700 | [diff] [blame] | 663 | public abstract Bundle updateCredentials(AccountAuthenticatorResponse response, |
Fred Quintana | 31957f1 | 2009-10-21 13:43:10 -0700 | [diff] [blame] | 664 | Account account, String authTokenType, Bundle options) throws NetworkErrorException; |
Fred Quintana | 8570f74 | 2010-02-18 10:32:54 -0800 | [diff] [blame] | 665 | |
Fred Quintana | 756b735 | 2009-10-21 13:43:10 -0700 | [diff] [blame] | 666 | /** |
| 667 | * Checks if the account supports all the specified authenticator specific features. |
| 668 | * @param response to send the result back to the AccountManager, will never be null |
| 669 | * @param account the account to check, will never be null |
| 670 | * @param features an array of features to check, will never be null |
| 671 | * @return a Bundle result or null if the result is to be returned via the response. The result |
| 672 | * will contain either: |
| 673 | * <ul> |
| 674 | * <li> {@link AccountManager#KEY_INTENT}, or |
| 675 | * <li> {@link AccountManager#KEY_BOOLEAN_RESULT}, true if the account has all the features, |
| 676 | * false otherwise |
| 677 | * <li> {@link AccountManager#KEY_ERROR_CODE} and {@link AccountManager#KEY_ERROR_MESSAGE} to |
| 678 | * indicate an error |
| 679 | * </ul> |
| 680 | * @throws NetworkErrorException if the authenticator could not honor the request due to a |
| 681 | * network error |
| 682 | */ |
Fred Quintana | 3326920 | 2009-04-20 16:05:10 -0700 | [diff] [blame] | 683 | public abstract Bundle hasFeatures(AccountAuthenticatorResponse response, |
| 684 | Account account, String[] features) throws NetworkErrorException; |
Fred Quintana | 756b735 | 2009-10-21 13:43:10 -0700 | [diff] [blame] | 685 | |
| 686 | /** |
| 687 | * Checks if the removal of this account is allowed. |
| 688 | * @param response to send the result back to the AccountManager, will never be null |
| 689 | * @param account the account to check, will never be null |
| 690 | * @return a Bundle result or null if the result is to be returned via the response. The result |
| 691 | * will contain either: |
| 692 | * <ul> |
| 693 | * <li> {@link AccountManager#KEY_INTENT}, or |
| 694 | * <li> {@link AccountManager#KEY_BOOLEAN_RESULT}, true if the removal of the account is |
| 695 | * allowed, false otherwise |
| 696 | * <li> {@link AccountManager#KEY_ERROR_CODE} and {@link AccountManager#KEY_ERROR_MESSAGE} to |
| 697 | * indicate an error |
| 698 | * </ul> |
| 699 | * @throws NetworkErrorException if the authenticator could not honor the request due to a |
| 700 | * network error |
| 701 | */ |
Fred Quintana | ffd0cb04 | 2009-08-15 21:45:26 -0700 | [diff] [blame] | 702 | public Bundle getAccountRemovalAllowed(AccountAuthenticatorResponse response, |
| 703 | Account account) throws NetworkErrorException { |
| 704 | final Bundle result = new Bundle(); |
Fred Quintana | f7ae77c | 2009-10-02 17:19:31 -0700 | [diff] [blame] | 705 | result.putBoolean(AccountManager.KEY_BOOLEAN_RESULT, true); |
Fred Quintana | ffd0cb04 | 2009-08-15 21:45:26 -0700 | [diff] [blame] | 706 | return result; |
| 707 | } |
Amith Yamasani | 67df64b | 2012-12-14 12:09:36 -0800 | [diff] [blame] | 708 | |
| 709 | /** |
Amith Yamasani | 67df64b | 2012-12-14 12:09:36 -0800 | [diff] [blame] | 710 | * Returns a Bundle that contains whatever is required to clone the account on a different |
| 711 | * user. The Bundle is passed to the authenticator instance in the target user via |
| 712 | * {@link #addAccountFromCredentials(AccountAuthenticatorResponse, Account, Bundle)}. |
| 713 | * The default implementation returns null, indicating that cloning is not supported. |
| 714 | * @param response to send the result back to the AccountManager, will never be null |
| 715 | * @param account the account to clone, will never be null |
| 716 | * @return a Bundle result or null if the result is to be returned via the response. |
| 717 | * @throws NetworkErrorException |
Elliot Waite | 54de774 | 2017-01-11 15:30:35 -0800 | [diff] [blame] | 718 | * @see #addAccountFromCredentials(AccountAuthenticatorResponse, Account, Bundle) |
Amith Yamasani | 67df64b | 2012-12-14 12:09:36 -0800 | [diff] [blame] | 719 | */ |
| 720 | public Bundle getAccountCredentialsForCloning(final AccountAuthenticatorResponse response, |
| 721 | final Account account) throws NetworkErrorException { |
| 722 | new Thread(new Runnable() { |
Carlos Valdivia | 91979be | 2015-05-22 14:11:35 -0700 | [diff] [blame] | 723 | @Override |
Amith Yamasani | 67df64b | 2012-12-14 12:09:36 -0800 | [diff] [blame] | 724 | public void run() { |
| 725 | Bundle result = new Bundle(); |
| 726 | result.putBoolean(AccountManager.KEY_BOOLEAN_RESULT, false); |
| 727 | response.onResult(result); |
| 728 | } |
| 729 | }).start(); |
| 730 | return null; |
| 731 | } |
| 732 | |
| 733 | /** |
Amith Yamasani | 67df64b | 2012-12-14 12:09:36 -0800 | [diff] [blame] | 734 | * Creates an account based on credentials provided by the authenticator instance of another |
| 735 | * user on the device, who has chosen to share the account with this user. |
| 736 | * @param response to send the result back to the AccountManager, will never be null |
| 737 | * @param account the account to clone, will never be null |
| 738 | * @param accountCredentials the Bundle containing the required credentials to create the |
| 739 | * account. Contents of the Bundle are only meaningful to the authenticator. This Bundle is |
| 740 | * provided by {@link #getAccountCredentialsForCloning(AccountAuthenticatorResponse, Account)}. |
| 741 | * @return a Bundle result or null if the result is to be returned via the response. |
| 742 | * @throws NetworkErrorException |
Elliot Waite | 54de774 | 2017-01-11 15:30:35 -0800 | [diff] [blame] | 743 | * @see #getAccountCredentialsForCloning(AccountAuthenticatorResponse, Account) |
Amith Yamasani | 67df64b | 2012-12-14 12:09:36 -0800 | [diff] [blame] | 744 | */ |
| 745 | public Bundle addAccountFromCredentials(final AccountAuthenticatorResponse response, |
| 746 | Account account, |
| 747 | Bundle accountCredentials) throws NetworkErrorException { |
| 748 | new Thread(new Runnable() { |
Carlos Valdivia | 91979be | 2015-05-22 14:11:35 -0700 | [diff] [blame] | 749 | @Override |
Amith Yamasani | 67df64b | 2012-12-14 12:09:36 -0800 | [diff] [blame] | 750 | public void run() { |
| 751 | Bundle result = new Bundle(); |
| 752 | result.putBoolean(AccountManager.KEY_BOOLEAN_RESULT, false); |
| 753 | response.onResult(result); |
| 754 | } |
| 755 | }).start(); |
| 756 | return null; |
| 757 | } |
Sandra Kwan | 7881228 | 2015-11-04 11:19:47 -0800 | [diff] [blame] | 758 | |
| 759 | /** |
| 760 | * Starts the add account session to authenticate user to an account of the |
Sandra Kwan | 920f6ef | 2015-11-10 14:13:29 -0800 | [diff] [blame] | 761 | * specified accountType. No file I/O should be performed in this call. |
| 762 | * Account should be added to device only when {@link #finishSession} is |
| 763 | * called after this. |
| 764 | * <p> |
| 765 | * Note: when overriding this method, {@link #finishSession} should be |
| 766 | * overridden too. |
| 767 | * </p> |
Sandra Kwan | 7881228 | 2015-11-04 11:19:47 -0800 | [diff] [blame] | 768 | * |
| 769 | * @param response to send the result back to the AccountManager, will never |
| 770 | * be null |
| 771 | * @param accountType the type of account to authenticate with, will never |
| 772 | * be null |
| 773 | * @param authTokenType the type of auth token to retrieve after |
| 774 | * authenticating with the account, may be null |
| 775 | * @param requiredFeatures a String array of authenticator-specific features |
| 776 | * that the account authenticated with must support, may be null |
| 777 | * @param options a Bundle of authenticator-specific options, may be null |
| 778 | * @return a Bundle result or null if the result is to be returned via the |
| 779 | * response. The result will contain either: |
| 780 | * <ul> |
| 781 | * <li>{@link AccountManager#KEY_INTENT}, or |
| 782 | * <li>{@link AccountManager#KEY_ACCOUNT_SESSION_BUNDLE} for adding |
| 783 | * the account to device later, and if account is authenticated, |
| 784 | * optional {@link AccountManager#KEY_PASSWORD} and |
| 785 | * {@link AccountManager#KEY_ACCOUNT_STATUS_TOKEN} for checking the |
| 786 | * status of the account, or |
| 787 | * <li>{@link AccountManager#KEY_ERROR_CODE} and |
| 788 | * {@link AccountManager#KEY_ERROR_MESSAGE} to indicate an error |
| 789 | * </ul> |
| 790 | * @throws NetworkErrorException if the authenticator could not honor the |
| 791 | * request due to a network error |
Sandra Kwan | 920f6ef | 2015-11-10 14:13:29 -0800 | [diff] [blame] | 792 | * @see #finishSession(AccountAuthenticatorResponse, String, Bundle) |
Sandra Kwan | 7881228 | 2015-11-04 11:19:47 -0800 | [diff] [blame] | 793 | */ |
Sandra Kwan | 920f6ef | 2015-11-10 14:13:29 -0800 | [diff] [blame] | 794 | public Bundle startAddAccountSession( |
| 795 | final AccountAuthenticatorResponse response, |
| 796 | final String accountType, |
| 797 | final String authTokenType, |
| 798 | final String[] requiredFeatures, |
Sandra Kwan | 7881228 | 2015-11-04 11:19:47 -0800 | [diff] [blame] | 799 | final Bundle options) |
| 800 | throws NetworkErrorException { |
| 801 | new Thread(new Runnable() { |
| 802 | @Override |
| 803 | public void run() { |
| 804 | Bundle sessionBundle = new Bundle(); |
| 805 | sessionBundle.putString(KEY_AUTH_TOKEN_TYPE, authTokenType); |
| 806 | sessionBundle.putStringArray(KEY_REQUIRED_FEATURES, requiredFeatures); |
| 807 | sessionBundle.putBundle(KEY_OPTIONS, options); |
| 808 | Bundle result = new Bundle(); |
| 809 | result.putBundle(AccountManager.KEY_ACCOUNT_SESSION_BUNDLE, sessionBundle); |
| 810 | response.onResult(result); |
| 811 | } |
| 812 | |
| 813 | }).start(); |
| 814 | return null; |
| 815 | } |
Sandra Kwan | e68c37e | 2015-11-12 17:11:49 -0800 | [diff] [blame] | 816 | |
| 817 | /** |
Sandra Kwan | 920f6ef | 2015-11-10 14:13:29 -0800 | [diff] [blame] | 818 | * Asks user to re-authenticate for an account but defers updating the |
| 819 | * locally stored credentials. No file I/O should be performed in this call. |
| 820 | * Local credentials should be updated only when {@link #finishSession} is |
| 821 | * called after this. |
| 822 | * <p> |
| 823 | * Note: when overriding this method, {@link #finishSession} should be |
| 824 | * overridden too. |
| 825 | * </p> |
Sandra Kwan | e68c37e | 2015-11-12 17:11:49 -0800 | [diff] [blame] | 826 | * |
| 827 | * @param response to send the result back to the AccountManager, will never |
| 828 | * be null |
| 829 | * @param account the account whose credentials are to be updated, will |
| 830 | * never be null |
| 831 | * @param authTokenType the type of auth token to retrieve after updating |
Sandra Kwan | 920f6ef | 2015-11-10 14:13:29 -0800 | [diff] [blame] | 832 | * the credentials, may be null |
Sandra Kwan | e68c37e | 2015-11-12 17:11:49 -0800 | [diff] [blame] | 833 | * @param options a Bundle of authenticator-specific options, may be null |
| 834 | * @return a Bundle result or null if the result is to be returned via the |
| 835 | * response. The result will contain either: |
| 836 | * <ul> |
| 837 | * <li>{@link AccountManager#KEY_INTENT}, or |
Sandra Kwan | 920f6ef | 2015-11-10 14:13:29 -0800 | [diff] [blame] | 838 | * <li>{@link AccountManager#KEY_ACCOUNT_SESSION_BUNDLE} for |
| 839 | * updating the locally stored credentials later, and if account is |
| 840 | * re-authenticated, optional {@link AccountManager#KEY_PASSWORD} |
| 841 | * and {@link AccountManager#KEY_ACCOUNT_STATUS_TOKEN} for checking |
| 842 | * the status of the account later, or |
Sandra Kwan | e68c37e | 2015-11-12 17:11:49 -0800 | [diff] [blame] | 843 | * <li>{@link AccountManager#KEY_ERROR_CODE} and |
| 844 | * {@link AccountManager#KEY_ERROR_MESSAGE} to indicate an error |
| 845 | * </ul> |
| 846 | * @throws NetworkErrorException if the authenticator could not honor the |
| 847 | * request due to a network error |
Sandra Kwan | 920f6ef | 2015-11-10 14:13:29 -0800 | [diff] [blame] | 848 | * @see #finishSession(AccountAuthenticatorResponse, String, Bundle) |
Sandra Kwan | e68c37e | 2015-11-12 17:11:49 -0800 | [diff] [blame] | 849 | */ |
Sandra Kwan | 920f6ef | 2015-11-10 14:13:29 -0800 | [diff] [blame] | 850 | public Bundle startUpdateCredentialsSession( |
| 851 | final AccountAuthenticatorResponse response, |
| 852 | final Account account, |
| 853 | final String authTokenType, |
| 854 | final Bundle options) throws NetworkErrorException { |
Sandra Kwan | e68c37e | 2015-11-12 17:11:49 -0800 | [diff] [blame] | 855 | new Thread(new Runnable() { |
| 856 | @Override |
| 857 | public void run() { |
| 858 | Bundle sessionBundle = new Bundle(); |
| 859 | sessionBundle.putString(KEY_AUTH_TOKEN_TYPE, authTokenType); |
| 860 | sessionBundle.putParcelable(KEY_ACCOUNT, account); |
| 861 | sessionBundle.putBundle(KEY_OPTIONS, options); |
| 862 | Bundle result = new Bundle(); |
| 863 | result.putBundle(AccountManager.KEY_ACCOUNT_SESSION_BUNDLE, sessionBundle); |
| 864 | response.onResult(result); |
| 865 | } |
| 866 | |
| 867 | }).start(); |
| 868 | return null; |
| 869 | } |
Sandra Kwan | 920f6ef | 2015-11-10 14:13:29 -0800 | [diff] [blame] | 870 | |
| 871 | /** |
| 872 | * Finishes the session started by #startAddAccountSession or |
| 873 | * #startUpdateCredentials by installing the account to device with |
| 874 | * AccountManager, or updating the local credentials. File I/O may be |
| 875 | * performed in this call. |
| 876 | * <p> |
| 877 | * Note: when overriding this method, {@link #startAddAccountSession} and |
| 878 | * {@link #startUpdateCredentialsSession} should be overridden too. |
| 879 | * </p> |
| 880 | * |
| 881 | * @param response to send the result back to the AccountManager, will never |
| 882 | * be null |
| 883 | * @param accountType the type of account to authenticate with, will never |
| 884 | * be null |
| 885 | * @param sessionBundle a bundle of session data created by |
| 886 | * {@link #startAddAccountSession} used for adding account to |
| 887 | * device, or by {@link #startUpdateCredentialsSession} used for |
| 888 | * updating local credentials. |
| 889 | * @return a Bundle result or null if the result is to be returned via the |
| 890 | * response. The result will contain either: |
| 891 | * <ul> |
| 892 | * <li>{@link AccountManager#KEY_INTENT}, or |
| 893 | * <li>{@link AccountManager#KEY_ACCOUNT_NAME} and |
| 894 | * {@link AccountManager#KEY_ACCOUNT_TYPE} of the account that was |
Hongming Jin | 8b44275 | 2016-06-26 10:36:21 -0700 | [diff] [blame] | 895 | * added or local credentials were updated, and optional |
| 896 | * {@link AccountManager#KEY_ACCOUNT_STATUS_TOKEN} for checking |
| 897 | * the status of the account later, or |
Sandra Kwan | 920f6ef | 2015-11-10 14:13:29 -0800 | [diff] [blame] | 898 | * <li>{@link AccountManager#KEY_ERROR_CODE} and |
| 899 | * {@link AccountManager#KEY_ERROR_MESSAGE} to indicate an error |
| 900 | * </ul> |
Sandra Kwan | 390c9d2 | 2016-01-12 14:13:37 -0800 | [diff] [blame] | 901 | * @throws NetworkErrorException if the authenticator could not honor the request due to a |
| 902 | * network error |
Sandra Kwan | 920f6ef | 2015-11-10 14:13:29 -0800 | [diff] [blame] | 903 | * @see #startAddAccountSession and #startUpdateCredentialsSession |
| 904 | */ |
| 905 | public Bundle finishSession( |
| 906 | final AccountAuthenticatorResponse response, |
| 907 | final String accountType, |
| 908 | final Bundle sessionBundle) throws NetworkErrorException { |
| 909 | if (TextUtils.isEmpty(accountType)) { |
| 910 | Log.e(TAG, "Account type cannot be empty."); |
| 911 | Bundle result = new Bundle(); |
| 912 | result.putInt(AccountManager.KEY_ERROR_CODE, AccountManager.ERROR_CODE_BAD_ARGUMENTS); |
| 913 | result.putString(AccountManager.KEY_ERROR_MESSAGE, |
| 914 | "accountType cannot be empty."); |
| 915 | return result; |
| 916 | } |
| 917 | |
| 918 | if (sessionBundle == null) { |
| 919 | Log.e(TAG, "Session bundle cannot be null."); |
| 920 | Bundle result = new Bundle(); |
| 921 | result.putInt(AccountManager.KEY_ERROR_CODE, AccountManager.ERROR_CODE_BAD_ARGUMENTS); |
| 922 | result.putString(AccountManager.KEY_ERROR_MESSAGE, |
| 923 | "sessionBundle cannot be null."); |
| 924 | return result; |
| 925 | } |
| 926 | |
| 927 | if (!sessionBundle.containsKey(KEY_AUTH_TOKEN_TYPE)) { |
| 928 | // We cannot handle Session bundle not created by default startAddAccountSession(...) |
| 929 | // nor startUpdateCredentialsSession(...) implementation. Return error. |
| 930 | Bundle result = new Bundle(); |
| 931 | result.putInt(AccountManager.KEY_ERROR_CODE, |
| 932 | AccountManager.ERROR_CODE_UNSUPPORTED_OPERATION); |
| 933 | result.putString(AccountManager.KEY_ERROR_MESSAGE, |
| 934 | "Authenticator must override finishSession if startAddAccountSession" |
| 935 | + " or startUpdateCredentialsSession is overridden."); |
| 936 | response.onResult(result); |
| 937 | return result; |
| 938 | } |
| 939 | String authTokenType = sessionBundle.getString(KEY_AUTH_TOKEN_TYPE); |
| 940 | Bundle options = sessionBundle.getBundle(KEY_OPTIONS); |
| 941 | String[] requiredFeatures = sessionBundle.getStringArray(KEY_REQUIRED_FEATURES); |
| 942 | Account account = sessionBundle.getParcelable(KEY_ACCOUNT); |
| 943 | boolean containsKeyAccount = sessionBundle.containsKey(KEY_ACCOUNT); |
| 944 | |
| 945 | // Actual options passed to add account or update credentials flow. |
| 946 | Bundle sessionOptions = new Bundle(sessionBundle); |
| 947 | // Remove redundant extras in session bundle before passing it to addAccount(...) or |
| 948 | // updateCredentials(...). |
| 949 | sessionOptions.remove(KEY_AUTH_TOKEN_TYPE); |
| 950 | sessionOptions.remove(KEY_REQUIRED_FEATURES); |
| 951 | sessionOptions.remove(KEY_OPTIONS); |
| 952 | sessionOptions.remove(KEY_ACCOUNT); |
| 953 | |
| 954 | if (options != null) { |
| 955 | // options may contains old system info such as |
| 956 | // AccountManager.KEY_ANDROID_PACKAGE_NAME required by the add account flow or update |
| 957 | // credentials flow, we should replace with the new values of the current call added |
| 958 | // to sessionBundle by AccountManager or AccountManagerService. |
| 959 | options.putAll(sessionOptions); |
| 960 | sessionOptions = options; |
| 961 | } |
| 962 | |
| 963 | // Session bundle created by startUpdateCredentialsSession default implementation should |
| 964 | // contain KEY_ACCOUNT. |
| 965 | if (containsKeyAccount) { |
| 966 | return updateCredentials(response, account, authTokenType, options); |
| 967 | } |
| 968 | // Otherwise, session bundle was created by startAddAccountSession default implementation. |
| 969 | return addAccount(response, accountType, authTokenType, requiredFeatures, sessionOptions); |
| 970 | } |
Sandra Kwan | 390c9d2 | 2016-01-12 14:13:37 -0800 | [diff] [blame] | 971 | |
| 972 | /** |
| 973 | * Checks if update of the account credentials is suggested. |
| 974 | * |
| 975 | * @param response to send the result back to the AccountManager, will never be null. |
| 976 | * @param account the account to check, will never be null |
| 977 | * @param statusToken a String of token to check if update of credentials is suggested. |
| 978 | * @return a Bundle result or null if the result is to be returned via the response. The result |
| 979 | * will contain either: |
| 980 | * <ul> |
| 981 | * <li>{@link AccountManager#KEY_BOOLEAN_RESULT}, true if update of account's |
| 982 | * credentials is suggested, false otherwise |
| 983 | * <li>{@link AccountManager#KEY_ERROR_CODE} and |
| 984 | * {@link AccountManager#KEY_ERROR_MESSAGE} to indicate an error |
| 985 | * </ul> |
| 986 | * @throws NetworkErrorException if the authenticator could not honor the request due to a |
| 987 | * network error |
Sandra Kwan | 390c9d2 | 2016-01-12 14:13:37 -0800 | [diff] [blame] | 988 | */ |
Sandra Kwan | 390c9d2 | 2016-01-12 14:13:37 -0800 | [diff] [blame] | 989 | public Bundle isCredentialsUpdateSuggested( |
| 990 | final AccountAuthenticatorResponse response, |
| 991 | Account account, |
| 992 | String statusToken) throws NetworkErrorException { |
| 993 | Bundle result = new Bundle(); |
| 994 | result.putBoolean(AccountManager.KEY_BOOLEAN_RESULT, false); |
| 995 | return result; |
| 996 | } |
Fred Quintana | 6030734 | 2009-03-24 22:48:12 -0700 | [diff] [blame] | 997 | } |