Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 9469611f authored by Michał Brzeziński's avatar Michał Brzeziński
Browse files

Adding more logs to keyboard/touchpad tutorial

Bug: 360873976
Test: just adding logs
Flag: com.android.systemui.shared.new_touchpad_gestures_tutorial
Change-Id: Ifd2d11d4245d14dbd64aa1ef01caa52af6a1064f
parent 5c90d2f7
Loading
Loading
Loading
Loading
+3 −0
Original line number Diff line number Diff line
@@ -25,6 +25,7 @@ import androidx.test.filters.SmallTest
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.Rule
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 @@ class KeyboardTouchpadTutorialViewModelTest : SysuiTestCase() {
                Optional.of(kosmos.touchpadGesturesInteractor),
                KeyboardTouchpadConnectionInteractor(keyboardRepo, touchpadRepo),
                hasTouchpadTutorialScreens,
                mock<InputDeviceTutorialLogger>(),
                SavedStateHandle(mapOf(INTENT_TUTORIAL_TYPE_KEY to startingPeripheral))
            )
        lifecycle.addObserver(viewModel)
+63 −12
Original line number Diff line number Diff line
@@ -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 @@ constructor(@InputDeviceTutorialLog private val buffer: LogBuffer) {
    }

    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) {
+7 −0
Original line number Diff line number Diff line
@@ -28,6 +28,8 @@ import androidx.lifecycle.Lifecycle.State.STARTED
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 @@ class KeyboardTouchpadTutorialActivity
constructor(
    private val viewModelFactoryAssistedProvider: ViewModelFactoryAssistedProvider,
    private val touchpadTutorialScreensProvider: Optional<TouchpadTutorialScreensProvider>,
    private val logger: InputDeviceTutorialLogger,
) : ComponentActivity() {

    companion object {
@@ -74,6 +77,7 @@ constructor(
        lifecycleScope.launch {
            vm.closeActivity.collect { finish ->
                if (finish) {
                    logger.logCloseTutorial(TutorialContext.KEYBOARD_TOUCHPAD_TUTORIAL)
                    finish()
                }
            }
@@ -81,6 +85,9 @@ constructor(
        setContent {
            PlatformTheme { KeyboardTouchpadTutorialContainer(vm, touchpadTutorialScreensProvider) }
        }
        if (savedInstanceState == null) {
            logger.logOpenTutorial(TutorialContext.KEYBOARD_TOUCHPAD_TUTORIAL)
        }
    }
}

+21 −2
Original line number Diff line number Diff line
@@ -22,6 +22,7 @@ import androidx.lifecycle.LifecycleOwner
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 @@ class KeyboardTouchpadTutorialViewModel(
    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 @@ class KeyboardTouchpadTutorialViewModel(

    init {
        viewModelScope.launch {
            keyboardTouchpadConnectionInteractor.connectionState.collect { connectionState = it }
            keyboardTouchpadConnectionInteractor.connectionState.collect {
                logger.logNewConnectionState(connectionState)
                connectionState = it
            }
        }

        viewModelScope.launch {
@@ -89,7 +94,14 @@ class KeyboardTouchpadTutorialViewModel(
        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 @@ class KeyboardTouchpadTutorialViewModel(
            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 @@ class KeyboardTouchpadTutorialViewModel(
    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 @@ class KeyboardTouchpadTutorialViewModel(
            _closeActivity.value = true
        } else {
            screensBackStack.removeLast()
            logger.logGoingBack(screensBackStack.last())
            _screen.value = screensBackStack.last()
        }
    }
@@ -162,6 +179,7 @@ class KeyboardTouchpadTutorialViewModel(
    constructor(
        private val gesturesInteractor: Optional<TouchpadGesturesInteractor>,
        private val keyboardTouchpadConnected: KeyboardTouchpadConnectionInteractor,
        private val logger: InputDeviceTutorialLogger,
        @Assisted private val hasTouchpadTutorialScreens: Boolean,
    ) : AbstractSavedStateViewModelFactory() {

@@ -180,6 +198,7 @@ class KeyboardTouchpadTutorialViewModel(
                gesturesInteractor,
                keyboardTouchpadConnected,
                hasTouchpadTutorialScreens,
                logger,
                handle
            )
                as T
+2 −2
Original line number Diff line number Diff line
@@ -30,12 +30,12 @@ class TouchpadGesturesInteractor(
    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)
    }

Loading