Skip to content

Commit 7cbfa97

Browse files
fredquintanaAndroid (Google) Code Review
authored andcommitted
Merge "Add a form of getAuthToken that both accepts an options Bundle and doesn't accepts an activity."
2 parents a6f61c5 + ad93a32 commit 7cbfa97

File tree

2 files changed

+100
-1
lines changed

2 files changed

+100
-1
lines changed

api/current.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2075,7 +2075,8 @@ package android.accounts {
20752075
method public android.accounts.Account[] getAccountsByType(java.lang.String);
20762076
method public android.accounts.AccountManagerFuture<android.accounts.Account[]> getAccountsByTypeAndFeatures(java.lang.String, java.lang.String[], android.accounts.AccountManagerCallback<android.accounts.Account[]>, android.os.Handler);
20772077
method public android.accounts.AccountManagerFuture<android.os.Bundle> getAuthToken(android.accounts.Account, java.lang.String, android.os.Bundle, android.app.Activity, android.accounts.AccountManagerCallback<android.os.Bundle>, android.os.Handler);
2078-
method public android.accounts.AccountManagerFuture<android.os.Bundle> getAuthToken(android.accounts.Account, java.lang.String, boolean, android.accounts.AccountManagerCallback<android.os.Bundle>, android.os.Handler);
2078+
method public deprecated android.accounts.AccountManagerFuture<android.os.Bundle> getAuthToken(android.accounts.Account, java.lang.String, boolean, android.accounts.AccountManagerCallback<android.os.Bundle>, android.os.Handler);
2079+
method public android.accounts.AccountManagerFuture<android.os.Bundle> getAuthToken(android.accounts.Account, java.lang.String, android.os.Bundle, boolean, android.accounts.AccountManagerCallback<android.os.Bundle>, android.os.Handler);
20792080
method public android.accounts.AccountManagerFuture<android.os.Bundle> getAuthTokenByFeatures(java.lang.String, java.lang.String, java.lang.String[], android.app.Activity, android.os.Bundle, android.os.Bundle, android.accounts.AccountManagerCallback<android.os.Bundle>, android.os.Handler);
20802081
method public android.accounts.AuthenticatorDescription[] getAuthenticatorTypes();
20812082
method public java.lang.String getPassword(android.accounts.Account);
@@ -2104,6 +2105,7 @@ package android.accounts {
21042105
field public static final java.lang.String KEY_ACCOUNT_MANAGER_RESPONSE = "accountManagerResponse";
21052106
field public static final java.lang.String KEY_ACCOUNT_NAME = "authAccount";
21062107
field public static final java.lang.String KEY_ACCOUNT_TYPE = "accountType";
2108+
field public static final java.lang.String KEY_ANDROID_PACKAGE_NAME = "androidPackageName";
21072109
field public static final java.lang.String KEY_AUTHENTICATOR_TYPES = "authenticator_types";
21082110
field public static final java.lang.String KEY_AUTHTOKEN = "authtoken";
21092111
field public static final java.lang.String KEY_AUTH_FAILED_MESSAGE = "authFailedMessage";

core/java/android/accounts/AccountManager.java

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,16 @@ public class AccountManager {
196196
public static final String KEY_CALLER_UID = "callerUid";
197197
public static final String KEY_CALLER_PID = "callerPid";
198198

199+
/**
200+
* The Android package of the caller will be set in the options bundle by the
201+
* {@link AccountManager} and will be passed to the AccountManagerService and
202+
* to the AccountAuthenticators. The uid of the caller will be known by the
203+
* AccountManagerService as well as the AccountAuthenticators so they will be able to
204+
* verify that the package is consistent with the uid (a uid might be shared by many
205+
* packages).
206+
*/
207+
public static final String KEY_ANDROID_PACKAGE_NAME = "androidPackageName";
208+
199209
/**
200210
* Boolean, if set and 'customTokens' the authenticator is responsible for
201211
* notifications.
@@ -880,7 +890,10 @@ public void doWork() throws RemoteException {
880890
* If the account is no longer present on the device, the return value is
881891
* authenticator-dependent. The caller should verify the validity of the
882892
* account before requesting an auth token.
893+
* @deprecated use {@link #getAuthToken(Account, String, android.os.Bundle,
894+
* boolean, AccountManagerCallback, android.os.Handler)} instead
883895
*/
896+
@Deprecated
884897
public AccountManagerFuture<Bundle> getAuthToken(
885898
final Account account, final String authTokenType, final boolean notifyAuthFailure,
886899
AccountManagerCallback<Bundle> callback, Handler handler) {
@@ -894,6 +907,90 @@ public void doWork() throws RemoteException {
894907
}.start();
895908
}
896909

910+
/**
911+
* Gets an auth token of the specified type for a particular account,
912+
* optionally raising a notification if the user must enter credentials.
913+
* This method is intended for background tasks and services where the
914+
* user should not be immediately interrupted with a password prompt.
915+
*
916+
* <p>If a previously generated auth token is cached for this account and
917+
* type, then it is returned. Otherwise, if a saved password is
918+
* available, it is sent to the server to generate a new auth token.
919+
* Otherwise, an {@link Intent} is returned which, when started, will
920+
* prompt the user for a password. If the notifyAuthFailure parameter is
921+
* set, a status bar notification is also created with the same Intent,
922+
* alerting the user that they need to enter a password at some point.
923+
*
924+
* <p>In that case, you may need to wait until the user responds, which
925+
* could take hours or days or forever. When the user does respond and
926+
* supply a new password, the account manager will broadcast the
927+
* {@link #LOGIN_ACCOUNTS_CHANGED_ACTION} Intent, which applications can
928+
* use to try again.
929+
*
930+
* <p>If notifyAuthFailure is not set, it is the application's
931+
* responsibility to launch the returned Intent at some point.
932+
* Either way, the result from this call will not wait for user action.
933+
*
934+
* <p>Some authenticators have auth token <em>types</em>, whose value
935+
* is authenticator-dependent. Some services use different token types to
936+
* access different functionality -- for example, Google uses different auth
937+
* tokens to access Gmail and Google Calendar for the same account.
938+
*
939+
* <p>This method may be called from any thread, but the returned
940+
* {@link AccountManagerFuture} must not be used on the main thread.
941+
*
942+
* <p>This method requires the caller to hold the permission
943+
* {@link android.Manifest.permission#USE_CREDENTIALS}.
944+
*
945+
* @param account The account to fetch an auth token for
946+
* @param authTokenType The auth token type, an authenticator-dependent
947+
* string token, must not be null
948+
* @param options Authenticator-specific options for the request,
949+
* may be null or empty
950+
* @param notifyAuthFailure True to add a notification to prompt the
951+
* user for a password if necessary, false to leave that to the caller
952+
* @param callback Callback to invoke when the request completes,
953+
* null for no callback
954+
* @param handler {@link Handler} identifying the callback thread,
955+
* null for the main thread
956+
* @return An {@link AccountManagerFuture} which resolves to a Bundle with
957+
* at least the following fields on success:
958+
* <ul>
959+
* <li> {@link #KEY_ACCOUNT_NAME} - the name of the account you supplied
960+
* <li> {@link #KEY_ACCOUNT_TYPE} - the type of the account
961+
* <li> {@link #KEY_AUTHTOKEN} - the auth token you wanted
962+
* </ul>
963+
*
964+
* (Other authenticator-specific values may be returned.) If the user
965+
* must enter credentials, the returned Bundle contains only
966+
* {@link #KEY_INTENT} with the {@link Intent} needed to launch a prompt.
967+
*
968+
* If an error occurred, {@link AccountManagerFuture#getResult()} throws:
969+
* <ul>
970+
* <li> {@link AuthenticatorException} if the authenticator failed to respond
971+
* <li> {@link OperationCanceledException} if the operation is canceled for
972+
* any reason, incluidng the user canceling a credential request
973+
* <li> {@link IOException} if the authenticator experienced an I/O problem
974+
* creating a new auth token, usually because of network trouble
975+
* </ul>
976+
* If the account is no longer present on the device, the return value is
977+
* authenticator-dependent. The caller should verify the validity of the
978+
* account before requesting an auth token.
979+
*/
980+
public AccountManagerFuture<Bundle> getAuthToken(
981+
final Account account, final String authTokenType,
982+
final Bundle options, final boolean notifyAuthFailure,
983+
AccountManagerCallback<Bundle> callback, Handler handler) {
984+
if (account == null) throw new IllegalArgumentException("account is null");
985+
if (authTokenType == null) throw new IllegalArgumentException("authTokenType is null");
986+
return new AmsTask(null, handler, callback) {
987+
public void doWork() throws RemoteException {
988+
mService.getAuthToken(mResponse, account, authTokenType,
989+
notifyAuthFailure, false /* expectActivityLaunch */, options);
990+
}
991+
}.start();
992+
}
993+
897994
/**
898995
* Asks the user to add an account of a specified type. The authenticator
899996
* for this account type processes this request with the appropriate user

0 commit comments

Comments
 (0)