1 /*
2  * Copyright (C) 2022 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.bluetooth
18 
19 import com.android.systemui.dagger.SysUISingleton
20 import com.android.systemui.log.LogBuffer
21 import com.android.systemui.log.core.LogLevel
22 import com.android.systemui.log.dagger.BluetoothLog
23 import javax.inject.Inject
24 
25 /** Helper class for logging bluetooth events. */
26 @SysUISingleton
27 class BluetoothLogger @Inject constructor(@BluetoothLog private val logBuffer: LogBuffer) {
logActiveDeviceChangednull28     fun logActiveDeviceChanged(address: String?, profileId: Int) =
29         logBuffer.log(
30             TAG,
31             LogLevel.DEBUG,
32             {
33                 str1 = address
34                 int1 = profileId
35             },
<lambda>null36             { "ActiveDeviceChanged. address=$str1 profileId=$int1" }
37         )
38 
logDeviceConnectionStateChangednull39     fun logDeviceConnectionStateChanged(address: String?, state: String) =
40         logBuffer.log(
41             TAG,
42             LogLevel.DEBUG,
43             {
44                 str1 = address
45                 str2 = state
46             },
<lambda>null47             { "DeviceConnectionStateChanged. address=$str1 state=$str2" }
48         )
49 
logAclConnectionStateChangednull50     fun logAclConnectionStateChanged(address: String, state: String) =
51         logBuffer.log(
52             TAG,
53             LogLevel.DEBUG,
54             {
55                 str1 = address
56                 str2 = state
57             },
<lambda>null58             { "AclConnectionStateChanged. address=$str1 state=$str2" }
59         )
60 
logProfileConnectionStateChangednull61     fun logProfileConnectionStateChanged(address: String?, state: String, profileId: Int) =
62         logBuffer.log(
63             TAG,
64             LogLevel.DEBUG,
65             {
66                 str1 = address
67                 str2 = state
68                 int1 = profileId
69             },
<lambda>null70             { "ProfileConnectionStateChanged. address=$str1 state=$str2 profileId=$int1" }
71         )
72 
logStateChangenull73     fun logStateChange(state: String) =
74         logBuffer.log(
75             TAG,
76             LogLevel.DEBUG,
77             { str1 = state },
<lambda>null78             { "BluetoothStateChanged. state=$str1" }
79         )
80 
logBondStateChangenull81     fun logBondStateChange(address: String, state: Int) =
82         logBuffer.log(
83             TAG,
84             LogLevel.DEBUG,
85             {
86                 str1 = address
87                 int1 = state
88             },
<lambda>null89             { "DeviceBondStateChanged. address=$str1 state=$int1" }
90         )
91 
logDeviceAddednull92     fun logDeviceAdded(address: String) =
93         logBuffer.log(TAG, LogLevel.DEBUG, { str1 = address }, { "DeviceAdded. address=$str1" })
94 
logDeviceDeletednull95     fun logDeviceDeleted(address: String) =
96         logBuffer.log(TAG, LogLevel.DEBUG, { str1 = address }, { "DeviceDeleted. address=$str1" })
97 
logDeviceAttributesChangednull98     fun logDeviceAttributesChanged() =
99         logBuffer.log(TAG, LogLevel.DEBUG, {}, { "DeviceAttributesChanged." })
100 }
101 
102 private const val TAG = "BluetoothLog"
103