[Media TTT] Make the SwipeUpGestureHandler generic. am: b7ec39e18d am: 19595177f3

Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/21024665

Change-Id: Id09275fef97d9ee602fc93fff5e241a6909cc53a
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/dagger/CentralSurfacesDependenciesModule.java b/packages/SystemUI/src/com/android/systemui/statusbar/dagger/CentralSurfacesDependenciesModule.java
index adaae44..9a65e34 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/dagger/CentralSurfacesDependenciesModule.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/dagger/CentralSurfacesDependenciesModule.java
@@ -48,7 +48,7 @@
 import com.android.systemui.statusbar.StatusBarStateControllerImpl;
 import com.android.systemui.statusbar.SysuiStatusBarStateController;
 import com.android.systemui.statusbar.commandline.CommandRegistry;
-import com.android.systemui.statusbar.gesture.SwipeUpGestureHandler;
+import com.android.systemui.statusbar.gesture.SwipeStatusBarAwayGestureHandler;
 import com.android.systemui.statusbar.notification.NotifPipelineFlags;
 import com.android.systemui.statusbar.notification.collection.NotifCollection;
 import com.android.systemui.statusbar.notification.collection.NotifPipeline;
@@ -230,7 +230,7 @@
             OngoingCallLogger logger,
             DumpManager dumpManager,
             StatusBarWindowController statusBarWindowController,
