From ee9d6e5ab93be31c76b90111326078e837e83001 Mon Sep 17 00:00:00 2001 From: greenart7c3 Date: Sat, 28 Feb 2026 14:40:23 -0300 Subject: [PATCH] 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 --- app/src/main/AndroidManifest.xml | 1 - .../nostrsigner/service/BootReceiver.kt | 30 +++---------------- 2 files changed, 4 insertions(+), 27 deletions(-) diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index cb1638d3..06fcc033 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -46,7 +46,6 @@ - diff --git a/app/src/main/java/com/greenart7c3/nostrsigner/service/BootReceiver.kt b/app/src/main/java/com/greenart7c3/nostrsigner/service/BootReceiver.kt index b0c5e338..6242229a 100644 --- a/app/src/main/java/com/greenart7c3/nostrsigner/service/BootReceiver.kt +++ b/app/src/main/java/com/greenart7c3/nostrsigner/service/BootReceiver.kt @@ -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() } }