Iterate over all swipeable regions when calculating quickswitch gesture bounds
Previously when creating a new CurrentDisplay, we would
never get the correct OrientationRectF from the hashmap
because the size field of CurrentDisplay would be incorrect
for a given rotation.
Ex. Rotation 0 and Rotation 1 would have inverted display sizes
Thus hashcode would return different values and we would only
ever see if a point is contained in the current rotation's
OrientationRectF.
Bug: 183897242
Test: Tested swiping from portrait to landscape app, was
able to swipe continuously
Change-Id: I6de625389956f55cfc2142dcb7aeef2e90c157ac
diff --git a/quickstep/robolectric_tests/src/com/android/quickstep/OrientationTouchTransformerTest.java b/quickstep/robolectric_tests/src/com/android/quickstep/OrientationTouchTransformerTest.java
index eca27b5..e771962 100644
--- a/quickstep/robolectric_tests/src/com/android/quickstep/OrientationTouchTransformerTest.java
+++ b/quickstep/robolectric_tests/src/com/android/quickstep/OrientationTouchTransformerTest.java
@@ -247,10 +247,7 @@
}
@Test
- @Ignore("There's too much that goes into needing to mock a real motion event so the "
- + "transforms in native code get applied correctly. Once that happens then maybe we can"
- + " write slightly more complex unit tests")
- public void applyTransform_taskNotFrozen_90Rotate_inTwoRegions() {
+ public void applyTransform_taskNotFrozen_90Rotate_withTwoRegions() {
mTouchTransformer.createOrAddTouchRegion(mInfo);
mTouchTransformer.enableMultipleRegions(true, mInfo);
mTouchTransformer
@@ -262,6 +259,7 @@
// Portrait point in landscape orientation axis
MotionEvent inRegion2 = generateMotionEvent(MotionEvent.ACTION_DOWN, 10, 10);
mTouchTransformer.transform(inRegion1_down);
+ // no-op
mTouchTransformer.transform(inRegion2);
assertTrue(mTouchTransformer.touchInValidSwipeRegions(
inRegion1_down.getX(), inRegion1_down.getY()));
@@ -269,9 +267,19 @@
assertFalse(mTouchTransformer.touchInValidSwipeRegions(inRegion2.getX(), inRegion2.getY()));
mTouchTransformer.transform(inRegion1_up);
+ }
- // Set the new region with this MotionEvent.ACTION_DOWN
- inRegion2 = generateAndTransformMotionEvent(MotionEvent.ACTION_DOWN, 10, 370);
+ @Test
+ public void applyTransform_90Rotate_inRotatedRegion() {
+ // Create regions for both 0 Rotation and 90 Rotation
+ mTouchTransformer.createOrAddTouchRegion(mInfo);
+ mTouchTransformer.enableMultipleRegions(true, mInfo);
+ mTouchTransformer
+ .createOrAddTouchRegion(createDisplayInfo(NORMAL_SCREEN_SIZE, Surface.ROTATION_90));
+ // Portrait point in landscape orientation axis
+ float x1 = generateTouchRegionHeight(NORMAL_SCREEN_SIZE, Surface.ROTATION_0);
+ // bottom of screen, from landscape perspective right side of screen
+ MotionEvent inRegion2 = generateAndTransformMotionEvent(MotionEvent.ACTION_DOWN, x1, 370);
assertTrue(mTouchTransformer.touchInValidSwipeRegions(inRegion2.getX(), inRegion2.getY()));
}
diff --git a/quickstep/src/com/android/quickstep/OrientationTouchTransformer.java b/quickstep/src/com/android/quickstep/OrientationTouchTransformer.java
index a749f9a..2a6e478 100644
--- a/quickstep/src/com/android/quickstep/OrientationTouchTransformer.java
+++ b/quickstep/src/com/android/quickstep/OrientationTouchTransformer.java
@@ -53,7 +53,7 @@
*/
class OrientationTouchTransformer {
- class CurrentDisplay {
+ private static class CurrentDisplay {
public Point size;
public int rotation;
@@ -68,6 +68,13 @@
}
@Override
+ public String toString() {
+ return "CurrentDisplay:"
+ + " rotation: " + rotation
+ + " size: " + size;
+ }
+
+ @Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
@@ -86,21 +93,20 @@
private static final String TAG = "OrientationTouchTransformer";
private static final boolean DEBUG = false;
- private static final int MAX_ORIENTATIONS = 4;
private static final int QUICKSTEP_ROTATION_UNINITIALIZED = -1;
private final Matrix mTmpMatrix = new Matrix();
private final float[] mTmpPoint = new float[2];
- private Map<CurrentDisplay, OrientationRectF> mSwipeTouchRegions =
+ private final Map<CurrentDisplay, OrientationRectF> mSwipeTouchRegions =
new HashMap<CurrentDisplay, OrientationRectF>();
private final RectF mAssistantLeftRegion = new RectF();
private final RectF mAssistantRightRegion = new RectF();
private final RectF mOneHandedModeRegion = new RectF();
private CurrentDisplay mCurrentDisplay = new CurrentDisplay();
private int mNavBarGesturalHeight;
- private int mNavBarLargerGesturalHeight;
+ private final int mNavBarLargerGesturalHeight;
private boolean mEnableMultipleRegions;
private Resources mResources;
private OrientationRectF mLastRectTouched;
@@ -374,10 +380,7 @@
return;
}
- for (int i = 0; i < MAX_ORIENTATIONS; i++) {
- CurrentDisplay display = new CurrentDisplay(mCurrentDisplay.size, i);
- OrientationRectF rect = mSwipeTouchRegions.get(display);
-
+ for (OrientationRectF rect : mSwipeTouchRegions.values()) {
if (TestProtocol.sDebugTracing) {
Log.d(TestProtocol.NO_SWIPE_TO_HOME, "transform:DOWN, rect=" + rect);
}