Skip to content

Commit 5d42a7d

Browse files
costinmAndroid (Google) Code Review
authored andcommitted
Merge "For consistency with getAuthToken, pass UID/PID for add account. Needed for customizing the add account flow"
2 parents 7a685e8 + b61e8fb commit 5d42a7d

File tree

2 files changed

+36
-32
lines changed

2 files changed

+36
-32
lines changed

core/java/android/accounts/AccountManager.java

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,7 @@ public class AccountManager {
189189
public static final String KEY_ERROR_CODE = "errorCode";
190190
public static final String KEY_ERROR_MESSAGE = "errorMessage";
191191
public static final String KEY_USERDATA = "userdata";
192+
192193
/**
193194
* Authenticators using 'customTokens' option will also get the UID of the
194195
* caller
@@ -814,11 +815,13 @@ public AccountManagerFuture<Bundle> getAuthToken(
814815
final Activity activity, AccountManagerCallback<Bundle> callback, Handler handler) {
815816
if (account == null) throw new IllegalArgumentException("account is null");
816817
if (authTokenType == null) throw new IllegalArgumentException("authTokenType is null");
818+
final Bundle optionsIn = options == null ? new Bundle() : options;
819+
optionsIn.putString(KEY_ANDROID_PACKAGE_NAME, mContext.getPackageName());
817820
return new AmsTask(activity, handler, callback) {
818821
public void doWork() throws RemoteException {
819822
mService.getAuthToken(mResponse, account, authTokenType,
820823
false /* notifyOnAuthFailure */, true /* expectActivityLaunch */,
821-
options);
824+
optionsIn);
822825
}
823826
}.start();
824827
}
@@ -895,16 +898,11 @@ public void doWork() throws RemoteException {
895898
*/
896899
@Deprecated
897900
public AccountManagerFuture<Bundle> getAuthToken(
898-
final Account account, final String authTokenType, final boolean notifyAuthFailure,
901+
final Account account, final String authTokenType,
902+
final boolean notifyAuthFailure,
899903
AccountManagerCallback<Bundle> callback, Handler handler) {
900-
if (account == null) throw new IllegalArgumentException("account is null");
901-
if (authTokenType == null) throw new IllegalArgumentException("authTokenType is null");
902-
return new AmsTask(null, handler, callback) {
903-
public void doWork() throws RemoteException {
904-
mService.getAuthToken(mResponse, account, authTokenType,
905-
notifyAuthFailure, false /* expectActivityLaunch */, null /* options */);
906-
}
907-
}.start();
904+
return getAuthToken(account, authTokenType, null, notifyAuthFailure, callback,
905+
handler);
908906
}
909907

910908
/**
@@ -978,15 +976,18 @@ public void doWork() throws RemoteException {
978976
* account before requesting an auth token.
979977
*/
980978
public AccountManagerFuture<Bundle> getAuthToken(
981-
final Account account, final String authTokenType,
982-
final Bundle options, final boolean notifyAuthFailure,
979+
final Account account, final String authTokenType, final Bundle options,
980+
final boolean notifyAuthFailure,
983981
AccountManagerCallback<Bundle> callback, Handler handler) {
982+
984983
if (account == null) throw new IllegalArgumentException("account is null");
985984
if (authTokenType == null) throw new IllegalArgumentException("authTokenType is null");
985+
final Bundle optionsIn = options == null ? new Bundle() : options;
986+
optionsIn.putString(KEY_ANDROID_PACKAGE_NAME, mContext.getPackageName());
986987
return new AmsTask(null, handler, callback) {
987988
public void doWork() throws RemoteException {
988989
mService.getAuthToken(mResponse, account, authTokenType,
989-
notifyAuthFailure, false /* expectActivityLaunch */, options);
990+
notifyAuthFailure, false /* expectActivityLaunch */, optionsIn);
990991
}
991992
}.start();
992993
}
@@ -1044,10 +1045,14 @@ public AccountManagerFuture<Bundle> addAccount(final String accountType,
10441045
final Bundle addAccountOptions,
10451046
final Activity activity, AccountManagerCallback<Bundle> callback, Handler handler) {
10461047
if (accountType == null) throw new IllegalArgumentException("accountType is null");
1048+
final Bundle options = (addAccountOptions == null) ? new Bundle() :
1049+
addAccountOptions;
1050+
options.putString(KEY_ANDROID_PACKAGE_NAME, mContext.getPackageName());
1051+
10471052
return new AmsTask(activity, handler, callback) {
10481053
public void doWork() throws RemoteException {
10491054
mService.addAcount(mResponse, accountType, authTokenType,
1050-
requiredFeatures, activity != null, addAccountOptions);
1055+
requiredFeatures, activity != null, options);
10511056
}
10521057
}.start();
10531058
}

