From 87cc0620ff6f3ce4a075ed1da5c4d98d29a6d808 Mon Sep 17 00:00:00 2001 From: Naimul Kabir Date: Mon, 9 Oct 2023 14:36:01 +0600 Subject: [PATCH 1/3] fix[642]: fix crash issue on broadcast registering for not adding RECEIVER_EXPORTED or RECEIVER_NOT_EXPORTED (#642) https://github.com/gotev/android-upload-service/issues/642 Caused by: java.lang.SecurityException: ************: One of RECEIVER_EXPORTED or RECEIVER_NOT_EXPORTED should be specified when a receiver isn't being registered exclusively for system broadcasts at android.os.Parcel.createExceptionOrNull(Parcel.java:3057) at android.os.Parcel.createException(Parcel.java:3041) at android.os.Parcel.readException(Parcel.java:3024) at android.os.Parcel.readException(Parcel.java:2966) at android.app.IActivityManager$Stub$Proxy.registerReceiverWithFeature(IActivityManager.java:5684) at android.app.ContextImpl.registerReceiverInternal(ContextImpl.java:1852) at android.app.ContextImpl.registerReceiver(ContextImpl.java:1792) at android.app.ContextImpl.registerReceiver(ContextImpl.java:1780) at android.content.ContextWrapper.registerReceiver(ContextWrapper.java:755) at net.gotev.uploadservice.observer.request.BaseRequestObserver.register(BaseRequestObserver.kt:36) at net.gotev.uploadservice.observer.request.GlobalRequestObserver.(GlobalRequestObserver.kt:12) at net.gotev.uploadservice.observer.request.GlobalRequestObserver.(GlobalRequestObserver.kt:6) at net.gotev.uploadservice.observer.request.GlobalRequestObserver.(Unknown Source:16) --- .../observer/request/BaseRequestObserver.kt | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/uploadservice/src/main/java/net/gotev/uploadservice/observer/request/BaseRequestObserver.kt b/uploadservice/src/main/java/net/gotev/uploadservice/observer/request/BaseRequestObserver.kt index d65e1e31..0a56014f 100644 --- a/uploadservice/src/main/java/net/gotev/uploadservice/observer/request/BaseRequestObserver.kt +++ b/uploadservice/src/main/java/net/gotev/uploadservice/observer/request/BaseRequestObserver.kt @@ -2,7 +2,9 @@ package net.gotev.uploadservice.observer.request import android.content.BroadcastReceiver import android.content.Context +import android.content.Context.RECEIVER_NOT_EXPORTED import android.content.Intent +import android.os.Build import net.gotev.uploadservice.UploadServiceConfig import net.gotev.uploadservice.data.BroadcastData import net.gotev.uploadservice.data.UploadInfo @@ -33,7 +35,13 @@ open class BaseRequestObserver( } open fun register() { - context.registerReceiver(this, UploadServiceConfig.broadcastStatusIntentFilter) + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) { + context.registerReceiver( + this, UploadServiceConfig.broadcastStatusIntentFilter, RECEIVER_NOT_EXPORTED + ) + } else { + context.registerReceiver(this, UploadServiceConfig.broadcastStatusIntentFilter) + } } open fun unregister() { From a962a92f6bb7b914abbbcc3c88c6a8c269b9f032 Mon Sep 17 00:00:00 2001 From: Naimul Kabir Date: Mon, 9 Oct 2023 14:36:42 +0600 Subject: [PATCH 2/3] chore: remove deprecated code where possible --- .../src/main/java/net/gotev/uploadservice/UploadService.kt | 4 ++-- .../java/net/gotev/uploadservice/data/BroadcastData.kt | 7 ++++++- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/uploadservice/src/main/java/net/gotev/uploadservice/UploadService.kt b/uploadservice/src/main/java/net/gotev/uploadservice/UploadService.kt index 130d1331..b9694d32 100644 --- a/uploadservice/src/main/java/net/gotev/uploadservice/UploadService.kt +++ b/uploadservice/src/main/java/net/gotev/uploadservice/UploadService.kt @@ -182,7 +182,7 @@ class UploadService : Service() { if (UploadServiceConfig.isForegroundService && uploadTasksMap.isEmpty()) { UploadServiceLogger.debug(TAG, NA) { "All tasks completed, stopping foreground execution" } - stopForeground(true) + stopForeground(STOP_FOREGROUND_REMOVE) shutdownIfThereArentAnyActiveTasks() } } @@ -248,7 +248,7 @@ class UploadService : Service() { if (UploadServiceConfig.isForegroundService) { UploadServiceLogger.debug(TAG, NA) { "Stopping foreground execution" } - stopForeground(true) + stopForeground(STOP_FOREGROUND_REMOVE) } wakeLock.safeRelease() diff --git a/uploadservice/src/main/java/net/gotev/uploadservice/data/BroadcastData.kt b/uploadservice/src/main/java/net/gotev/uploadservice/data/BroadcastData.kt index cdfa049c..6299951d 100644 --- a/uploadservice/src/main/java/net/gotev/uploadservice/data/BroadcastData.kt +++ b/uploadservice/src/main/java/net/gotev/uploadservice/data/BroadcastData.kt @@ -1,6 +1,7 @@ package net.gotev.uploadservice.data import android.content.Intent +import android.os.Build import android.os.Parcelable import kotlinx.parcelize.Parcelize import net.gotev.uploadservice.UploadServiceConfig @@ -17,7 +18,11 @@ internal data class BroadcastData @JvmOverloads constructor( private const val paramName = "broadcastData" fun fromIntent(intent: Intent): BroadcastData? { - return intent.getParcelableExtra(paramName) + return if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) { + intent.getParcelableExtra(paramName, BroadcastData::class.java) + } else { + intent.getParcelableExtra(paramName) + } } } From 54e0fd8a4453ee5bb33a8bfac0c415bb9b090ccb Mon Sep 17 00:00:00 2001 From: Naimul Kabir Date: Tue, 10 Oct 2023 13:07:22 +0600 Subject: [PATCH 3/3] fix [#642]: fix in NotificationActionsObserver.kt as well --- .../observer/request/NotificationActionsObserver.kt | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/uploadservice/src/main/java/net/gotev/uploadservice/observer/request/NotificationActionsObserver.kt b/uploadservice/src/main/java/net/gotev/uploadservice/observer/request/NotificationActionsObserver.kt index b70c06b1..d1676e9c 100644 --- a/uploadservice/src/main/java/net/gotev/uploadservice/observer/request/NotificationActionsObserver.kt +++ b/uploadservice/src/main/java/net/gotev/uploadservice/observer/request/NotificationActionsObserver.kt @@ -3,7 +3,9 @@ package net.gotev.uploadservice.observer.request import android.content.BroadcastReceiver import android.content.Context import android.content.Intent +import android.os.Build import net.gotev.uploadservice.UploadService +import net.gotev.uploadservice.UploadServiceConfig import net.gotev.uploadservice.UploadServiceConfig.broadcastNotificationAction import net.gotev.uploadservice.UploadServiceConfig.broadcastNotificationActionIntentFilter import net.gotev.uploadservice.extensions.uploadIdToCancel @@ -28,7 +30,13 @@ open class NotificationActionsObserver( } fun register() { - context.registerReceiver(this, broadcastNotificationActionIntentFilter) + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) { + context.registerReceiver( + this, broadcastNotificationActionIntentFilter, Context.RECEIVER_NOT_EXPORTED + ) + } else { + context.registerReceiver(this, broadcastNotificationActionIntentFilter) + } UploadServiceLogger.debug(NotificationActionsObserver::class.java.simpleName, NA) { "registered" }