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

Commit 0940e629 authored by yyalan's avatar yyalan
Browse files

Add logs to TutorialSchedulerInteractor

Bug: 360873976
Flag: com.android.systemui.shared.new_touchpad_gestures_tutorial
Test: logcat
Change-Id: I27c03db9100937d97c84391a8789507089b261a4
parent fc76d6cc
Loading
Loading
Loading
Loading
+12 −6
Original line number Diff line number Diff line
@@ -23,6 +23,7 @@ import androidx.test.ext.junit.runners.AndroidJUnit4
import androidx.test.filters.SmallTest
import com.android.systemui.SysuiTestCase
import com.android.systemui.inputdevice.tutorial.data.repository.TutorialSchedulerRepository
import com.android.systemui.inputdevice.tutorial.inputDeviceTutorialLogger
import com.android.systemui.inputdevice.tutorial.ui.TutorialNotificationCoordinator
import com.android.systemui.keyboard.data.repository.FakeKeyboardRepository
import com.android.systemui.kosmos.Kosmos
@@ -75,16 +76,21 @@ class TutorialNotificationCoordinatorTest : SysuiTestCase() {
            TutorialSchedulerRepository(
                context,
                dataStoreScope,
                dataStoreName = "TutorialNotificationCoordinatorTest"
                dataStoreName = "TutorialNotificationCoordinatorTest",
            )
        val interactor =
            TutorialSchedulerInteractor(keyboardRepository, touchpadRepository, repository)
            TutorialSchedulerInteractor(
                keyboardRepository,
                touchpadRepository,
                repository,
                kosmos.inputDeviceTutorialLogger,
            )
        underTest =
            TutorialNotificationCoordinator(
                testScope.backgroundScope,
                context,
                interactor,
                notificationManager
                notificationManager,
            )
        notificationCaptor = ArgumentCaptor.forClass(Notification::class.java)
        underTest.start()
@@ -103,7 +109,7 @@ class TutorialNotificationCoordinatorTest : SysuiTestCase() {
            advanceTimeBy(LAUNCH_DELAY)
            verifyNotification(
                R.string.launch_keyboard_tutorial_notification_title,
                R.string.launch_keyboard_tutorial_notification_content
                R.string.launch_keyboard_tutorial_notification_content,
            )
        }

@@ -114,7 +120,7 @@ class TutorialNotificationCoordinatorTest : SysuiTestCase() {
            advanceTimeBy(LAUNCH_DELAY)
            verifyNotification(
                R.string.launch_touchpad_tutorial_notification_title,
                R.string.launch_touchpad_tutorial_notification_content
                R.string.launch_touchpad_tutorial_notification_content,
            )
        }

@@ -126,7 +132,7 @@ class TutorialNotificationCoordinatorTest : SysuiTestCase() {
            advanceTimeBy(LAUNCH_DELAY)
            verifyNotification(
                R.string.launch_keyboard_touchpad_tutorial_notification_title,
                R.string.launch_keyboard_touchpad_tutorial_notification_content
                R.string.launch_keyboard_touchpad_tutorial_notification_content,
            )
        }

+8 −2
Original line number Diff line number Diff line
@@ -22,6 +22,7 @@ import com.android.systemui.SysuiTestCase
import com.android.systemui.inputdevice.tutorial.data.repository.DeviceType
import com.android.systemui.inputdevice.tutorial.data.repository.TutorialSchedulerRepository
import com.android.systemui.inputdevice.tutorial.domain.interactor.TutorialSchedulerInteractor.TutorialType
import com.android.systemui.inputdevice.tutorial.inputDeviceTutorialLogger
import com.android.systemui.keyboard.data.repository.FakeKeyboardRepository
import com.android.systemui.kosmos.Kosmos
import com.android.systemui.kosmos.testScope
@@ -62,10 +63,15 @@ class TutorialSchedulerInteractorTest : SysuiTestCase() {
            TutorialSchedulerRepository(
                context,
                dataStoreScope,
                dataStoreName = "TutorialSchedulerInteractorTest"
                dataStoreName = "TutorialSchedulerInteractorTest",
            )
        underTest =
            TutorialSchedulerInteractor(keyboardRepository, touchpadRepository, schedulerRepository)
            TutorialSchedulerInteractor(
                keyboardRepository,
                touchpadRepository,
                schedulerRepository,
                kosmos.inputDeviceTutorialLogger,
            )
    }

    @After
+16 −6
Original line number Diff line number Diff line
@@ -16,7 +16,9 @@

package com.android.systemui.inputdevice.tutorial

import com.android.systemui.inputdevice.tutorial.data.repository.DeviceType
import com.android.systemui.inputdevice.tutorial.domain.interactor.ConnectionState
import com.android.systemui.inputdevice.tutorial.domain.interactor.TutorialSchedulerInteractor.TutorialType
import com.android.systemui.inputdevice.tutorial.ui.viewmodel.Screen as KeyboardTouchpadTutorialScreen
import com.android.systemui.log.ConstantStringsLogger
import com.android.systemui.log.ConstantStringsLoggerImpl
@@ -41,7 +43,7 @@ constructor(@InputDeviceTutorialLog private val buffer: LogBuffer) :
                str1 = screen.toString()
                str2 = context.string
            },
            { "Emitting new screen $str1 in $str2" }
            { "Emitting new screen $str1 in $str2" },
        )
    }

