Tutorial correctly handling META key event
Removing previous workaround where ALT key was needed to be pressed.
Also fixing the bug when you have to press non-modifier button first and only after that modifier key is intercepted by our view.
Bug: 358587037
Flag: com.android.systemui.shared.new_touchpad_gestures_tutorial
Test: open keyboard tutorial and use Meta/Action key to finish it!
Change-Id: Ifc4e989b54650bd0ee239b48c248fde90c76a3c6
diff --git a/packages/SystemUI/src/com/android/systemui/inputdevice/tutorial/ui/composable/ActionKeyTutorialScreen.kt b/packages/SystemUI/src/com/android/systemui/inputdevice/tutorial/ui/composable/ActionKeyTutorialScreen.kt
index c5b0ca7..6bc640d 100644
--- a/packages/SystemUI/src/com/android/systemui/inputdevice/tutorial/ui/composable/ActionKeyTutorialScreen.kt
+++ b/packages/SystemUI/src/com/android/systemui/inputdevice/tutorial/ui/composable/ActionKeyTutorialScreen.kt
@@ -17,15 +17,19 @@
package com.android.systemui.inputdevice.tutorial.ui.composable
import androidx.activity.compose.BackHandler
+import androidx.compose.foundation.focusable
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.material3.MaterialTheme
import androidx.compose.runtime.Composable
+import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.Modifier
+import androidx.compose.ui.focus.FocusRequester
+import androidx.compose.ui.focus.focusRequester
import androidx.compose.ui.input.key.Key
import androidx.compose.ui.input.key.KeyEvent
import androidx.compose.ui.input.key.KeyEventType
@@ -46,18 +50,27 @@
BackHandler(onBack = onBack)
val screenConfig = buildScreenConfig()
var actionState by remember { mutableStateOf(NOT_STARTED) }
+ val focusRequester = remember { FocusRequester() }
Box(
modifier =
- Modifier.fillMaxSize().onKeyEvent { keyEvent: KeyEvent ->
- // temporary before we can access Action/Meta key
- if (keyEvent.key == Key.AltLeft && keyEvent.type == KeyEventType.KeyUp) {
- actionState = FINISHED
+ Modifier.fillMaxSize()
+ .onKeyEvent { keyEvent: KeyEvent ->
+ if (keyEvent.key == Key.MetaLeft && keyEvent.type == KeyEventType.KeyUp) {
+ actionState = FINISHED
+ }
+ true
}
- true
- }
+ .focusRequester(focusRequester)
+ .focusable()
) {
ActionTutorialContent(actionState, onDoneButtonClicked, screenConfig)
}
+ LaunchedEffect(Unit) {
+ // we need to request focus on main container so it can handle all key events immediately
+ // when it's open. Otherwise user needs to press non-modifier key before modifier key can
+ // be handled as nothing is focused
+ focusRequester.requestFocus()
+ }
}
@Composable
diff --git a/packages/SystemUI/src/com/android/systemui/inputdevice/tutorial/ui/view/KeyboardTouchpadTutorialActivity.kt b/packages/SystemUI/src/com/android/systemui/inputdevice/tutorial/ui/view/KeyboardTouchpadTutorialActivity.kt
index 34ecc95..8debe79 100644
--- a/packages/SystemUI/src/com/android/systemui/inputdevice/tutorial/ui/view/KeyboardTouchpadTutorialActivity.kt
+++ b/packages/SystemUI/src/com/android/systemui/inputdevice/tutorial/ui/view/KeyboardTouchpadTutorialActivity.kt
@@ -68,6 +68,7 @@
enableEdgeToEdge()
// required to handle 3+ fingers on touchpad
window.addPrivateFlags(WindowManager.LayoutParams.PRIVATE_FLAG_TRUSTED_OVERLAY)
+ window.addPrivateFlags(WindowManager.LayoutParams.PRIVATE_FLAG_ALLOW_ACTION_KEY_EVENTS)
lifecycle.addObserver(vm)
lifecycleScope.launch {
vm.closeActivity.collect { finish ->
diff --git a/packages/SystemUI/src/com/android/systemui/touchpad/tutorial/ui/view/TouchpadTutorialActivity.kt b/packages/SystemUI/src/com/android/systemui/touchpad/tutorial/ui/view/TouchpadTutorialActivity.kt
index bb6c7f2..821b51a 100644
--- a/packages/SystemUI/src/com/android/systemui/touchpad/tutorial/ui/view/TouchpadTutorialActivity.kt
+++ b/packages/SystemUI/src/com/android/systemui/touchpad/tutorial/ui/view/TouchpadTutorialActivity.kt
@@ -57,6 +57,7 @@
}
// required to handle 3+ fingers on touchpad
window.addPrivateFlags(WindowManager.LayoutParams.PRIVATE_FLAG_TRUSTED_OVERLAY)
+ window.addPrivateFlags(WindowManager.LayoutParams.PRIVATE_FLAG_ALLOW_ACTION_KEY_EVENTS)
}
private fun finishTutorial() {