Merge "For consistency with getAuthToken, pass UID/PID for add account. Needed for customizing the add account flow"
This commit is contained in:
committed by
Android (Google) Code Review
commit
5d42a7df1d
@@ -189,6 +189,7 @@ public class AccountManager {
|
|||||||
public static final String KEY_ERROR_CODE = "errorCode";
|
public static final String KEY_ERROR_CODE = "errorCode";
|
||||||
public static final String KEY_ERROR_MESSAGE = "errorMessage";
|
public static final String KEY_ERROR_MESSAGE = "errorMessage";
|
||||||
public static final String KEY_USERDATA = "userdata";
|
public static final String KEY_USERDATA = "userdata";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Authenticators using 'customTokens' option will also get the UID of the
|
* Authenticators using 'customTokens' option will also get the UID of the
|
||||||
* caller
|
* caller
|
||||||
@@ -814,11 +815,13 @@ public class AccountManager {
|
|||||||
final Activity activity, AccountManagerCallback<Bundle> callback, Handler handler) {
|
final Activity activity, AccountManagerCallback<Bundle> callback, Handler handler) {
|
||||||
if (account == null) throw new IllegalArgumentException("account is null");
|
if (account == null) throw new IllegalArgumentException("account is null");
|
||||||
if (authTokenType == null) throw new IllegalArgumentException("authTokenType is null");
|
if (authTokenType == null) throw new IllegalArgumentException("authTokenType is null");
|
||||||
|
final Bundle optionsIn = options == null ? new Bundle() : options;
|
||||||
|
optionsIn.putString(KEY_ANDROID_PACKAGE_NAME, mContext.getPackageName());
|
||||||
return new AmsTask(activity, handler, callback) {
|
return new AmsTask(activity, handler, callback) {
|
||||||
public void doWork() throws RemoteException {
|
public void doWork() throws RemoteException {
|
||||||
mService.getAuthToken(mResponse, account, authTokenType,
|
mService.getAuthToken(mResponse, account, authTokenType,
|
||||||
false /* notifyOnAuthFailure */, true /* expectActivityLaunch */,
|
false /* notifyOnAuthFailure */, true /* expectActivityLaunch */,
|
||||||
options);
|
optionsIn);
|
||||||
}
|
}
|
||||||
}.start();
|
}.start();
|
||||||
}
|
}
|
||||||
@@ -895,16 +898,11 @@ public class AccountManager {
|
|||||||
*/
|
*/
|
||||||
@Deprecated
|
@Deprecated
|
||||||
public AccountManagerFuture<Bundle> getAuthToken(
|
public AccountManagerFuture<Bundle> getAuthToken(
|
||||||
final Account account, final String authTokenType, final boolean notifyAuthFailure,
|
final Account account, final String authTokenType,
|
||||||
|
final boolean notifyAuthFailure,
|
||||||
AccountManagerCallback<Bundle> callback, Handler handler) {
|
AccountManagerCallback<Bundle> callback, Handler handler) {
|
||||||
if (account == null) throw new IllegalArgumentException("account is null");
|
return getAuthToken(account, authTokenType, null, notifyAuthFailure, callback,
|
||||||
if (authTokenType == null) throw new IllegalArgumentException("authTokenType is null");
|
handler);
|
||||||
return new AmsTask(null, handler, callback) {
|
|
||||||
public void doWork() throws RemoteException {
|
|
||||||
mService.getAuthToken(mResponse, account, authTokenType,
|
|
||||||
notifyAuthFailure, false /* expectActivityLaunch */, null /* options */);
|
|
||||||
}
|
|
||||||
}.start();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -978,15 +976,18 @@ public class AccountManager {
|
|||||||
* account before requesting an auth token.
|
* account before requesting an auth token.
|
||||||
*/
|
*/
|
||||||
public AccountManagerFuture<Bundle> getAuthToken(
|
public AccountManagerFuture<Bundle> getAuthToken(
|
||||||
final Account account, final String authTokenType,
|
final Account account, final String authTokenType, final Bundle options,
|
||||||
final Bundle options, final boolean notifyAuthFailure,
|
final boolean notifyAuthFailure,
|
||||||
AccountManagerCallback<Bundle> callback, Handler handler) {
|
AccountManagerCallback<Bundle> callback, Handler handler) {
|
||||||
|
|
||||||
if (account == null) throw new IllegalArgumentException("account is null");
|
if (account == null) throw new IllegalArgumentException("account is null");
|
||||||
if (authTokenType == null) throw new IllegalArgumentException("authTokenType is null");
|
if (authTokenType == null) throw new IllegalArgumentException("authTokenType is null");
|
||||||
|
final Bundle optionsIn = options == null ? new Bundle() : options;
|
||||||
|
optionsIn.putString(KEY_ANDROID_PACKAGE_NAME, mContext.getPackageName());
|
||||||
return new AmsTask(null, handler, callback) {
|
return new AmsTask(null, handler, callback) {
|
||||||
public void doWork() throws RemoteException {
|
public void doWork() throws RemoteException {
|
||||||
mService.getAuthToken(mResponse, account, authTokenType,
|
mService.getAuthToken(mResponse, account, authTokenType,
|
||||||
notifyAuthFailure, false /* expectActivityLaunch */, options);
|
notifyAuthFailure, false /* expectActivityLaunch */, optionsIn);
|
||||||
}
|
}
|
||||||
}.start();
|
}.start();
|
||||||
}
|
}
|
||||||
@@ -1044,10 +1045,14 @@ public class AccountManager {
|
|||||||
final Bundle addAccountOptions,
|
final Bundle addAccountOptions,
|
||||||
final Activity activity, AccountManagerCallback<Bundle> callback, Handler handler) {
|
final Activity activity, AccountManagerCallback<Bundle> callback, Handler handler) {
|
||||||
if (accountType == null) throw new IllegalArgumentException("accountType is null");
|
if (accountType == null) throw new IllegalArgumentException("accountType is null");
|
||||||
|
final Bundle options = (addAccountOptions == null) ? new Bundle() :
|
||||||
|
addAccountOptions;
|
||||||
|
options.putString(KEY_ANDROID_PACKAGE_NAME, mContext.getPackageName());
|
||||||
|
|
||||||
return new AmsTask(activity, handler, callback) {
|
return new AmsTask(activity, handler, callback) {
|
||||||
public void doWork() throws RemoteException {
|
public void doWork() throws RemoteException {
|
||||||
mService.addAcount(mResponse, accountType, authTokenType,
|
mService.addAcount(mResponse, accountType, authTokenType,
|
||||||
requiredFeatures, activity != null, addAccountOptions);
|
requiredFeatures, activity != null, options);
|
||||||
}
|
}
|
||||||
}.start();
|
}.start();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,10 +16,6 @@
|
|||||||
|
|
||||||
package android.accounts;
|
package android.accounts;
|
||||||
|
|
||||||
import com.android.internal.R;
|
|
||||||
import com.android.internal.telephony.ITelephony;
|
|
||||||
import com.android.internal.telephony.TelephonyIntents;
|
|
||||||
|
|
||||||
import android.Manifest;
|
import android.Manifest;
|
||||||
import android.app.ActivityManager;
|
import android.app.ActivityManager;
|
||||||
import android.app.Notification;
|
import android.app.Notification;
|
||||||
@@ -51,13 +47,13 @@ import android.os.IBinder;
|
|||||||
import android.os.Looper;
|
import android.os.Looper;
|
||||||
import android.os.Message;
|
import android.os.Message;
|
||||||
import android.os.RemoteException;
|
import android.os.RemoteException;
|
||||||
import android.os.ServiceManager;
|
|
||||||
import android.os.SystemClock;
|
import android.os.SystemClock;
|
||||||
import android.telephony.TelephonyManager;
|
|
||||||
import android.text.TextUtils;
|
import android.text.TextUtils;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
import android.util.Pair;
|
import android.util.Pair;
|
||||||
|
|
||||||
|
import com.android.internal.R;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileDescriptor;
|
import java.io.FileDescriptor;
|
||||||
import java.io.PrintWriter;
|
import java.io.PrintWriter;
|
||||||
@@ -924,9 +920,6 @@ public class AccountManagerService
|
|||||||
if (account == null) throw new IllegalArgumentException("account is null");
|
if (account == null) throw new IllegalArgumentException("account is null");
|
||||||
if (authTokenType == null) throw new IllegalArgumentException("authTokenType is null");
|
if (authTokenType == null) throw new IllegalArgumentException("authTokenType is null");
|
||||||
checkBinderPermission(Manifest.permission.USE_CREDENTIALS);
|
checkBinderPermission(Manifest.permission.USE_CREDENTIALS);
|
||||||
final int callerUid = Binder.getCallingUid();
|
|
||||||
final int callerPid = Binder.getCallingPid();
|
|
||||||
|
|
||||||
AccountAuthenticatorCache.ServiceInfo<AuthenticatorDescription> authenticatorInfo =
|
AccountAuthenticatorCache.ServiceInfo<AuthenticatorDescription> authenticatorInfo =
|
||||||
mAuthenticatorCache.getServiceInfo(
|
mAuthenticatorCache.getServiceInfo(
|
||||||
AuthenticatorDescription.newKey(account.type));
|
AuthenticatorDescription.newKey(account.type));
|
||||||
@@ -934,20 +927,19 @@ public class AccountManagerService
|
|||||||
authenticatorInfo != null && authenticatorInfo.type.customTokens;
|
authenticatorInfo != null && authenticatorInfo.type.customTokens;
|
||||||
|
|
||||||
// skip the check if customTokens
|
// skip the check if customTokens
|
||||||
|
final int callerUid = Binder.getCallingUid();
|
||||||
final boolean permissionGranted = customTokens ||
|
final boolean permissionGranted = customTokens ||
|
||||||
permissionIsGranted(account, authTokenType, callerUid);
|
permissionIsGranted(account, authTokenType, callerUid);
|
||||||
|
|
||||||
final Bundle loginOptions = (loginOptionsIn == null) ? new Bundle() :
|
final Bundle loginOptions = (loginOptionsIn == null) ? new Bundle() :
|
||||||
loginOptionsIn;
|
loginOptionsIn;
|
||||||
if (customTokens) {
|
// let authenticator know the identity of the caller
|
||||||
// let authenticator know the identity of the caller
|
loginOptions.putInt(AccountManager.KEY_CALLER_UID, callerUid);
|
||||||
loginOptions.putInt(AccountManager.KEY_CALLER_UID, callerUid);
|
loginOptions.putInt(AccountManager.KEY_CALLER_PID, Binder.getCallingPid());
|
||||||
loginOptions.putInt(AccountManager.KEY_CALLER_PID, callerPid);
|
if (notifyOnAuthFailure) {
|
||||||
if (notifyOnAuthFailure) {
|
loginOptions.putBoolean(AccountManager.KEY_NOTIFY_ON_FAILURE, true);
|
||||||
loginOptions.putBoolean(AccountManager.KEY_NOTIFY_ON_FAILURE, true);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
long identityToken = clearCallingIdentity();
|
long identityToken = clearCallingIdentity();
|
||||||
try {
|
try {
|
||||||
// if the caller has permission, do the peek. otherwise go the more expensive
|
// if the caller has permission, do the peek. otherwise go the more expensive
|
||||||
@@ -1120,7 +1112,7 @@ public class AccountManagerService
|
|||||||
|
|
||||||
public void addAcount(final IAccountManagerResponse response, final String accountType,
|
public void addAcount(final IAccountManagerResponse response, final String accountType,
|
||||||
final String authTokenType, final String[] requiredFeatures,
|
final String authTokenType, final String[] requiredFeatures,
|
||||||
final boolean expectActivityLaunch, final Bundle options) {
|
final boolean expectActivityLaunch, final Bundle optionsIn) {
|
||||||
if (Log.isLoggable(TAG, Log.VERBOSE)) {
|
if (Log.isLoggable(TAG, Log.VERBOSE)) {
|
||||||
Log.v(TAG, "addAccount: accountType " + accountType
|
Log.v(TAG, "addAccount: accountType " + accountType
|
||||||
+ ", response " + response
|
+ ", response " + response
|
||||||
@@ -1133,6 +1125,13 @@ public class AccountManagerService
|
|||||||
if (response == null) throw new IllegalArgumentException("response is null");
|
if (response == null) throw new IllegalArgumentException("response is null");
|
||||||
if (accountType == null) throw new IllegalArgumentException("accountType is null");
|
if (accountType == null) throw new IllegalArgumentException("accountType is null");
|
||||||
checkManageAccountsPermission();
|
checkManageAccountsPermission();
|
||||||
|
|
||||||
|
final int pid = Binder.getCallingPid();
|
||||||
|
final int uid = Binder.getCallingUid();
|
||||||
|
final Bundle options = (optionsIn == null) ? new Bundle() : optionsIn;
|
||||||
|
options.putInt(AccountManager.KEY_CALLER_UID, uid);
|
||||||
|
options.putInt(AccountManager.KEY_CALLER_PID, pid);
|
||||||
|
|
||||||
long identityToken = clearCallingIdentity();
|
long identityToken = clearCallingIdentity();
|
||||||
try {
|
try {
|
||||||
new Session(response, accountType, expectActivityLaunch,
|
new Session(response, accountType, expectActivityLaunch,
|
||||||
|
|||||||
Reference in New Issue
Block a user