Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit b22429d5 authored by sunjian's avatar sunjian Committed by android-build-merger
Browse files

Update AccountManagerService side logic for .getAccountsByTypeForPackage with null type.

am: d62dc39d

Change-Id: Idf3475786676e9713e4fa5756ecce9c675da8c3e
parents cc162a1e d62dc39d
Loading
Loading
Loading
Loading
+4 −0
Original line number Diff line number Diff line
@@ -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 */);
    }
+4 −0
Original line number Diff line number Diff line
@@ -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" />

+25 −0
Original line number Diff line number Diff line
@@ -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();