1 /*
2  * Copyright (C) 2020 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.toast
18 
19 import com.android.systemui.log.dagger.ToastLog
20 import com.android.systemui.log.LogBuffer
21 import com.android.systemui.log.core.LogLevel
22 import com.android.systemui.log.core.LogLevel.DEBUG
23 import com.android.systemui.log.core.LogMessage
24 import javax.inject.Inject
25 
26 private const val TAG = "ToastLog"
27 
28 class ToastLogger @Inject constructor(
29     @ToastLog private val buffer: LogBuffer
30 ) {
31 
32     fun logOnShowToast(uid: Int, packageName: String, text: String, token: String) {
33         log(DEBUG, {
34             int1 = uid
35             str1 = packageName
36             str2 = text
37             str3 = token
38         }, {
39             "[$str3] Show toast for ($str1, $int1). msg=\'$str2\'"
40         })
41     }
42 
43     fun logOnHideToast(packageName: String, token: String) {
44         log(DEBUG, {
45             str1 = packageName
46             str2 = token
47         }, {
48             "[$str2] Hide toast for [$str1]"
49         })
50     }
51 
52     fun logOrientationChange(text: String, isPortrait: Boolean) {
53         log(DEBUG, {
54             str1 = text
55             bool1 = isPortrait
56         }, {
57             "Orientation change for toast. msg=\'$str1\' isPortrait=$bool1"
58         })
59     }
60 
61     fun logOnSkipToastForInvalidDisplay(packageName: String, token: String, displayId: Int) {
62         log(DEBUG, {
63             str1 = packageName
64             str2 = token
65             int1 = displayId
66         }, {
67             "[$str2] Skip toast for [$str1] scheduled on unavailable display #$int1"
68         })
69     }
70 
71     private inline fun log(
72         logLevel: LogLevel,
73         initializer: LogMessage.() -> Unit,
74         noinline printer: LogMessage.() -> String
75     ) {
76         buffer.log(TAG, logLevel, initializer, printer)
77     }
78 }