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.systemui.log.LogBuffer 20 import com.android.systemui.log.core.LogLevel 21 import com.android.systemui.log.dagger.SceneFrameworkLog 22 import com.android.systemui.scene.shared.model.SceneKey 23 import javax.inject.Inject 24 25 class SceneLogger @Inject constructor(@SceneFrameworkLog private val logBuffer: LogBuffer) { 26 27 fun logFrameworkEnabled(isEnabled: Boolean) { 28 fun asWord(isEnabled: Boolean): String { 29 return if (isEnabled) "enabled" else "disabled" 30 } 31 32 logBuffer.log( 33 tag = TAG, 34 level = LogLevel.INFO, 35 messageInitializer = { bool1 = isEnabled }, 36 messagePrinter = { "Scene framework is ${asWord(bool1)}" } 37 ) 38 } 39 40 fun logSceneChangeRequested( 41 from: SceneKey, 42 to: SceneKey, 43 reason: String, 44 ) { 45 logBuffer.log( 46 tag = TAG, 47 level = LogLevel.INFO, 48 messageInitializer = { 49 str1 = from.toString() 50 str2 = to.toString() 51 str3 = reason 52 }, 53 messagePrinter = { "Scene change requested: $str1 → $str2, reason: $str3" }, 54 ) 55 } 56 57 fun logSceneChangeCommitted( 58 from: SceneKey, 59 to: SceneKey, 60 reason: String, 61 ) { 62 logBuffer.log( 63 tag = TAG, 64 level = LogLevel.INFO, 65 messageInitializer = { 66 str1 = from.toString() 67 str2 = to.toString() 68 str3 = reason 69 }, 70 messagePrinter = { "Scene change committed: $str1 → $str2, reason: $str3" }, 71 ) 72 } 73 74 fun logVisibilityChange( 75 from: Boolean, 76 to: Boolean, 77 reason: String, 78 ) { 79 fun asWord(isVisible: Boolean): String { 80 return if (isVisible) "visible" else "invisible" 81 } 82 83 logBuffer.log( 84 tag = TAG, 85 level = LogLevel.INFO, 86 messageInitializer = { 87 str1 = asWord(from) 88 str2 = asWord(to) 89 str3 = reason 90 }, 91 messagePrinter = { "$str1 → $str2, reason: $str3" }, 92 ) 93 } 94 95 companion object { 96 private const val TAG = "SceneFramework" 97 } 98 } 99