AbstractAccountAuthenticator.java revision ffd0cb04f97e62d286d185c520580d81a9c328b1
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;
22d4a1d2e14297a3387fdb5761090961e714370492Fred Quintanaimport android.util.Log;
23d4a1d2e14297a3387fdb5761090961e714370492Fred Quintanaimport android.content.pm.PackageManager;
24d4a1d2e14297a3387fdb5761090961e714370492Fred Quintanaimport android.content.Context;
25d4a1d2e14297a3387fdb5761090961e714370492Fred Quintanaimport android.Manifest;
26603073430bbcb1bd29db7afb9b14e2732ad589fbFred Quintana
27603073430bbcb1bd29db7afb9b14e2732ad589fbFred Quintana/**
28603073430bbcb1bd29db7afb9b14e2732ad589fbFred Quintana * Base class for creating AccountAuthenticators. This implements the IAccountAuthenticator
29603073430bbcb1bd29db7afb9b14e2732ad589fbFred Quintana * binder interface and also provides helper libraries to simplify the creation of
30603073430bbcb1bd29db7afb9b14e2732ad589fbFred Quintana * AccountAuthenticators.
31603073430bbcb1bd29db7afb9b14e2732ad589fbFred Quintana */
32603073430bbcb1bd29db7afb9b14e2732ad589fbFred Quintanapublic abstract class AbstractAccountAuthenticator {
33d4a1d2e14297a3387fdb5761090961e714370492Fred Quintana    private final Context mContext;
34d4a1d2e14297a3387fdb5761090961e714370492Fred Quintana
35d4a1d2e14297a3387fdb5761090961e714370492Fred Quintana    public AbstractAccountAuthenticator(Context context) {
36d4a1d2e14297a3387fdb5761090961e714370492Fred Quintana        mContext = context;
37d4a1d2e14297a3387fdb5761090961e714370492Fred Quintana    }
38d4a1d2e14297a3387fdb5761090961e714370492Fred Quintana
39603073430bbcb1bd29db7afb9b14e2732ad589fbFred Quintana    class Transport extends IAccountAuthenticator.Stub {
40a698f4276968d078b1b9e2f3738c4f559a3307b2Fred Quintana        public void addAccount(IAccountAuthenticatorResponse response, String accountType,
413326920329cecb57c7ff1fc5c6add5c98aab9ed9Fred Quintana                String authTokenType, String[] requiredFeatures, Bundle options)
42603073430bbcb1bd29db7afb9b14e2732ad589fbFred Quintana                throws RemoteException {
43d4a1d2e14297a3387fdb5761090961e714370492Fred Quintana            checkBinderPermission();
44a698f4276968d078b1b9e2f3738c4f559a3307b2Fred Quintana            final Bundle result;
45a698f4276968d078b1b9e2f3738c4f559a3307b2Fred Quintana            try {
46a698f4276968d078b1b9e2f3738c4f559a3307b2Fred Quintana                result = AbstractAccountAuthenticator.this.addAccount(
47a698f4276968d078b1b9e2f3738c4f559a3307b2Fred Quintana                    new AccountAuthenticatorResponse(response),
483326920329cecb57c7ff1fc5c6add5c98aab9ed9Fred Quintana                        accountType, authTokenType, requiredFeatures, options);
49a698f4276968d078b1b9e2f3738c4f559a3307b2Fred Quintana            } catch (NetworkErrorException e) {
50a698f4276968d078b1b9e2f3738c4f559a3307b2Fred Quintana                response.onError(Constants.ERROR_CODE_NETWORK_ERROR, e.getMessage());
51a698f4276968d078b1b9e2f3738c4f559a3307b2Fred Quintana                return;
52a698f4276968d078b1b9e2f3738c4f559a3307b2Fred Quintana            } catch (UnsupportedOperationException e) {
53a698f4276968d078b1b9e2f3738c4f559a3307b2Fred Quintana                response.onError(Constants.ERROR_CODE_UNSUPPORTED_OPERATION,
54a698f4276968d078b1b9e2f3738c4f559a3307b2Fred Quintana                        "addAccount not supported");
55a698f4276968d078b1b9e2f3738c4f559a3307b2Fred Quintana                return;
56a698f4276968d078b1b9e2f3738c4f559a3307b2Fred Quintana            }
57a698f4276968d078b1b9e2f3738c4f559a3307b2Fred Quintana            if (result != null) {
58a698f4276968d078b1b9e2f3738c4f559a3307b2Fred Quintana                response.onResult(result);
59a698f4276968d078b1b9e2f3738c4f559a3307b2Fred Quintana            }
60603073430bbcb1bd29db7afb9b14e2732ad589fbFred Quintana        }
61603073430bbcb1bd29db7afb9b14e2732ad589fbFred Quintana
62a698f4276968d078b1b9e2f3738c4f559a3307b2Fred Quintana        public void confirmPassword(IAccountAuthenticatorResponse response,
63a698f4276968d078b1b9e2f3738c4f559a3307b2Fred Quintana                Account account, String password) throws RemoteException {
64d4a1d2e14297a3387fdb5761090961e714370492Fred Quintana            checkBinderPermission();
65a698f4276968d078b1b9e2f3738c4f559a3307b2Fred Quintana            boolean result;
66a698f4276968d078b1b9e2f3738c4f559a3307b2Fred Quintana            try {
67a698f4276968d078b1b9e2f3738c4f559a3307b2Fred Quintana                result = AbstractAccountAuthenticator.this.confirmPassword(
68603073430bbcb1bd29db7afb9b14e2732ad589fbFred Quintana                    new AccountAuthenticatorResponse(response),
69a698f4276968d078b1b9e2f3738c4f559a3307b2Fred Quintana                        account, password);
70a698f4276968d078b1b9e2f3738c4f559a3307b2Fred Quintana            } catch (UnsupportedOperationException e) {
71a698f4276968d078b1b9e2f3738c4f559a3307b2Fred Quintana                response.onError(Constants.ERROR_CODE_UNSUPPORTED_OPERATION,
72a698f4276968d078b1b9e2f3738c4f559a3307b2Fred Quintana                        "confirmPassword not supported");
73a698f4276968d078b1b9e2f3738c4f559a3307b2Fred Quintana                return;
74a698f4276968d078b1b9e2f3738c4f559a3307b2Fred Quintana            } catch (NetworkErrorException e) {
75a698f4276968d078b1b9e2f3738c4f559a3307b2Fred Quintana                response.onError(Constants.ERROR_CODE_NETWORK_ERROR, e.getMessage());
76a698f4276968d078b1b9e2f3738c4f559a3307b2Fred Quintana                return;
77a698f4276968d078b1b9e2f3738c4f559a3307b2Fred Quintana            }
78a698f4276968d078b1b9e2f3738c4f559a3307b2Fred Quintana            Bundle bundle = new Bundle();
79a698f4276968d078b1b9e2f3738c4f559a3307b2Fred Quintana            bundle.putBoolean(Constants.BOOLEAN_RESULT_KEY, result);
80a698f4276968d078b1b9e2f3738c4f559a3307b2Fred Quintana            response.onResult(bundle);
81603073430bbcb1bd29db7afb9b14e2732ad589fbFred Quintana        }
82603073430bbcb1bd29db7afb9b14e2732ad589fbFred Quintana
83a698f4276968d078b1b9e2f3738c4f559a3307b2Fred Quintana        public void confirmCredentials(IAccountAuthenticatorResponse response,
84a698f4276968d078b1b9e2f3738c4f559a3307b2Fred Quintana                Account account) throws RemoteException {
85d4a1d2e14297a3387fdb5761090961e714370492Fred Quintana            checkBinderPermission();
86a698f4276968d078b1b9e2f3738c4f559a3307b2Fred Quintana            final Bundle result;
87a698f4276968d078b1b9e2f3738c4f559a3307b2Fred Quintana            try {
88a698f4276968d078b1b9e2f3738c4f559a3307b2Fred Quintana                result = AbstractAccountAuthenticator.this.confirmCredentials(
89a698f4276968d078b1b9e2f3738c4f559a3307b2Fred Quintana                    new AccountAuthenticatorResponse(response), account);
90a698f4276968d078b1b9e2f3738c4f559a3307b2Fred Quintana            } catch (UnsupportedOperationException e) {
91a698f4276968d078b1b9e2f3738c4f559a3307b2Fred Quintana                response.onError(Constants.ERROR_CODE_UNSUPPORTED_OPERATION,
92a698f4276968d078b1b9e2f3738c4f559a3307b2Fred Quintana                        "confirmCredentials not supported");
93a698f4276968d078b1b9e2f3738c4f559a3307b2Fred Quintana                return;
94a698f4276968d078b1b9e2f3738c4f559a3307b2Fred Quintana            }
95a698f4276968d078b1b9e2f3738c4f559a3307b2Fred Quintana            if (result != null) {
96a698f4276968d078b1b9e2f3738c4f559a3307b2Fred Quintana                response.onResult(result);
97a698f4276968d078b1b9e2f3738c4f559a3307b2Fred Quintana            }
98603073430bbcb1bd29db7afb9b14e2732ad589fbFred Quintana        }
99603073430bbcb1bd29db7afb9b14e2732ad589fbFred Quintana
100d4a1d2e14297a3387fdb5761090961e714370492Fred Quintana        public void getAuthTokenLabel(IAccountAuthenticatorResponse response,
101d4a1d2e14297a3387fdb5761090961e714370492Fred Quintana                String authTokenType)
102d4a1d2e14297a3387fdb5761090961e714370492Fred Quintana                throws RemoteException {
103d4a1d2e14297a3387fdb5761090961e714370492Fred Quintana            checkBinderPermission();
104d4a1d2e14297a3387fdb5761090961e714370492Fred Quintana            try {
105d4a1d2e14297a3387fdb5761090961e714370492Fred Quintana                Bundle result = new Bundle();
106d4a1d2e14297a3387fdb5761090961e714370492Fred Quintana                result.putString(Constants.AUTH_TOKEN_LABEL_KEY,
107d4a1d2e14297a3387fdb5761090961e714370492Fred Quintana                        AbstractAccountAuthenticator.this.getAuthTokenLabel(authTokenType));
108d4a1d2e14297a3387fdb5761090961e714370492Fred Quintana                response.onResult(result);
109d4a1d2e14297a3387fdb5761090961e714370492Fred Quintana            } catch (IllegalArgumentException e) {
110d4a1d2e14297a3387fdb5761090961e714370492Fred Quintana                response.onError(Constants.ERROR_CODE_BAD_ARGUMENTS,
111d4a1d2e14297a3387fdb5761090961e714370492Fred Quintana                        "unknown authTokenType");
112d4a1d2e14297a3387fdb5761090961e714370492Fred Quintana            } catch (UnsupportedOperationException e) {
113d4a1d2e14297a3387fdb5761090961e714370492Fred Quintana                response.onError(Constants.ERROR_CODE_UNSUPPORTED_OPERATION,
114d4a1d2e14297a3387fdb5761090961e714370492Fred Quintana                        "getAuthTokenTypeLabel not supported");
115d4a1d2e14297a3387fdb5761090961e714370492Fred Quintana            }
116d4a1d2e14297a3387fdb5761090961e714370492Fred Quintana        }
117d4a1d2e14297a3387fdb5761090961e714370492Fred Quintana
118a698f4276968d078b1b9e2f3738c4f559a3307b2Fred Quintana        public void getAuthToken(IAccountAuthenticatorResponse response,
119a698f4276968d078b1b9e2f3738c4f559a3307b2Fred Quintana                Account account, String authTokenType, Bundle loginOptions)
120603073430bbcb1bd29db7afb9b14e2732ad589fbFred Quintana                throws RemoteException {
121d4a1d2e14297a3387fdb5761090961e714370492Fred Quintana            checkBinderPermission();
122a698f4276968d078b1b9e2f3738c4f559a3307b2Fred Quintana            try {
123a698f4276968d078b1b9e2f3738c4f559a3307b2Fred Quintana                final Bundle result = AbstractAccountAuthenticator.this.getAuthToken(
124a698f4276968d078b1b9e2f3738c4f559a3307b2Fred Quintana                        new AccountAuthenticatorResponse(response), account,
125a698f4276968d078b1b9e2f3738c4f559a3307b2Fred Quintana                        authTokenType, loginOptions);
126a698f4276968d078b1b9e2f3738c4f559a3307b2Fred Quintana                if (result != null) {
127a698f4276968d078b1b9e2f3738c4f559a3307b2Fred Quintana                    response.onResult(result);
128a698f4276968d078b1b9e2f3738c4f559a3307b2Fred Quintana                }
129a698f4276968d078b1b9e2f3738c4f559a3307b2Fred Quintana            } catch (UnsupportedOperationException e) {
130a698f4276968d078b1b9e2f3738c4f559a3307b2Fred Quintana                response.onError(Constants.ERROR_CODE_UNSUPPORTED_OPERATION,
131a698f4276968d078b1b9e2f3738c4f559a3307b2Fred Quintana                        "getAuthToken not supported");
132a698f4276968d078b1b9e2f3738c4f559a3307b2Fred Quintana            } catch (NetworkErrorException e) {
133a698f4276968d078b1b9e2f3738c4f559a3307b2Fred Quintana                response.onError(Constants.ERROR_CODE_NETWORK_ERROR, e.getMessage());
134a698f4276968d078b1b9e2f3738c4f559a3307b2Fred Quintana            }
135603073430bbcb1bd29db7afb9b14e2732ad589fbFred Quintana        }
136603073430bbcb1bd29db7afb9b14e2732ad589fbFred Quintana
137a698f4276968d078b1b9e2f3738c4f559a3307b2Fred Quintana        public void updateCredentials(IAccountAuthenticatorResponse response, Account account,
138a698f4276968d078b1b9e2f3738c4f559a3307b2Fred Quintana                String authTokenType, Bundle loginOptions) throws RemoteException {
139d4a1d2e14297a3387fdb5761090961e714370492Fred Quintana            checkBinderPermission();
140a698f4276968d078b1b9e2f3738c4f559a3307b2Fred Quintana            final Bundle result;
141a698f4276968d078b1b9e2f3738c4f559a3307b2Fred Quintana            try {
142a698f4276968d078b1b9e2f3738c4f559a3307b2Fred Quintana                result = AbstractAccountAuthenticator.this.updateCredentials(
143a698f4276968d078b1b9e2f3738c4f559a3307b2Fred Quintana                    new AccountAuthenticatorResponse(response), account,
144a698f4276968d078b1b9e2f3738c4f559a3307b2Fred Quintana                        authTokenType, loginOptions);
145a698f4276968d078b1b9e2f3738c4f559a3307b2Fred Quintana            } catch (UnsupportedOperationException e) {
146a698f4276968d078b1b9e2f3738c4f559a3307b2Fred Quintana                response.onError(Constants.ERROR_CODE_UNSUPPORTED_OPERATION,
147a698f4276968d078b1b9e2f3738c4f559a3307b2Fred Quintana                        "updateCredentials not supported");
148a698f4276968d078b1b9e2f3738c4f559a3307b2Fred Quintana                return;
149a698f4276968d078b1b9e2f3738c4f559a3307b2Fred Quintana            }
150a698f4276968d078b1b9e2f3738c4f559a3307b2Fred Quintana            if (result != null) {
151a698f4276968d078b1b9e2f3738c4f559a3307b2Fred Quintana                response.onResult(result);
152a698f4276968d078b1b9e2f3738c4f559a3307b2Fred Quintana            }
153603073430bbcb1bd29db7afb9b14e2732ad589fbFred Quintana        }
154603073430bbcb1bd29db7afb9b14e2732ad589fbFred Quintana
155a698f4276968d078b1b9e2f3738c4f559a3307b2Fred Quintana        public void editProperties(IAccountAuthenticatorResponse response,
156a698f4276968d078b1b9e2f3738c4f559a3307b2Fred Quintana                String accountType) throws RemoteException {
157d4a1d2e14297a3387fdb5761090961e714370492Fred Quintana            checkBinderPermission();
158a698f4276968d078b1b9e2f3738c4f559a3307b2Fred Quintana            final Bundle result;
159a698f4276968d078b1b9e2f3738c4f559a3307b2Fred Quintana            try {
160a698f4276968d078b1b9e2f3738c4f559a3307b2Fred Quintana                result = AbstractAccountAuthenticator.this.editProperties(
161603073430bbcb1bd29db7afb9b14e2732ad589fbFred Quintana                    new AccountAuthenticatorResponse(response), accountType);
162a698f4276968d078b1b9e2f3738c4f559a3307b2Fred Quintana            } catch (UnsupportedOperationException e) {
163a698f4276968d078b1b9e2f3738c4f559a3307b2Fred Quintana                response.onError(Constants.ERROR_CODE_UNSUPPORTED_OPERATION,
164a698f4276968d078b1b9e2f3738c4f559a3307b2Fred Quintana                        "editProperties not supported");
165a698f4276968d078b1b9e2f3738c4f559a3307b2Fred Quintana                return;
166a698f4276968d078b1b9e2f3738c4f559a3307b2Fred Quintana            }
167a698f4276968d078b1b9e2f3738c4f559a3307b2Fred Quintana            if (result != null) {
168a698f4276968d078b1b9e2f3738c4f559a3307b2Fred Quintana                response.onResult(result);
169a698f4276968d078b1b9e2f3738c4f559a3307b2Fred Quintana            }
170603073430bbcb1bd29db7afb9b14e2732ad589fbFred Quintana        }
1713326920329cecb57c7ff1fc5c6add5c98aab9ed9Fred Quintana
1723326920329cecb57c7ff1fc5c6add5c98aab9ed9Fred Quintana        public void hasFeatures(IAccountAuthenticatorResponse response,
1733326920329cecb57c7ff1fc5c6add5c98aab9ed9Fred Quintana                Account account, String[] features) throws RemoteException {
174d4a1d2e14297a3387fdb5761090961e714370492Fred Quintana            checkBinderPermission();
1753326920329cecb57c7ff1fc5c6add5c98aab9ed9Fred Quintana            final Bundle result;
1763326920329cecb57c7ff1fc5c6add5c98aab9ed9Fred Quintana            try {
1773326920329cecb57c7ff1fc5c6add5c98aab9ed9Fred Quintana                result = AbstractAccountAuthenticator.this.hasFeatures(
1783326920329cecb57c7ff1fc5c6add5c98aab9ed9Fred Quintana                    new AccountAuthenticatorResponse(response), account, features);
1793326920329cecb57c7ff1fc5c6add5c98aab9ed9Fred Quintana            } catch (UnsupportedOperationException e) {
1803326920329cecb57c7ff1fc5c6add5c98aab9ed9Fred Quintana                response.onError(Constants.ERROR_CODE_UNSUPPORTED_OPERATION,
1813326920329cecb57c7ff1fc5c6add5c98aab9ed9Fred Quintana                        "hasFeatures not supported");
1823326920329cecb57c7ff1fc5c6add5c98aab9ed9Fred Quintana                return;
1833326920329cecb57c7ff1fc5c6add5c98aab9ed9Fred Quintana            } catch (NetworkErrorException e) {
1843326920329cecb57c7ff1fc5c6add5c98aab9ed9Fred Quintana                response.onError(Constants.ERROR_CODE_NETWORK_ERROR, e.getMessage());
1853326920329cecb57c7ff1fc5c6add5c98aab9ed9Fred Quintana                return;
1863326920329cecb57c7ff1fc5c6add5c98aab9ed9Fred Quintana            }
1873326920329cecb57c7ff1fc5c6add5c98aab9ed9Fred Quintana            if (result != null) {
1883326920329cecb57c7ff1fc5c6add5c98aab9ed9Fred Quintana                response.onResult(result);
1893326920329cecb57c7ff1fc5c6add5c98aab9ed9Fred Quintana            }
1903326920329cecb57c7ff1fc5c6add5c98aab9ed9Fred Quintana        }
191ffd0cb04f97e62d286d185c520580d81a9c328b1Fred Quintana
192ffd0cb04f97e62d286d185c520580d81a9c328b1Fred Quintana        public void getAccountRemovalAllowed(IAccountAuthenticatorResponse response,
193ffd0cb04f97e62d286d185c520580d81a9c328b1Fred Quintana                Account account) throws RemoteException {
194ffd0cb04f97e62d286d185c520580d81a9c328b1Fred Quintana            checkBinderPermission();
195ffd0cb04f97e62d286d185c520580d81a9c328b1Fred Quintana            try {
196ffd0cb04f97e62d286d185c520580d81a9c328b1Fred Quintana                final Bundle result = AbstractAccountAuthenticator.this.getAccountRemovalAllowed(
197ffd0cb04f97e62d286d185c520580d81a9c328b1Fred Quintana                    new AccountAuthenticatorResponse(response), account);
198ffd0cb04f97e62d286d185c520580d81a9c328b1Fred Quintana                if (result != null) {
199ffd0cb04f97e62d286d185c520580d81a9c328b1Fred Quintana                    response.onResult(result);
200ffd0cb04f97e62d286d185c520580d81a9c328b1Fred Quintana                }
201ffd0cb04f97e62d286d185c520580d81a9c328b1Fred Quintana            } catch (UnsupportedOperationException e) {
202ffd0cb04f97e62d286d185c520580d81a9c328b1Fred Quintana                response.onError(Constants.ERROR_CODE_UNSUPPORTED_OPERATION,
203ffd0cb04f97e62d286d185c520580d81a9c328b1Fred Quintana                        "getAccountRemovalAllowed not supported");
204ffd0cb04f97e62d286d185c520580d81a9c328b1Fred Quintana                return;
205ffd0cb04f97e62d286d185c520580d81a9c328b1Fred Quintana            } catch (NetworkErrorException e) {
206ffd0cb04f97e62d286d185c520580d81a9c328b1Fred Quintana                response.onError(Constants.ERROR_CODE_NETWORK_ERROR, e.getMessage());
207ffd0cb04f97e62d286d185c520580d81a9c328b1Fred Quintana                return;
208ffd0cb04f97e62d286d185c520580d81a9c328b1Fred Quintana            }
209ffd0cb04f97e62d286d185c520580d81a9c328b1Fred Quintana        }
210603073430bbcb1bd29db7afb9b14e2732ad589fbFred Quintana    }
211603073430bbcb1bd29db7afb9b14e2732ad589fbFred Quintana
212d4a1d2e14297a3387fdb5761090961e714370492Fred Quintana    private void checkBinderPermission() {
213d4a1d2e14297a3387fdb5761090961e714370492Fred Quintana        final int uid = Binder.getCallingUid();
214d4a1d2e14297a3387fdb5761090961e714370492Fred Quintana        final String perm = Manifest.permission.ACCOUNT_MANAGER_SERVICE;
215d4a1d2e14297a3387fdb5761090961e714370492Fred Quintana        if (mContext.checkCallingOrSelfPermission(perm) != PackageManager.PERMISSION_GRANTED) {
216d4a1d2e14297a3387fdb5761090961e714370492Fred Quintana            throw new SecurityException("caller uid " + uid + " lacks " + perm);
217d4a1d2e14297a3387fdb5761090961e714370492Fred Quintana        }
218d4a1d2e14297a3387fdb5761090961e714370492Fred Quintana    }
219d4a1d2e14297a3387fdb5761090961e714370492Fred Quintana
220603073430bbcb1bd29db7afb9b14e2732ad589fbFred Quintana    Transport mTransport = new Transport();
221603073430bbcb1bd29db7afb9b14e2732ad589fbFred Quintana
222603073430bbcb1bd29db7afb9b14e2732ad589fbFred Quintana    /**
223603073430bbcb1bd29db7afb9b14e2732ad589fbFred Quintana     * @return the IAccountAuthenticator binder transport object
224603073430bbcb1bd29db7afb9b14e2732ad589fbFred Quintana     */
225603073430bbcb1bd29db7afb9b14e2732ad589fbFred Quintana    public final IAccountAuthenticator getIAccountAuthenticator()
226603073430bbcb1bd29db7afb9b14e2732ad589fbFred Quintana    {
227603073430bbcb1bd29db7afb9b14e2732ad589fbFred Quintana        return mTransport;
228603073430bbcb1bd29db7afb9b14e2732ad589fbFred Quintana    }
229603073430bbcb1bd29db7afb9b14e2732ad589fbFred Quintana
230603073430bbcb1bd29db7afb9b14e2732ad589fbFred Quintana    /**
231a698f4276968d078b1b9e2f3738c4f559a3307b2Fred Quintana     * Returns a Bundle that contains the Intent of the activity that can be used to edit the
232a698f4276968d078b1b9e2f3738c4f559a3307b2Fred Quintana     * properties. In order to indicate success the activity should call response.setResult()
233a698f4276968d078b1b9e2f3738c4f559a3307b2Fred Quintana     * with a non-null Bundle.
234a698f4276968d078b1b9e2f3738c4f559a3307b2Fred Quintana     * @param response used to set the result for the request. If the Constants.INTENT_KEY
235a698f4276968d078b1b9e2f3738c4f559a3307b2Fred Quintana     *   is set in the bundle then this response field is to be used for sending future
236a698f4276968d078b1b9e2f3738c4f559a3307b2Fred Quintana     *   results if and when the Intent is started.
237a698f4276968d078b1b9e2f3738c4f559a3307b2Fred Quintana     * @param accountType the AccountType whose properties are to be edited.
238a698f4276968d078b1b9e2f3738c4f559a3307b2Fred Quintana     * @return a Bundle containing the result or the Intent to start to continue the request.
239a698f4276968d078b1b9e2f3738c4f559a3307b2Fred Quintana     *   If this is null then the request is considered to still be active and the result should
240a698f4276968d078b1b9e2f3738c4f559a3307b2Fred Quintana     *   sent later using response.
241603073430bbcb1bd29db7afb9b14e2732ad589fbFred Quintana     */
242a698f4276968d078b1b9e2f3738c4f559a3307b2Fred Quintana    public abstract Bundle editProperties(AccountAuthenticatorResponse response,
243a698f4276968d078b1b9e2f3738c4f559a3307b2Fred Quintana            String accountType);
244a698f4276968d078b1b9e2f3738c4f559a3307b2Fred Quintana    public abstract Bundle addAccount(AccountAuthenticatorResponse response, String accountType,
2453326920329cecb57c7ff1fc5c6add5c98aab9ed9Fred Quintana            String authTokenType, String[] requiredFeatures, Bundle options)
2463326920329cecb57c7ff1fc5c6add5c98aab9ed9Fred Quintana            throws NetworkErrorException;
247a698f4276968d078b1b9e2f3738c4f559a3307b2Fred Quintana    /* @deprecated */
248a698f4276968d078b1b9e2f3738c4f559a3307b2Fred Quintana    public abstract boolean confirmPassword(AccountAuthenticatorResponse response,
249a698f4276968d078b1b9e2f3738c4f559a3307b2Fred Quintana            Account account, String password) throws NetworkErrorException;
250a698f4276968d078b1b9e2f3738c4f559a3307b2Fred Quintana    public abstract Bundle confirmCredentials(AccountAuthenticatorResponse response,
251a698f4276968d078b1b9e2f3738c4f559a3307b2Fred Quintana            Account account);
252a698f4276968d078b1b9e2f3738c4f559a3307b2Fred Quintana    public abstract Bundle getAuthToken(AccountAuthenticatorResponse response,
253a698f4276968d078b1b9e2f3738c4f559a3307b2Fred Quintana            Account account, String authTokenType, Bundle loginOptions)
254a698f4276968d078b1b9e2f3738c4f559a3307b2Fred Quintana            throws NetworkErrorException;
255d4a1d2e14297a3387fdb5761090961e714370492Fred Quintana    public abstract String getAuthTokenLabel(String authTokenType);
256a698f4276968d078b1b9e2f3738c4f559a3307b2Fred Quintana    public abstract Bundle updateCredentials(AccountAuthenticatorResponse response,
257a698f4276968d078b1b9e2f3738c4f559a3307b2Fred Quintana            Account account, String authTokenType, Bundle loginOptions);
2583326920329cecb57c7ff1fc5c6add5c98aab9ed9Fred Quintana    public abstract Bundle hasFeatures(AccountAuthenticatorResponse response,
2593326920329cecb57c7ff1fc5c6add5c98aab9ed9Fred Quintana            Account account, String[] features) throws NetworkErrorException;
260ffd0cb04f97e62d286d185c520580d81a9c328b1Fred Quintana    public Bundle getAccountRemovalAllowed(AccountAuthenticatorResponse response,
261ffd0cb04f97e62d286d185c520580d81a9c328b1Fred Quintana            Account account) throws NetworkErrorException {
262ffd0cb04f97e62d286d185c520580d81a9c328b1Fred Quintana        final Bundle result = new Bundle();
263ffd0cb04f97e62d286d185c520580d81a9c328b1Fred Quintana        result.putBoolean(Constants.BOOLEAN_RESULT_KEY, true);
264ffd0cb04f97e62d286d185c520580d81a9c328b1Fred Quintana        return result;
265ffd0cb04f97e62d286d185c520580d81a9c328b1Fred Quintana    }
266603073430bbcb1bd29db7afb9b14e2732ad589fbFred Quintana}
267