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

Commit 00abf9e1 authored by Kazuki Takise's avatar Kazuki Takise Committed by Android (Google) Code Review
Browse files

Merge "Disallow invisible presentations" into main

parents 674ca99d 37d215f6
Loading
Loading
Loading
Loading
+7 −3
Original line number Diff line number Diff line
@@ -224,13 +224,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
@@ -5587,6 +5587,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() {