From 95cb52a647c512b77aa7fd13081cecd86cab1a52 Mon Sep 17 00:00:00 2001 From: Riddle Hsu Date: Fri, 12 Jun 2020 00:44:02 +0800 Subject: [PATCH] Don't lock rotation to natural rotation when entering overview Overview (recents) will use fixed portrait orientation if home rotation is disabled, then the orientation will be portrait when leaving overview to a application which was rotated to landscape. Which is inconsistent from user perspective. This change ignores the rotation change caused by the overview once. So the original user rotation can be preserved. Bug: 148982179 Test: 1. Disable auto-rotation and home rotation. 2. Launch an activity in portrait. 3. Rotate the device to landscape and press rotation button. 4. Enter overview (recents). 5. Return to the application. Check with 2-button, 3-button, and gesture navigation. The device should be in landscape after step 5. And the behavior doesn't change with home rotation enabled. Change-Id: I43005753031b13e66c3c388b221d51ce3fd543bf --- .../systemui/recents/OverviewProxyRecentsImpl.java | 1 + .../systemui/recents/OverviewProxyService.java | 8 ++++++++ .../statusbar/phone/NavigationBarFragment.java | 14 ++++++++++++++ .../statusbar/phone/RotationButtonController.java | 14 ++++++++++++++ 4 files changed, 37 insertions(+) diff --git a/packages/SystemUI/src/com/android/systemui/recents/OverviewProxyRecentsImpl.java b/packages/SystemUI/src/com/android/systemui/recents/OverviewProxyRecentsImpl.java index f3e2f104621e4..f89185e3efa94 100644 --- a/packages/SystemUI/src/com/android/systemui/recents/OverviewProxyRecentsImpl.java +++ b/packages/SystemUI/src/com/android/systemui/recents/OverviewProxyRecentsImpl.java @@ -118,6 +118,7 @@ public class OverviewProxyRecentsImpl implements RecentsImplementation { try { if (mOverviewProxyService.getProxy() != null) { mOverviewProxyService.getProxy().onOverviewToggle(); + mOverviewProxyService.notifyToggleRecentApps(); } } catch (RemoteException e) { Log.e(TAG, "Cannot send toggle recents through proxy service.", e); diff --git a/packages/SystemUI/src/com/android/systemui/recents/OverviewProxyService.java b/packages/SystemUI/src/com/android/systemui/recents/OverviewProxyService.java index 8a012b8b06f18..d0347f9f34867 100644 --- a/packages/SystemUI/src/com/android/systemui/recents/OverviewProxyService.java +++ b/packages/SystemUI/src/com/android/systemui/recents/OverviewProxyService.java @@ -871,6 +871,12 @@ public class OverviewProxyService extends CurrentUserTracker implements } } + void notifyToggleRecentApps() { + for (int i = mConnectionCallbacks.size() - 1; i >= 0; --i) { + mConnectionCallbacks.get(i).onToggleRecentApps(); + } + } + private void updateEnabledState() { mIsEnabled = mContext.getPackageManager().resolveServiceAsUser(mQuickStepIntent, MATCH_SYSTEM_ONLY, @@ -901,6 +907,8 @@ public class OverviewProxyService extends CurrentUserTracker implements default void onQuickSwitchToNewTask(@Surface.Rotation int rotation) {} default void onOverviewShown(boolean fromHome) {} default void onQuickScrubStarted() {} + /** Notify the recents app (overview) is started by 3-button navigation. */ + default void onToggleRecentApps() {} /** Notify changes in the nav bar button alpha */ default void onNavBarButtonAlphaChanged(float alpha, boolean animate) {} default void onSystemUiStateChanged(int sysuiStateFlags) {} diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/phone/NavigationBarFragment.java b/packages/SystemUI/src/com/android/systemui/statusbar/phone/NavigationBarFragment.java index 8954d98d02015..1548a4ada8243 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/NavigationBarFragment.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/NavigationBarFragment.java @@ -323,6 +323,20 @@ public class NavigationBarFragment extends LifecycleFragment implements Callback buttonDispatcher.setAlpha(forceVisible ? 1f : alpha, animate); } } + + @Override + public void onOverviewShown(boolean fromHome) { + // If the overview has fixed orientation that may change display to natural rotation, + // we don't want the user rotation to be reset. So after user returns to application, + // it can keep in the original rotation. + mNavigationBarView.getRotationButtonController().setSkipOverrideUserLockPrefsOnce(); + } + + @Override + public void onToggleRecentApps() { + // The same case as onOverviewShown but only for 3-button navigation. + mNavigationBarView.getRotationButtonController().setSkipOverrideUserLockPrefsOnce(); + } }; private NavigationBarTransitions.DarkIntensityListener mOrientationHandleIntensityListener = diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/phone/RotationButtonController.java b/packages/SystemUI/src/com/android/systemui/statusbar/phone/RotationButtonController.java index de9c745cb3579..59b10e416b037 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/RotationButtonController.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/RotationButtonController.java @@ -74,6 +74,7 @@ public class RotationButtonController { private Consumer mRotWatcherListener; private boolean mListenersRegistered = false; private boolean mIsNavigationBarShowing; + private boolean mSkipOverrideUserLockPrefsOnce; private final Runnable mRemoveRotationProposal = () -> setRotateSuggestionButtonState(false /* visible */); @@ -349,7 +350,20 @@ public class RotationButtonController { mUiEventLogger.log(RotationButtonEvent.ROTATION_SUGGESTION_SHOWN); } + /** + * Makes {@link #shouldOverrideUserLockPrefs} always return {@code false} once. It is used to + * avoid losing original user rotation when display rotation is changed by entering the fixed + * orientation overview. + */ + void setSkipOverrideUserLockPrefsOnce() { + mSkipOverrideUserLockPrefsOnce = true; + } + private boolean shouldOverrideUserLockPrefs(final int rotation) { + if (mSkipOverrideUserLockPrefsOnce) { + mSkipOverrideUserLockPrefsOnce = false; + return false; + } // Only override user prefs when returning to the natural rotation (normally portrait). // Don't let apps that force landscape or 180 alter user lock. return rotation == NATURAL_ROTATION;