1 /*
2  * Copyright (C) 2021 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.phone.fragment
18 
19 import com.android.systemui.log.LogBuffer
20 import com.android.systemui.log.LogLevel
21 import com.android.systemui.log.dagger.CollapsedSbFragmentLog
22 import com.android.systemui.statusbar.DisableFlagsLogger
23 import javax.inject.Inject
24 
25 /** Used by [CollapsedStatusBarFragment] to log messages to a [LogBuffer]. */
26 class CollapsedStatusBarFragmentLogger @Inject constructor(
27         @CollapsedSbFragmentLog private val buffer: LogBuffer,
28         private val disableFlagsLogger: DisableFlagsLogger,
29 ) {
30 
31     /**
32      * Logs a string representing the new state received by [CollapsedStatusBarFragment] and any
33      * modifications that were made to the flags locally.
34      *
35      * @param new see [DisableFlagsLogger.getDisableFlagsString]
36      * @param newAfterLocalModification see [DisableFlagsLogger.getDisableFlagsString]
37      */
38     fun logDisableFlagChange(
39         new: DisableFlagsLogger.DisableState,
40         newAfterLocalModification: DisableFlagsLogger.DisableState
41     ) {
42         buffer.log(
43                 TAG,
44                 LogLevel.INFO,
45                 {
46                     int1 = new.disable1
47                     int2 = new.disable2
48                     long1 = newAfterLocalModification.disable1.toLong()
49                     long2 = newAfterLocalModification.disable2.toLong()
50                 },
51                 {
52                     disableFlagsLogger.getDisableFlagsString(
53                         old = null,
54                         new = DisableFlagsLogger.DisableState(int1, int2),
55                         newAfterLocalModification =
56                             DisableFlagsLogger.DisableState(long1.toInt(), long2.toInt())
57                     )
58                 }
59         )
60     }
61 }
62 
63 private const val TAG = "CollapsedSbFragment"