BootReceiver.kt
| 1 | package org.opentracker |
| 2 | |
| 3 | import android.content.BroadcastReceiver |
| 4 | import android.content.Context |
| 5 | import android.content.Intent |
| 6 | |
| 7 | /** Restarts tracking after a reboot or an app update, if it was on. */ |
| 8 | class BootReceiver : BroadcastReceiver() { |
| 9 | override fun onReceive(context: Context, intent: Intent) { |
| 10 | if (intent.action != Intent.ACTION_BOOT_COMPLETED && intent.action != Intent.ACTION_MY_PACKAGE_REPLACED) return |
| 11 | val prefs = Prefs(context) |
| 12 | if (!prefs.tracking || prefs.token == null) return |
| 13 | // Without "Allow all the time" location, Android refuses to start the service from here. |
| 14 | runCatching { TrackerService.start(context) } |
| 15 | } |
| 16 | } |
| 17 |