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

Commit 31dca6dc authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Added VISIBLE_FOR_USER flag for policy visibility" into qt-dev

parents ec0bd298 15ad49fb
Loading
Loading
Loading
Loading
+4 −3
Original line number Original line Diff line number Diff line
@@ -78,6 +78,7 @@ import static com.android.server.wm.WindowManagerService.H.NOTIFY_ACTIVITY_DRAWN
import static com.android.server.wm.WindowManagerService.UPDATE_FOCUS_NORMAL;
import static com.android.server.wm.WindowManagerService.UPDATE_FOCUS_NORMAL;
import static com.android.server.wm.WindowManagerService.UPDATE_FOCUS_WILL_PLACE_SURFACES;
import static com.android.server.wm.WindowManagerService.UPDATE_FOCUS_WILL_PLACE_SURFACES;
import static com.android.server.wm.WindowManagerService.logWithStack;
import static com.android.server.wm.WindowManagerService.logWithStack;
import static com.android.server.wm.WindowState.LEGACY_POLICY_VISIBILITY;
import static com.android.server.wm.WindowStateAnimator.STACK_CLIP_AFTER_ANIM;
import static com.android.server.wm.WindowStateAnimator.STACK_CLIP_AFTER_ANIM;
import static com.android.server.wm.WindowStateAnimator.STACK_CLIP_BEFORE_ANIM;
import static com.android.server.wm.WindowStateAnimator.STACK_CLIP_BEFORE_ANIM;


@@ -638,8 +639,8 @@ class AppWindowToken extends WindowToken implements WindowManagerService.AppFree
                // If we are being set visible, and the starting window is not yet displayed,
                // If we are being set visible, and the starting window is not yet displayed,
                // then make sure it doesn't get displayed.
                // then make sure it doesn't get displayed.
                if (startingWindow != null && !startingWindow.isDrawnLw()) {
                if (startingWindow != null && !startingWindow.isDrawnLw()) {
                    startingWindow.mPolicyVisibility = false;
                    startingWindow.clearPolicyVisibilityFlag(LEGACY_POLICY_VISIBILITY);
                    startingWindow.mPolicyVisibilityAfterAnim = false;
                    startingWindow.mLegacyPolicyVisibilityAfterAnim = false;
                }
                }


                // We are becoming visible, so better freeze the screen with the windows that are
                // We are becoming visible, so better freeze the screen with the windows that are
@@ -1932,7 +1933,7 @@ class AppWindowToken extends WindowToken implements WindowManagerService.AppFree
                        + ", isAnimationSet=" + isSelfAnimating());
                        + ", isAnimationSet=" + isSelfAnimating());
                if (!w.isDrawnLw()) {
                if (!w.isDrawnLw()) {
                    Slog.v(TAG, "Not displayed: s=" + winAnimator.mSurfaceController
                    Slog.v(TAG, "Not displayed: s=" + winAnimator.mSurfaceController
                            + " pv=" + w.mPolicyVisibility
                            + " pv=" + w.isVisibleByPolicy()
                            + " mDrawState=" + winAnimator.drawStateToString()
                            + " mDrawState=" + winAnimator.drawStateToString()
                            + " ph=" + w.isParentWindowHidden() + " th=" + hiddenRequested
                            + " ph=" + w.isParentWindowHidden() + " th=" + hiddenRequested
                            + " a=" + isSelfAnimating());
                            + " a=" + isSelfAnimating());
+1 −1
Original line number Original line Diff line number Diff line
@@ -4562,7 +4562,7 @@ class DisplayContent extends WindowContainer<DisplayContent.DisplayChildWindowCo
                        token2.mOwnerCanManageAppTokens) ? -1 : 1;
                        token2.mOwnerCanManageAppTokens) ? -1 : 1;


        private final Predicate<WindowState> mGetOrientingWindow = w -> {
        private final Predicate<WindowState> mGetOrientingWindow = w -> {
            if (!w.isVisibleLw() || !w.mPolicyVisibilityAfterAnim) {
            if (!w.isVisibleLw() || !w.mLegacyPolicyVisibilityAfterAnim) {
                return false;
                return false;
            }
            }
            final int req = w.mAttrs.screenOrientation;
            final int req = w.mAttrs.screenOrientation;
+3 −4
Original line number Original line Diff line number Diff line
@@ -29,12 +29,11 @@ import android.annotation.Nullable;
import android.graphics.Point;
import android.graphics.Point;
import android.graphics.Rect;
import android.graphics.Rect;
import android.util.proto.ProtoOutputStream;
import android.util.proto.ProtoOutputStream;
import android.view.InsetsSource;
import android.view.InsetsSourceControl;
import android.view.InsetsState;
import android.view.InsetsState;
import android.view.SurfaceControl;
import android.view.SurfaceControl;
import android.view.SurfaceControl.Transaction;
import android.view.SurfaceControl.Transaction;
import android.view.InsetsSource;
import android.view.InsetsSourceControl;
import android.view.ViewRootImpl;


import com.android.internal.util.function.TriConsumer;
import com.android.internal.util.function.TriConsumer;
import com.android.internal.util.function.pooled.PooledLambda;
import com.android.internal.util.function.pooled.PooledLambda;
@@ -142,7 +141,7 @@ class InsetsSourceProvider {
                mStateController.notifyControlChanged(mControllingWin);
                mStateController.notifyControlChanged(mControllingWin);
            }
            }
        }
        }
        setServerVisible(mWin.wouldBeVisibleIfPolicyIgnored() && mWin.mPolicyVisibility
        setServerVisible(mWin.wouldBeVisibleIfPolicyIgnored() && mWin.isVisibleByPolicy()
                && !mWin.mGivenInsetsPending);
                && !mWin.mGivenInsetsPending);
    }
    }


