mirror of
https://github.com/aljazceru/Android-nRF-Toolbox.git
synced 2026-01-09 01:34:22 +01:00
Ensure bonding for CGMS profile
This commit is contained in:
@@ -19,6 +19,7 @@ import kotlinx.coroutines.launch
|
||||
import no.nordicsemi.android.log.timber.nRFLoggerTree
|
||||
import no.nordicsemi.android.service.NotificationService
|
||||
import no.nordicsemi.android.service.R
|
||||
import no.nordicsemi.android.toolbox.lib.utils.spec.CGMS_SERVICE_UUID
|
||||
import no.nordicsemi.android.toolbox.profile.manager.ServiceManager
|
||||
import no.nordicsemi.android.toolbox.profile.manager.ServiceManagerFactory
|
||||
import no.nordicsemi.android.ui.view.internal.DisconnectReason
|
||||
@@ -33,6 +34,7 @@ import no.nordicsemi.kotlin.ble.core.WriteType
|
||||
import timber.log.Timber
|
||||
import javax.inject.Inject
|
||||
import kotlin.uuid.ExperimentalUuidApi
|
||||
import kotlin.uuid.toKotlinUuid
|
||||
|
||||
@AndroidEntryPoint
|
||||
internal class ProfileService : NotificationService() {
|
||||
@@ -175,9 +177,8 @@ internal class ProfileService : NotificationService() {
|
||||
manager: ServiceManager
|
||||
) {
|
||||
try {
|
||||
// if (manager.requiresBonding(service.uuid) && peripheral.bondingState != BondState.BONDED) {
|
||||
// peripheral.ensureBonded()
|
||||
// }
|
||||
if (service.uuid == CGMS_SERVICE_UUID.toKotlinUuid())
|
||||
peripheral.ensureBonded()
|
||||
manager.observeServiceInteractions(peripheral.address, service, lifecycleScope)
|
||||
} catch (e: Exception) {
|
||||
Timber.tag("ObserveServices").e(e)
|
||||
@@ -258,11 +259,14 @@ internal class ProfileService : NotificationService() {
|
||||
getPeripheral(address)?.ensureBonded()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Helper extension function for bonding
|
||||
private suspend fun Peripheral.ensureBonded() {
|
||||
if (this.bondState.value == BondState.BONDED) return
|
||||
// Create bond and wait until bonded.
|
||||
createBond()
|
||||
/**
|
||||
* Ensures the peripheral is bonded. If not, initiates bonding.
|
||||
*/
|
||||
private suspend fun Peripheral.ensureBonded() {
|
||||
if (this.bondState.value == BondState.BONDED) return
|
||||
// Create bond and wait until bonded.
|
||||
createBond()
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user