Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit fc7a8202 authored by Sandeep Jawalkar's avatar Sandeep Jawalkar Committed by Android (Google) Code Review
Browse files

Merge "Updating Unit Test for EuiccContollers methods"

parents c3e147c5 16bc55ef
Loading
Loading
Loading
Loading
+4 −2
Original line number Diff line number Diff line
@@ -1147,7 +1147,8 @@ public class EuiccController extends IEuiccController.Stub {
     * Returns the resolved portIndex or {@link TelephonyManager#INVALID_PORT_INDEX} if calling
     * cannot manage any active subscription.
     */
    private int getResolvedPortIndexForDisableSubscription(int cardId, String callingPackage,
    @VisibleForTesting(visibility = VisibleForTesting.Visibility.PRIVATE)
    public int getResolvedPortIndexForDisableSubscription(int cardId, String callingPackage,
            boolean callerCanWriteEmbeddedSubscriptions) {
        List<SubscriptionInfo> subInfoList = mSubscriptionManager
                .getActiveSubscriptionInfoList(/* userVisibleOnly */false);
@@ -1175,7 +1176,8 @@ public class EuiccController extends IEuiccController.Stub {
     * Returns the resolved portIndex or {@link TelephonyManager#INVALID_PORT_INDEX} if no port
     * is available without user consent.
     */
    private int getResolvedPortIndexForSubscriptionSwitch(int cardId) {
    @VisibleForTesting(visibility = VisibleForTesting.Visibility.PRIVATE)
    public int getResolvedPortIndexForSubscriptionSwitch(int cardId) {
        int slotIndex = getSlotIndexFromCardId(cardId);
        // Euicc Slot
        UiccSlot slot = UiccController.getInstance().getUiccSlot(slotIndex);
+89 −1
Original line number Diff line number Diff line
@@ -128,7 +128,6 @@ public class EuiccControllerTest extends TelephonyTest {
    private static final int SUBSCRIPTION_ID = 12345;
    private static final String ICC_ID = "54321";
    private static final int CARD_ID = 25;
    private static final int PORT_INDEX = 0;

    // Mocked classes
    private EuiccConnector mMockConnector;
@@ -786,6 +785,70 @@ public class EuiccControllerTest extends TelephonyTest {
        assertTrue(mController.mCalledRefreshSubscriptionsAndSendResult);
    }

    @Test
    public void testGetResolvedPortIndexForSubscriptionSwitchWithOutMEP() throws Exception {
        setUpUiccSlotData();
        assertEquals(TelephonyManager.DEFAULT_PORT_INDEX,
                mController.getResolvedPortIndexForSubscriptionSwitch(CARD_ID));
    }

    @Test
    public void testGetResolvedPortIndexForSubscriptionSwitchWithMEP() throws Exception {
        setUpUiccSlotDataWithMEP();
        when(mUiccSlot.getPortList()).thenReturn(new int[]{0, 1});
        when(mUiccSlot.isPortActive(TelephonyManager.DEFAULT_PORT_INDEX)).thenReturn(false);
        when(mUiccSlot.isPortActive(1)).thenReturn(true);
        when(mTelephonyManager.getActiveModemCount()).thenReturn(2);
        assertEquals(1, mController.getResolvedPortIndexForSubscriptionSwitch(CARD_ID));
    }

    @Test
    public void testGetResolvedPortIndexForSubscriptionSwitchWithUiccSlotNull() throws Exception {
        assertEquals(TelephonyManager.DEFAULT_PORT_INDEX,
                mController.getResolvedPortIndexForSubscriptionSwitch(CARD_ID));
    }

    @Test
    public void testGetResolvedPortIndexForSubscriptionSwitchWithPsimActiveAndSS()
            throws Exception {
        when(mUiccController.getUiccSlot(anyInt())).thenReturn(mUiccSlot);
        when(mUiccSlot.isRemovable()).thenReturn(true);
        when(mUiccSlot.isEuicc()).thenReturn(false);
        when(mUiccSlot.isActive()).thenReturn(true);
        when(mTelephonyManager.getActiveModemCount()).thenReturn(1);
        assertEquals(TelephonyManager.DEFAULT_PORT_INDEX,
                mController.getResolvedPortIndexForSubscriptionSwitch(CARD_ID));
    }

    @Test
    public void testGetResolvedPortIndexForSubscriptionSwitchWithPsimInActiveAndSS()
            throws Exception {
        setUpUiccSlotDataWithMEP();
        when(mUiccSlot.getPortList()).thenReturn(new int[]{0});
        when(mUiccSlot.isPortActive(TelephonyManager.DEFAULT_PORT_INDEX)).thenReturn(true);
        when(mTelephonyManager.getActiveModemCount()).thenReturn(1);
        assertEquals(TelephonyManager.DEFAULT_PORT_INDEX,
                mController.getResolvedPortIndexForSubscriptionSwitch(CARD_ID));
    }

    @Test
    public void testgetResolvedPortIndexForDisableSubscriptionForNoActiveSubscription()
            throws Exception {
        when(mSubscriptionManager.getActiveSubscriptionInfoList(anyBoolean())).thenReturn(null);
        assertEquals(-1,
                mController.getResolvedPortIndexForDisableSubscription(
                        CARD_ID, PACKAGE_NAME, true));
    }

    @Test
    public void testgetResolvedPortIndexForDisableSubscriptionForActiveSubscriptions()
            throws Exception {
        setActiveSubscriptionInfoInMEPMode();
        assertEquals(1,
                mController.getResolvedPortIndexForDisableSubscription(
                        CARD_ID, PACKAGE_NAME, false));
    }

    @Test
    public void testDeleteSubscription_noPrivileges() throws Exception {
        setHasWriteEmbeddedPermission(false);
@@ -1233,6 +1296,11 @@ public class EuiccControllerTest extends TelephonyTest {
        when(mUiccSlot.isMultipleEnabledProfileSupported()).thenReturn(false);
    }

    private void setUpUiccSlotDataWithMEP() {
        when(mUiccController.getUiccSlot(anyInt())).thenReturn(mUiccSlot);
        when(mUiccSlot.isMultipleEnabledProfileSupported()).thenReturn(true);
    }

    private void setGetEidPermissions(
            boolean hasPhoneStatePrivileged, boolean hasCarrierPrivileges) throws Exception {
        doReturn(hasPhoneStatePrivileged
@@ -1314,6 +1382,26 @@ public class EuiccControllerTest extends TelephonyTest {
        when(mSubscriptionManager.getActiveSubscriptionInfoList(anyBoolean())).thenReturn(subInfos);
    }

    private void setActiveSubscriptionInfoInMEPMode()
            throws Exception {
        SubscriptionInfo subInfo1 = new SubscriptionInfo.Builder()
                .setEmbedded(true)
                .setCardId(CARD_ID)
                .setPortIndex(TelephonyManager.DEFAULT_PORT_INDEX)
                .build();
        SubscriptionInfo subInfo2 = new SubscriptionInfo.Builder()
                .setEmbedded(true)
                .setCardId(CARD_ID)
                .setPortIndex(1)
                .build();
        when(mSubscriptionManager.canManageSubscription(subInfo1, PACKAGE_NAME)).thenReturn(
                false);
        when(mSubscriptionManager.canManageSubscription(subInfo2, PACKAGE_NAME)).thenReturn(
                true);
        ArrayList<SubscriptionInfo> subInfos = new ArrayList<>(Arrays.asList(subInfo1, subInfo2));
        when(mSubscriptionManager.getActiveSubscriptionInfoList(anyBoolean())).thenReturn(subInfos);
    }

    private void prepareOperationSubscription(boolean hasPrivileges) throws Exception {
        SubscriptionInfo subInfo = new SubscriptionInfo.Builder()
                .setId(SUBSCRIPTION_ID)