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

Commit a6897a1b authored by Dmitry Dementyev's avatar Dmitry Dementyev Committed by Android (Google) Code Review
Browse files

Merge "Don't send ACCOUNT_REMOVED if account is marked as visible twice." into main

parents b409758a 60676d08
Loading
Loading
Loading
Loading
+5 −0
Original line number Diff line number Diff line
@@ -897,6 +897,11 @@ public class AccountManagerService
                        }
                    }
                    for (String packageNameToNotify : accountRemovedReceivers) {
                        int currentVisibility =
                                resolveAccountVisibility(account, packageNameToNotify, accounts);
                        if (isVisible(currentVisibility)) {
                            continue;
                        }
                        sendAccountRemovedBroadcast(
                                account,
                                packageNameToNotify,
+39 −0
Original line number Diff line number Diff line
@@ -3155,6 +3155,39 @@ public class AccountManagerServiceTest extends AndroidTestCase {
        assertEquals(mAccountRemovedBroadcasts, 0); // account was never visible.
    }

    @SmallTest
    public void testAccountRemovedBroadcastMarkedAccountAsVisibleTwice() throws Exception {
        unlockSystemUser();

        HashMap<String, Integer> visibility = new HashMap<>();
        visibility.put("testpackage1", AccountManager.VISIBILITY_USER_MANAGED_VISIBLE);

        addAccountRemovedReceiver("testpackage1");
        mAms.registerAccountListener(
                new String [] {AccountManagerServiceTestFixtures.ACCOUNT_TYPE_1},
                "testpackage1");
        mAms.addAccountExplicitlyWithVisibility(
                AccountManagerServiceTestFixtures.ACCOUNT_SUCCESS,
                /* password= */ "p11",
                /* extras= */ null,
                visibility,
                /* callerPackage= */ null);

        updateBroadcastCounters(2);
        assertEquals(mVisibleAccountsChangedBroadcasts, 1);
        assertEquals(mLoginAccountsChangedBroadcasts, 1);
        assertEquals(mAccountRemovedBroadcasts, 0);

        mAms.setAccountVisibility(AccountManagerServiceTestFixtures.ACCOUNT_SUCCESS,
                "testpackage1",
                AccountManager.VISIBILITY_VISIBLE);

        updateBroadcastCounters(3);
        assertEquals(mVisibleAccountsChangedBroadcasts, 1); // visibility was not changed
        assertEquals(mLoginAccountsChangedBroadcasts, 2);
        assertEquals(mAccountRemovedBroadcasts, 0);
    }

    @SmallTest
    public void testRegisterAccountListenerCredentialsUpdate() throws Exception {
        unlockSystemUser();
@@ -3492,6 +3525,12 @@ public class AccountManagerServiceTest extends AndroidTestCase {
            return mTestContext.bindServiceAsUser(service, conn, flags, user);
        }

        @Override
        public boolean bindServiceAsUser(Intent service, ServiceConnection conn,
                Context.BindServiceFlags flags, UserHandle user) {
            return mTestContext.bindServiceAsUser(service, conn, flags, user);
        }

        @Override
        public void unbindService(ServiceConnection conn) {
            mTestContext.unbindService(conn);