Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

For targeting SDK 34 - Added RECEIVER_EXPORTED/RECEIVER_NOT_EXPORTED flag support in DevSupportManagerBase #38256

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import android.content.pm.PackageManager;
import android.graphics.Typeface;
import android.hardware.SensorManager;
import android.os.Build;
import android.util.Pair;
import android.view.Gravity;
import android.view.View;
Expand Down Expand Up @@ -1022,7 +1023,7 @@ private void reload() {
if (!mIsReceiverRegistered) {
IntentFilter filter = new IntentFilter();
filter.addAction(getReloadAppAction(mApplicationContext));
mApplicationContext.registerReceiver(mReloadAppBroadcastReceiver, filter);
compatRegisterReceiver(mApplicationContext, mReloadAppBroadcastReceiver, filter, true);
mIsReceiverRegistered = true;
}

Expand Down Expand Up @@ -1120,4 +1121,21 @@ public void setPackagerLocationCustomizer(

return mSurfaceDelegateFactory.createSurfaceDelegate(moduleName);
}

/**
* Starting with Android 14, apps and services that target Android 14 and use context-registered
* receivers are required to specify a flag to indicate whether or not the receiver should be
* exported to all other apps on the device: either RECEIVER_EXPORTED or RECEIVER_NOT_EXPORTED
*
* <p>https://developer.android.com/about/versions/14/behavior-changes-14#runtime-receivers-exported
*/
private void compatRegisterReceiver(
Context context, BroadcastReceiver receiver, IntentFilter filter, boolean exported) {
if (Build.VERSION.SDK_INT >= 34 && context.getApplicationInfo().targetSdkVersion >= 34) {
context.registerReceiver(
receiver, filter, exported ? Context.RECEIVER_EXPORTED : Context.RECEIVER_NOT_EXPORTED);
} else {
context.registerReceiver(receiver, filter);
}
}
}