Skip to content

Commit ba5763c

Browse files
fix: pass RECEIVER_EXPORTED flag to registerReceiver (#260)
* 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 <[email protected]>
1 parent efb162b commit ba5763c

File tree

2 files changed

+16
-6
lines changed

2 files changed

+16
-6
lines changed

android/gradle.properties

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@ BlobCourier_testExtVersion = 1.1.+
1414
BlobCourier_testLoggerVersion = 2.1.1
1515

1616
BlobCourier_buildToolsVersion = 30.0.2
17-
BlobCourier_compileSdkVersion = 31
17+
BlobCourier_compileSdkVersion = 34
1818
BlobCourier_minSdkVersion = 24
19-
BlobCourier_targetSdkVersion = 30
19+
BlobCourier_targetSdkVersion = 34
2020

2121
ADB_COMMAND_TIMEOUT_MILLISECONDS = 10000L
2222
PROMISE_TIMEOUT_MILLISECONDS = 60000L

android/src/main/java/io/deckers/blob_courier/fetch/ManagedDownloader.kt

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import android.content.BroadcastReceiver
1111
import android.content.Context
1212
import android.content.Intent
1313
import android.content.IntentFilter
14+
import android.os.Build
1415
import androidx.localbroadcastmanager.content.LocalBroadcastManager
1516
import io.deckers.blob_courier.common.ACTION_CANCEL_REQUEST
1617
import io.deckers.blob_courier.common.BlobCourierError
@@ -162,10 +163,19 @@ class ManagedDownloader(
162163
private fun registerDownloadCompletionHandler(downloadReceiver: ManagedDownloadReceiver) {
163164
lv("Registering ${DownloadManager.ACTION_DOWNLOAD_COMPLETE} receiver")
164165

165-
context.registerReceiver(
166-
downloadReceiver,
167-
IntentFilter(DownloadManager.ACTION_DOWNLOAD_COMPLETE)
168-
)
166+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
167+
context.registerReceiver(
168+
downloadReceiver,
169+
IntentFilter(DownloadManager.ACTION_DOWNLOAD_COMPLETE),
170+
Context.RECEIVER_EXPORTED
171+
)
172+
} else {
173+
@Suppress("UnspecifiedRegisterReceiverFlag")
174+
context.registerReceiver(
175+
downloadReceiver,
176+
IntentFilter(DownloadManager.ACTION_DOWNLOAD_COMPLETE)
177+
)
178+
}
169179

170180
lv("Registered ${DownloadManager.ACTION_DOWNLOAD_COMPLETE} receiver")
171181
}

0 commit comments

Comments
 (0)