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

Commit cbe85d4d authored by Xiang Wang's avatar Xiang Wang
Browse files

Revert "Modify the logic that updates the information of enabled services in...

Revert "Modify the logic that updates the information of enabled services in ManagedServices to handle the visible background user in MUMD"

This reverts commit d1f905fd.

Reason for revert: Original CL broke CtsNotificationTestCases and CtsJobSchedulerTestCases on secondary_user_on_secondary_display and without the original CL the logic still has no negative impact on the current user as populateComponentsToBind, if triggered from visible background users, just clears mEnabledServicesForCurrentProfiles and mEnabledServicesPackageNames but also repopulates them for the active users (current user and their work profiles).

Bug: 374182059
Bug: 376252164
Bug: 376145534
Test: atest CtsNotificationTestCases
Test: atest --user-type secondary_user_on_secondary_display CtsNotificationTestCases
Test: atest ManagedServicesTest
Test: Manual testing on gcar_md emulator / seahawk_md reference hardware with Kitchen Sink->Notification and observe notifications can be fired and received for the driver and passenger independent of each other.
Change-Id: I493e96e8fcd4896cf507afaa2d705e829cbb18f6
parent d1f905fd
Loading
Loading
Loading
Loading
+5 −23
Original line number Diff line number Diff line
@@ -75,9 +75,7 @@ import com.android.internal.util.XmlUtils;
import com.android.internal.util.function.TriPredicate;
import com.android.modules.utils.TypedXmlPullParser;
import com.android.modules.utils.TypedXmlSerializer;
import com.android.server.LocalServices;
import com.android.server.notification.NotificationManagerService.DumpFilter;
import com.android.server.pm.UserManagerInternal;
import com.android.server.utils.TimingsTraceAndSlog;

