Update AccountManagerService side logic for .getAccountsByTypeForPackage

with null type.

Bug: 37987384
Test: manual, APCT
Change-Id: I4d5f735736f1b1d7bbf778aee2ec813071c34f19
This commit is contained in:
sunjian
2017-06-01 12:05:59 -07:00
committed by Jian Sun
parent 9fd3076fe6
commit d62dc39dc5
3 changed files with 33 additions and 0 deletions

View File

@@ -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 */);
}

View File

@@ -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" />

View File

@@ -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();