1 /* 2 * Copyright 2023 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.scene.shared.logger 18 19 import com.android.compose.animation.scene.SceneKey 20 import com.android.systemui.log.LogBuffer 21 import com.android.systemui.log.core.LogLevel 22 import com.android.systemui.log.dagger.SceneFrameworkLog 23 import javax.inject.Inject 24 25 class SceneLogger @Inject constructor(@SceneFrameworkLog private val logBuffer: LogBuffer) { 26 logFrameworkEnablednull27 fun logFrameworkEnabled(isEnabled: Boolean, reason: String? = null) { 28 fun asWord(isEnabled: Boolean): String { 29 return if (isEnabled) "enabled" else "disabled" 30 } 31 32 logBuffer.log( 33 tag = TAG, 34 level = if (isEnabled) LogLevel.INFO else LogLevel.WARNING, 35 messageInitializer = { 36 bool1 = isEnabled 37 str1 = reason 38 }, 39 messagePrinter = { 40 "Scene framework is ${asWord(bool1)}${if (str1 != null) " $str1" else ""}" 41 } 42 ) 43 } 44 logSceneChangeRequestednull45 fun logSceneChangeRequested( 46 from: SceneKey, 47 to: SceneKey, 48 reason: String, 49 isInstant: Boolean, 50 ) { 51 logBuffer.log( 52 tag = TAG, 53 level = LogLevel.INFO, 54 messageInitializer = { 55 str1 = from.toString() 56 str2 = to.toString() 57 str3 = reason 58 bool1 = isInstant 59 }, 60 messagePrinter = { 61 buildString { 62 append("Scene change requested: $str1 → $str2") 63 if (isInstant) { 64 append(" (instant)") 65 } 66 append(", reason: $str3") 67 } 68 }, 69 ) 70 } 71 logSceneChangeCommittednull72 fun logSceneChangeCommitted( 73 from: SceneKey, 74 to: SceneKey, 75 ) { 76 logBuffer.log( 77 tag = TAG, 78 level = LogLevel.INFO, 79 messageInitializer = { 80 str1 = from.toString() 81 str2 = to.toString() 82 }, 83 messagePrinter = { "Scene change committed: $str1 → $str2" }, 84 ) 85 } 86 logVisibilityChangenull87 fun logVisibilityChange( 88 from: Boolean, 89 to: Boolean, 90 reason: String, 91 ) { 92 fun asWord(isVisible: Boolean): String { 93 return if (isVisible) "visible" else "invisible" 94 } 95 96 logBuffer.log( 97 tag = TAG, 98 level = LogLevel.INFO, 99 messageInitializer = { 100 str1 = asWord(from) 101 str2 = asWord(to) 102 str3 = reason 103 }, 104 messagePrinter = { "$str1 → $str2, reason: $str3" }, 105 ) 106 } 107 logRemoteUserInteractionStartednull108 fun logRemoteUserInteractionStarted( 109 reason: String, 110 ) { 111 logBuffer.log( 112 tag = TAG, 113 level = LogLevel.INFO, 114 messageInitializer = { str1 = reason }, 115 messagePrinter = { "remote user interaction started, reason: $str1" }, 116 ) 117 } 118 logUserInteractionFinishednull119 fun logUserInteractionFinished() { 120 logBuffer.log( 121 tag = TAG, 122 level = LogLevel.INFO, 123 messageInitializer = {}, 124 messagePrinter = { "user interaction finished" }, 125 ) 126 } 127 logSceneBackStacknull128 fun logSceneBackStack(backStack: Iterable<SceneKey>) { 129 logBuffer.log( 130 tag = TAG, 131 level = LogLevel.INFO, 132 messageInitializer = { str1 = backStack.joinToString(", ") { it.debugName } }, 133 messagePrinter = { "back stack: $str1" }, 134 ) 135 } 136 137 companion object { 138 private const val TAG = "SceneFramework" 139 } 140 } 141