BootReceiver.kt
⎇
Raw
1package org.opentracker
2
3import android.content.BroadcastReceiver
4import android.content.Context
5import android.content.Intent
6
7/** Restarts tracking after a reboot or an app update, if it was on. */
8class 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