Suppress BT deprecation comming from targeting Andorid 13 (API 33)
This commit is contained in:
parent
a1c987695b
commit
7ffe1e28f5
9 changed files with 23 additions and 33 deletions
|
@ -213,35 +213,12 @@ class BLEComm @Inject internal constructor(
|
||||||
|
|
||||||
@SuppressLint("MissingPermission")
|
@SuppressLint("MissingPermission")
|
||||||
@Synchronized fun close() {
|
@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")
|
aapsLogger.debug(LTag.PUMPBTCOMM, "BluetoothAdapter close")
|
||||||
bluetoothGatt?.close()
|
bluetoothGatt?.close()
|
||||||
bluetoothGatt = null
|
bluetoothGatt = null
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Suppress("DEPRECATION", "OVERRIDE_DEPRECATION")
|
||||||
private val mGattCallback: BluetoothGattCallback = object : BluetoothGattCallback() {
|
private val mGattCallback: BluetoothGattCallback = object : BluetoothGattCallback() {
|
||||||
override fun onConnectionStateChange(gatt: BluetoothGatt, status: Int, newState: Int) {
|
override fun onConnectionStateChange(gatt: BluetoothGatt, status: Int, newState: Int) {
|
||||||
onConnectionStateChangeSynchronized(gatt, newState) // call it synchronized
|
onConnectionStateChangeSynchronized(gatt, newState) // call it synchronized
|
||||||
|
@ -289,6 +266,7 @@ class BLEComm @Inject internal constructor(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Suppress("DEPRECATION")
|
||||||
@SuppressLint("MissingPermission")
|
@SuppressLint("MissingPermission")
|
||||||
@Synchronized
|
@Synchronized
|
||||||
private fun setCharacteristicNotification(characteristic: BluetoothGattCharacteristic?, enabled: Boolean) {
|
private fun setCharacteristicNotification(characteristic: BluetoothGattCharacteristic?, enabled: Boolean) {
|
||||||
|
@ -309,6 +287,7 @@ class BLEComm @Inject internal constructor(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Suppress("DEPRECATION")
|
||||||
@SuppressLint("MissingPermission")
|
@SuppressLint("MissingPermission")
|
||||||
@Synchronized
|
@Synchronized
|
||||||
private fun writeCharacteristicNoResponse(characteristic: BluetoothGattCharacteristic, data: ByteArray) {
|
private fun writeCharacteristicNoResponse(characteristic: BluetoothGattCharacteristic, data: ByteArray) {
|
||||||
|
|
|
@ -144,6 +144,7 @@ class BLECommonService @Inject internal constructor(
|
||||||
bluetoothGatt = null
|
bluetoothGatt = null
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Suppress("OVERRIDE_DEPRECATION", "DEPRECATION")
|
||||||
private val mGattCallback: BluetoothGattCallback = object : BluetoothGattCallback() {
|
private val mGattCallback: BluetoothGattCallback = object : BluetoothGattCallback() {
|
||||||
override fun onConnectionStateChange(gatt: BluetoothGatt, status: Int, newState: Int) {
|
override fun onConnectionStateChange(gatt: BluetoothGatt, status: Int, newState: Int) {
|
||||||
onConnectionStateChangeSynchronized(gatt, newState) // call it synchronized
|
onConnectionStateChangeSynchronized(gatt, newState) // call it synchronized
|
||||||
|
@ -179,6 +180,7 @@ class BLECommonService @Inject internal constructor(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Suppress("DEPRECATION")
|
||||||
@SuppressLint("MissingPermission")
|
@SuppressLint("MissingPermission")
|
||||||
@Synchronized
|
@Synchronized
|
||||||
private fun writeCharacteristicNoResponse(characteristic: BluetoothGattCharacteristic, data: ByteArray) {
|
private fun writeCharacteristicNoResponse(characteristic: BluetoothGattCharacteristic, data: ByteArray) {
|
||||||
|
@ -218,6 +220,7 @@ class BLECommonService @Inject internal constructor(
|
||||||
return bluetoothGatt?.services
|
return bluetoothGatt?.services
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Suppress("DEPRECATION")
|
||||||
@SuppressLint("MissingPermission")
|
@SuppressLint("MissingPermission")
|
||||||
@Synchronized
|
@Synchronized
|
||||||
private fun findCharacteristic() {
|
private fun findCharacteristic() {
|
||||||
|
|
|
@ -103,6 +103,7 @@ class BleCommCallbacks(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Suppress("DEPRECATION")
|
||||||
override fun onCharacteristicWrite(gatt: BluetoothGatt, characteristic: BluetoothGattCharacteristic, status: Int) {
|
override fun onCharacteristicWrite(gatt: BluetoothGatt, characteristic: BluetoothGattCharacteristic, status: Int) {
|
||||||
aapsLogger.debug(
|
aapsLogger.debug(
|
||||||
LTag.PUMPBTCOMM,
|
LTag.PUMPBTCOMM,
|
||||||
|
@ -115,6 +116,7 @@ class BleCommCallbacks(
|
||||||
onWrite(status, characteristic.uuid, characteristic.value)
|
onWrite(status, characteristic.uuid, characteristic.value)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Suppress("DEPRECATION", "OVERRIDE_DEPRECATION")
|
||||||
override fun onCharacteristicChanged(gatt: BluetoothGatt, characteristic: BluetoothGattCharacteristic) {
|
override fun onCharacteristicChanged(gatt: BluetoothGatt, characteristic: BluetoothGattCharacteristic) {
|
||||||
super.onCharacteristicChanged(gatt, characteristic)
|
super.onCharacteristicChanged(gatt, characteristic)
|
||||||
|
|
||||||
|
@ -134,6 +136,7 @@ class BleCommCallbacks(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Suppress("DEPRECATION")
|
||||||
override fun onDescriptorWrite(gatt: BluetoothGatt, descriptor: BluetoothGattDescriptor, status: Int) {
|
override fun onDescriptorWrite(gatt: BluetoothGatt, descriptor: BluetoothGattDescriptor, status: Int) {
|
||||||
super.onDescriptorWrite(gatt, descriptor, status)
|
super.onDescriptorWrite(gatt, descriptor, status)
|
||||||
|
|
||||||
|
|
|
@ -24,7 +24,7 @@ data class BleSendErrorConfirming(val msg: String, val cause: Throwable? = null)
|
||||||
|
|
||||||
open class BleIO(
|
open class BleIO(
|
||||||
private val aapsLogger: AAPSLogger,
|
private val aapsLogger: AAPSLogger,
|
||||||
var characteristic: BluetoothGattCharacteristic,
|
private var characteristic: BluetoothGattCharacteristic,
|
||||||
private val incomingPackets: BlockingQueue<ByteArray>,
|
private val incomingPackets: BlockingQueue<ByteArray>,
|
||||||
private val gatt: BluetoothGatt,
|
private val gatt: BluetoothGatt,
|
||||||
private val bleCommCallbacks: BleCommCallbacks,
|
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
|
* @return a byte array with the received data or error
|
||||||
*/
|
*/
|
||||||
fun receivePacket(timeoutMs: Long = DEFAULT_IO_TIMEOUT_MS): ByteArray? {
|
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
|
* @param payload the data to send
|
||||||
*/
|
*/
|
||||||
@Suppress("ReturnCount")
|
@Suppress("ReturnCount", "DEPRECATION")
|
||||||
fun sendAndConfirmPacket(payload: ByteArray): BleSendResult {
|
fun sendAndConfirmPacket(payload: ByteArray): BleSendResult {
|
||||||
aapsLogger.debug(LTag.PUMPBTCOMM, "BleIO: Sending on $type: ${payload.toHex()}")
|
aapsLogger.debug(LTag.PUMPBTCOMM, "BleIO: Sending on $type: ${payload.toHex()}")
|
||||||
val set = characteristic.setValue(payload)
|
val set = characteristic.setValue(payload)
|
||||||
|
@ -103,7 +101,7 @@ open class BleIO(
|
||||||
* This will signal the pod it can start sending back data
|
* This will signal the pod it can start sending back data
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
fun readyToRead(): BleSendResult {
|
@Suppress("DEPRECATION") fun readyToRead(): BleSendResult {
|
||||||
gatt.setCharacteristicNotification(characteristic, true)
|
gatt.setCharacteristicNotification(characteristic, true)
|
||||||
.assertTrue("enable notifications")
|
.assertTrue("enable notifications")
|
||||||
|
|
||||||
|
|
|
@ -324,6 +324,7 @@ class RileyLinkBLE @Inject constructor(
|
||||||
init {
|
init {
|
||||||
//orangeLink.rileyLinkBLE = this;
|
//orangeLink.rileyLinkBLE = this;
|
||||||
bluetoothGattCallback = object : BluetoothGattCallback() {
|
bluetoothGattCallback = object : BluetoothGattCallback() {
|
||||||
|
@Suppress("DEPRECATION", "OVERRIDE_DEPRECATION")
|
||||||
override fun onCharacteristicChanged(gatt: BluetoothGatt, characteristic: BluetoothGattCharacteristic) {
|
override fun onCharacteristicChanged(gatt: BluetoothGatt, characteristic: BluetoothGattCharacteristic) {
|
||||||
super.onCharacteristicChanged(gatt, characteristic)
|
super.onCharacteristicChanged(gatt, characteristic)
|
||||||
if (gattDebugEnabled) {
|
if (gattDebugEnabled) {
|
||||||
|
@ -333,9 +334,10 @@ class RileyLinkBLE @Inject constructor(
|
||||||
}
|
}
|
||||||
if (characteristic.uuid == UUID.fromString(GattAttributes.CHARA_RADIO_RESPONSE_COUNT))
|
if (characteristic.uuid == UUID.fromString(GattAttributes.CHARA_RADIO_RESPONSE_COUNT))
|
||||||
radioResponseCountNotified?.run()
|
radioResponseCountNotified?.run()
|
||||||
orangeLink.onCharacteristicChanged(characteristic)
|
orangeLink.onCharacteristicChanged(characteristic, characteristic.value)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Suppress("OVERRIDE_DEPRECATION", "DEPRECATION")
|
||||||
override fun onCharacteristicRead(gatt: BluetoothGatt, characteristic: BluetoothGattCharacteristic, status: Int) {
|
override fun onCharacteristicRead(gatt: BluetoothGatt, characteristic: BluetoothGattCharacteristic, status: Int) {
|
||||||
super.onCharacteristicRead(gatt, characteristic, status)
|
super.onCharacteristicRead(gatt, characteristic, status)
|
||||||
val statusMessage = getGattStatusMessage(status)
|
val statusMessage = getGattStatusMessage(status)
|
||||||
|
@ -344,6 +346,7 @@ class RileyLinkBLE @Inject constructor(
|
||||||
mCurrentOperation?.gattOperationCompletionCallback(characteristic.uuid, characteristic.value)
|
mCurrentOperation?.gattOperationCompletionCallback(characteristic.uuid, characteristic.value)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Suppress("DEPRECATION")
|
||||||
override fun onCharacteristicWrite(gatt: BluetoothGatt, characteristic: BluetoothGattCharacteristic, status: Int) {
|
override fun onCharacteristicWrite(gatt: BluetoothGatt, characteristic: BluetoothGattCharacteristic, status: Int) {
|
||||||
super.onCharacteristicWrite(gatt, characteristic, status)
|
super.onCharacteristicWrite(gatt, characteristic, status)
|
||||||
val uuidString = GattAttributes.lookup(characteristic.uuid)
|
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) {
|
override fun onDescriptorWrite(gatt: BluetoothGatt, descriptor: BluetoothGattDescriptor, status: Int) {
|
||||||
super.onDescriptorWrite(gatt, descriptor, status)
|
super.onDescriptorWrite(gatt, descriptor, status)
|
||||||
if (gattDebugEnabled)
|
if (gattDebugEnabled)
|
||||||
|
@ -394,6 +398,7 @@ class RileyLinkBLE @Inject constructor(
|
||||||
mCurrentOperation?.gattOperationCompletionCallback(descriptor.uuid, descriptor.value)
|
mCurrentOperation?.gattOperationCompletionCallback(descriptor.uuid, descriptor.value)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Suppress("OVERRIDE_DEPRECATION", "DEPRECATION")
|
||||||
override fun onDescriptorRead(gatt: BluetoothGatt, descriptor: BluetoothGattDescriptor, status: Int) {
|
override fun onDescriptorRead(gatt: BluetoothGatt, descriptor: BluetoothGattDescriptor, status: Int) {
|
||||||
super.onDescriptorRead(gatt, descriptor, status)
|
super.onDescriptorRead(gatt, descriptor, status)
|
||||||
mCurrentOperation?.gattOperationCompletionCallback(descriptor.uuid, descriptor.value)
|
mCurrentOperation?.gattOperationCompletionCallback(descriptor.uuid, descriptor.value)
|
||||||
|
|
|
@ -32,11 +32,10 @@ class OrangeLinkImpl @Inject constructor(
|
||||||
|
|
||||||
lateinit var rileyLinkBLE: RileyLinkBLE
|
lateinit var rileyLinkBLE: RileyLinkBLE
|
||||||
|
|
||||||
fun onCharacteristicChanged(characteristic: BluetoothGattCharacteristic) {
|
fun onCharacteristicChanged(characteristic: BluetoothGattCharacteristic, data: ByteArray) {
|
||||||
if (characteristic.uuid.toString() == GattAttributes.CHARA_NOTIFICATION_ORANGE) {
|
if (characteristic.uuid.toString() == GattAttributes.CHARA_NOTIFICATION_ORANGE) {
|
||||||
val data = characteristic.value
|
|
||||||
val first = 0xff and data[0].toInt()
|
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 fv = data[3].toString() + "." + data[4]
|
||||||
val hv = data[5].toString() + "." + data[6]
|
val hv = data[5].toString() + "." + data[6]
|
||||||
rileyLinkServiceData.versionOrangeFirmware = fv
|
rileyLinkServiceData.versionOrangeFirmware = fv
|
||||||
|
|
|
@ -29,6 +29,7 @@ public class CharacteristicReadOperation extends BLECommOperation {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@SuppressWarnings({"deprecation"})
|
||||||
@Override
|
@Override
|
||||||
public void execute(RileyLinkBLE comm) {
|
public void execute(RileyLinkBLE comm) {
|
||||||
gatt.readCharacteristic(characteristic);
|
gatt.readCharacteristic(characteristic);
|
||||||
|
|
|
@ -30,6 +30,7 @@ public class CharacteristicWriteOperation extends BLECommOperation {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@SuppressWarnings({"deprecation"})
|
||||||
@Override
|
@Override
|
||||||
public void execute(RileyLinkBLE comm) {
|
public void execute(RileyLinkBLE comm) {
|
||||||
|
|
||||||
|
|
|
@ -36,6 +36,7 @@ public class DescriptorWriteOperation extends BLECommOperation {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@SuppressWarnings({"deprecation"})
|
||||||
@Override
|
@Override
|
||||||
public void execute(RileyLinkBLE comm) {
|
public void execute(RileyLinkBLE comm) {
|
||||||
descr.setValue(value);
|
descr.setValue(value);
|
||||||
|
|
Loading…
Reference in a new issue