Check Carrier Privilege on Hidden Subs
When calling CheckCarrierPrivilegeForAnySubId the
hidden subscriptions were not being taken into account
due to getAllActiveSubscriptionIds being a public method
that intentionally ignores hidden subscriptions.
NOTE: This is identical to ag/8193293, except that the
SubscriptionManager modifications don't make
getActiveSubscriptionIdList() static (it was causing test failures). A
further bug can be pursued to make everything static all at once.
Bug: 135684437
Test: manual
Change-Id: Iad6a3c2635e5eac2d33a16aa460b98394fd817f4
Merged-In: Iad6a3c2635e5eac2d33a16aa460b98394fd817f4
diff --git a/telephony/java/android/telephony/SubscriptionManager.java b/telephony/java/android/telephony/SubscriptionManager.java
index 519a954..4be1770 100644
--- a/telephony/java/android/telephony/SubscriptionManager.java
+++ b/telephony/java/android/telephony/SubscriptionManager.java
@@ -2116,29 +2116,36 @@
}
/**
+ * TODO(b/137102918) Make this static, tests use this as an instance method currently.
+ *
* @return the list of subId's that are active,
* is never null but the length maybe 0.
* @hide
*/
@UnsupportedAppUsage
public @NonNull int[] getActiveSubscriptionIdList() {
- int[] subId = null;
+ return getActiveSubscriptionIdList(/* visibleOnly */ true);
+ }
+ /**
+ * TODO(b/137102918) Make this static, tests use this as an instance method currently.
+ *
+ * @return a non-null list of subId's that are active.
+ *
+ * @hide
+ */
+ public @NonNull int[] getActiveSubscriptionIdList(boolean visibleOnly) {
try {
ISub iSub = ISub.Stub.asInterface(ServiceManager.getService("isub"));
if (iSub != null) {
- subId = iSub.getActiveSubIdList(/*visibleOnly*/true);
+ int[] subId = iSub.getActiveSubIdList(visibleOnly);
+ if (subId != null) return subId;
}
} catch (RemoteException ex) {
// ignore it
}
- if (subId == null) {
- subId = new int[0];
- }
-
- return subId;
-
+ return new int[0];
}
/**
diff --git a/telephony/java/com/android/internal/telephony/TelephonyPermissions.java b/telephony/java/com/android/internal/telephony/TelephonyPermissions.java
index 2dba70f..67103bf 100644
--- a/telephony/java/com/android/internal/telephony/TelephonyPermissions.java
+++ b/telephony/java/com/android/internal/telephony/TelephonyPermissions.java
@@ -593,26 +593,21 @@
}
}
- /**
- * Returns whether the provided uid has carrier privileges for any active subscription ID.
- */
- private static boolean checkCarrierPrivilegeForAnySubId(Context context,
- Supplier<ITelephony> telephonySupplier, int uid) {
+ /** Returns whether the provided uid has carrier privileges for any active subscription ID. */
+ private static boolean checkCarrierPrivilegeForAnySubId(
+ Context context, Supplier<ITelephony> telephonySupplier, int uid) {
SubscriptionManager sm = (SubscriptionManager) context.getSystemService(
Context.TELEPHONY_SUBSCRIPTION_SERVICE);
- int[] activeSubIds = sm.getActiveSubscriptionIdList();
- if (activeSubIds != null) {
- for (int activeSubId : activeSubIds) {
- if (getCarrierPrivilegeStatus(telephonySupplier, activeSubId, uid)
- == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
- return true;
- }
+ int[] activeSubIds = sm.getActiveSubscriptionIdList(/* visibleOnly */ false);
+ for (int activeSubId : activeSubIds) {
+ if (getCarrierPrivilegeStatus(telephonySupplier, activeSubId, uid)
+ == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) {
+ return true;
}
}
return false;
}
-
private static int getCarrierPrivilegeStatus(
Supplier<ITelephony> telephonySupplier, int subId, int uid) {
ITelephony telephony = telephonySupplier.get();