• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.kairos.ExperimentalKairosApi
24 import com.android.systemui.log.LogBuffer
25 import com.android.systemui.log.core.LogLevel
26 import com.android.systemui.statusbar.pipeline.dagger.MobileViewLog
27 import com.android.systemui.statusbar.pipeline.mobile.ui.viewmodel.LocationBasedMobileViewModel
28 import com.android.systemui.statusbar.pipeline.mobile.ui.viewmodel.LocationBasedMobileViewModelKairos
29 import java.io.PrintWriter
30 import javax.inject.Inject
31 
32 /** Logs for changes with the new mobile views. */
33 @SysUISingleton
34 class MobileViewLogger
35 @Inject
36 constructor(@MobileViewLog private val buffer: LogBuffer, dumpManager: DumpManager) : Dumpable {
37     init {
38         dumpManager.registerNormalDumpable(this)
39     }
40 
41     private val collectionStatuses = mutableMapOf<String, Boolean>()
42 
43     fun logUiAdapterSubIdsSentToIconController(subs: List<Int>, isStackable: Boolean) {
44         buffer.log(
45             TAG,
46             LogLevel.INFO,
47             {
48                 str1 = subs.toString()
49                 bool1 = isStackable
50             },
51             {
52                 "Sub IDs in MobileUiAdapter being sent to icon controller: $str1, isStackable=$bool1"
53             },
54         )
55     }
56 
57     fun logNewViewBinding(view: View, viewModel: LocationBasedMobileViewModel) =
58         logNewViewBinding(view, viewModel, viewModel.location.name)
59 
60     fun logNewViewBinding(view: View, viewModel: Any, location: String) {
61         buffer.log(
62             TAG,
63             LogLevel.INFO,
64             {
65                 str1 = view.getIdForLogging()
66                 str2 = viewModel.getIdForLogging()
67                 str3 = location
68             },
69             { "New view binding. viewId=$str1, viewModelId=$str2, viewModelLocation=$str3" },
70         )
71     }
72 
73     fun logCollectionStarted(view: View, viewModel: LocationBasedMobileViewModel) {
74         collectionStatuses[view.getIdForLogging()] = true
75         buffer.log(
76             TAG,
77             LogLevel.INFO,
78             {
79                 str1 = view.getIdForLogging()
80                 str2 = viewModel.getIdForLogging()
81                 str3 = viewModel.location.name
82             },
83             { "Collection started. viewId=$str1, viewModelId=$str2, viewModelLocation=$str3" },
84         )
85     }
86 
87     fun logCollectionStopped(view: View, viewModel: LocationBasedMobileViewModel) {
88         collectionStatuses[view.getIdForLogging()] = false
89         buffer.log(
90             TAG,
91             LogLevel.INFO,
92             {
93                 str1 = view.getIdForLogging()
94                 str2 = viewModel.getIdForLogging()
95                 str3 = viewModel.location.name
96             },
97             { "Collection stopped. viewId=$str1, viewModelId=$str2, viewModelLocation=$str3" },
98         )
99     }
100 
101     @OptIn(ExperimentalKairosApi::class)
102     fun logCollectionStarted(view: View, viewModel: LocationBasedMobileViewModelKairos) {
103         collectionStatuses[view.getIdForLogging()] = true
104         buffer.log(
105             TAG,
106             LogLevel.INFO,
107             {
108                 str1 = view.getIdForLogging()
109                 str2 = viewModel.getIdForLogging()
110                 str3 = viewModel.location.name
111             },
112             { "Collection started. viewId=$str1, viewModelId=$str2, viewModelLocation=$str3" },
113         )
114     }
115 
116     @OptIn(ExperimentalKairosApi::class)
117     fun logCollectionStopped(view: View, viewModel: LocationBasedMobileViewModelKairos) {
118         collectionStatuses[view.getIdForLogging()] = false
119         buffer.log(
120             TAG,
121             LogLevel.INFO,
122             {
123                 str1 = view.getIdForLogging()
124                 str2 = viewModel.getIdForLogging()
125                 str3 = viewModel.location.name
126             },
127             { "Collection stopped. viewId=$str1, viewModelId=$str2, viewModelLocation=$str3" },
128         )
129     }
130 
131     override fun dump(pw: PrintWriter, args: Array<out String>) {
132         pw.println("Collection statuses per view:---")
133         collectionStatuses.forEach { viewId, isCollecting ->
134             pw.println("viewId=$viewId, isCollecting=$isCollecting")
135         }
136     }
137 
138     companion object {
139         fun Any.getIdForLogging(): String {
140             // The identityHashCode is guaranteed to be constant for the lifetime of the object.
141             return Integer.toHexString(System.identityHashCode(this))
142         }
143     }
144 }
145 
146 private const val TAG = "MobileViewLogger"
147