blob: 8bc7428a6fa827c5d807b4dc22e150d51bbeb766 [file] [log] [blame]
Fred Quintana60307342009-03-24 22:48:12 -07001/*
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
17package android.accounts;
18
Fred Quintanaa698f422009-04-08 19:14:54 -070019import android.os.Bundle;
Fred Quintana60307342009-03-24 22:48:12 -070020import android.os.RemoteException;
Fred Quintanad4a1d2e2009-07-16 16:36:38 -070021import android.os.Binder;
Fred Quintanaf7ae77c2009-10-02 17:19:31 -070022import android.os.IBinder;
Fred Quintanad4a1d2e2009-07-16 16:36:38 -070023import android.content.pm.PackageManager;
24import android.content.Context;
Fred Quintanaf7ae77c2009-10-02 17:19:31 -070025import android.content.Intent;
Fred Quintanad4a1d2e2009-07-16 16:36:38 -070026import android.Manifest;
Fred Quintana60307342009-03-24 22:48:12 -070027
28/**
Fred Quintana756b7352009-10-21 13:43:10 -070029 * Abstract base class for creating AccountAuthenticators.
30 * In order to be an authenticator one must extend this class, provider implementations for the
31 * abstract methods and write a service that returns the result of {@link #getIBinder()}
32 * in the service's {@link android.app.Service#onBind(android.content.Intent)} when invoked
33 * with an intent with action {@link AccountManager#ACTION_AUTHENTICATOR_INTENT}. This service
34 * must specify the following intent filter and metadata tags in its AndroidManifest.xml file
35 * <pre>
36 * &lt;intent-filter&gt;
37 * &lt;action android:name="android.accounts.AccountAuthenticator" /&gt;
38 * &lt;/intent-filter&gt;
39 * &lt;meta-data android:name="android.accounts.AccountAuthenticator"
40 * android:resource="@xml/authenticator" /&gt;
41 * </pre>
42 * The <code>android:resource</code> attribute must point to a resource that looks like:
43 * <pre>
44 * &lt;account-authenticator xmlns:android="http://schemas.android.com/apk/res/android"
45 * android:accountType="typeOfAuthenticator"
46 * android:icon="@drawable/icon"
47 * android:smallIcon="@drawable/miniIcon"
48 * android:label="@string/label"
49 * android:accountPreferences="@xml/account_preferences"
50 * /&gt;
51 * </pre>
52 * Replace the icons and labels with your own resources. The <code>android:accountType</code>
53 * attribute must be a string that uniquely identifies your authenticator and will be the same
54 * string that user will use when making calls on the {@link AccountManager} and it also
55 * corresponds to {@link Account#type} for your accounts. One user of the android:icon is the
56 * "Account & Sync" settings page and one user of the android:smallIcon is the Contact Application's
57 * tab panels.
58 * <p>
59 * The preferences attribute points to an PreferenceScreen xml hierarchy that contains
60 * a list of PreferenceScreens that can be invoked to manage the authenticator. An example is:
61 * <pre>
62 * &lt;PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"&gt;
63 * &lt;PreferenceCategory android:title="@string/title_fmt" /&gt;
64 * &lt;PreferenceScreen
65 * android:key="key1"
66 * android:title="@string/key1_action"
67 * android:summary="@string/key1_summary"&gt;
68 * &lt;intent
69 * android:action="key1.ACTION"
70 * android:targetPackage="key1.package"
71 * android:targetClass="key1.class" /&gt;
72 * &lt;/PreferenceScreen&gt;
73 * &lt;/PreferenceScreen&gt;
74 * </pre>
75 *
76 * <p>
77 * The standard pattern for implementing any of the abstract methods is the following:
78 * <ul>
79 * <li> If the supplied arguments are enough for the authenticator to fully satisfy the request
80 * then it will do so and return a {@link Bundle} that contains the results.
81 * <li> If the authenticator needs information from the user to satisfy the request then it
82 * will create an {@link Intent} to an activity that will prompt the user for the information
83 * and then carry out the request. This intent must be returned in a Bundle as key
84 * {@link AccountManager#KEY_INTENT}.
85 * <p>
86 * The activity needs to return the final result when it is complete so the Intent should contain
87 * the {@link AccountAuthenticatorResponse} as {@link AccountManager#KEY_ACCOUNT_MANAGER_RESPONSE}.
88 * The activity must then call {@link AccountAuthenticatorResponse#onResult} or
89 * {@link AccountAuthenticatorResponse#onError} when it is complete.
Fred Quintana31957f12009-10-21 13:43:10 -070090 * <li> If the authenticator cannot synchronously process the request and return a result then it
Ed Heyld6f158b2009-10-29 10:18:45 -070091 * may choose to return null and then use the AccountManagerResponse to send the result
Fred Quintana31957f12009-10-21 13:43:10 -070092 * when it has completed the request.
Fred Quintana756b7352009-10-21 13:43:10 -070093 * </ul>
94 * <p>
95 * The following descriptions of each of the abstract authenticator methods will not describe the
96 * possible asynchronous nature of the request handling and will instead just describe the input
97 * parameters and the expected result.
98 * <p>
99 * When writing an activity to satisfy these requests one must pass in the AccountManagerResponse
100 * and return the result via that response when the activity finishes (or whenever else the
101 * activity author deems it is the correct time to respond).
102 * The {@link AccountAuthenticatorActivity} handles this, so one may wish to extend that when
103 * writing activities to handle these requests.
Fred Quintana60307342009-03-24 22:48:12 -0700104 */
105public abstract class AbstractAccountAuthenticator {
Fred Quintanad4a1d2e2009-07-16 16:36:38 -0700106 private final Context mContext;
107
108 public AbstractAccountAuthenticator(Context context) {
109 mContext = context;
110 }
111
Fred Quintanaf7ae77c2009-10-02 17:19:31 -0700112 private class Transport extends IAccountAuthenticator.Stub {
Fred Quintanaa698f422009-04-08 19:14:54 -0700113 public void addAccount(IAccountAuthenticatorResponse response, String accountType,
Fred Quintana33269202009-04-20 16:05:10 -0700114 String authTokenType, String[] requiredFeatures, Bundle options)
Fred Quintana60307342009-03-24 22:48:12 -0700115 throws RemoteException {
Fred Quintanad4a1d2e2009-07-16 16:36:38 -0700116 checkBinderPermission();
Fred Quintanaa698f422009-04-08 19:14:54 -0700117 try {
Fred Quintana31957f12009-10-21 13:43:10 -0700118 final Bundle result = AbstractAccountAuthenticator.this.addAccount(
Fred Quintanaa698f422009-04-08 19:14:54 -0700119 new AccountAuthenticatorResponse(response),
Fred Quintana33269202009-04-20 16:05:10 -0700120 accountType, authTokenType, requiredFeatures, options);
Fred Quintana31957f12009-10-21 13:43:10 -0700121 if (result != null) {
122 response.onResult(result);
123 }
Fred Quintanaa698f422009-04-08 19:14:54 -0700124 } catch (NetworkErrorException e) {
Fred Quintanaf7ae77c2009-10-02 17:19:31 -0700125 response.onError(AccountManager.ERROR_CODE_NETWORK_ERROR, e.getMessage());
Fred Quintanaa698f422009-04-08 19:14:54 -0700126 } catch (UnsupportedOperationException e) {
Fred Quintanaf7ae77c2009-10-02 17:19:31 -0700127 response.onError(AccountManager.ERROR_CODE_UNSUPPORTED_OPERATION,
Fred Quintanaa698f422009-04-08 19:14:54 -0700128 "addAccount not supported");
Fred Quintanaa698f422009-04-08 19:14:54 -0700129 }
Fred Quintana60307342009-03-24 22:48:12 -0700130 }
131
Fred Quintanaa698f422009-04-08 19:14:54 -0700132 public void confirmCredentials(IAccountAuthenticatorResponse response,
Fred Quintanaf7ae77c2009-10-02 17:19:31 -0700133 Account account, Bundle options) throws RemoteException {
Fred Quintanad4a1d2e2009-07-16 16:36:38 -0700134 checkBinderPermission();
Fred Quintanaa698f422009-04-08 19:14:54 -0700135 try {
Fred Quintana31957f12009-10-21 13:43:10 -0700136 final Bundle result = AbstractAccountAuthenticator.this.confirmCredentials(
Fred Quintanaf7ae77c2009-10-02 17:19:31 -0700137 new AccountAuthenticatorResponse(response), account, options);
Fred Quintana31957f12009-10-21 13:43:10 -0700138 if (result != null) {
139 response.onResult(result);
140 }
141 } catch (NetworkErrorException e) {
142 response.onError(AccountManager.ERROR_CODE_NETWORK_ERROR, e.getMessage());
Fred Quintanaa698f422009-04-08 19:14:54 -0700143 } catch (UnsupportedOperationException e) {
Fred Quintanaf7ae77c2009-10-02 17:19:31 -0700144 response.onError(AccountManager.ERROR_CODE_UNSUPPORTED_OPERATION,
Fred Quintanaa698f422009-04-08 19:14:54 -0700145 "confirmCredentials not supported");
Fred Quintanaa698f422009-04-08 19:14:54 -0700146 }
Fred Quintana60307342009-03-24 22:48:12 -0700147 }
148
Fred Quintanad4a1d2e2009-07-16 16:36:38 -0700149 public void getAuthTokenLabel(IAccountAuthenticatorResponse response,
150 String authTokenType)
151 throws RemoteException {
152 checkBinderPermission();
153 try {
154 Bundle result = new Bundle();
Fred Quintanaf7ae77c2009-10-02 17:19:31 -0700155 result.putString(AccountManager.KEY_AUTH_TOKEN_LABEL,
Fred Quintanad4a1d2e2009-07-16 16:36:38 -0700156 AbstractAccountAuthenticator.this.getAuthTokenLabel(authTokenType));
157 response.onResult(result);
158 } catch (IllegalArgumentException e) {
Fred Quintanaf7ae77c2009-10-02 17:19:31 -0700159 response.onError(AccountManager.ERROR_CODE_BAD_ARGUMENTS,
Fred Quintanad4a1d2e2009-07-16 16:36:38 -0700160 "unknown authTokenType");
161 } catch (UnsupportedOperationException e) {
Fred Quintanaf7ae77c2009-10-02 17:19:31 -0700162 response.onError(AccountManager.ERROR_CODE_UNSUPPORTED_OPERATION,
Fred Quintanad4a1d2e2009-07-16 16:36:38 -0700163 "getAuthTokenTypeLabel not supported");
164 }
165 }
166
Fred Quintana60307342009-03-24 22:48:12 -0700167 public void getAuthToken(IAccountAuthenticatorResponse response,
Fred Quintanaa698f422009-04-08 19:14:54 -0700168 Account account, String authTokenType, Bundle loginOptions)
Fred Quintana60307342009-03-24 22:48:12 -0700169 throws RemoteException {
Fred Quintanad4a1d2e2009-07-16 16:36:38 -0700170 checkBinderPermission();
Fred Quintanaa698f422009-04-08 19:14:54 -0700171 try {
172 final Bundle result = AbstractAccountAuthenticator.this.getAuthToken(
173 new AccountAuthenticatorResponse(response), account,
174 authTokenType, loginOptions);
175 if (result != null) {
176 response.onResult(result);
177 }
178 } catch (UnsupportedOperationException e) {
Fred Quintanaf7ae77c2009-10-02 17:19:31 -0700179 response.onError(AccountManager.ERROR_CODE_UNSUPPORTED_OPERATION,
Fred Quintanaa698f422009-04-08 19:14:54 -0700180 "getAuthToken not supported");
181 } catch (NetworkErrorException e) {
Fred Quintanaf7ae77c2009-10-02 17:19:31 -0700182 response.onError(AccountManager.ERROR_CODE_NETWORK_ERROR, e.getMessage());
Fred Quintanaa698f422009-04-08 19:14:54 -0700183 }
Fred Quintana60307342009-03-24 22:48:12 -0700184 }
185
Fred Quintanaa698f422009-04-08 19:14:54 -0700186 public void updateCredentials(IAccountAuthenticatorResponse response, Account account,
187 String authTokenType, Bundle loginOptions) throws RemoteException {
Fred Quintanad4a1d2e2009-07-16 16:36:38 -0700188 checkBinderPermission();
Fred Quintanaa698f422009-04-08 19:14:54 -0700189 try {
Fred Quintana31957f12009-10-21 13:43:10 -0700190 final Bundle result = AbstractAccountAuthenticator.this.updateCredentials(
Fred Quintanaa698f422009-04-08 19:14:54 -0700191 new AccountAuthenticatorResponse(response), account,
192 authTokenType, loginOptions);
Fred Quintana31957f12009-10-21 13:43:10 -0700193 if (result != null) {
194 response.onResult(result);
195 }
196 } catch (NetworkErrorException e) {
197 response.onError(AccountManager.ERROR_CODE_NETWORK_ERROR, e.getMessage());
Fred Quintanaa698f422009-04-08 19:14:54 -0700198 } catch (UnsupportedOperationException e) {
Fred Quintanaf7ae77c2009-10-02 17:19:31 -0700199 response.onError(AccountManager.ERROR_CODE_UNSUPPORTED_OPERATION,
Fred Quintanaa698f422009-04-08 19:14:54 -0700200 "updateCredentials not supported");
Fred Quintanaa698f422009-04-08 19:14:54 -0700201 }
Fred Quintana60307342009-03-24 22:48:12 -0700202 }
203
Fred Quintanaa698f422009-04-08 19:14:54 -0700204 public void editProperties(IAccountAuthenticatorResponse response,
205 String accountType) throws RemoteException {
Fred Quintanad4a1d2e2009-07-16 16:36:38 -0700206 checkBinderPermission();
Fred Quintanaa698f422009-04-08 19:14:54 -0700207 try {
Fred Quintana31957f12009-10-21 13:43:10 -0700208 final Bundle result = AbstractAccountAuthenticator.this.editProperties(
Fred Quintana60307342009-03-24 22:48:12 -0700209 new AccountAuthenticatorResponse(response), accountType);
Fred Quintana31957f12009-10-21 13:43:10 -0700210 if (result != null) {
211 response.onResult(result);
212 }
Fred Quintanaa698f422009-04-08 19:14:54 -0700213 } catch (UnsupportedOperationException e) {
Fred Quintanaf7ae77c2009-10-02 17:19:31 -0700214 response.onError(AccountManager.ERROR_CODE_UNSUPPORTED_OPERATION,
Fred Quintanaa698f422009-04-08 19:14:54 -0700215 "editProperties not supported");
Fred Quintanaa698f422009-04-08 19:14:54 -0700216 }
Fred Quintana60307342009-03-24 22:48:12 -0700217 }
Fred Quintana33269202009-04-20 16:05:10 -0700218
219 public void hasFeatures(IAccountAuthenticatorResponse response,
220 Account account, String[] features) throws RemoteException {
Fred Quintanad4a1d2e2009-07-16 16:36:38 -0700221 checkBinderPermission();
Fred Quintana33269202009-04-20 16:05:10 -0700222 try {
Fred Quintana31957f12009-10-21 13:43:10 -0700223 final Bundle result = AbstractAccountAuthenticator.this.hasFeatures(
Fred Quintana33269202009-04-20 16:05:10 -0700224 new AccountAuthenticatorResponse(response), account, features);
Fred Quintana31957f12009-10-21 13:43:10 -0700225 if (result != null) {
226 response.onResult(result);
227 }
Fred Quintana33269202009-04-20 16:05:10 -0700228 } catch (UnsupportedOperationException e) {
Fred Quintanaf7ae77c2009-10-02 17:19:31 -0700229 response.onError(AccountManager.ERROR_CODE_UNSUPPORTED_OPERATION,
Fred Quintana33269202009-04-20 16:05:10 -0700230 "hasFeatures not supported");
Fred Quintana33269202009-04-20 16:05:10 -0700231 } catch (NetworkErrorException e) {
Fred Quintanaf7ae77c2009-10-02 17:19:31 -0700232 response.onError(AccountManager.ERROR_CODE_NETWORK_ERROR, e.getMessage());
Fred Quintana33269202009-04-20 16:05:10 -0700233 }
234 }
Fred Quintanaffd0cb042009-08-15 21:45:26 -0700235
236 public void getAccountRemovalAllowed(IAccountAuthenticatorResponse response,
237 Account account) throws RemoteException {
238 checkBinderPermission();
239 try {
240 final Bundle result = AbstractAccountAuthenticator.this.getAccountRemovalAllowed(
241 new AccountAuthenticatorResponse(response), account);
242 if (result != null) {
243 response.onResult(result);
244 }
245 } catch (UnsupportedOperationException e) {
Fred Quintanaf7ae77c2009-10-02 17:19:31 -0700246 response.onError(AccountManager.ERROR_CODE_UNSUPPORTED_OPERATION,
Fred Quintanaffd0cb042009-08-15 21:45:26 -0700247 "getAccountRemovalAllowed not supported");
Fred Quintanaffd0cb042009-08-15 21:45:26 -0700248 } catch (NetworkErrorException e) {
Fred Quintanaf7ae77c2009-10-02 17:19:31 -0700249 response.onError(AccountManager.ERROR_CODE_NETWORK_ERROR, e.getMessage());
Fred Quintanaffd0cb042009-08-15 21:45:26 -0700250 }
251 }
Fred Quintana60307342009-03-24 22:48:12 -0700252 }
253
Fred Quintanad4a1d2e2009-07-16 16:36:38 -0700254 private void checkBinderPermission() {
255 final int uid = Binder.getCallingUid();
Fred Quintanaf7ae77c2009-10-02 17:19:31 -0700256 final String perm = Manifest.permission.ACCOUNT_MANAGER;
Fred Quintanad4a1d2e2009-07-16 16:36:38 -0700257 if (mContext.checkCallingOrSelfPermission(perm) != PackageManager.PERMISSION_GRANTED) {
258 throw new SecurityException("caller uid " + uid + " lacks " + perm);
259 }
260 }
261
Fred Quintanaf7ae77c2009-10-02 17:19:31 -0700262 private Transport mTransport = new Transport();
Fred Quintana60307342009-03-24 22:48:12 -0700263
264 /**
Fred Quintanaf7ae77c2009-10-02 17:19:31 -0700265 * @return the IBinder for the AccountAuthenticator
Fred Quintana60307342009-03-24 22:48:12 -0700266 */
Fred Quintanaf7ae77c2009-10-02 17:19:31 -0700267 public final IBinder getIBinder() {
268 return mTransport.asBinder();
Fred Quintana60307342009-03-24 22:48:12 -0700269 }
270
271 /**
Fred Quintanaa698f422009-04-08 19:14:54 -0700272 * Returns a Bundle that contains the Intent of the activity that can be used to edit the
273 * properties. In order to indicate success the activity should call response.setResult()
274 * with a non-null Bundle.
275 * @param response used to set the result for the request. If the Constants.INTENT_KEY
276 * is set in the bundle then this response field is to be used for sending future
277 * results if and when the Intent is started.
278 * @param accountType the AccountType whose properties are to be edited.
279 * @return a Bundle containing the result or the Intent to start to continue the request.
280 * If this is null then the request is considered to still be active and the result should
281 * sent later using response.
Fred Quintana60307342009-03-24 22:48:12 -0700282 */
Fred Quintanaa698f422009-04-08 19:14:54 -0700283 public abstract Bundle editProperties(AccountAuthenticatorResponse response,
284 String accountType);
Fred Quintana756b7352009-10-21 13:43:10 -0700285
286 /**
287 * Adds an account of the specified accountType.
288 * @param response to send the result back to the AccountManager, will never be null
289 * @param accountType the type of account to add, will never be null
290 * @param authTokenType the type of auth token to retrieve after adding the account, may be null
291 * @param requiredFeatures a String array of authenticator-specific features that the added
292 * account must support, may be null
293 * @param options a Bundle of authenticator-specific options, may be null
294 * @return a Bundle result or null if the result is to be returned via the response. The result
295 * will contain either:
296 * <ul>
297 * <li> {@link AccountManager#KEY_INTENT}, or
298 * <li> {@link AccountManager#KEY_ACCOUNT_NAME} and {@link AccountManager#KEY_ACCOUNT_TYPE} of
Fred Quintana8570f742010-02-18 10:32:54 -0800299 * the account that was added, or
Fred Quintana756b7352009-10-21 13:43:10 -0700300 * <li> {@link AccountManager#KEY_ERROR_CODE} and {@link AccountManager#KEY_ERROR_MESSAGE} to
301 * indicate an error
302 * </ul>
303 * @throws NetworkErrorException if the authenticator could not honor the request due to a
304 * network error
305 */
Fred Quintanaa698f422009-04-08 19:14:54 -0700306 public abstract Bundle addAccount(AccountAuthenticatorResponse response, String accountType,
Fred Quintana33269202009-04-20 16:05:10 -0700307 String authTokenType, String[] requiredFeatures, Bundle options)
308 throws NetworkErrorException;
Fred Quintana756b7352009-10-21 13:43:10 -0700309
310 /**
311 * Checks that the user knows the credentials of an account.
312 * @param response to send the result back to the AccountManager, will never be null
313 * @param account the account whose credentials are to be checked, will never be null
314 * @param options a Bundle of authenticator-specific options, may be null
315 * @return a Bundle result or null if the result is to be returned via the response. The result
316 * will contain either:
317 * <ul>
318 * <li> {@link AccountManager#KEY_INTENT}, or
319 * <li> {@link AccountManager#KEY_BOOLEAN_RESULT}, true if the check succeeded, false otherwise
320 * <li> {@link AccountManager#KEY_ERROR_CODE} and {@link AccountManager#KEY_ERROR_MESSAGE} to
321 * indicate an error
322 * </ul>
Fred Quintana31957f12009-10-21 13:43:10 -0700323 * @throws NetworkErrorException if the authenticator could not honor the request due to a
324 * network error
Fred Quintana756b7352009-10-21 13:43:10 -0700325 */
Fred Quintanaa698f422009-04-08 19:14:54 -0700326 public abstract Bundle confirmCredentials(AccountAuthenticatorResponse response,
Fred Quintana31957f12009-10-21 13:43:10 -0700327 Account account, Bundle options)
328 throws NetworkErrorException;
Fred Quintana756b7352009-10-21 13:43:10 -0700329 /**
330 * Gets the authtoken for an account.
331 * @param response to send the result back to the AccountManager, will never be null
332 * @param account the account whose credentials are to be retrieved, will never be null
333 * @param authTokenType the type of auth token to retrieve, will never be null
Fred Quintana31957f12009-10-21 13:43:10 -0700334 * @param options a Bundle of authenticator-specific options, may be null
Fred Quintana756b7352009-10-21 13:43:10 -0700335 * @return a Bundle result or null if the result is to be returned via the response. The result
336 * will contain either:
337 * <ul>
338 * <li> {@link AccountManager#KEY_INTENT}, or
339 * <li> {@link AccountManager#KEY_ACCOUNT_NAME}, {@link AccountManager#KEY_ACCOUNT_TYPE},
340 * and {@link AccountManager#KEY_AUTHTOKEN}, or
341 * <li> {@link AccountManager#KEY_ERROR_CODE} and {@link AccountManager#KEY_ERROR_MESSAGE} to
342 * indicate an error
343 * </ul>
344 * @throws NetworkErrorException if the authenticator could not honor the request due to a
345 * network error
346 */
Fred Quintanaa698f422009-04-08 19:14:54 -0700347 public abstract Bundle getAuthToken(AccountAuthenticatorResponse response,
Fred Quintana31957f12009-10-21 13:43:10 -0700348 Account account, String authTokenType, Bundle options)
Fred Quintanaa698f422009-04-08 19:14:54 -0700349 throws NetworkErrorException;
Fred Quintana756b7352009-10-21 13:43:10 -0700350
351 /**
352 * Ask the authenticator for a localized label for the given authTokenType.
353 * @param authTokenType the authTokenType whose label is to be returned, will never be null
354 * @return the localized label of the auth token type, may be null if the type isn't known
355 */
Fred Quintanad4a1d2e2009-07-16 16:36:38 -0700356 public abstract String getAuthTokenLabel(String authTokenType);
Fred Quintana756b7352009-10-21 13:43:10 -0700357
358 /**
359 * Update the locally stored credentials for an account.
360 * @param response to send the result back to the AccountManager, will never be null
361 * @param account the account whose credentials are to be updated, will never be null
362 * @param authTokenType the type of auth token to retrieve after updating the credentials,
363 * may be null
Fred Quintana31957f12009-10-21 13:43:10 -0700364 * @param options a Bundle of authenticator-specific options, may be null
Fred Quintana756b7352009-10-21 13:43:10 -0700365 * @return a Bundle result or null if the result is to be returned via the response. The result
366 * will contain either:
367 * <ul>
368 * <li> {@link AccountManager#KEY_INTENT}, or
369 * <li> {@link AccountManager#KEY_ACCOUNT_NAME} and {@link AccountManager#KEY_ACCOUNT_TYPE} of
Fred Quintana8570f742010-02-18 10:32:54 -0800370 * the account that was added, or
Fred Quintana756b7352009-10-21 13:43:10 -0700371 * <li> {@link AccountManager#KEY_ERROR_CODE} and {@link AccountManager#KEY_ERROR_MESSAGE} to
372 * indicate an error
373 * </ul>
Fred Quintana31957f12009-10-21 13:43:10 -0700374 * @throws NetworkErrorException if the authenticator could not honor the request due to a
375 * network error
Fred Quintana756b7352009-10-21 13:43:10 -0700376 */
Fred Quintanaa698f422009-04-08 19:14:54 -0700377 public abstract Bundle updateCredentials(AccountAuthenticatorResponse response,
Fred Quintana31957f12009-10-21 13:43:10 -0700378 Account account, String authTokenType, Bundle options) throws NetworkErrorException;
Fred Quintana8570f742010-02-18 10:32:54 -0800379
Fred Quintana756b7352009-10-21 13:43:10 -0700380 /**
381 * Checks if the account supports all the specified authenticator specific features.
382 * @param response to send the result back to the AccountManager, will never be null
383 * @param account the account to check, will never be null
384 * @param features an array of features to check, will never be null
385 * @return a Bundle result or null if the result is to be returned via the response. The result
386 * will contain either:
387 * <ul>
388 * <li> {@link AccountManager#KEY_INTENT}, or
389 * <li> {@link AccountManager#KEY_BOOLEAN_RESULT}, true if the account has all the features,
390 * false otherwise
391 * <li> {@link AccountManager#KEY_ERROR_CODE} and {@link AccountManager#KEY_ERROR_MESSAGE} to
392 * indicate an error
393 * </ul>
394 * @throws NetworkErrorException if the authenticator could not honor the request due to a
395 * network error
396 */
Fred Quintana33269202009-04-20 16:05:10 -0700397 public abstract Bundle hasFeatures(AccountAuthenticatorResponse response,
398 Account account, String[] features) throws NetworkErrorException;
Fred Quintana756b7352009-10-21 13:43:10 -0700399
400 /**
401 * Checks if the removal of this account is allowed.
402 * @param response to send the result back to the AccountManager, will never be null
403 * @param account the account to check, will never be null
404 * @return a Bundle result or null if the result is to be returned via the response. The result
405 * will contain either:
406 * <ul>
407 * <li> {@link AccountManager#KEY_INTENT}, or
408 * <li> {@link AccountManager#KEY_BOOLEAN_RESULT}, true if the removal of the account is
409 * allowed, false otherwise
410 * <li> {@link AccountManager#KEY_ERROR_CODE} and {@link AccountManager#KEY_ERROR_MESSAGE} to
411 * indicate an error
412 * </ul>
413 * @throws NetworkErrorException if the authenticator could not honor the request due to a
414 * network error
415 */
Fred Quintanaffd0cb042009-08-15 21:45:26 -0700416 public Bundle getAccountRemovalAllowed(AccountAuthenticatorResponse response,
417 Account account) throws NetworkErrorException {
418 final Bundle result = new Bundle();
Fred Quintanaf7ae77c2009-10-02 17:19:31 -0700419 result.putBoolean(AccountManager.KEY_BOOLEAN_RESULT, true);
Fred Quintanaffd0cb042009-08-15 21:45:26 -0700420 return result;
421 }
Fred Quintana60307342009-03-24 22:48:12 -0700422}