Add getSubscriptionId API

The old getSubId or getSubscriptionIds return multiple sub ids
per slot index, which is not possible in today's implementation
because the slot index here refers to the logical slot index,
which is also known as phone id, or the logical modem index. In
today's telephony, one logical phone can only have one
subscription at one time, so does the modem.

Bug: 239607619
Test: Manual
Merged-In: I7e1e44509169b11024455d52749531f021ab7383
Change-Id: I7e1e44509169b11024455d52749531f021ab7383
diff --git a/src/com/android/phone/CarrierConfigLoader.java b/src/com/android/phone/CarrierConfigLoader.java
index d944fa0..69f29bd 100644
--- a/src/com/android/phone/CarrierConfigLoader.java
+++ b/src/com/android/phone/CarrierConfigLoader.java
@@ -813,10 +813,10 @@
                 Intent.FLAG_RECEIVER_FOREGROUND);
         if (addSubIdExtra) {
             int simApplicationState = TelephonyManager.SIM_STATE_UNKNOWN;
-            int[] subIds = SubscriptionManager.getSubId(phoneId);
-            if (!ArrayUtils.isEmpty(subIds)) {
+            int subId = SubscriptionManager.getSubscriptionId(phoneId);
+            if (SubscriptionManager.isValidSubscriptionId(subId)) {
                 TelephonyManager telMgr = TelephonyManager.from(mContext)
-                        .createForSubscriptionId(subIds[0]);
+                        .createForSubscriptionId(subId);
                 simApplicationState = telMgr.getSimApplicationState();
             }
             logd("Broadcast CARRIER_CONFIG_CHANGED for phone " + phoneId
@@ -834,9 +834,9 @@
         intent.putExtra(CarrierConfigManager.EXTRA_REBROADCAST_ON_UNLOCK,
                 mFromSystemUnlocked[phoneId]);
         mContext.sendBroadcastAsUser(intent, UserHandle.ALL);
-        int[] subIds = SubscriptionManager.getSubId(phoneId);
-        if (subIds != null && subIds.length > 0) {
-            logd("Broadcast CARRIER_CONFIG_CHANGED for phone " + phoneId + ", subId=" + subIds[0]);
+        int subId = SubscriptionManager.getSubscriptionId(phoneId);
+        if (SubscriptionManager.isValidSubscriptionId(subId)) {
+            logd("Broadcast CARRIER_CONFIG_CHANGED for phone " + phoneId + ", subId=" + subId);
         } else {
             logd("Broadcast CARRIER_CONFIG_CHANGED for phone " + phoneId);
         }
@@ -1730,12 +1730,12 @@
     }
 
     private boolean hasCarrierPrivileges(@NonNull String pkgName, int phoneId) {
-        int[] subIds = SubscriptionManager.getSubId(phoneId);
-        if (ArrayUtils.isEmpty(subIds)) {
+        int subId = SubscriptionManager.getSubscriptionId(phoneId);
+        if (!SubscriptionManager.isValidSubscriptionId(subId)) {
             return false;
         }
-        return TelephonyManager.from(mContext).createForSubscriptionId(
-                subIds[0]).checkCarrierPrivilegesForPackage(pkgName)
+        return TelephonyManager.from(mContext).createForSubscriptionId(subId)
+                .checkCarrierPrivilegesForPackage(pkgName)
                 == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS;
     }
 
diff --git a/src/com/android/phone/ImsUtil.java b/src/com/android/phone/ImsUtil.java
index ba4ad38..d90c256 100644
--- a/src/com/android/phone/ImsUtil.java
+++ b/src/com/android/phone/ImsUtil.java
@@ -154,12 +154,7 @@
     }
 
     private static int getSubId(int phoneId) {
-        final int[] subIds = SubscriptionManager.getSubId(phoneId);
-        int subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
-        if (subIds != null && subIds.length >= 1) {
-            subId = subIds[0];
-        }
-        return subId;
+        return SubscriptionManager.getSubscriptionId(phoneId);
     }
 
     private static boolean getLastKnownRoamingState(int phoneId) {
diff --git a/src/com/android/phone/PhoneInterfaceManager.java b/src/com/android/phone/PhoneInterfaceManager.java
index 3c22957..c953de5 100644
--- a/src/com/android/phone/PhoneInterfaceManager.java
+++ b/src/com/android/phone/PhoneInterfaceManager.java
@@ -5809,11 +5809,9 @@
      */
     public boolean setBoundImsServiceOverride(int slotIndex, boolean isCarrierService,
             int[] featureTypes, String packageName) {
-        int[] subIds = SubscriptionManager.getSubId(slotIndex);
         TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setBoundImsServiceOverride");
         TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
-                (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
-                "setBoundImsServiceOverride");
+                SubscriptionManager.getSubscriptionId(slotIndex), "setBoundImsServiceOverride");
 
         final long identity = Binder.clearCallingIdentity();
         try {
@@ -5843,12 +5841,10 @@
      */
     @Override
     public boolean clearCarrierImsServiceOverride(int slotIndex) {
-        int[] subIds = SubscriptionManager.getSubId(slotIndex);
         TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(),
                 "clearCarrierImsServiceOverride");
         TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp,
-                (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
-                "clearCarrierImsServiceOverride");
+                SubscriptionManager.getSubscriptionId(slotIndex), "clearCarrierImsServiceOverride");
 
         final long identity = Binder.clearCallingIdentity();
         try {
@@ -5873,11 +5869,9 @@
      */
     public String getBoundImsServicePackage(int slotId, boolean isCarrierImsService,
             @ImsFeature.FeatureType int featureType) {
-        int[] subIds = SubscriptionManager.getSubId(slotId);
         TelephonyPermissions
-                .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(
-                mApp, (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID),
-                "getBoundImsServicePackage");
+                .enforceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege(mApp,
+                        SubscriptionManager.getSubscriptionId(slotId), "getBoundImsServicePackage");
 
         final long identity = Binder.clearCallingIdentity();
         try {
diff --git a/src/com/android/phone/TelephonyShellCommand.java b/src/com/android/phone/TelephonyShellCommand.java
index 3eb4511..9f86c24 100644
--- a/src/com/android/phone/TelephonyShellCommand.java
+++ b/src/com/android/phone/TelephonyShellCommand.java
@@ -1060,7 +1060,7 @@
     private int handleBarringSendCommand() {
         PrintWriter errPw = getErrPrintWriter();
         int slotId = getDefaultSlot();
-        int subId = SubscriptionManager.getSubId(slotId)[0];
+        int subId = SubscriptionManager.getSubscriptionId(slotId);
         @BarringInfo.BarringServiceInfo.BarringType int barringType =
                 BarringInfo.BarringServiceInfo.BARRING_TYPE_UNCONDITIONAL;
         boolean isConditionallyBarred = false;
@@ -1072,7 +1072,7 @@
                 case "-s": {
                     try {
                         slotId = Integer.parseInt(getNextArgRequired());
-                        subId = SubscriptionManager.getSubId(slotId)[0];
+                        subId = SubscriptionManager.getSubscriptionId(slotId);
                     } catch (NumberFormatException e) {
                         errPw.println("barring send requires an integer as a SLOT_ID.");
                         return -1;
@@ -2123,8 +2123,7 @@
                 return SubscriptionManager.INVALID_SUBSCRIPTION_ID;
             }
         }
-        int[] subIds = SubscriptionManager.getSubId(slotId);
-        return subIds[0];
+        return SubscriptionManager.getSubscriptionId(slotId);
     }
 
     private int handleGbaSetServiceCommand() {
diff --git a/src/com/android/phone/settings/RadioInfo.java b/src/com/android/phone/settings/RadioInfo.java
index 3840999..3cf0c93 100644
--- a/src/com/android/phone/settings/RadioInfo.java
+++ b/src/com/android/phone/settings/RadioInfo.java
@@ -1875,14 +1875,8 @@
                     return;
                 }
                 // getSubId says it takes a slotIndex, but it actually takes a phone index
-                int subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
-                int[] subIds = SubscriptionManager.getSubId(phoneIndex);
-                if (subIds != null && subIds.length > 0) {
-                    subId = subIds[0];
-                }
                 mSelectedPhoneIndex = phoneIndex;
-
-                updatePhoneIndex(phoneIndex, subId);
+                updatePhoneIndex(phoneIndex, SubscriptionManager.getSubscriptionId(phoneIndex));
             }
         }