Skip to content

Commit

Permalink
fix: pass RECEIVER_EXPORTED flag to registerReceiver (#260)
Browse files Browse the repository at this point in the history
* fix: security exception thrown due to missing receiver flag for android 14

* fix: switch RECEIVER_NOT_EXPORTED with RECEIVER_EXPORTED to listen for system events

* fix: bump compileSdk and targetSdk to 34

---------

Co-authored-by: Ely Deckers <e.deckers@gmail.com>
  • Loading branch information
gladiuscode and edeckers authored Apr 12, 2024
1 parent efb162b commit ba5763c
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
4 changes: 2 additions & 2 deletions android/gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ BlobCourier_testExtVersion = 1.1.+
BlobCourier_testLoggerVersion = 2.1.1

BlobCourier_buildToolsVersion = 30.0.2
BlobCourier_compileSdkVersion = 31
BlobCourier_compileSdkVersion = 34
BlobCourier_minSdkVersion = 24
BlobCourier_targetSdkVersion = 30
BlobCourier_targetSdkVersion = 34

ADB_COMMAND_TIMEOUT_MILLISECONDS = 10000L
PROMISE_TIMEOUT_MILLISECONDS = 60000L
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import android.content.BroadcastReceiver
import android.content.Context
import android.content.Intent
import android.content.IntentFilter
import android.os.Build
import androidx.localbroadcastmanager.content.LocalBroadcastManager
import io.deckers.blob_courier.common.ACTION_CANCEL_REQUEST
import io.deckers.blob_courier.common.BlobCourierError
Expand Down Expand Up @@ -162,10 +163,19 @@ class ManagedDownloader(
private fun registerDownloadCompletionHandler(downloadReceiver: ManagedDownloadReceiver) {
lv("Registering ${DownloadManager.ACTION_DOWNLOAD_COMPLETE} receiver")

context.registerReceiver(
downloadReceiver,
IntentFilter(DownloadManager.ACTION_DOWNLOAD_COMPLETE)
)
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
context.registerReceiver(
downloadReceiver,
IntentFilter(DownloadManager.ACTION_DOWNLOAD_COMPLETE),
Context.RECEIVER_EXPORTED
)
} else {
@Suppress("UnspecifiedRegisterReceiverFlag")
context.registerReceiver(
downloadReceiver,
IntentFilter(DownloadManager.ACTION_DOWNLOAD_COMPLETE)
)
}

lv("Registered ${DownloadManager.ACTION_DOWNLOAD_COMPLETE} receiver")
}
Expand Down

0 comments on commit ba5763c

Please sign in to comment.