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

Commit 0384f120 authored by Adrian Roos's avatar Adrian Roos
Browse files

WM: Refactor DisplayContent.getOrientation in preparation for DisplayArea (2/n)

DisplayContent.getOrientation:
 - When the display is frozen, we no longer need to keep track of the last
   non-app-window requested orientation, if any, because the case of the
   keyguard becoming intermittently unoccluded is now handled by the condition
   just below.
 - We no longer ignore the above app window containers while the display is frozen.
   This was originally introduced so we don't pick up the keyguard's orientation
   during occlusion, but this was no longer necessary once we started tracking the
   occlusion state explicitly.
 - The logic for forcing the keyguard orientation whenever it is showing or we're
   unoccluding is now moved to the NonAppWindowContainer, in preparation for
   DisplayArea.

NonAppWindowContainer.getOrientation:
 - Cleaned up looking for the orienting view when Keyguard is going away

Bug: 147406652
Test: atest WmTests
Change-Id: Icb0b6f3e80d26a5ce060f2379ca0ca26f6146bbf
parent efa4070b
Loading
Loading
Loading
Loading
+45 −58
Original line number Diff line number Diff line
@@ -396,14 +396,6 @@ class DisplayContent extends WindowContainer<DisplayContent.DisplayChildWindowCo
    /** @see #getCurrentOverrideConfigurationChanges */
    private int mCurrentOverrideConfigurationChanges;

    /**
     * Orientation forced by some window. If there is no visible window that specifies orientation
     * it is set to {@link android.content.pm.ActivityInfo#SCREEN_ORIENTATION_UNSPECIFIED}.
     *
     * @see NonAppWindowContainers#getOrientation()
     */
    private int mLastWindowForcedOrientation = SCREEN_ORIENTATION_UNSPECIFIED;

    /**
     * Last orientation forced by the keyguard. It is applied when keyguard is shown and is not
     * occluded.
@@ -1250,11 +1242,6 @@ class DisplayContent extends WindowContainer<DisplayContent.DisplayChildWindowCo
        return mDisplayRotation.getLastOrientation();
    }

    @ScreenOrientation
    int getLastWindowForcedOrientation() {
        return mLastWindowForcedOrientation;
    }

    void registerRemoteAnimations(RemoteAnimationDefinition definition) {
        mAppTransitionController.registerRemoteAnimations(definition);
    }
@@ -2101,16 +2088,7 @@ class DisplayContent extends WindowContainer<DisplayContent.DisplayChildWindowCo
        }

        if (mWmService.mDisplayFrozen) {
            if (mLastWindowForcedOrientation != SCREEN_ORIENTATION_UNSPECIFIED) {
                ProtoLog.v(WM_DEBUG_ORIENTATION,
                        "Display id=%d is frozen, return %d", mDisplayId,
                        mLastWindowForcedOrientation);
                // If the display is frozen, some activities may be in the middle of restarting, and
                // thus have removed their old window. If the window has the flag to hide the lock
                // screen, then the lock screen can re-appear and inflict its own orientation on us.
                // Keep the orientation stable until this all settles down.
                return mLastWindowForcedOrientation;
            } else if (policy.isKeyguardLocked()) {
            if (policy.isKeyguardLocked()) {
                // Use the last orientation the while the display is frozen with the keyguard
                // locked. This could be the keyguard forced orientation or from a SHOW_WHEN_LOCKED
                // window. We don't want to check the show when locked window directly though as
@@ -2121,12 +2099,11 @@ class DisplayContent extends WindowContainer<DisplayContent.DisplayChildWindowCo
                        mDisplayId, getLastOrientation());
                return getLastOrientation();
            }
        } else {
        }
        final int orientation = mAboveAppWindowsContainers.getOrientation();
        if (orientation != SCREEN_ORIENTATION_UNSET) {
            return orientation;
        }
        }

        // Top system windows are not requesting an orientation. Start searching from apps.
        return mTaskStackContainers.getOrientation();
@@ -4088,6 +4065,8 @@ class DisplayContent extends WindowContainer<DisplayContent.DisplayChildWindowCo

        DisplayChildWindowContainer(WindowManagerService service) {
            super(service);
            // TODO(display-area): move to ConfigurationContainer?
            mOrientation = SCREEN_ORIENTATION_UNSET;
        }

        @Override
@@ -4482,7 +4461,7 @@ class DisplayContent extends WindowContainer<DisplayContent.DisplayChildWindowCo
        }

        @Override
        int getOrientation() {
        int getOrientation(int candidate) {
            if (isStackVisible(WINDOWING_MODE_SPLIT_SCREEN_PRIMARY)) {
                // Apps and their containers are not allowed to specify an orientation while the
                // docked stack is visible...except for the home stack if the docked stack is
@@ -4500,7 +4479,7 @@ class DisplayContent extends WindowContainer<DisplayContent.DisplayChildWindowCo
                return SCREEN_ORIENTATION_UNSPECIFIED;
            }

            final int orientation = super.getOrientation();
            final int orientation = super.getOrientation(candidate);
            if (orientation != SCREEN_ORIENTATION_UNSET
                    && orientation != SCREEN_ORIENTATION_BEHIND) {
                ProtoLog.v(WM_DEBUG_ORIENTATION,
@@ -4755,9 +4734,23 @@ class DisplayContent extends WindowContainer<DisplayContent.DisplayChildWindowCo
                        token2.mOwnerCanManageAppTokens) ? -1 : 1;

        private final Predicate<WindowState> mGetOrientingWindow = w -> {
            if (!w.isVisibleLw() || !w.mLegacyPolicyVisibilityAfterAnim) {
            final WindowManagerPolicy policy = mWmService.mPolicy;
            if (policy.isKeyguardHostWindow(w.mAttrs)) {
                if (mWmService.mKeyguardGoingAway) {
                    return false;
                }
                // Consider unoccluding only when all unknown visibilities have been
                // resolved, as otherwise we just may be starting another occluding activity.
                final boolean isUnoccluding =
                        mDisplayContent.mAppTransition.getAppTransition()
                                == TRANSIT_KEYGUARD_UNOCCLUDE
                                && mDisplayContent.mUnknownAppVisibilityController.allResolved();
                // If keyguard is showing, or we're unoccluding, force the keyguard's orientation,
                // even if SystemUI hasn't updated the attrs yet.
                if (policy.isKeyguardShowingAndNotOccluded() || isUnoccluding) {
                    return true;
                }
            }
            final int req = w.mAttrs.screenOrientation;
            if (req == SCREEN_ORIENTATION_UNSPECIFIED || req == SCREEN_ORIENTATION_BEHIND
                    || req == SCREEN_ORIENTATION_UNSET) {
@@ -4786,39 +4779,27 @@ class DisplayContent extends WindowContainer<DisplayContent.DisplayChildWindowCo
        }

        @Override
        int getOrientation() {
            final WindowManagerPolicy policy = mWmService.mPolicy;
        int getOrientation(int candidate) {
            // Find a window requesting orientation.
            final WindowState win = getWindow(mGetOrientingWindow);

            if (win != null) {
                final int req = win.mAttrs.screenOrientation;
                if (policy.isKeyguardHostWindow(win.mAttrs)) {
                    mLastKeyguardForcedOrientation = req;
                    if (mWmService.mKeyguardGoingAway) {
                        // Keyguard can't affect the orientation if it is going away...
                        mLastWindowForcedOrientation = SCREEN_ORIENTATION_UNSPECIFIED;
                        return SCREEN_ORIENTATION_UNSET;
                    }
                }
                int req = win.mAttrs.screenOrientation;
                ProtoLog.v(WM_DEBUG_ORIENTATION,
                        "%s forcing orientation to %d for display id=%d", win, req,
                        mDisplayId);
                return (mLastWindowForcedOrientation = req);
                if (mWmService.mPolicy.isKeyguardHostWindow(win.mAttrs)) {
                    // SystemUI controls the Keyguard orientation asynchronously, and mAttrs may be
                    // stale. We record / use the last known override.
                    if (req != SCREEN_ORIENTATION_UNSET && req != SCREEN_ORIENTATION_UNSPECIFIED) {
                        mDisplayContent.mLastKeyguardForcedOrientation = req;
                    } else {
                        req = mDisplayContent.mLastKeyguardForcedOrientation;
                    }

            mLastWindowForcedOrientation = SCREEN_ORIENTATION_UNSPECIFIED;

            // Only allow force setting the orientation when all unknown visibilities have been
            // resolved, as otherwise we just may be starting another occluding activity.
            final boolean isUnoccluding =
                    mAppTransition.getAppTransition() == TRANSIT_KEYGUARD_UNOCCLUDE
                            && mUnknownAppVisibilityController.allResolved();
            if (policy.isKeyguardShowingAndNotOccluded() || isUnoccluding) {
                return mLastKeyguardForcedOrientation;
                }

            return SCREEN_ORIENTATION_UNSET;
                return req;
            }
            return candidate;
        }

        @Override
@@ -4864,6 +4845,12 @@ class DisplayContent extends WindowContainer<DisplayContent.DisplayChildWindowCo
            mNeedsLayer = true;
        }

        @Override
        int getOrientation(int candidate) {
            // IME does not participate in orientation.
            return candidate;
        }

        @Override
        boolean forAllWindows(ToBooleanFunction<WindowState> callback,
                boolean traverseTopToBottom) {
+4 −6
Original line number Diff line number Diff line
@@ -5948,8 +5948,6 @@ public class WindowManagerService extends IWindowManager.Stub
                    pw.print(" apps="); pw.print(mAppsFreezingScreen);
            final DisplayContent defaultDisplayContent = getDefaultDisplayContentLocked();
            pw.print("  mRotation="); pw.print(defaultDisplayContent.getRotation());
            pw.print("  mLastWindowForcedOrientation=");
                    pw.print(defaultDisplayContent.getLastWindowForcedOrientation());
            pw.print("  mLastOrientation=");
                    pw.println(defaultDisplayContent.getLastOrientation());
            pw.print(" waitingForConfig=");