Skip to content

Commit b37bca9

Browse files
egnorAndroid (Google) Code Review
authored andcommitted
Merge "COMMENT ONLY change to fix some formatting glitches and (more importantly) clarify issues surrounding removed accounts." into froyo
2 parents 9093717 + 8e4378b commit b37bca9

File tree

1 file changed

+73
-69
lines changed

1 file changed

+73
-69
lines changed

core/java/android/accounts/AccountManager.java

Lines changed: 73 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -45,26 +45,26 @@
4545

4646
/**
4747
* This class provides access to a centralized registry of the user's
48-
* online accounts. With this service, users only need to enter their
49-
* credentials (username and password) once for any account, granting
50-
* applications access to online resources with "one-click" approval.
48+
* online accounts. The user enters credentials (username and password) once
49+
* per account, granting applications access to online resources with
50+
* "one-click" approval.
5151
*
5252
* <p>Different online services have different ways of handling accounts and
5353
* authentication, so the account manager uses pluggable <em>authenticator</em>
54-
* modules for different <em>account types</em>. The authenticators (which
55-
* may be written by third parties) handle the actual details of validating
56-
* account credentials and storing account information. For example, Google,
57-
* Facebook, and Microsoft Exchange each have their own authenticator.
54+
* modules for different <em>account types</em>. Authenticators (which may be
55+
* written by third parties) handle the actual details of validating account
56+
* credentials and storing account information. For example, Google, Facebook,
57+
* and Microsoft Exchange each have their own authenticator.
5858
*
5959
* <p>Many servers support some notion of an <em>authentication token</em>,
6060
* which can be used to authenticate a request to the server without sending
6161
* the user's actual password. (Auth tokens are normally created with a
6262
* separate request which does include the user's credentials.) AccountManager
63-
* can generate these auth tokens for applications, so the application doesn't
64-
* need to handle passwords directly. Auth tokens are normally reusable, and
65-
* cached by AccountManager, but must be refreshed periodically. It's the
66-
* responsibility of applications to <em>invalidate</em> auth tokens when they
67-
* stop working so the AccountManager knows it needs to regenerate them.
63+
* can generate auth tokens for applications, so the application doesn't need to
64+
* handle passwords directly. Auth tokens are normally reusable and cached by
65+
* AccountManager, but must be refreshed periodically. It's the responsibility
66+
* of applications to <em>invalidate</em> auth tokens when they stop working so
67+
* the AccountManager knows it needs to regenerate them.
6868
*
6969
* <p>Applications accessing a server normally go through these steps:
7070
*
@@ -84,14 +84,19 @@
8484
* {@link #addAccount} may be called to prompt the user to create an
8585
* account of the appropriate type.
8686
*
87+
* <li><b>Important:</b> If the application is using a previously remembered
88+
* account selection, it must make sure the account is still in the list
89+
* of accounts returned by {@link #getAccountsByType}. Requesting an auth token
90+
* for an account no longer on the device results in an undefined failure.
91+
*
8792
* <li>Request an auth token for the selected account(s) using one of the
8893
* {@link #getAuthToken} methods or related helpers. Refer to the description
8994
* of each method for exact usage and error handling details.
9095
*
9196
* <li>Make the request using the auth token. The form of the auth token,
9297
* the format of the request, and the protocol used are all specific to the
93-
* service you are accessing. The application makes the request itself, using
94-
* whatever network and protocol libraries are useful.
98+
* service you are accessing. The application may use whatever network and
99+
* protocol libraries are useful.
95100
*
96101
* <li><b>Important:</b> If the request fails with an authentication error,
97102
* it could be that a cached auth token is stale and no longer honored by
@@ -103,7 +108,7 @@
103108
* appropriate actions taken.
104109
* </ul>
105110
*
106-
* <p>Some AccountManager methods may require interaction with the user to
111+
* <p>Some AccountManager methods may need to interact with the user to
107112
* prompt for credentials, present options, or ask the user to add an account.
108113
* The caller may choose whether to allow AccountManager to directly launch the
109114
* necessary user interface and wait for the user, or to return an Intent which
@@ -113,18 +118,17 @@
113118
* the current foreground {@link Activity} context.
114119
*
115120
* <p>Many AccountManager methods take {@link AccountManagerCallback} and
116-
* {@link Handler} as parameters. These methods return immediately but
121+
* {@link Handler} as parameters. These methods return immediately and
117122
* run asynchronously. If a callback is provided then
118123
* {@link AccountManagerCallback#run} will be invoked on the Handler's
119124
* thread when the request completes, successfully or not.
120-
* An {@link AccountManagerFuture} is returned by these requests and also
121-
* supplied to the callback (if any). The result is retrieved by calling
122-
* {@link AccountManagerFuture#getResult()} which waits for the operation
123-
* to complete (if necessary) and either returns the result or throws an
124-
* exception if an error occurred during the operation.
125-
* To make the request synchronously, call
125+
* The result is retrieved by calling {@link AccountManagerFuture#getResult()}
126+
* on the {@link AccountManagerFuture} returned by the method (and also passed
127+
* to the callback). This method waits for the operation to complete (if
128+
* necessary) and either returns the result or throws an exception if an error
129+
* occurred during the operation. To make the request synchronously, call
126130
* {@link AccountManagerFuture#getResult()} immediately on receiving the
127-
* future from the method. No callback need be supplied.
131+
* future from the method; no callback need be supplied.
128132
*
129133
* <p>Requests which may block, including
130134
* {@link AccountManagerFuture#getResult()}, must never be called on
@@ -143,32 +147,32 @@ public class AccountManager {
143147
public static final int ERROR_CODE_BAD_REQUEST = 8;
144148

145149
/**
146-
* The Bundle key used for the {@link String} account name in results
150+
* Bundle key used for the {@link String} account name in results
147151
* from methods which return information about a particular account.
148152
*/
149153
public static final String KEY_ACCOUNT_NAME = "authAccount";
150154

