Merge "introduce GET_PASSWORD_PRIVILEDGED permission." into nyc-dev

This commit is contained in:
Carlos Valdivia
2016-04-01 20:01:58 +00:00
committed by Android (Google) Code Review
6 changed files with 56 additions and 9 deletions

View File

@@ -71,6 +71,7 @@ package android {
field public static final java.lang.String GET_ACCOUNTS = "android.permission.GET_ACCOUNTS";
field public static final java.lang.String GET_ACCOUNTS_PRIVILEGED = "android.permission.GET_ACCOUNTS_PRIVILEGED";
field public static final java.lang.String GET_PACKAGE_SIZE = "android.permission.GET_PACKAGE_SIZE";
field public static final java.lang.String GET_PASSWORD_PRIVILEGED = "android.permission.GET_PASSWORD_PRIVILEGED";
field public static final deprecated java.lang.String GET_TASKS = "android.permission.GET_TASKS";
field public static final java.lang.String GLOBAL_SEARCH = "android.permission.GLOBAL_SEARCH";
field public static final java.lang.String INSTALL_LOCATION_PROVIDER = "android.permission.INSTALL_LOCATION_PROVIDER";

View File

@@ -103,6 +103,7 @@ package android {
field public static final java.lang.String GET_APP_OPS_STATS = "android.permission.GET_APP_OPS_STATS";
field public static final java.lang.String GET_PACKAGE_IMPORTANCE = "android.permission.GET_PACKAGE_IMPORTANCE";
field public static final java.lang.String GET_PACKAGE_SIZE = "android.permission.GET_PACKAGE_SIZE";
field public static final java.lang.String GET_PASSWORD_PRIVILEGED = "android.permission.GET_PASSWORD_PRIVILEGED";
field public static final java.lang.String GET_PROCESS_STATE_AND_OOM_SCORE = "android.permission.GET_PROCESS_STATE_AND_OOM_SCORE";
field public static final deprecated java.lang.String GET_TASKS = "android.permission.GET_TASKS";
field public static final java.lang.String GET_TOP_ACTIVITY_INFO = "android.permission.GET_TOP_ACTIVITY_INFO";

View File

@@ -71,6 +71,7 @@ package android {
field public static final java.lang.String GET_ACCOUNTS = "android.permission.GET_ACCOUNTS";
field public static final java.lang.String GET_ACCOUNTS_PRIVILEGED = "android.permission.GET_ACCOUNTS_PRIVILEGED";
field public static final java.lang.String GET_PACKAGE_SIZE = "android.permission.GET_PACKAGE_SIZE";
field public static final java.lang.String GET_PASSWORD_PRIVILEGED = "android.permission.GET_PASSWORD_PRIVILEGED";
field public static final deprecated java.lang.String GET_TASKS = "android.permission.GET_TASKS";
field public static final java.lang.String GLOBAL_SEARCH = "android.permission.GLOBAL_SEARCH";
field public static final java.lang.String INSTALL_LOCATION_PROVIDER = "android.permission.INSTALL_LOCATION_PROVIDER";

View File

@@ -2798,6 +2798,15 @@ public class AccountManager {
if (account == null) {
throw new IllegalArgumentException("account is null");
}
// Always include the calling package name. This just makes life easier
// down stream.
final Bundle optionsIn = new Bundle();
if (options != null) {
optionsIn.putAll(options);
}
optionsIn.putString(KEY_ANDROID_PACKAGE_NAME, mContext.getPackageName());
return new AmsTask(activity, handler, callback) {
@Override
public void doWork() throws RemoteException {
@@ -2806,7 +2815,7 @@ public class AccountManager {
account,
authTokenType,
activity != null,
options);
optionsIn);
}
}.start();
}

View File

@@ -2004,6 +2004,11 @@
<permission android:name="android.permission.GET_ACCOUNTS_PRIVILEGED"
android:protectionLevel="signature|privileged" />
<!-- @SystemApi Allows but does not guarantee access to user passwords at the conclusion of add
account -->
<permission android:name="android.permission.GET_PASSWORD_PRIVILEGED"
android:protectionLevel="signature|privileged" />
<!-- @SystemApi Allows applications to RW to diagnostic resources.
<p>Not for use by third-party applications. -->
<permission android:name="android.permission.DIAGNOSTIC"

View File

@@ -2500,21 +2500,31 @@ public class AccountManagerService
userId);
return;
}
final int pid = Binder.getCallingPid();
final Bundle options = (optionsIn == null) ? new Bundle() : optionsIn;
options.putInt(AccountManager.KEY_CALLER_UID, uid);
options.putInt(AccountManager.KEY_CALLER_PID, pid);
// Check to see if the Password should be included to the caller.
String callerPkg = optionsIn.getString(AccountManager.KEY_ANDROID_PACKAGE_NAME);
boolean isPasswordForwardingAllowed = isPermitted(
callerPkg, uid, Manifest.permission.GET_PASSWORD_PRIVILEGED);
int usrId = UserHandle.getCallingUserId();
long identityToken = clearCallingIdentity();
try {
UserAccounts accounts = getUserAccounts(usrId);
logRecordWithUid(accounts, DebugDbHelper.ACTION_CALLED_START_ACCOUNT_ADD,
TABLE_ACCOUNTS, uid);
new StartAccountSession(accounts, response, accountType, expectActivityLaunch,
null /* accountName */, false /* authDetailsRequired */,
true /* updateLastAuthenticationTime */) {
new StartAccountSession(
accounts,
response,
accountType,
expectActivityLaunch,
null /* accountName */,
false /* authDetailsRequired */,
true /* updateLastAuthenticationTime */,
isPasswordForwardingAllowed) {
@Override
public void run() throws RemoteException {
mAuthenticator.startAddAccountSession(this, mAccountType, authTokenType,
@@ -2537,12 +2547,21 @@ public class AccountManagerService
/** Session that will encrypt the KEY_ACCOUNT_SESSION_BUNDLE in result. */
private abstract class StartAccountSession extends Session {
public StartAccountSession(UserAccounts accounts, IAccountManagerResponse response,
String accountType, boolean expectActivityLaunch, String accountName,
boolean authDetailsRequired, boolean updateLastAuthenticationTime) {
private final boolean mIsPasswordForwardingAllowed;
public StartAccountSession(
UserAccounts accounts,
IAccountManagerResponse response,
String accountType,
boolean expectActivityLaunch,
String accountName,
boolean authDetailsRequired,
boolean updateLastAuthenticationTime,
boolean isPasswordForwardingAllowed) {
super(accounts, response, accountType, expectActivityLaunch,
true /* stripAuthTokenFromResult */, accountName, authDetailsRequired,
updateLastAuthenticationTime);
mIsPasswordForwardingAllowed = isPasswordForwardingAllowed;
}
@Override
@@ -2555,6 +2574,10 @@ public class AccountManagerService
checkKeyIntent(
Binder.getCallingUid(),
intent);
// Omit passwords if the caller isn't permitted to see them.
if (!mIsPasswordForwardingAllowed) {
result.remove(AccountManager.KEY_PASSWORD);
}
}
IAccountManagerResponse response;
if (mExpectActivityLaunch && result != null
@@ -2901,6 +2924,12 @@ public class AccountManagerService
}
int userId = UserHandle.getCallingUserId();
// Check to see if the Password should be included to the caller.
String callerPkg = loginOptions.getString(AccountManager.KEY_ANDROID_PACKAGE_NAME);
boolean isPasswordForwardingAllowed = isPermitted(
callerPkg, uid, Manifest.permission.GET_PASSWORD_PRIVILEGED);
long identityToken = clearCallingIdentity();
try {
UserAccounts accounts = getUserAccounts(userId);
@@ -2911,7 +2940,8 @@ public class AccountManagerService
expectActivityLaunch,
account.name,
false /* authDetailsRequired */,
true /* updateLastCredentialTime */) {
true /* updateLastCredentialTime */,
isPasswordForwardingAllowed) {
@Override
public void run() throws RemoteException {
mAuthenticator.startUpdateCredentialsSession(this, account, authTokenType,