react-native-webrtc / react-native-callkeep

iOS CallKit framework and Android ConnectionService for React Native
ISC License
923 stars 445 forks source link

[Android] One of RECEIVER_EXPORTED or RECEIVER_NOT_EXPORTED should be specified when receiving call when targetSdkVersion is 34 #780

Closed taekeun-two closed 4 months ago

taekeun-two commented 5 months ago

Bug report

Description

After upgrading

// android/build.gradle

buildscript {
    ext {
        buildToolsVersion = "34.0.0"
        minSdkVersion = 21
        compileSdkVersion = 34
        targetSdkVersion = 34
        ndkVersion = "25.1.8937393"
        kotlinVersion = "1.8.0"
    }

the following error occurs whenever receiving call in Android 14 platform phone.

One of RECEIVER_EXPORTED or RECEIVER_NOT_EXPORTED should be specified 

References

Registering receivers with intention using the RECEIVER_EXPORTED / RECEIVER_NOT_EXPORTED flag was introduced as part of Android 13 and is now a requirement for apps running on Android 14 or higher (U+). It seems that it should be applied for callkeep's registering receivers.

diff --git a/node_modules/rn-fetch-blob/android/src/main/java/com/RNFetchBlob/RNFetchBlobReq.java b/node_modules/rn-fetch-blob/android/src/main/java/com/RNFetchBlob/RNFetchBlobReq.java
index a8abd71..efa1b46 100644
--- a/node_modules/rn-fetch-blob/android/src/main/java/com/RNFetchBlob/RNFetchBlobReq.java
+++ b/node_modules/rn-fetch-blob/android/src/main/java/com/RNFetchBlob/RNFetchBlobReq.java
@@ -196,7 +196,11 @@ public class RNFetchBlobReq extends BroadcastReceiver implements Runnable {
                 DownloadManager dm = (DownloadManager) appCtx.getSystemService(Context.DOWNLOAD_SERVICE);
                 downloadManagerId = dm.enqueue(req);
                 androidDownloadManagerTaskTable.put(taskId, Long.valueOf(downloadManagerId));
-                appCtx.registerReceiver(this, new IntentFilter(DownloadManager.ACTION_DOWNLOAD_COMPLETE));
+                if (Build.VERSION.SDK_INT >= 34 && appCtx.getApplicationInfo().targetSdkVersion >= 34) {
+                  appCtx.registerReceiver(this, new IntentFilter(DownloadManager.ACTION_DOWNLOAD_COMPLETE), Context.RECEIVER_EXPORTED);
+                }else{
+                  appCtx.registerReceiver(this, new IntentFilter(DownloadManager.ACTION_DOWNLOAD_COMPLETE));
+                }
                 return;
             }

Steps to Reproduce

Versions

- Callkeep: 4.3.9
- React Native: 0.73.8   // upgraded from 0.72.10
- Expo : 50.0.18         // upgraded from 49
- iOS:
- Android: Android version 14
- Phone model: Samsung Galaxy S23+ SM-S916N

Logs

java.lang.SecurityException: <packageName>: One of RECEIVER_EXPORTED or RECEIVER_NOT_EXPORTED should be specified when a receiver isn't being registered exclusively for system broadcasts

iScreen Shoter - Microsoft Teams - 240527101342

taekeun-two commented 4 months ago

Initially I thought that it's callkeep's code, but finally I found that the error comes from react-native-incall-manager. I'm so sorry for wrong error report.

image

In react-native-incall-manger latest v4.2.0 , this problem was fixed.

https://github.com/react-native-webrtc/react-native-incall-manager/releases/tag/4.2.0

Support Android 14 receiver changes
fix(android): specify export mode on BroadcastReceivers ( Santhosh Vaiyapuri 2024-02-16 10:41:22 +0100)