@@ -58,7 +60,7 @@ constructor(@InputDeviceTutorialLog private val buffer: LogBuffer) :
            TAG,
            LogLevel.WARNING,
            { str1 = nextScreen.toString() },
            { "next screen should be $str1 but required hardware is missing" }
            { "next screen should be $str1 but required hardware is missing" },
        )
    }

@@ -72,20 +74,20 @@ constructor(@InputDeviceTutorialLog private val buffer: LogBuffer) :
                bool1 = connectionState.touchpadConnected
                bool2 = connectionState.keyboardConnected
            },
            { "Received connection state: touchpad connected: $bool1 keyboard connected: $bool2" }
            { "Received connection state: touchpad connected: $bool1 keyboard connected: $bool2" },
        )
    }

    fun logMovingBetweenScreens(
        previousScreen: KeyboardTouchpadTutorialScreen?,
        currentScreen: KeyboardTouchpadTutorialScreen
        currentScreen: KeyboardTouchpadTutorialScreen,
    ) {
        logInfo(
            {
                str1 = previousScreen?.toString() ?: "NO_SCREEN"
                str2 = currentScreen.toString()
            },
            { "Moving from $str1 screen to $str2 screen" }
            { "Moving from $str1 screen to $str2 screen" },
        )
    }

@@ -93,9 +95,17 @@ constructor(@InputDeviceTutorialLog private val buffer: LogBuffer) :
        logInfo({ str1 = previousScreen.toString() }, { "Going back to $str1 screen" })
    }

    fun logDeviceFirstConnection(deviceType: DeviceType) {
        logInfo({ str1 = deviceType.toString() }, { "$str1 has connected for the first time" })
    }

    fun logTutorialLaunched(tutorialType: TutorialType) {
        logInfo({ str1 = tutorialType.toString() }, { "Launching $str1 tutorial" })
    }

    private inline fun logInfo(
        messageInitializer: MessageInitializer,
        noinline messagePrinter: MessagePrinter
        noinline messagePrinter: MessagePrinter,
    ) {
        buffer.log(TAG, LogLevel.INFO, messageInitializer, messagePrinter)
    }
+12 −5
Original line number Diff line number Diff line
@@ -18,6 +18,7 @@ package com.android.systemui.inputdevice.tutorial.domain.interactor

import android.os.SystemProperties
import com.android.systemui.dagger.SysUISingleton
import com.android.systemui.inputdevice.tutorial.InputDeviceTutorialLogger
import com.android.systemui.inputdevice.tutorial.data.repository.DeviceType
import com.android.systemui.inputdevice.tutorial.data.repository.DeviceType.KEYBOARD
import com.android.systemui.inputdevice.tutorial.data.repository.DeviceType.TOUCHPAD
@@ -47,12 +48,13 @@ class TutorialSchedulerInteractor
constructor(
    keyboardRepository: KeyboardRepository,
    touchpadRepository: TouchpadRepository,
    private val repo: TutorialSchedulerRepository
    private val repo: TutorialSchedulerRepository,
    private val logger: InputDeviceTutorialLogger,
) {
    private val isAnyDeviceConnected =
        mapOf(
            KEYBOARD to keyboardRepository.isAnyKeyboardConnected,
            TOUCHPAD to touchpadRepository.isAnyTouchpadConnected
            TOUCHPAD to touchpadRepository.isAnyTouchpadConnected,
        )

    private val touchpadScheduleFlow = flow {
@@ -71,10 +73,14 @@ constructor(

    private suspend fun schedule(deviceType: DeviceType) {
        if (!repo.wasEverConnected(deviceType)) {
            logger.d("Waiting for $deviceType to connect")
            waitForDeviceConnection(deviceType)
            logger.logDeviceFirstConnection(deviceType)
            repo.updateFirstConnectionTime(deviceType, Instant.now())
        }
        delay(remainingTime(start = repo.firstConnectionTime(deviceType)!!))
        val remainingTime = remainingTime(start = repo.firstConnectionTime(deviceType)!!)
        logger.d("Tutorial is scheduled in ${remainingTime.inWholeSeconds} seconds")
        delay(remainingTime)
        waitForDeviceConnection(deviceType)
    }

@@ -92,6 +98,7 @@ constructor(
            if (tutorialType == TutorialType.TOUCHPAD || tutorialType == TutorialType.BOTH)
                repo.updateLaunchTime(TOUCHPAD, Instant.now())

            logger.logTutorialLaunched(tutorialType)
            tutorialType
        }

@@ -119,7 +126,7 @@ constructor(
                Duration.ofSeconds(
                    SystemProperties.getLong(
                        "persist.peripheral_tutorial_delay_sec",
                        DEFAULT_LAUNCH_DELAY_SEC
                        DEFAULT_LAUNCH_DELAY_SEC,
                    )
                )
    }
@@ -128,6 +135,6 @@ constructor(
        KEYBOARD,
        TOUCHPAD,
        BOTH,
        NONE
        NONE,
    }
}