Skip to content

Commit

Permalink
Merge pull request #47 from discord/android_14_support
Browse files Browse the repository at this point in the history
Adds Android 14 support to DevSupportManagerBase
  • Loading branch information
AndyG authored Nov 3, 2023
2 parents ea81413 + 72576a3 commit 7ae8fa5
Showing 1 changed file with 19 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import android.graphics.Color;
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 @@ -1142,7 +1143,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 @@ -1258,4 +1259,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);
}
}
}

0 comments on commit 7ae8fa5

Please sign in to comment.