From 2b9a0e9e0f55a796d54ddd462717b65dd00da314 Mon Sep 17 00:00:00 2001 From: Beverly Date: Fri, 10 Mar 2023 16:28:51 +0000 Subject: [PATCH] RESTRICT AUTOMERGE Only handle altBouncer touches if up & down received Test: atest StatusBarKeyguardViewManagerTest Test: manually longpress a notification on the lockscreen and allow finger to linger - alternate bouncer shows and doesn't disappear on fingerUP Fixes: 270285915 Change-Id: I57bab58a47b9227fc13876edd3f6af22a840c147 --- .../phone/StatusBarKeyguardViewManager.java | 16 ++++-- .../StatusBarKeyguardViewManagerTest.java | 55 +++++++++++++++---- 2 files changed, 55 insertions(+), 16 deletions(-) diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBarKeyguardViewManager.java b/packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBarKeyguardViewManager.java index bea779336b363..2dc15d09afe20 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBarKeyguardViewManager.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBarKeyguardViewManager.java @@ -279,6 +279,7 @@ public class StatusBarKeyguardViewManager implements RemoteInputController.Callb private int mLastBiometricMode; private boolean mLastScreenOffAnimationPlaying; private float mQsExpansion; + private boolean mAlternateBouncerReceivedDownTouch = false; final Set mCallbacks = new HashSet<>(); private boolean mIsModernAlternateBouncerEnabled; private boolean mIsBackAnimationEnabled; @@ -1389,6 +1390,7 @@ public class StatusBarKeyguardViewManager implements RemoteInputController.Callb pw.println(" mPendingWakeupAction: " + mPendingWakeupAction); pw.println(" isBouncerShowing(): " + isBouncerShowing()); pw.println(" bouncerIsOrWillBeShowing(): " + primaryBouncerIsOrWillBeShowing()); + pw.println(" mAlternateBouncerReceivedDownTouch: " + mAlternateBouncerReceivedDownTouch); pw.println(" Registered KeyguardViewManagerCallbacks:"); for (KeyguardViewManagerCallback callback : mCallbacks) { pw.println(" " + callback); @@ -1449,11 +1451,17 @@ public class StatusBarKeyguardViewManager implements RemoteInputController.Callb */ public boolean onTouch(MotionEvent event) { boolean handledTouch = false; - if (event.getAction() == MotionEvent.ACTION_UP - && mAlternateBouncerInteractor.isVisibleState() - && mAlternateBouncerInteractor.hasAlternateBouncerShownWithMinTime()) { - showPrimaryBouncer(true); + if (mAlternateBouncerInteractor.isVisibleState()) { + if (event.getAction() == MotionEvent.ACTION_DOWN) { + mAlternateBouncerReceivedDownTouch = true; + } else if (event.getAction() == MotionEvent.ACTION_UP + && mAlternateBouncerInteractor.hasAlternateBouncerShownWithMinTime() + && mAlternateBouncerReceivedDownTouch) { + showPrimaryBouncer(true); + } handledTouch = true; + } else { + mAlternateBouncerReceivedDownTouch = false; } // Forward NPVC touches to callbacks in case they want to respond to touches diff --git a/packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/StatusBarKeyguardViewManagerTest.java b/packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/StatusBarKeyguardViewManagerTest.java index 31462623ce2d9..61286a43217c5 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/StatusBarKeyguardViewManagerTest.java +++ b/packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/StatusBarKeyguardViewManagerTest.java @@ -19,7 +19,6 @@ package com.android.systemui.statusbar.phone; import static com.android.systemui.keyguard.shared.constants.KeyguardBouncerConstants.EXPANSION_HIDDEN; import static com.android.systemui.keyguard.shared.constants.KeyguardBouncerConstants.EXPANSION_VISIBLE; -import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.anyBoolean; @@ -729,30 +728,62 @@ public class StatusBarKeyguardViewManagerTest extends SysuiTestCase { } @Test - public void testAlternateBouncerOnTouch_actionDown_doesNotHandleTouch() { + public void testAlternateBouncerOnTouch_actionDownThenUp_noMinTimeShown_noHideAltBouncer() { + reset(mAlternateBouncerInteractor); + // GIVEN the alternate bouncer has shown for a minimum amount of time - when(mAlternateBouncerInteractor.hasAlternateBouncerShownWithMinTime()).thenReturn(true); + when(mAlternateBouncerInteractor.hasAlternateBouncerShownWithMinTime()).thenReturn(false); when(mAlternateBouncerInteractor.isVisibleState()).thenReturn(true); - // WHEN ACTION_DOWN touch event comes - boolean touchHandled = mStatusBarKeyguardViewManager.onTouch( + // WHEN ACTION_DOWN and ACTION_UP touch event comes + boolean touchHandledDown = mStatusBarKeyguardViewManager.onTouch( MotionEvent.obtain(0L, 0L, MotionEvent.ACTION_DOWN, 0f, 0f, 0)); + boolean touchHandledUp = mStatusBarKeyguardViewManager.onTouch( + MotionEvent.obtain(0L, 0L, MotionEvent.ACTION_UP, 0f, 0f, 0)); - // THEN the touch is not handled - assertFalse(touchHandled); + // THEN the touches are handled (doesn't let touches through to underlying views) + assertTrue(touchHandledDown); + assertTrue(touchHandledUp); + + // THEN alternate bouncer does NOT attempt to hide since min showing time wasn't met + verify(mAlternateBouncerInteractor, never()).hide(); } @Test - public void testAlternateBouncerOnTouch_actionUp_handlesTouch() { + public void testAlternateBouncerOnTouch_actionDownThenUp_handlesTouch_hidesAltBouncer() { + reset(mAlternateBouncerInteractor); + // GIVEN the alternate bouncer has shown for a minimum amount of time when(mAlternateBouncerInteractor.hasAlternateBouncerShownWithMinTime()).thenReturn(true); when(mAlternateBouncerInteractor.isVisibleState()).thenReturn(true); - // WHEN ACTION_UP touch event comes - boolean touchHandled = mStatusBarKeyguardViewManager.onTouch( + // WHEN ACTION_DOWN and ACTION_UP touch event comes + boolean touchHandledDown = mStatusBarKeyguardViewManager.onTouch( + MotionEvent.obtain(0L, 0L, MotionEvent.ACTION_DOWN, 0f, 0f, 0)); + boolean touchHandledUp = mStatusBarKeyguardViewManager.onTouch( MotionEvent.obtain(0L, 0L, MotionEvent.ACTION_UP, 0f, 0f, 0)); - // THEN the touch is handled - assertTrue(touchHandled); + // THEN the touches are handled + assertTrue(touchHandledDown); + assertTrue(touchHandledUp); + + // THEN alternate bouncer attempts to hide + verify(mAlternateBouncerInteractor).hide(); + } + + @Test + public void testAlternateBouncerOnTouch_actionUp_doesNotHideAlternateBouncer() { + reset(mAlternateBouncerInteractor); + + // GIVEN the alternate bouncer has shown for a minimum amount of time + when(mAlternateBouncerInteractor.hasAlternateBouncerShownWithMinTime()).thenReturn(true); + when(mAlternateBouncerInteractor.isVisibleState()).thenReturn(true); + + // WHEN only ACTION_UP touch event comes + mStatusBarKeyguardViewManager.onTouch( + MotionEvent.obtain(0L, 0L, MotionEvent.ACTION_UP, 0f, 0f, 0)); + + // THEN the alternateBouncer doesn't hide + verify(mAlternateBouncerInteractor, never()).hide(); } }