AbstractAccountAuthenticator.java revision 603073430bbcb1bd29db7afb9b14e2732ad589fb
1/*
2 * Copyright (C) 2009 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 *      http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package android.accounts;
18
19import android.os.RemoteException;
20
21/**
22 * Base class for creating AccountAuthenticators. This implements the IAccountAuthenticator
23 * binder interface and also provides helper libraries to simplify the creation of
24 * AccountAuthenticators.
25 */
26public abstract class AbstractAccountAuthenticator {
27    private static final String TAG = "AccountAuthenticator";
28
29    class Transport extends IAccountAuthenticator.Stub {
30        public void addAccount(IAccountAuthenticatorResponse response, String accountType)
31                throws RemoteException {
32            AbstractAccountAuthenticator.this.addAccount(new AccountAuthenticatorResponse(response),
33                    accountType);
34        }
35
36        public void authenticateAccount(IAccountAuthenticatorResponse
37                response, String name, String type, String password)
38                throws RemoteException {
39            AbstractAccountAuthenticator.this.authenticateAccount(
40                    new AccountAuthenticatorResponse(response), new Account(name, type), password);
41        }
42
43        public void getAuthToken(IAccountAuthenticatorResponse response,
44                String name, String type, String authTokenType)
45                throws RemoteException {
46            AbstractAccountAuthenticator.this.getAuthToken(
47                    new AccountAuthenticatorResponse(response),
48                    new Account(name, type), authTokenType);
49        }
50
51        public void getPasswordStrength(IAccountAuthenticatorResponse response,
52                String accountType, String password)
53                throws RemoteException {
54            AbstractAccountAuthenticator.this.getPasswordStrength(
55                    new AccountAuthenticatorResponse(response), accountType, password);
56        }
57
58        public void checkUsernameExistence(IAccountAuthenticatorResponse response,
59                String accountType, String username)
60                throws RemoteException {
61            AbstractAccountAuthenticator.this.checkUsernameExistence(
62                    new AccountAuthenticatorResponse(response), accountType, username);
63        }
64
65        public void updatePassword(IAccountAuthenticatorResponse response, String name, String type)
66                throws RemoteException {
67            AbstractAccountAuthenticator.this.updatePassword(
68                    new AccountAuthenticatorResponse(response), new Account(name, type));
69        }
70
71        public void editProperties(IAccountAuthenticatorResponse response, String accountType)
72                throws RemoteException {
73            AbstractAccountAuthenticator.this.editProperties(
74                    new AccountAuthenticatorResponse(response), accountType);
75        }
76    }
77
78    Transport mTransport = new Transport();
79
80    /**
81     * @return the IAccountAuthenticator binder transport object
82     */
83    public final IAccountAuthenticator getIAccountAuthenticator()
84    {
85        return mTransport;
86    }
87
88    /**
89     * prompts the user for account information and adds the result to the IAccountManager
90     */
91    public abstract void addAccount(AccountAuthenticatorResponse response, String accountType);
92
93    /**
94     * prompts the user for the credentials of the account
95     */
96    public abstract void authenticateAccount(AccountAuthenticatorResponse response,
97            Account account, String password);
98
99    /**
100     * gets the password by either prompting the user or querying the IAccountManager
101     */
102    public abstract void getAuthToken(AccountAuthenticatorResponse response,
103            Account account, String authTokenType);
104
105    /**
106     * does local analysis or uses a service in the cloud
107     */
108    public abstract void getPasswordStrength(AccountAuthenticatorResponse response,
109        String accountType, String password);
110
111    /**
112     * checks with the login service in the cloud
113     */
114    public abstract void checkUsernameExistence(AccountAuthenticatorResponse response,
115        String accountType, String username);
116
117    /**
118     * prompts the user for a new password and writes it to the IAccountManager
119     */
120    public abstract void updatePassword(AccountAuthenticatorResponse response, Account account);
121
122    /**
123     * launches an activity that lets the user edit and set the properties for an authenticator
124     */
125    public abstract void editProperties(AccountAuthenticatorResponse response, String accountType);
126}
127