From a62b62081de816201a62a9477709c7aaf93f526a Mon Sep 17 00:00:00 2001 From: Matthew Ng Date: Mon, 3 Dec 2018 15:58:52 -0800 Subject: [PATCH] Fixed quickscrub regression Forgot that quickscrub does not proxy motion events when refactoring. Added a new function for actions to proxy events and made sure that the test catches if events were proxied. Test: atest QuickStepControllerTest Change-Id: I8c047816aa266dfd9d220df7d47a13dadf5987f9 Fixes: 119502592 --- .../phone/NavigationGestureAction.java | 9 ++++++++ .../statusbar/phone/QuickScrubAction.java | 5 ++++ .../statusbar/phone/QuickStepController.java | 23 +++++++++---------- .../phone/QuickStepControllerTest.java | 5 +++- 4 files changed, 29 insertions(+), 13 deletions(-) diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/phone/NavigationGestureAction.java b/packages/SystemUI/src/com/android/systemui/statusbar/phone/NavigationGestureAction.java index 83067f6cff87c..a8d00c454548f 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/NavigationGestureAction.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/NavigationGestureAction.java @@ -126,6 +126,15 @@ public abstract class NavigationGestureAction { return true; } + /** + * Decide if the controller should not send the current motion event to launcher via + * {@link OverviewProxyService} + * @return if controller should not proxy + */ + public boolean disableProxyEvents() { + return false; + } + /** * Tell if action is enabled. Compared to {@link #canPerformAction()} this is based on settings * if the action is disabled for a particular gesture. For example a back action can be enabled diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/phone/QuickScrubAction.java b/packages/SystemUI/src/com/android/systemui/statusbar/phone/QuickScrubAction.java index 74744f1408fb2..2b202eb834315 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/QuickScrubAction.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/QuickScrubAction.java @@ -211,6 +211,11 @@ public class QuickScrubAction extends NavigationGestureAction { return mNavigationBarView.isQuickScrubEnabled(); } + @Override + public boolean disableProxyEvents() { + return true; + } + @Override protected void onGestureStart(MotionEvent event) { updateHighlight(); diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/phone/QuickStepController.java b/packages/SystemUI/src/com/android/systemui/statusbar/phone/QuickStepController.java index 497fdfb2deb17..c3fff30339e5a 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/QuickStepController.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/QuickStepController.java @@ -274,25 +274,21 @@ public class QuickStepController implements GestureHelper { if (mDragVPositive ? (posV < touchDownV) : (posV > touchDownV)) { // Swiping up gesture tryToStartGesture(mGestureActions[ACTION_SWIPE_UP_INDEX], - false /* alignedWithNavBar */, false /* positiveDirection */, - event); + false /* alignedWithNavBar */, event); } else { // Swiping down gesture tryToStartGesture(mGestureActions[ACTION_SWIPE_DOWN_INDEX], - false /* alignedWithNavBar */, true /* positiveDirection */, - event); + false /* alignedWithNavBar */, event); } } else if (exceededSwipeHorizontalTouchSlop) { if (mDragHPositive ? (posH < touchDownH) : (posH > touchDownH)) { // Swiping left (ltr) gesture tryToStartGesture(mGestureActions[ACTION_SWIPE_LEFT_INDEX], - true /* alignedWithNavBar */, false /* positiveDirection */, - event); + true /* alignedWithNavBar */, event); } else { // Swiping right (ltr) gesture tryToStartGesture(mGestureActions[ACTION_SWIPE_RIGHT_INDEX], - true /* alignedWithNavBar */, true /* positiveDirection */, - event); + true /* alignedWithNavBar */, event); } } } @@ -305,7 +301,6 @@ public class QuickStepController implements GestureHelper { case MotionEvent.ACTION_UP: if (mCurrentAction != null) { mCurrentAction.endGesture(); - mCurrentAction = null; } // Return the hit target back to its original position @@ -328,6 +323,11 @@ public class QuickStepController implements GestureHelper { if (shouldProxyEvents(action)) { proxyMotionEvents(event); } + + // Clear action when gesture and event proxy finishes + if (action == MotionEvent.ACTION_CANCEL || action == MotionEvent.ACTION_UP) { + mCurrentAction = null; + } return mCurrentAction != null || deadZoneConsumed; } @@ -353,8 +353,7 @@ public class QuickStepController implements GestureHelper { private boolean shouldProxyEvents(int action) { final boolean actionValid = (mCurrentAction == null - || (mGestureActions[ACTION_SWIPE_UP_INDEX] != null - && mGestureActions[ACTION_SWIPE_UP_INDEX].isActive())); + || !mCurrentAction.disableProxyEvents()); if (actionValid && !mIsInScreenPinning) { // Allow down, cancel and up events, move and other events are passed if notifications // are not showing and disabled gestures (such as long press) are not executed @@ -451,7 +450,7 @@ public class QuickStepController implements GestureHelper { } private void tryToStartGesture(NavigationGestureAction action, boolean alignedWithNavBar, - boolean positiveDirection, MotionEvent event) { + MotionEvent event) { if (action == null) { return; } diff --git a/packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/QuickStepControllerTest.java b/packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/QuickStepControllerTest.java index 4177cd16c8bfc..8fc15b247ab9b 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/QuickStepControllerTest.java +++ b/packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/QuickStepControllerTest.java @@ -38,12 +38,12 @@ import static org.mockito.Mockito.spy; import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; -import android.content.Context; import com.android.systemui.R; import com.android.systemui.recents.OverviewProxyService; import com.android.systemui.shared.recents.IOverviewProxy; import com.android.systemui.SysuiTestCase; +import android.content.Context; import android.content.res.Resources; import android.support.test.filters.SmallTest; import android.testing.AndroidTestingRunner; @@ -395,6 +395,7 @@ public class QuickStepControllerTest extends SysuiTestCase { verify(mProxy, times(1)).onQuickScrubStart(); verify(mProxyService, times(1)).notifyQuickScrubStarted(); verify(mNavigationBarView, times(1)).updateSlippery(); + verify(mProxy, never()).onMotionEvent(moveEvent1); // Move again for scrub MotionEvent moveEvent2 = event(MotionEvent.ACTION_MOVE, 200, y); @@ -402,6 +403,7 @@ public class QuickStepControllerTest extends SysuiTestCase { assertEquals(action, mController.getCurrentAction()); verify(action, times(1)).onGestureMove(200, y); verify(mProxy, times(1)).onQuickScrubProgress(1f / 2); + verify(mProxy, never()).onMotionEvent(moveEvent2); // Action up MotionEvent upEvent = event(MotionEvent.ACTION_UP, 1, y); @@ -409,6 +411,7 @@ public class QuickStepControllerTest extends SysuiTestCase { assertNull(mController.getCurrentAction()); verify(action, times(1)).onGestureEnd(); verify(mProxy, times(1)).onQuickScrubEnd(); + verify(mProxy, never()).onMotionEvent(upEvent); } @Test