Skip to content

Commit 5c36f10

Browse files
apurunichrisbobbe
authored andcommitted
For targeting SDK 34 - Added RECEIVER_EXPORTED/RECEIVER_NOT_EXPORTED flag support in DevSupportManagerBase (facebook#38256)
Summary: Pull Request resolved: facebook#38256 Add RECEIVER_EXPORTED/RECEIVER_NOT_EXPORTED flag support to DevSupportManagerBase for Android 14 change. See https://developer.android.com/about/versions/14/behavior-changes-14#runtime-receivers-exported for details. Without this fix, app crashes during launch because of : ```SecurityException: {package name here}: One of RECEIVER_EXPORTED or RECEIVER_NOT_EXPORTED should be specified when a receiver isn't being registered exclusively for system broadcasts``` Changelog: [Targeting SDK 34] Added RECEIVER_EXPORTED/RECEIVER_NOT_EXPORTED flag support in DevSupportManagerBase Reviewed By: javache Differential Revision: D47313501 fbshipit-source-id: 12e8299559d08b4ff87b4bdabb0a29d27763c698 (Cherry picked from commit 177d97d to support targetSdkVersion = 34.)
1 parent d607b0b commit 5c36f10

File tree

1 file changed

+19
-1
lines changed

1 file changed

+19
-1
lines changed

Diff for: ReactAndroid/src/main/java/com/facebook/react/devsupport/DevSupportManagerBase.java

+19-1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import android.graphics.Color;
2121
import android.graphics.Typeface;
2222
import android.hardware.SensorManager;
23+
import android.os.Build;
2324
import android.util.Pair;
2425
import android.view.Gravity;
2526
import android.view.View;
@@ -1107,7 +1108,7 @@ private void reload() {
11071108
if (!mIsReceiverRegistered) {
11081109
IntentFilter filter = new IntentFilter();
11091110
filter.addAction(getReloadAppAction(mApplicationContext));
1110-
mApplicationContext.registerReceiver(mReloadAppBroadcastReceiver, filter);
1111+
compatRegisterReceiver(mApplicationContext, mReloadAppBroadcastReceiver, filter, true);
11111112
mIsReceiverRegistered = true;
11121113
}
11131114

@@ -1223,4 +1224,21 @@ public void setPackagerLocationCustomizer(
12231224

12241225
return mSurfaceDelegateFactory.createSurfaceDelegate(moduleName);
12251226
}
1227+
1228+
/**
1229+
* Starting with Android 14, apps and services that target Android 14 and use context-registered
1230+
* receivers are required to specify a flag to indicate whether or not the receiver should be
1231+
* exported to all other apps on the device: either RECEIVER_EXPORTED or RECEIVER_NOT_EXPORTED
1232+
*
1233+
* <p>https://developer.android.com/about/versions/14/behavior-changes-14#runtime-receivers-exported
1234+
*/
1235+
private void compatRegisterReceiver(
1236+
Context context, BroadcastReceiver receiver, IntentFilter filter, boolean exported) {
1237+
if (Build.VERSION.SDK_INT >= 34 && context.getApplicationInfo().targetSdkVersion >= 34) {
1238+
context.registerReceiver(
1239+
receiver, filter, exported ? Context.RECEIVER_EXPORTED : Context.RECEIVER_NOT_EXPORTED);
1240+
} else {
1241+
context.registerReceiver(receiver, filter);
1242+
}
1243+
}
12261244
}

0 commit comments

Comments
 (0)