diff options
| -rw-r--r-- | packages/SystemUI/src/com/android/systemui/shade/QuickSettingsController.java | 19 | ||||
| -rw-r--r-- | packages/SystemUI/tests/src/com/android/systemui/shade/QuickSettingsControllerTest.java | 236 |
2 files changed, 209 insertions, 46 deletions
diff --git a/packages/SystemUI/src/com/android/systemui/shade/QuickSettingsController.java b/packages/SystemUI/src/com/android/systemui/shade/QuickSettingsController.java index c0ef4c1a872a..50ff11f23cdc 100644 --- a/packages/SystemUI/src/com/android/systemui/shade/QuickSettingsController.java +++ b/packages/SystemUI/src/com/android/systemui/shade/QuickSettingsController.java @@ -434,6 +434,11 @@ public class QuickSettingsController { updateExpansionEnabledAmbient(); } + @VisibleForTesting + void setStatusBarMinHeight(int height) { + mStatusBarMinHeight = height; + } + int getHeaderHeight() { return mQs.getHeader().getHeight(); } @@ -483,7 +488,8 @@ public class QuickSettingsController { } /** Returns whether or not event should open QS */ - private boolean isOpenQsEvent(MotionEvent event) { + @VisibleForTesting + boolean isOpenQsEvent(MotionEvent event) { final int pointerCount = event.getPointerCount(); final int action = event.getActionMasked(); @@ -844,6 +850,11 @@ public class QuickSettingsController { mTwoFingerExpandPossible = expandPossible; } + @VisibleForTesting + boolean isTwoFingerExpandPossible() { + return mTwoFingerExpandPossible; + } + /** Called when Qs starts expanding */ private void onExpansionStarted() { cancelExpansionAnimation(); @@ -1360,7 +1371,8 @@ public class QuickSettingsController { return mTouchAboveFalsingThreshold; } - private void onHeightChanged() { + @VisibleForTesting + void onHeightChanged() { mMaxExpansionHeight = isQsFragmentCreated() ? mQs.getDesiredHeight() : 0; if (mExpanded && mFullyExpanded) { mExpansionHeight = mMaxExpansionHeight; @@ -1662,7 +1674,8 @@ public class QuickSettingsController { return false; } - private void onPanelExpansionChanged(ShadeExpansionChangeEvent event) { + @VisibleForTesting + void onPanelExpansionChanged(ShadeExpansionChangeEvent event) { mShadeExpandedFraction = event.getFraction(); } diff --git a/packages/SystemUI/tests/src/com/android/systemui/shade/QuickSettingsControllerTest.java b/packages/SystemUI/tests/src/com/android/systemui/shade/QuickSettingsControllerTest.java index c2fca6f2120b..4c1a9348205f 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/shade/QuickSettingsControllerTest.java +++ b/packages/SystemUI/tests/src/com/android/systemui/shade/QuickSettingsControllerTest.java @@ -16,6 +16,13 @@ package com.android.systemui.shade; +import static android.view.MotionEvent.ACTION_DOWN; +import static android.view.MotionEvent.ACTION_MOVE; +import static android.view.MotionEvent.ACTION_POINTER_DOWN; +import static android.view.MotionEvent.ACTION_UP; +import static android.view.MotionEvent.BUTTON_SECONDARY; +import static android.view.MotionEvent.BUTTON_STYLUS_PRIMARY; + import static com.android.systemui.statusbar.StatusBarState.KEYGUARD; import static com.android.systemui.statusbar.StatusBarState.SHADE; @@ -70,13 +77,11 @@ import com.android.systemui.statusbar.StatusBarStateControllerImpl; import com.android.systemui.statusbar.SysuiStatusBarStateController; import com.android.systemui.statusbar.notification.stack.AmbientState; import com.android.systemui.statusbar.notification.stack.NotificationStackScrollLayoutController; -import com.android.systemui.statusbar.phone.DozeParameters; import com.android.systemui.statusbar.phone.HeadsUpManagerPhone; import com.android.systemui.statusbar.phone.KeyguardBottomAreaView; import com.android.systemui.statusbar.phone.KeyguardBypassController; import com.android.systemui.statusbar.phone.KeyguardStatusBarView; import com.android.systemui.statusbar.phone.LockscreenGestureLogger; -import com.android.systemui.statusbar.phone.ScreenOffAnimationController; import com.android.systemui.statusbar.phone.ScrimController; import com.android.systemui.statusbar.phone.StatusBarKeyguardViewManager; import com.android.systemui.statusbar.phone.StatusBarTouchableRegionManager; @@ -97,6 +102,11 @@ import dagger.Lazy; public class QuickSettingsControllerTest extends SysuiTestCase { private static final int SPLIT_SHADE_FULL_TRANSITION_DISTANCE = 400; + private static final float QS_FRAME_START_X = 0f; + private static final int QS_FRAME_WIDTH = 1000; + private static final int QS_FRAME_TOP = 0; + private static final int QS_FRAME_BOTTOM = 1000; + private QuickSettingsController mQsController; @@ -139,8 +149,7 @@ public class QuickSettingsControllerTest extends SysuiTestCase { @Mock private ShadeLogger mShadeLogger; @Mock private DumpManager mDumpManager; - @Mock private DozeParameters mDozeParameters; - @Mock private ScreenOffAnimationController mScreenOffAnimationController; + @Mock private HeadsUpManagerPhone mHeadsUpManager; @Mock private UiEventLogger mUiEventLogger; @@ -169,6 +178,12 @@ public class QuickSettingsControllerTest extends SysuiTestCase { when(mPanelView.findViewById(R.id.keyguard_header)).thenReturn(mKeyguardStatusBar); when(mNotificationStackScrollLayoutController.getHeight()).thenReturn(1000); when(mPanelView.findViewById(R.id.qs_frame)).thenReturn(mQsFrame); + when(mQsFrame.getX()).thenReturn(QS_FRAME_START_X); + when(mQsFrame.getWidth()).thenReturn(QS_FRAME_WIDTH); + when(mQsHeader.getTop()).thenReturn(QS_FRAME_TOP); + when(mQsHeader.getBottom()).thenReturn(QS_FRAME_BOTTOM); + when(mPanelView.getY()).thenReturn((float) QS_FRAME_TOP); + when(mPanelView.getHeight()).thenReturn(QS_FRAME_BOTTOM); when(mPanelView.findViewById(R.id.keyguard_status_view)) .thenReturn(mock(KeyguardStatusView.class)); when(mQs.getView()).thenReturn(mPanelView); @@ -229,21 +244,10 @@ public class QuickSettingsControllerTest extends SysuiTestCase { @After public void tearDown() { - mNotificationPanelViewController.cancelHeightAnimator(); mMainHandler.removeCallbacksAndMessages(null); } @Test - public void testOnTouchEvent_isConflictingExpansionGestureSet() { - assertThat(mQsController.isConflictingExpansionGesture()).isFalse(); - mShadeExpansionStateManager.onPanelExpansionChanged(1f, true, false, 0f); - mQsController.handleTouch(MotionEvent.obtain(0L /* downTime */, - 0L /* eventTime */, MotionEvent.ACTION_DOWN, 0f /* x */, 0f /* y */, - 0 /* metaState */), false, false); - assertThat(mQsController.isConflictingExpansionGesture()).isTrue(); - } - - @Test public void testCloseQsSideEffects() { enableSplitShade(true); mQsController.setExpandImmediate(true); @@ -270,7 +274,7 @@ public class QuickSettingsControllerTest extends SysuiTestCase { public void testPanelStaysOpenWhenClosingQs() { mShadeExpansionStateManager.onPanelExpansionChanged(/* fraction= */ 1, /* expanded= */ true, /* tracking= */ false, /* dragDownPxAmount= */ 0); - mNotificationPanelViewController.setExpandedFraction(1f); + mQsController.setShadeExpandedHeight(1); float shadeExpandedHeight = mQsController.getShadeExpandedHeight(); mQsController.animateCloseQs(false); @@ -281,16 +285,12 @@ public class QuickSettingsControllerTest extends SysuiTestCase { @Test public void interceptTouchEvent_withinQs_shadeExpanded_startsQsTracking() { mQsController.setQs(mQs); - when(mQsFrame.getX()).thenReturn(0f); - when(mQsFrame.getWidth()).thenReturn(1000); - when(mQsHeader.getTop()).thenReturn(0); - when(mQsHeader.getBottom()).thenReturn(1000); mQsController.setShadeExpandedHeight(1f); mQsController.onIntercept( - createMotionEvent(0, 0, MotionEvent.ACTION_DOWN)); + createMotionEvent(0, 0, ACTION_DOWN)); mQsController.onIntercept( - createMotionEvent(0, 500, MotionEvent.ACTION_MOVE)); + createMotionEvent(0, 500, ACTION_MOVE)); assertThat(mQsController.isTracking()).isTrue(); } @@ -299,21 +299,124 @@ public class QuickSettingsControllerTest extends SysuiTestCase { public void interceptTouchEvent_withinQs_shadeExpanded_inSplitShade_doesNotStartQsTracking() { enableSplitShade(true); mQsController.setQs(mQs); - when(mQsFrame.getX()).thenReturn(0f); - when(mQsFrame.getWidth()).thenReturn(1000); - when(mQsHeader.getTop()).thenReturn(0); - when(mQsHeader.getBottom()).thenReturn(1000); mQsController.setShadeExpandedHeight(1f); mQsController.onIntercept( - createMotionEvent(0, 0, MotionEvent.ACTION_DOWN)); + createMotionEvent(0, 0, ACTION_DOWN)); mQsController.onIntercept( - createMotionEvent(0, 500, MotionEvent.ACTION_MOVE)); + createMotionEvent(0, 500, ACTION_MOVE)); + + assertThat(mQsController.isTracking()).isFalse(); + } + + @Test + public void interceptTouch_downBetweenFullyCollapsedAndExpanded() { + mQsController.setQs(mQs); + when(mQs.getDesiredHeight()).thenReturn(QS_FRAME_BOTTOM); + mQsController.onHeightChanged(); + mQsController.setExpansionHeight(QS_FRAME_BOTTOM / 2f); + + assertThat(mQsController.onIntercept( + createMotionEvent(0, QS_FRAME_BOTTOM / 2, ACTION_DOWN))).isTrue(); + } + + @Test + public void onTouch_moveActionSetsCorrectExpansionHeight() { + mQsController.setQs(mQs); + when(mQs.getDesiredHeight()).thenReturn(QS_FRAME_BOTTOM); + mQsController.onHeightChanged(); + mQsController.setExpansionHeight(QS_FRAME_BOTTOM / 2f); + mQsController.handleTouch( + createMotionEvent(0, QS_FRAME_BOTTOM / 4, ACTION_DOWN), false, false); + assertThat(mQsController.isTracking()).isTrue(); + mQsController.handleTouch( + createMotionEvent(0, QS_FRAME_BOTTOM / 4 + 1, ACTION_MOVE), false, false); + assertThat(mQsController.getExpansionHeight()).isEqualTo(QS_FRAME_BOTTOM / 2 + 1); + } + + @Test + public void handleTouch_downActionInQsArea() { + mQsController.setQs(mQs); + mQsController.setBarState(SHADE); + mQsController.onPanelExpansionChanged( + new ShadeExpansionChangeEvent( + 0.5f, + true, + true, + 0 + )); + MotionEvent event = + createMotionEvent(QS_FRAME_WIDTH / 2, QS_FRAME_BOTTOM / 2, ACTION_DOWN); + mQsController.handleTouch(event, false, false); + + assertThat(mQsController.isTracking()).isTrue(); + assertThat(mQsController.getInitialTouchY()).isEqualTo(QS_FRAME_BOTTOM / 2); + } + + @Test + public void handleTouch_qsTouchedWhileCollapsingDisablesTracking() { + mQsController.handleTouch( + createMotionEvent(0, QS_FRAME_BOTTOM, ACTION_DOWN), false, false); + mQsController.setLastShadeFlingWasExpanding(false); + mQsController.handleTouch( + createMotionEvent(0, QS_FRAME_BOTTOM / 2, ACTION_MOVE), false, true); + MotionEvent secondTouch = createMotionEvent(0, QS_FRAME_TOP, ACTION_DOWN); + mQsController.handleTouch(secondTouch, false, true); assertThat(mQsController.isTracking()).isFalse(); } @Test + public void handleTouch_qsTouchedWhileExpanding() { + mQsController.setQs(mQs); + mQsController.handleTouch( + createMotionEvent(100, 100, ACTION_DOWN), false, false); + mQsController.handleTouch( + createMotionEvent(0, QS_FRAME_BOTTOM / 2, ACTION_MOVE), false, false); + mQsController.setLastShadeFlingWasExpanding(true); + mQsController.handleTouch( + createMotionEvent(0, QS_FRAME_TOP, ACTION_DOWN), false, false); + assertThat(mQsController.isTracking()).isTrue(); + } + + @Test + public void handleTouch_isConflictingExpansionGestureSet() { + assertThat(mQsController.isConflictingExpansionGesture()).isFalse(); + mShadeExpansionStateManager.onPanelExpansionChanged(1f, true, false, 0f); + mQsController.handleTouch(MotionEvent.obtain(0L /* downTime */, + 0L /* eventTime */, ACTION_DOWN, 0f /* x */, 0f /* y */, + 0 /* metaState */), false, false); + assertThat(mQsController.isConflictingExpansionGesture()).isTrue(); + } + + @Test + public void handleTouch_isConflictingExpansionGestureSet_cancel() { + mShadeExpansionStateManager.onPanelExpansionChanged(1f, true, false, 0f); + mQsController.handleTouch(createMotionEvent(0, 0, ACTION_DOWN), false, false); + assertThat(mQsController.isConflictingExpansionGesture()).isTrue(); + mQsController.handleTouch(createMotionEvent(0, 0, ACTION_UP), true, true); + assertThat(mQsController.isConflictingExpansionGesture()).isFalse(); + } + + @Test + public void handleTouch_twoFingerExpandPossibleConditions() { + assertThat(mQsController.isTwoFingerExpandPossible()).isFalse(); + mQsController.handleTouch(createMotionEvent(0, 0, ACTION_DOWN), true, false); + assertThat(mQsController.isTwoFingerExpandPossible()).isTrue(); + } + + @Test + public void handleTouch_twoFingerDrag() { + mQsController.setQs(mQs); + mQsController.setStatusBarMinHeight(1); + mQsController.setTwoFingerExpandPossible(true); + mQsController.handleTouch( + createMultitouchMotionEvent(ACTION_POINTER_DOWN), false, false); + assertThat(mQsController.isExpandImmediate()).isTrue(); + verify(mQs).setListening(true); + } + + @Test public void onQsFragmentAttached_fullWidth_setsFullWidthTrueOnQS() { setIsFullWidth(true); mFragmentListener.onFragmentViewCreated(QS.TAG, mQSFragment); @@ -330,19 +433,6 @@ public class QuickSettingsControllerTest extends SysuiTestCase { } @Test - public void getMaxPanelTransitionDistance_inSplitShade_withHeadsUp_returnsBiggerValue() { - enableSplitShade(true); - mNotificationPanelViewController.expandWithQs(); - when(mHeadsUpManager.isTrackingHeadsUp()).thenReturn(true); - - mNotificationPanelViewController.setHeadsUpDraggingStartingHeight( - SPLIT_SHADE_FULL_TRANSITION_DISTANCE); - - assertThat(mQsController.calculatePanelHeightExpanded(0)) - .isGreaterThan(SPLIT_SHADE_FULL_TRANSITION_DISTANCE); - } - - @Test public void setQsExpansion_lockscreenShadeTransitionInProgress_usesLockscreenSquishiness() { float squishinessFraction = 0.456f; mQsController.setQs(mQs); @@ -379,6 +469,21 @@ public class QuickSettingsControllerTest extends SysuiTestCase { } @Test + public void updateExpansion_expandImmediateOrAlreadyExpanded_usesFullSquishiness() { + mQsController.setQs(mQs); + when(mQs.getDesiredHeight()).thenReturn(100); + mQsController.onHeightChanged(); + + mQsController.setExpandImmediate(true); + mQsController.setExpanded(false); + mQsController.updateExpansion(); + mQsController.setExpandImmediate(false); + mQsController.setExpanded(true); + mQsController.updateExpansion(); + verify(mQs, times(2)).setQsExpansion(0, 0, 0, 1); + } + + @Test public void shadeExpanded_onKeyguard() { mStatusBarStateController.setState(KEYGUARD); // set maxQsExpansion in NPVC @@ -393,9 +498,52 @@ public class QuickSettingsControllerTest extends SysuiTestCase { assertThat(mQsController.computeExpansionFraction()).isEqualTo(1f); } + @Test + public void handleTouch_splitShadeAndtouchXOutsideQs() { + enableSplitShade(true); + + assertThat(mQsController.handleTouch(createMotionEvent( + QS_FRAME_WIDTH + 1, QS_FRAME_BOTTOM - 1, ACTION_DOWN), + false, false)).isFalse(); + } + + @Test + public void isOpenQsEvent_twoFingerDrag() { + assertThat(mQsController.isOpenQsEvent( + createMultitouchMotionEvent(ACTION_POINTER_DOWN))).isTrue(); + } + + @Test + public void isOpenQsEvent_stylusButtonClickDrag() { + MotionEvent event = createMotionEvent(0, 0, ACTION_DOWN); + event.setButtonState(BUTTON_STYLUS_PRIMARY); + + assertThat(mQsController.isOpenQsEvent(event)).isTrue(); + } + + @Test + public void isOpenQsEvent_mouseButtonClickDrag() { + MotionEvent event = createMotionEvent(0, 0, ACTION_DOWN); + event.setButtonState(BUTTON_SECONDARY); + + assertThat(mQsController.isOpenQsEvent(event)).isTrue(); + } + private static MotionEvent createMotionEvent(int x, int y, int action) { - return MotionEvent.obtain( - /* downTime= */ 0, /* eventTime= */ 0, action, x, y, /* metaState= */ 0); + return MotionEvent.obtain(0, 0, action, x, y, 0); + } + + // Creates an empty multitouch event for now + private static MotionEvent createMultitouchMotionEvent(int action) { + return MotionEvent.obtain(0, 0, action, 2, + new MotionEvent.PointerProperties[] { + new MotionEvent.PointerProperties(), + new MotionEvent.PointerProperties() + }, + new MotionEvent.PointerCoords[] { + new MotionEvent.PointerCoords(), + new MotionEvent.PointerCoords() + }, 0, 0, 0, 0, 0, 0, 0, 0); } private void enableSplitShade(boolean enabled) { @@ -412,4 +560,6 @@ public class QuickSettingsControllerTest extends SysuiTestCase { int oldMaxHeight = mQsController.updateHeightsOnShadeLayoutChange(); mQsController.handleShadeLayoutChanged(oldMaxHeight); } + + } |