Skip to content

Commit

Permalink
Fix compatibility with Android 14 (SDK 34) UpsideDownCake
Browse files Browse the repository at this point in the history
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: tonyofrancis#655
  • Loading branch information
YotamDagai committed Jun 12, 2023
1 parent af3ccae commit f82b752
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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,
Expand Down Expand Up @@ -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 {
Expand Down
4 changes: 2 additions & 2 deletions versions.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit f82b752

Please sign in to comment.