diff options
5 files changed, 37 insertions, 92 deletions
diff --git a/packages/SystemUI/src/com/android/systemui/shade/NotificationShadeWindowViewController.java b/packages/SystemUI/src/com/android/systemui/shade/NotificationShadeWindowViewController.java index 832a25bfbc41..802ed8069a69 100644 --- a/packages/SystemUI/src/com/android/systemui/shade/NotificationShadeWindowViewController.java +++ b/packages/SystemUI/src/com/android/systemui/shade/NotificationShadeWindowViewController.java @@ -21,8 +21,6 @@ import static com.android.systemui.flags.Flags.TRACKPAD_GESTURE_COMMON; import static com.android.systemui.util.kotlin.JavaAdapterKt.collectFlow; import android.app.StatusBarManager; -import android.media.AudioManager; -import android.media.session.MediaSessionLegacyHelper; import android.os.PowerManager; import android.util.Log; import android.view.GestureDetector; @@ -47,6 +45,7 @@ import com.android.systemui.dagger.SysUISingleton; import com.android.systemui.dock.DockManager; import com.android.systemui.flags.FeatureFlags; import com.android.systemui.flags.Flags; +import com.android.systemui.keyevent.domain.interactor.KeyEventInteractor; import com.android.systemui.keyguard.KeyguardUnlockAnimationController; import com.android.systemui.keyguard.domain.interactor.KeyguardTransitionInteractor; import com.android.systemui.keyguard.shared.model.TransitionState; @@ -101,6 +100,7 @@ public class NotificationShadeWindowViewController { private final NotificationInsetsController mNotificationInsetsController; private final boolean mIsTrackpadCommonEnabled; private final FeatureFlags mFeatureFlags; + private final KeyEventInteractor mKeyEventInteractor; private GestureDetector mPulsingWakeupGestureHandler; private GestureDetector mDreamingWakeupGestureHandler; private View mBrightnessMirror; @@ -164,7 +164,8 @@ public class NotificationShadeWindowViewController { FeatureFlags featureFlags, SystemClock clock, BouncerMessageInteractor bouncerMessageInteractor, - BouncerLogger bouncerLogger) { + BouncerLogger bouncerLogger, + KeyEventInteractor keyEventInteractor) { mLockscreenShadeTransitionController = transitionController; mFalsingCollector = falsingCollector; mStatusBarStateController = statusBarStateController; @@ -190,6 +191,7 @@ public class NotificationShadeWindowViewController { mNotificationInsetsController = notificationInsetsController; mIsTrackpadCommonEnabled = featureFlags.isEnabled(TRACKPAD_GESTURE_COMMON); mFeatureFlags = featureFlags; + mKeyEventInteractor = keyEventInteractor; // This view is not part of the newly inflated expanded status bar. mBrightnessMirror = mView.findViewById(R.id.brightness_mirror_container); @@ -457,44 +459,17 @@ public class NotificationShadeWindowViewController { @Override public boolean interceptMediaKey(KeyEvent event) { - return mService.interceptMediaKey(event); + return mKeyEventInteractor.interceptMediaKey(event); } @Override public boolean dispatchKeyEventPreIme(KeyEvent event) { - return mService.dispatchKeyEventPreIme(event); + return mKeyEventInteractor.dispatchKeyEventPreIme(event); } @Override public boolean dispatchKeyEvent(KeyEvent event) { - boolean down = event.getAction() == KeyEvent.ACTION_DOWN; - switch (event.getKeyCode()) { - case KeyEvent.KEYCODE_BACK: - if (!down) { - mBackActionInteractor.onBackRequested(); - } - return true; - case KeyEvent.KEYCODE_MENU: - if (!down) { - return mService.onMenuPressed(); - } - break; - case KeyEvent.KEYCODE_SPACE: - if (!down) { - return mService.onSpacePressed(); - } - break; - case KeyEvent.KEYCODE_VOLUME_DOWN: - case KeyEvent.KEYCODE_VOLUME_UP: - if (mStatusBarStateController.isDozing()) { - MediaSessionLegacyHelper.getHelper(mView.getContext()) - .sendVolumeKeyEvent( - event, AudioManager.USE_DEFAULT_STREAM_TYPE, true); - return true; - } - break; - } - return false; + return mKeyEventInteractor.dispatchKeyEvent(event); } }); diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/phone/CentralSurfaces.java b/packages/SystemUI/src/com/android/systemui/statusbar/phone/CentralSurfaces.java index 5c28be3bc678..af09bf281c0c 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/CentralSurfaces.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/CentralSurfaces.java @@ -25,7 +25,6 @@ import android.content.Intent; import android.content.pm.PackageManager; import android.os.Bundle; import android.os.UserHandle; -import android.view.KeyEvent; import android.view.MotionEvent; import android.view.RemoteAnimationAdapter; import android.view.View; @@ -276,19 +275,11 @@ public interface CentralSurfaces extends Dumpable, LifecycleOwner { void userActivity(); - boolean interceptMediaKey(KeyEvent event); - - boolean dispatchKeyEventPreIme(KeyEvent event); - - boolean onMenuPressed(); - void endAffordanceLaunch(); /** Should the keyguard be hidden immediately in response to a back press/gesture. */ boolean shouldKeyguardHideImmediately(); - boolean onSpacePressed(); - void showBouncerWithDimissAndCancelIfKeyguard(OnDismissAction performAction, Runnable cancelAction); diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/phone/CentralSurfacesImpl.java b/packages/SystemUI/src/com/android/systemui/statusbar/phone/CentralSurfacesImpl.java index 8ffd43a6eb89..ccb87bf44dc8 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/CentralSurfacesImpl.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/CentralSurfacesImpl.java @@ -89,7 +89,6 @@ import android.util.MathUtils; import android.view.Display; import android.view.IRemoteAnimationRunner; import android.view.IWindowManager; -import android.view.KeyEvent; import android.view.MotionEvent; import android.view.ThreadedRenderer; import android.view.View; @@ -2636,44 +2635,6 @@ public class CentralSurfacesImpl implements CoreStartable, CentralSurfaces { } @Override - public boolean interceptMediaKey(KeyEvent event) { - return mState == StatusBarState.KEYGUARD - && mStatusBarKeyguardViewManager.interceptMediaKey(event); - } - - /** - * While IME is active and a BACK event is detected, check with - * {@link StatusBarKeyguardViewManager#dispatchBackKeyEventPreIme()} to see if the event - * should be handled before routing to IME, in order to prevent the user having to hit back - * twice to exit bouncer. - */ - @Override - public boolean dispatchKeyEventPreIme(KeyEvent event) { - switch (event.getKeyCode()) { - case KeyEvent.KEYCODE_BACK: - if (mState == StatusBarState.KEYGUARD - && mStatusBarKeyguardViewManager.dispatchBackKeyEventPreIme()) { - return mBackActionInteractor.onBackRequested(); - } - } - return false; - } - - protected boolean shouldUnlockOnMenuPressed() { - return mDeviceInteractive && mState != StatusBarState.SHADE - && mStatusBarKeyguardViewManager.shouldDismissOnMenuPressed(); - } - - @Override - public boolean onMenuPressed() { - if (shouldUnlockOnMenuPressed()) { - mShadeController.animateCollapseShadeForced(); - return true; - } - return false; - } - - @Override public void endAffordanceLaunch() { releaseGestureWakeLock(); mCameraLauncherLazy.get().setLaunchingAffordance(false); @@ -2692,15 +2653,6 @@ public class CentralSurfacesImpl implements CoreStartable, CentralSurfaces { return (isScrimmedBouncer || isBouncerOverDream); } - @Override - public boolean onSpacePressed() { - if (mDeviceInteractive && mState != StatusBarState.SHADE) { - mShadeController.animateCollapseShadeForced(); - return true; - } - return false; - } - private void showBouncerOrLockScreenIfKeyguard() { // If the keyguard is animating away, we aren't really the keyguard anymore and should not // show the bouncer/lockscreen. diff --git a/packages/SystemUI/tests/src/com/android/systemui/shade/NotificationShadeWindowViewControllerTest.kt b/packages/SystemUI/tests/src/com/android/systemui/shade/NotificationShadeWindowViewControllerTest.kt index 1edeeffe5217..dc506a5b1d25 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/shade/NotificationShadeWindowViewControllerTest.kt +++ b/packages/SystemUI/tests/src/com/android/systemui/shade/NotificationShadeWindowViewControllerTest.kt @@ -18,6 +18,7 @@ package com.android.systemui.shade import android.testing.AndroidTestingRunner import android.testing.TestableLooper.RunWithLooper +import android.view.KeyEvent import android.view.MotionEvent import android.view.ViewGroup import androidx.test.filters.SmallTest @@ -38,6 +39,7 @@ import com.android.systemui.dock.DockManager import com.android.systemui.dump.logcatLogBuffer import com.android.systemui.flags.FakeFeatureFlags import com.android.systemui.flags.Flags +import com.android.systemui.keyevent.domain.interactor.KeyEventInteractor import com.android.systemui.keyguard.KeyguardUnlockAnimationController import com.android.systemui.keyguard.domain.interactor.KeyguardTransitionInteractor import com.android.systemui.keyguard.shared.model.TransitionStep @@ -118,6 +120,7 @@ class NotificationShadeWindowViewControllerTest : SysuiTestCase() { @Mock lateinit var keyguardTransitionInteractor: KeyguardTransitionInteractor @Mock lateinit var primaryBouncerToGoneTransitionViewModel: PrimaryBouncerToGoneTransitionViewModel + @Mock lateinit var keyEventInteractor: KeyEventInteractor private val notificationExpansionRepository = NotificationExpansionRepository() private lateinit var interactionEventHandlerCaptor: ArgumentCaptor<InteractionEventHandler> @@ -188,7 +191,8 @@ class NotificationShadeWindowViewControllerTest : SysuiTestCase() { CountDownTimerUtil(), featureFlags ), - BouncerLogger(logcatLogBuffer("BouncerLog")) + BouncerLogger(logcatLogBuffer("BouncerLog")), + keyEventInteractor, ) underTest.setupExpandedStatusBar() @@ -345,6 +349,27 @@ class NotificationShadeWindowViewControllerTest : SysuiTestCase() { verify(view).findViewById<ViewGroup>(R.id.keyguard_message_area) } + @Test + fun forwardsDispatchKeyEvent() { + val keyEvent = KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_B) + interactionEventHandler.dispatchKeyEvent(keyEvent) + verify(keyEventInteractor).dispatchKeyEvent(keyEvent) + } + + @Test + fun forwardsDispatchKeyEventPreIme() { + val keyEvent = KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_B) + interactionEventHandler.dispatchKeyEventPreIme(keyEvent) + verify(keyEventInteractor).dispatchKeyEventPreIme(keyEvent) + } + + @Test + fun forwardsInterceptMediaKey() { + val keyEvent = KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_VOLUME_UP) + interactionEventHandler.interceptMediaKey(keyEvent) + verify(keyEventInteractor).interceptMediaKey(keyEvent) + } + companion object { private val DOWN_EVENT = MotionEvent.obtain(0L, 0L, MotionEvent.ACTION_DOWN, 0f, 0f, 0) private const val VIEW_BOTTOM = 100 diff --git a/packages/SystemUI/tests/src/com/android/systemui/shade/NotificationShadeWindowViewTest.kt b/packages/SystemUI/tests/src/com/android/systemui/shade/NotificationShadeWindowViewTest.kt index 829184c4f05a..66d48d64b3a3 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/shade/NotificationShadeWindowViewTest.kt +++ b/packages/SystemUI/tests/src/com/android/systemui/shade/NotificationShadeWindowViewTest.kt @@ -38,6 +38,7 @@ import com.android.systemui.dock.DockManager import com.android.systemui.dump.logcatLogBuffer import com.android.systemui.flags.FakeFeatureFlags import com.android.systemui.flags.Flags +import com.android.systemui.keyevent.domain.interactor.KeyEventInteractor import com.android.systemui.keyguard.KeyguardUnlockAnimationController import com.android.systemui.keyguard.domain.interactor.KeyguardTransitionInteractor import com.android.systemui.keyguard.ui.viewmodel.PrimaryBouncerToGoneTransitionViewModel @@ -198,7 +199,8 @@ class NotificationShadeWindowViewTest : SysuiTestCase() { CountDownTimerUtil(), featureFlags ), - BouncerLogger(logcatLogBuffer("BouncerLog")) + BouncerLogger(logcatLogBuffer("BouncerLog")), + Mockito.mock(KeyEventInteractor::class.java), ) controller.setupExpandedStatusBar() |