From e3595db332752d2f8e6d443fb92cbb151d2d801a Mon Sep 17 00:00:00 2001 From: greenart7c3 Date: Mon, 14 Oct 2024 11:29:39 -0300 Subject: [PATCH] If the app was updated try to start the service again --- app/src/main/AndroidManifest.xml | 1 + .../nostrsigner/service/BootReceiver.kt | 25 ++++++++++++++++++- 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index da4c9352..5dd11e1f 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -35,6 +35,7 @@ + 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 6c39e191..a2dce3d5 100644 --- a/app/src/main/java/com/greenart7c3/nostrsigner/service/BootReceiver.kt +++ b/app/src/main/java/com/greenart7c3/nostrsigner/service/BootReceiver.kt @@ -3,6 +3,7 @@ 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.BuildConfig @@ -11,8 +12,30 @@ 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") + context.startForegroundService( + Intent( + context, + ConnectivityService::class.java, + ), + ) + } + } + + 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") + Log.d("BootReceiver", "Starting ConnectivityService ACTION_BOOT_COMPLETED") context.startForegroundService( Intent( context,