Re-enable orientation sensor for Overview animation
Slight revert of ag/10668129 with adjustment
of disabling it for tests.
Fixes: 151456795
Test: Ran the labtest command for OOP
tests for crosshatch (where this issue
was first detected)
Change-Id: I315d138c2e4a6d4068304e9b5fb2e1b7feb34e63
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 57a9940..4a36f54 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
@@ -69,6 +69,7 @@
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.MotionEvent;
+import android.view.OrientationEventListener;
import android.view.View;
import android.view.ViewDebug;
import android.view.ViewGroup;
@@ -88,6 +89,7 @@
import com.android.launcher3.PagedView;
import com.android.launcher3.R;
import com.android.launcher3.Utilities;
+import com.android.launcher3.anim.AnimationSuccessListener;
import com.android.launcher3.anim.AnimatorPlaybackController;
import com.android.launcher3.anim.PendingAnimation;
import com.android.launcher3.anim.PendingAnimation.EndState;
@@ -98,6 +100,7 @@
import com.android.launcher3.graphics.RotationMode;
import com.android.launcher3.statehandlers.DepthController;
import com.android.launcher3.states.RotationHelper;
+import com.android.launcher3.testing.TestProtocol;
import com.android.launcher3.touch.PagedOrientationHandler.CurveProperties;
import com.android.launcher3.userevent.nano.LauncherLogProto;
import com.android.launcher3.userevent.nano.LauncherLogProto.Action.Direction;
@@ -167,6 +170,7 @@
}
};
+ private OrientationEventListener mOrientationListener;
private int mPreviousRotation;
protected RecentsAnimationController mRecentsAnimationController;
protected RecentsAnimationTargets mRecentsAnimationTargets;
@@ -374,6 +378,22 @@
// Initialize quickstep specific cache params here, as this is constructed only once
mActivity.getViewCache().setCacheSize(R.layout.digital_wellbeing_toast, 5);
+
+ mOrientationListener = new OrientationEventListener(getContext()) {
+ @Override
+ public void onOrientationChanged(int i) {
+ int rotation = RotationHelper.getRotationFromDegrees(i);
+ if (mPreviousRotation != rotation) {
+ animateRecentsRotationInPlace(rotation);
+ if (rotation == 0) {
+ showActionsView();
+ } else {
+ hideActionsView();
+ }
+ mPreviousRotation = rotation;
+ }
+ }
+ };
}
public OverScroller getScroller() {
@@ -502,6 +522,15 @@
}
public void setOverviewStateEnabled(boolean enabled) {
+ if (supportsVerticalLandscape()
+ && !TestProtocol.sDisableSensorRotation // Ignore hardware dependency for tests
+ && mOrientationListener.canDetectOrientation()) {
+ if (enabled) {
+ mOrientationListener.enable();
+ } else {
+ mOrientationListener.disable();
+ }
+ }
mOverviewStateEnabled = enabled;
updateTaskStackListenerState();
if (!enabled) {
@@ -945,6 +974,35 @@
setSwipeDownShouldLaunchApp(true);
}
+ private void animateRecentsRotationInPlace(int newRotation) {
+ if (!supportsVerticalLandscape()) {
+ return;
+ }
+
+ AnimatorSet pa = setRecentsChangedOrientation(true);
+ pa.addListener(AnimationSuccessListener.forRunnable(() -> {
+ updateLayoutRotation(newRotation);
+ mActivity.getDragLayer().recreateControllers();
+ rotateAllChildTasks();
+ setRecentsChangedOrientation(false).start();
+ }));
+ pa.start();
+ }
+
+ public AnimatorSet setRecentsChangedOrientation(boolean fadeInChildren) {
+ getRunningTaskIndex();
+ int runningIndex = getCurrentPage();
+ AnimatorSet as = new AnimatorSet();
+ for (int i = 0; i < getTaskViewCount(); i++) {
+ if (runningIndex == i) {
+ continue;
+ }
+ View taskView = getTaskViewAt(i);
+ as.play(ObjectAnimator.ofFloat(taskView, View.ALPHA, fadeInChildren ? 0 : 1));
+ }
+ return as;
+ }
+
abstract protected boolean supportsVerticalLandscape();
private void rotateAllChildTasks() {
diff --git a/src/com/android/launcher3/testing/TestInformationHandler.java b/src/com/android/launcher3/testing/TestInformationHandler.java
index 4e49c6e..e786f07 100644
--- a/src/com/android/launcher3/testing/TestInformationHandler.java
+++ b/src/com/android/launcher3/testing/TestInformationHandler.java
@@ -184,6 +184,10 @@
mDeviceProfile.allAppsCellHeightPx);
break;
}
+
+ case TestProtocol.REQUEST_MOCK_SENSOR_ROTATION:
+ TestProtocol.sDisableSensorRotation = true;
+ break;
}
return response;
}
diff --git a/src/com/android/launcher3/testing/TestProtocol.java b/src/com/android/launcher3/testing/TestProtocol.java
index 9f20df6..3181752 100644
--- a/src/com/android/launcher3/testing/TestProtocol.java
+++ b/src/com/android/launcher3/testing/TestProtocol.java
@@ -92,6 +92,9 @@
public static final String REQUEST_OVERVIEW_ACTIONS_ENABLED = "overview-actions-enabled";
+ public static boolean sDisableSensorRotation;
+ public static final String REQUEST_MOCK_SENSOR_ROTATION = "mock-sensor-rotation";
+
public static final String PERMANENT_DIAG_TAG = "TaplTarget";
public static final String NO_BACKGROUND_TO_OVERVIEW_TAG = "b/138251824";
diff --git a/tests/src/com/android/launcher3/ui/AbstractLauncherUiTest.java b/tests/src/com/android/launcher3/ui/AbstractLauncherUiTest.java
index 7cd656e..873f1cb 100644
--- a/tests/src/com/android/launcher3/ui/AbstractLauncherUiTest.java
+++ b/tests/src/com/android/launcher3/ui/AbstractLauncherUiTest.java
@@ -162,6 +162,7 @@
mLauncher.enableDebugTracing();
// Avoid double-reporting of Launcher crashes.
mLauncher.setOnLauncherCrashed(() -> mLauncherPid = 0);
+ mLauncher.disableSensorRotation();
}
protected final LauncherActivityRule mActivityMonitor = new LauncherActivityRule();
@@ -277,6 +278,7 @@
clearPackageData(mDevice.getLauncherPackageName());
mLauncher.enableDebugTracing();
mLauncherPid = mLauncher.getPid();
+ mLauncher.disableSensorRotation();
}
}
diff --git a/tests/tapl/com/android/launcher3/tapl/LauncherInstrumentation.java b/tests/tapl/com/android/launcher3/tapl/LauncherInstrumentation.java
index d171a69..d7374a4 100644
--- a/tests/tapl/com/android/launcher3/tapl/LauncherInstrumentation.java
+++ b/tests/tapl/com/android/launcher3/tapl/LauncherInstrumentation.java
@@ -1255,6 +1255,10 @@
TestProtocol.TEST_INFO_RESPONSE_FIELD);
}
+ public void disableSensorRotation() {
+ getTestInfo(TestProtocol.REQUEST_MOCK_SENSOR_ROTATION);
+ }
+
public void disableDebugTracing() {
getTestInfo(TestProtocol.REQUEST_DISABLE_DEBUG_TRACING);
}