import org.xmlpull.v1.XmlPullParser;
@@ -136,7 +134,6 @@ abstract public class ManagedServices {
    private final UserProfiles mUserProfiles;
    protected final IPackageManager mPm;
    protected final UserManager mUm;
    private final UserManagerInternal mUserManagerInternal;
    private final Config mConfig;
    private final Handler mHandler = new Handler(Looper.getMainLooper());

@@ -198,7 +195,6 @@ abstract public class ManagedServices {
        mConfig = getConfig();
        mApprovalLevel = APPROVAL_BY_COMPONENT;
        mUm = (UserManager) mContext.getSystemService(Context.USER_SERVICE);
        mUserManagerInternal = LocalServices.getService(UserManagerInternal.class);
    }

    abstract protected Config getConfig();
@@ -1376,14 +1372,9 @@ abstract public class ManagedServices {
    @GuardedBy("mMutex")
    protected void populateComponentsToBind(SparseArray<Set<ComponentName>> componentsToBind,
            final IntArray activeUsers,
            SparseArray<ArraySet<ComponentName>> approvedComponentsByUser,
            boolean isVisibleBackgroundUser) {
        // When it is a visible background user in Automotive MUMD environment,
        // don't clear mEnabledServicesForCurrentProfile and mEnabledServicesPackageNames.
        if (!isVisibleBackgroundUser) {
            SparseArray<ArraySet<ComponentName>> approvedComponentsByUser) {
        mEnabledServicesForCurrentProfiles.clear();
        mEnabledServicesPackageNames.clear();
        }
        final int nUserIds = activeUsers.size();

        for (int i = 0; i < nUserIds; ++i) {
@@ -1404,12 +1395,7 @@ abstract public class ManagedServices {
            }

            componentsToBind.put(userId, add);
            // When it is a visible background user in Automotive MUMD environment,
            // skip adding items to mEnabledServicesForCurrentProfile
            // and mEnabledServicesPackageNames.
            if (isVisibleBackgroundUser) {
                continue;
            }

            mEnabledServicesForCurrentProfiles.addAll(userComponents);

            for (int j = 0; j < userComponents.size(); j++) {
@@ -1457,10 +1443,7 @@ abstract public class ManagedServices {
        IntArray userIds = mUserProfiles.getCurrentProfileIds();
        boolean rebindAllCurrentUsers = mUserProfiles.isProfileUser(userToRebind, mContext)
                && allowRebindForParentUser();
        boolean isVisibleBackgroundUser = false;
        if (userToRebind != USER_ALL && !rebindAllCurrentUsers) {
            isVisibleBackgroundUser =
                    mUserManagerInternal.isVisibleBackgroundFullUser(userToRebind);
            userIds = new IntArray(1);
            userIds.add(userToRebind);
        }
@@ -1475,8 +1458,7 @@ abstract public class ManagedServices {

            // Filter approvedComponentsByUser to collect all of the components that are allowed
            // for the currently active user(s).
            populateComponentsToBind(componentsToBind, userIds, approvedComponentsByUser,
                    isVisibleBackgroundUser);
            populateComponentsToBind(componentsToBind, userIds, approvedComponentsByUser);

            // For every current non-system connection, disconnect services that are no longer
            // approved, or ALL services if we are force rebinding
+0 −4
Original line number Diff line number Diff line
@@ -30,7 +30,6 @@ import android.testing.TestableContext;

import androidx.test.InstrumentationRegistry;

import com.android.server.pm.UserManagerInternal;
import com.android.server.uri.UriGrantsManagerInternal;

import org.junit.After;
@@ -42,7 +41,6 @@ import org.mockito.MockitoAnnotations;

public class UiServiceTestCase {
    @Mock protected PackageManagerInternal mPmi;
    @Mock protected UserManagerInternal mUmi;
    @Mock protected UriGrantsManagerInternal mUgmInternal;

    protected static final String PKG_N_MR1 = "com.example.n_mr1";
@@ -94,8 +92,6 @@ public class UiServiceTestCase {
                    }
                });

        LocalServices.removeServiceForTest(UserManagerInternal.class);
        LocalServices.addService(UserManagerInternal.class, mUmi);
        LocalServices.removeServiceForTest(UriGrantsManagerInternal.class);
        LocalServices.addService(UriGrantsManagerInternal.class, mUgmInternal);
        when(mUgmInternal.checkGrantUriPermission(
+1 −30
Original line number Diff line number Diff line
@@ -1542,7 +1542,6 @@ public class ManagedServicesTest extends UiServiceTestCase {
        assertTrue(componentsToUnbind.get(0).contains(ComponentName.unflattenFromString("c/c")));
    }

    @SuppressWarnings("GuardedBy")
    @Test
    public void populateComponentsToBind() {
        ManagedServices service = new TestManagedServices(getContext(), mLock, mUserProfiles, mIpm,
@@ -1566,8 +1565,7 @@ public class ManagedServicesTest extends UiServiceTestCase {

        SparseArray<Set<ComponentName>> componentsToBind = new SparseArray<>();

        service.populateComponentsToBind(componentsToBind, users, approvedComponentsByUser,
                /* isVisibleBackgroundUser= */ false);
        service.populateComponentsToBind(componentsToBind, users, approvedComponentsByUser);

        assertEquals(2, componentsToBind.size());
        assertEquals(1, componentsToBind.get(0).size());
@@ -1577,33 +1575,6 @@ public class ManagedServicesTest extends UiServiceTestCase {
        assertTrue(componentsToBind.get(10).contains(ComponentName.unflattenFromString("c/c")));
    }

    @SuppressWarnings("GuardedBy")
    @Test
    public void populateComponentsToBind_isVisibleBackgroundUser_addComponentsToBindButNotAddToEnabledComponent() {
        ManagedServices service = new TestManagedServices(getContext(), mLock, mUserProfiles, mIpm,
                APPROVAL_BY_COMPONENT);

        SparseArray<ArraySet<ComponentName>> approvedComponentsByUser = new SparseArray<>();
        ArraySet<ComponentName> allowed = new ArraySet<>();
        allowed.add(ComponentName.unflattenFromString("pkg1/cmp1"));
        approvedComponentsByUser.put(11, allowed);
        IntArray users = new IntArray();
        users.add(11);

        SparseArray<Set<ComponentName>> componentsToBind = new SparseArray<>();

        service.populateComponentsToBind(componentsToBind, users, approvedComponentsByUser,
                /* isVisibleBackgroundUser= */ true);

        assertEquals(1, componentsToBind.size());
        assertEquals(1, componentsToBind.get(11).size());
        assertTrue(componentsToBind.get(11).contains(ComponentName.unflattenFromString(
                "pkg1/cmp1")));
        assertThat(service.isComponentEnabledForCurrentProfiles(
                new ComponentName("pkg1", "cmp1"))).isFalse();
        assertThat(service.isComponentEnabledForPackage("pkg1")).isFalse();
    }

    @Test
    public void testOnNullBinding() throws Exception {
        Context context = mock(Context.class);