The location notice and GPS stop when the car is gone, even if a map app left its hold behind

This commit is contained in:
Seb3thehacker committed 2026-11-29 16:10:29 -08:00
1 parent 3b9e5b591e
commit 694129576e
2 files changed
+18

No files matched your search

@@ -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()
@@ -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