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

Commit 399301ae authored by Evan Rosky's avatar Evan Rosky
Browse files

Make WindowState.isVisibleRequested actually report requested

It was just deferring to isVisible(). However, that wasn't correct
since it relies on committed state. Instead, this uses non-commit
information only.

Bug: 187461719
Test: atest WindowStateTests#testRequestedVisibility
Change-Id: I8e2b90310ce14f7739a392b513687ccae170a140
parent 4244ff3a
Loading
Loading
Loading
Loading
+22 −6
Original line number Diff line number Diff line
@@ -1823,21 +1823,27 @@ class WindowState extends WindowContainer<WindowState> implements WindowManagerP
        return super.hasContentToDisplay();
    }

    @Override
    boolean isVisible() {
        return wouldBeVisibleIfPolicyIgnored() && isVisibleByPolicy()
    private boolean isVisibleByPolicyOrInsets() {
        return isVisibleByPolicy()
                // If we don't have a provider, this window isn't used as a window generating
                // insets, so nobody can hide it over the inset APIs.
                && (mControllableInsetProvider == null
                        || mControllableInsetProvider.isClientVisible());
    }

    @Override
    boolean isVisible() {
        return wouldBeVisibleIfPolicyIgnored() && isVisibleByPolicyOrInsets();
    }

    @Override
    boolean isVisibleRequested() {
        if (shouldCheckTokenVisibleRequested()) {
            return isVisible() && mToken.isVisibleRequested();
        final boolean localVisibleRequested =
                wouldBeVisibleRequestedIfPolicyIgnored() && isVisibleByPolicyOrInsets();
        if (localVisibleRequested && shouldCheckTokenVisibleRequested()) {
            return mToken.isVisibleRequested();
        }
        return isVisible();
        return localVisibleRequested;
    }

    /**
@@ -1884,6 +1890,16 @@ class WindowState extends WindowContainer<WindowState> implements WindowManagerP
        return !isWallpaper || mToken.isVisible();
    }

    private boolean wouldBeVisibleRequestedIfPolicyIgnored() {
        final WindowState parent = getParentWindow();
        final boolean isParentHiddenRequested = parent != null && !parent.isVisibleRequested();
        if (isParentHiddenRequested || mAnimatingExit || mDestroying) {
            return false;
        }
        final boolean isWallpaper = mToken.asWallpaperToken() != null;
        return !isWallpaper || mToken.isVisibleRequested();
    }

    /**
     * Is this window visible, ignoring its app token? It is not visible if there is no surface,
     * or we are in the process of running an exit animation that will remove the surface.
+15 −0
Original line number Diff line number Diff line
@@ -956,4 +956,19 @@ public class WindowStateTests extends WindowTestsBase {
        assertNotNull(state.peekSource(ITYPE_IME));
        assertTrue(state.getSource(ITYPE_IME).isVisible());
    }

    @Test
    public void testRequestedVisibility() {
        final WindowState app = createWindow(null, TYPE_APPLICATION, "app");
        app.mActivityRecord.setVisible(false);
        app.mActivityRecord.setVisibility(false /* visible */, false /* deferHidingClient */);
        assertFalse(app.isVisibleRequested());

        // It doesn't have a surface yet, but should still be visible requested.
        app.setHasSurface(false);
        app.mActivityRecord.setVisibility(true /* visible */, false /* deferHidingClient */);

        assertFalse(app.isVisible());
        assertTrue(app.isVisibleRequested());
    }
}