Skip to content

Commit 15f7f44

Browse files
author
Android Build Coastguard Worker
committed
Merge cherrypicks of ['googleplex-android-review.googlesource.com/29599458', 'googleplex-android-review.googlesource.com/30025545'] into 24Q4-release.
Change-Id: I42c841ed44d7c297168ab5756ac10908311f3f4f
2 parents 87be755 + dfa33e9 commit 15f7f44

File tree

3 files changed

+24
-134
lines changed

3 files changed

+24
-134
lines changed

packages/SettingsProvider/src/com/android/providers/settings/SettingsProvider.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2479,10 +2479,10 @@ private void assertCallingUserDenyList(@NonNull Set<String> flags) {
24792479
final long identity = Binder.clearCallingIdentity();
24802480
try {
24812481
int currentUser = ActivityManager.getCurrentUser();
2482-
if (callingUser == currentUser) {
2483-
// enforce the deny list only if the caller is not current user. Currently only auto
2484-
// uses background visible user, and auto doesn't support profiles so profiles of
2485-
// current users is not checked here.
2482+
if (callingUser == currentUser || callingUser == UserHandle.USER_SYSTEM) {
2483+
// enforce the deny list only if the caller is not current user or not a system
2484+
// user. Currently only auto uses background visible user, and auto doesn't
2485+
// support profiles so profiles of current users is not checked here.
24862486
return;
24872487
}
24882488
} finally {

services/core/java/com/android/server/accounts/AccountManagerService.java

Lines changed: 4 additions & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -1773,8 +1773,7 @@ public void onResult(Bundle result) {
17731773
// Create a Session for the target user and pass in the bundle
17741774
completeCloningAccount(response, result, account, toAccounts, userFrom);
17751775
} else {
1776-
// Bundle format is not defined.
1777-
super.onResultSkipSanitization(result);
1776+
super.onResult(result);
17781777
}
17791778
}
17801779
}.bind();
@@ -1861,8 +1860,7 @@ public void onResult(Bundle result) {
18611860
// account to avoid retries?
18621861
// TODO: what we do with the visibility?
18631862

1864-
// Bundle format is not defined.
1865-
super.onResultSkipSanitization(result);
1863+
super.onResult(result);
18661864
}
18671865

18681866
@Override
@@ -2108,7 +2106,6 @@ public void run() throws RemoteException {
21082106
@Override
21092107
public void onResult(Bundle result) {
21102108
Bundle.setDefusable(result, true);
2111-
result = sanitizeBundle(result);
21122109
IAccountManagerResponse response = getResponseAndClose();
21132110
if (response != null) {
21142111
try {
@@ -2462,7 +2459,6 @@ public void run() throws RemoteException {
24622459
@Override
24632460
public void onResult(Bundle result) {
24642461
Bundle.setDefusable(result, true);
2465-
result = sanitizeBundle(result);
24662462
if (result != null && result.containsKey(AccountManager.KEY_BOOLEAN_RESULT)
24672463
&& !result.containsKey(AccountManager.KEY_INTENT)) {
24682464
final boolean removalAllowed = result.getBoolean(AccountManager.KEY_BOOLEAN_RESULT);
@@ -2977,7 +2973,6 @@ public void run() throws RemoteException {
29772973
@Override
29782974
public void onResult(Bundle result) {
29792975
Bundle.setDefusable(result, true);
2980-
result = sanitizeBundle(result);
29812976
if (result != null) {
29822977
String label = result.getString(AccountManager.KEY_AUTH_TOKEN_LABEL);
29832978
Bundle bundle = new Bundle();
@@ -3155,7 +3150,6 @@ public void run() throws RemoteException {
31553150
@Override
31563151
public void onResult(Bundle result) {
31573152
Bundle.setDefusable(result, true);
3158-
result = sanitizeBundle(result);
31593153
if (result != null) {
31603154
if (result.containsKey(AccountManager.KEY_AUTH_TOKEN_LABEL)) {
31613155
Intent intent = newGrantCredentialsPermissionIntent(
@@ -3627,12 +3621,6 @@ public StartAccountSession(
36273621
@Override
36283622
public void onResult(Bundle result) {
36293623
Bundle.setDefusable(result, true);
3630-
Bundle sessionBundle = null;
3631-
if (result != null) {
3632-
// Session bundle will be removed from result.
3633-
sessionBundle = result.getBundle(AccountManager.KEY_ACCOUNT_SESSION_BUNDLE);
3634-
}
3635-
result = sanitizeBundle(result);
36363624
mNumResults++;
36373625
Intent intent = null;
36383626
if (result != null) {
@@ -3694,6 +3682,7 @@ public void onResult(Bundle result) {
36943682
// bundle contains data necessary for finishing the session
36953683
// later. The session bundle will be encrypted here and
36963684
// decrypted later when trying to finish the session.
3685+
Bundle sessionBundle = result.getBundle(AccountManager.KEY_ACCOUNT_SESSION_BUNDLE);
36973686
if (sessionBundle != null) {
36983687
String accountType = sessionBundle.getString(AccountManager.KEY_ACCOUNT_TYPE);
36993688
if (TextUtils.isEmpty(accountType)
@@ -4081,7 +4070,6 @@ public void run() throws RemoteException {
40814070
@Override
40824071
public void onResult(Bundle result) {
40834072
Bundle.setDefusable(result, true);
4084-
result = sanitizeBundle(result);
40854073
IAccountManagerResponse response = getResponseAndClose();
40864074
if (response == null) {
40874075
return;
@@ -4395,7 +4383,6 @@ public void checkAccount() {
43954383
@Override
43964384
public void onResult(Bundle result) {
43974385
Bundle.setDefusable(result, true);
4398-
result = sanitizeBundle(result);
43994386
mNumResults++;
44004387
if (result == null) {
44014388
onError(AccountManager.ERROR_CODE_INVALID_RESPONSE, "null bundle");
@@ -4952,68 +4939,6 @@ public void onShellCommand(FileDescriptor in, FileDescriptor out,
49524939
callback, resultReceiver);
49534940
}
49544941

4955-
4956-
// All keys for Strings passed from AbstractAccountAuthenticator using Bundle.
4957-
private static final String[] sStringBundleKeys = new String[] {
4958-
AccountManager.KEY_ACCOUNT_NAME,
4959-
AccountManager.KEY_ACCOUNT_TYPE,
4960-
AccountManager.KEY_AUTHTOKEN,
4961-
AccountManager.KEY_AUTH_TOKEN_LABEL,
4962-
AccountManager.KEY_ERROR_MESSAGE,
4963-
AccountManager.KEY_PASSWORD,
4964-
AccountManager.KEY_ACCOUNT_STATUS_TOKEN};
4965-
4966-
/**
4967-
* Keep only documented fields in a Bundle received from AbstractAccountAuthenticator.
4968-
*/
4969-
protected static Bundle sanitizeBundle(Bundle bundle) {
4970-
if (bundle == null) {
4971-
return null;
4972-
}
4973-
Bundle sanitizedBundle = new Bundle();
4974-
Bundle.setDefusable(sanitizedBundle, true);
4975-
int updatedKeysCount = 0;
4976-
for (String stringKey : sStringBundleKeys) {
4977-
if (bundle.containsKey(stringKey)) {
4978-
String value = bundle.getString(stringKey);
4979-
sanitizedBundle.putString(stringKey, value);
4980-
updatedKeysCount++;
4981-
}
4982-
}
4983-
String key = AbstractAccountAuthenticator.KEY_CUSTOM_TOKEN_EXPIRY;
4984-
if (bundle.containsKey(key)) {
4985-
long expiryMillis = bundle.getLong(key, 0L);
4986-
sanitizedBundle.putLong(key, expiryMillis);
4987-
updatedKeysCount++;
4988-
}
4989-
key = AccountManager.KEY_BOOLEAN_RESULT;
4990-
if (bundle.containsKey(key)) {
4991-
boolean booleanResult = bundle.getBoolean(key, false);
4992-
sanitizedBundle.putBoolean(key, booleanResult);
4993-
updatedKeysCount++;
4994-
}
4995-
key = AccountManager.KEY_ERROR_CODE;
4996-
if (bundle.containsKey(key)) {
4997-
int errorCode = bundle.getInt(key, 0);
4998-
sanitizedBundle.putInt(key, errorCode);
4999-
updatedKeysCount++;
5000-
}
5001-
key = AccountManager.KEY_INTENT;
5002-
if (bundle.containsKey(key)) {
5003-
Intent intent = bundle.getParcelable(key, Intent.class);
5004-
sanitizedBundle.putParcelable(key, intent);
5005-
updatedKeysCount++;
5006-
}
5007-
if (bundle.containsKey(AccountManager.KEY_ACCOUNT_SESSION_BUNDLE)) {
5008-
// The field is not copied in sanitized bundle.
5009-
updatedKeysCount++;
5010-
}
5011-
if (updatedKeysCount != bundle.size()) {
5012-
Log.w(TAG, "Size mismatch after sanitizeBundle call.");
5013-
}
5014-
return sanitizedBundle;
5015-
}
5016-
50174942
private abstract class Session extends IAccountAuthenticatorResponse.Stub
50184943
implements IBinder.DeathRecipient, ServiceConnection {
50194944
private final Object mSessionLock = new Object();
@@ -5304,14 +5229,9 @@ public void onTimedOut() {
53045229
}
53055230
}
53065231
}
5232+
53075233
@Override
53085234
public void onResult(Bundle result) {
5309-
Bundle.setDefusable(result, true);
5310-
result = sanitizeBundle(result);
5311-
onResultSkipSanitization(result);
5312-
}
5313-
5314-
public void onResultSkipSanitization(Bundle result) {
53155235
Bundle.setDefusable(result, true);
53165236
mNumResults++;
53175237
Intent intent = null;

services/tests/servicestests/src/com/android/server/accounts/AccountManagerServiceTest.java

Lines changed: 16 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1163,6 +1163,16 @@ public void testFinishSessionAsUserSuccess() throws Exception {
11631163

11641164
verify(mMockAccountManagerResponse).onResult(mBundleCaptor.capture());
11651165
Bundle result = mBundleCaptor.getValue();
1166+
Bundle sessionBundle = result.getBundle(AccountManager.KEY_ACCOUNT_SESSION_BUNDLE);
1167+
assertNotNull(sessionBundle);
1168+
// Assert that session bundle is decrypted and hence data is visible.
1169+
assertEquals(AccountManagerServiceTestFixtures.SESSION_DATA_VALUE_1,
1170+
sessionBundle.getString(AccountManagerServiceTestFixtures.SESSION_DATA_NAME_1));
1171+
// Assert finishSessionAsUser added calling uid and pid into the sessionBundle
1172+
assertTrue(sessionBundle.containsKey(AccountManager.KEY_CALLER_UID));
1173+
assertTrue(sessionBundle.containsKey(AccountManager.KEY_CALLER_PID));
1174+
assertEquals(sessionBundle.getString(
1175+
AccountManager.KEY_ANDROID_PACKAGE_NAME), "APCT.package");
11661176

11671177
// Verify response data
11681178
assertNull(result.getString(AccountManager.KEY_AUTHTOKEN, null));
@@ -2111,6 +2121,12 @@ public void testAddAccountAsUserSuccess() throws Exception {
21112121
result.getString(AccountManager.KEY_ACCOUNT_NAME));
21122122
assertEquals(AccountManagerServiceTestFixtures.ACCOUNT_TYPE_1,
21132123
result.getString(AccountManager.KEY_ACCOUNT_TYPE));
2124+
2125+
Bundle optionBundle = result.getParcelable(
2126+
AccountManagerServiceTestFixtures.KEY_OPTIONS_BUNDLE);
2127+
// Assert addAccountAsUser added calling uid and pid into the option bundle
2128+
assertTrue(optionBundle.containsKey(AccountManager.KEY_CALLER_UID));
2129+
assertTrue(optionBundle.containsKey(AccountManager.KEY_CALLER_PID));
21142130
}
21152131

21162132
@SmallTest
@@ -3441,52 +3457,6 @@ public void testConcurrencyRead() throws Exception {
34413457
+ (readTotalTime.doubleValue() / readerCount / loopSize));
34423458
}
34433459

3444-
@SmallTest
3445-
public void testSanitizeBundle_expectedFields() throws Exception {
3446-
Bundle bundle = new Bundle();
3447-
bundle.putString(AccountManager.KEY_ACCOUNT_NAME, "name");
3448-
bundle.putString(AccountManager.KEY_ACCOUNT_TYPE, "type");
3449-
bundle.putString(AccountManager.KEY_AUTHTOKEN, "token");
3450-
bundle.putString(AccountManager.KEY_AUTH_TOKEN_LABEL, "label");
3451-
bundle.putString(AccountManager.KEY_ERROR_MESSAGE, "error message");
3452-
bundle.putString(AccountManager.KEY_PASSWORD, "password");
3453-
bundle.putString(AccountManager.KEY_ACCOUNT_STATUS_TOKEN, "status");
3454-
3455-
bundle.putLong(AbstractAccountAuthenticator.KEY_CUSTOM_TOKEN_EXPIRY, 123L);
3456-
bundle.putBoolean(AccountManager.KEY_BOOLEAN_RESULT, true);
3457-
bundle.putInt(AccountManager.KEY_ERROR_CODE, 456);
3458-
3459-
Bundle sanitizedBundle = AccountManagerService.sanitizeBundle(bundle);
3460-
assertEquals(sanitizedBundle.getString(AccountManager.KEY_ACCOUNT_NAME), "name");
3461-
assertEquals(sanitizedBundle.getString(AccountManager.KEY_ACCOUNT_TYPE), "type");
3462-
assertEquals(sanitizedBundle.getString(AccountManager.KEY_AUTHTOKEN), "token");
3463-
assertEquals(sanitizedBundle.getString(AccountManager.KEY_AUTH_TOKEN_LABEL), "label");
3464-
assertEquals(sanitizedBundle.getString(AccountManager.KEY_ERROR_MESSAGE), "error message");
3465-
assertEquals(sanitizedBundle.getString(AccountManager.KEY_PASSWORD), "password");
3466-
assertEquals(sanitizedBundle.getString(AccountManager.KEY_ACCOUNT_STATUS_TOKEN), "status");
3467-
3468-
assertEquals(sanitizedBundle.getLong(
3469-
AbstractAccountAuthenticator.KEY_CUSTOM_TOKEN_EXPIRY, 0), 123L);
3470-
assertEquals(sanitizedBundle.getBoolean(AccountManager.KEY_BOOLEAN_RESULT, false), true);
3471-
assertEquals(sanitizedBundle.getInt(AccountManager.KEY_ERROR_CODE, 0), 456);
3472-
}
3473-
3474-
@SmallTest
3475-
public void testSanitizeBundle_filtersUnexpectedFields() throws Exception {
3476-
Bundle bundle = new Bundle();
3477-
bundle.putString(AccountManager.KEY_ACCOUNT_NAME, "name");
3478-
bundle.putString("unknown_key", "value");
3479-
Bundle sessionBundle = new Bundle();
3480-
bundle.putBundle(AccountManager.KEY_ACCOUNT_SESSION_BUNDLE, sessionBundle);
3481-
3482-
Bundle sanitizedBundle = AccountManagerService.sanitizeBundle(bundle);
3483-
3484-
assertEquals(sanitizedBundle.getString(AccountManager.KEY_ACCOUNT_NAME), "name");
3485-
assertFalse(sanitizedBundle.containsKey("unknown_key"));
3486-
// It is a valid response from Authenticator which will be accessed using original Bundle
3487-
assertFalse(sanitizedBundle.containsKey(AccountManager.KEY_ACCOUNT_SESSION_BUNDLE));
3488-
}
3489-
34903460
private void waitForCyclicBarrier(CyclicBarrier cyclicBarrier) {
34913461
try {
34923462
cyclicBarrier.await(LATCH_TIMEOUT_MS, TimeUnit.MILLISECONDS);

0 commit comments

Comments
 (0)