refactor BootReceiver

This commit is contained in:
greenart7c3
2024-10-27 15:31:30 -03:00
parent 213e10d8eb
commit 7faf183f1c
@@ -4,7 +4,6 @@ import android.content.BroadcastReceiver
import android.content.Context
import android.content.Intent
import android.os.Build
import android.util.Log
import com.greenart7c3.nostrsigner.BuildConfig
class BootReceiver : BroadcastReceiver() {
@@ -12,9 +11,26 @@ class BootReceiver : BroadcastReceiver() {
@Suppress("KotlinConstantConditions")
if (BuildConfig.FLAVOR == "offline") return
if (intent.action == Intent.ACTION_PACKAGE_REPLACED && Build.VERSION.SDK_INT < Build.VERSION_CODES.S) {
if (intent.dataString?.contains("com.greenart7c3.nostrsigner") == true) {
Log.d("BootReceiver", "Starting ConnectivityService ACTION_PACKAGE_REPLACED")
when (intent.action) {
Intent.ACTION_PACKAGE_REPLACED -> {
if (intent.dataString?.contains("com.greenart7c3.nostrsigner") == true && Build.VERSION.SDK_INT < Build.VERSION_CODES.S) {
context.startForegroundService(
Intent(
context,
ConnectivityService::class.java,
),
)
}
}
Intent.ACTION_MY_PACKAGE_REPLACED -> {
context.startForegroundService(
Intent(
context,
ConnectivityService::class.java,
),
)
}
Intent.ACTION_BOOT_COMPLETED -> {
context.startForegroundService(
Intent(
context,
@@ -23,25 +39,5 @@ class BootReceiver : BroadcastReceiver() {
)
}
}
if (intent.action == Intent.ACTION_MY_PACKAGE_REPLACED) {
Log.d("BootReceiver", "Starting ConnectivityService ACTION_MY_PACKAGE_REPLACED")
context.startForegroundService(
Intent(
context,
ConnectivityService::class.java,
),
)
}
if (intent.action == Intent.ACTION_BOOT_COMPLETED) {
Log.d("BootReceiver", "Starting ConnectivityService ACTION_BOOT_COMPLETED")
context.startForegroundService(
Intent(
context,
ConnectivityService::class.java,
),
)
}
}
}