From 4eb05b01a8ee634107fb1bbbfa8c30bf7b88d360 Mon Sep 17 00:00:00 2001 From: Milos Kozak Date: Thu, 5 May 2022 23:05:48 +0200 Subject: [PATCH] Wear: log API level --- .../wear/wearintegration/DataHandlerMobile.kt | 3 +- .../DataLayerListenerServiceMobile.kt | 28 +++++++++++-------- .../nightscout/shared/weardata/EventData.kt | 2 +- .../androidaps/comm/DataHandlerWear.kt | 3 +- 4 files changed, 20 insertions(+), 16 deletions(-) diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/general/wear/wearintegration/DataHandlerMobile.kt b/app/src/main/java/info/nightscout/androidaps/plugins/general/wear/wearintegration/DataHandlerMobile.kt index 045e147e2b..1f70a2cfc0 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/general/wear/wearintegration/DataHandlerMobile.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/wear/wearintegration/DataHandlerMobile.kt @@ -28,7 +28,6 @@ import info.nightscout.androidaps.plugins.iob.iobCobCalculator.GlucoseStatusProv import info.nightscout.androidaps.queue.Callback import info.nightscout.androidaps.receivers.ReceiverStatusStore import info.nightscout.androidaps.utils.* -import info.nightscout.androidaps.interfaces.ResourceHelper import info.nightscout.androidaps.utils.rx.AapsSchedulers import info.nightscout.androidaps.utils.wizard.BolusWizard import info.nightscout.androidaps.utils.wizard.QuickWizard @@ -46,7 +45,6 @@ import java.util.concurrent.TimeUnit import java.util.stream.Collectors import javax.inject.Inject import javax.inject.Singleton -import kotlin.collections.ArrayList import kotlin.math.abs import kotlin.math.min @@ -89,6 +87,7 @@ class DataHandlerMobile @Inject constructor( .observeOn(aapsSchedulers.io) .subscribe({ aapsLogger.debug(LTag.WEAR, "Pong received from ${it.sourceNodeId}") + fabricPrivacy.logCustom("WearOS_${it.apiLevel}") }, fabricPrivacy::logException) disposable += rxBus .toObservable(EventData.CancelBolus::class.java) diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/general/wear/wearintegration/DataLayerListenerServiceMobile.kt b/app/src/main/java/info/nightscout/androidaps/plugins/general/wear/wearintegration/DataLayerListenerServiceMobile.kt index 3bc626cd22..ed1ac23bdb 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/general/wear/wearintegration/DataLayerListenerServiceMobile.kt +++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/wear/wearintegration/DataLayerListenerServiceMobile.kt @@ -20,6 +20,7 @@ import info.nightscout.androidaps.plugins.general.wear.events.EventWearUpdateGui import info.nightscout.androidaps.receivers.ReceiverStatusStore import info.nightscout.androidaps.utils.DefaultValueHelper import info.nightscout.androidaps.interfaces.ResourceHelper +import info.nightscout.androidaps.utils.FabricPrivacy import info.nightscout.androidaps.utils.rx.AapsSchedulers import info.nightscout.androidaps.utils.wizard.QuickWizard import info.nightscout.shared.logging.AAPSLogger @@ -35,6 +36,7 @@ import javax.inject.Inject class DataLayerListenerServiceMobile : WearableListenerService() { @Inject lateinit var aapsLogger: AAPSLogger + @Inject lateinit var fabricPrivacy: FabricPrivacy @Inject lateinit var profileFunction: ProfileFunction @Inject lateinit var iobCobCalculator: IobCobCalculator @Inject lateinit var rh: ResourceHelper @@ -125,17 +127,21 @@ class DataLayerListenerServiceMobile : WearableListenerService() { private var transcriptionNodeId: String? = null private fun updateTranscriptionCapability() { - val capabilityInfo: CapabilityInfo = Tasks.await( - capabilityClient.getCapability(WEAR_CAPABILITY, CapabilityClient.FILTER_REACHABLE) - ) - aapsLogger.debug(LTag.WEAR, "Nodes: ${capabilityInfo.nodes.joinToString(", ") { it.displayName + "(" + it.id + ")" }}") - val bestNode = pickBestNodeId(capabilityInfo.nodes) - transcriptionNodeId = bestNode?.id - wearPlugin.connectedDevice = bestNode?.displayName ?: "---" - rxBus.send(EventWearUpdateGui()) - aapsLogger.debug(LTag.WEAR, "Selected node: ${bestNode?.displayName} $transcriptionNodeId") - rxBus.send(EventMobileToWear(EventData.ActionPing(System.currentTimeMillis()))) - rxBus.send(EventData.ActionResendData("WatchUpdaterService")) + try { + val capabilityInfo: CapabilityInfo = Tasks.await( + capabilityClient.getCapability(WEAR_CAPABILITY, CapabilityClient.FILTER_REACHABLE) + ) + aapsLogger.debug(LTag.WEAR, "Nodes: ${capabilityInfo.nodes.joinToString(", ") { it.displayName + "(" + it.id + ")" }}") + val bestNode = pickBestNodeId(capabilityInfo.nodes) + transcriptionNodeId = bestNode?.id + wearPlugin.connectedDevice = bestNode?.displayName ?: "---" + rxBus.send(EventWearUpdateGui()) + aapsLogger.debug(LTag.WEAR, "Selected node: ${bestNode?.displayName} $transcriptionNodeId") + rxBus.send(EventMobileToWear(EventData.ActionPing(System.currentTimeMillis()))) + rxBus.send(EventData.ActionResendData("WatchUpdaterService")) + } catch (e: Exception) { + fabricPrivacy.logCustom("WearOS_unsupported") + } } // Find a nearby node or pick one arbitrarily diff --git a/shared/src/main/java/info/nightscout/shared/weardata/EventData.kt b/shared/src/main/java/info/nightscout/shared/weardata/EventData.kt index 45db4cd8fc..f570743aa6 100644 --- a/shared/src/main/java/info/nightscout/shared/weardata/EventData.kt +++ b/shared/src/main/java/info/nightscout/shared/weardata/EventData.kt @@ -19,7 +19,7 @@ sealed class EventData : Event() { // Mobile <- Wear @Serializable - data class ActionPong(val timeStamp: Long) : EventData() + data class ActionPong(val timeStamp: Long, val apiLevel: Int) : EventData() @Serializable data class Error(val timeStamp: Long) : EventData() // ignored diff --git a/wear/src/main/java/info/nightscout/androidaps/comm/DataHandlerWear.kt b/wear/src/main/java/info/nightscout/androidaps/comm/DataHandlerWear.kt index af9967f71a..f816358b71 100644 --- a/wear/src/main/java/info/nightscout/androidaps/comm/DataHandlerWear.kt +++ b/wear/src/main/java/info/nightscout/androidaps/comm/DataHandlerWear.kt @@ -57,7 +57,7 @@ class DataHandlerWear @Inject constructor( .observeOn(aapsSchedulers.io) .subscribe { aapsLogger.debug(LTag.WEAR, "Ping received from ${it.sourceNodeId}") - rxBus.send(EventWearToMobile(EventData.ActionPong(System.currentTimeMillis()))) + rxBus.send(EventWearToMobile(EventData.ActionPong(System.currentTimeMillis(), Build.VERSION.SDK_INT))) } disposable += rxBus .toObservable(EventData.ConfirmAction::class.java) @@ -115,7 +115,6 @@ class DataHandlerWear @Inject constructor( .subscribe { aapsLogger.debug(LTag.WEAR, "Bolus progress received from ${it.sourceNodeId}") handleBolusProgress(it) - rxBus.send(EventWearToMobile(EventData.ActionPong(System.currentTimeMillis()))) } disposable += rxBus .toObservable(EventData.Status::class.java)