Fixed crash when device boots & start at boot setting is disabled

This commit is contained in:
Sylvain Berfini 2022-05-05 09:25:59 +02:00
parent d6f83f0057
commit 209f577890

View file

@ -36,16 +36,12 @@ class BootReceiver : BroadcastReceiver() {
Log.i("[Boot Receiver] Device is starting, autoStart is $autoStart") Log.i("[Boot Receiver] Device is starting, autoStart is $autoStart")
if (autoStart) { if (autoStart) {
startService(context) startService(context)
} else {
stopService()
} }
} else if (intent.action.equals(Intent.ACTION_MY_PACKAGE_REPLACED, ignoreCase = true)) { } else if (intent.action.equals(Intent.ACTION_MY_PACKAGE_REPLACED, ignoreCase = true)) {
val autoStart = corePreferences.autoStart val autoStart = corePreferences.autoStart
Log.i("[Boot Receiver] App has been updated, autoStart is $autoStart") Log.i("[Boot Receiver] App has been updated, autoStart is $autoStart")
if (autoStart) { if (autoStart) {
startService(context) startService(context)
} else {
stopService()
} }
} }
} }
@ -62,10 +58,4 @@ class BootReceiver : BroadcastReceiver() {
serviceIntent.putExtra("StartForeground", true) serviceIntent.putExtra("StartForeground", true)
Compatibility.startForegroundService(context, serviceIntent) Compatibility.startForegroundService(context, serviceIntent)
} }
private fun stopService() {
Log.i("[Boot Receiver] Auto start setting is disabled, stopping foreground service")
coreContext.notificationsManager.stopForegroundNotification()
coreContext.stop()
}
} }