feat: restart notification service after app updates
Handle ACTION_MY_PACKAGE_REPLACED in BootCompletedReceiver so the always-on notification service auto-restarts after app updates. Without this, the service stays dead until the user opens the app or reboots. Inspired by Pokey's approach. https://claude.ai/code/session_01LEPfmgGnwjB9a5SDFw5U8t
This commit is contained in:
@@ -282,6 +282,7 @@
|
|||||||
<intent-filter>
|
<intent-filter>
|
||||||
<action android:name="android.intent.action.BOOT_COMPLETED" />
|
<action android:name="android.intent.action.BOOT_COMPLETED" />
|
||||||
<action android:name="android.intent.action.QUICKBOOT_POWERON" />
|
<action android:name="android.intent.action.QUICKBOOT_POWERON" />
|
||||||
|
<action android:name="android.intent.action.MY_PACKAGE_REPLACED" />
|
||||||
</intent-filter>
|
</intent-filter>
|
||||||
</receiver>
|
</receiver>
|
||||||
|
|
||||||
|
|||||||
+16
-8
@@ -26,7 +26,12 @@ import android.content.Intent
|
|||||||
import com.vitorpamplona.quartz.utils.Log
|
import com.vitorpamplona.quartz.utils.Log
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Restarts the NotificationRelayService after device reboot.
|
* Restarts the NotificationRelayService after device reboot or app update.
|
||||||
|
*
|
||||||
|
* Handles:
|
||||||
|
* - BOOT_COMPLETED / QUICKBOOT_POWERON: restart after device reboot
|
||||||
|
* - MY_PACKAGE_REPLACED: restart after app update (without this, the service
|
||||||
|
* stays dead until the user manually opens the app or reboots)
|
||||||
*
|
*
|
||||||
* The specialUse foreground service type is allowed to start from BOOT_COMPLETED
|
* The specialUse foreground service type is allowed to start from BOOT_COMPLETED
|
||||||
* on Android 15+, unlike dataSync which is restricted.
|
* on Android 15+, unlike dataSync which is restricted.
|
||||||
@@ -40,13 +45,16 @@ class BootCompletedReceiver : BroadcastReceiver() {
|
|||||||
context: Context,
|
context: Context,
|
||||||
intent: Intent,
|
intent: Intent,
|
||||||
) {
|
) {
|
||||||
if (intent.action == Intent.ACTION_BOOT_COMPLETED ||
|
when (intent.action) {
|
||||||
intent.action == "android.intent.action.QUICKBOOT_POWERON"
|
Intent.ACTION_BOOT_COMPLETED,
|
||||||
) {
|
"android.intent.action.QUICKBOOT_POWERON",
|
||||||
Log.d(TAG, "Boot completed, checking if notification service should start")
|
Intent.ACTION_MY_PACKAGE_REPLACED,
|
||||||
if (NotificationRelayService.isEnabled(context)) {
|
-> {
|
||||||
Log.d(TAG, "Starting notification relay service after boot")
|
Log.d(TAG) { "Received ${intent.action}, checking if notification service should start" }
|
||||||
NotificationRelayService.start(context)
|
if (NotificationRelayService.isEnabled(context)) {
|
||||||
|
Log.d(TAG, "Starting notification relay service")
|
||||||
|
NotificationRelayService.start(context)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user