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
Change-Id: I7e1e44509169b11024455d52749531f021ab7383
diff --git a/src/com/android/phone/CarrierConfigLoader.java b/src/com/android/phone/CarrierConfigLoader.java
index 5d9928e..a270e07 100644
--- a/src/com/android/phone/CarrierConfigLoader.java
+++ b/src/com/android/phone/CarrierConfigLoader.java
@@ -804,10 +804,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
@@ -825,9 +825,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);
         }
@@ -1686,12 +1686,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 c50e99a..865a948 100644
--- a/src/com/android/phone/PhoneInterfaceManager.java
+++ b/src/com/android/phone/PhoneInterfaceManager.java
@@ -5976,11 +5976,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 {
@@ -6010,12 +6008,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 {
@@ -6040,11 +6036,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 0cf120a..fdaf1bb 100644
--- a/src/com/android/phone/TelephonyShellCommand.java
+++ b/src/com/android/phone/TelephonyShellCommand.java
@@ -1099,7 +1099,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;
@@ -1111,7 +1111,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;
@@ -2162,8 +2162,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 29f2d73..ac3259a 100644
--- a/src/com/android/phone/settings/RadioInfo.java
+++ b/src/com/android/phone/settings/RadioInfo.java
@@ -1902,14 +1902,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));
             }
         }