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

Commit 9fe9bb39 authored by Treehugger Robot's avatar Treehugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Skip the user visibility check for private displays" into main

parents 7171a401 b51b1114
Loading
Loading
Loading
Loading
+4 −0
Original line number Original line Diff line number Diff line
@@ -2738,6 +2738,10 @@ class DisplayContent extends RootDisplayArea implements WindowManagerPolicy.Disp
        if (!mVisibleBackgroundUserEnabled) {
        if (!mVisibleBackgroundUserEnabled) {
            return true;
            return true;
        }
        }
        if (isPrivate()) {
            // UserManager doesn't track the user visibility for private displays.
            return true;
        }
        final int userId = UserHandle.getUserId(uid);
        final int userId = UserHandle.getUserId(uid);
        return userId == UserHandle.USER_SYSTEM
        return userId == UserHandle.USER_SYSTEM
                || mWmService.mUmInternal.isUserVisible(userId, mDisplayId);
                || mWmService.mUmInternal.isUserVisible(userId, mDisplayId);
+37 −0
Original line number Original line Diff line number Diff line
@@ -114,6 +114,8 @@ import android.metrics.LogMaker;
import android.os.Binder;
import android.os.Binder;
import android.os.RemoteException;
import android.os.RemoteException;
import android.os.SystemClock;
import android.os.SystemClock;
import android.os.UserHandle;
import android.os.UserManager;
import android.platform.test.annotations.Presubmit;
import android.platform.test.annotations.Presubmit;
import android.platform.test.annotations.RequiresFlagsDisabled;
import android.platform.test.annotations.RequiresFlagsDisabled;
import android.platform.test.flag.junit.CheckFlagsRule;
import android.platform.test.flag.junit.CheckFlagsRule;
@@ -2813,6 +2815,41 @@ public class DisplayContentTests extends WindowTestsBase {
                mDisplayContent.getKeepClearAreas());
                mDisplayContent.getKeepClearAreas());
    }
    }


    @Test
    public void testHasAccessConsidersUserVisibilityForBackgroundVisibleUsers() {
        doReturn(true).when(() -> UserManager.isVisibleBackgroundUsersEnabled());
        final int appId = 1234;
        final int userId1 = 11;
        final int userId2 = 12;
        final int uid1 = UserHandle.getUid(userId1, appId);
        final int uid2 = UserHandle.getUid(userId2, appId);
        final DisplayInfo displayInfo = new DisplayInfo(mDisplayInfo);
        final DisplayContent dc = createNewDisplay(displayInfo);
        int displayId = dc.getDisplayId();
        doReturn(true).when(mWm.mUmInternal).isUserVisible(userId1, displayId);
        doReturn(false).when(mWm.mUmInternal).isUserVisible(userId2, displayId);

        assertTrue(dc.hasAccess(uid1));
        assertFalse(dc.hasAccess(uid2));
    }

    @Test
    public void testHasAccessIgnoresUserVisibilityForPrivateDisplay() {
        doReturn(true).when(() -> UserManager.isVisibleBackgroundUsersEnabled());
        final int appId = 1234;
        final int userId2 = 12;
        final int uid2 = UserHandle.getUid(userId2, appId);
        final DisplayInfo displayInfo = new DisplayInfo(mDisplayInfo);
        displayInfo.flags = FLAG_PRIVATE;
        displayInfo.ownerUid = uid2;
        final DisplayContent dc = createNewDisplay(displayInfo);
        int displayId = dc.getDisplayId();

        assertTrue(dc.hasAccess(uid2));

        verify(mWm.mUmInternal, never()).isUserVisible(userId2, displayId);
    }

    private void removeRootTaskTests(Runnable runnable) {
    private void removeRootTaskTests(Runnable runnable) {
        final TaskDisplayArea taskDisplayArea = mRootWindowContainer.getDefaultTaskDisplayArea();
        final TaskDisplayArea taskDisplayArea = mRootWindowContainer.getDefaultTaskDisplayArea();
        final Task rootTask1 = taskDisplayArea.createRootTask(WINDOWING_MODE_FULLSCREEN,
        final Task rootTask1 = taskDisplayArea.createRootTask(WINDOWING_MODE_FULLSCREEN,