From f82b752862e716b1249cebebf36bc708b65c9503 Mon Sep 17 00:00:00 2001 From: YotamDagai Date: Tue, 13 Jun 2023 02:36:53 +0300 Subject: [PATCH] Fix compatibility with Android 14 (SDK 34) UpsideDownCake This commit addresses the compatibility issue with Android 14 (SDK 34) and SDK 33 by ensuring proper registration of broadcast receivers in accordance with the behavior changes introduced in SDK 34. The `PriorityListProcessorImpl` class now registers the receiver with the appropriate export flags based on the target SDK version of the app. This resolves the `SecurityException` and allows seamless integration with SDK 34. Fixes: #655 --- .../fetch2/helper/PriorityListProcessorImpl.kt | 14 +++++++++++++- versions.gradle | 4 ++-- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/fetch2/src/main/java/com/tonyodev/fetch2/helper/PriorityListProcessorImpl.kt b/fetch2/src/main/java/com/tonyodev/fetch2/helper/PriorityListProcessorImpl.kt index b9d755b5..2bd06cab 100644 --- a/fetch2/src/main/java/com/tonyodev/fetch2/helper/PriorityListProcessorImpl.kt +++ b/fetch2/src/main/java/com/tonyodev/fetch2/helper/PriorityListProcessorImpl.kt @@ -1,9 +1,14 @@ package com.tonyodev.fetch2.helper +import android.annotation.SuppressLint import android.content.BroadcastReceiver import android.content.Context import android.content.Intent import android.content.IntentFilter +import android.os.Build +import android.util.Log +import androidx.annotation.RequiresApi +import androidx.core.content.ContextCompat import com.tonyodev.fetch2.* import com.tonyodev.fetch2.downloader.DownloadManager import com.tonyodev.fetch2core.HandlerWrapper @@ -16,6 +21,8 @@ import com.tonyodev.fetch2core.Logger import com.tonyodev.fetch2core.isFetchFileServerUrl import java.util.concurrent.TimeUnit +@SuppressLint("UnspecifiedRegisterReceiverFlag") +@RequiresApi(Build.VERSION_CODES.O) class PriorityListProcessorImpl constructor(private val handlerWrapper: HandlerWrapper, private val downloadProvider: DownloadProvider, private val downloadManager: DownloadManager, @@ -68,7 +75,12 @@ class PriorityListProcessorImpl constructor(private val handlerWrapper: HandlerW init { networkInfoProvider.registerNetworkChangeListener(networkChangeListener) - context.registerReceiver(priorityBackoffResetReceiver, IntentFilter(ACTION_QUEUE_BACKOFF_RESET)) + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) { + context.registerReceiver(priorityBackoffResetReceiver, IntentFilter(ACTION_QUEUE_BACKOFF_RESET), + Context.RECEIVER_NOT_EXPORTED) + } else { + context.registerReceiver(priorityBackoffResetReceiver, IntentFilter(ACTION_QUEUE_BACKOFF_RESET)) + } } private val priorityIteratorRunnable = Runnable { diff --git a/versions.gradle b/versions.gradle index 0d4bdf6c..607c74f4 100644 --- a/versions.gradle +++ b/versions.gradle @@ -10,8 +10,8 @@ ext { espresso_version = '3.3.0' test_runner_version = '1.3.0' library_min_version = '14' - library_compile_version = 30 - library_target_version = 30 + library_compile_version = 34 + library_target_version = 34 library_build_tools_version = "30.0.3" gradle_tools_version = '3.4.1' rxJava2_version = "2.2.20"