+1 −1
Original line number Original line Diff line number Diff line
@@ -5300,7 +5300,7 @@ public class WindowManagerService extends IWindowManager.Stub
                    ": removed=" + win.mRemoved + " visible=" + win.isVisibleLw() +
                    ": removed=" + win.mRemoved + " visible=" + win.isVisibleLw() +
                    " mHasSurface=" + win.mHasSurface +
                    " mHasSurface=" + win.mHasSurface +
                    " drawState=" + win.mWinAnimator.mDrawState);
                    " drawState=" + win.mWinAnimator.mDrawState);
            if (win.mRemoved || !win.mHasSurface || !win.mPolicyVisibility) {
            if (win.mRemoved || !win.mHasSurface || !win.isVisibleByPolicy()) {
                // Window has been removed or hidden; no draw will now happen, so stop waiting.
                // Window has been removed or hidden; no draw will now happen, so stop waiting.
                if (DEBUG_SCREEN_ON) Slog.w(TAG_WM, "Aborted waiting for drawn: " + win);
                if (DEBUG_SCREEN_ON) Slog.w(TAG_WM, "Aborted waiting for drawn: " + win);
                mWaitingForDrawn.remove(win);
                mWaitingForDrawn.remove(win);
+74 −32
Original line number Original line Diff line number Diff line
@@ -251,18 +251,33 @@ class WindowState extends WindowContainer<WindowState> implements WindowManagerP
    int mSeq;
    int mSeq;
    int mViewVisibility;
    int mViewVisibility;
    int mSystemUiVisibility;
    int mSystemUiVisibility;

    /**
    /**
     * The visibility of the window based on policy like {@link WindowManagerPolicy}.
     * The visibility flag of the window based on policy like {@link WindowManagerPolicy}.
     * Normally set by calling {@link #showLw} and {@link #hideLw}.
     * Normally set by calling {@link #showLw} and {@link #hideLw}.
     *
     * TODO: b/131253938 This will eventually be split into individual visibility policy flags.
     */
    static final int LEGACY_POLICY_VISIBILITY = 1;
    /**
     * The visibility flag that determines whether this window is visible for the current user.
     */
     */
    boolean mPolicyVisibility = true;
    private static final int VISIBLE_FOR_USER = 1 << 1;
    private static final int POLICY_VISIBILITY_ALL = VISIBLE_FOR_USER | LEGACY_POLICY_VISIBILITY;
    /**
    /**
     * What {@link #mPolicyVisibility} should be set to after a transition animation.
     * The Bitwise-or of flags that contribute to visibility of the WindowState
     * For example, {@link #mPolicyVisibility} might true during an exit animation to hide it and
     * then set to the value of {@link #mPolicyVisibilityAfterAnim} which is false after the exit
     * animation is done.
     */
     */
    boolean mPolicyVisibilityAfterAnim = true;
    private int mPolicyVisibility = POLICY_VISIBILITY_ALL;

    /**
     * Whether {@link #LEGACY_POLICY_VISIBILITY} flag should be set after a transition animation.
     * For example, {@link #LEGACY_POLICY_VISIBILITY} might be set during an exit animation to hide
     * it and then unset when the value of {@link #mLegacyPolicyVisibilityAfterAnim} is false
     * after the exit animation is done.
     *
     * TODO: b/131253938 Determine whether this can be changed to use a visibility flag instead.
     */
    boolean mLegacyPolicyVisibilityAfterAnim = true;
    // overlay window is hidden because the owning app is suspended
    // overlay window is hidden because the owning app is suspended
    private boolean mHiddenWhileSuspended;
    private boolean mHiddenWhileSuspended;
    private boolean mAppOpVisibility = true;
    private boolean mAppOpVisibility = true;
@@ -1414,12 +1429,32 @@ class WindowState extends WindowContainer<WindowState> implements WindowManagerP


    @Override
    @Override
    boolean isVisible() {
    boolean isVisible() {
        return wouldBeVisibleIfPolicyIgnored() && mPolicyVisibility
        return wouldBeVisibleIfPolicyIgnored() && isVisibleByPolicy()
                // If we don't have a provider, this window isn't used as a window generating
                // 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.
                // insets, so nobody can hide it over the inset APIs.
                && (mInsetProvider == null || mInsetProvider.isClientVisible());
                && (mInsetProvider == null || mInsetProvider.isClientVisible());
    }
    }


    /**
     * Ensures that all the policy visibility bits are set.
     * @return {@code true} if all flags about visiblity are set
     */
    boolean isVisibleByPolicy() {
        return (mPolicyVisibility & POLICY_VISIBILITY_ALL) == POLICY_VISIBILITY_ALL;
    }

    void clearPolicyVisibilityFlag(int policyVisibilityFlag) {
        mPolicyVisibility &= ~policyVisibilityFlag;
    }

    void setPolicyVisibilityFlag(int policyVisibilityFlag) {
        mPolicyVisibility |= policyVisibilityFlag;
    }

    private boolean isLegacyPolicyVisibility() {
        return (mPolicyVisibility & LEGACY_POLICY_VISIBILITY) != 0;
    }

    /**
    /**
     * @return {@code true} if the window would be visible if we'd ignore policy visibility,
     * @return {@code true} if the window would be visible if we'd ignore policy visibility,
     *         {@code false} otherwise.
     *         {@code false} otherwise.
@@ -1470,7 +1505,7 @@ class WindowState extends WindowContainer<WindowState> implements WindowManagerP
    boolean isVisibleOrAdding() {
    boolean isVisibleOrAdding() {
        final AppWindowToken atoken = mAppToken;
        final AppWindowToken atoken = mAppToken;
        return (mHasSurface || (!mRelayoutCalled && mViewVisibility == View.VISIBLE))
        return (mHasSurface || (!mRelayoutCalled && mViewVisibility == View.VISIBLE))
                && mPolicyVisibility && !isParentWindowHidden()
                && isVisibleByPolicy() && !isParentWindowHidden()
                && (atoken == null || !atoken.hiddenRequested)
                && (atoken == null || !atoken.hiddenRequested)
                && !mAnimatingExit && !mDestroying;
                && !mAnimatingExit && !mDestroying;
    }
    }
@@ -1481,7 +1516,7 @@ class WindowState extends WindowContainer<WindowState> implements WindowManagerP
     * being visible.
     * being visible.
     */
     */
    boolean isOnScreen() {
    boolean isOnScreen() {
        if (!mHasSurface || mDestroying || !mPolicyVisibility) {
        if (!mHasSurface || mDestroying || !isVisibleByPolicy()) {
            return false;
            return false;
        }
        }
        final AppWindowToken atoken = mAppToken;
        final AppWindowToken atoken = mAppToken;
@@ -1522,7 +1557,7 @@ class WindowState extends WindowContainer<WindowState> implements WindowManagerP
        }
        }
        final boolean parentAndClientVisible = !isParentWindowHidden()
        final boolean parentAndClientVisible = !isParentWindowHidden()
                && mViewVisibility == View.VISIBLE && !mToken.isHidden();
                && mViewVisibility == View.VISIBLE && !mToken.isHidden();
        return mHasSurface && mPolicyVisibility && !mDestroying
        return mHasSurface && isVisibleByPolicy() && !mDestroying
                && (parentAndClientVisible || isAnimating());
                && (parentAndClientVisible || isAnimating());
    }
    }


