summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Treehugger Robot <android-test-infra-autosubmit@system.gserviceaccount.com> 2023-09-21 05:17:05 +0000
committer Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com> 2023-09-21 05:17:05 +0000
commit83bec07c84feb16c77a7bae84eb69d3248600400 (patch)
tree2db6d38948de15b12841a7f62e88f395c535e855
parenta0031557ab96378bc942f265d1dda0c5c79eb5d3 (diff)
parent77c5cd9afe1db14728b5cc2dceff36de3dd0ac7b (diff)
Merge changes from topic "cherrypicker-L35800000963116081:N91200001406548621" into udc-qpr-dev am: 77c5cd9afe
Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/24807356 Change-Id: Ib37303c3e288fe4b0d9363c2a18cda7ac85d24b9 Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
-rw-r--r--packages/SystemUI/src/com/android/systemui/notetask/NoteTaskInitializer.kt45
-rw-r--r--packages/SystemUI/tests/src/com/android/systemui/notetask/NoteTaskInitializerTest.kt38
2 files changed, 73 insertions, 10 deletions
diff --git a/packages/SystemUI/src/com/android/systemui/notetask/NoteTaskInitializer.kt b/packages/SystemUI/src/com/android/systemui/notetask/NoteTaskInitializer.kt
index 3f609a25c3fc..338d3ed42f95 100644
--- a/packages/SystemUI/src/com/android/systemui/notetask/NoteTaskInitializer.kt
+++ b/packages/SystemUI/src/com/android/systemui/notetask/NoteTaskInitializer.kt
@@ -23,6 +23,7 @@ import android.os.UserHandle
import android.view.KeyEvent
import android.view.KeyEvent.KEYCODE_N
import android.view.KeyEvent.KEYCODE_STYLUS_BUTTON_TAIL
+import android.view.ViewConfiguration
import com.android.keyguard.KeyguardUpdateMonitor
import com.android.keyguard.KeyguardUpdateMonitorCallback
import com.android.systemui.dagger.qualifiers.Background
@@ -128,15 +129,39 @@ constructor(
controller.updateNoteTaskForCurrentUserAndManagedProfiles()
}
}
-}
-/**
- * Maps a [KeyEvent] to a [NoteTaskEntryPoint]. If the [KeyEvent] does not represent a
- * [NoteTaskEntryPoint], returns null.
- */
-private fun KeyEvent.toNoteTaskEntryPointOrNull(): NoteTaskEntryPoint? =
- when {
- keyCode == KEYCODE_STYLUS_BUTTON_TAIL && action == KeyEvent.ACTION_UP -> TAIL_BUTTON
- keyCode == KEYCODE_N && isMetaPressed && isCtrlPressed -> KEYBOARD_SHORTCUT
- else -> null
+ /**
+ * Tracks a [KeyEvent], and determines if it should trigger an action to show the note task.
+ * Returns a [NoteTaskEntryPoint] if an action should be taken, and null otherwise.
+ */
+ private fun KeyEvent.toNoteTaskEntryPointOrNull(): NoteTaskEntryPoint? =
+ when {
+ keyCode == KEYCODE_STYLUS_BUTTON_TAIL && isTailButtonNotesGesture() -> TAIL_BUTTON
+ keyCode == KEYCODE_N && isMetaPressed && isCtrlPressed -> KEYBOARD_SHORTCUT
+ else -> null
+ }
+
+ private var lastStylusButtonTailUpEventTime: Long = -MULTI_PRESS_TIMEOUT
+
+ /**
+ * Perform gesture detection for the stylus tail button to make sure we only show the note task
+ * when there is a single press. Long presses and multi-presses are ignored for now.
+ */
+ private fun KeyEvent.isTailButtonNotesGesture(): Boolean {
+ if (keyCode != KEYCODE_STYLUS_BUTTON_TAIL || action != KeyEvent.ACTION_UP) {
+ return false
+ }
+
+ val isMultiPress = (downTime - lastStylusButtonTailUpEventTime) < MULTI_PRESS_TIMEOUT
+ val isLongPress = (eventTime - downTime) >= LONG_PRESS_TIMEOUT
+ lastStylusButtonTailUpEventTime = eventTime
+ // For now, trigger action immediately on UP of a single press, without waiting for
+ // the multi-press timeout to expire.
+ return !isMultiPress && !isLongPress
}
+
+ companion object {
+ val MULTI_PRESS_TIMEOUT = ViewConfiguration.getMultiPressTimeout().toLong()
+ val LONG_PRESS_TIMEOUT = ViewConfiguration.getLongPressTimeout().toLong()
+ }
+}
diff --git a/packages/SystemUI/tests/src/com/android/systemui/notetask/NoteTaskInitializerTest.kt b/packages/SystemUI/tests/src/com/android/systemui/notetask/NoteTaskInitializerTest.kt
index 162b7b3d41db..78330078076c 100644
--- a/packages/SystemUI/tests/src/com/android/systemui/notetask/NoteTaskInitializerTest.kt
+++ b/packages/SystemUI/tests/src/com/android/systemui/notetask/NoteTaskInitializerTest.kt
@@ -235,4 +235,42 @@ internal class NoteTaskInitializerTest : SysuiTestCase() {
verify(controller).showNoteTask(any())
}
+
+ @Test
+ fun tailButtonGestureDetection_doublePress_shouldNotShowNoteTaskTwice() {
+ val underTest = createUnderTest(isEnabled = true, bubbles = bubbles)
+ underTest.initialize()
+ val callback = withArgCaptor { verify(commandQueue).addCallback(capture()) }
+
+ callback.handleSystemKey(
+ createKeyEvent(ACTION_DOWN, KEYCODE_STYLUS_BUTTON_TAIL, downTime = 0, eventTime = 0)
+ )
+ callback.handleSystemKey(
+ createKeyEvent(ACTION_UP, KEYCODE_STYLUS_BUTTON_TAIL, downTime = 0, eventTime = 50)
+ )
+ callback.handleSystemKey(
+ createKeyEvent(ACTION_DOWN, KEYCODE_STYLUS_BUTTON_TAIL, downTime = 99, eventTime = 99)
+ )
+ callback.handleSystemKey(
+ createKeyEvent(ACTION_UP, KEYCODE_STYLUS_BUTTON_TAIL, downTime = 99, eventTime = 150)
+ )
+
+ verify(controller, times(1)).showNoteTask(any())
+ }
+
+ @Test
+ fun tailButtonGestureDetection_longPress_shouldNotShowNoteTask() {
+ val underTest = createUnderTest(isEnabled = true, bubbles = bubbles)
+ underTest.initialize()
+ val callback = withArgCaptor { verify(commandQueue).addCallback(capture()) }
+
+ callback.handleSystemKey(
+ createKeyEvent(ACTION_DOWN, KEYCODE_STYLUS_BUTTON_TAIL, downTime = 0, eventTime = 0)
+ )
+ callback.handleSystemKey(
+ createKeyEvent(ACTION_UP, KEYCODE_STYLUS_BUTTON_TAIL, downTime = 0, eventTime = 1000)
+ )
+
+ verify(controller, never()).showNoteTask(any())
+ }
}