Merge "Adding more logs to keyboard/touchpad tutorial" into main
diff --git a/packages/SystemUI/multivalentTests/src/com/android/systemui/inputdevice/tutorial/ui/viewmodel/KeyboardTouchpadTutorialViewModelTest.kt b/packages/SystemUI/multivalentTests/src/com/android/systemui/inputdevice/tutorial/ui/viewmodel/KeyboardTouchpadTutorialViewModelTest.kt
index 0c716137..639737b 100644
--- a/packages/SystemUI/multivalentTests/src/com/android/systemui/inputdevice/tutorial/ui/viewmodel/KeyboardTouchpadTutorialViewModelTest.kt
+++ b/packages/SystemUI/multivalentTests/src/com/android/systemui/inputdevice/tutorial/ui/viewmodel/KeyboardTouchpadTutorialViewModelTest.kt
@@ -25,6 +25,7 @@
import com.android.systemui.SysuiTestCase
import com.android.systemui.coroutines.collectLastValue
import com.android.systemui.coroutines.collectValues
+import com.android.systemui.inputdevice.tutorial.InputDeviceTutorialLogger
import com.android.systemui.inputdevice.tutorial.domain.interactor.KeyboardTouchpadConnectionInteractor
import com.android.systemui.inputdevice.tutorial.ui.view.KeyboardTouchpadTutorialActivity.Companion.INTENT_TUTORIAL_TYPE_KEY
import com.android.systemui.inputdevice.tutorial.ui.view.KeyboardTouchpadTutorialActivity.Companion.INTENT_TUTORIAL_TYPE_KEYBOARD
@@ -53,6 +54,7 @@
import org.junit.Test
import org.junit.runner.RunWith
import org.mockito.Mockito.mock
+import org.mockito.kotlin.mock
@OptIn(ExperimentalCoroutinesApi::class)
@SmallTest
@@ -81,6 +83,7 @@
Optional.of(kosmos.touchpadGesturesInteractor),
KeyboardTouchpadConnectionInteractor(keyboardRepo, touchpadRepo),
hasTouchpadTutorialScreens,
+ mock<InputDeviceTutorialLogger>(),
SavedStateHandle(mapOf(INTENT_TUTORIAL_TYPE_KEY to startingPeripheral))
)
lifecycle.addObserver(viewModel)
diff --git a/packages/SystemUI/src/com/android/systemui/inputdevice/tutorial/InputDeviceTutorialLogger.kt b/packages/SystemUI/src/com/android/systemui/inputdevice/tutorial/InputDeviceTutorialLogger.kt
index 9525174..48f5cb6 100644
--- a/packages/SystemUI/src/com/android/systemui/inputdevice/tutorial/InputDeviceTutorialLogger.kt
+++ b/packages/SystemUI/src/com/android/systemui/inputdevice/tutorial/InputDeviceTutorialLogger.kt
@@ -16,27 +16,27 @@
package com.android.systemui.inputdevice.tutorial
+import com.android.systemui.inputdevice.tutorial.domain.interactor.ConnectionState
+import com.android.systemui.inputdevice.tutorial.ui.viewmodel.Screen as KeyboardTouchpadTutorialScreen
+import com.android.systemui.log.ConstantStringsLogger
+import com.android.systemui.log.ConstantStringsLoggerImpl
import com.android.systemui.log.LogBuffer
import com.android.systemui.log.core.LogLevel
+import com.android.systemui.log.core.MessageInitializer
+import com.android.systemui.log.core.MessagePrinter
import com.android.systemui.log.dagger.InputDeviceTutorialLog
-import com.android.systemui.touchpad.tutorial.ui.viewmodel.Screen
-import com.google.errorprone.annotations.CompileTimeConstant
+import com.android.systemui.touchpad.tutorial.ui.viewmodel.Screen as TouchpadTutorialScreen
import javax.inject.Inject
private const val TAG = "InputDeviceTutorial"
class InputDeviceTutorialLogger
@Inject
-constructor(@InputDeviceTutorialLog private val buffer: LogBuffer) {
+constructor(@InputDeviceTutorialLog private val buffer: LogBuffer) :
+ ConstantStringsLogger by ConstantStringsLoggerImpl(buffer, TAG) {
- fun log(@CompileTimeConstant s: String) {
- buffer.log(TAG, LogLevel.INFO, message = s)
- }
-
- fun logGoingToScreen(screen: Screen, context: TutorialContext) {
- buffer.log(
- TAG,
- LogLevel.INFO,
+ fun logGoingToScreen(screen: TouchpadTutorialScreen, context: TutorialContext) {
+ logInfo(
{
str1 = screen.toString()
str2 = context.string
@@ -46,7 +46,58 @@
}
fun logCloseTutorial(context: TutorialContext) {
- buffer.log(TAG, LogLevel.INFO, { str1 = context.string }, { "Closing $str1" })
+ logInfo({ str1 = context.string }, { "Closing $str1" })
+ }
+
+ fun logOpenTutorial(context: TutorialContext) {
+ logInfo({ str1 = context.string }, { "Opening $str1" })
+ }
+
+ fun logNextScreenMissingHardware(nextScreen: KeyboardTouchpadTutorialScreen) {
+ buffer.log(
+ TAG,
+ LogLevel.WARNING,
+ { str1 = nextScreen.toString() },
+ { "next screen should be $str1 but required hardware is missing" }
+ )
+ }
+
+ fun logNextScreen(nextScreen: KeyboardTouchpadTutorialScreen) {
+ logInfo({ str1 = nextScreen.toString() }, { "going to $str1 screen" })
+ }
+
+ fun logNewConnectionState(connectionState: ConnectionState) {
+ logInfo(
+ {
+ bool1 = connectionState.touchpadConnected
+ bool2 = connectionState.keyboardConnected
+ },
+ { "Received connection state: touchpad connected: $bool1 keyboard connected: $bool2" }
+ )
+ }
+
+ fun logMovingBetweenScreens(
+ previousScreen: KeyboardTouchpadTutorialScreen?,
+ currentScreen: KeyboardTouchpadTutorialScreen
+ ) {
+ logInfo(
+ {
+ str1 = previousScreen?.toString() ?: "NO_SCREEN"
+ str2 = currentScreen.toString()
+ },
+ { "Moving from $str1 screen to $str2 screen" }
+ )
+ }
+
+ fun logGoingBack(previousScreen: KeyboardTouchpadTutorialScreen) {
+ logInfo({ str1 = previousScreen.toString() }, { "Going back to $str1 screen" })
+ }
+
+ private inline fun logInfo(
+ messageInitializer: MessageInitializer,
+ noinline messagePrinter: MessagePrinter
+ ) {
+ buffer.log(TAG, LogLevel.INFO, messageInitializer, messagePrinter)
}
enum class TutorialContext(val string: String) {
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 1adc285..c130c6c 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
@@ -28,6 +28,8 @@
import androidx.lifecycle.compose.collectAsStateWithLifecycle
import androidx.lifecycle.lifecycleScope
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.TouchpadTutorialScreensProvider
import com.android.systemui.inputdevice.tutorial.ui.composable.ActionKeyTutorialScreen
import com.android.systemui.inputdevice.tutorial.ui.viewmodel.KeyboardTouchpadTutorialViewModel
@@ -48,6 +50,7 @@
constructor(
private val viewModelFactoryAssistedProvider: ViewModelFactoryAssistedProvider,
private val touchpadTutorialScreensProvider: Optional<TouchpadTutorialScreensProvider>,
+ private val logger: InputDeviceTutorialLogger,
) : ComponentActivity() {
companion object {
@@ -74,6 +77,7 @@
lifecycleScope.launch {
vm.closeActivity.collect { finish ->
if (finish) {
+ logger.logCloseTutorial(TutorialContext.KEYBOARD_TOUCHPAD_TUTORIAL)
finish()
}
}
@@ -81,6 +85,9 @@
setContent {
PlatformTheme { KeyboardTouchpadTutorialContainer(vm, touchpadTutorialScreensProvider) }
}
+ if (savedInstanceState == null) {
+ logger.logOpenTutorial(TutorialContext.KEYBOARD_TOUCHPAD_TUTORIAL)
+ }
}
}
diff --git a/packages/SystemUI/src/com/android/systemui/inputdevice/tutorial/ui/viewmodel/KeyboardTouchpadTutorialViewModel.kt b/packages/SystemUI/src/com/android/systemui/inputdevice/tutorial/ui/viewmodel/KeyboardTouchpadTutorialViewModel.kt
index 315c102..5cf1967 100644
--- a/packages/SystemUI/src/com/android/systemui/inputdevice/tutorial/ui/viewmodel/KeyboardTouchpadTutorialViewModel.kt
+++ b/packages/SystemUI/src/com/android/systemui/inputdevice/tutorial/ui/viewmodel/KeyboardTouchpadTutorialViewModel.kt
@@ -22,6 +22,7 @@
import androidx.lifecycle.SavedStateHandle
import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
+import com.android.systemui.inputdevice.tutorial.InputDeviceTutorialLogger
import com.android.systemui.inputdevice.tutorial.domain.interactor.ConnectionState
import com.android.systemui.inputdevice.tutorial.domain.interactor.KeyboardTouchpadConnectionInteractor
import com.android.systemui.inputdevice.tutorial.ui.view.KeyboardTouchpadTutorialActivity.Companion.INTENT_TUTORIAL_TYPE_KEY
@@ -47,6 +48,7 @@
private val gesturesInteractor: Optional<TouchpadGesturesInteractor>,
private val keyboardTouchpadConnectionInteractor: KeyboardTouchpadConnectionInteractor,
private val hasTouchpadTutorialScreens: Boolean,
+ private val logger: InputDeviceTutorialLogger,
handle: SavedStateHandle
) : ViewModel(), DefaultLifecycleObserver {
@@ -68,7 +70,10 @@
init {
viewModelScope.launch {
- keyboardTouchpadConnectionInteractor.connectionState.collect { connectionState = it }
+ keyboardTouchpadConnectionInteractor.connectionState.collect {
+ logger.logNewConnectionState(connectionState)
+ connectionState = it
+ }
}
viewModelScope.launch {
@@ -89,7 +94,14 @@
viewModelScope.launch {
// close activity if screen requires touchpad but we don't have it. This can only happen
// when current sysui build doesn't contain touchpad module dependency
- _screen.filterNot { it.canBeShown() }.collect { _closeActivity.value = true }
+ _screen
+ .filterNot { it.canBeShown() }
+ .collect {
+ logger.e(
+ "Touchpad is connected but touchpad module is missing, something went wrong"
+ )
+ _closeActivity.value = true
+ }
}
}
@@ -114,11 +126,14 @@
if (requiredHardwarePresent(nextScreen)) {
break
}
+ logger.logNextScreenMissingHardware(nextScreen)
nextScreen = nextScreen.next()
}
if (nextScreen == null) {
+ logger.d("Final screen reached, closing tutorial")
_closeActivity.value = true
} else {
+ logger.logNextScreen(nextScreen)
_screen.value = nextScreen
screensBackStack.add(nextScreen)
}
@@ -127,6 +142,7 @@
private fun Screen.canBeShown() = requiredHardware != TOUCHPAD || hasTouchpadTutorialScreens
private fun setupDeviceState(previousScreen: Screen?, currentScreen: Screen) {
+ logger.logMovingBetweenScreens(previousScreen, currentScreen)
if (previousScreen?.requiredHardware == currentScreen.requiredHardware) return
previousScreen?.let { clearDeviceStateForScreen(it) }
when (currentScreen.requiredHardware) {
@@ -153,6 +169,7 @@
_closeActivity.value = true
} else {
screensBackStack.removeLast()
+ logger.logGoingBack(screensBackStack.last())
_screen.value = screensBackStack.last()
}
}
@@ -162,6 +179,7 @@
constructor(
private val gesturesInteractor: Optional<TouchpadGesturesInteractor>,
private val keyboardTouchpadConnected: KeyboardTouchpadConnectionInteractor,
+ private val logger: InputDeviceTutorialLogger,
@Assisted private val hasTouchpadTutorialScreens: Boolean,
) : AbstractSavedStateViewModelFactory() {
@@ -180,6 +198,7 @@
gesturesInteractor,
keyboardTouchpadConnected,
hasTouchpadTutorialScreens,
+ logger,
handle
)
as T
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 1a41987..80ea925 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
@@ -30,12 +30,12 @@
private val logger: InputDeviceTutorialLogger,
) {
fun disableGestures() {
- logger.log("Disabling touchpad gestures across the system")
+ logger.d("Disabling touchpad gestures across the system")
setGesturesState(disabled = true)
}
fun enableGestures() {
- logger.log("Enabling touchpad gestures across the system")
+ logger.d("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 6fe6547..d03b2e7 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)
+ logger.logOpenTutorial(TutorialContext.TOUCHPAD_TUTORIAL)
}
private fun finishTutorial() {