mirror of
https://github.com/greenart7c3/Amber.git
synced 2026-10-05 19:08:23 +00:00
Improve BootReceiver: fix double start, dedup branches, use Flow.first
- Remove ACTION_PACKAGE_REPLACED handler and manifest entry; MY_PACKAGE_REPLACED
covers all supported API levels, so both firing caused startService() to be
called twice on pre-S devices
- Merge identical ACTION_MY_PACKAGE_REPLACED and ACTION_BOOT_COMPLETED branches
- Replace busy-poll loop with isStartingAppState.first { !it } for efficient suspension
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Sonnet 4.6
parent
7d910ea57d
commit
ee9d6e5ab9
@@ -46,7 +46,6 @@
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.BOOT_COMPLETED" />
|
||||
<action android:name="android.intent.action.MY_PACKAGE_REPLACED" />
|
||||
<action android:name="android.intent.action.PACKAGE_REPLACED" />
|
||||
|
||||
<category android:name="android.intent.category.DEFAULT" />
|
||||
</intent-filter>
|
||||
|
||||
@@ -3,11 +3,10 @@ package com.greenart7c3.nostrsigner.service
|
||||
import android.content.BroadcastReceiver
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.os.Build
|
||||
import android.util.Log
|
||||
import com.greenart7c3.nostrsigner.Amber
|
||||
import com.greenart7c3.nostrsigner.BuildFlavorChecker
|
||||
import kotlinx.coroutines.delay
|
||||
import kotlinx.coroutines.flow.first
|
||||
import kotlinx.coroutines.launch
|
||||
|
||||
class BootReceiver : BroadcastReceiver() {
|
||||
@@ -16,32 +15,11 @@ class BootReceiver : BroadcastReceiver() {
|
||||
Log.d(Amber.TAG, "Received intent: ${intent.action}")
|
||||
|
||||
when (intent.action) {
|
||||
Intent.ACTION_PACKAGE_REPLACED -> {
|
||||
Log.d(Amber.TAG, "Received ACTION_PACKAGE_REPLACED")
|
||||
if (intent.dataString?.contains("com.greenart7c3.nostrsigner") == true && Build.VERSION.SDK_INT < Build.VERSION_CODES.S) {
|
||||
Amber.instance.applicationIOScope.launch {
|
||||
while (Amber.instance.isStartingAppState.value) {
|
||||
delay(1000)
|
||||
}
|
||||
Amber.instance.startService()
|
||||
}
|
||||
}
|
||||
}
|
||||
Intent.ACTION_MY_PACKAGE_REPLACED -> {
|
||||
Log.d(Amber.TAG, "Received ACTION_MY_PACKAGE_REPLACED")
|
||||
Amber.instance.applicationIOScope.launch {
|
||||
while (Amber.instance.isStartingAppState.value) {
|
||||
delay(1000)
|
||||
}
|
||||
Amber.instance.startService()
|
||||
}
|
||||
}
|
||||
Intent.ACTION_MY_PACKAGE_REPLACED,
|
||||
Intent.ACTION_BOOT_COMPLETED -> {
|
||||
Log.d(Amber.TAG, "Received ACTION_BOOT_COMPLETED")
|
||||
Log.d(Amber.TAG, "Received ${intent.action}")
|
||||
Amber.instance.applicationIOScope.launch {
|
||||
while (Amber.instance.isStartingAppState.value) {
|
||||
delay(1000)
|
||||
}
|
||||
Amber.instance.isStartingAppState.first { !it }
|
||||
Amber.instance.startService()
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user