1603073430bbcb1bd29db7afb9b14e2732ad589fbFred Quintana/*
2603073430bbcb1bd29db7afb9b14e2732ad589fbFred Quintana * Copyright (C) 2009 The Android Open Source Project
3603073430bbcb1bd29db7afb9b14e2732ad589fbFred Quintana *
4603073430bbcb1bd29db7afb9b14e2732ad589fbFred Quintana * Licensed under the Apache License, Version 2.0 (the "License");
5603073430bbcb1bd29db7afb9b14e2732ad589fbFred Quintana * you may not use this file except in compliance with the License.
6603073430bbcb1bd29db7afb9b14e2732ad589fbFred Quintana * You may obtain a copy of the License at
7603073430bbcb1bd29db7afb9b14e2732ad589fbFred Quintana *
8603073430bbcb1bd29db7afb9b14e2732ad589fbFred Quintana *      http://www.apache.org/licenses/LICENSE-2.0
9603073430bbcb1bd29db7afb9b14e2732ad589fbFred Quintana *
10603073430bbcb1bd29db7afb9b14e2732ad589fbFred Quintana * Unless required by applicable law or agreed to in writing, software
11603073430bbcb1bd29db7afb9b14e2732ad589fbFred Quintana * distributed under the License is distributed on an "AS IS" BASIS,
12603073430bbcb1bd29db7afb9b14e2732ad589fbFred Quintana * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13603073430bbcb1bd29db7afb9b14e2732ad589fbFred Quintana * See the License for the specific language governing permissions and
14603073430bbcb1bd29db7afb9b14e2732ad589fbFred Quintana * limitations under the License.
15603073430bbcb1bd29db7afb9b14e2732ad589fbFred Quintana */
16603073430bbcb1bd29db7afb9b14e2732ad589fbFred Quintana
17603073430bbcb1bd29db7afb9b14e2732ad589fbFred Quintanapackage android.accounts;
18603073430bbcb1bd29db7afb9b14e2732ad589fbFred Quintana
19a698f4276968d078b1b9e2f3738c4f559a3307b2Fred Quintanaimport android.os.Bundle;
20603073430bbcb1bd29db7afb9b14e2732ad589fbFred Quintanaimport android.os.RemoteException;
21d4a1d2e14297a3387fdb5761090961e714370492Fred Quintanaimport android.os.Binder;
22f7ae77cd67f1a3993b8e56c1af4720a7adf4e69dFred Quintanaimport android.os.IBinder;
23d4a1d2e14297a3387fdb5761090961e714370492Fred Quintanaimport android.content.pm.PackageManager;
24d4a1d2e14297a3387fdb5761090961e714370492Fred Quintanaimport android.content.Context;
25f7ae77cd67f1a3993b8e56c1af4720a7adf4e69dFred Quintanaimport android.content.Intent;
26d4a1d2e14297a3387fdb5761090961e714370492Fred Quintanaimport android.Manifest;
27f0fd8436b3ec2aa47cd5de61072b8395bbe46765Fred Quintanaimport android.util.Log;
28f0fd8436b3ec2aa47cd5de61072b8395bbe46765Fred Quintana
29f0fd8436b3ec2aa47cd5de61072b8395bbe46765Fred Quintanaimport java.util.Arrays;
30603073430bbcb1bd29db7afb9b14e2732ad589fbFred Quintana
31603073430bbcb1bd29db7afb9b14e2732ad589fbFred Quintana/**
32756b735e9312ee52618158270f0bdd0ec691a712Fred Quintana * Abstract base class for creating AccountAuthenticators.
33756b735e9312ee52618158270f0bdd0ec691a712Fred Quintana * In order to be an authenticator one must extend this class, provider implementations for the
34756b735e9312ee52618158270f0bdd0ec691a712Fred Quintana * abstract methods and write a service that returns the result of {@link #getIBinder()}
35756b735e9312ee52618158270f0bdd0ec691a712Fred Quintana * in the service's {@link android.app.Service#onBind(android.content.Intent)} when invoked
36756b735e9312ee52618158270f0bdd0ec691a712Fred Quintana * with an intent with action {@link AccountManager#ACTION_AUTHENTICATOR_INTENT}. This service
37756b735e9312ee52618158270f0bdd0ec691a712Fred Quintana * must specify the following intent filter and metadata tags in its AndroidManifest.xml file
38756b735e9312ee52618158270f0bdd0ec691a712Fred Quintana * <pre>
39756b735e9312ee52618158270f0bdd0ec691a712Fred Quintana *   &lt;intent-filter&gt;
40756b735e9312ee52618158270f0bdd0ec691a712Fred Quintana *     &lt;action android:name="android.accounts.AccountAuthenticator" /&gt;
41756b735e9312ee52618158270f0bdd0ec691a712Fred Quintana *   &lt;/intent-filter&gt;
42756b735e9312ee52618158270f0bdd0ec691a712Fred Quintana *   &lt;meta-data android:name="android.accounts.AccountAuthenticator"
43756b735e9312ee52618158270f0bdd0ec691a712Fred Quintana *             android:resource="@xml/authenticator" /&gt;
44756b735e9312ee52618158270f0bdd0ec691a712Fred Quintana * </pre>
45756b735e9312ee52618158270f0bdd0ec691a712Fred Quintana * The <code>android:resource</code> attribute must point to a resource that looks like:
46756b735e9312ee52618158270f0bdd0ec691a712Fred Quintana * <pre>
47756b735e9312ee52618158270f0bdd0ec691a712Fred Quintana * &lt;account-authenticator xmlns:android="http://schemas.android.com/apk/res/android"
48756b735e9312ee52618158270f0bdd0ec691a712Fred Quintana *    android:accountType="typeOfAuthenticator"
49756b735e9312ee52618158270f0bdd0ec691a712Fred Quintana *    android:icon="@drawable/icon"
50756b735e9312ee52618158270f0bdd0ec691a712Fred Quintana *    android:smallIcon="@drawable/miniIcon"
51756b735e9312ee52618158270f0bdd0ec691a712Fred Quintana *    android:label="@string/label"
52756b735e9312ee52618158270f0bdd0ec691a712Fred Quintana *    android:accountPreferences="@xml/account_preferences"
53756b735e9312ee52618158270f0bdd0ec691a712Fred Quintana * /&gt;
54756b735e9312ee52618158270f0bdd0ec691a712Fred Quintana * </pre>
55756b735e9312ee52618158270f0bdd0ec691a712Fred Quintana * Replace the icons and labels with your own resources. The <code>android:accountType</code>
56756b735e9312ee52618158270f0bdd0ec691a712Fred Quintana * attribute must be a string that uniquely identifies your authenticator and will be the same
57756b735e9312ee52618158270f0bdd0ec691a712Fred Quintana * string that user will use when making calls on the {@link AccountManager} and it also
58756b735e9312ee52618158270f0bdd0ec691a712Fred Quintana * corresponds to {@link Account#type} for your accounts. One user of the android:icon is the
59756b735e9312ee52618158270f0bdd0ec691a712Fred Quintana * "Account & Sync" settings page and one user of the android:smallIcon is the Contact Application's
60756b735e9312ee52618158270f0bdd0ec691a712Fred Quintana * tab panels.
61756b735e9312ee52618158270f0bdd0ec691a712Fred Quintana * <p>
62f76a50ce8fdc6aea22cabc77b2977a1a15a79630Ken Wakasa * The preferences attribute points to a PreferenceScreen xml hierarchy that contains
63756b735e9312ee52618158270f0bdd0ec691a712Fred Quintana * a list of PreferenceScreens that can be invoked to manage the authenticator. An example is:
64756b735e9312ee52618158270f0bdd0ec691a712Fred Quintana * <pre>
65756b735e9312ee52618158270f0bdd0ec691a712Fred Quintana * &lt;PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"&gt;
66756b735e9312ee52618158270f0bdd0ec691a712Fred Quintana *    &lt;PreferenceCategory android:title="@string/title_fmt" /&gt;
67756b735e9312ee52618158270f0bdd0ec691a712Fred Quintana *    &lt;PreferenceScreen
68756b735e9312ee52618158270f0bdd0ec691a712Fred Quintana *         android:key="key1"
69756b735e9312ee52618158270f0bdd0ec691a712Fred Quintana *         android:title="@string/key1_action"
70756b735e9312ee52618158270f0bdd0ec691a712Fred Quintana *         android:summary="@string/key1_summary"&gt;
71756b735e9312ee52618158270f0bdd0ec691a712Fred Quintana *         &lt;intent
72756b735e9312ee52618158270f0bdd0ec691a712Fred Quintana *             android:action="key1.ACTION"
73756b735e9312ee52618158270f0bdd0ec691a712Fred Quintana *             android:targetPackage="key1.package"
74756b735e9312ee52618158270f0bdd0ec691a712Fred Quintana *             android:targetClass="key1.class" /&gt;
75756b735e9312ee52618158270f0bdd0ec691a712Fred Quintana *     &lt;/PreferenceScreen&gt;
76756b735e9312ee52618158270f0bdd0ec691a712Fred Quintana * &lt;/PreferenceScreen&gt;
77756b735e9312ee52618158270f0bdd0ec691a712Fred Quintana * </pre>
78756b735e9312ee52618158270f0bdd0ec691a712Fred Quintana *
79756b735e9312ee52618158270f0bdd0ec691a712Fred Quintana * <p>
80756b735e9312ee52618158270f0bdd0ec691a712Fred Quintana * The standard pattern for implementing any of the abstract methods is the following:
81756b735e9312ee52618158270f0bdd0ec691a712Fred Quintana * <ul>
82756b735e9312ee52618158270f0bdd0ec691a712Fred Quintana * <li> If the supplied arguments are enough for the authenticator to fully satisfy the request
83756b735e9312ee52618158270f0bdd0ec691a712Fred Quintana * then it will do so and return a {@link Bundle} that contains the results.
84756b735e9312ee52618158270f0bdd0ec691a712Fred Quintana * <li> If the authenticator needs information from the user to satisfy the request then it
85756b735e9312ee52618158270f0bdd0ec691a712Fred Quintana * will create an {@link Intent} to an activity that will prompt the user for the information
86756b735e9312ee52618158270f0bdd0ec691a712Fred Quintana * and then carry out the request. This intent must be returned in a Bundle as key
87756b735e9312ee52618158270f0bdd0ec691a712Fred Quintana * {@link AccountManager#KEY_INTENT}.
88756b735e9312ee52618158270f0bdd0ec691a712Fred Quintana * <p>
89756b735e9312ee52618158270f0bdd0ec691a712Fred Quintana * The activity needs to return the final result when it is complete so the Intent should contain
90756b735e9312ee52618158270f0bdd0ec691a712Fred Quintana * the {@link AccountAuthenticatorResponse} as {@link AccountManager#KEY_ACCOUNT_MANAGER_RESPONSE}.
91756b735e9312ee52618158270f0bdd0ec691a712Fred Quintana * The activity must then call {@link AccountAuthenticatorResponse#onResult} or
92756b735e9312ee52618158270f0bdd0ec691a712Fred Quintana * {@link AccountAuthenticatorResponse#onError} when it is complete.
9331957f1badbb900bbfe211317e1ea992d650a72dFred Quintana * <li> If the authenticator cannot synchronously process the request and return a result then it
94d6f158b3684acdf877ff6afb7208e1140afc4e12Ed Heyl * may choose to return null and then use the AccountManagerResponse to send the result
9531957f1badbb900bbfe211317e1ea992d650a72dFred Quintana * when it has completed the request.
96756b735e9312ee52618158270f0bdd0ec691a712Fred Quintana * </ul>
97756b735e9312ee52618158270f0bdd0ec691a712Fred Quintana * <p>
98756b735e9312ee52618158270f0bdd0ec691a712Fred Quintana * The following descriptions of each of the abstract authenticator methods will not describe the
99756b735e9312ee52618158270f0bdd0ec691a712Fred Quintana * possible asynchronous nature of the request handling and will instead just describe the input
100756b735e9312ee52618158270f0bdd0ec691a712Fred Quintana * parameters and the expected result.
101756b735e9312ee52618158270f0bdd0ec691a712Fred Quintana * <p>
102756b735e9312ee52618158270f0bdd0ec691a712Fred Quintana * When writing an activity to satisfy these requests one must pass in the AccountManagerResponse
103756b735e9312ee52618158270f0bdd0ec691a712Fred Quintana * and return the result via that response when the activity finishes (or whenever else  the
104756b735e9312ee52618158270f0bdd0ec691a712Fred Quintana * activity author deems it is the correct time to respond).
105756b735e9312ee52618158270f0bdd0ec691a712Fred Quintana * The {@link AccountAuthenticatorActivity} handles this, so one may wish to extend that when
106756b735e9312ee52618158270f0bdd0ec691a712Fred Quintana * writing activities to handle these requests.
107603073430bbcb1bd29db7afb9b14e2732ad589fbFred Quintana */
108603073430bbcb1bd29db7afb9b14e2732ad589fbFred Quintanapublic abstract class AbstractAccountAuthenticator {
109f0fd8436b3ec2aa47cd5de61072b8395bbe46765Fred Quintana    private static final String TAG = "AccountAuthenticator";
110f0fd8436b3ec2aa47cd5de61072b8395bbe46765Fred Quintana
111d4a1d2e14297a3387fdb5761090961e714370492Fred Quintana    private final Context mContext;
112d4a1d2e14297a3387fdb5761090961e714370492Fred Quintana
113d4a1d2e14297a3387fdb5761090961e714370492Fred Quintana    public AbstractAccountAuthenticator(Context context) {
114d4a1d2e14297a3387fdb5761090961e714370492Fred Quintana        mContext = context;
115d4a1d2e14297a3387fdb5761090961e714370492Fred Quintana    }
116d4a1d2e14297a3387fdb5761090961e714370492Fred Quintana
117f7ae77cd67f1a3993b8e56c1af4720a7adf4e69dFred Quintana    private class Transport extends IAccountAuthenticator.Stub {
118a698f4276968d078b1b9e2f3738c4f559a3307b2Fred Quintana        public void addAccount(IAccountAuthenticatorResponse response, String accountType,
119f0fd8436b3ec2aa47cd5de61072b8395bbe46765Fred Quintana                String authTokenType, String[] features, Bundle options)
120603073430bbcb1bd29db7afb9b14e2732ad589fbFred Quintana                throws RemoteException {
121f0fd8436b3ec2aa47cd5de61072b8395bbe46765Fred Quintana            if (Log.isLoggable(TAG, Log.VERBOSE)) {
122f0fd8436b3ec2aa47cd5de61072b8395bbe46765Fred Quintana                Log.v(TAG, "addAccount: accountType " + accountType
123f0fd8436b3ec2aa47cd5de61072b8395bbe46765Fred Quintana                        + ", authTokenType " + authTokenType
124f0fd8436b3ec2aa47cd5de61072b8395bbe46765Fred Quintana                        + ", features " + (features == null ? "[]" : Arrays.toString(features)));
125f0fd8436b3ec2aa47cd5de61072b8395bbe46765Fred Quintana            }
126d4a1d2e14297a3387fdb5761090961e714370492Fred Quintana            checkBinderPermission();
127a698f4276968d078b1b9e2f3738c4f559a3307b2Fred Quintana            try {
12831957f1badbb900bbfe211317e1ea992d650a72dFred Quintana                final Bundle result = AbstractAccountAuthenticator.this.addAccount(
129a698f4276968d078b1b9e2f3738c4f559a3307b2Fred Quintana                    new AccountAuthenticatorResponse(response),
130f0fd8436b3ec2aa47cd5de61072b8395bbe46765Fred Quintana                        accountType, authTokenType, features, options);
131f0fd8436b3ec2aa47cd5de61072b8395bbe46765Fred Quintana                if (Log.isLoggable(TAG, Log.VERBOSE)) {
132f0fd8436b3ec2aa47cd5de61072b8395bbe46765Fred Quintana                    result.keySet(); // force it to be unparcelled
133f0fd8436b3ec2aa47cd5de61072b8395bbe46765Fred Quintana                    Log.v(TAG, "addAccount: result " + AccountManager.sanitizeResult(result));
134f0fd8436b3ec2aa47cd5de61072b8395bbe46765Fred Quintana                }
13531957f1badbb900bbfe211317e1ea992d650a72dFred Quintana                if (result != null) {
13631957f1badbb900bbfe211317e1ea992d650a72dFred Quintana                    response.onResult(result);
13731957f1badbb900bbfe211317e1ea992d650a72dFred Quintana                }
1385d1a0c3933253d66a9c230ea1da051a7626937d4Fred Quintana            } catch (Exception e) {
1395d1a0c3933253d66a9c230ea1da051a7626937d4Fred Quintana                handleException(response, "addAccount", accountType, e);
140a698f4276968d078b1b9e2f3738c4f559a3307b2Fred Quintana            }
141603073430bbcb1bd29db7afb9b14e2732ad589fbFred Quintana        }
142603073430bbcb1bd29db7afb9b14e2732ad589fbFred Quintana
143a698f4276968d078b1b9e2f3738c4f559a3307b2Fred Quintana        public void confirmCredentials(IAccountAuthenticatorResponse response,
144f7ae77cd67f1a3993b8e56c1af4720a7adf4e69dFred Quintana                Account account, Bundle options) throws RemoteException {
145f0fd8436b3ec2aa47cd5de61072b8395bbe46765Fred Quintana            if (Log.isLoggable(TAG, Log.VERBOSE)) {
146f0fd8436b3ec2aa47cd5de61072b8395bbe46765Fred Quintana                Log.v(TAG, "confirmCredentials: " + account);
147f0fd8436b3ec2aa47cd5de61072b8395bbe46765Fred Quintana            }
148d4a1d2e14297a3387fdb5761090961e714370492Fred Quintana            checkBinderPermission();
149a698f4276968d078b1b9e2f3738c4f559a3307b2Fred Quintana            try {
15031957f1badbb900bbfe211317e1ea992d650a72dFred Quintana                final Bundle result = AbstractAccountAuthenticator.this.confirmCredentials(
151f7ae77cd67f1a3993b8e56c1af4720a7adf4e69dFred Quintana                    new AccountAuthenticatorResponse(response), account, options);
152f0fd8436b3ec2aa47cd5de61072b8395bbe46765Fred Quintana                if (Log.isLoggable(TAG, Log.VERBOSE)) {
153f0fd8436b3ec2aa47cd5de61072b8395bbe46765Fred Quintana                    result.keySet(); // force it to be unparcelled
154f0fd8436b3ec2aa47cd5de61072b8395bbe46765Fred Quintana                    Log.v(TAG, "confirmCredentials: result "
155f0fd8436b3ec2aa47cd5de61072b8395bbe46765Fred Quintana                            + AccountManager.sanitizeResult(result));
156f0fd8436b3ec2aa47cd5de61072b8395bbe46765Fred Quintana                }
15731957f1badbb900bbfe211317e1ea992d650a72dFred Quintana                if (result != null) {
15831957f1badbb900bbfe211317e1ea992d650a72dFred Quintana                    response.onResult(result);
15931957f1badbb900bbfe211317e1ea992d650a72dFred Quintana                }
1605d1a0c3933253d66a9c230ea1da051a7626937d4Fred Quintana            } catch (Exception e) {
1615d1a0c3933253d66a9c230ea1da051a7626937d4Fred Quintana                handleException(response, "confirmCredentials", account.toString(), e);
162a698f4276968d078b1b9e2f3738c4f559a3307b2Fred Quintana            }
163603073430bbcb1bd29db7afb9b14e2732ad589fbFred Quintana        }
164603073430bbcb1bd29db7afb9b14e2732ad589fbFred Quintana
165d4a1d2e14297a3387fdb5761090961e714370492Fred Quintana        public void getAuthTokenLabel(IAccountAuthenticatorResponse response,
166d4a1d2e14297a3387fdb5761090961e714370492Fred Quintana                String authTokenType)
167d4a1d2e14297a3387fdb5761090961e714370492Fred Quintana                throws RemoteException {
168f0fd8436b3ec2aa47cd5de61072b8395bbe46765Fred Quintana            if (Log.isLoggable(TAG, Log.VERBOSE)) {
169f0fd8436b3ec2aa47cd5de61072b8395bbe46765Fred Quintana                Log.v(TAG, "getAuthTokenLabel: authTokenType " + authTokenType);
170f0fd8436b3ec2aa47cd5de61072b8395bbe46765Fred Quintana            }
171d4a1d2e14297a3387fdb5761090961e714370492Fred Quintana            checkBinderPermission();
172d4a1d2e14297a3387fdb5761090961e714370492Fred Quintana            try {
173d4a1d2e14297a3387fdb5761090961e714370492Fred Quintana                Bundle result = new Bundle();
174f7ae77cd67f1a3993b8e56c1af4720a7adf4e69dFred Quintana                result.putString(AccountManager.KEY_AUTH_TOKEN_LABEL,
175d4a1d2e14297a3387fdb5761090961e714370492Fred Quintana                        AbstractAccountAuthenticator.this.getAuthTokenLabel(authTokenType));
176f0fd8436b3ec2aa47cd5de61072b8395bbe46765Fred Quintana                if (Log.isLoggable(TAG, Log.VERBOSE)) {
177f0fd8436b3ec2aa47cd5de61072b8395bbe46765Fred Quintana                    result.keySet(); // force it to be unparcelled
178f0fd8436b3ec2aa47cd5de61072b8395bbe46765Fred Quintana                    Log.v(TAG, "getAuthTokenLabel: result "
179f0fd8436b3ec2aa47cd5de61072b8395bbe46765Fred Quintana                            + AccountManager.sanitizeResult(result));
180f0fd8436b3ec2aa47cd5de61072b8395bbe46765Fred Quintana                }
1815d1a0c3933253d66a9c230ea1da051a7626937d4Fred Quintana                response.onResult(result);
1825d1a0c3933253d66a9c230ea1da051a7626937d4Fred Quintana            } catch (Exception e) {
1835d1a0c3933253d66a9c230ea1da051a7626937d4Fred Quintana                handleException(response, "getAuthTokenLabel", authTokenType, e);
184d4a1d2e14297a3387fdb5761090961e714370492Fred Quintana            }
185d4a1d2e14297a3387fdb5761090961e714370492Fred Quintana        }
186d4a1d2e14297a3387fdb5761090961e714370492Fred Quintana
187a698f4276968d078b1b9e2f3738c4f559a3307b2Fred Quintana        public void getAuthToken(IAccountAuthenticatorResponse response,
188a698f4276968d078b1b9e2f3738c4f559a3307b2Fred Quintana                Account account, String authTokenType, Bundle loginOptions)
189603073430bbcb1bd29db7afb9b14e2732ad589fbFred Quintana                throws RemoteException {
190f0fd8436b3ec2aa47cd5de61072b8395bbe46765Fred Quintana            if (Log.isLoggable(TAG, Log.VERBOSE)) {
191f0fd8436b3ec2aa47cd5de61072b8395bbe46765Fred Quintana                Log.v(TAG, "getAuthToken: " + account
192f0fd8436b3ec2aa47cd5de61072b8395bbe46765Fred Quintana                        + ", authTokenType " + authTokenType);
193f0fd8436b3ec2aa47cd5de61072b8395bbe46765Fred Quintana            }
194d4a1d2e14297a3387fdb5761090961e714370492Fred Quintana            checkBinderPermission();
195a698f4276968d078b1b9e2f3738c4f559a3307b2Fred Quintana            try {
196a698f4276968d078b1b9e2f3738c4f559a3307b2Fred Quintana                final Bundle result = AbstractAccountAuthenticator.this.getAuthToken(
197a698f4276968d078b1b9e2f3738c4f559a3307b2Fred Quintana                        new AccountAuthenticatorResponse(response), account,
198a698f4276968d078b1b9e2f3738c4f559a3307b2Fred Quintana                        authTokenType, loginOptions);
199f0fd8436b3ec2aa47cd5de61072b8395bbe46765Fred Quintana                if (Log.isLoggable(TAG, Log.VERBOSE)) {
200f0fd8436b3ec2aa47cd5de61072b8395bbe46765Fred Quintana                    result.keySet(); // force it to be unparcelled
201f0fd8436b3ec2aa47cd5de61072b8395bbe46765Fred Quintana                    Log.v(TAG, "getAuthToken: result " + AccountManager.sanitizeResult(result));
202f0fd8436b3ec2aa47cd5de61072b8395bbe46765Fred Quintana                }
203a698f4276968d078b1b9e2f3738c4f559a3307b2Fred Quintana                if (result != null) {
204a698f4276968d078b1b9e2f3738c4f559a3307b2Fred Quintana                    response.onResult(result);
205a698f4276968d078b1b9e2f3738c4f559a3307b2Fred Quintana                }
2065d1a0c3933253d66a9c230ea1da051a7626937d4Fred Quintana            } catch (Exception e) {
2075d1a0c3933253d66a9c230ea1da051a7626937d4Fred Quintana                handleException(response, "getAuthToken",
2085d1a0c3933253d66a9c230ea1da051a7626937d4Fred Quintana                        account.toString() + "," + authTokenType, e);
209a698f4276968d078b1b9e2f3738c4f559a3307b2Fred Quintana            }
210603073430bbcb1bd29db7afb9b14e2732ad589fbFred Quintana        }
211603073430bbcb1bd29db7afb9b14e2732ad589fbFred Quintana
212a698f4276968d078b1b9e2f3738c4f559a3307b2Fred Quintana        public void updateCredentials(IAccountAuthenticatorResponse response, Account account,
213a698f4276968d078b1b9e2f3738c4f559a3307b2Fred Quintana                String authTokenType, Bundle loginOptions) throws RemoteException {
214f0fd8436b3ec2aa47cd5de61072b8395bbe46765Fred Quintana            if (Log.isLoggable(TAG, Log.VERBOSE)) {
215f0fd8436b3ec2aa47cd5de61072b8395bbe46765Fred Quintana                Log.v(TAG, "updateCredentials: " + account
216f0fd8436b3ec2aa47cd5de61072b8395bbe46765Fred Quintana                        + ", authTokenType " + authTokenType);
217f0fd8436b3ec2aa47cd5de61072b8395bbe46765Fred Quintana            }
218d4a1d2e14297a3387fdb5761090961e714370492Fred Quintana            checkBinderPermission();
219a698f4276968d078b1b9e2f3738c4f559a3307b2Fred Quintana            try {
22031957f1badbb900bbfe211317e1ea992d650a72dFred Quintana                final Bundle result = AbstractAccountAuthenticator.this.updateCredentials(
221a698f4276968d078b1b9e2f3738c4f559a3307b2Fred Quintana                    new AccountAuthenticatorResponse(response), account,
222a698f4276968d078b1b9e2f3738c4f559a3307b2Fred Quintana                        authTokenType, loginOptions);
223f0fd8436b3ec2aa47cd5de61072b8395bbe46765Fred Quintana                if (Log.isLoggable(TAG, Log.VERBOSE)) {
224f0fd8436b3ec2aa47cd5de61072b8395bbe46765Fred Quintana                    result.keySet(); // force it to be unparcelled
225f0fd8436b3ec2aa47cd5de61072b8395bbe46765Fred Quintana                    Log.v(TAG, "updateCredentials: result "
226f0fd8436b3ec2aa47cd5de61072b8395bbe46765Fred Quintana                            + AccountManager.sanitizeResult(result));
227f0fd8436b3ec2aa47cd5de61072b8395bbe46765Fred Quintana                }
22831957f1badbb900bbfe211317e1ea992d650a72dFred Quintana                if (result != null) {
22931957f1badbb900bbfe211317e1ea992d650a72dFred Quintana                    response.onResult(result);
23031957f1badbb900bbfe211317e1ea992d650a72dFred Quintana                }
2315d1a0c3933253d66a9c230ea1da051a7626937d4Fred Quintana            } catch (Exception e) {
2325d1a0c3933253d66a9c230ea1da051a7626937d4Fred Quintana                handleException(response, "updateCredentials",
2335d1a0c3933253d66a9c230ea1da051a7626937d4Fred Quintana                        account.toString() + "," + authTokenType, e);
234a698f4276968d078b1b9e2f3738c4f559a3307b2Fred Quintana            }
235603073430bbcb1bd29db7afb9b14e2732ad589fbFred Quintana        }
236603073430bbcb1bd29db7afb9b14e2732ad589fbFred Quintana
237a698f4276968d078b1b9e2f3738c4f559a3307b2Fred Quintana        public void editProperties(IAccountAuthenticatorResponse response,
238a698f4276968d078b1b9e2f3738c4f559a3307b2Fred Quintana                String accountType) throws RemoteException {
239d4a1d2e14297a3387fdb5761090961e714370492Fred Quintana            checkBinderPermission();
240a698f4276968d078b1b9e2f3738c4f559a3307b2Fred Quintana            try {
24131957f1badbb900bbfe211317e1ea992d650a72dFred Quintana                final Bundle result = AbstractAccountAuthenticator.this.editProperties(
242603073430bbcb1bd29db7afb9b14e2732ad589fbFred Quintana                    new AccountAuthenticatorResponse(response), accountType);
24331957f1badbb900bbfe211317e1ea992d650a72dFred Quintana                if (result != null) {
24431957f1badbb900bbfe211317e1ea992d650a72dFred Quintana                    response.onResult(result);
24531957f1badbb900bbfe211317e1ea992d650a72dFred Quintana                }
2465d1a0c3933253d66a9c230ea1da051a7626937d4Fred Quintana            } catch (Exception e) {
2475d1a0c3933253d66a9c230ea1da051a7626937d4Fred Quintana                handleException(response, "editProperties", accountType, e);
248a698f4276968d078b1b9e2f3738c4f559a3307b2Fred Quintana            }
249603073430bbcb1bd29db7afb9b14e2732ad589fbFred Quintana        }
2503326920329cecb57c7ff1fc5c6add5c98aab9ed9Fred Quintana
2513326920329cecb57c7ff1fc5c6add5c98aab9ed9Fred Quintana        public void hasFeatures(IAccountAuthenticatorResponse response,
2523326920329cecb57c7ff1fc5c6add5c98aab9ed9Fred Quintana                Account account, String[] features) throws RemoteException {
253d4a1d2e14297a3387fdb5761090961e714370492Fred Quintana            checkBinderPermission();
2543326920329cecb57c7ff1fc5c6add5c98aab9ed9Fred Quintana            try {
25531957f1badbb900bbfe211317e1ea992d650a72dFred Quintana                final Bundle result = AbstractAccountAuthenticator.this.hasFeatures(
2563326920329cecb57c7ff1fc5c6add5c98aab9ed9Fred Quintana                    new AccountAuthenticatorResponse(response), account, features);
25731957f1badbb900bbfe211317e1ea992d650a72dFred Quintana                if (result != null) {
25831957f1badbb900bbfe211317e1ea992d650a72dFred Quintana                    response.onResult(result);
25931957f1badbb900bbfe211317e1ea992d650a72dFred Quintana                }
2605d1a0c3933253d66a9c230ea1da051a7626937d4Fred Quintana            } catch (Exception e) {
2615d1a0c3933253d66a9c230ea1da051a7626937d4Fred Quintana                handleException(response, "hasFeatures", account.toString(), e);
2623326920329cecb57c7ff1fc5c6add5c98aab9ed9Fred Quintana            }
2633326920329cecb57c7ff1fc5c6add5c98aab9ed9Fred Quintana        }
264ffd0cb04f97e62d286d185c520580d81a9c328b1Fred Quintana
265ffd0cb04f97e62d286d185c520580d81a9c328b1Fred Quintana        public void getAccountRemovalAllowed(IAccountAuthenticatorResponse response,
266ffd0cb04f97e62d286d185c520580d81a9c328b1Fred Quintana                Account account) throws RemoteException {
267ffd0cb04f97e62d286d185c520580d81a9c328b1Fred Quintana            checkBinderPermission();
268ffd0cb04f97e62d286d185c520580d81a9c328b1Fred Quintana            try {
269ffd0cb04f97e62d286d185c520580d81a9c328b1Fred Quintana                final Bundle result = AbstractAccountAuthenticator.this.getAccountRemovalAllowed(
270ffd0cb04f97e62d286d185c520580d81a9c328b1Fred Quintana                    new AccountAuthenticatorResponse(response), account);
271ffd0cb04f97e62d286d185c520580d81a9c328b1Fred Quintana                if (result != null) {
272ffd0cb04f97e62d286d185c520580d81a9c328b1Fred Quintana                    response.onResult(result);
273ffd0cb04f97e62d286d185c520580d81a9c328b1Fred Quintana                }
2745d1a0c3933253d66a9c230ea1da051a7626937d4Fred Quintana            } catch (Exception e) {
2755d1a0c3933253d66a9c230ea1da051a7626937d4Fred Quintana                handleException(response, "getAccountRemovalAllowed", account.toString(), e);
2765d1a0c3933253d66a9c230ea1da051a7626937d4Fred Quintana            }
2775d1a0c3933253d66a9c230ea1da051a7626937d4Fred Quintana        }
2785d1a0c3933253d66a9c230ea1da051a7626937d4Fred Quintana    }
2795d1a0c3933253d66a9c230ea1da051a7626937d4Fred Quintana
2805d1a0c3933253d66a9c230ea1da051a7626937d4Fred Quintana    private void handleException(IAccountAuthenticatorResponse response, String method,
2815d1a0c3933253d66a9c230ea1da051a7626937d4Fred Quintana            String data, Exception e) throws RemoteException {
2825d1a0c3933253d66a9c230ea1da051a7626937d4Fred Quintana        if (e instanceof NetworkErrorException) {
2835d1a0c3933253d66a9c230ea1da051a7626937d4Fred Quintana            if (Log.isLoggable(TAG, Log.VERBOSE)) {
2845d1a0c3933253d66a9c230ea1da051a7626937d4Fred Quintana                Log.v(TAG, method + "(" + data + ")", e);
2855d1a0c3933253d66a9c230ea1da051a7626937d4Fred Quintana            }
2865d1a0c3933253d66a9c230ea1da051a7626937d4Fred Quintana            response.onError(AccountManager.ERROR_CODE_NETWORK_ERROR, e.getMessage());
2875d1a0c3933253d66a9c230ea1da051a7626937d4Fred Quintana        } else if (e instanceof UnsupportedOperationException) {
2885d1a0c3933253d66a9c230ea1da051a7626937d4Fred Quintana            if (Log.isLoggable(TAG, Log.VERBOSE)) {
2895d1a0c3933253d66a9c230ea1da051a7626937d4Fred Quintana                Log.v(TAG, method + "(" + data + ")", e);
2905d1a0c3933253d66a9c230ea1da051a7626937d4Fred Quintana            }
2915d1a0c3933253d66a9c230ea1da051a7626937d4Fred Quintana            response.onError(AccountManager.ERROR_CODE_UNSUPPORTED_OPERATION,
2925d1a0c3933253d66a9c230ea1da051a7626937d4Fred Quintana                    method + " not supported");
2935d1a0c3933253d66a9c230ea1da051a7626937d4Fred Quintana        } else if (e instanceof IllegalArgumentException) {
2945d1a0c3933253d66a9c230ea1da051a7626937d4Fred Quintana            if (Log.isLoggable(TAG, Log.VERBOSE)) {
2955d1a0c3933253d66a9c230ea1da051a7626937d4Fred Quintana                Log.v(TAG, method + "(" + data + ")", e);
296ffd0cb04f97e62d286d185c520580d81a9c328b1Fred Quintana            }
2975d1a0c3933253d66a9c230ea1da051a7626937d4Fred Quintana            response.onError(AccountManager.ERROR_CODE_BAD_ARGUMENTS,
2985d1a0c3933253d66a9c230ea1da051a7626937d4Fred Quintana                    method + " not supported");
2995d1a0c3933253d66a9c230ea1da051a7626937d4Fred Quintana        } else {
3005d1a0c3933253d66a9c230ea1da051a7626937d4Fred Quintana            Log.w(TAG, method + "(" + data + ")", e);
3015d1a0c3933253d66a9c230ea1da051a7626937d4Fred Quintana            response.onError(AccountManager.ERROR_CODE_REMOTE_EXCEPTION,
3025d1a0c3933253d66a9c230ea1da051a7626937d4Fred Quintana                    method + " failed");
303ffd0cb04f97e62d286d185c520580d81a9c328b1Fred Quintana        }
304603073430bbcb1bd29db7afb9b14e2732ad589fbFred Quintana    }
305603073430bbcb1bd29db7afb9b14e2732ad589fbFred Quintana
306d4a1d2e14297a3387fdb5761090961e714370492Fred Quintana    private void checkBinderPermission() {
307d4a1d2e14297a3387fdb5761090961e714370492Fred Quintana        final int uid = Binder.getCallingUid();
308f7ae77cd67f1a3993b8e56c1af4720a7adf4e69dFred Quintana        final String perm = Manifest.permission.ACCOUNT_MANAGER;
309d4a1d2e14297a3387fdb5761090961e714370492Fred Quintana        if (mContext.checkCallingOrSelfPermission(perm) != PackageManager.PERMISSION_GRANTED) {
310d4a1d2e14297a3387fdb5761090961e714370492Fred Quintana            throw new SecurityException("caller uid " + uid + " lacks " + perm);
311d4a1d2e14297a3387fdb5761090961e714370492Fred Quintana        }
312d4a1d2e14297a3387fdb5761090961e714370492Fred Quintana    }
313d4a1d2e14297a3387fdb5761090961e714370492Fred Quintana
314f7ae77cd67f1a3993b8e56c1af4720a7adf4e69dFred Quintana    private Transport mTransport = new Transport();
315603073430bbcb1bd29db7afb9b14e2732ad589fbFred Quintana
316603073430bbcb1bd29db7afb9b14e2732ad589fbFred Quintana    /**
317f7ae77cd67f1a3993b8e56c1af4720a7adf4e69dFred Quintana     * @return the IBinder for the AccountAuthenticator
318603073430bbcb1bd29db7afb9b14e2732ad589fbFred Quintana     */
319f7ae77cd67f1a3993b8e56c1af4720a7adf4e69dFred Quintana    public final IBinder getIBinder() {
320f7ae77cd67f1a3993b8e56c1af4720a7adf4e69dFred Quintana        return mTransport.asBinder();
321603073430bbcb1bd29db7afb9b14e2732ad589fbFred Quintana    }
322603073430bbcb1bd29db7afb9b14e2732ad589fbFred Quintana
323603073430bbcb1bd29db7afb9b14e2732ad589fbFred Quintana    /**
324a698f4276968d078b1b9e2f3738c4f559a3307b2Fred Quintana     * Returns a Bundle that contains the Intent of the activity that can be used to edit the
325a698f4276968d078b1b9e2f3738c4f559a3307b2Fred Quintana     * properties. In order to indicate success the activity should call response.setResult()
326a698f4276968d078b1b9e2f3738c4f559a3307b2Fred Quintana     * with a non-null Bundle.
327a698f4276968d078b1b9e2f3738c4f559a3307b2Fred Quintana     * @param response used to set the result for the request. If the Constants.INTENT_KEY
328a698f4276968d078b1b9e2f3738c4f559a3307b2Fred Quintana     *   is set in the bundle then this response field is to be used for sending future
329a698f4276968d078b1b9e2f3738c4f559a3307b2Fred Quintana     *   results if and when the Intent is started.
330a698f4276968d078b1b9e2f3738c4f559a3307b2Fred Quintana     * @param accountType the AccountType whose properties are to be edited.
331a698f4276968d078b1b9e2f3738c4f559a3307b2Fred Quintana     * @return a Bundle containing the result or the Intent to start to continue the request.
332a698f4276968d078b1b9e2f3738c4f559a3307b2Fred Quintana     *   If this is null then the request is considered to still be active and the result should
333a698f4276968d078b1b9e2f3738c4f559a3307b2Fred Quintana     *   sent later using response.
334603073430bbcb1bd29db7afb9b14e2732ad589fbFred Quintana     */
335a698f4276968d078b1b9e2f3738c4f559a3307b2Fred Quintana    public abstract Bundle editProperties(AccountAuthenticatorResponse response,
336a698f4276968d078b1b9e2f3738c4f559a3307b2Fred Quintana            String accountType);
337756b735e9312ee52618158270f0bdd0ec691a712Fred Quintana
338756b735e9312ee52618158270f0bdd0ec691a712Fred Quintana    /**
339756b735e9312ee52618158270f0bdd0ec691a712Fred Quintana     * Adds an account of the specified accountType.
340756b735e9312ee52618158270f0bdd0ec691a712Fred Quintana     * @param response to send the result back to the AccountManager, will never be null
341756b735e9312ee52618158270f0bdd0ec691a712Fred Quintana     * @param accountType the type of account to add, will never be null
342756b735e9312ee52618158270f0bdd0ec691a712Fred Quintana     * @param authTokenType the type of auth token to retrieve after adding the account, may be null
343756b735e9312ee52618158270f0bdd0ec691a712Fred Quintana     * @param requiredFeatures a String array of authenticator-specific features that the added
344756b735e9312ee52618158270f0bdd0ec691a712Fred Quintana     * account must support, may be null
345756b735e9312ee52618158270f0bdd0ec691a712Fred Quintana     * @param options a Bundle of authenticator-specific options, may be null
346756b735e9312ee52618158270f0bdd0ec691a712Fred Quintana     * @return a Bundle result or null if the result is to be returned via the response. The result
347756b735e9312ee52618158270f0bdd0ec691a712Fred Quintana     * will contain either:
348756b735e9312ee52618158270f0bdd0ec691a712Fred Quintana     * <ul>
349756b735e9312ee52618158270f0bdd0ec691a712Fred Quintana     * <li> {@link AccountManager#KEY_INTENT}, or
350756b735e9312ee52618158270f0bdd0ec691a712Fred Quintana     * <li> {@link AccountManager#KEY_ACCOUNT_NAME} and {@link AccountManager#KEY_ACCOUNT_TYPE} of
3518570f7440780db5c9b410e033e843b0e80e2fd27Fred Quintana     * the account that was added, or
352756b735e9312ee52618158270f0bdd0ec691a712Fred Quintana     * <li> {@link AccountManager#KEY_ERROR_CODE} and {@link AccountManager#KEY_ERROR_MESSAGE} to
353756b735e9312ee52618158270f0bdd0ec691a712Fred Quintana     * indicate an error
354756b735e9312ee52618158270f0bdd0ec691a712Fred Quintana     * </ul>
355756b735e9312ee52618158270f0bdd0ec691a712Fred Quintana     * @throws NetworkErrorException if the authenticator could not honor the request due to a
356756b735e9312ee52618158270f0bdd0ec691a712Fred Quintana     * network error
357756b735e9312ee52618158270f0bdd0ec691a712Fred Quintana     */
358a698f4276968d078b1b9e2f3738c4f559a3307b2Fred Quintana    public abstract Bundle addAccount(AccountAuthenticatorResponse response, String accountType,
3593326920329cecb57c7ff1fc5c6add5c98aab9ed9Fred Quintana            String authTokenType, String[] requiredFeatures, Bundle options)
3603326920329cecb57c7ff1fc5c6add5c98aab9ed9Fred Quintana            throws NetworkErrorException;
361756b735e9312ee52618158270f0bdd0ec691a712Fred Quintana
362756b735e9312ee52618158270f0bdd0ec691a712Fred Quintana    /**
363756b735e9312ee52618158270f0bdd0ec691a712Fred Quintana     * Checks that the user knows the credentials of an account.
364756b735e9312ee52618158270f0bdd0ec691a712Fred Quintana     * @param response to send the result back to the AccountManager, will never be null
365756b735e9312ee52618158270f0bdd0ec691a712Fred Quintana     * @param account the account whose credentials are to be checked, will never be null
366756b735e9312ee52618158270f0bdd0ec691a712Fred Quintana     * @param options a Bundle of authenticator-specific options, may be null
367756b735e9312ee52618158270f0bdd0ec691a712Fred Quintana     * @return a Bundle result or null if the result is to be returned via the response. The result
368756b735e9312ee52618158270f0bdd0ec691a712Fred Quintana     * will contain either:
369756b735e9312ee52618158270f0bdd0ec691a712Fred Quintana     * <ul>
370756b735e9312ee52618158270f0bdd0ec691a712Fred Quintana     * <li> {@link AccountManager#KEY_INTENT}, or
371756b735e9312ee52618158270f0bdd0ec691a712Fred Quintana     * <li> {@link AccountManager#KEY_BOOLEAN_RESULT}, true if the check succeeded, false otherwise
372756b735e9312ee52618158270f0bdd0ec691a712Fred Quintana     * <li> {@link AccountManager#KEY_ERROR_CODE} and {@link AccountManager#KEY_ERROR_MESSAGE} to
373756b735e9312ee52618158270f0bdd0ec691a712Fred Quintana     * indicate an error
374756b735e9312ee52618158270f0bdd0ec691a712Fred Quintana     * </ul>
37531957f1badbb900bbfe211317e1ea992d650a72dFred Quintana     * @throws NetworkErrorException if the authenticator could not honor the request due to a
37631957f1badbb900bbfe211317e1ea992d650a72dFred Quintana     * network error
377756b735e9312ee52618158270f0bdd0ec691a712Fred Quintana     */
378a698f4276968d078b1b9e2f3738c4f559a3307b2Fred Quintana    public abstract Bundle confirmCredentials(AccountAuthenticatorResponse response,
37931957f1badbb900bbfe211317e1ea992d650a72dFred Quintana            Account account, Bundle options)
38031957f1badbb900bbfe211317e1ea992d650a72dFred Quintana            throws NetworkErrorException;
381756b735e9312ee52618158270f0bdd0ec691a712Fred Quintana    /**
382756b735e9312ee52618158270f0bdd0ec691a712Fred Quintana     * Gets the authtoken for an account.
383756b735e9312ee52618158270f0bdd0ec691a712Fred Quintana     * @param response to send the result back to the AccountManager, will never be null
384756b735e9312ee52618158270f0bdd0ec691a712Fred Quintana     * @param account the account whose credentials are to be retrieved, will never be null
385756b735e9312ee52618158270f0bdd0ec691a712Fred Quintana     * @param authTokenType the type of auth token to retrieve, will never be null
38631957f1badbb900bbfe211317e1ea992d650a72dFred Quintana     * @param options a Bundle of authenticator-specific options, may be null
387756b735e9312ee52618158270f0bdd0ec691a712Fred Quintana     * @return a Bundle result or null if the result is to be returned via the response. The result
388756b735e9312ee52618158270f0bdd0ec691a712Fred Quintana     * will contain either:
389756b735e9312ee52618158270f0bdd0ec691a712Fred Quintana     * <ul>
390756b735e9312ee52618158270f0bdd0ec691a712Fred Quintana     * <li> {@link AccountManager#KEY_INTENT}, or
391756b735e9312ee52618158270f0bdd0ec691a712Fred Quintana     * <li> {@link AccountManager#KEY_ACCOUNT_NAME}, {@link AccountManager#KEY_ACCOUNT_TYPE},
392756b735e9312ee52618158270f0bdd0ec691a712Fred Quintana     * and {@link AccountManager#KEY_AUTHTOKEN}, or
393756b735e9312ee52618158270f0bdd0ec691a712Fred Quintana     * <li> {@link AccountManager#KEY_ERROR_CODE} and {@link AccountManager#KEY_ERROR_MESSAGE} to
394756b735e9312ee52618158270f0bdd0ec691a712Fred Quintana     * indicate an error
395756b735e9312ee52618158270f0bdd0ec691a712Fred Quintana     * </ul>
396756b735e9312ee52618158270f0bdd0ec691a712Fred Quintana     * @throws NetworkErrorException if the authenticator could not honor the request due to a
397756b735e9312ee52618158270f0bdd0ec691a712Fred Quintana     * network error
398756b735e9312ee52618158270f0bdd0ec691a712Fred Quintana     */
399a698f4276968d078b1b9e2f3738c4f559a3307b2Fred Quintana    public abstract Bundle getAuthToken(AccountAuthenticatorResponse response,
40031957f1badbb900bbfe211317e1ea992d650a72dFred Quintana            Account account, String authTokenType, Bundle options)
401a698f4276968d078b1b9e2f3738c4f559a3307b2Fred Quintana            throws NetworkErrorException;
402756b735e9312ee52618158270f0bdd0ec691a712Fred Quintana
403756b735e9312ee52618158270f0bdd0ec691a712Fred Quintana    /**
404756b735e9312ee52618158270f0bdd0ec691a712Fred Quintana     * Ask the authenticator for a localized label for the given authTokenType.
405756b735e9312ee52618158270f0bdd0ec691a712Fred Quintana     * @param authTokenType the authTokenType whose label is to be returned, will never be null
406756b735e9312ee52618158270f0bdd0ec691a712Fred Quintana     * @return the localized label of the auth token type, may be null if the type isn't known
407756b735e9312ee52618158270f0bdd0ec691a712Fred Quintana     */
408d4a1d2e14297a3387fdb5761090961e714370492Fred Quintana    public abstract String getAuthTokenLabel(String authTokenType);
409756b735e9312ee52618158270f0bdd0ec691a712Fred Quintana
410756b735e9312ee52618158270f0bdd0ec691a712Fred Quintana    /**
411756b735e9312ee52618158270f0bdd0ec691a712Fred Quintana     * Update the locally stored credentials for an account.
412756b735e9312ee52618158270f0bdd0ec691a712Fred Quintana     * @param response to send the result back to the AccountManager, will never be null
413756b735e9312ee52618158270f0bdd0ec691a712Fred Quintana     * @param account the account whose credentials are to be updated, will never be null
414756b735e9312ee52618158270f0bdd0ec691a712Fred Quintana     * @param authTokenType the type of auth token to retrieve after updating the credentials,
415756b735e9312ee52618158270f0bdd0ec691a712Fred Quintana     * may be null
41631957f1badbb900bbfe211317e1ea992d650a72dFred Quintana     * @param options a Bundle of authenticator-specific options, may be null
417756b735e9312ee52618158270f0bdd0ec691a712Fred Quintana     * @return a Bundle result or null if the result is to be returned via the response. The result
418756b735e9312ee52618158270f0bdd0ec691a712Fred Quintana     * will contain either:
419756b735e9312ee52618158270f0bdd0ec691a712Fred Quintana     * <ul>
420756b735e9312ee52618158270f0bdd0ec691a712Fred Quintana     * <li> {@link AccountManager#KEY_INTENT}, or
421756b735e9312ee52618158270f0bdd0ec691a712Fred Quintana     * <li> {@link AccountManager#KEY_ACCOUNT_NAME} and {@link AccountManager#KEY_ACCOUNT_TYPE} of
4228570f7440780db5c9b410e033e843b0e80e2fd27Fred Quintana     * the account that was added, or
423756b735e9312ee52618158270f0bdd0ec691a712Fred Quintana     * <li> {@link AccountManager#KEY_ERROR_CODE} and {@link AccountManager#KEY_ERROR_MESSAGE} to
424756b735e9312ee52618158270f0bdd0ec691a712Fred Quintana     * indicate an error
425756b735e9312ee52618158270f0bdd0ec691a712Fred Quintana     * </ul>
42631957f1badbb900bbfe211317e1ea992d650a72dFred Quintana     * @throws NetworkErrorException if the authenticator could not honor the request due to a
42731957f1badbb900bbfe211317e1ea992d650a72dFred Quintana     * network error
428756b735e9312ee52618158270f0bdd0ec691a712Fred Quintana     */
429a698f4276968d078b1b9e2f3738c4f559a3307b2Fred Quintana    public abstract Bundle updateCredentials(AccountAuthenticatorResponse response,
43031957f1badbb900bbfe211317e1ea992d650a72dFred Quintana            Account account, String authTokenType, Bundle options) throws NetworkErrorException;
4318570f7440780db5c9b410e033e843b0e80e2fd27Fred Quintana
432756b735e9312ee52618158270f0bdd0ec691a712Fred Quintana    /**
433756b735e9312ee52618158270f0bdd0ec691a712Fred Quintana     * Checks if the account supports all the specified authenticator specific features.
434756b735e9312ee52618158270f0bdd0ec691a712Fred Quintana     * @param response to send the result back to the AccountManager, will never be null
435756b735e9312ee52618158270f0bdd0ec691a712Fred Quintana     * @param account the account to check, will never be null
436756b735e9312ee52618158270f0bdd0ec691a712Fred Quintana     * @param features an array of features to check, will never be null
437756b735e9312ee52618158270f0bdd0ec691a712Fred Quintana     * @return a Bundle result or null if the result is to be returned via the response. The result
438756b735e9312ee52618158270f0bdd0ec691a712Fred Quintana     * will contain either:
439756b735e9312ee52618158270f0bdd0ec691a712Fred Quintana     * <ul>
440756b735e9312ee52618158270f0bdd0ec691a712Fred Quintana     * <li> {@link AccountManager#KEY_INTENT}, or
441756b735e9312ee52618158270f0bdd0ec691a712Fred Quintana     * <li> {@link AccountManager#KEY_BOOLEAN_RESULT}, true if the account has all the features,
442756b735e9312ee52618158270f0bdd0ec691a712Fred Quintana     * false otherwise
443756b735e9312ee52618158270f0bdd0ec691a712Fred Quintana     * <li> {@link AccountManager#KEY_ERROR_CODE} and {@link AccountManager#KEY_ERROR_MESSAGE} to
444756b735e9312ee52618158270f0bdd0ec691a712Fred Quintana     * indicate an error
445756b735e9312ee52618158270f0bdd0ec691a712Fred Quintana     * </ul>
446756b735e9312ee52618158270f0bdd0ec691a712Fred Quintana     * @throws NetworkErrorException if the authenticator could not honor the request due to a
447756b735e9312ee52618158270f0bdd0ec691a712Fred Quintana     * network error
448756b735e9312ee52618158270f0bdd0ec691a712Fred Quintana     */
4493326920329cecb57c7ff1fc5c6add5c98aab9ed9Fred Quintana    public abstract Bundle hasFeatures(AccountAuthenticatorResponse response,
4503326920329cecb57c7ff1fc5c6add5c98aab9ed9Fred Quintana            Account account, String[] features) throws NetworkErrorException;
451756b735e9312ee52618158270f0bdd0ec691a712Fred Quintana
452756b735e9312ee52618158270f0bdd0ec691a712Fred Quintana    /**
453756b735e9312ee52618158270f0bdd0ec691a712Fred Quintana     * Checks if the removal of this account is allowed.
454756b735e9312ee52618158270f0bdd0ec691a712Fred Quintana     * @param response to send the result back to the AccountManager, will never be null
455756b735e9312ee52618158270f0bdd0ec691a712Fred Quintana     * @param account the account to check, will never be null
456756b735e9312ee52618158270f0bdd0ec691a712Fred Quintana     * @return a Bundle result or null if the result is to be returned via the response. The result
457756b735e9312ee52618158270f0bdd0ec691a712Fred Quintana     * will contain either:
458756b735e9312ee52618158270f0bdd0ec691a712Fred Quintana     * <ul>
459756b735e9312ee52618158270f0bdd0ec691a712Fred Quintana     * <li> {@link AccountManager#KEY_INTENT}, or
460756b735e9312ee52618158270f0bdd0ec691a712Fred Quintana     * <li> {@link AccountManager#KEY_BOOLEAN_RESULT}, true if the removal of the account is
461756b735e9312ee52618158270f0bdd0ec691a712Fred Quintana     * allowed, false otherwise
462756b735e9312ee52618158270f0bdd0ec691a712Fred Quintana     * <li> {@link AccountManager#KEY_ERROR_CODE} and {@link AccountManager#KEY_ERROR_MESSAGE} to
463756b735e9312ee52618158270f0bdd0ec691a712Fred Quintana     * indicate an error
464756b735e9312ee52618158270f0bdd0ec691a712Fred Quintana     * </ul>
465756b735e9312ee52618158270f0bdd0ec691a712Fred Quintana     * @throws NetworkErrorException if the authenticator could not honor the request due to a
466756b735e9312ee52618158270f0bdd0ec691a712Fred Quintana     * network error
467756b735e9312ee52618158270f0bdd0ec691a712Fred Quintana     */
468ffd0cb04f97e62d286d185c520580d81a9c328b1Fred Quintana    public Bundle getAccountRemovalAllowed(AccountAuthenticatorResponse response,
469ffd0cb04f97e62d286d185c520580d81a9c328b1Fred Quintana            Account account) throws NetworkErrorException {
470ffd0cb04f97e62d286d185c520580d81a9c328b1Fred Quintana        final Bundle result = new Bundle();
471f7ae77cd67f1a3993b8e56c1af4720a7adf4e69dFred Quintana        result.putBoolean(AccountManager.KEY_BOOLEAN_RESULT, true);
472ffd0cb04f97e62d286d185c520580d81a9c328b1Fred Quintana        return result;
473ffd0cb04f97e62d286d185c520580d81a9c328b1Fred Quintana    }
474603073430bbcb1bd29db7afb9b14e2732ad589fbFred Quintana}
475