Add not exported flag to receiver in EntitlementManager
Android T allows apps to declare a runtime receiver as not exported
by invoking registerReceiver with a new RECEIVER_NOT_EXPORTED flag;
receivers registered with this flag will only receive broadcasts from
the platform and the app itself. However to ensure developers can
properly protect their receivers, all apps targeting a future
platform release and registering a receiver for non-system
broadcasts must specify either the exported or not exported flag
when invoking #registerReceiver; if one of these flags is not
provided, the platform will throw a SecurityException. This commit
adds the RECEIVER_NOT_EXPORTED flag to the receiver in
EntitlementManager since this broadcast is sent as a PendingIntent
alarm.
Bug: 234659204
Test: atest com.android.networkstack.tethering.EntitlementManagerTest
Change-Id: I46c2df038ccf7669636166f50fe0331efcc42e4b
diff --git a/Tethering/src/com/android/networkstack/tethering/EntitlementManager.java b/Tethering/src/com/android/networkstack/tethering/EntitlementManager.java
index 784ebd5..6d502ce 100644
--- a/Tethering/src/com/android/networkstack/tethering/EntitlementManager.java
+++ b/Tethering/src/com/android/networkstack/tethering/EntitlementManager.java
@@ -34,6 +34,7 @@
import static android.net.TetheringManager.TETHER_ERROR_PROVISIONING_FAILED;
import static com.android.networkstack.apishim.ConstantsShim.ACTION_TETHER_UNSUPPORTED_CARRIER_UI;
+import static com.android.networkstack.apishim.ConstantsShim.RECEIVER_NOT_EXPORTED;
import android.app.AlarmManager;
import android.app.PendingIntent;
@@ -119,8 +120,13 @@
mEntitlementCacheValue = new SparseIntArray();
mPermissionChangeCallback = callback;
mHandler = h;
- mContext.registerReceiver(mReceiver, new IntentFilter(ACTION_PROVISIONING_ALARM),
- null, mHandler);
+ if (SdkLevel.isAtLeastU()) {
+ mContext.registerReceiver(mReceiver, new IntentFilter(ACTION_PROVISIONING_ALARM),
+ null, mHandler, RECEIVER_NOT_EXPORTED);
+ } else {
+ mContext.registerReceiver(mReceiver, new IntentFilter(ACTION_PROVISIONING_ALARM),
+ null, mHandler);
+ }
mSilentProvisioningService = ComponentName.unflattenFromString(
mContext.getResources().getString(R.string.config_wifi_tether_enable));
}