From 94541b99b999955c1f50ce39650eb824f6f9e38d Mon Sep 17 00:00:00 2001 From: Vinit Nayak Date: Sat, 18 Apr 2020 12:02:35 -0700 Subject: [PATCH] Rotate overview only if system rotation allowed Don't rotate overview if all of launcher can be rotated. Fixes: 154243745, 154299710 Test: Toggled system rotation while overview was showing. Also toggled home rotation to ensure no intermediate overview rotation animation. Change-Id: I49acf2dafb84e7f05c46f8908ba9ffdd43f1d1e7 --- .../android/quickstep/views/RecentsView.java | 27 +++++++---- .../quickstep/util/RecentsOrientedState.java | 46 +++++++++++++++---- 2 files changed, 55 insertions(+), 18 deletions(-) diff --git a/quickstep/recents_ui_overrides/src/com/android/quickstep/views/RecentsView.java b/quickstep/recents_ui_overrides/src/com/android/quickstep/views/RecentsView.java index e8d314dc95..08a5ee9147 100644 --- a/quickstep/recents_ui_overrides/src/com/android/quickstep/views/RecentsView.java +++ b/quickstep/recents_ui_overrides/src/com/android/quickstep/views/RecentsView.java @@ -285,6 +285,9 @@ public abstract class RecentsView extends PagedView impl } }; + private final RecentsOrientedState.SystemRotationChangeListener mSystemRotationChangeListener = + enabled -> toggleOrientationEventListener(); + private final PinnedStackAnimationListener mIPinnedStackAnimationListener = new PinnedStackAnimationListener(); @@ -487,6 +490,7 @@ public abstract class RecentsView extends PagedView impl mIPinnedStackAnimationListener); setActionsView(); mOrientationState.init(); + mOrientationState.addSystemRotationChangeListener(mSystemRotationChangeListener); } @Override @@ -501,6 +505,7 @@ public abstract class RecentsView extends PagedView impl mIdp.removeOnChangeListener(this); SystemUiProxy.INSTANCE.get(getContext()).setPinnedStackAnimationListener(null); mIPinnedStackAnimationListener.setActivity(null); + mOrientationState.removeSystemRotationChangeListener(mSystemRotationChangeListener); mOrientationState.destroy(); } @@ -555,13 +560,6 @@ public abstract class RecentsView extends PagedView impl } public void setOverviewStateEnabled(boolean enabled) { - if (canEnableOverviewRotationAnimation()) { - if (enabled) { - mOrientationListener.enable(); - } else { - mOrientationListener.disable(); - } - } mOverviewStateEnabled = enabled; updateTaskStackListenerState(); if (!enabled) { @@ -569,13 +567,26 @@ public abstract class RecentsView extends PagedView impl // its thumbnail mTmpRunningTask = null; } + toggleOrientationEventListener(); + } + + private void toggleOrientationEventListener() { + boolean canEnable = canEnableOverviewRotationAnimation() && mOverviewStateEnabled; + UI_HELPER_EXECUTOR.execute(() -> { + if (canEnable) { + mOrientationListener.enable(); + } else { + mOrientationListener.disable(); + } + }); } private boolean canEnableOverviewRotationAnimation() { return supportsVerticalLandscape() // not 3P launcher && !TestProtocol.sDisableSensorRotation // Ignore hardware dependency for tests.. && mOrientationListener.canDetectOrientation() // ..but does the hardware even work? - && !mOrientationState.canLauncherAutoRotate(); // launcher is going to rotate itself + && (mOrientationState.isSystemRotationAllowed() && + !mOrientationState.canLauncherRotate()); // launcher is going to rotate itself } public void onDigitalWellbeingToastShown() { diff --git a/quickstep/src/com/android/quickstep/util/RecentsOrientedState.java b/quickstep/src/com/android/quickstep/util/RecentsOrientedState.java index eefe8ac04b..bc0d2cc9f3 100644 --- a/quickstep/src/com/android/quickstep/util/RecentsOrientedState.java +++ b/quickstep/src/com/android/quickstep/util/RecentsOrientedState.java @@ -51,6 +51,8 @@ import com.android.launcher3.touch.PagedOrientationHandler; import com.android.launcher3.touch.PortraitPagedViewHandler; import java.lang.annotation.Retention; +import java.util.ArrayList; +import java.util.List; /** * Container to hold orientation/rotation related information for Launcher. @@ -81,6 +83,10 @@ public final class RecentsOrientedState implements SharedPreferences.OnSharedPre private @SurfaceRotation int mDisplayRotation = ROTATION_0; private @SurfaceRotation int mLauncherRotation = Surface.ROTATION_0; + public interface SystemRotationChangeListener { + void onSystemRotationChanged(boolean enabled); + } + /** * If {@code true} we default to {@link PortraitPagedViewHandler} and don't support any fake * launcher orientations. @@ -93,6 +99,7 @@ public final class RecentsOrientedState implements SharedPreferences.OnSharedPre private final SharedPreferences mSharedPrefs; private final boolean mAllowConfigurationDefaultValue; + private List mSystemRotationChangeListeners = new ArrayList<>(); private final Matrix mTmpMatrix = new Matrix(); private final Matrix mTmpInverseMatrix = new Matrix(); @@ -167,14 +174,6 @@ public final class RecentsOrientedState implements SharedPreferences.OnSharedPre return true; } - public boolean areMultipleLayoutOrientationsDisabled() { - return mDisableMultipleOrientations; - } - - public boolean canLauncherAutoRotate() { - return mIsHomeRotationAllowed && mIsSystemRotationAllowed; - } - /** * Setting this preference renders future calls to {@link #update(int, int, int)} as a no-op. */ @@ -198,6 +197,10 @@ public final class RecentsOrientedState implements SharedPreferences.OnSharedPre } catch (Settings.SettingNotFoundException e) { Log.e(TAG, "autorotate setting not found", e); } + + for (SystemRotationChangeListener listener : mSystemRotationChangeListeners) { + listener.onSystemRotationChanged(mIsSystemRotationAllowed); + } } private void updateHomeRotationSetting() { @@ -205,6 +208,15 @@ public final class RecentsOrientedState implements SharedPreferences.OnSharedPre mAllowConfigurationDefaultValue); } + public void addSystemRotationChangeListener(SystemRotationChangeListener listener) { + mSystemRotationChangeListeners.add(listener); + listener.onSystemRotationChanged(mIsSystemRotationAllowed); + } + + public void removeSystemRotationChangeListener(SystemRotationChangeListener listener) { + mSystemRotationChangeListeners.remove(listener); + } + public void init() { mSharedPrefs.registerOnSharedPreferenceChangeListener(this); mContentResolver.registerContentObserver( @@ -217,6 +229,7 @@ public final class RecentsOrientedState implements SharedPreferences.OnSharedPre public void destroy() { mSharedPrefs.unregisterOnSharedPreferenceChangeListener(this); mContentResolver.unregisterContentObserver(mSystemAutoRotateObserver); + mSystemRotationChangeListeners.clear(); } @SurfaceRotation @@ -229,12 +242,25 @@ public final class RecentsOrientedState implements SharedPreferences.OnSharedPre return mTouchRotation; } + @SurfaceRotation + public int getLauncherRotation() { + return mLauncherRotation; + } + + public boolean areMultipleLayoutOrientationsDisabled() { + return mDisableMultipleOrientations; + } + + public boolean isSystemRotationAllowed() { + return mIsSystemRotationAllowed; + } + public boolean isHomeRotationAllowed() { return mIsHomeRotationAllowed; } - public int getLauncherRotation() { - return mLauncherRotation; + public boolean canLauncherRotate() { + return isSystemRotationAllowed() && isHomeRotationAllowed(); } public int getTouchRotationDegrees() {