-            SwipeUpGestureHandler swipeStatusBarAwayGestureHandler,
+            SwipeStatusBarAwayGestureHandler swipeStatusBarAwayGestureHandler,
             StatusBarStateController statusBarStateController,
             OngoingCallFlags ongoingCallFlags) {
 
@@ -239,7 +239,7 @@
                 ongoingCallInImmersiveEnabled
                         ? Optional.of(statusBarWindowController)
                         : Optional.empty();
-        Optional<SwipeUpGestureHandler> gestureHandler =
+        Optional<SwipeStatusBarAwayGestureHandler> gestureHandler =
                 ongoingCallInImmersiveEnabled
                         ? Optional.of(swipeStatusBarAwayGestureHandler)
                         : Optional.empty();
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/gesture/SwipeStatusBarAwayGestureHandler.kt b/packages/SystemUI/src/com/android/systemui/statusbar/gesture/SwipeStatusBarAwayGestureHandler.kt
new file mode 100644
index 0000000..5ab3d7c
--- /dev/null
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/gesture/SwipeStatusBarAwayGestureHandler.kt
@@ -0,0 +1,41 @@
+/*
+ * Copyright (C) 2021 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.systemui.statusbar.gesture
+
+import android.content.Context
+import android.view.MotionEvent
+import com.android.systemui.dagger.SysUISingleton
+import com.android.systemui.statusbar.window.StatusBarWindowController
+import javax.inject.Inject
+
+/** A class to detect when a user swipes away the status bar. */
+@SysUISingleton
+class SwipeStatusBarAwayGestureHandler
+@Inject
+constructor(
+    context: Context,
+    logger: SwipeUpGestureLogger,
+    private val statusBarWindowController: StatusBarWindowController,
+) : SwipeUpGestureHandler(context, logger, loggerTag = LOGGER_TAG) {
+    override fun startOfGestureIsWithinBounds(ev: MotionEvent): Boolean {
+        // Gesture starts just below the status bar
+        return ev.y >= statusBarWindowController.statusBarHeight &&
+            ev.y <= 3 * statusBarWindowController.statusBarHeight
+    }
+}
+
+private const val LOGGER_TAG = "SwipeStatusBarAway"
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/gesture/SwipeUpGestureHandler.kt b/packages/SystemUI/src/com/android/systemui/statusbar/gesture/SwipeUpGestureHandler.kt
index 4ff1423..5ecc35c 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/gesture/SwipeUpGestureHandler.kt
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/gesture/SwipeUpGestureHandler.kt
@@ -24,18 +24,16 @@
 import android.view.MotionEvent.ACTION_MOVE
 import android.view.MotionEvent.ACTION_UP
 import com.android.systemui.dagger.SysUISingleton
-import com.android.systemui.statusbar.window.StatusBarWindowController
-import javax.inject.Inject
 
 /**
- * A class to detect when a user swipes away the status bar. To be notified when the swipe away
- * gesture is detected, add a callback via [addOnGestureDetectedCallback].
+ * A class to detect a generic "swipe up" gesture. To be notified when the swipe up gesture is
+ * detected, add a callback via [addOnGestureDetectedCallback].
  */
 @SysUISingleton
-open class SwipeUpGestureHandler @Inject constructor(
+abstract class SwipeUpGestureHandler(
     context: Context,
-    private val statusBarWindowController: StatusBarWindowController,
-    private val logger: SwipeUpGestureLogger
+    private val logger: SwipeUpGestureLogger,
+    private val loggerTag: String,
 ) : GenericGestureDetector(SwipeUpGestureHandler::class.simpleName!!) {
 
     private var startY: Float = 0f
@@ -54,11 +52,9 @@
         when (ev.actionMasked) {
             ACTION_DOWN -> {
                 if (
-                    // Gesture starts just below the status bar
-                    ev.y >= statusBarWindowController.statusBarHeight
-                    && ev.y <= 3 * statusBarWindowController.statusBarHeight
+                    startOfGestureIsWithinBounds(ev)
                 ) {
-                    logger.logGestureDetectionStarted(ev.y.toInt())
+                    logger.logGestureDetectionStarted(loggerTag, ev.y.toInt())
                     startY = ev.y
                     startTime = ev.eventTime
                     monitoringCurrentTouch = true
@@ -79,27 +75,36 @@
                     (ev.eventTime - startTime) < SWIPE_TIMEOUT_MS
                 ) {
                     monitoringCurrentTouch = false
-                    logger.logGestureDetected(ev.y.toInt())
+                    logger.logGestureDetected(loggerTag, ev.y.toInt())
                     onGestureDetected(ev)
                 }
             }
             ACTION_CANCEL, ACTION_UP -> {
                 if (monitoringCurrentTouch) {
-                    logger.logGestureDetectionEndedWithoutTriggering(ev.y.toInt())
+                    logger.logGestureDetectionEndedWithoutTriggering(loggerTag, ev.y.toInt())
                 }
                 monitoringCurrentTouch = false
             }
         }
     }
 
+    /**
+     * Returns true if the [ACTION_DOWN] event falls within bounds for this specific swipe-up
+     * gesture.
+     *
+     * Implementations must override this method to specify what part(s) of the screen are valid
+     * locations for the swipe up gesture to start at.
+     */
+    abstract fun startOfGestureIsWithinBounds(ev: MotionEvent): Boolean
+
     override fun startGestureListening() {
         super.startGestureListening()
-        logger.logInputListeningStarted()
+        logger.logInputListeningStarted(loggerTag)
     }
 
     override fun stopGestureListening() {
         super.stopGestureListening()
-        logger.logInputListeningStopped()
+        logger.logInputListeningStopped(loggerTag)
     }
 }
 
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/gesture/SwipeUpGestureLogger.kt b/packages/SystemUI/src/com/android/systemui/statusbar/gesture/SwipeUpGestureLogger.kt
index 72759c7..9ce6b02 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/gesture/SwipeUpGestureLogger.kt
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/gesture/SwipeUpGestureLogger.kt
@@ -16,49 +16,49 @@
 
 package com.android.systemui.statusbar.gesture
 
+import com.android.systemui.dagger.SysUISingleton
 import com.android.systemui.log.dagger.SwipeUpLog
 import com.android.systemui.plugins.log.LogBuffer
 import com.android.systemui.plugins.log.LogLevel
 import javax.inject.Inject
 
 /** Log messages for [SwipeUpGestureHandler]. */
+@SysUISingleton
 class SwipeUpGestureLogger @Inject constructor(
     @SwipeUpLog private val buffer: LogBuffer,
 ) {
-    fun logGestureDetectionStarted(y: Int) {
+    fun logGestureDetectionStarted(tag: String, y: Int) {
         buffer.log(
-            TAG,
+            tag,
             LogLevel.DEBUG,
             { int1 = y },
             { "Beginning gesture detection. y=$int1" }
         )
     }
 
-    fun logGestureDetectionEndedWithoutTriggering(y: Int) {
+    fun logGestureDetectionEndedWithoutTriggering(tag: String, y: Int) {
         buffer.log(
-            TAG,
+            tag,
             LogLevel.DEBUG,
             { int1 = y },
             { "Gesture finished; no swipe up gesture detected. Final y=$int1" }
         )
     }
 
-    fun logGestureDetected(y: Int) {
+    fun logGestureDetected(tag: String, y: Int) {
         buffer.log(
-            TAG,
+            tag,
             LogLevel.INFO,
             { int1 = y },
             { "Gesture detected; notifying callbacks. y=$int1" }
         )
     }
 
-    fun logInputListeningStarted() {
-        buffer.log(TAG, LogLevel.VERBOSE, {}, { "Input listening started "})
+    fun logInputListeningStarted(tag: String) {
+        buffer.log(tag, LogLevel.VERBOSE, {}, { "Input listening started "})
     }
 
-    fun logInputListeningStopped() {
-        buffer.log(TAG, LogLevel.VERBOSE, {}, { "Input listening stopped "})
+    fun logInputListeningStopped(tag: String) {
+        buffer.log(tag, LogLevel.VERBOSE, {}, { "Input listening stopped "})
     }
 }
-
-private const val TAG = "SwipeUpGestureHandler"
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/phone/ongoingcall/OngoingCallController.kt b/packages/SystemUI/src/com/android/systemui/statusbar/phone/ongoingcall/OngoingCallController.kt
index 9d5d2a2..dfa6838 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/ongoingcall/OngoingCallController.kt
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/ongoingcall/OngoingCallController.kt
@@ -35,7 +35,7 @@
 import com.android.systemui.dump.DumpManager
 import com.android.systemui.plugins.ActivityStarter
 import com.android.systemui.plugins.statusbar.StatusBarStateController
-import com.android.systemui.statusbar.gesture.SwipeUpGestureHandler
+import com.android.systemui.statusbar.gesture.SwipeStatusBarAwayGestureHandler
 import com.android.systemui.statusbar.notification.collection.NotificationEntry
 import com.android.systemui.statusbar.notification.collection.notifcollection.CommonNotifCollection
 import com.android.systemui.statusbar.notification.collection.notifcollection.NotifCollectionListener
@@ -62,7 +62,7 @@
     private val logger: OngoingCallLogger,
     private val dumpManager: DumpManager,
     private val statusBarWindowController: Optional<StatusBarWindowController>,
-    private val swipeStatusBarAwayGestureHandler: Optional<SwipeUpGestureHandler>,
+    private val swipeStatusBarAwayGestureHandler: Optional<SwipeStatusBarAwayGestureHandler>,
     private val statusBarStateController: StatusBarStateController
 ) : CallbackController<OngoingCallListener>, Dumpable {
     private var isFullscreen: Boolean = false
diff --git a/packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/ongoingcall/OngoingCallControllerTest.kt b/packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/ongoingcall/OngoingCallControllerTest.kt
index 7e2275c..711e4ac 100644
--- a/packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/ongoingcall/OngoingCallControllerTest.kt
+++ b/packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/ongoingcall/OngoingCallControllerTest.kt
@@ -35,7 +35,7 @@
 import com.android.systemui.dump.DumpManager
 import com.android.systemui.plugins.ActivityStarter
 import com.android.systemui.plugins.statusbar.StatusBarStateController
-import com.android.systemui.statusbar.gesture.SwipeUpGestureHandler
+import com.android.systemui.statusbar.gesture.SwipeStatusBarAwayGestureHandler
 import com.android.systemui.statusbar.notification.collection.NotificationEntry
 import com.android.systemui.statusbar.notification.collection.NotificationEntryBuilder
 import com.android.systemui.statusbar.notification.collection.notifcollection.CommonNotifCollection
@@ -50,7 +50,9 @@
 import org.junit.Test
 import org.junit.runner.RunWith
 import org.mockito.ArgumentCaptor
-import org.mockito.ArgumentMatchers.*
+import org.mockito.ArgumentMatchers.anyBoolean
+import org.mockito.ArgumentMatchers.anyString
+import org.mockito.ArgumentMatchers.nullable
 import org.mockito.Mock
 import org.mockito.Mockito.`when`
 import org.mockito.Mockito.eq
@@ -83,7 +85,8 @@
     private lateinit var notifCollectionListener: NotifCollectionListener
 
     @Mock private lateinit var mockOngoingCallFlags: OngoingCallFlags
-    @Mock private lateinit var mockSwipeStatusBarAwayGestureHandler: SwipeUpGestureHandler
+    @Mock private lateinit var mockSwipeStatusBarAwayGestureHandler:
+        SwipeStatusBarAwayGestureHandler
     @Mock private lateinit var mockOngoingCallListener: OngoingCallListener
     @Mock private lateinit var mockActivityStarter: ActivityStarter
     @Mock private lateinit var mockIActivityManager: IActivityManager