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

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

Merge "Don't allow to create a window in an unassigned display." into main

parents 7ddb8ae4 d53f7551
Loading
Loading
Loading
Loading
+5 −1
Original line number Diff line number Diff line
@@ -2705,7 +2705,11 @@ class DisplayContent extends RootDisplayArea implements WindowManagerPolicy.Disp
     * Returns true if the specified UID has access to this display.
     */
    boolean hasAccess(int uid) {
        return mDisplay.hasAccess(uid);
        int userId = UserHandle.getUserId(uid);
        boolean isUserVisibleOnDisplay = mWmService.mUmInternal.isUserVisible(
                userId, mDisplayId);
        return mDisplay.hasAccess(uid)
                && (userId == UserHandle.USER_SYSTEM || isUserVisibleOnDisplay);
    }

    boolean isPrivate() {
+20 −0
Original line number Diff line number Diff line
@@ -101,6 +101,7 @@ import android.view.View;
import android.view.WindowInsets;
import android.view.WindowManager;
import android.view.WindowManager.LayoutParams;
import android.view.WindowManagerGlobal;
import android.window.ActivityWindowInfo;
import android.window.ClientWindowFrames;
import android.window.InputTransferToken;
@@ -556,6 +557,7 @@ public class WindowManagerServiceTests extends WindowTestsBase {
                .hasListener(eq(windowContextToken));
        doReturn(TYPE_INPUT_METHOD).when(mWm.mWindowContextListenerController)
                .getWindowType(eq(windowContextToken));
        doReturn(true).when(mWm.mUmInternal).isUserVisible(anyInt(), anyInt());

        mWm.addWindow(session, new TestIWindow(), params, View.VISIBLE, DEFAULT_DISPLAY,
                UserHandle.USER_SYSTEM, WindowInsets.Type.defaultVisible(), null, new InsetsState(),
@@ -1308,6 +1310,24 @@ public class WindowManagerServiceTests extends WindowTestsBase {
        assertEquals(activityWindowInfo2, activityWindowInfo3);
    }

    @Test
    public void testAddOverlayWindowToUnassignedDisplay_notAllowed() {
        int uid = 100000; // uid for non-system user
        Session session = createTestSession(mAtm, 1234 /* pid */, uid);
        DisplayContent dc = createNewDisplay();
        int displayId = dc.getDisplayId();
        int userId = UserHandle.getUserId(uid);
        doReturn(false).when(mWm.mUmInternal).isUserVisible(eq(userId), eq(displayId));
        WindowManager.LayoutParams params = new WindowManager.LayoutParams(
                LayoutParams.TYPE_APPLICATION_OVERLAY);

        int result = mWm.addWindow(session, new TestIWindow(), params, View.VISIBLE, displayId,
                userId, WindowInsets.Type.defaultVisible(), null, new InsetsState(),
                new InsetsSourceControl.Array(), new Rect(), new float[1]);

        assertThat(result).isEqualTo(WindowManagerGlobal.ADD_INVALID_DISPLAY);
    }

    class TestResultReceiver implements IResultReceiver {
        public android.os.Bundle resultData;
        private final IBinder mBinder = mock(IBinder.class);