From 66dd0330fb3a0b0e3b1d66afeed5cb7e19f8d367 Mon Sep 17 00:00:00 2001 From: Dianne Hackborn Date: Wed, 9 Dec 2015 17:22:26 -0800 Subject: [PATCH] Add new target SDK filtering feature to BroadcastOptions. You can now control the range of target SDKs that receivers will be need to have in order to receive your broadcast. Use this for CONNECTIVITY_ACTION to not allow N+ applications to receive these broadcasts through their manifest. Also tweak the broadcast debug output code to now include the disposition of each receiver in the list. This is becoming important as skipping receivers is becoming a more common thing to have happen. Change-Id: I251daf68575c07cbb447536286ab4e68b7015148 --- .../java/com/android/server/ConnectivityService.java | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/services/core/java/com/android/server/ConnectivityService.java b/services/core/java/com/android/server/ConnectivityService.java index c712a568c4..ed64c2b37a 100644 --- a/services/core/java/com/android/server/ConnectivityService.java +++ b/services/core/java/com/android/server/ConnectivityService.java @@ -34,6 +34,7 @@ import static android.net.NetworkPolicyManager.RULE_REJECT_METERED; import android.annotation.Nullable; import android.app.AlarmManager; +import android.app.BroadcastOptions; import android.app.Notification; import android.app.NotificationManager; import android.app.PendingIntent; @@ -72,6 +73,7 @@ import android.net.RouteInfo; import android.net.UidRange; import android.net.Uri; import android.os.Binder; +import android.os.Build; import android.os.Bundle; import android.os.FileUtils; import android.os.Handler; @@ -1529,6 +1531,7 @@ public class ConnectivityService extends IConnectivityManager.Stub log("sendStickyBroadcast: action=" + intent.getAction()); } + Bundle options = null; final long ident = Binder.clearCallingIdentity(); if (ConnectivityManager.CONNECTIVITY_ACTION.equals(intent.getAction())) { final NetworkInfo ni = intent.getParcelableExtra( @@ -1536,6 +1539,10 @@ public class ConnectivityService extends IConnectivityManager.Stub if (ni.getType() == ConnectivityManager.TYPE_MOBILE_SUPL) { intent.setAction(ConnectivityManager.CONNECTIVITY_ACTION_SUPL); intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY); + } else { + BroadcastOptions opts = BroadcastOptions.makeBasic(); + opts.setMaxManifestReceiverApiLevel(Build.VERSION_CODES.M); + options = opts.toBundle(); } final IBatteryStats bs = BatteryStatsService.getService(); try { @@ -1546,7 +1553,7 @@ public class ConnectivityService extends IConnectivityManager.Stub } } try { - mContext.sendStickyBroadcastAsUser(intent, UserHandle.ALL); + mContext.sendStickyBroadcastAsUser(intent, UserHandle.ALL, options); } finally { Binder.restoreCallingIdentity(ident); }