diff options
| author | 2024-08-20 19:32:25 +0000 | |
|---|---|---|
| committer | 2024-08-20 19:32:25 +0000 | |
| commit | 62c19ce14f56a068da6dca9737379e24a19c207a (patch) | |
| tree | 1143feb2b3a23343948da557226e2538be5cbc5c | |
| parent | 9302f8498f204d4e9cb098bd749cab778447af70 (diff) | |
| parent | 297e47923c501bd4063361aaa81a26aa242a1372 (diff) | |
Merge changes Ifc4e989b,I51bda79d into main
* changes:
Tutorial correctly handling META key event
Adding logger for touchpad and keyboard tutorials
12 files changed, 182 insertions, 17 deletions
diff --git a/packages/SystemUI/src/com/android/systemui/inputdevice/tutorial/InputDeviceTutorialLogger.kt b/packages/SystemUI/src/com/android/systemui/inputdevice/tutorial/InputDeviceTutorialLogger.kt new file mode 100644 index 000000000000..95251749132d --- /dev/null +++ b/packages/SystemUI/src/com/android/systemui/inputdevice/tutorial/InputDeviceTutorialLogger.kt @@ -0,0 +1,56 @@ +/* + * Copyright (C) 2024 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.inputdevice.tutorial + +import com.android.systemui.log.LogBuffer +import com.android.systemui.log.core.LogLevel +import com.android.systemui.log.dagger.InputDeviceTutorialLog +import com.android.systemui.touchpad.tutorial.ui.viewmodel.Screen +import com.google.errorprone.annotations.CompileTimeConstant +import javax.inject.Inject + +private const val TAG = "InputDeviceTutorial" + +class InputDeviceTutorialLogger +@Inject +constructor(@InputDeviceTutorialLog private val buffer: LogBuffer) { + + fun log(@CompileTimeConstant s: String) { + buffer.log(TAG, LogLevel.INFO, message = s) + } + + fun logGoingToScreen(screen: Screen, context: TutorialContext) { + buffer.log( + TAG, + LogLevel.INFO, + { + str1 = screen.toString() + str2 = context.string + }, + { "Emitting new screen $str1 in $str2" } + ) + } + + fun logCloseTutorial(context: TutorialContext) { + buffer.log(TAG, LogLevel.INFO, { str1 = context.string }, { "Closing $str1" }) + } + + enum class TutorialContext(val string: String) { + KEYBOARD_TOUCHPAD_TUTORIAL("keyboard touchpad tutorial"), + TOUCHPAD_TUTORIAL("touchpad tutorial"), + } +} 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 c5b0ca78d65a..6bc640d4d1f4 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 @@ fun ActionKeyTutorialScreen( 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 34ecc9518e83..8debe7975197 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 @@ constructor( 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/log/dagger/InputDeviceTutorialLog.kt b/packages/SystemUI/src/com/android/systemui/log/dagger/InputDeviceTutorialLog.kt new file mode 100644 index 000000000000..a788279a579f --- /dev/null +++ b/packages/SystemUI/src/com/android/systemui/log/dagger/InputDeviceTutorialLog.kt @@ -0,0 +1,25 @@ +/* + * Copyright (C) 2024 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.log.dagger + +import javax.inject.Qualifier + +/** A [com.android.systemui.log.LogBuffer] for input device tutorial. */ +@Qualifier +@MustBeDocumented +@Retention(AnnotationRetention.RUNTIME) +annotation class InputDeviceTutorialLog diff --git a/packages/SystemUI/src/com/android/systemui/log/dagger/LogModule.java b/packages/SystemUI/src/com/android/systemui/log/dagger/LogModule.java index 40bb8e1978b8..5cae58a81cf9 100644 --- a/packages/SystemUI/src/com/android/systemui/log/dagger/LogModule.java +++ b/packages/SystemUI/src/com/android/systemui/log/dagger/LogModule.java @@ -660,6 +660,14 @@ public class LogModule { return factory.create("KeyboardLog", 50); } + /** Provides a {@link LogBuffer} for the input devices tutorial. */ + @Provides + @SysUISingleton + @InputDeviceTutorialLog + public static LogBuffer provideInputDeviceTutorialLogBuffer(LogBufferFactory factory) { + return factory.create("InputDeviceTutorialLog", 50); + } + /** Provides a {@link LogBuffer} for {@link PackageChangeRepository} */ @Provides @SysUISingleton diff --git a/packages/SystemUI/src/com/android/systemui/touchpad/tutorial/TouchpadTutorialModule.kt b/packages/SystemUI/src/com/android/systemui/touchpad/tutorial/TouchpadTutorialModule.kt index 238e8a1c01ad..3fa3f638a340 100644 --- a/packages/SystemUI/src/com/android/systemui/touchpad/tutorial/TouchpadTutorialModule.kt +++ b/packages/SystemUI/src/com/android/systemui/touchpad/tutorial/TouchpadTutorialModule.kt @@ -20,6 +20,7 @@ import android.app.Activity import androidx.compose.runtime.Composable import com.android.systemui.dagger.SysUISingleton import com.android.systemui.dagger.qualifiers.Background +import com.android.systemui.inputdevice.tutorial.InputDeviceTutorialLogger import com.android.systemui.inputdevice.tutorial.TouchpadTutorialScreensProvider import com.android.systemui.model.SysUiState import com.android.systemui.settings.DisplayTracker @@ -53,9 +54,10 @@ interface TouchpadTutorialModule { fun touchpadGesturesInteractor( sysUiState: SysUiState, displayTracker: DisplayTracker, - @Background backgroundScope: CoroutineScope + @Background backgroundScope: CoroutineScope, + logger: InputDeviceTutorialLogger, ): TouchpadGesturesInteractor { - return TouchpadGesturesInteractor(sysUiState, displayTracker, backgroundScope) + return TouchpadGesturesInteractor(sysUiState, displayTracker, backgroundScope, logger) } } } diff --git a/packages/SystemUI/src/com/android/systemui/touchpad/tutorial/domain/interactor/TouchpadGesturesInteractor.kt b/packages/SystemUI/src/com/android/systemui/touchpad/tutorial/domain/interactor/TouchpadGesturesInteractor.kt index df95232758a4..1a41987a8e5b 100644 --- a/packages/SystemUI/src/com/android/systemui/touchpad/tutorial/domain/interactor/TouchpadGesturesInteractor.kt +++ b/packages/SystemUI/src/com/android/systemui/touchpad/tutorial/domain/interactor/TouchpadGesturesInteractor.kt @@ -16,6 +16,7 @@ package com.android.systemui.touchpad.tutorial.domain.interactor +import com.android.systemui.inputdevice.tutorial.InputDeviceTutorialLogger import com.android.systemui.model.SysUiState import com.android.systemui.settings.DisplayTracker import com.android.systemui.shared.system.QuickStepContract @@ -25,13 +26,16 @@ import kotlinx.coroutines.launch class TouchpadGesturesInteractor( private val sysUiState: SysUiState, private val displayTracker: DisplayTracker, - private val backgroundScope: CoroutineScope + private val backgroundScope: CoroutineScope, + private val logger: InputDeviceTutorialLogger, ) { fun disableGestures() { + logger.log("Disabling touchpad gestures across the system") setGesturesState(disabled = true) } fun enableGestures() { + logger.log("Enabling touchpad gestures across the system") setGesturesState(disabled = false) } 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 256c5b590b14..821b51a18a8e 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 @@ -27,6 +27,8 @@ import androidx.compose.runtime.getValue import androidx.lifecycle.Lifecycle.State.STARTED import androidx.lifecycle.compose.collectAsStateWithLifecycle import com.android.compose.theme.PlatformTheme +import com.android.systemui.inputdevice.tutorial.InputDeviceTutorialLogger +import com.android.systemui.inputdevice.tutorial.InputDeviceTutorialLogger.TutorialContext import com.android.systemui.inputdevice.tutorial.ui.composable.ActionKeyTutorialScreen import com.android.systemui.touchpad.tutorial.ui.composable.BackGestureTutorialScreen import com.android.systemui.touchpad.tutorial.ui.composable.HomeGestureTutorialScreen @@ -42,6 +44,7 @@ class TouchpadTutorialActivity @Inject constructor( private val viewModelFactory: TouchpadTutorialViewModel.Factory, + private val logger: InputDeviceTutorialLogger, ) : ComponentActivity() { private val vm by viewModels<TouchpadTutorialViewModel>(factoryProducer = { viewModelFactory }) @@ -49,9 +52,17 @@ constructor( override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) enableEdgeToEdge() - setContent { PlatformTheme { TouchpadTutorialScreen(vm) { finish() } } } + setContent { + PlatformTheme { TouchpadTutorialScreen(vm, closeTutorial = ::finishTutorial) } + } // 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() { + logger.logCloseTutorial(TutorialContext.TOUCHPAD_TUTORIAL) + finish() } override fun onResume() { diff --git a/packages/SystemUI/src/com/android/systemui/touchpad/tutorial/ui/viewmodel/TouchpadTutorialViewModel.kt b/packages/SystemUI/src/com/android/systemui/touchpad/tutorial/ui/viewmodel/TouchpadTutorialViewModel.kt index d3aeaa7e3dca..43266ad8da76 100644 --- a/packages/SystemUI/src/com/android/systemui/touchpad/tutorial/ui/viewmodel/TouchpadTutorialViewModel.kt +++ b/packages/SystemUI/src/com/android/systemui/touchpad/tutorial/ui/viewmodel/TouchpadTutorialViewModel.kt @@ -18,18 +18,23 @@ package com.android.systemui.touchpad.tutorial.ui.viewmodel import androidx.lifecycle.ViewModel import androidx.lifecycle.ViewModelProvider +import com.android.systemui.inputdevice.tutorial.InputDeviceTutorialLogger +import com.android.systemui.inputdevice.tutorial.InputDeviceTutorialLogger.TutorialContext import com.android.systemui.touchpad.tutorial.domain.interactor.TouchpadGesturesInteractor import javax.inject.Inject import kotlinx.coroutines.flow.MutableStateFlow import kotlinx.coroutines.flow.StateFlow -class TouchpadTutorialViewModel(private val gesturesInteractor: TouchpadGesturesInteractor) : - ViewModel() { +class TouchpadTutorialViewModel( + private val gesturesInteractor: TouchpadGesturesInteractor, + private val logger: InputDeviceTutorialLogger +) : ViewModel() { private val _screen = MutableStateFlow(Screen.TUTORIAL_SELECTION) val screen: StateFlow<Screen> = _screen fun goTo(screen: Screen) { + logger.logGoingToScreen(screen, TutorialContext.TOUCHPAD_TUTORIAL) _screen.value = screen } @@ -41,12 +46,16 @@ class TouchpadTutorialViewModel(private val gesturesInteractor: TouchpadGestures gesturesInteractor.enableGestures() } - class Factory @Inject constructor(private val gesturesInteractor: TouchpadGesturesInteractor) : - ViewModelProvider.Factory { + class Factory + @Inject + constructor( + private val gesturesInteractor: TouchpadGesturesInteractor, + private val logger: InputDeviceTutorialLogger + ) : ViewModelProvider.Factory { @Suppress("UNCHECKED_CAST") override fun <T : ViewModel> create(modelClass: Class<T>): T { - return TouchpadTutorialViewModel(gesturesInteractor) as T + return TouchpadTutorialViewModel(gesturesInteractor, logger) as T } } } diff --git a/packages/SystemUI/tests/src/com/android/systemui/touchpad/tutorial/ui/viewmodel/TouchpadTutorialViewModelTest.kt b/packages/SystemUI/tests/src/com/android/systemui/touchpad/tutorial/ui/viewmodel/TouchpadTutorialViewModelTest.kt index c705cea2beff..89e88958caa9 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/touchpad/tutorial/ui/viewmodel/TouchpadTutorialViewModelTest.kt +++ b/packages/SystemUI/tests/src/com/android/systemui/touchpad/tutorial/ui/viewmodel/TouchpadTutorialViewModelTest.kt @@ -19,6 +19,7 @@ package com.android.systemui.touchpad.tutorial.ui.viewmodel import androidx.test.ext.junit.runners.AndroidJUnit4 import androidx.test.filters.SmallTest import com.android.systemui.SysuiTestCase +import com.android.systemui.inputdevice.tutorial.inputDeviceTutorialLogger import com.android.systemui.model.sysUiState import com.android.systemui.settings.displayTracker import com.android.systemui.shared.system.QuickStepContract.SYSUI_STATE_TOUCHPAD_GESTURES_DISABLED @@ -41,7 +42,13 @@ class TouchpadTutorialViewModelTest : SysuiTestCase() { private val sysUiState = kosmos.sysUiState private val viewModel = TouchpadTutorialViewModel( - TouchpadGesturesInteractor(sysUiState, kosmos.displayTracker, testScope.backgroundScope) + TouchpadGesturesInteractor( + sysUiState, + kosmos.displayTracker, + testScope.backgroundScope, + kosmos.inputDeviceTutorialLogger + ), + kosmos.inputDeviceTutorialLogger ) @Test diff --git a/packages/SystemUI/tests/utils/src/com/android/systemui/inputdevice/tutorial/InputDeviceTutorialKosmos.kt b/packages/SystemUI/tests/utils/src/com/android/systemui/inputdevice/tutorial/InputDeviceTutorialKosmos.kt new file mode 100644 index 000000000000..827f0d277d11 --- /dev/null +++ b/packages/SystemUI/tests/utils/src/com/android/systemui/inputdevice/tutorial/InputDeviceTutorialKosmos.kt @@ -0,0 +1,23 @@ +/* + * Copyright (C) 2024 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.inputdevice.tutorial + +import com.android.systemui.kosmos.Kosmos +import org.mockito.kotlin.mock + +var Kosmos.inputDeviceTutorialLogger: InputDeviceTutorialLogger by + Kosmos.Fixture { mock<InputDeviceTutorialLogger>() } diff --git a/packages/SystemUI/tests/utils/src/com/android/systemui/touchpad/tutorial/TouchpadTutorialKosmos.kt b/packages/SystemUI/tests/utils/src/com/android/systemui/touchpad/tutorial/TouchpadTutorialKosmos.kt index f502df0b4075..ee9a4d24c927 100644 --- a/packages/SystemUI/tests/utils/src/com/android/systemui/touchpad/tutorial/TouchpadTutorialKosmos.kt +++ b/packages/SystemUI/tests/utils/src/com/android/systemui/touchpad/tutorial/TouchpadTutorialKosmos.kt @@ -16,6 +16,7 @@ package com.android.systemui.touchpad.tutorial +import com.android.systemui.inputdevice.tutorial.inputDeviceTutorialLogger import com.android.systemui.kosmos.Kosmos import com.android.systemui.kosmos.testScope import com.android.systemui.model.sysUiState @@ -24,5 +25,10 @@ import com.android.systemui.touchpad.tutorial.domain.interactor.TouchpadGestures var Kosmos.touchpadGesturesInteractor: TouchpadGesturesInteractor by Kosmos.Fixture { - TouchpadGesturesInteractor(sysUiState, displayTracker, testScope.backgroundScope) + TouchpadGesturesInteractor( + sysUiState, + displayTracker, + testScope.backgroundScope, + inputDeviceTutorialLogger + ) } |