• 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.communal.shared.log
18 
19 import com.android.compose.animation.scene.ObservableTransitionState
20 import com.android.compose.animation.scene.SceneKey
21 import com.android.systemui.log.LogBuffer
22 import com.android.systemui.log.core.LogLevel
23 import com.android.systemui.log.dagger.CommunalLog
24 import javax.inject.Inject
25 
26 class CommunalSceneLogger @Inject constructor(@CommunalLog private val logBuffer: LogBuffer) {
27 
logSceneChangeRequestednull28     fun logSceneChangeRequested(
29         from: SceneKey,
30         to: SceneKey,
31         reason: String,
32         isInstant: Boolean,
33     ) {
34         logBuffer.log(
35             tag = TAG,
36             level = LogLevel.INFO,
37             messageInitializer = {
38                 str1 = from.toString()
39                 str2 = to.toString()
40                 str3 = reason
41                 bool1 = isInstant
42             },
43             messagePrinter = {
44                 buildString {
45                     append("Scene change requested: $str1 → $str2")
46                     if (isInstant) {
47                         append(" (instant)")
48                     }
49                     append(", reason: $str3")
50                 }
51             },
52         )
53     }
54 
logSceneChangeCommittednull55     fun logSceneChangeCommitted(
56         from: SceneKey,
57         to: SceneKey,
58     ) {
59         logBuffer.log(
60             tag = TAG,
61             level = LogLevel.INFO,
62             messageInitializer = {
63                 str1 = from.toString()
64                 str2 = to.toString()
65             },
66             messagePrinter = { "Scene change committed: $str1 → $str2" },
67         )
68     }
69 
logSceneTransitionnull70     fun logSceneTransition(transitionState: ObservableTransitionState) {
71         when (transitionState) {
72             is ObservableTransitionState.Transition -> {
73                 logBuffer.log(
74                     tag = TAG,
75                     level = LogLevel.INFO,
76                     messageInitializer = {
77                         str1 = transitionState.fromContent.toString()
78                         str2 = transitionState.toContent.toString()
79                     },
80                     messagePrinter = { "Scene transition started: $str1 → $str2" },
81                 )
82             }
83             is ObservableTransitionState.Idle -> {
84                 logBuffer.log(
85                     tag = TAG,
86                     level = LogLevel.INFO,
87                     messageInitializer = { str1 = transitionState.currentScene.toString() },
88                     messagePrinter = { "Scene transition idle on: $str1" },
89                 )
90             }
91         }
92     }
93 
94     companion object {
95         private const val TAG = "CommunalSceneLogger"
96     }
97 }
98