From 7ffe1e28f540f53d05f22b15ecdf558a5068e7ac Mon Sep 17 00:00:00 2001 From: Milos Kozak Date: Wed, 21 Sep 2022 15:26:44 +0200 Subject: [PATCH] Suppress BT deprecation comming from targeting Andorid 13 (API 33) --- .../androidaps/danars/services/BLEComm.kt | 27 +++---------------- .../diaconn/service/BLECommonService.kt | 3 +++ .../driver/comm/callbacks/BleCommCallbacks.kt | 3 +++ .../pump/omnipod/dash/driver/comm/io/BleIO.kt | 8 +++--- .../common/hw/rileylink/ble/RileyLinkBLE.kt | 7 ++++- .../hw/rileylink/ble/device/OrangeLinkImpl.kt | 5 ++-- .../CharacteristicReadOperation.java | 1 + .../CharacteristicWriteOperation.java | 1 + .../operations/DescriptorWriteOperation.java | 1 + 9 files changed, 23 insertions(+), 33 deletions(-) diff --git a/danars/src/main/java/info/nightscout/androidaps/danars/services/BLEComm.kt b/danars/src/main/java/info/nightscout/androidaps/danars/services/BLEComm.kt index d3ad649bd9..1da8076216 100644 --- a/danars/src/main/java/info/nightscout/androidaps/danars/services/BLEComm.kt +++ b/danars/src/main/java/info/nightscout/androidaps/danars/services/BLEComm.kt @@ -213,35 +213,12 @@ class BLEComm @Inject internal constructor( @SuppressLint("MissingPermission") @Synchronized fun close() { - /* - if (!encryptedDataRead && !encryptedCommandSent) { - // there was no response from pump before started encryption - // assume pairing is invalid - val lastClearRequest = sp.getLong(R.string.key_rs_last_clear_key_request, 0) - if (lastClearRequest != 0L && dateUtil.isOlderThan(lastClearRequest, 5)) { - ToastUtils.showToastInUiThread(context, R.string.invalidpairing) - danaRSPlugin.changePump() - sp.getStringOrNull(R.string.key_danars_address, null)?.let { address -> - bluetoothAdapter?.getRemoteDevice(address)?.let { device -> - try { - aapsLogger.debug(LTag.PUMPBTCOMM, "Removing bond") - device::class.java.getMethod("removeBond").invoke(device) - } catch (e: Exception) { - aapsLogger.error("Removing bond has been failed. ${e.message}") - } - } - } - } else if (lastClearRequest == 0L) { - aapsLogger.error("Clearing pairing keys postponed") - sp.putLong(R.string.key_rs_last_clear_key_request, dateUtil.now()) - } - } - */ aapsLogger.debug(LTag.PUMPBTCOMM, "BluetoothAdapter close") bluetoothGatt?.close() bluetoothGatt = null } + @Suppress("DEPRECATION", "OVERRIDE_DEPRECATION") private val mGattCallback: BluetoothGattCallback = object : BluetoothGattCallback() { override fun onConnectionStateChange(gatt: BluetoothGatt, status: Int, newState: Int) { onConnectionStateChangeSynchronized(gatt, newState) // call it synchronized @@ -289,6 +266,7 @@ class BLEComm @Inject internal constructor( } } + @Suppress("DEPRECATION") @SuppressLint("MissingPermission") @Synchronized private fun setCharacteristicNotification(characteristic: BluetoothGattCharacteristic?, enabled: Boolean) { @@ -309,6 +287,7 @@ class BLEComm @Inject internal constructor( } } + @Suppress("DEPRECATION") @SuppressLint("MissingPermission") @Synchronized private fun writeCharacteristicNoResponse(characteristic: BluetoothGattCharacteristic, data: ByteArray) { diff --git a/diaconn/src/main/java/info/nightscout/androidaps/diaconn/service/BLECommonService.kt b/diaconn/src/main/java/info/nightscout/androidaps/diaconn/service/BLECommonService.kt index 44b53851e7..556e8dc38f 100644 --- a/diaconn/src/main/java/info/nightscout/androidaps/diaconn/service/BLECommonService.kt +++ b/diaconn/src/main/java/info/nightscout/androidaps/diaconn/service/BLECommonService.kt @@ -144,6 +144,7 @@ class BLECommonService @Inject internal constructor( bluetoothGatt = null } + @Suppress("OVERRIDE_DEPRECATION", "DEPRECATION") private val mGattCallback: BluetoothGattCallback = object : BluetoothGattCallback() { override fun onConnectionStateChange(gatt: BluetoothGatt, status: Int, newState: Int) { onConnectionStateChangeSynchronized(gatt, newState) // call it synchronized @@ -179,6 +180,7 @@ class BLECommonService @Inject internal constructor( } } + @Suppress("DEPRECATION") @SuppressLint("MissingPermission") @Synchronized private fun writeCharacteristicNoResponse(characteristic: BluetoothGattCharacteristic, data: ByteArray) { @@ -218,6 +220,7 @@ class BLECommonService @Inject internal constructor( return bluetoothGatt?.services } + @Suppress("DEPRECATION") @SuppressLint("MissingPermission") @Synchronized private fun findCharacteristic() { diff --git a/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/driver/comm/callbacks/BleCommCallbacks.kt b/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/driver/comm/callbacks/BleCommCallbacks.kt index 3724341c89..226fbe9dce 100644 --- a/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/driver/comm/callbacks/BleCommCallbacks.kt +++ b/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/driver/comm/callbacks/BleCommCallbacks.kt @@ -103,6 +103,7 @@ class BleCommCallbacks( } } + @Suppress("DEPRECATION") override fun onCharacteristicWrite(gatt: BluetoothGatt, characteristic: BluetoothGattCharacteristic, status: Int) { aapsLogger.debug( LTag.PUMPBTCOMM, @@ -115,6 +116,7 @@ class BleCommCallbacks( onWrite(status, characteristic.uuid, characteristic.value) } + @Suppress("DEPRECATION", "OVERRIDE_DEPRECATION") override fun onCharacteristicChanged(gatt: BluetoothGatt, characteristic: BluetoothGattCharacteristic) { super.onCharacteristicChanged(gatt, characteristic) @@ -134,6 +136,7 @@ class BleCommCallbacks( } } + @Suppress("DEPRECATION") override fun onDescriptorWrite(gatt: BluetoothGatt, descriptor: BluetoothGattDescriptor, status: Int) { super.onDescriptorWrite(gatt, descriptor, status) diff --git a/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/driver/comm/io/BleIO.kt b/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/driver/comm/io/BleIO.kt index 0c93a2fc88..5e1974ea51 100644 --- a/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/driver/comm/io/BleIO.kt +++ b/omnipod-dash/src/main/java/info/nightscout/androidaps/plugins/pump/omnipod/dash/driver/comm/io/BleIO.kt @@ -24,7 +24,7 @@ data class BleSendErrorConfirming(val msg: String, val cause: Throwable? = null) open class BleIO( private val aapsLogger: AAPSLogger, - var characteristic: BluetoothGattCharacteristic, + private var characteristic: BluetoothGattCharacteristic, private val incomingPackets: BlockingQueue, private val gatt: BluetoothGatt, private val bleCommCallbacks: BleCommCallbacks, @@ -33,7 +33,6 @@ open class BleIO( /*** * - * @param characteristic where to read from(CMD or DATA) * @return a byte array with the received data or error */ fun receivePacket(timeoutMs: Long = DEFAULT_IO_TIMEOUT_MS): ByteArray? { @@ -51,10 +50,9 @@ open class BleIO( /*** * - * @param characteristic where to write to(CMD or DATA) * @param payload the data to send */ - @Suppress("ReturnCount") + @Suppress("ReturnCount", "DEPRECATION") fun sendAndConfirmPacket(payload: ByteArray): BleSendResult { aapsLogger.debug(LTag.PUMPBTCOMM, "BleIO: Sending on $type: ${payload.toHex()}") val set = characteristic.setValue(payload) @@ -103,7 +101,7 @@ open class BleIO( * This will signal the pod it can start sending back data * @return */ - fun readyToRead(): BleSendResult { + @Suppress("DEPRECATION") fun readyToRead(): BleSendResult { gatt.setCharacteristicNotification(characteristic, true) .assertTrue("enable notifications") diff --git a/rileylink/src/main/java/info/nightscout/androidaps/plugins/pump/common/hw/rileylink/ble/RileyLinkBLE.kt b/rileylink/src/main/java/info/nightscout/androidaps/plugins/pump/common/hw/rileylink/ble/RileyLinkBLE.kt index 09a7a68c49..bcb6630d9a 100644 --- a/rileylink/src/main/java/info/nightscout/androidaps/plugins/pump/common/hw/rileylink/ble/RileyLinkBLE.kt +++ b/rileylink/src/main/java/info/nightscout/androidaps/plugins/pump/common/hw/rileylink/ble/RileyLinkBLE.kt @@ -324,6 +324,7 @@ class RileyLinkBLE @Inject constructor( init { //orangeLink.rileyLinkBLE = this; bluetoothGattCallback = object : BluetoothGattCallback() { + @Suppress("DEPRECATION", "OVERRIDE_DEPRECATION") override fun onCharacteristicChanged(gatt: BluetoothGatt, characteristic: BluetoothGattCharacteristic) { super.onCharacteristicChanged(gatt, characteristic) if (gattDebugEnabled) { @@ -333,9 +334,10 @@ class RileyLinkBLE @Inject constructor( } if (characteristic.uuid == UUID.fromString(GattAttributes.CHARA_RADIO_RESPONSE_COUNT)) radioResponseCountNotified?.run() - orangeLink.onCharacteristicChanged(characteristic) + orangeLink.onCharacteristicChanged(characteristic, characteristic.value) } + @Suppress("OVERRIDE_DEPRECATION", "DEPRECATION") override fun onCharacteristicRead(gatt: BluetoothGatt, characteristic: BluetoothGattCharacteristic, status: Int) { super.onCharacteristicRead(gatt, characteristic, status) val statusMessage = getGattStatusMessage(status) @@ -344,6 +346,7 @@ class RileyLinkBLE @Inject constructor( mCurrentOperation?.gattOperationCompletionCallback(characteristic.uuid, characteristic.value) } + @Suppress("DEPRECATION") override fun onCharacteristicWrite(gatt: BluetoothGatt, characteristic: BluetoothGattCharacteristic, status: Int) { super.onCharacteristicWrite(gatt, characteristic, status) val uuidString = GattAttributes.lookup(characteristic.uuid) @@ -387,6 +390,7 @@ class RileyLinkBLE @Inject constructor( } } + @Suppress("DEPRECATION") override fun onDescriptorWrite(gatt: BluetoothGatt, descriptor: BluetoothGattDescriptor, status: Int) { super.onDescriptorWrite(gatt, descriptor, status) if (gattDebugEnabled) @@ -394,6 +398,7 @@ class RileyLinkBLE @Inject constructor( mCurrentOperation?.gattOperationCompletionCallback(descriptor.uuid, descriptor.value) } + @Suppress("OVERRIDE_DEPRECATION", "DEPRECATION") override fun onDescriptorRead(gatt: BluetoothGatt, descriptor: BluetoothGattDescriptor, status: Int) { super.onDescriptorRead(gatt, descriptor, status) mCurrentOperation?.gattOperationCompletionCallback(descriptor.uuid, descriptor.value) diff --git a/rileylink/src/main/java/info/nightscout/androidaps/plugins/pump/common/hw/rileylink/ble/device/OrangeLinkImpl.kt b/rileylink/src/main/java/info/nightscout/androidaps/plugins/pump/common/hw/rileylink/ble/device/OrangeLinkImpl.kt index 4cfa13000b..0f1ab68f74 100644 --- a/rileylink/src/main/java/info/nightscout/androidaps/plugins/pump/common/hw/rileylink/ble/device/OrangeLinkImpl.kt +++ b/rileylink/src/main/java/info/nightscout/androidaps/plugins/pump/common/hw/rileylink/ble/device/OrangeLinkImpl.kt @@ -32,11 +32,10 @@ class OrangeLinkImpl @Inject constructor( lateinit var rileyLinkBLE: RileyLinkBLE - fun onCharacteristicChanged(characteristic: BluetoothGattCharacteristic) { + fun onCharacteristicChanged(characteristic: BluetoothGattCharacteristic, data: ByteArray) { if (characteristic.uuid.toString() == GattAttributes.CHARA_NOTIFICATION_ORANGE) { - val data = characteristic.value val first = 0xff and data[0].toInt() - aapsLogger.info(LTag.PUMPBTCOMM, "OrangeLinkImpl: onCharacteristicChanged ${ByteUtil.shortHexString(characteristic.value)}=====$first") + aapsLogger.info(LTag.PUMPBTCOMM, "OrangeLinkImpl: onCharacteristicChanged ${ByteUtil.shortHexString(data)}=====$first") val fv = data[3].toString() + "." + data[4] val hv = data[5].toString() + "." + data[6] rileyLinkServiceData.versionOrangeFirmware = fv diff --git a/rileylink/src/main/java/info/nightscout/androidaps/plugins/pump/common/hw/rileylink/ble/operations/CharacteristicReadOperation.java b/rileylink/src/main/java/info/nightscout/androidaps/plugins/pump/common/hw/rileylink/ble/operations/CharacteristicReadOperation.java index c85dec375c..9b96c498cc 100644 --- a/rileylink/src/main/java/info/nightscout/androidaps/plugins/pump/common/hw/rileylink/ble/operations/CharacteristicReadOperation.java +++ b/rileylink/src/main/java/info/nightscout/androidaps/plugins/pump/common/hw/rileylink/ble/operations/CharacteristicReadOperation.java @@ -29,6 +29,7 @@ public class CharacteristicReadOperation extends BLECommOperation { } + @SuppressWarnings({"deprecation"}) @Override public void execute(RileyLinkBLE comm) { gatt.readCharacteristic(characteristic); diff --git a/rileylink/src/main/java/info/nightscout/androidaps/plugins/pump/common/hw/rileylink/ble/operations/CharacteristicWriteOperation.java b/rileylink/src/main/java/info/nightscout/androidaps/plugins/pump/common/hw/rileylink/ble/operations/CharacteristicWriteOperation.java index 843e4e9816..802057c986 100644 --- a/rileylink/src/main/java/info/nightscout/androidaps/plugins/pump/common/hw/rileylink/ble/operations/CharacteristicWriteOperation.java +++ b/rileylink/src/main/java/info/nightscout/androidaps/plugins/pump/common/hw/rileylink/ble/operations/CharacteristicWriteOperation.java @@ -30,6 +30,7 @@ public class CharacteristicWriteOperation extends BLECommOperation { } + @SuppressWarnings({"deprecation"}) @Override public void execute(RileyLinkBLE comm) { diff --git a/rileylink/src/main/java/info/nightscout/androidaps/plugins/pump/common/hw/rileylink/ble/operations/DescriptorWriteOperation.java b/rileylink/src/main/java/info/nightscout/androidaps/plugins/pump/common/hw/rileylink/ble/operations/DescriptorWriteOperation.java index b2fe8e55a5..1df2cc0a58 100644 --- a/rileylink/src/main/java/info/nightscout/androidaps/plugins/pump/common/hw/rileylink/ble/operations/DescriptorWriteOperation.java +++ b/rileylink/src/main/java/info/nightscout/androidaps/plugins/pump/common/hw/rileylink/ble/operations/DescriptorWriteOperation.java @@ -36,6 +36,7 @@ public class DescriptorWriteOperation extends BLECommOperation { } + @SuppressWarnings({"deprecation"}) @Override public void execute(RileyLinkBLE comm) { descr.setValue(value);