Merge "Touch handling and other tiny cleanups in NPVC" into tm-qpr-dev

This commit is contained in:
Justin Weir
2023-03-10 21:47:18 +00:00
committed by Android (Google) Code Review
7 changed files with 49 additions and 87 deletions

View File

@@ -119,6 +119,7 @@ import com.android.keyguard.dagger.KeyguardStatusViewComponent;
import com.android.keyguard.dagger.KeyguardUserSwitcherComponent; import com.android.keyguard.dagger.KeyguardUserSwitcherComponent;
import com.android.systemui.DejankUtils; import com.android.systemui.DejankUtils;
import com.android.systemui.Dumpable; import com.android.systemui.Dumpable;
import com.android.systemui.Gefingerpoken;
import com.android.systemui.R; import com.android.systemui.R;
import com.android.systemui.animation.ActivityLaunchAnimator; import com.android.systemui.animation.ActivityLaunchAnimator;
import com.android.systemui.animation.Interpolators; 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.qs.QS;
import com.android.systemui.plugins.statusbar.StatusBarStateController; import com.android.systemui.plugins.statusbar.StatusBarStateController;
import com.android.systemui.plugins.statusbar.StatusBarStateController.StateListener; 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.shade.transition.ShadeTransitionController;
import com.android.systemui.shared.system.QuickStepContract; import com.android.systemui.shared.system.QuickStepContract;
import com.android.systemui.statusbar.CommandQueue; import com.android.systemui.statusbar.CommandQueue;
import com.android.systemui.statusbar.GestureRecorder; import com.android.systemui.statusbar.GestureRecorder;
import com.android.systemui.statusbar.KeyguardIndicationController; import com.android.systemui.statusbar.KeyguardIndicationController;
import com.android.systemui.statusbar.LockscreenShadeTransitionController; import com.android.systemui.statusbar.LockscreenShadeTransitionController;
import com.android.systemui.statusbar.NotificationRemoteInputManager;
import com.android.systemui.statusbar.NotificationShadeDepthController; import com.android.systemui.statusbar.NotificationShadeDepthController;
import com.android.systemui.statusbar.NotificationShadeWindowController; import com.android.systemui.statusbar.NotificationShadeWindowController;
import com.android.systemui.statusbar.NotificationShelfController; import com.android.systemui.statusbar.NotificationShelfController;
@@ -357,6 +356,7 @@ public final class NotificationPanelViewController implements Dumpable {
private final AlternateBouncerInteractor mAlternateBouncerInteractor; private final AlternateBouncerInteractor mAlternateBouncerInteractor;
private final QuickSettingsController mQsController; private final QuickSettingsController mQsController;
private final InteractionJankMonitor mInteractionJankMonitor; private final InteractionJankMonitor mInteractionJankMonitor;
private final TouchHandler mTouchHandler = new TouchHandler();
private long mDownTime; private long mDownTime;
private boolean mTouchSlopExceededBeforeDown; private boolean mTouchSlopExceededBeforeDown;
@@ -541,7 +541,7 @@ public final class NotificationPanelViewController implements Dumpable {
private final KeyguardBottomAreaViewModel mKeyguardBottomAreaViewModel; private final KeyguardBottomAreaViewModel mKeyguardBottomAreaViewModel;
private final KeyguardBottomAreaInteractor mKeyguardBottomAreaInteractor; private final KeyguardBottomAreaInteractor mKeyguardBottomAreaInteractor;
private float mMinExpandHeight; private float mMinExpandHeight;
private ShadeHeightLogger mShadeHeightLogger; private final ShadeHeightLogger mShadeHeightLogger;
private boolean mPanelUpdateWhenAnimatorEnds; private boolean mPanelUpdateWhenAnimatorEnds;
private boolean mHasVibratedOnOpen = false; private boolean mHasVibratedOnOpen = false;
private int mFixedDuration = NO_FIXED_DURATION; private int mFixedDuration = NO_FIXED_DURATION;
@@ -586,15 +586,15 @@ public final class NotificationPanelViewController implements Dumpable {
private boolean mGestureWaitForTouchSlop; private boolean mGestureWaitForTouchSlop;
private boolean mIgnoreXTouchSlop; private boolean mIgnoreXTouchSlop;
private boolean mExpandLatencyTracking; private boolean mExpandLatencyTracking;
private DreamingToLockscreenTransitionViewModel mDreamingToLockscreenTransitionViewModel; private final DreamingToLockscreenTransitionViewModel mDreamingToLockscreenTransitionViewModel;
private OccludedToLockscreenTransitionViewModel mOccludedToLockscreenTransitionViewModel; private final OccludedToLockscreenTransitionViewModel mOccludedToLockscreenTransitionViewModel;
private LockscreenToDreamingTransitionViewModel mLockscreenToDreamingTransitionViewModel; private final LockscreenToDreamingTransitionViewModel mLockscreenToDreamingTransitionViewModel;
private GoneToDreamingTransitionViewModel mGoneToDreamingTransitionViewModel; private final GoneToDreamingTransitionViewModel mGoneToDreamingTransitionViewModel;
private LockscreenToOccludedTransitionViewModel mLockscreenToOccludedTransitionViewModel; private final LockscreenToOccludedTransitionViewModel mLockscreenToOccludedTransitionViewModel;
private KeyguardTransitionInteractor mKeyguardTransitionInteractor; private final KeyguardTransitionInteractor mKeyguardTransitionInteractor;
private final KeyguardInteractor mKeyguardInteractor; private final KeyguardInteractor mKeyguardInteractor;
private CoroutineDispatcher mMainDispatcher; private final CoroutineDispatcher mMainDispatcher;
private boolean mIsOcclusionTransitionRunning = false; private boolean mIsOcclusionTransitionRunning = false;
private int mDreamingToLockscreenTransitionTranslationY; private int mDreamingToLockscreenTransitionTranslationY;
private int mOccludedToLockscreenTransitionTranslationY; private int mOccludedToLockscreenTransitionTranslationY;
@@ -708,12 +708,10 @@ public final class NotificationPanelViewController implements Dumpable {
QuickSettingsController quickSettingsController, QuickSettingsController quickSettingsController,
FragmentService fragmentService, FragmentService fragmentService,
ContentResolver contentResolver, ContentResolver contentResolver,
RecordingController recordingController,
ShadeHeaderController shadeHeaderController, ShadeHeaderController shadeHeaderController,
ScreenOffAnimationController screenOffAnimationController, ScreenOffAnimationController screenOffAnimationController,
LockscreenGestureLogger lockscreenGestureLogger, LockscreenGestureLogger lockscreenGestureLogger,
ShadeExpansionStateManager shadeExpansionStateManager, ShadeExpansionStateManager shadeExpansionStateManager,
NotificationRemoteInputManager remoteInputManager,
Optional<SysUIUnfoldComponent> unfoldComponent, Optional<SysUIUnfoldComponent> unfoldComponent,
SysUiState sysUiState, SysUiState sysUiState,
Provider<KeyguardBottomAreaViewController> keyguardBottomAreaViewControllerProvider, Provider<KeyguardBottomAreaViewController> keyguardBottomAreaViewControllerProvider,
@@ -771,7 +769,7 @@ public final class NotificationPanelViewController implements Dumpable {
}); });
mView.addOnLayoutChangeListener(new ShadeLayoutChangeListener()); mView.addOnLayoutChangeListener(new ShadeLayoutChangeListener());
mView.setOnTouchListener(createTouchHandler()); mView.setOnTouchListener(getTouchHandler());
mView.setOnConfigurationChangedListener(config -> loadDimens()); mView.setOnConfigurationChangedListener(config -> loadDimens());
mResources = mView.getResources(); mResources = mView.getResources();
@@ -1643,10 +1641,6 @@ public final class NotificationPanelViewController implements Dumpable {
return mDozing && mDozeParameters.getAlwaysOn(); return mDozing && mDozeParameters.getAlwaysOn();
} }
boolean isDozing() {
return mDozing;
}
private boolean hasVisibleNotifications() { private boolean hasVisibleNotifications() {
return mNotificationStackScrollLayoutController return mNotificationStackScrollLayoutController
.getVisibleNotificationCount() != 0 .getVisibleNotificationCount() != 0
@@ -3336,8 +3330,8 @@ public final class NotificationPanelViewController implements Dumpable {
} }
@VisibleForTesting @VisibleForTesting
TouchHandler createTouchHandler() { TouchHandler getTouchHandler() {
return new TouchHandler(); return mTouchHandler;
} }
public NotificationStackScrollLayoutController getNotificationStackScrollLayoutController() { public NotificationStackScrollLayoutController getNotificationStackScrollLayoutController() {
@@ -3985,14 +3979,14 @@ public final class NotificationPanelViewController implements Dumpable {
return mView.post(action); return mView.post(action);
} }
/** */ /** Sends an external (e.g. Status Bar) intercept touch event to the Shade touch handler. */
public boolean sendInterceptTouchEventToView(MotionEvent event) { public boolean handleExternalInterceptTouch(MotionEvent event) {
return mView.onInterceptTouchEvent(event); return mTouchHandler.onInterceptTouchEvent(event);
} }
/** */ /** Sends an external (e.g. Status Bar) touch event to the Shade touch handler. */
public boolean sendTouchEventToView(MotionEvent event) { public boolean handleExternalTouch(MotionEvent event) {
return mView.dispatchTouchEvent(event); return mTouchHandler.onTouchEvent(event);
} }
/** */ /** */
@@ -4010,14 +4004,6 @@ public final class NotificationPanelViewController implements Dumpable {
return mView.isEnabled(); return mView.isEnabled();
} }
int getDisplayRightInset() {
return mDisplayRightInset;
}
int getDisplayLeftInset() {
return mDisplayLeftInset;
}
float getOverStretchAmount() { float getOverStretchAmount() {
return mOverStretchAmount; return mOverStretchAmount;
} }
@@ -4026,10 +4012,6 @@ public final class NotificationPanelViewController implements Dumpable {
return mMinFraction; return mMinFraction;
} }
boolean getCollapsedOnDown() {
return mCollapsedOnDown;
}
int getNavigationBarBottomHeight() { int getNavigationBarBottomHeight() {
return mNavigationBarBottomHeight; return mNavigationBarBottomHeight;
} }
@@ -4593,7 +4575,7 @@ public final class NotificationPanelViewController implements Dumpable {
} }
/** Handles MotionEvents for the Shade. */ /** Handles MotionEvents for the Shade. */
public final class TouchHandler implements View.OnTouchListener { public final class TouchHandler implements View.OnTouchListener, Gefingerpoken {
private long mLastTouchDownTime = -1L; private long mLastTouchDownTime = -1L;
/** @see ViewGroup#onInterceptTouchEvent(MotionEvent) */ /** @see ViewGroup#onInterceptTouchEvent(MotionEvent) */
@@ -4739,6 +4721,11 @@ public final class NotificationPanelViewController implements Dumpable {
@Override @Override
public boolean onTouch(View v, MotionEvent event) { public boolean onTouch(View v, MotionEvent event) {
return onTouchEvent(event);
}
@Override
public boolean onTouchEvent(MotionEvent event) {
if (event.getAction() == MotionEvent.ACTION_DOWN) { if (event.getAction() == MotionEvent.ACTION_DOWN) {
if (event.getDownTime() == mLastTouchDownTime) { if (event.getDownTime() == mLastTouchDownTime) {
// An issue can occur when swiping down after unlock, where multiple down // An issue can occur when swiping down after unlock, where multiple down

View File

@@ -342,7 +342,7 @@ public class NotificationShadeWindowViewController {
MotionEvent cancellation = MotionEvent.obtain(ev); MotionEvent cancellation = MotionEvent.obtain(ev);
cancellation.setAction(MotionEvent.ACTION_CANCEL); cancellation.setAction(MotionEvent.ACTION_CANCEL);
mStackScrollLayout.onInterceptTouchEvent(cancellation); mStackScrollLayout.onInterceptTouchEvent(cancellation);
mNotificationPanelViewController.sendInterceptTouchEventToView(cancellation); mNotificationPanelViewController.handleExternalInterceptTouch(cancellation);
cancellation.recycle(); cancellation.recycle();
} }

View File

@@ -35,6 +35,7 @@ import android.widget.LinearLayout;
import com.android.internal.policy.SystemBarUtils; import com.android.internal.policy.SystemBarUtils;
import com.android.systemui.Dependency; import com.android.systemui.Dependency;
import com.android.systemui.Gefingerpoken;
import com.android.systemui.R; import com.android.systemui.R;
import com.android.systemui.plugins.DarkIconDispatcher; import com.android.systemui.plugins.DarkIconDispatcher;
import com.android.systemui.plugins.DarkIconDispatcher.DarkReceiver; import com.android.systemui.plugins.DarkIconDispatcher.DarkReceiver;
@@ -60,7 +61,7 @@ public class PhoneStatusBarView extends FrameLayout {
private Rect mDisplaySize; private Rect mDisplaySize;
private int mStatusBarHeight; private int mStatusBarHeight;
@Nullable @Nullable
private TouchEventHandler mTouchEventHandler; private Gefingerpoken mTouchEventHandler;
/** /**
* Draw this many pixels into the left/right side of the cutout to optimally use the space * 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); mContentInsetsProvider = Dependency.get(StatusBarContentInsetsProvider.class);
} }
void setTouchEventHandler(TouchEventHandler handler) { void setTouchEventHandler(Gefingerpoken handler) {
mTouchEventHandler = handler; mTouchEventHandler = handler;
} }
@@ -185,7 +186,7 @@ public class PhoneStatusBarView extends FrameLayout {
); );
return true; return true;
} }
return mTouchEventHandler.handleTouchEvent(event); return mTouchEventHandler.onTouchEvent(event);
} }
@Override @Override
@@ -267,28 +268,4 @@ public class PhoneStatusBarView extends FrameLayout {
insets.second, insets.second,
getPaddingBottom()); 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);
}
} }

View File

@@ -24,11 +24,11 @@ import android.view.MotionEvent
import android.view.View import android.view.View
import android.view.ViewGroup import android.view.ViewGroup
import android.view.ViewTreeObserver import android.view.ViewTreeObserver
import com.android.systemui.Gefingerpoken
import com.android.systemui.R import com.android.systemui.R
import com.android.systemui.shade.ShadeController import com.android.systemui.shade.ShadeController
import com.android.systemui.shade.ShadeLogger import com.android.systemui.shade.ShadeLogger
import com.android.systemui.shared.animation.UnfoldMoveFromCenterAnimator 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.statusbar.policy.ConfigurationController
import com.android.systemui.unfold.SysUIUnfoldComponent import com.android.systemui.unfold.SysUIUnfoldComponent
import com.android.systemui.unfold.UNFOLD_STATUS_BAR 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}. */ /** Called when a touch event occurred on {@link PhoneStatusBarView}. */
fun onTouchEvent(event: MotionEvent) { fun onTouch(event: MotionEvent) {
if (centralSurfaces.statusBarWindowState == WINDOW_STATE_SHOWING) { if (centralSurfaces.statusBarWindowState == WINDOW_STATE_SHOWING) {
val upOrCancel = val upOrCancel =
event.action == MotionEvent.ACTION_UP || event.action == MotionEvent.ACTION_UP ||
@@ -141,13 +141,14 @@ class PhoneStatusBarViewController private constructor(
} }
} }
inner class PhoneStatusBarViewTouchHandler : TouchEventHandler { inner class PhoneStatusBarViewTouchHandler : Gefingerpoken {
override fun onInterceptTouchEvent(event: MotionEvent) { override fun onInterceptTouchEvent(event: MotionEvent): Boolean {
onTouchEvent(event) onTouch(event)
return false
} }
override fun handleTouchEvent(event: MotionEvent): Boolean { override fun onTouchEvent(event: MotionEvent): Boolean {
onTouchEvent(event) onTouch(event)
// If panels aren't enabled, ignore the gesture and don't pass it down to the // If panels aren't enabled, ignore the gesture and don't pass it down to the
// panel view. // panel view.
@@ -174,7 +175,7 @@ class PhoneStatusBarViewController private constructor(
return true return true
} }
} }
return centralSurfaces.notificationPanelViewController.sendTouchEventToView(event) return centralSurfaces.notificationPanelViewController.handleExternalTouch(event)
} }
} }

View File

@@ -536,12 +536,10 @@ public class NotificationPanelViewControllerBaseTest extends SysuiTestCase {
mQsController, mQsController,
mFragmentService, mFragmentService,
mContentResolver, mContentResolver,
mRecordingController,
mShadeHeaderController, mShadeHeaderController,
mScreenOffAnimationController, mScreenOffAnimationController,
mLockscreenGestureLogger, mLockscreenGestureLogger,
mShadeExpansionStateManager, mShadeExpansionStateManager,
mNotificationRemoteInputManager,
mSysUIUnfoldComponent, mSysUIUnfoldComponent,
mSysUiState, mSysUiState,
() -> mKeyguardBottomAreaViewController, () -> mKeyguardBottomAreaViewController,

View File

@@ -18,7 +18,6 @@ package com.android.systemui.statusbar.phone
import android.view.LayoutInflater import android.view.LayoutInflater
import android.view.MotionEvent import android.view.MotionEvent
import android.view.ViewGroup
import android.view.ViewTreeObserver import android.view.ViewTreeObserver
import android.view.ViewTreeObserver.OnPreDrawListener import android.view.ViewTreeObserver.OnPreDrawListener
import android.widget.FrameLayout import android.widget.FrameLayout
@@ -55,8 +54,6 @@ class PhoneStatusBarViewControllerTest : SysuiTestCase() {
@Mock @Mock
private lateinit var notificationPanelViewController: NotificationPanelViewController private lateinit var notificationPanelViewController: NotificationPanelViewController
@Mock @Mock
private lateinit var panelView: ViewGroup
@Mock
private lateinit var moveFromCenterAnimation: StatusBarMoveFromCenterAnimationController private lateinit var moveFromCenterAnimation: StatusBarMoveFromCenterAnimationController
@Mock @Mock
private lateinit var sysuiUnfoldComponent: SysUIUnfoldComponent private lateinit var sysuiUnfoldComponent: SysUIUnfoldComponent
@@ -116,7 +113,7 @@ class PhoneStatusBarViewControllerTest : SysuiTestCase() {
val returnVal = view.onTouchEvent( val returnVal = view.onTouchEvent(
MotionEvent.obtain(0L, 0L, MotionEvent.ACTION_DOWN, 0f, 0f, 0)) MotionEvent.obtain(0L, 0L, MotionEvent.ACTION_DOWN, 0f, 0f, 0))
assertThat(returnVal).isFalse() assertThat(returnVal).isFalse()
verify(notificationPanelViewController, never()).sendTouchEventToView(any()) verify(notificationPanelViewController, never()).handleExternalTouch(any())
} }
@Test @Test
@@ -128,7 +125,7 @@ class PhoneStatusBarViewControllerTest : SysuiTestCase() {
val returnVal = view.onTouchEvent( val returnVal = view.onTouchEvent(
MotionEvent.obtain(0L, 0L, MotionEvent.ACTION_DOWN, 0f, 0f, 0)) MotionEvent.obtain(0L, 0L, MotionEvent.ACTION_DOWN, 0f, 0f, 0))
assertThat(returnVal).isTrue() assertThat(returnVal).isTrue()
verify(notificationPanelViewController, never()).sendTouchEventToView(any()) verify(notificationPanelViewController, never()).handleExternalTouch(any())
} }
@Test @Test
@@ -141,7 +138,7 @@ class PhoneStatusBarViewControllerTest : SysuiTestCase() {
view.onTouchEvent(event) view.onTouchEvent(event)
verify(notificationPanelViewController).sendTouchEventToView(event) verify(notificationPanelViewController).handleExternalTouch(event)
} }
@Test @Test
@@ -154,7 +151,7 @@ class PhoneStatusBarViewControllerTest : SysuiTestCase() {
view.onTouchEvent(event) view.onTouchEvent(event)
verify(notificationPanelViewController).sendTouchEventToView(event) verify(notificationPanelViewController).handleExternalTouch(event)
} }
@Test @Test
@@ -167,7 +164,7 @@ class PhoneStatusBarViewControllerTest : SysuiTestCase() {
view.onTouchEvent(event) view.onTouchEvent(event)
verify(notificationPanelViewController, never()).sendTouchEventToView(any()) verify(notificationPanelViewController, never()).handleExternalTouch(any())
} }
private fun createViewMock(): PhoneStatusBarView { private fun createViewMock(): PhoneStatusBarView {

View File

@@ -19,6 +19,7 @@ package com.android.systemui.statusbar.phone
import android.view.MotionEvent import android.view.MotionEvent
import android.view.ViewGroup import android.view.ViewGroup
import androidx.test.filters.SmallTest import androidx.test.filters.SmallTest
import com.android.systemui.Gefingerpoken
import com.android.systemui.SysuiTestCase import com.android.systemui.SysuiTestCase
import com.android.systemui.shade.NotificationPanelViewController import com.android.systemui.shade.NotificationPanelViewController
import com.google.common.truth.Truth.assertThat import com.google.common.truth.Truth.assertThat
@@ -94,16 +95,17 @@ class PhoneStatusBarViewTest : SysuiTestCase() {
// No assert needed, just testing no crash // No assert needed, just testing no crash
} }
private class TestTouchEventHandler : PhoneStatusBarView.TouchEventHandler { private class TestTouchEventHandler : Gefingerpoken {
var lastInterceptEvent: MotionEvent? = null var lastInterceptEvent: MotionEvent? = null
var lastEvent: MotionEvent? = null var lastEvent: MotionEvent? = null
var handleTouchReturnValue: Boolean = false var handleTouchReturnValue: Boolean = false
override fun onInterceptTouchEvent(event: MotionEvent?) { override fun onInterceptTouchEvent(event: MotionEvent?): Boolean {
lastInterceptEvent = event lastInterceptEvent = event
return handleTouchReturnValue
} }
override fun handleTouchEvent(event: MotionEvent?): Boolean { override fun onTouchEvent(event: MotionEvent?): Boolean {
lastEvent = event lastEvent = event
return handleTouchReturnValue return handleTouchReturnValue
} }