Fix not working disconnect on CSC profile

This commit is contained in:
Sylwester Zieliński
2022-02-04 11:13:09 +01:00
parent bd2a7851ff
commit f6a188ae3d
8 changed files with 13 additions and 18 deletions

View File

@@ -26,6 +26,7 @@ import android.bluetooth.BluetoothDevice
import android.content.Intent
import android.os.Handler
import android.os.IBinder
import android.util.Log
import android.widget.Toast
import dagger.hilt.android.AndroidEntryPoint
import kotlinx.coroutines.Dispatchers
@@ -78,7 +79,6 @@ abstract class BleProfileService : Service() {
override fun onDeviceFailedToConnect(device: BluetoothDevice, reason: Int) {
super.onDeviceFailedToConnect(device, reason)
_status.value = BleServiceStatus.DISCONNECTED
stopSelf()
}
override fun onDeviceDisconnected(device: BluetoothDevice, reason: Int) {

View File

@@ -115,7 +115,7 @@ internal class BPSManager @Inject constructor(
bpmCharacteristic = service.getCharacteristic(BPM_CHARACTERISTIC_UUID)
icpCharacteristic = service.getCharacteristic(ICP_CHARACTERISTIC_UUID)
}
return bpmCharacteristic != null
return bpmCharacteristic != null && icpCharacteristic != null
}
override fun onServicesInvalidated() {}

View File

@@ -76,7 +76,7 @@ internal class CGMManager(
private var sessionStartTime: Long = 0
private val exceptionHandler = CoroutineExceptionHandler { _, t->
private val exceptionHandler = CoroutineExceptionHandler { _, t ->
Log.e("COROUTINE-EXCEPTION", "Uncaught exception", t)
}
@@ -124,7 +124,8 @@ internal class CGMManager(
when (it.requestCode) {
CGMSpecificOpsControlPointCallback.CGM_OP_CODE_START_SESSION -> sessionStartTime =
System.currentTimeMillis()
CGMSpecificOpsControlPointCallback.CGM_OP_CODE_STOP_SESSION -> sessionStartTime = 0
CGMSpecificOpsControlPointCallback.CGM_OP_CODE_STOP_SESSION -> sessionStartTime =
0
}
} else {
when (it.requestCode) {
@@ -132,7 +133,8 @@ internal class CGMManager(
if (it.errorCode == CGMSpecificOpsControlPointCallback.CGM_ERROR_PROCEDURE_NOT_COMPLETED) {
sessionStartTime = 0
}
CGMSpecificOpsControlPointCallback.CGM_OP_CODE_STOP_SESSION -> sessionStartTime = 0
CGMSpecificOpsControlPointCallback.CGM_OP_CODE_STOP_SESSION -> sessionStartTime =
0
}
}
}.launchIn(scope)
@@ -231,7 +233,7 @@ internal class CGMManager(
)
recordAccessControlPointCharacteristic = service.getCharacteristic(RACP_UUID)
}
return cgmMeasurementCharacteristic != null && cgmSpecificOpsControlPointCharacteristic != null && recordAccessControlPointCharacteristic != null
return cgmMeasurementCharacteristic != null && cgmSpecificOpsControlPointCharacteristic != null && recordAccessControlPointCharacteristic != null && cgmStatusCharacteristic != null && cgmFeatureCharacteristic != null
}
override fun onServicesInvalidated() {}

View File

@@ -97,11 +97,9 @@ internal class CSCManager(
public override fun isRequiredServiceSupported(gatt: BluetoothGatt): Boolean {
val service = gatt.getService(CSC_SERVICE_UUID)
if (service != null) {
cscMeasurementCharacteristic = service.getCharacteristic(
CSC_MEASUREMENT_CHARACTERISTIC_UUID
)
cscMeasurementCharacteristic = service.getCharacteristic(CSC_MEASUREMENT_CHARACTERISTIC_UUID)
}
return true
return cscMeasurementCharacteristic != null
}
override fun onDeviceDisconnected() {

View File

@@ -6,7 +6,6 @@ import kotlinx.coroutines.flow.onEach
import no.nordicsemi.android.csc.data.CSCRepository
import no.nordicsemi.android.csc.data.DisconnectCommand
import no.nordicsemi.android.csc.data.SetWheelSizeCommand
import no.nordicsemi.android.service.BleManagerStatus
import no.nordicsemi.android.service.ForegroundBleService
import no.nordicsemi.android.utils.exhaustive
import javax.inject.Inject

View File

@@ -189,7 +189,7 @@ internal class GLSManager @Inject constructor(
glucoseMeasurementContextCharacteristic = service.getCharacteristic(GM_CONTEXT_CHARACTERISTIC)
recordAccessControlPointCharacteristic = service.getCharacteristic(RACP_CHARACTERISTIC)
}
return glucoseMeasurementCharacteristic != null && recordAccessControlPointCharacteristic != null
return glucoseMeasurementCharacteristic != null && recordAccessControlPointCharacteristic != null && glucoseMeasurementContextCharacteristic != null
}
override fun onServicesInvalidated() {}

View File

@@ -102,9 +102,7 @@ internal class HRSManager(context: Context, private val dataHolder: HRSRepositor
override fun isRequiredServiceSupported(gatt: BluetoothGatt): Boolean {
val service = gatt.getService(HRS_SERVICE_UUID)
if (service != null) {
heartRateCharacteristic = service.getCharacteristic(
HEART_RATE_MEASUREMENT_CHARACTERISTIC_UUID
)
heartRateCharacteristic = service.getCharacteristic(HEART_RATE_MEASUREMENT_CHARACTERISTIC_UUID)
}
return heartRateCharacteristic != null
}

View File

@@ -77,9 +77,7 @@ internal class RSCSManager internal constructor(
public override fun isRequiredServiceSupported(gatt: BluetoothGatt): Boolean {
val service = gatt.getService(RSCS_SERVICE_UUID)
if (service != null) {
rscMeasurementCharacteristic = service.getCharacteristic(
RSC_MEASUREMENT_CHARACTERISTIC_UUID
)
rscMeasurementCharacteristic = service.getCharacteristic(RSC_MEASUREMENT_CHARACTERISTIC_UUID)
}
return rscMeasurementCharacteristic != null
}