eSIM deprecated API test Refactoring

Test: build
Bug: 159354974
Change-Id: Iedeb90f186ab9f82894e2fecef86d339c8989542
Merged-In: Iedeb90f186ab9f82894e2fecef86d339c8989542
diff --git a/src/com/android/settings/deviceinfo/simstatus/SimStatusDialogController.java b/src/com/android/settings/deviceinfo/simstatus/SimStatusDialogController.java
index 95f74fa..f2bce78 100644
--- a/src/com/android/settings/deviceinfo/simstatus/SimStatusDialogController.java
+++ b/src/com/android/settings/deviceinfo/simstatus/SimStatusDialogController.java
@@ -631,7 +631,7 @@
                 final List<UiccCardInfo> infos = mTelephonyManager.getUiccCardsInfo();
 
                 for (UiccCardInfo info : infos) {
-                    if (info.getSlotIndex() == pSlotId) {
+                    if (info.getPhysicalSlotIndex() == pSlotId) {
                         if (info.isEuicc()) {
                             shouldHaveEid = true;
                             eid = info.getEid();
diff --git a/src/com/android/settings/network/EnableMultiSimSidecar.java b/src/com/android/settings/network/EnableMultiSimSidecar.java
index 4a32433..aefd55f 100644
--- a/src/com/android/settings/network/EnableMultiSimSidecar.java
+++ b/src/com/android/settings/network/EnableMultiSimSidecar.java
@@ -24,6 +24,7 @@
 import android.provider.Settings;
 import android.telephony.CarrierConfigManager;
 import android.telephony.TelephonyManager;
+import android.telephony.UiccPortInfo;
 import android.telephony.UiccSlotInfo;
 import android.util.ArraySet;
 import android.util.Log;
@@ -62,23 +63,23 @@
                 @Override
                 public void onReceive(Context context, Intent intent) {
                     int readySimsCount = getReadySimsCount();
-                    int activeSlotsCount = getActiveSlotsCount();
-                    // If the number of ready SIM count and active slots equal to the number of SIMs
+                    int activePortsCount = getActivePortsCount();
+                    // If the number of ready SIM count and active ports equal to the number of SIMs
                     // need to be activated, the device is successfully switched to multiple active
                     // SIM mode.
-                    if (readySimsCount == mNumOfActiveSim && activeSlotsCount == mNumOfActiveSim) {
+                    if (readySimsCount == mNumOfActiveSim && activePortsCount == mNumOfActiveSim) {
                         Log.i(
                                 TAG,
-                                String.format("%d slots are active and ready.", mNumOfActiveSim));
+                                String.format("%d ports are active and ready.", mNumOfActiveSim));
                         mSimCardStateChangedLatch.countDown();
                         return;
                     }
                     Log.i(
                             TAG,
                             String.format(
-                                    "%d slots are active and %d SIMs are ready. Keep waiting until"
+                                    "%d ports are active and %d SIMs are ready. Keep waiting until"
                                             + " timeout.",
-                                    activeSlotsCount, readySimsCount));
+                                    activePortsCount, readySimsCount));
                 }
             };
 
@@ -162,19 +163,22 @@
         return readyCardsCount;
     }
 
