Update AccountManagerService side logic for .getAccountsByTypeForPackage
with null type. Bug: 37987384 Test: manual, APCT Change-Id: I4d5f735736f1b1d7bbf778aee2ec813071c34f19
This commit is contained in:
@@ -4428,6 +4428,10 @@ public class AccountManagerService
|
||||
&& (type != null && !isAccountManagedByCaller(type, callingUid, userId))) {
|
||||
return EMPTY_ACCOUNT_ARRAY;
|
||||
}
|
||||
if (!UserHandle.isSameApp(callingUid, Process.SYSTEM_UID) && type == null) {
|
||||
return getAccountsAsUserForPackage(type, userId,
|
||||
packageName, packageUid, opPackageName, false /* includeUserManagedNotVisible */);
|
||||
}
|
||||
return getAccountsAsUserForPackage(type, userId,
|
||||
packageName, packageUid, opPackageName, true /* includeUserManagedNotVisible */);
|
||||
}
|
||||
|
||||
@@ -52,6 +52,10 @@
|
||||
<uses-permission android:name="android.permission.CHANGE_COMPONENT_ENABLED_STATE" />
|
||||
<uses-permission android:name="android.permission.DELETE_PACKAGES" />
|
||||
|
||||
<!-- Uses API introduced in O (26) -->
|
||||
<uses-sdk android:minSdkVersion="1"
|
||||
android:targetSdkVersion="26"/>
|
||||
|
||||
<application>
|
||||
<uses-library android:name="android.test.runner" />
|
||||
|
||||
|
||||
@@ -1483,6 +1483,31 @@ public class AccountManagerServiceTest extends AndroidTestCase {
|
||||
assertNotNull(intent);
|
||||
}
|
||||
|
||||
@SmallTest
|
||||
public void testGetAccountsByTypeForPackageWhenTypeIsNull() throws Exception {
|
||||
unlockSystemUser();
|
||||
HashMap<String, Integer> visibility1 = new HashMap<>();
|
||||
visibility1.put(AccountManagerServiceTestFixtures.CALLER_PACKAGE,
|
||||
AccountManager.VISIBILITY_USER_MANAGED_VISIBLE);
|
||||
|
||||
HashMap<String, Integer> visibility2 = new HashMap<>();
|
||||
visibility2.put(AccountManagerServiceTestFixtures.CALLER_PACKAGE,
|
||||
AccountManager.VISIBILITY_USER_MANAGED_NOT_VISIBLE);
|
||||
|
||||
mAms.addAccountExplicitlyWithVisibility(
|
||||
AccountManagerServiceTestFixtures.ACCOUNT_SUCCESS, "P11", null, visibility1);
|
||||
mAms.addAccountExplicitlyWithVisibility(
|
||||
AccountManagerServiceTestFixtures.ACCOUNT_INTERVENE, "P12", null, visibility2);
|
||||
|
||||
Account[] accounts = mAms.getAccountsByTypeForPackage(
|
||||
null, "otherPackageName",
|
||||
AccountManagerServiceTestFixtures.CALLER_PACKAGE);
|
||||
// Only get the USER_MANAGED_NOT_VISIBLE account.
|
||||
assertEquals(1, accounts.length);
|
||||
assertEquals(AccountManagerServiceTestFixtures.ACCOUNT_NAME_SUCCESS, accounts[0].name);
|
||||
assertEquals(AccountManagerServiceTestFixtures.ACCOUNT_TYPE_1, accounts[0].type);
|
||||
}
|
||||
|
||||
@SmallTest
|
||||
public void testGetAuthTokenLabelWithNullAccountType() throws Exception {
|
||||
unlockSystemUser();
|
||||
|
||||
Reference in New Issue
Block a user