@@ -1551,7 +1586,7 @@ class WindowState extends WindowContainer<WindowState> implements WindowManagerP
    @Override
    @Override
    public boolean isDisplayedLw() {
    public boolean isDisplayedLw() {
        final AppWindowToken atoken = mAppToken;
        final AppWindowToken atoken = mAppToken;
        return isDrawnLw() && mPolicyVisibility
        return isDrawnLw() && isVisibleByPolicy()
                && ((!isParentWindowHidden() && (atoken == null || !atoken.hiddenRequested))
                && ((!isParentWindowHidden() && (atoken == null || !atoken.hiddenRequested))
                        || isAnimating());
                        || isAnimating());
    }
    }
@@ -2057,8 +2092,8 @@ class WindowState extends WindowContainer<WindowState> implements WindowManagerP
                Slog.i(TAG_WM, "  mSurfaceController=" + mWinAnimator.mSurfaceController
                Slog.i(TAG_WM, "  mSurfaceController=" + mWinAnimator.mSurfaceController
                        + " relayoutCalled=" + mRelayoutCalled
                        + " relayoutCalled=" + mRelayoutCalled
                        + " viewVis=" + mViewVisibility
                        + " viewVis=" + mViewVisibility
                        + " policyVis=" + mPolicyVisibility
                        + " policyVis=" + isVisibleByPolicy()
                        + " policyVisAfterAnim=" + mPolicyVisibilityAfterAnim
                        + " policyVisAfterAnim=" + mLegacyPolicyVisibilityAfterAnim
                        + " parentHidden=" + isParentWindowHidden()
                        + " parentHidden=" + isParentWindowHidden()
                        + " exiting=" + mAnimatingExit + " destroying=" + mDestroying);
                        + " exiting=" + mAnimatingExit + " destroying=" + mDestroying);
                if (mAppToken != null) {
                if (mAppToken != null) {
@@ -2192,7 +2227,9 @@ class WindowState extends WindowContainer<WindowState> implements WindowManagerP
        if (isHiddenFromUserLocked()) {
        if (isHiddenFromUserLocked()) {
            if (DEBUG_VISIBILITY) Slog.w(TAG_WM, "user changing, hiding " + this
            if (DEBUG_VISIBILITY) Slog.w(TAG_WM, "user changing, hiding " + this
                    + ", attrs=" + mAttrs.type + ", belonging to " + mOwnerUid);
                    + ", attrs=" + mAttrs.type + ", belonging to " + mOwnerUid);
            hideLw(false);
            clearPolicyVisibilityFlag(VISIBLE_FOR_USER);
        } else {
            setPolicyVisibilityFlag(VISIBLE_FOR_USER);
        }
        }
    }
    }


