1 /* 2 * 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.qs.pipeline.shared.logging 18 19 import com.android.systemui.log.LogBuffer 20 import com.android.systemui.log.core.LogLevel 21 import com.android.systemui.qs.pipeline.dagger.QSAutoAddLog 22 import com.android.systemui.qs.pipeline.dagger.QSRestoreLog 23 import com.android.systemui.qs.pipeline.dagger.QSTileListLog 24 import com.android.systemui.qs.pipeline.data.model.RestoreData 25 import com.android.systemui.qs.pipeline.data.repository.UserTileSpecRepository 26 import com.android.systemui.qs.pipeline.shared.TileSpec 27 import javax.inject.Inject 28 29 /** 30 * Logger for the new pipeline. 31 * 32 * This may log to different buffers depending of the function of the log. 33 */ 34 class QSPipelineLogger 35 @Inject 36 constructor( 37 @QSTileListLog private val tileListLogBuffer: LogBuffer, 38 @QSAutoAddLog private val tileAutoAddLogBuffer: LogBuffer, 39 @QSRestoreLog private val restoreLogBuffer: LogBuffer, 40 ) { 41 42 companion object { 43 const val TILE_LIST_TAG = "QSTileListLog" 44 const val AUTO_ADD_TAG = "QSAutoAddableLog" 45 const val RESTORE_TAG = "QSRestoreLog" 46 } 47 48 /** 49 * Log the tiles that are parsed in the repo. This is effectively what is surfaces in the flow. 50 * 51 * [usesDefault] indicates if the default tiles were used (due to the setting being empty or 52 * invalid). 53 */ logParsedTilesnull54 fun logParsedTiles(tiles: List<TileSpec>, usesDefault: Boolean, user: Int) { 55 tileListLogBuffer.log( 56 TILE_LIST_TAG, 57 LogLevel.DEBUG, 58 { 59 str1 = tiles.toString() 60 bool1 = usesDefault 61 int1 = user 62 }, 63 { "Parsed tiles (default=$bool1, user=$int1): $str1" }, 64 ) 65 } 66 logTilesRestoredAndReconcilednull67 fun logTilesRestoredAndReconciled( 68 currentTiles: List<TileSpec>, 69 reconciledTiles: List<TileSpec>, 70 user: Int, 71 ) { 72 tileListLogBuffer.log( 73 TILE_LIST_TAG, 74 LogLevel.DEBUG, 75 { 76 str1 = currentTiles.toString() 77 str2 = reconciledTiles.toString() 78 int1 = user 79 }, 80 { "Tiles restored and reconciled for user: $int1\nWas: $str1\nSet to: $str2" }, 81 ) 82 } 83 logProcessTileChangenull84 fun logProcessTileChange( 85 action: UserTileSpecRepository.ChangeAction, 86 newList: List<TileSpec>, 87 userId: Int, 88 ) { 89 tileListLogBuffer.log( 90 TILE_LIST_TAG, 91 LogLevel.DEBUG, 92 { 93 str1 = action.toString() 94 str2 = newList.toString() 95 int1 = userId 96 }, 97 { "Processing $str1 for user $int1\nNew list: $str2" }, 98 ) 99 } 100 101 /** Log when a tile is destroyed and its reason for destroying. */ logTileDestroyednull102 fun logTileDestroyed(spec: TileSpec, reason: TileDestroyedReason) { 103 tileListLogBuffer.log( 104 TILE_LIST_TAG, 105 LogLevel.DEBUG, 106 { 107 str1 = spec.toString() 108 str2 = reason.readable 109 }, 110 { "Tile $str1 destroyed. Reason: $str2" }, 111 ) 112 } 113 logTileDestroyedIgnorednull114 fun logTileDestroyedIgnored(spec: TileSpec) { 115 tileListLogBuffer.log( 116 TILE_LIST_TAG, 117 LogLevel.DEBUG, 118 { str1 = spec.toString() }, 119 { "Tile $str1 ignored as it was already destroyed." }, 120 ) 121 } 122 123 /** Log when a tile is created. */ logTileCreatednull124 fun logTileCreated(spec: TileSpec) { 125 tileListLogBuffer.log( 126 TILE_LIST_TAG, 127 LogLevel.DEBUG, 128 { str1 = spec.toString() }, 129 { "Tile $str1 created" }, 130 ) 131 } 132 133 /** Ĺog when trying to create a tile, but it's not found in the factory. */ logTileNotFoundInFactorynull134 fun logTileNotFoundInFactory(spec: TileSpec) { 135 tileListLogBuffer.log( 136 TILE_LIST_TAG, 137 LogLevel.VERBOSE, 138 { str1 = spec.toString() }, 139 { "Tile $str1 not found in factory" }, 140 ) 141 } 142 143 /** Log when the user is changed for a platform tile. */ logTileUserChangednull144 fun logTileUserChanged(spec: TileSpec, user: Int) { 145 tileListLogBuffer.log( 146 TILE_LIST_TAG, 147 LogLevel.VERBOSE, 148 { 149 str1 = spec.toString() 150 int1 = user 151 }, 152 { "User changed to $int1 for tile $str1" }, 153 ) 154 } 155 logUsingRetailTilesnull156 fun logUsingRetailTiles() { 157 tileListLogBuffer.log(TILE_LIST_TAG, LogLevel.DEBUG, {}, { "Using retail tiles" }) 158 } 159 logTilesNotInstallednull160 fun logTilesNotInstalled(tiles: Collection<TileSpec>, user: Int) { 161 tileListLogBuffer.log( 162 TILE_LIST_TAG, 163 LogLevel.DEBUG, 164 { 165 str1 = tiles.toString() 166 int1 = user 167 }, 168 { "Tiles kept for not installed packages for user $int1: $str1" }, 169 ) 170 } 171 logAutoAddTilesParsednull172 fun logAutoAddTilesParsed(userId: Int, tiles: Set<TileSpec>) { 173 tileAutoAddLogBuffer.log( 174 AUTO_ADD_TAG, 175 LogLevel.DEBUG, 176 { 177 str1 = tiles.toString() 178 int1 = userId 179 }, 180 { "Auto add tiles parsed for user $int1: $str1" }, 181 ) 182 } 183 logAutoAddTilesRestoredReconcilednull184 fun logAutoAddTilesRestoredReconciled(userId: Int, tiles: Set<TileSpec>) { 185 tileAutoAddLogBuffer.log( 186 AUTO_ADD_TAG, 187 LogLevel.DEBUG, 188 { 189 str1 = tiles.toString() 190 int1 = userId 191 }, 192 { "Auto-add tiles reconciled for user $int1: $str1" }, 193 ) 194 } 195 logTileAutoAddednull196 fun logTileAutoAdded(userId: Int, spec: TileSpec, position: Int) { 197 tileAutoAddLogBuffer.log( 198 AUTO_ADD_TAG, 199 LogLevel.DEBUG, 200 { 201 int1 = userId 202 int2 = position 203 str1 = spec.toString() 204 }, 205 { "Tile $str1 auto added for user $int1 at position $int2" }, 206 ) 207 } 208 logTileAutoRemovednull209 fun logTileAutoRemoved(userId: Int, spec: TileSpec) { 210 tileAutoAddLogBuffer.log( 211 AUTO_ADD_TAG, 212 LogLevel.DEBUG, 213 { 214 int1 = userId 215 str1 = spec.toString() 216 }, 217 { "Tile $str1 auto removed for user $int1" }, 218 ) 219 } 220 logTileUnmarkednull221 fun logTileUnmarked(userId: Int, spec: TileSpec) { 222 tileAutoAddLogBuffer.log( 223 AUTO_ADD_TAG, 224 LogLevel.DEBUG, 225 { 226 int1 = userId 227 str1 = spec.toString() 228 }, 229 { "Tile $str1 unmarked as auto-added for user $int1" }, 230 ) 231 } 232 logSettingsRestoredOnUserSetupCompletenull233 fun logSettingsRestoredOnUserSetupComplete(userId: Int) { 234 restoreLogBuffer.log( 235 RESTORE_TAG, 236 LogLevel.DEBUG, 237 { int1 = userId }, 238 { "Restored from single intent after user setup complete for user $int1" }, 239 ) 240 } 241 logSettingsRestorednull242 fun logSettingsRestored(restoreData: RestoreData) { 243 restoreLogBuffer.log( 244 RESTORE_TAG, 245 LogLevel.DEBUG, 246 { 247 int1 = restoreData.userId 248 str1 = restoreData.restoredTiles.toString() 249 str2 = restoreData.restoredAutoAddedTiles.toString() 250 }, 251 { 252 "Restored settings data for user $int1\n" + 253 "\tRestored tiles: $str1\n" + 254 "\tRestored auto added tiles: $str2" 255 }, 256 ) 257 } 258 logRestoreProcessorAppliednull259 fun logRestoreProcessorApplied( 260 restoreProcessorClassName: String?, 261 step: RestorePreprocessorStep, 262 ) { 263 restoreLogBuffer.log( 264 RESTORE_TAG, 265 LogLevel.DEBUG, 266 { 267 str1 = restoreProcessorClassName 268 str2 = step.name 269 }, 270 { "Restore $str2 processed by $str1" }, 271 ) 272 } 273 274 /** Reasons for destroying an existing tile. */ 275 enum class TileDestroyedReason(val readable: String) { 276 TILE_REMOVED("Tile removed from current set"), 277 CUSTOM_TILE_USER_CHANGED("User changed for custom tile"), 278 NEW_TILE_NOT_AVAILABLE("New tile not available"), 279 EXISTING_TILE_NOT_AVAILABLE("Existing tile not available"), 280 TILE_NOT_PRESENT_IN_NEW_USER("Tile not present in new user"), 281 } 282 283 enum class RestorePreprocessorStep { 284 PREPROCESSING, 285 POSTPROCESSING, 286 } 287 } 288