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 24 class AdapterBinder(rawBinder: IBinder) { 25 private val TAG = "AdapterBinder" 26 val adapterBinder: IBluetooth = IBluetooth.Stub.asInterface(rawBinder) 27 private val createdAt = System.currentTimeMillis() 28 toStringnull29 override fun toString(): String = 30 "[Binder=" + 31 adapterBinder.hashCode() + 32 ", createdAt=" + 33 Log.timeToStringWithZone(createdAt) + 34 "]" 35 36 @Throws(RemoteException::class) 37 fun onToBleOn(source: AttributionSource) { 38 adapterBinder.onToBleOn(source) 39 } 40 41 @Throws(RemoteException::class) offToBleOnnull42 fun offToBleOn(quietMode: Boolean, source: AttributionSource) { 43 adapterBinder.offToBleOn(quietMode, source) 44 } 45 46 @Throws(RemoteException::class) getAddressnull47 fun getAddress(source: AttributionSource): String? { 48 return adapterBinder.getAddress(source) 49 } 50 51 @Throws(RemoteException::class) getNamenull52 fun getName(source: AttributionSource): String? { 53 return adapterBinder.getName(source) 54 } 55 56 @Throws(RemoteException::class) bleOnToOffnull57 fun bleOnToOff(source: AttributionSource) { 58 adapterBinder.bleOnToOff(source) 59 } 60 61 @Throws(RemoteException::class) bleOnToOnnull62 fun bleOnToOn(source: AttributionSource) { 63 adapterBinder.bleOnToOn(source) 64 } 65 66 @Throws(RemoteException::class) registerCallbacknull67 fun registerCallback(callback: IBluetoothCallback, source: AttributionSource) { 68 adapterBinder.registerCallback(callback, source) 69 } 70 71 @Throws(RemoteException::class) unregisterCallbacknull72 fun unregisterCallback(callback: IBluetoothCallback, source: AttributionSource) { 73 adapterBinder.unregisterCallback(callback, source) 74 } 75 76 @Throws(RemoteException::class) setForegroundUserIdnull77 fun setForegroundUserId(userId: Int, source: AttributionSource) { 78 adapterBinder.setForegroundUserId(userId, source) 79 } 80 81 @Throws(RemoteException::class) unregAllGattClientnull82 fun unregAllGattClient(source: AttributionSource) { 83 adapterBinder.unregAllGattClient(source) 84 } 85 isMediaProfileConnectednull86 fun isMediaProfileConnected(source: AttributionSource): Boolean { 87 try { 88 return adapterBinder.isMediaProfileConnected(source) 89 } catch (ex: RemoteException) { 90 Log.e(TAG, "Error when calling isMediaProfileConnected", ex) 91 } 92 return false 93 } 94 95 @Throws(RemoteException::class) killBluetoothProcessnull96 fun killBluetoothProcess() { 97 adapterBinder.killBluetoothProcess() 98 } 99 } 100