From f6a188ae3d708574139cdd007ce2110ff64cb214 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sylwester=20Zieli=C5=84ski?= Date: Fri, 4 Feb 2022 11:13:09 +0100 Subject: [PATCH] Fix not working disconnect on CSC profile --- .../no/nordicsemi/android/service/BleProfileService.kt | 2 +- .../no/nordicsemi/android/bps/repository/BPSManager.kt | 2 +- .../nordicsemi/android/cgms/repository/CGMManager.kt | 10 ++++++---- .../no/nordicsemi/android/csc/repository/CSCManager.kt | 6 ++---- .../no/nordicsemi/android/csc/repository/CSCService.kt | 1 - .../no/nordicsemi/android/gls/repository/GLSManager.kt | 2 +- .../no/nordicsemi/android/hrs/service/HRSManager.kt | 4 +--- .../nordicsemi/android/rscs/repository/RSCSManager.kt | 4 +--- 8 files changed, 13 insertions(+), 18 deletions(-) diff --git a/lib_service/src/main/java/no/nordicsemi/android/service/BleProfileService.kt b/lib_service/src/main/java/no/nordicsemi/android/service/BleProfileService.kt index 7e674d39..15760d1e 100644 --- a/lib_service/src/main/java/no/nordicsemi/android/service/BleProfileService.kt +++ b/lib_service/src/main/java/no/nordicsemi/android/service/BleProfileService.kt @@ -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) { diff --git a/profile_bps/src/main/java/no/nordicsemi/android/bps/repository/BPSManager.kt b/profile_bps/src/main/java/no/nordicsemi/android/bps/repository/BPSManager.kt index bb455fe1..95de9f53 100644 --- a/profile_bps/src/main/java/no/nordicsemi/android/bps/repository/BPSManager.kt +++ b/profile_bps/src/main/java/no/nordicsemi/android/bps/repository/BPSManager.kt @@ -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() {} diff --git a/profile_cgms/src/main/java/no/nordicsemi/android/cgms/repository/CGMManager.kt b/profile_cgms/src/main/java/no/nordicsemi/android/cgms/repository/CGMManager.kt index 6e6dbef2..abaafb07 100644 --- a/profile_cgms/src/main/java/no/nordicsemi/android/cgms/repository/CGMManager.kt +++ b/profile_cgms/src/main/java/no/nordicsemi/android/cgms/repository/CGMManager.kt @@ -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() {} diff --git a/profile_csc/src/main/java/no/nordicsemi/android/csc/repository/CSCManager.kt b/profile_csc/src/main/java/no/nordicsemi/android/csc/repository/CSCManager.kt index df75637f..aac475c0 100644 --- a/profile_csc/src/main/java/no/nordicsemi/android/csc/repository/CSCManager.kt +++ b/profile_csc/src/main/java/no/nordicsemi/android/csc/repository/CSCManager.kt @@ -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() { diff --git a/profile_csc/src/main/java/no/nordicsemi/android/csc/repository/CSCService.kt b/profile_csc/src/main/java/no/nordicsemi/android/csc/repository/CSCService.kt index 2ece5e23..6cf4b723 100644 --- a/profile_csc/src/main/java/no/nordicsemi/android/csc/repository/CSCService.kt +++ b/profile_csc/src/main/java/no/nordicsemi/android/csc/repository/CSCService.kt @@ -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 diff --git a/profile_gls/src/main/java/no/nordicsemi/android/gls/repository/GLSManager.kt b/profile_gls/src/main/java/no/nordicsemi/android/gls/repository/GLSManager.kt index 363001a4..e98eff16 100644 --- a/profile_gls/src/main/java/no/nordicsemi/android/gls/repository/GLSManager.kt +++ b/profile_gls/src/main/java/no/nordicsemi/android/gls/repository/GLSManager.kt @@ -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() {} diff --git a/profile_hrs/src/main/java/no/nordicsemi/android/hrs/service/HRSManager.kt b/profile_hrs/src/main/java/no/nordicsemi/android/hrs/service/HRSManager.kt index 464b8d8b..2907e2fc 100644 --- a/profile_hrs/src/main/java/no/nordicsemi/android/hrs/service/HRSManager.kt +++ b/profile_hrs/src/main/java/no/nordicsemi/android/hrs/service/HRSManager.kt @@ -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 } diff --git a/profile_rscs/src/main/java/no/nordicsemi/android/rscs/repository/RSCSManager.kt b/profile_rscs/src/main/java/no/nordicsemi/android/rscs/repository/RSCSManager.kt index 307e9f71..42451f36 100644 --- a/profile_rscs/src/main/java/no/nordicsemi/android/rscs/repository/RSCSManager.kt +++ b/profile_rscs/src/main/java/no/nordicsemi/android/rscs/repository/RSCSManager.kt @@ -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 }