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