From 694129576e0649515f66553c937625f78bce4561 Mon Sep 17 00:00:00 2001 From: Seb3thehacker Date: Sun, 29 Nov 2026 16:10:29 -0800 Subject: [PATCH] The location notice and GPS stop when the car is gone, even if a map app left its hold behind --- .../seb3thehacker/gearslip/car/CarServices.kt | 2 ++ .../gearslip/host/LocationKeepAlive.kt | 16 ++++++++++++++++ 2 files changed, 18 insertions(+) diff --git a/gearslip/src/main/java/app/seb3thehacker/gearslip/car/CarServices.kt b/gearslip/src/main/java/app/seb3thehacker/gearslip/car/CarServices.kt index c661dea..ab7979f 100644 --- a/gearslip/src/main/java/app/seb3thehacker/gearslip/car/CarServices.kt +++ b/gearslip/src/main/java/app/seb3thehacker/gearslip/car/CarServices.kt @@ -360,6 +360,8 @@ object CarServices { runCatching { nav.disconnect() } runCatching { media.disconnect() } runCatching { browse.disconnect() } + // After the map apps let go, so a hold one of them left behind can't keep the GPS on. + context?.let { app.seb3thehacker.gearslip.host.LocationKeepAlive.releaseAll(it) } CarAssistant.cancel() // About 900 MB that nothing needs once the car's gone. app.seb3thehacker.gearslip.speech.SpeechEngine.unload() diff --git a/gearslip/src/main/java/app/seb3thehacker/gearslip/host/LocationKeepAlive.kt b/gearslip/src/main/java/app/seb3thehacker/gearslip/host/LocationKeepAlive.kt index 0584d85..6236257 100644 --- a/gearslip/src/main/java/app/seb3thehacker/gearslip/host/LocationKeepAlive.kt +++ b/gearslip/src/main/java/app/seb3thehacker/gearslip/host/LocationKeepAlive.kt @@ -127,6 +127,22 @@ class LocationKeepAlive : Service() { } } + /** + * Lets go of every hold, for when the car is gone. A hold left behind kept the GPS on and + * the "sharing location" notice up with no car around, which drained the battery + * (issues #106, #160). The count goes back to zero too, so the next drive starts it again. + */ + fun releaseAll(context: Context) { + val app = context.applicationContext + main.post { + if (holders > 0) GearslipLog.w("location keep-alive: $holders hold(s) left at car shutdown, stopping it") + holders = 0 + waiting.clear() + app.stopService(Intent(app, LocationKeepAlive::class.java)) + state = State.OFF + } + } + private fun begin(context: Context) { val granted = context.checkSelfPermission(Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED