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

Commit 37d215f6 authored by Kazuki Takise's avatar Kazuki Takise
Browse files

Disallow invisible presentations

For security reasons, presentations should not exist in an
invisible state, so remove them immediately when they become
invisible.

Flag: com.android.window.flags.enable_presentation_for_connected_displays
Bug: 417406465
Test: PresentationControllerTests#testInvisiblePresentationIsNotAllowed
Change-Id: I33471146e072c6c53ef2ce8e1404394fb17f140a
parent af3aec1e
Loading
Loading
Loading
Loading
+7 −3
Original line number Diff line number Diff line
@@ -225,13 +225,17 @@ class PresentationController implements DisplayManager.DisplayListener {
    void removePresentation(int displayId, @NonNull String reason) {
        final Presentation presentation = mPresentations.get(displayId);
        if (ENABLE_PRESENTATION_FOR_CONNECTED_DISPLAYS.isTrue() && presentation != null) {
            ProtoLog.v(WmProtoLogGroups.WM_DEBUG_PRESENTATION, "Removing Presentation %s for "
                    + "reason %s", mPresentations.get(displayId), reason);
            final WindowState win = presentation.mWin;
            win.mWmService.mAtmService.mH.post(() -> {
                synchronized (win.mWmService.mGlobalLock) {
                    // Invoke removeIfPossible() only if the presentation isn't being removed.
                    if (!win.mAnimatingExit || !win.mRemoveOnExit) {
                        ProtoLog.v(WmProtoLogGroups.WM_DEBUG_PRESENTATION,
                                "Removing Presentation %s for reason %s",
                                mPresentations.get(displayId), reason);
                        win.removeIfPossible();
                    }
                }
            });
        }
    }
+6 −0
Original line number Diff line number Diff line
@@ -5514,6 +5514,12 @@ class WindowState extends WindowContainer<WindowState> implements WindowManagerP

    void setViewVisibility(int viewVisibility) {
        mViewVisibility = viewVisibility;

        if (isPresentation()
                && (viewVisibility == View.INVISIBLE || viewVisibility == View.GONE)) {
            mWmService.mPresentationController.removePresentation(getDisplayId(),
                    "setViewVisibility");
        }
    }

    SurfaceControl getClientViewRootSurface() {
+27 −0
Original line number Diff line number Diff line
@@ -171,6 +171,33 @@ public class PresentationControllerTests extends WindowTestsBase {
        assertAddPresentationWindowFails(uid + 1, presentationDisplay.mDisplayId);
    }

    @EnableFlags(FLAG_ENABLE_PRESENTATION_FOR_CONNECTED_DISPLAYS)
    @Test
    public void testInvisiblePresentationIsNotAllowed() {
        final int uid = Binder.getCallingUid();
        final Task task = createTask(mDefaultDisplay);
        task.effectiveUid = uid;
        final ActivityRecord activity = createActivityRecord(task);
        assertTrue(activity.isVisible());

        // Add a presentation window on a presentation display.
        final DisplayContent presentationDisplay = createPresentationDisplay();
        final WindowState window = addPresentationWindow(uid, presentationDisplay.getDisplayId());
        window.setViewVisibility(View.VISIBLE);
        final Transition addTransition = window.mTransitionController.getCollectingTransition();
        completeTransition(addTransition, /*abortSync=*/ true);
        assertTrue(window.isVisible());

        // Making the presentation view invisible automatically removes it.
        window.setViewVisibility(View.GONE);
        assertTrue(window.isVisible());
        waitHandlerIdle(window.mWmService.mAtmService.mH);
        final Transition removeTransition = window.mTransitionController.getCollectingTransition();
        assertEquals(TRANSIT_CLOSE, removeTransition.mType);
        completeTransition(removeTransition, /*abortSync=*/ false);
        assertFalse(window.isVisible());
    }

    @EnableFlags(FLAG_ENABLE_PRESENTATION_FOR_CONNECTED_DISPLAYS)
    @Test
    public void testPresentationCannotLaunchOnNonPresentationDisplayWithoutHostHavingGlobalFocus() {