• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.privacy.logging
18 
19 import android.permission.PermGroupUsage
20 import com.android.systemui.log.LogBuffer
21 import com.android.systemui.log.LogLevel
22 import com.android.systemui.log.LogMessage
23 import com.android.systemui.log.dagger.PrivacyLog
24 import com.android.systemui.privacy.PrivacyDialog
25 import com.android.systemui.privacy.PrivacyItem
26 import java.text.SimpleDateFormat
27 import java.util.Locale
28 import javax.inject.Inject
29 
30 private const val TAG = "PrivacyLog"
31 private val DATE_FORMAT = SimpleDateFormat("MM-dd HH:mm:ss.SSS", Locale.US)
32 class PrivacyLogger @Inject constructor(
33     @PrivacyLog private val buffer: LogBuffer
34 ) {
35 
logUpdatedItemFromAppOpsnull36     fun logUpdatedItemFromAppOps(code: Int, uid: Int, packageName: String, active: Boolean) {
37         log(LogLevel.INFO, {
38             int1 = code
39             int2 = uid
40             str1 = packageName
41             bool1 = active
42         }, {
43             "App Op: $int1 for $str1($int2), active=$bool1"
44         })
45     }
46 
logRetrievedPrivacyItemsListnull47     fun logRetrievedPrivacyItemsList(list: List<PrivacyItem>) {
48         log(LogLevel.INFO, {
49             str1 = listToString(list)
50         }, {
51             "Retrieved list to process: $str1"
52         })
53     }
54 
logPrivacyItemsToHoldnull55     fun logPrivacyItemsToHold(list: List<PrivacyItem>) {
56         log(LogLevel.DEBUG, {
57             str1 = listToString(list)
58         }, {
59             "Holding items: $str1"
60         })
61     }
62 
logPrivacyItemsUpdateSchedulednull63     fun logPrivacyItemsUpdateScheduled(delay: Long) {
64         log(LogLevel.INFO, {
65             val scheduledFor = System.currentTimeMillis() + delay
66             val formattedTimestamp = DATE_FORMAT.format(scheduledFor)
67             str1 = formattedTimestamp
68         }, {
69             "Updating items scheduled for $str1"
70         })
71     }
72 
logCurrentProfilesChangednull73     fun logCurrentProfilesChanged(profiles: List<Int>) {
74         log(LogLevel.INFO, {
75             str1 = profiles.toString()
76         }, {
77             "Profiles changed: $str1"
78         })
79     }
80 
logChipVisiblenull81     fun logChipVisible(visible: Boolean) {
82         log(LogLevel.INFO, {
83             bool1 = visible
84         }, {
85             "Chip visible: $bool1"
86         })
87     }
88 
logStatusBarIconsVisiblenull89     fun logStatusBarIconsVisible(
90         showCamera: Boolean,
91         showMicrophone: Boolean,
92         showLocation: Boolean
93     ) {
94         log(LogLevel.INFO, {
95             bool1 = showCamera
96             bool2 = showMicrophone
97             bool3 = showLocation
98         }, {
99             "Status bar icons visible: camera=$bool1, microphone=$bool2, location=$bool3"
100         })
101     }
102 
logUnfilteredPermGroupUsagenull103     fun logUnfilteredPermGroupUsage(contents: List<PermGroupUsage>) {
104         log(LogLevel.DEBUG, {
105             str1 = contents.toString()
106         }, {
107             "Perm group usage: $str1"
108         })
109     }
110 
logShowDialogContentsnull111     fun logShowDialogContents(contents: List<PrivacyDialog.PrivacyElement>) {
112         log(LogLevel.INFO, {
113             str1 = contents.toString()
114         }, {
115             "Privacy dialog shown. Contents: $str1"
116         })
117     }
118 
logEmptyDialognull119     fun logEmptyDialog() {
120         log(LogLevel.WARNING, {}, {
121             "Trying to show an empty dialog"
122         })
123     }
124 
logPrivacyDialogDismissednull125     fun logPrivacyDialogDismissed() {
126         log(LogLevel.INFO, {}, {
127             "Privacy dialog dismissed"
128         })
129     }
130 
logStartSettingsActivityFromDialognull131     fun logStartSettingsActivityFromDialog(packageName: String, userId: Int) {
132         log(LogLevel.INFO, {
133             str1 = packageName
134             int1 = userId
135         }, {
136             "Start settings activity from dialog for packageName=$str1, userId=$int1 "
137         })
138     }
139 
listToStringnull140     private fun listToString(list: List<PrivacyItem>): String {
141         return list.joinToString(separator = ", ", transform = PrivacyItem::log)
142     }
143 
lognull144     private inline fun log(
145         logLevel: LogLevel,
146         initializer: LogMessage.() -> Unit,
147         noinline printer: LogMessage.() -> String
148     ) {
149         buffer.log(TAG, logLevel, initializer, printer)
150     }
151 }