[MEP] Adding getSimSlotMapping Telephony API

Adding getSimSlotsMapping Telephony API
Test: build
Bug: 206718882
Change-Id: I2a0b6264a818ad115f347f627eca6c8a0ae07846
Merged-In: I2a0b6264a818ad115f347f627eca6c8a0ae07846
diff --git a/src/com/android/phone/PhoneInterfaceManager.java b/src/com/android/phone/PhoneInterfaceManager.java
index 3b1cfbd..3110021 100755
--- a/src/com/android/phone/PhoneInterfaceManager.java
+++ b/src/com/android/phone/PhoneInterfaceManager.java
@@ -8773,7 +8773,7 @@
 
     @Override
     public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) {
-        // Verify that tha callingPackage belongs to the calling UID
+        // Verify that the callingPackage belongs to the calling UID
         mApp.getSystemService(AppOpsManager.class)
                 .checkPackage(Binder.getCallingUid(), callingPackage);
 
@@ -8818,7 +8818,6 @@
                     filteredInfos.add(getUiccCardInfoUnPrivileged(cardInfo));
                     continue;
                 }
-
                 if (haveCarrierPrivilegeAccess(card, callingPackage)) {
                     filteredInfos.add(cardInfo);
                 } else {
@@ -8870,7 +8869,7 @@
     }
     @Override
     public UiccSlotInfo[] getUiccSlotsInfo(String callingPackage) {
-        // Verify that tha callingPackage belongs to the calling UID
+        // Verify that the callingPackage belongs to the calling UID
         mApp.getSystemService(AppOpsManager.class)
                 .checkPackage(Binder.getCallingUid(), callingPackage);
 
@@ -8915,12 +8914,16 @@
                 if (hasReadPermission) {
                     iccId = slot.getIccId();
                 } else {
-                    // if no read permission checking carrier
-                    if (haveCarrierPrivilegeAccess(card, callingPackage)) {
-                        iccId = slot.getIccId();
+                    if (card != null) {
+                        // if no read permission checking carrier
+                        if (haveCarrierPrivilegeAccess(card, callingPackage)) {
+                            iccId = slot.getIccId();
+                        } else {
+                            //if no carrier permission redact ICCID
+                            iccId = IccUtils.TEST_ICCID;
+                        }
                     } else {
-                        //if no carrier permission redact ICCID
-                        iccId = IccUtils.TEST_ICCID;
+                        iccId = null;
                     }
                 }
                 if (card != null) {
@@ -9591,21 +9594,26 @@
     }
 
     @Override
-    public int[] getSlotsMapping(@NonNull String callingPackage) {
+    public List<UiccSlotMapping> getSlotsMapping(String callingPackage) {
         enforceReadPrivilegedPermission("getSlotsMapping");
-
+        // Verify that the callingPackage belongs to the calling UID
+        mApp.getSystemService(AppOpsManager.class)
+                .checkPackage(Binder.getCallingUid(), callingPackage);
         final long identity = Binder.clearCallingIdentity();
+        List<UiccSlotMapping> slotMap = new ArrayList<>();
         try {
-            int phoneCount = TelephonyManager.getDefault().getPhoneCount();
-            // All logical slots should have a mapping to a physical slot.
-            int[] logicalSlotsMapping = new int[phoneCount];
-            UiccSlotInfo[] slotInfos = getUiccSlotsInfo(callingPackage);
-            for (int i = 0; i < slotInfos.length; i++) {
-                if (SubscriptionManager.isValidPhoneId(slotInfos[i].getLogicalSlotIdx())) {
-                    logicalSlotsMapping[slotInfos[i].getLogicalSlotIdx()] = i;
+            UiccSlotInfo[] slotInfos = getUiccSlotsInfo(mApp.getOpPackageName());
+            if (slotInfos != null) {
+                for (int i = 0; i < slotInfos.length; i++) {
+                    for (UiccPortInfo portInfo : slotInfos[i].getPorts()) {
+                        if (SubscriptionManager.isValidPhoneId(portInfo.getLogicalSlotIndex())) {
+                            slotMap.add(new UiccSlotMapping(portInfo.getPortIndex(), i,
+                                    portInfo.getLogicalSlotIndex()));
+                        }
+                    }
                 }
             }
-            return logicalSlotsMapping;
+            return slotMap;
         } finally {
             Binder.restoreCallingIdentity(identity);
         }