@@ -2284,13 +2321,17 @@ class WindowState extends WindowContainer<WindowState> implements WindowManagerP
    }
    }


    void checkPolicyVisibilityChange() {
    void checkPolicyVisibilityChange() {
        if (mPolicyVisibility != mPolicyVisibilityAfterAnim) {
        if (isLegacyPolicyVisibility() != mLegacyPolicyVisibilityAfterAnim) {
            if (DEBUG_VISIBILITY) {
            if (DEBUG_VISIBILITY) {
                Slog.v(TAG, "Policy visibility changing after anim in " +
                Slog.v(TAG, "Policy visibility changing after anim in " +
                        mWinAnimator + ": " + mPolicyVisibilityAfterAnim);
                        mWinAnimator + ": " + mLegacyPolicyVisibilityAfterAnim);
            }
            if (mLegacyPolicyVisibilityAfterAnim) {
                setPolicyVisibilityFlag(LEGACY_POLICY_VISIBILITY);
            } else {
                clearPolicyVisibilityFlag(LEGACY_POLICY_VISIBILITY);
            }
            }
            mPolicyVisibility = mPolicyVisibilityAfterAnim;
            if (!isVisibleByPolicy()) {
            if (!mPolicyVisibility) {
                mWinAnimator.hide("checkPolicyVisibilityChange");
                mWinAnimator.hide("checkPolicyVisibilityChange");
                if (isFocused()) {
                if (isFocused()) {
                    if (DEBUG_FOCUS_LIGHT) Slog.i(TAG,
                    if (DEBUG_FOCUS_LIGHT) Slog.i(TAG,
@@ -2531,7 +2572,7 @@ class WindowState extends WindowContainer<WindowState> implements WindowManagerP
    }
    }


    boolean showLw(boolean doAnimation, boolean requestAnim) {
    boolean showLw(boolean doAnimation, boolean requestAnim) {
        if (mPolicyVisibility && mPolicyVisibilityAfterAnim) {
        if (isLegacyPolicyVisibility() && mLegacyPolicyVisibilityAfterAnim) {
            // Already showing.
            // Already showing.
            return false;
            return false;
        }
        }
@@ -2558,18 +2599,18 @@ class WindowState extends WindowContainer<WindowState> implements WindowManagerP
        if (DEBUG_VISIBILITY) Slog.v(TAG, "Policy visibility true: " + this);
        if (DEBUG_VISIBILITY) Slog.v(TAG, "Policy visibility true: " + this);
        if (doAnimation) {
        if (doAnimation) {
            if (DEBUG_VISIBILITY) Slog.v(TAG, "doAnimation: mPolicyVisibility="
            if (DEBUG_VISIBILITY) Slog.v(TAG, "doAnimation: mPolicyVisibility="
                    + mPolicyVisibility + " animating=" + isAnimating());
                    + isLegacyPolicyVisibility() + " animating=" + isAnimating());
            if (!mToken.okToAnimate()) {
            if (!mToken.okToAnimate()) {
                doAnimation = false;
                doAnimation = false;
            } else if (mPolicyVisibility && !isAnimating()) {
            } else if (isLegacyPolicyVisibility() && !isAnimating()) {
                // Check for the case where we are currently visible and
                // Check for the case where we are currently visible and
                // not animating; we do not want to do animation at such a
                // not animating; we do not want to do animation at such a
                // point to become visible when we already are.
                // point to become visible when we already are.
                doAnimation = false;
                doAnimation = false;
            }
            }
        }
        }
        mPolicyVisibility = true;
        setPolicyVisibilityFlag(LEGACY_POLICY_VISIBILITY);
        mPolicyVisibilityAfterAnim = true;
        mLegacyPolicyVisibilityAfterAnim = true;
        if (doAnimation) {
        if (doAnimation) {
            mWinAnimator.applyAnimationLocked(TRANSIT_ENTER, true);
            mWinAnimator.applyAnimationLocked(TRANSIT_ENTER, true);
        }
        }
@@ -2593,7 +2634,8 @@ class WindowState extends WindowContainer<WindowState> implements WindowManagerP
                doAnimation = false;
                doAnimation = false;
            }
            }
        }
        }
        boolean current = doAnimation ? mPolicyVisibilityAfterAnim : mPolicyVisibility;
        boolean current =
                doAnimation ? mLegacyPolicyVisibilityAfterAnim : isLegacyPolicyVisibility();
        if (!current) {
        if (!current) {
            // Already hiding.
            // Already hiding.
            return false;
            return false;
@@ -2604,11 +2646,11 @@ class WindowState extends WindowContainer<WindowState> implements WindowManagerP
                doAnimation = false;
                doAnimation = false;
            }
            }
        }
        }
        mPolicyVisibilityAfterAnim = false;
        mLegacyPolicyVisibilityAfterAnim = false;
        final boolean isFocused = isFocused();
        final boolean isFocused = isFocused();
        if (!doAnimation) {
        if (!doAnimation) {
            if (DEBUG_VISIBILITY) Slog.v(TAG, "Policy visibility false: " + this);
            if (DEBUG_VISIBILITY) Slog.v(TAG, "Policy visibility false: " + this);
            mPolicyVisibility = false;
            clearPolicyVisibilityFlag(LEGACY_POLICY_VISIBILITY);
            // Window is no longer visible -- make sure if we were waiting
            // Window is no longer visible -- make sure if we were waiting
            // for it to be displayed before enabling the display, that
            // for it to be displayed before enabling the display, that
            // we allow the display to be enabled now.
            // we allow the display to be enabled now.
@@ -3443,11 +3485,11 @@ class WindowState extends WindowContainer<WindowState> implements WindowManagerP
            pw.println(prefix + "mSeq=" + mSeq
            pw.println(prefix + "mSeq=" + mSeq
                    + " mSystemUiVisibility=0x" + Integer.toHexString(mSystemUiVisibility));
                    + " mSystemUiVisibility=0x" + Integer.toHexString(mSystemUiVisibility));
        }
        }
        if (!mPolicyVisibility || !mPolicyVisibilityAfterAnim || !mAppOpVisibility
        if (!isVisibleByPolicy() || !mLegacyPolicyVisibilityAfterAnim || !mAppOpVisibility
                || isParentWindowHidden() || mPermanentlyHidden || mForceHideNonSystemOverlayWindow
                || isParentWindowHidden() || mPermanentlyHidden || mForceHideNonSystemOverlayWindow
                || mHiddenWhileSuspended) {
                || mHiddenWhileSuspended) {
            pw.println(prefix + "mPolicyVisibility=" + mPolicyVisibility
            pw.println(prefix + "mPolicyVisibility=" + isVisibleByPolicy()
                    + " mPolicyVisibilityAfterAnim=" + mPolicyVisibilityAfterAnim
                    + " mLegacyPolicyVisibilityAfterAnim=" + mLegacyPolicyVisibilityAfterAnim
                    + " mAppOpVisibility=" + mAppOpVisibility
                    + " mAppOpVisibility=" + mAppOpVisibility
                    + " parentHidden=" + isParentWindowHidden()
                    + " parentHidden=" + isParentWindowHidden()
                    + " mPermanentlyHidden=" + mPermanentlyHidden
                    + " mPermanentlyHidden=" + mPermanentlyHidden
@@ -3904,7 +3946,7 @@ class WindowState extends WindowContainer<WindowState> implements WindowManagerP
                    + ": mDrawState=" + mWinAnimator.drawStateToString()
                    + ": mDrawState=" + mWinAnimator.drawStateToString()
                    + " readyForDisplay=" + isReadyForDisplay()
                    + " readyForDisplay=" + isReadyForDisplay()
                    + " starting=" + (mAttrs.type == TYPE_APPLICATION_STARTING)
                    + " starting=" + (mAttrs.type == TYPE_APPLICATION_STARTING)
                    + " during animation: policyVis=" + mPolicyVisibility
                    + " during animation: policyVis=" + isVisibleByPolicy()
                    + " parentHidden=" + isParentWindowHidden()
                    + " parentHidden=" + isParentWindowHidden()
                    + " tok.hiddenRequested="
                    + " tok.hiddenRequested="
                    + (mAppToken != null && mAppToken.hiddenRequested)
                    + (mAppToken != null && mAppToken.hiddenRequested)
@@ -4313,7 +4355,7 @@ class WindowState extends WindowContainer<WindowState> implements WindowManagerP
                    + ", animating=" + isAnimating());
                    + ", animating=" + isAnimating());
            if (!isDrawnLw()) {
            if (!isDrawnLw()) {
                Slog.v(TAG, "Not displayed: s=" + mWinAnimator.mSurfaceController
                Slog.v(TAG, "Not displayed: s=" + mWinAnimator.mSurfaceController
                        + " pv=" + mPolicyVisibility
                        + " pv=" + isVisibleByPolicy()
                        + " mDrawState=" + mWinAnimator.mDrawState
                        + " mDrawState=" + mWinAnimator.mDrawState
                        + " ph=" + isParentWindowHidden()
                        + " ph=" + isParentWindowHidden()
                        + " th=" + (mAppToken != null ? mAppToken.hiddenRequested : false)
                        + " th=" + (mAppToken != null ? mAppToken.hiddenRequested : false)
Loading