151155
/**
152-
* The Bundle key used for the {@link String} account type in results
156+
* Bundle key used for the {@link String} account type in results
153157
* from methods which return information about a particular account.
154158
*/
155159
public static final String KEY_ACCOUNT_TYPE = "accountType";
156160

157161
/**
158-
* The Bundle key used for the auth token value in results
162+
* Bundle key used for the auth token value in results
159163
* from {@link #getAuthToken} and friends.
160164
*/
161165
public static final String KEY_AUTHTOKEN = "authtoken";
162166

163167
/**
164-
* The Bundle key used for an {@link Intent} in results from methods that
168+
* Bundle key used for an {@link Intent} in results from methods that
165169
* may require the caller to interact with the user. The Intent can
166170
* be used to start the corresponding user interface activity.
167171
*/
168172
public static final String KEY_INTENT = "intent";
169173

170174
/**
171-
* The Bundle key used to supply the password directly in options to
175+
* Bundle key used to supply the password directly in options to
172176
* {@link #confirmCredentials}, rather than prompting the user with
173177
* the standard password prompt.
174178
*/
@@ -476,7 +480,7 @@ public Account[] bundleToResult(Bundle bundle) throws AuthenticatorException {
476480
* @param account The {@link Account} to add
477481
* @param password The password to associate with the account, null for none
478482
* @param userdata String values to use for the account's userdata, null for none
479-
* @return Whether the account was successfully added. False if the account
483+
* @return True if the account was successfully added, false if the account
480484
* already exists, the account is null, or another error occurs.
481485
*/
482486
public boolean addAccountExplicitly(Account account, String password, Bundle userdata) {
@@ -733,15 +737,14 @@ public String blockingGetAuthToken(Account account, String authTokenType,
733737
* sense to ask the user directly for a password.
734738
*
735739
* <p>If a previously generated auth token is cached for this account and
736-
* type, then it will be returned. Otherwise, if we have a saved password
737-
* the server accepts, it will be used to generate a new auth token.
738-
* Otherwise, the user will be asked for a password, which will be sent to
739-
* the server to generate a new auth token.
740+
* type, then it is returned. Otherwise, if a saved password is
741+
* available, it is sent to the server to generate a new auth token.
742+
* Otherwise, the user is prompted to enter a password.
740743
*
741-
* <p>The value of the auth token type depends on the authenticator.
742-
* Some services use different tokens to access different functionality --
743-
* for example, Google uses different auth tokens to access Gmail and
744-
* Google Calendar for the same account.
744+
* <p>Some authenticators have auth token <em>types</em>, whose value
745+
* is authenticator-dependent. Some services use different token types to
746+
* access different functionality -- for example, Google uses different auth
747+
* tokens to access Gmail and Google Calendar for the same account.
745748
*
746749
* <p>This method may be called from any thread, but the returned
747750
* {@link AccountManagerFuture} must not be used on the main thread.
@@ -778,6 +781,9 @@ public String blockingGetAuthToken(Account account, String authTokenType,
778781
* <li> {@link IOException} if the authenticator experienced an I/O problem
779782
* creating a new auth token, usually because of network trouble
780783
* </ul>
784+
* If the account is no longer present on the device, the return value is
785+
* authenticator-dependent. The caller should verify the validity of the
786+
* account before requesting an auth token.
781787
*/
782788
public AccountManagerFuture<Bundle> getAuthToken(
783789
final Account account, final String authTokenType, final Bundle options,
@@ -800,29 +806,27 @@ public void doWork() throws RemoteException {
800806
* user should not be immediately interrupted with a password prompt.
801807
*
802808
* <p>If a previously generated auth token is cached for this account and
803-
* type, then it will be returned. Otherwise, if we have saved credentials
804-
* the server accepts, it will be used to generate a new auth token.
805-
* Otherwise, an Intent will be returned which, when started, will prompt
806-
* the user for a password. If the notifyAuthFailure parameter is set,
807-
* the same Intent will be associated with a status bar notification,
809+
* type, then it is returned. Otherwise, if a saved password is
810+
* available, it is sent to the server to generate a new auth token.
811+
* Otherwise, an {@link Intent} is returned which, when started, will
812+
* prompt the user for a password. If the notifyAuthFailure parameter is
813+
* set, a status bar notification is also created with the same Intent,
808814
* alerting the user that they need to enter a password at some point.
809815
*
810-
* <p>If the intent is left in a notification, you will need to wait until
811-
* the user gets around to entering a password before trying again,
812-
* which could be hours or days or never. When it does happen, the
813-
* account manager will broadcast the {@link #LOGIN_ACCOUNTS_CHANGED_ACTION}
814-
* {@link Intent}, which applications can use to trigger another attempt
815-
* to fetch an auth token.
816+
* <p>In that case, you may need to wait until the user responds, which
817+
* could take hours or days or forever. When the user does respond and
818+
* supply a new password, the account manager will broadcast the
819+
* {@link #LOGIN_ACCOUNTS_CHANGED_ACTION} Intent, which applications can
820+
* use to try again.
816821
*
817-
* <p>If notifications are not enabled, it is the application's
818-
* responsibility to launch the returned intent at some point to let
819-
* the user enter credentials. In either case, the result from this
820-
* call will not wait for user action.
822+
* <p>If notifyAuthFailure is not set, it is the application's
823+
* responsibility to launch the returned Intent at some point.
824+
* Either way, the result from this call will not wait for user action.
821825
*
822-
* <p>The value of the auth token type depends on the authenticator.
823-
* Some services use different tokens to access different functionality --
824-
* for example, Google uses different auth tokens to access Gmail and
825-
* Google Calendar for the same account.
826+
* <p>Some authenticators have auth token <em>types</em>, whose value
827+
* is authenticator-dependent. Some services use different token types to
828+
* access different functionality -- for example, Google uses different auth
829+
* tokens to access Gmail and Google Calendar for the same account.
826830
*
827831
* <p>This method may be called from any thread, but the returned
828832
* {@link AccountManagerFuture} must not be used on the main thread.
@@ -851,14 +855,17 @@ public void doWork() throws RemoteException {
851855
* must enter credentials, the returned Bundle contains only
852856
* {@link #KEY_INTENT} with the {@link Intent} needed to launch a prompt.
853857
*
854-
* <p>If an error occurred, {@link AccountManagerFuture#getResult()} throws:
858+
* If an error occurred, {@link AccountManagerFuture#getResult()} throws:
855859
* <ul>
856860
* <li> {@link AuthenticatorException} if the authenticator failed to respond
857861
* <li> {@link OperationCanceledException} if the operation is canceled for
858862
* any reason, incluidng the user canceling a credential request
859863
* <li> {@link IOException} if the authenticator experienced an I/O problem
860864
* creating a new auth token, usually because of network trouble
861865
* </ul>
866+
* If the account is no longer present on the device, the return value is
867+
* authenticator-dependent. The caller should verify the validity of the
868+
* account before requesting an auth token.
862869
*/
863870
public AccountManagerFuture<Bundle> getAuthToken(
864871
final Account account, final String authTokenType, final boolean notifyAuthFailure,
@@ -910,9 +917,8 @@ public void doWork() throws RemoteException {
910917
*
911918
* If no activity was specified, the returned Bundle contains only
912919
* {@link #KEY_INTENT} with the {@link Intent} needed to launch the
913-
* actual account creation process.
914-
*
915-
* <p>If an error occurred, {@link AccountManagerFuture#getResult()} throws:
920+
* actual account creation process. If an error occurred,
921+
* {@link AccountManagerFuture#getResult()} throws:
916922
* <ul>
917923
* <li> {@link AuthenticatorException} if no authenticator was registered for
918924
* this account type or the authenticator failed to respond
@@ -979,9 +985,8 @@ public void doWork() throws RemoteException {
979985
*
980986
* If no activity or password was specified, the returned Bundle contains
981987
* only {@link #KEY_INTENT} with the {@link Intent} needed to launch the
982-
* password prompt.
983-
*
984-
* <p>If an error occurred, {@link AccountManagerFuture#getResult()} throws:
988+
* password prompt. If an error occurred,
989+
* {@link AccountManagerFuture#getResult()} throws:
985990
* <ul>
986991
* <li> {@link AuthenticatorException} if the authenticator failed to respond
987992
* <li> {@link OperationCanceledException} if the operation was canceled for
@@ -1040,9 +1045,8 @@ public void doWork() throws RemoteException {
10401045
*
10411046
* If no activity was specified, the returned Bundle contains only
10421047
* {@link #KEY_INTENT} with the {@link Intent} needed to launch the
1043-
* password prompt.
1044-
*
1045-
* <p>If an error occurred, {@link AccountManagerFuture#getResult()} throws:
1048+
* password prompt. If an error occurred,
1049+
* {@link AccountManagerFuture#getResult()} throws:
10461050
* <ul>
10471051
* <li> {@link AuthenticatorException} if the authenticator failed to respond
10481052
* <li> {@link OperationCanceledException} if the operation was canceled for
@@ -1091,8 +1095,8 @@ public void doWork() throws RemoteException {
10911095
* which is empty if properties were edited successfully, or
10921096
* if no activity was specified, contains only {@link #KEY_INTENT}
10931097
* needed to launch the authenticator's settings dialog.
1094-
*
1095-
* <p>If an error occurred, {@link AccountManagerFuture#getResult()} throws:
1098+
* If an error occurred, {@link AccountManagerFuture#getResult()}
1099+
* throws:
10961100
* <ul>
10971101
* <li> {@link AuthenticatorException} if no authenticator was registered for
10981102
* this account type or the authenticator failed to respond
@@ -1617,7 +1621,7 @@ public void run(AccountManagerFuture<Bundle> future) {
16171621
* <li> {@link #KEY_AUTHTOKEN} - the auth token you wanted
16181622
* </ul>
16191623
*
1620-
* <p>If an error occurred, {@link AccountManagerFuture#getResult()} throws:
1624+
* If an error occurred, {@link AccountManagerFuture#getResult()} throws:
16211625
* <ul>
16221626
* <li> {@link AuthenticatorException} if no authenticator was registered for
16231627
* this account type or the authenticator failed to respond

0 commit comments

Comments
 (0)