From b75f730233c0a26afafae01c2a59ec4958216fee Mon Sep 17 00:00:00 2001 From: Daniel Shokouhi Date: Thu, 28 Oct 2021 10:53:45 -0700 Subject: [PATCH] Fix high accuracy command after sensor update logic was corrected (#1849) --- .../companion/android/notifications/MessagingService.kt | 3 ++- .../companion/android/sensors/LocationSensorManager.kt | 9 +++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/app/src/full/java/io/homeassistant/companion/android/notifications/MessagingService.kt b/app/src/full/java/io/homeassistant/companion/android/notifications/MessagingService.kt index d888b58f83b..7cb402f89db 100644 --- a/app/src/full/java/io/homeassistant/companion/android/notifications/MessagingService.kt +++ b/app/src/full/java/io/homeassistant/companion/android/notifications/MessagingService.kt @@ -537,7 +537,8 @@ class MessagingService : FirebaseMessagingService() { LocationSensorManager.setHighAccuracyModeSetting(applicationContext, true) } val intent = Intent(this, LocationSensorManager::class.java) - intent.action = LocationSensorManager.ACTION_REQUEST_LOCATION_UPDATES + intent.action = LocationSensorManager.ACTION_FORCE_HIGH_ACCURACY + intent.putExtra("command", title) applicationContext.sendBroadcast(intent) } COMMAND_ACTIVITY -> { diff --git a/app/src/full/java/io/homeassistant/companion/android/sensors/LocationSensorManager.kt b/app/src/full/java/io/homeassistant/companion/android/sensors/LocationSensorManager.kt index 5677078eeaa..65456148d84 100644 --- a/app/src/full/java/io/homeassistant/companion/android/sensors/LocationSensorManager.kt +++ b/app/src/full/java/io/homeassistant/companion/android/sensors/LocationSensorManager.kt @@ -62,6 +62,8 @@ class LocationSensorManager : BroadcastReceiver(), SensorManager { "io.homeassistant.companion.android.background.PROCESS_UPDATES" const val ACTION_PROCESS_GEO = "io.homeassistant.companion.android.background.PROCESS_GEOFENCE" + const val ACTION_FORCE_HIGH_ACCURACY = + "io.homeassistant.companion.android.background.FORCE_HIGH_ACCURACY" val backgroundLocation = SensorManager.BasicSensor( "location_background", @@ -139,6 +141,13 @@ class LocationSensorManager : BroadcastReceiver(), SensorManager { ACTION_PROCESS_LOCATION -> handleLocationUpdate(intent) ACTION_PROCESS_GEO -> handleGeoUpdate(intent) ACTION_REQUEST_ACCURATE_LOCATION_UPDATE -> requestSingleAccurateLocation() + ACTION_FORCE_HIGH_ACCURACY -> { + val intentData = intent.extras?.get("command")?.toString() + if (intentData == "turn_on") + startHighAccuracyService(getHighAccuracyModeIntervalSetting(latestContext)) + else if (intentData == "turn_off") + stopHighAccuracyService() + } else -> Log.w(TAG, "Unknown intent action: ${intent.action}!") } }