1 /* <lambda>null2 * Copyright (C) 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.statusbar.pipeline.mobile.ui 18 19 import android.view.View 20 import com.android.systemui.Dumpable 21 import com.android.systemui.dagger.SysUISingleton 22 import com.android.systemui.dump.DumpManager 23 import com.android.systemui.plugins.log.LogBuffer 24 import com.android.systemui.plugins.log.LogLevel 25 import com.android.systemui.statusbar.pipeline.dagger.MobileViewLog 26 import com.android.systemui.statusbar.pipeline.mobile.ui.viewmodel.LocationBasedMobileViewModel 27 import java.io.PrintWriter 28 import javax.inject.Inject 29 30 /** Logs for changes with the new mobile views. */ 31 @SysUISingleton 32 class MobileViewLogger 33 @Inject 34 constructor( 35 @MobileViewLog private val buffer: LogBuffer, 36 dumpManager: DumpManager, 37 ) : Dumpable { 38 init { 39 dumpManager.registerNormalDumpable(this) 40 } 41 42 private val collectionStatuses = mutableMapOf<String, Boolean>() 43 44 fun logUiAdapterSubIdsUpdated(subs: List<Int>) { 45 buffer.log( 46 TAG, 47 LogLevel.INFO, 48 { str1 = subs.toString() }, 49 { "Sub IDs in MobileUiAdapter updated internally: $str1" }, 50 ) 51 } 52 53 fun logUiAdapterSubIdsSentToIconController(subs: List<Int>) { 54 buffer.log( 55 TAG, 56 LogLevel.INFO, 57 { str1 = subs.toString() }, 58 { "Sub IDs in MobileUiAdapter being sent to icon controller: $str1" }, 59 ) 60 } 61 62 fun logNewViewBinding(view: View, viewModel: LocationBasedMobileViewModel) { 63 buffer.log( 64 TAG, 65 LogLevel.INFO, 66 { 67 str1 = view.getIdForLogging() 68 str2 = viewModel.getIdForLogging() 69 str3 = viewModel.locationName 70 }, 71 { "New view binding. viewId=$str1, viewModelId=$str2, viewModelLocation=$str3" }, 72 ) 73 } 74 75 fun logCollectionStarted(view: View, viewModel: LocationBasedMobileViewModel) { 76 collectionStatuses[view.getIdForLogging()] = true 77 buffer.log( 78 TAG, 79 LogLevel.INFO, 80 { 81 str1 = view.getIdForLogging() 82 str2 = viewModel.getIdForLogging() 83 str3 = viewModel.locationName 84 }, 85 { "Collection started. viewId=$str1, viewModelId=$str2, viewModelLocation=$str3" }, 86 ) 87 } 88 89 fun logCollectionStopped(view: View, viewModel: LocationBasedMobileViewModel) { 90 collectionStatuses[view.getIdForLogging()] = false 91 buffer.log( 92 TAG, 93 LogLevel.INFO, 94 { 95 str1 = view.getIdForLogging() 96 str2 = viewModel.getIdForLogging() 97 str3 = viewModel.locationName 98 }, 99 { "Collection stopped. viewId=$str1, viewModelId=$str2, viewModelLocation=$str3" }, 100 ) 101 } 102 103 override fun dump(pw: PrintWriter, args: Array<out String>) { 104 pw.println("Collection statuses per view:---") 105 collectionStatuses.forEach { viewId, isCollecting -> 106 pw.println("viewId=$viewId, isCollecting=$isCollecting") 107 } 108 } 109 110 companion object { 111 fun Any.getIdForLogging(): String { 112 // The identityHashCode is guaranteed to be constant for the lifetime of the object. 113 return Integer.toHexString(System.identityHashCode(this)) 114 } 115 } 116 } 117 118 private const val TAG = "MobileViewLogger" 119