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 package com.android.server.bluetooth
17 
18 import android.bluetooth.IBluetooth
19 import android.bluetooth.IBluetoothCallback
20 import android.content.AttributionSource
21 import android.os.IBinder
22 import android.os.RemoteException
23 import com.android.server.bluetooth.BluetoothManagerService.timeToLog
24 
25 class AdapterBinder(rawBinder: IBinder) {
26     private val TAG = "AdapterBinder"
27     val adapterBinder: IBluetooth = IBluetooth.Stub.asInterface(rawBinder)
28     private val createdAt = System.currentTimeMillis()
29 
toStringnull30     override fun toString(): String =
31         "[Binder=" + adapterBinder.hashCode() + ", createdAt=" + timeToLog(createdAt) + "]"
32 
33     @Throws(RemoteException::class)
34     fun disable(source: AttributionSource) {
35         adapterBinder.disable(source)
36     }
37 
38     @Throws(RemoteException::class)
enablenull39     fun enable(quietMode: Boolean, source: AttributionSource) {
40         adapterBinder.enable(quietMode, source)
41     }
42 
43     @Throws(RemoteException::class)
getAddressnull44     fun getAddress(source: AttributionSource): String? {
45         return adapterBinder.getAddress(source)
46     }
47 
48     @Throws(RemoteException::class)
getNamenull49     fun getName(source: AttributionSource): String? {
50         return adapterBinder.getName(source)
51     }
52 
53     @Throws(RemoteException::class)
stopBlenull54     fun stopBle(source: AttributionSource) {
55         adapterBinder.stopBle(source)
56     }
57 
58     @Throws(RemoteException::class)
startBrEdrnull59     fun startBrEdr(source: AttributionSource) {
60         adapterBinder.startBrEdr(source)
61     }
62 
63     @Throws(RemoteException::class)
registerCallbacknull64     fun registerCallback(callback: IBluetoothCallback, source: AttributionSource) {
65         adapterBinder.registerCallback(callback, source)
66     }
67 
68     @Throws(RemoteException::class)
unregisterCallbacknull69     fun unregisterCallback(callback: IBluetoothCallback, source: AttributionSource) {
70         adapterBinder.unregisterCallback(callback, source)
71     }
72 
73     @Throws(RemoteException::class)
setForegroundUserIdnull74     fun setForegroundUserId(userId: Int, source: AttributionSource) {
75         adapterBinder.setForegroundUserId(userId, source)
76     }
77 
78     @Throws(RemoteException::class)
unregAllGattClientnull79     fun unregAllGattClient(source: AttributionSource) {
80         adapterBinder.unregAllGattClient(source)
81     }
82 
isMediaProfileConnectednull83     fun isMediaProfileConnected(source: AttributionSource): Boolean {
84         try {
85             return adapterBinder.isMediaProfileConnected(source)
86         } catch (ex: RemoteException) {
87             Log.e(TAG, "Error when calling isMediaProfileConnected", ex)
88         }
89         return false
90     }
91 
92     @Throws(RemoteException::class)
killBluetoothProcessnull93     fun killBluetoothProcess() {
94         adapterBinder.killBluetoothProcess()
95     }
96 }
97