-    // Get active slots count from {@code TelephonyManager#getUiccSlotsInfo}.
-    private int getActiveSlotsCount() {
+    // Get active port count from {@code TelephonyManager#getUiccSlotsInfo}.
+    private int getActivePortsCount() {
         UiccSlotInfo[] slotsInfo = mTelephonyManager.getUiccSlotsInfo();
         if (slotsInfo == null) {
             return 0;
         }
-        int activeSlots = 0;
+        int activePorts = 0;
         for (UiccSlotInfo slotInfo : slotsInfo) {
-            if (slotInfo != null && slotInfo.getIsActive()) {
-                activeSlots++;
+            for (UiccPortInfo portInfo : slotInfo.getPorts()) {
+                if (slotInfo != null && portInfo.isActive()) {
+                    activePorts++;
+                }
             }
+
         }
-        return activeSlots;
+        return activePorts;
     }
 
     /** Returns a list of active removable logical slot ids. */
@@ -185,8 +189,10 @@
         }
         Set<Integer> activeRemovableLogicalSlotIds = new ArraySet<>();
         for (UiccSlotInfo info : infos) {
-            if (info != null && info.getIsActive() && info.isRemovable()) {
-                activeRemovableLogicalSlotIds.add(info.getLogicalSlotIdx());
+            for (UiccPortInfo portInfo :info.getPorts()) {
+                if (info != null && portInfo.isActive() && info.isRemovable()) {
+                    activeRemovableLogicalSlotIds.add(portInfo.getLogicalSlotIndex());
+                }
             }
         }
         return activeRemovableLogicalSlotIds;
diff --git a/src/com/android/settings/network/SubscriptionUtil.java b/src/com/android/settings/network/SubscriptionUtil.java
index 2d60778..c77a294 100644
--- a/src/com/android/settings/network/SubscriptionUtil.java
+++ b/src/com/android/settings/network/SubscriptionUtil.java
@@ -87,8 +87,8 @@
         if (slotInfo == null)  {
             return false;
         }
-        return !slotInfo.getIsEuicc() && !slotInfo.getIsActive() &&
-                slotInfo.getCardStateInfo() == CARD_STATE_INFO_PRESENT;
+        return !slotInfo.getIsEuicc() && !slotInfo.getPorts().stream().findFirst().get()
+                .isActive() && slotInfo.getCardStateInfo() == CARD_STATE_INFO_PRESENT;
     }
 
     /**
@@ -179,7 +179,8 @@
             // verify if subscription is inserted within slot
             for (UiccSlotInfo slotInfo : slotsInfo) {
                 if ((slotInfo != null) && (!slotInfo.getIsEuicc())
-                        && (slotInfo.getLogicalSlotIdx() == subInfo.getSimSlotIndex())) {
+                        && (slotInfo.getPorts().stream().findFirst().get().getLogicalSlotIndex()
+                        == subInfo.getSimSlotIndex())) {
                     return true;
                 }
             }
@@ -576,7 +577,7 @@
             if (!cardInfo.isRemovable()
                     || cardInfo.getCardId() == TelephonyManager.UNSUPPORTED_CARD_ID) {
                 Log.i(TAG, "Skip embedded card or invalid cardId on slot: "
-                        + cardInfo.getSlotIndex());
+                        + cardInfo.getPhysicalSlotIndex());
                 continue;
             }
             Log.i(TAG, "Target removable cardId :" + cardInfo.getCardId());
diff --git a/src/com/android/settings/network/UiccSlotUtil.java b/src/com/android/settings/network/UiccSlotUtil.java
index 6113f5a..ccf3f91 100644
--- a/src/com/android/settings/network/UiccSlotUtil.java
+++ b/src/com/android/settings/network/UiccSlotUtil.java
@@ -96,7 +96,7 @@
         if (slotId == INVALID_PHYSICAL_SLOT_ID) {
             for (int i = 0; i < slots.length; i++) {
                 if (slots[i].isRemovable()
-                        && !slots[i].getIsActive()
+                        && !slots[i].getPorts().stream().findFirst().get().isActive()
                         && slots[i].getCardStateInfo() != UiccSlotInfo.CARD_STATE_INFO_ERROR
                         && slots[i].getCardStateInfo() != UiccSlotInfo.CARD_STATE_INFO_RESTRICTED) {
                     performSwitchToRemovableSlot(i, context);
@@ -107,7 +107,7 @@
             if (slotId >= slots.length || !slots[slotId].isRemovable()) {
                 throw new UiccSlotsException("The given slotId is not a removable slot: " + slotId);
             }
-            if (!slots[slotId].getIsActive()) {
+            if (!slots[slotId].getPorts().stream().findFirst().get().isActive()) {
                 performSwitchToRemovableSlot(slotId, context);
             }
         }
diff --git a/src/com/android/settings/network/telephony/ToggleSubscriptionDialogActivity.java b/src/com/android/settings/network/telephony/ToggleSubscriptionDialogActivity.java
index 0064e6c..65d8cd7 100644
--- a/src/com/android/settings/network/telephony/ToggleSubscriptionDialogActivity.java
+++ b/src/com/android/settings/network/telephony/ToggleSubscriptionDialogActivity.java
@@ -462,7 +462,8 @@
                                 slot ->
                                         slot != null
                                                 && slot.isRemovable()
-                                                && slot.getIsActive()
+                                                && slot.getPorts().stream().anyMatch(
+                                                        port -> port.isActive())
                                                 && slot.getCardStateInfo()
                                                         == UiccSlotInfo.CARD_STATE_INFO_PRESENT);
         if (mIsEsimOperation && isRemovableSimEnabled) {
@@ -476,7 +477,7 @@
             Log.i(
                     TAG,
                     "Removable SIM operation and eSIM profile is enabled. DSDS condition"
-                        + " satisfied.");
+                            + " satisfied.");
             return true;
         }
         Log.i(TAG, "DSDS condition not satisfied.");
diff --git a/src/com/android/settings/sim/receivers/SimSlotChangeHandler.java b/src/com/android/settings/sim/receivers/SimSlotChangeHandler.java
index fe44389..e0bc9cd 100644
--- a/src/com/android/settings/sim/receivers/SimSlotChangeHandler.java
+++ b/src/com/android/settings/sim/receivers/SimSlotChangeHandler.java
@@ -164,14 +164,12 @@
 
     private void handleSimInsert(UiccSlotInfo removableSlotInfo) {
         Log.i(TAG, "Handle SIM inserted.");
-
         if (!isSuwFinished(mContext)) {
             Log.i(TAG, "Still in SUW. Handle SIM insertion after SUW is finished");
             setSuwRemovableSlotAction(mContext, LAST_USER_ACTION_IN_SUW_INSERT);
             return;
         }
-
-        if (removableSlotInfo.getIsActive()) {
+        if (removableSlotInfo.getPorts().stream().findFirst().get().isActive()) {
             Log.i(TAG, "The removable slot is already active. Do nothing.");
             return;
         }
@@ -213,7 +211,8 @@
 
         List<SubscriptionInfo> groupedEmbeddedSubscriptions = getGroupedEmbeddedSubscriptions();
 
-        if (groupedEmbeddedSubscriptions.size() == 0 || !removableSlotInfo.getIsActive()) {
+        if (groupedEmbeddedSubscriptions.size() == 0 || !removableSlotInfo.getPorts().stream()
+                .findFirst().get().isActive()) {
             Log.i(TAG, "eSIM slot is active or no subscriptions exist. Do nothing.");
             return;
         }
diff --git a/src/com/android/settings/sim/receivers/SimSlotChangeReceiver.java b/src/com/android/settings/sim/receivers/SimSlotChangeReceiver.java
index f2c7c65..f144c6b 100644
--- a/src/com/android/settings/sim/receivers/SimSlotChangeReceiver.java
+++ b/src/com/android/settings/sim/receivers/SimSlotChangeReceiver.java
@@ -20,6 +20,7 @@
 import android.content.Intent;
 import android.telephony.TelephonyManager;
 import android.telephony.UiccCardInfo;
+import android.telephony.UiccPortInfo;
 import android.telephony.UiccSlotInfo;
 import android.telephony.euicc.EuiccManager;
 import android.text.TextUtils;
@@ -116,9 +117,11 @@
             if (cardInfo == null) {
                 continue;
             }
-            if (!TextUtils.isEmpty(slotInfo.getCardId())
-                    || !TextUtils.isEmpty(cardInfo.getIccId())) {
-                isAllCardStringsEmpty = false;
+            for (UiccPortInfo portInfo : cardInfo.getPorts()) {
+                if (!TextUtils.isEmpty(slotInfo.getCardId())
+                        || !TextUtils.isEmpty(portInfo.getIccId())) {
+                    isAllCardStringsEmpty = false;
+                }
             }
         }
 
@@ -139,7 +142,7 @@
             return null;
         }
         return cardInfos.stream()
-                .filter(info -> info.getSlotIndex() == physicalSlotIndex)
+                .filter(info -> info.getPhysicalSlotIndex() == physicalSlotIndex)
                 .findFirst()
                 .orElse(null);
     }
diff --git a/tests/unit/src/com/android/settings/deviceinfo/simstatus/SimStatusDialogControllerTest.java b/tests/unit/src/com/android/settings/deviceinfo/simstatus/SimStatusDialogControllerTest.java
index dfe2bc0..5360dac 100644
--- a/tests/unit/src/com/android/settings/deviceinfo/simstatus/SimStatusDialogControllerTest.java
+++ b/tests/unit/src/com/android/settings/deviceinfo/simstatus/SimStatusDialogControllerTest.java
@@ -54,6 +54,7 @@
 import android.telephony.SubscriptionManager;
 import android.telephony.TelephonyManager;
 import android.telephony.UiccCardInfo;
+import android.telephony.UiccPortInfo;
 import android.telephony.euicc.EuiccManager;
 
 import androidx.lifecycle.LifecycleOwner;
@@ -73,6 +74,7 @@
 import org.mockito.MockitoAnnotations;
 
 import java.util.ArrayList;
+import java.util.Collections;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
@@ -387,17 +389,34 @@
                 false,                                  // isEuicc
                 0,                                      // cardId
                 null,                                   // eid
-                "123451234567890",                      // iccid
                 0,                                      // slotIndex
-                true);                                  // isRemovable
+                true,                                   // isRemovable
+                false,            // isMultipleEnabledProfileSupported
+                Collections.singletonList(
+                        new UiccPortInfo(
+                                "123451234567890",     // iccId
+                                0,                   // portIdx
+                                0,              // logicalSlotIdx
+                                true               // isActive
+                        )
+                ));
         uiccCardInfos.add(uiccCardInfo1);
         UiccCardInfo uiccCardInfo2 = new UiccCardInfo(
                 true,                                   // isEuicc
                 1,                                      // cardId
                 null,                                   // eid (unavailable)
-                null,                                   // iccid
                 1,                                      // slotIndex
-                false);                                 // isRemovable
+                false,                             // isRemovable
+                false,
+                Collections.singletonList(
+                        new UiccPortInfo(
+                                null,                  // iccId
+                                1,                   // portIdx
+                                1,              // logicalSlotIdx
+                                true               // isActive
+                        )
+                )
+        );
         uiccCardInfos.add(uiccCardInfo2);
         when(mTelephonyManager.getUiccCardsInfo()).thenReturn(uiccCardInfos);
 
@@ -427,17 +446,31 @@
                 true,                                   // isEuicc
                 0,                                      // cardId
                 TEST_EID_FROM_CARD,                     // eid
-                null,                                   // iccid
                 0,                                      // slotIndex
-                false);                                 // isRemovable
+                false,                                 // isRemovable
+                false,
+                Collections.singletonList(new UiccPortInfo(
+                        null,                                 // iccId
+                        0,                                  // portIdx
+                        0,                             // logicalSlotIdx
+                        true                              // isActive
+                )));
         uiccCardInfos.add(uiccCardInfo1);
         UiccCardInfo uiccCardInfo2 = new UiccCardInfo(
                 false,                                  // isEuicc
                 1,                                      // cardId
                 null,                                   // eid
-                "123451234567890",                      // iccid
                 1,                                      // slotIndex
-                true);                                  // isRemovable
+                true,                             // isRemovable
+                false,           // isMultipleEnabledProfileSupported
+                Collections.singletonList(
+                        new UiccPortInfo(
+                                "123451234567890",      // iccId
+                                1,                    // portIdx
+                                1,               // logicalSlotIdx
+                                true                // isActive
+                        )
+                ));
         uiccCardInfos.add(uiccCardInfo2);
         when(mTelephonyManager.getUiccCardsInfo()).thenReturn(uiccCardInfos);
 
@@ -468,17 +501,34 @@
                 false,                                  // isEuicc
                 0,                                      // cardId
                 null,                                   // eid
-                "123451234567890",                      // iccid
                 0,                                      // slotIndex
-                true);                                  // isRemovable
+                true,                             // isRemovable
+                false,             // isMultipleEnabledProfileSupported
+                Collections.singletonList(
+                        new UiccPortInfo(
+                                "123451234567890",       // iccId
+                                1,                     // portIdx
+                                1,                // logicalSlotIdx
+                                true                 // isActive
+                        )
+                ));
         uiccCardInfos.add(uiccCardInfo1);
         UiccCardInfo uiccCardInfo2 = new UiccCardInfo(
                 true,                                   // isEuicc
                 1,                                      // cardId
                 null,                                   // eid (unavailable)
-                null,                                   // iccid
                 1,                                      // slotIndex
-                false);                                 // isRemovable
+                false,                                 // isRemovable
+                false,             // isMultipleEnabledProfileSupported
+                Collections.singletonList(
+                        new UiccPortInfo(
+                                null,                   // iccId
+                                1,                    // portIdx
+                                1,               // logicalSlotIdx
+                                true                // isActive
+                        )
+                )
+        );
         uiccCardInfos.add(uiccCardInfo2);
         when(mTelephonyManager.getUiccCardsInfo()).thenReturn(uiccCardInfos);
 
@@ -511,17 +561,33 @@
                 false,                                  // isEuicc
                 0,                                      // cardId
                 null,                                   // eid
-                "123451234567890",                      // iccid
                 0,                                      // slotIndex
-                true);                                  // isRemovable
+                true,                                  // isRemovable
+                false,              // isMultipleEnabledProfileSupported
+                Collections.singletonList(
+                        new UiccPortInfo(
+                                "123451234567890",        // iccId
+                                0,                      // portIdx
+                                0,                 // logicalSlotIdx
+                                true                  // isActive
+                        )
+                ));
         uiccCardInfos.add(uiccCardInfo1);
         UiccCardInfo uiccCardInfo2 = new UiccCardInfo(
                 true,                                   // isEuicc
                 1,                                      // cardId
                 TEST_EID_FROM_CARD,                     // eid
-                null,                                   // iccid
                 1,                                      // slotIndex
-                false);                                 // isRemovable
+                false,                                 // isRemovable
+                false,            // isMultipleEnabledProfileSupported
+                Collections.singletonList(
+                        new UiccPortInfo(
+                                null,                  // iccId
+                                1,                   // portIdx
+                                1,              // logicalSlotIdx
+                                true               // isActive
+                        )
+                ));
         uiccCardInfos.add(uiccCardInfo2);
         when(mTelephonyManager.getUiccCardsInfo()).thenReturn(uiccCardInfos);
 
@@ -552,9 +618,17 @@
                 true,                                   // isEuicc
                 0,                                      // cardId
                 TEST_EID_FROM_CARD,                     // eid (not used)
-                null,                                   // iccid
                 0,                                      // slotIndex
-                false);                                 // isRemovable
+                false,                                 // isRemovable
+                false,            // isMultipleEnabledProfileSupported
+                Collections.singletonList(
+                        new UiccPortInfo(
+                                null,                  // iccId
+                                0,                   // portIdx
+                                0,              // logicalSlotIdx
+                                true               // isActive
+                        )
+                ));
         uiccCardInfos.add(uiccCardInfo);
         when(mTelephonyManager.getUiccCardsInfo()).thenReturn(uiccCardInfos);
 
@@ -583,9 +657,18 @@
                 true,                                   // isEuicc (eUICC slot is selected)
                 0,                                      // cardId
                 TEST_EID_FROM_CARD,                     // eid (not used)
-                null,                                   // iccid
                 0,                                      // slotIndex
-                false);                                 // isRemovable
+                false,                                 // isRemovable
+                false,               // isMultipleEnabledProfileSupported
+                Collections.singletonList(
+                        new UiccPortInfo(
+                                null,                // iccId
+                                0,                 // portIdx
+                                0,            // logicalSlotIdx
+                                true             // isActive
+                        )
+                )
+        );
         uiccCardInfos.add(uiccCardInfo);
         when(mTelephonyManager.getUiccCardsInfo()).thenReturn(uiccCardInfos);
 
@@ -616,9 +699,18 @@
                 false,                                  // isEuicc (eUICC slot is not selected)
                 0,                                      // cardId
                 null,                                   // eid
-                "123451234567890",                      // iccid
                 0,                                      // slotIndex
-                true);                                  // isRemovable
+                true,                                  // isRemovable
+                false,            // isMultipleEnabledProfileSupported
+                Collections.singletonList(
+                        new UiccPortInfo(
+                                "123451234567890",        // iccId
+                                0,                      // portIdx
+                                0,                 // logicalSlotIdx
+                                true                  // isActive
+
+                        )
+                ));
         uiccCardInfos.add(uiccCardInfo);
         when(mTelephonyManager.getUiccCardsInfo()).thenReturn(uiccCardInfos);
 
@@ -649,9 +741,17 @@
                 false,                                  // isEuicc
                 0,                                      // cardId
                 null,                                   // eid
-                "123451234567890",                      // iccid
                 0,                                      // slotIndex
-                true);                                  // isRemovable
+                true,                                  // isRemovable
+                false,           //isMultipleEnabledProfileSupported
+                Collections.singletonList(
+                        new UiccPortInfo(
+                                "123451234567890",      // iccId
+                                0,                    // portIdx
+                                0,               // logicalSlotIdx
+                                true                // isActive
+                        )
+                ));
         uiccCardInfos.add(uiccCardInfo);
         when(mTelephonyManager.getUiccCardsInfo()).thenReturn(uiccCardInfos);