• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2024 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 package com.android.systemui.inputdevice.tutorial
18 
19 import com.android.systemui.inputdevice.tutorial.data.repository.DeviceType
20 import com.android.systemui.inputdevice.tutorial.domain.interactor.ConnectionState
21 import com.android.systemui.inputdevice.tutorial.domain.interactor.TutorialSchedulerInteractor.TutorialType
22 import com.android.systemui.inputdevice.tutorial.ui.viewmodel.Screen as KeyboardTouchpadTutorialScreen
23 import com.android.systemui.log.ConstantStringsLogger
24 import com.android.systemui.log.ConstantStringsLoggerImpl
25 import com.android.systemui.log.LogBuffer
26 import com.android.systemui.log.core.LogLevel
27 import com.android.systemui.log.core.MessageInitializer
28 import com.android.systemui.log.core.MessagePrinter
29 import com.android.systemui.log.dagger.InputDeviceTutorialLog
30 import com.android.systemui.touchpad.tutorial.ui.viewmodel.Screen as TouchpadTutorialScreen
31 import javax.inject.Inject
32 
33 private const val TAG = "InputDeviceTutorial"
34 
35 class InputDeviceTutorialLogger
36 @Inject
37 constructor(@InputDeviceTutorialLog private val buffer: LogBuffer) :
<lambda>null38     ConstantStringsLogger by ConstantStringsLoggerImpl(buffer, TAG) {
39 
40     fun logGoingToScreen(screen: TouchpadTutorialScreen, context: TutorialContext) {
41         logInfo(
42             {
43                 str1 = screen.toString()
44                 str2 = context.string
45             },
46             { "Emitting new screen $str1 in $str2" },
47         )
48     }
49 
50     fun logCloseTutorial(context: TutorialContext) {
51         logInfo({ str1 = context.string }, { "Closing $str1" })
52     }
53 
54     fun logOpenTutorial(context: TutorialContext) {
55         logInfo({ str1 = context.string }, { "Opening $str1" })
56     }
57 
58     fun logNextScreenMissingHardware(nextScreen: KeyboardTouchpadTutorialScreen) {
59         buffer.log(
60             TAG,
61             LogLevel.WARNING,
62             { str1 = nextScreen.toString() },
63             { "next screen should be $str1 but required hardware is missing" },
64         )
65     }
66 
67     fun logNextScreen(nextScreen: KeyboardTouchpadTutorialScreen) {
68         logInfo({ str1 = nextScreen.toString() }, { "going to $str1 screen" })
69     }
70 
71     fun logNewConnectionState(connectionState: ConnectionState) {
72         logInfo(
73             {
74                 bool1 = connectionState.touchpadConnected
75                 bool2 = connectionState.keyboardConnected
76             },
77             { "Received connection state: touchpad connected: $bool1 keyboard connected: $bool2" },
78         )
79     }
80 
81     fun logMovingBetweenScreens(
82         previousScreen: KeyboardTouchpadTutorialScreen?,
83         currentScreen: KeyboardTouchpadTutorialScreen,
84     ) {
85         logInfo(
86             {
87                 str1 = previousScreen?.toString() ?: "NO_SCREEN"
88                 str2 = currentScreen.toString()
89             },
90             { "Moving from $str1 screen to $str2 screen" },
91         )
92     }
93 
94     fun logGoingBack(previousScreen: KeyboardTouchpadTutorialScreen) {
95         logInfo({ str1 = previousScreen.toString() }, { "Going back to $str1 screen" })
96     }
97 
98     fun logDeviceFirstConnection(deviceType: DeviceType) {
99         logInfo({ str1 = deviceType.toString() }, { "$str1 has connected for the first time" })
100     }
101 
102     fun logTutorialLaunched(tutorialType: TutorialType) {
103         logInfo({ str1 = tutorialType.toString() }, { "Launching $str1 tutorial" })
104     }
105 
106     private inline fun logInfo(
107         messageInitializer: MessageInitializer,
108         noinline messagePrinter: MessagePrinter,
109     ) {
110         buffer.log(TAG, LogLevel.INFO, messageInitializer, messagePrinter)
111     }
112 
113     enum class TutorialContext(val string: String) {
114         KEYBOARD_TOUCHPAD_TUTORIAL("keyboard touchpad tutorial"),
115         TOUCHPAD_TUTORIAL("touchpad tutorial"),
116     }
117 }
118