core/java/android/accounts/AccountManagerService.java

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,6 @@
1616

1717
package android.accounts;
1818

19-
import com.android.internal.R;
20-
import com.android.internal.telephony.ITelephony;
21-
import com.android.internal.telephony.TelephonyIntents;
22-
2319
import android.Manifest;
2420
import android.app.ActivityManager;
2521
import android.app.Notification;
@@ -51,13 +47,13 @@
5147
import android.os.Looper;
5248
import android.os.Message;
5349
import android.os.RemoteException;
54-
import android.os.ServiceManager;
5550
import android.os.SystemClock;
56-
import android.telephony.TelephonyManager;
5751
import android.text.TextUtils;
5852
import android.util.Log;
5953
import android.util.Pair;
6054

55+
import com.android.internal.R;
56+
6157
import java.io.File;
6258
import java.io.FileDescriptor;
6359
import java.io.PrintWriter;
@@ -924,30 +920,26 @@ public void getAuthToken(IAccountManagerResponse response, final Account account
924920
if (account == null) throw new IllegalArgumentException("account is null");
925921
if (authTokenType == null) throw new IllegalArgumentException("authTokenType is null");
926922
checkBinderPermission(Manifest.permission.USE_CREDENTIALS);
927-
final int callerUid = Binder.getCallingUid();
928-
final int callerPid = Binder.getCallingPid();
929-
930923
AccountAuthenticatorCache.ServiceInfo<AuthenticatorDescription> authenticatorInfo =
931924
mAuthenticatorCache.getServiceInfo(
932925
AuthenticatorDescription.newKey(account.type));
933926
final boolean customTokens =
934927
authenticatorInfo != null && authenticatorInfo.type.customTokens;
935928

936929
// skip the check if customTokens
930+
final int callerUid = Binder.getCallingUid();
937931
final boolean permissionGranted = customTokens ||
938932
permissionIsGranted(account, authTokenType, callerUid);
939933

940934
final Bundle loginOptions = (loginOptionsIn == null) ? new Bundle() :
941935
loginOptionsIn;
942-
if (customTokens) {
943-
// let authenticator know the identity of the caller
944-
loginOptions.putInt(AccountManager.KEY_CALLER_UID, callerUid);
945-
loginOptions.putInt(AccountManager.KEY_CALLER_PID, callerPid);
946-
if (notifyOnAuthFailure) {
947-
loginOptions.putBoolean(AccountManager.KEY_NOTIFY_ON_FAILURE, true);
948-
}
936+
// let authenticator know the identity of the caller
937+
loginOptions.putInt(AccountManager.KEY_CALLER_UID, callerUid);
938+
loginOptions.putInt(AccountManager.KEY_CALLER_PID, Binder.getCallingPid());
939+
if (notifyOnAuthFailure) {
940+
loginOptions.putBoolean(AccountManager.KEY_NOTIFY_ON_FAILURE, true);
949941
}
950-
942+
951943
long identityToken = clearCallingIdentity();
952944
try {
953945
// if the caller has permission, do the peek. otherwise go the more expensive
@@ -1120,7 +1112,7 @@ private Integer getSigninRequiredNotificationId(Account account) {
11201112

11211113
public void addAcount(final IAccountManagerResponse response, final String accountType,
11221114
final String authTokenType, final String[] requiredFeatures,
1123-
final boolean expectActivityLaunch, final Bundle options) {
1115+
final boolean expectActivityLaunch, final Bundle optionsIn) {
11241116
if (Log.isLoggable(TAG, Log.VERBOSE)) {
11251117
Log.v(TAG, "addAccount: accountType " + accountType
11261118
+ ", response " + response
@@ -1133,6 +1125,13 @@ public void addAcount(final IAccountManagerResponse response, final String accou
11331125
if (response == null) throw new IllegalArgumentException("response is null");
11341126
if (accountType == null) throw new IllegalArgumentException("accountType is null");
11351127
checkManageAccountsPermission();
1128+
1129+
final int pid = Binder.getCallingPid();
1130+
final int uid = Binder.getCallingUid();
1131+
final Bundle options = (optionsIn == null) ? new Bundle() : optionsIn;
1132+
options.putInt(AccountManager.KEY_CALLER_UID, uid);
1133+
options.putInt(AccountManager.KEY_CALLER_PID, pid);
1134+
11361135
long identityToken = clearCallingIdentity();
11371136
try {
11381137
new Session(response, accountType, expectActivityLaunch,

0 commit comments

Comments
 (0)