From 363bda10d4f1e72c2c5e54f30d4a72b2f243c6e3 Mon Sep 17 00:00:00 2001 From: Miguel Matey Sanz Date: Thu, 1 Sep 2022 11:41:57 +0200 Subject: [PATCH] fix: use the correct sensorDelay for the SensorType.LOCATION --- .../android/collector-manager-impl.android.ts | 2 +- .../collection/collection-configuration.ts | 16 +++++++++++----- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/src/internal/collection/android/collector-manager-impl.android.ts b/src/internal/collection/android/collector-manager-impl.android.ts index ee367b3..dd378d4 100644 --- a/src/internal/collection/android/collector-manager-impl.android.ts +++ b/src/internal/collection/android/collector-manager-impl.android.ts @@ -71,7 +71,7 @@ export class CollectorManagerImpl implements CollectorManager { if (!hasCapability(node, sensor) || !this.isEnabled(sensor)) return; - const message = config ? configAsString(config) : configAsString(defaultCollectionConfiguration(sensor)); + const message = config ? configAsString(sensor, config) : configAsString(sensor, defaultCollectionConfiguration(sensor)); await this.messagingClient(sensor).sendStartMessage(node, message); } diff --git a/src/internal/collection/collection-configuration.ts b/src/internal/collection/collection-configuration.ts index d4b7f70..c3f52d7 100644 --- a/src/internal/collection/collection-configuration.ts +++ b/src/internal/collection/collection-configuration.ts @@ -23,21 +23,25 @@ export function defaultCollectionConfiguration(sensorType: SensorType): Collecti sensorInterval: NativeSensorDelay.NORMAL, batchSize: 50 }; - case SensorType.LOCATION: case SensorType.HEART_RATE: return { sensorInterval: NativeSensorDelay.NORMAL, batchSize: 5 }; + case SensorType.LOCATION: + return { + sensorInterval: 1000, + batchSize: 5 + }; } } -export function configAsString(collectionConfiguration: CollectionConfiguration) { - const intervalValue = sensorIntervalToNativeValue(collectionConfiguration.sensorInterval); +export function configAsString(sensor: SensorType, collectionConfiguration: CollectionConfiguration) { + const intervalValue = sensorIntervalToNativeValue(sensor, collectionConfiguration.sensorInterval); return `${intervalValue}#${collectionConfiguration.batchSize}`; } -function sensorIntervalToNativeValue(sensorInterval: SensorInterval) { +function sensorIntervalToNativeValue(sensor: SensorType, sensorInterval: SensorInterval) { switch (sensorInterval) { case NativeSensorDelay.UI: case NativeSensorDelay.NORMAL: @@ -45,6 +49,8 @@ function sensorIntervalToNativeValue(sensorInterval: SensorInterval) { case NativeSensorDelay.FASTEST: return sensorInterval; default: - return sensorInterval * 1000; // Native API expects interval in microseconds + return sensor === SensorType.LOCATION + ? sensorInterval + : sensorInterval * 1000; // Native sensors API expects interval in microseconds } }