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

Commit 7ffe7418 authored by Tracy Zhou's avatar Tracy Zhou
Browse files

[Live Tile] Do not allow rotation in Overview when home rotation is off

In live tile mode, the live tile app is considered the top window and therefore rotation proposals are sent even when home rotation is disabled. To detect this, launcher needs to send over home rotation state, besides the nav bar needs to listen to recents animation state.

Fixes: 185962767
Test: manual

Change-Id: Ibc873d1067a8a3b37b6c20672cdb32ea356d9f21
parent c5f21ce4
Loading
Loading
Loading
Loading
+4 −1
Original line number Diff line number Diff line
@@ -134,5 +134,8 @@ interface ISystemUiProxy {
     */
    void onBackPressed() = 44;

    // Next id = 45
    /** Sets home rotation enabled. */
    void setHomeRotationEnabled(boolean enabled) = 45;

    // Next id = 46
}
+6 −0
Original line number Diff line number Diff line
@@ -363,6 +363,11 @@ public class NavigationBar implements View.OnAttachStateChangeListener,
            }
        }

        @Override
        public void onHomeRotationEnabled(boolean enabled) {
            mNavigationBarView.getRotationButtonController().setHomeRotationEnabled(enabled);
        }

        @Override
        public void onOverviewShown(boolean fromHome) {
            // If the overview has fixed orientation that may change display to natural rotation,
@@ -951,6 +956,7 @@ public class NavigationBar implements View.OnAttachStateChangeListener,
        if (running) {
            mNavbarOverlayController.setButtonState(/* visible */false, /* force */true);
        }
        mNavigationBarView.getRotationButtonController().setRecentsAnimationRunning(running);
    }

    /** Restores the appearance and the transient saved state to {@link NavigationBar}. */
+28 −6
Original line number Diff line number Diff line
@@ -71,6 +71,8 @@ public class RotationButtonController {
    private final ViewRippler mViewRippler = new ViewRippler();
    private RotationButton mRotationButton;

    private boolean mIsRecentsAnimationRunning;
    private boolean mHomeRotationEnabled;
    private int mLastRotationSuggestion;
    private boolean mPendingRotationSuggestion;
    private boolean mHoveringRotationSuggestion;
@@ -92,7 +94,6 @@ public class RotationButtonController {
            () -> mPendingRotationSuggestion = false;
    private Animator mRotateHideAnimator;


    private final Stub mRotationWatcher = new Stub() {
        @Override
        public void onRotationChanged(final int rotation) throws RemoteException {
@@ -105,7 +106,7 @@ public class RotationButtonController {
                    if (shouldOverrideUserLockPrefs(rotation)) {
                        setRotationLockedAtAngle(rotation);
                    }
                    setRotateSuggestionButtonState(false /* visible */, true /* forced */);
                    setRotateSuggestionButtonState(false /* visible */, true /* hideImmediately */);
                }

                if (mRotWatcherListener != null) {
@@ -192,10 +193,14 @@ public class RotationButtonController {
    }

    void setRotateSuggestionButtonState(boolean visible) {
        setRotateSuggestionButtonState(visible, false /* force */);
        setRotateSuggestionButtonState(visible, false /* hideImmediately */);
    }

    void setRotateSuggestionButtonState(final boolean visible, final boolean force) {
    /**
     * Change the visibility of rotate suggestion button. If {@code hideImmediately} is true,
     * it doesn't wait until the completion of the running animation.
     */
    void setRotateSuggestionButtonState(final boolean visible, final boolean hideImmediately) {
        // At any point the the button can become invisible because an a11y service became active.
        // Similarly, a call to make the button visible may be rejected because an a11y service is
        // active. Must account for this.
@@ -236,7 +241,7 @@ public class RotationButtonController {
        } else { // Hide
            mViewRippler.stop(); // Prevent any pending ripples, force hide or not

            if (force) {
            if (hideImmediately) {
                // If a hide animator is running stop it and make invisible
                if (mRotateHideAnimator != null && mRotateHideAnimator.isRunning()) {
                    mRotateHideAnimator.pause();
@@ -263,12 +268,29 @@ public class RotationButtonController {
        }
    }

    void setRecentsAnimationRunning(boolean running) {
        mIsRecentsAnimationRunning = running;
        updateRotationButtonStateInOverview();
    }

    void setHomeRotationEnabled(boolean enabled) {
        mHomeRotationEnabled = enabled;
        updateRotationButtonStateInOverview();
    }

    private void updateRotationButtonStateInOverview() {
        if (mIsRecentsAnimationRunning && !mHomeRotationEnabled) {
            setRotateSuggestionButtonState(false, true /* hideImmediately */ );
        }
    }

    void setDarkIntensity(float darkIntensity) {
        mRotationButton.setDarkIntensity(darkIntensity);
    }

    void onRotationProposal(int rotation, int windowRotation, boolean isValid) {
        if (!mRotationButton.acceptRotationProposal()) {
        if (!mRotationButton.acceptRotationProposal() || (!mHomeRotationEnabled
                && mIsRecentsAnimationRunning)) {
            return;
        }

+22 −0
Original line number Diff line number Diff line
@@ -259,6 +259,21 @@ public class OverviewProxyService extends CurrentUserTracker implements
            }
        }

        @Override
        public void setHomeRotationEnabled(boolean enabled) {
            if (!verifyCaller("setHomeRotationEnabled")) {
                return;
            }
            final long token = Binder.clearCallingIdentity();
            try {
                mHandler.post(() -> {
                    mHandler.post(() -> notifyHomeRotationEnabled(enabled));
                });
            } finally {
                Binder.restoreCallingIdentity(token);
            }
        }

        private boolean sendEvent(int action, int code) {
            long when = SystemClock.uptimeMillis();
            final KeyEvent ev = new KeyEvent(when, when, action, code, 0 /* repeat */,
@@ -847,6 +862,12 @@ public class OverviewProxyService extends CurrentUserTracker implements
        }
    }

    private void notifyHomeRotationEnabled(boolean enabled) {
        for (int i = mConnectionCallbacks.size() - 1; i >= 0; --i) {
            mConnectionCallbacks.get(i).onHomeRotationEnabled(enabled);
        }
    }

    private void notifyConnectionChanged() {
        for (int i = mConnectionCallbacks.size() - 1; i >= 0; --i) {
            mConnectionCallbacks.get(i).onConnectionChanged(mOverviewProxy != null);
@@ -994,6 +1015,7 @@ public class OverviewProxyService extends CurrentUserTracker implements
        default void onToggleRecentApps() {}
        /** Notify changes in the nav bar button alpha */
        default void onNavBarButtonAlphaChanged(float alpha, boolean animate) {}
        default void onHomeRotationEnabled(boolean enabled) {}
        default void onSystemUiStateChanged(int sysuiStateFlags) {}
        default void onAssistantProgress(@FloatRange(from = 0.0, to = 1.0) float progress) {}
        default void onAssistantGestureCompletion(float velocity) {}