From 333522ba064eea602d54675096ced2ae6fb0e7ea Mon Sep 17 00:00:00 2001 From: Justin Weir Date: Fri, 3 Mar 2023 11:07:34 -0500 Subject: [PATCH] Touch handling and other tiny cleanups in NPVC The interface used for the touch handling handoff between Status Bar and Shade is nearly the same as Gefingerpoken, so this change will remove the redundancy. It also removes the usage of the view as an an unnecessary middleman by passing events directly to the Shade touch handler. Also includes some trivial warning cleanup. This was originally the first in a chain of CLs attempting to fix multitouch in the shade, but the follow up CL was too risky for QPR. Bug: 132458655 Test: manual and atest Change-Id: Iabb3484e43573b6e4f7755d1abe0a76512828834 --- .../NotificationPanelViewController.java | 63 ++++++++----------- ...NotificationShadeWindowViewController.java | 2 +- .../statusbar/phone/PhoneStatusBarView.java | 31 ++------- .../phone/PhoneStatusBarViewController.kt | 17 ++--- ...tificationPanelViewControllerBaseTest.java | 2 - .../phone/PhoneStatusBarViewControllerTest.kt | 13 ++-- .../statusbar/phone/PhoneStatusBarViewTest.kt | 8 ++- 7 files changed, 49 insertions(+), 87 deletions(-) diff --git a/packages/SystemUI/src/com/android/systemui/shade/NotificationPanelViewController.java b/packages/SystemUI/src/com/android/systemui/shade/NotificationPanelViewController.java index c44f4f3918317..ff523ad7fa0f3 100644 --- a/packages/SystemUI/src/com/android/systemui/shade/NotificationPanelViewController.java +++ b/packages/SystemUI/src/com/android/systemui/shade/NotificationPanelViewController.java @@ -119,6 +119,7 @@ import com.android.keyguard.dagger.KeyguardStatusViewComponent; import com.android.keyguard.dagger.KeyguardUserSwitcherComponent; import com.android.systemui.DejankUtils; import com.android.systemui.Dumpable; +import com.android.systemui.Gefingerpoken; import com.android.systemui.R; import com.android.systemui.animation.ActivityLaunchAnimator; import com.android.systemui.animation.Interpolators; @@ -162,14 +163,12 @@ import com.android.systemui.plugins.FalsingManager.FalsingTapListener; import com.android.systemui.plugins.qs.QS; import com.android.systemui.plugins.statusbar.StatusBarStateController; import com.android.systemui.plugins.statusbar.StatusBarStateController.StateListener; -import com.android.systemui.screenrecord.RecordingController; import com.android.systemui.shade.transition.ShadeTransitionController; import com.android.systemui.shared.system.QuickStepContract; import com.android.systemui.statusbar.CommandQueue; import com.android.systemui.statusbar.GestureRecorder; import com.android.systemui.statusbar.KeyguardIndicationController; import com.android.systemui.statusbar.LockscreenShadeTransitionController; -import com.android.systemui.statusbar.NotificationRemoteInputManager; import com.android.systemui.statusbar.NotificationShadeDepthController; import com.android.systemui.statusbar.NotificationShadeWindowController; import com.android.systemui.statusbar.NotificationShelfController; @@ -357,6 +356,7 @@ public final class NotificationPanelViewController implements Dumpable { private final AlternateBouncerInteractor mAlternateBouncerInteractor; private final QuickSettingsController mQsController; private final InteractionJankMonitor mInteractionJankMonitor; + private final TouchHandler mTouchHandler = new TouchHandler(); private long mDownTime; private boolean mTouchSlopExceededBeforeDown; @@ -541,7 +541,7 @@ public final class NotificationPanelViewController implements Dumpable { private final KeyguardBottomAreaViewModel mKeyguardBottomAreaViewModel; private final KeyguardBottomAreaInteractor mKeyguardBottomAreaInteractor; private float mMinExpandHeight; - private ShadeHeightLogger mShadeHeightLogger; + private final ShadeHeightLogger mShadeHeightLogger; private boolean mPanelUpdateWhenAnimatorEnds; private boolean mHasVibratedOnOpen = false; private int mFixedDuration = NO_FIXED_DURATION; @@ -586,15 +586,15 @@ public final class NotificationPanelViewController implements Dumpable { private boolean mGestureWaitForTouchSlop; private boolean mIgnoreXTouchSlop; private boolean mExpandLatencyTracking; - private DreamingToLockscreenTransitionViewModel mDreamingToLockscreenTransitionViewModel; - private OccludedToLockscreenTransitionViewModel mOccludedToLockscreenTransitionViewModel; - private LockscreenToDreamingTransitionViewModel mLockscreenToDreamingTransitionViewModel; - private GoneToDreamingTransitionViewModel mGoneToDreamingTransitionViewModel; - private LockscreenToOccludedTransitionViewModel mLockscreenToOccludedTransitionViewModel; + private final DreamingToLockscreenTransitionViewModel mDreamingToLockscreenTransitionViewModel; + private final OccludedToLockscreenTransitionViewModel mOccludedToLockscreenTransitionViewModel; + private final LockscreenToDreamingTransitionViewModel mLockscreenToDreamingTransitionViewModel; + private final GoneToDreamingTransitionViewModel mGoneToDreamingTransitionViewModel; + private final LockscreenToOccludedTransitionViewModel mLockscreenToOccludedTransitionViewModel; - private KeyguardTransitionInteractor mKeyguardTransitionInteractor; + private final KeyguardTransitionInteractor mKeyguardTransitionInteractor; private final KeyguardInteractor mKeyguardInteractor; - private CoroutineDispatcher mMainDispatcher; + private final CoroutineDispatcher mMainDispatcher; private boolean mIsOcclusionTransitionRunning = false; private int mDreamingToLockscreenTransitionTranslationY; private int mOccludedToLockscreenTransitionTranslationY; @@ -708,12 +708,10 @@ public final class NotificationPanelViewController implements Dumpable { QuickSettingsController quickSettingsController, FragmentService fragmentService, ContentResolver contentResolver, - RecordingController recordingController, ShadeHeaderController shadeHeaderController, ScreenOffAnimationController screenOffAnimationController, LockscreenGestureLogger lockscreenGestureLogger, ShadeExpansionStateManager shadeExpansionStateManager, - NotificationRemoteInputManager remoteInputManager, Optional unfoldComponent, SysUiState sysUiState, Provider keyguardBottomAreaViewControllerProvider, @@ -771,7 +769,7 @@ public final class NotificationPanelViewController implements Dumpable { }); mView.addOnLayoutChangeListener(new ShadeLayoutChangeListener()); - mView.setOnTouchListener(createTouchHandler()); + mView.setOnTouchListener(getTouchHandler()); mView.setOnConfigurationChangedListener(config -> loadDimens()); mResources = mView.getResources(); @@ -1643,10 +1641,6 @@ public final class NotificationPanelViewController implements Dumpable { return mDozing && mDozeParameters.getAlwaysOn(); } - boolean isDozing() { - return mDozing; - } - private boolean hasVisibleNotifications() { return mNotificationStackScrollLayoutController .getVisibleNotificationCount() != 0 @@ -3336,8 +3330,8 @@ public final class NotificationPanelViewController implements Dumpable { } @VisibleForTesting - TouchHandler createTouchHandler() { - return new TouchHandler(); + TouchHandler getTouchHandler() { + return mTouchHandler; } public NotificationStackScrollLayoutController getNotificationStackScrollLayoutController() { @@ -3985,14 +3979,14 @@ public final class NotificationPanelViewController implements Dumpable { return mView.post(action); } - /** */ - public boolean sendInterceptTouchEventToView(MotionEvent event) { - return mView.onInterceptTouchEvent(event); + /** Sends an external (e.g. Status Bar) intercept touch event to the Shade touch handler. */ + public boolean handleExternalInterceptTouch(MotionEvent event) { + return mTouchHandler.onInterceptTouchEvent(event); } - /** */ - public boolean sendTouchEventToView(MotionEvent event) { - return mView.dispatchTouchEvent(event); + /** Sends an external (e.g. Status Bar) touch event to the Shade touch handler. */ + public boolean handleExternalTouch(MotionEvent event) { + return mTouchHandler.onTouchEvent(event); } /** */ @@ -4010,14 +4004,6 @@ public final class NotificationPanelViewController implements Dumpable { return mView.isEnabled(); } - int getDisplayRightInset() { - return mDisplayRightInset; - } - - int getDisplayLeftInset() { - return mDisplayLeftInset; - } - float getOverStretchAmount() { return mOverStretchAmount; } @@ -4026,10 +4012,6 @@ public final class NotificationPanelViewController implements Dumpable { return mMinFraction; } - boolean getCollapsedOnDown() { - return mCollapsedOnDown; - } - int getNavigationBarBottomHeight() { return mNavigationBarBottomHeight; } @@ -4593,7 +4575,7 @@ public final class NotificationPanelViewController implements Dumpable { } /** Handles MotionEvents for the Shade. */ - public final class TouchHandler implements View.OnTouchListener { + public final class TouchHandler implements View.OnTouchListener, Gefingerpoken { private long mLastTouchDownTime = -1L; /** @see ViewGroup#onInterceptTouchEvent(MotionEvent) */ @@ -4739,6 +4721,11 @@ public final class NotificationPanelViewController implements Dumpable { @Override public boolean onTouch(View v, MotionEvent event) { + return onTouchEvent(event); + } + + @Override + public boolean onTouchEvent(MotionEvent event) { if (event.getAction() == MotionEvent.ACTION_DOWN) { if (event.getDownTime() == mLastTouchDownTime) { // An issue can occur when swiping down after unlock, where multiple down diff --git a/packages/SystemUI/src/com/android/systemui/shade/NotificationShadeWindowViewController.java b/packages/SystemUI/src/com/android/systemui/shade/NotificationShadeWindowViewController.java index c130b3913b640..ae9649478df77 100644 --- a/packages/SystemUI/src/com/android/systemui/shade/NotificationShadeWindowViewController.java +++ b/packages/SystemUI/src/com/android/systemui/shade/NotificationShadeWindowViewController.java @@ -342,7 +342,7 @@ public class NotificationShadeWindowViewController { MotionEvent cancellation = MotionEvent.obtain(ev); cancellation.setAction(MotionEvent.ACTION_CANCEL); mStackScrollLayout.onInterceptTouchEvent(cancellation); - mNotificationPanelViewController.sendInterceptTouchEventToView(cancellation); + mNotificationPanelViewController.handleExternalInterceptTouch(cancellation); cancellation.recycle(); } diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/phone/PhoneStatusBarView.java b/packages/SystemUI/src/com/android/systemui/statusbar/phone/PhoneStatusBarView.java index 28bc64de2cb90..d546a84791fc8 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/PhoneStatusBarView.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/PhoneStatusBarView.java @@ -35,6 +35,7 @@ import android.widget.LinearLayout; import com.android.internal.policy.SystemBarUtils; import com.android.systemui.Dependency; +import com.android.systemui.Gefingerpoken; import com.android.systemui.R; import com.android.systemui.plugins.DarkIconDispatcher; import com.android.systemui.plugins.DarkIconDispatcher.DarkReceiver; @@ -60,7 +61,7 @@ public class PhoneStatusBarView extends FrameLayout { private Rect mDisplaySize; private int mStatusBarHeight; @Nullable - private TouchEventHandler mTouchEventHandler; + private Gefingerpoken mTouchEventHandler; /** * Draw this many pixels into the left/right side of the cutout to optimally use the space @@ -72,7 +73,7 @@ public class PhoneStatusBarView extends FrameLayout { mContentInsetsProvider = Dependency.get(StatusBarContentInsetsProvider.class); } - void setTouchEventHandler(TouchEventHandler handler) { + void setTouchEventHandler(Gefingerpoken handler) { mTouchEventHandler = handler; } @@ -185,7 +186,7 @@ public class PhoneStatusBarView extends FrameLayout { ); return true; } - return mTouchEventHandler.handleTouchEvent(event); + return mTouchEventHandler.onTouchEvent(event); } @Override @@ -267,28 +268,4 @@ public class PhoneStatusBarView extends FrameLayout { insets.second, getPaddingBottom()); } - - /** - * A handler responsible for all touch event handling on the status bar. - * - * Touches that occur on the status bar view may have ramifications for the notification - * panel (e.g. a touch that pulls down the shade could start on the status bar), so this - * interface provides a way to notify the panel controller when these touches occur. - * - * The handler will be notified each time {@link PhoneStatusBarView#onTouchEvent} and - * {@link PhoneStatusBarView#onInterceptTouchEvent} are called. - **/ - public interface TouchEventHandler { - /** Called each time {@link PhoneStatusBarView#onInterceptTouchEvent} is called. */ - void onInterceptTouchEvent(MotionEvent event); - - /** - * Called each time {@link PhoneStatusBarView#onTouchEvent} is called. - * - * Should return true if the touch was handled by this handler and false otherwise. The - * return value from the handler will be returned from - * {@link PhoneStatusBarView#onTouchEvent}. - */ - boolean handleTouchEvent(MotionEvent event); - } } diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/phone/PhoneStatusBarViewController.kt b/packages/SystemUI/src/com/android/systemui/statusbar/phone/PhoneStatusBarViewController.kt index 11bc490286f9c..9a5d1b5514f55 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/PhoneStatusBarViewController.kt +++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/PhoneStatusBarViewController.kt @@ -24,11 +24,11 @@ import android.view.MotionEvent import android.view.View import android.view.ViewGroup import android.view.ViewTreeObserver +import com.android.systemui.Gefingerpoken import com.android.systemui.R import com.android.systemui.shade.ShadeController import com.android.systemui.shade.ShadeLogger import com.android.systemui.shared.animation.UnfoldMoveFromCenterAnimator -import com.android.systemui.statusbar.phone.PhoneStatusBarView.TouchEventHandler import com.android.systemui.statusbar.policy.ConfigurationController import com.android.systemui.unfold.SysUIUnfoldComponent import com.android.systemui.unfold.UNFOLD_STATUS_BAR @@ -131,7 +131,7 @@ class PhoneStatusBarViewController private constructor( } /** Called when a touch event occurred on {@link PhoneStatusBarView}. */ - fun onTouchEvent(event: MotionEvent) { + fun onTouch(event: MotionEvent) { if (centralSurfaces.statusBarWindowState == WINDOW_STATE_SHOWING) { val upOrCancel = event.action == MotionEvent.ACTION_UP || @@ -141,13 +141,14 @@ class PhoneStatusBarViewController private constructor( } } - inner class PhoneStatusBarViewTouchHandler : TouchEventHandler { - override fun onInterceptTouchEvent(event: MotionEvent) { - onTouchEvent(event) + inner class PhoneStatusBarViewTouchHandler : Gefingerpoken { + override fun onInterceptTouchEvent(event: MotionEvent): Boolean { + onTouch(event) + return false } - override fun handleTouchEvent(event: MotionEvent): Boolean { - onTouchEvent(event) + override fun onTouchEvent(event: MotionEvent): Boolean { + onTouch(event) // If panels aren't enabled, ignore the gesture and don't pass it down to the // panel view. @@ -174,7 +175,7 @@ class PhoneStatusBarViewController private constructor( return true } } - return centralSurfaces.notificationPanelViewController.sendTouchEventToView(event) + return centralSurfaces.notificationPanelViewController.handleExternalTouch(event) } } diff --git a/packages/SystemUI/tests/src/com/android/systemui/shade/NotificationPanelViewControllerBaseTest.java b/packages/SystemUI/tests/src/com/android/systemui/shade/NotificationPanelViewControllerBaseTest.java index 2dfb6e564d995..99cf8d0ebe93c 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/shade/NotificationPanelViewControllerBaseTest.java +++ b/packages/SystemUI/tests/src/com/android/systemui/shade/NotificationPanelViewControllerBaseTest.java @@ -536,12 +536,10 @@ public class NotificationPanelViewControllerBaseTest extends SysuiTestCase { mQsController, mFragmentService, mContentResolver, - mRecordingController, mShadeHeaderController, mScreenOffAnimationController, mLockscreenGestureLogger, mShadeExpansionStateManager, - mNotificationRemoteInputManager, mSysUIUnfoldComponent, mSysUiState, () -> mKeyguardBottomAreaViewController, diff --git a/packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/PhoneStatusBarViewControllerTest.kt b/packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/PhoneStatusBarViewControllerTest.kt index 14d239ab48cdb..cdc989897c8e9 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/PhoneStatusBarViewControllerTest.kt +++ b/packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/PhoneStatusBarViewControllerTest.kt @@ -18,7 +18,6 @@ package com.android.systemui.statusbar.phone import android.view.LayoutInflater import android.view.MotionEvent -import android.view.ViewGroup import android.view.ViewTreeObserver import android.view.ViewTreeObserver.OnPreDrawListener import android.widget.FrameLayout @@ -55,8 +54,6 @@ class PhoneStatusBarViewControllerTest : SysuiTestCase() { @Mock private lateinit var notificationPanelViewController: NotificationPanelViewController @Mock - private lateinit var panelView: ViewGroup - @Mock private lateinit var moveFromCenterAnimation: StatusBarMoveFromCenterAnimationController @Mock private lateinit var sysuiUnfoldComponent: SysUIUnfoldComponent @@ -116,7 +113,7 @@ class PhoneStatusBarViewControllerTest : SysuiTestCase() { val returnVal = view.onTouchEvent( MotionEvent.obtain(0L, 0L, MotionEvent.ACTION_DOWN, 0f, 0f, 0)) assertThat(returnVal).isFalse() - verify(notificationPanelViewController, never()).sendTouchEventToView(any()) + verify(notificationPanelViewController, never()).handleExternalTouch(any()) } @Test @@ -128,7 +125,7 @@ class PhoneStatusBarViewControllerTest : SysuiTestCase() { val returnVal = view.onTouchEvent( MotionEvent.obtain(0L, 0L, MotionEvent.ACTION_DOWN, 0f, 0f, 0)) assertThat(returnVal).isTrue() - verify(notificationPanelViewController, never()).sendTouchEventToView(any()) + verify(notificationPanelViewController, never()).handleExternalTouch(any()) } @Test @@ -141,7 +138,7 @@ class PhoneStatusBarViewControllerTest : SysuiTestCase() { view.onTouchEvent(event) - verify(notificationPanelViewController).sendTouchEventToView(event) + verify(notificationPanelViewController).handleExternalTouch(event) } @Test @@ -154,7 +151,7 @@ class PhoneStatusBarViewControllerTest : SysuiTestCase() { view.onTouchEvent(event) - verify(notificationPanelViewController).sendTouchEventToView(event) + verify(notificationPanelViewController).handleExternalTouch(event) } @Test @@ -167,7 +164,7 @@ class PhoneStatusBarViewControllerTest : SysuiTestCase() { view.onTouchEvent(event) - verify(notificationPanelViewController, never()).sendTouchEventToView(any()) + verify(notificationPanelViewController, never()).handleExternalTouch(any()) } private fun createViewMock(): PhoneStatusBarView { diff --git a/packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/PhoneStatusBarViewTest.kt b/packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/PhoneStatusBarViewTest.kt index 27b1da0cb8967..3ed454fff5847 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/PhoneStatusBarViewTest.kt +++ b/packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/PhoneStatusBarViewTest.kt @@ -19,6 +19,7 @@ package com.android.systemui.statusbar.phone import android.view.MotionEvent import android.view.ViewGroup import androidx.test.filters.SmallTest +import com.android.systemui.Gefingerpoken import com.android.systemui.SysuiTestCase import com.android.systemui.shade.NotificationPanelViewController import com.google.common.truth.Truth.assertThat @@ -94,16 +95,17 @@ class PhoneStatusBarViewTest : SysuiTestCase() { // No assert needed, just testing no crash } - private class TestTouchEventHandler : PhoneStatusBarView.TouchEventHandler { + private class TestTouchEventHandler : Gefingerpoken { var lastInterceptEvent: MotionEvent? = null var lastEvent: MotionEvent? = null var handleTouchReturnValue: Boolean = false - override fun onInterceptTouchEvent(event: MotionEvent?) { + override fun onInterceptTouchEvent(event: MotionEvent?): Boolean { lastInterceptEvent = event + return handleTouchReturnValue } - override fun handleTouchEvent(event: MotionEvent?): Boolean { + override fun onTouchEvent(event: MotionEvent?): Boolean { lastEvent = event return handleTouchReturnValue }