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

Commit c710b1fe authored by Malcolm Chen's avatar Malcolm Chen
Browse files

Adding unittest for enable / disable subscription.

Bug: 120945564
Test: unittest
Change-Id: I7690abdfec95340db8c5af68dd7bc9734ff801d2
Merged-In: I7690abdfec95340db8c5af68dd7bc9734ff801d2
parent 4ded8520
Loading
Loading
Loading
Loading
+41 −0
Original line number Original line Diff line number Diff line
@@ -37,6 +37,7 @@ import android.os.UserHandle;
import android.provider.Settings;
import android.provider.Settings;
import android.telephony.SubscriptionInfo;
import android.telephony.SubscriptionInfo;
import android.telephony.SubscriptionManager;
import android.telephony.SubscriptionManager;
import android.telephony.UiccSlotInfo;
import android.test.mock.MockContentResolver;
import android.test.mock.MockContentResolver;
import android.test.suitebuilder.annotation.SmallTest;
import android.test.suitebuilder.annotation.SmallTest;


@@ -54,6 +55,7 @@ import java.util.Map;


public class SubscriptionControllerTest extends TelephonyTest {
public class SubscriptionControllerTest extends TelephonyTest {
    private static final int SINGLE_SIM = 1;
    private static final int SINGLE_SIM = 1;
    private static final int DUAL_SIM = 2;
    private String mCallingPackage;
    private String mCallingPackage;
    private SubscriptionController mSubscriptionControllerUT;
    private SubscriptionController mSubscriptionControllerUT;
    private MockContentResolver mMockContentResolver;
    private MockContentResolver mMockContentResolver;
@@ -754,6 +756,45 @@ public class SubscriptionControllerTest extends TelephonyTest {
                .queryLocalInterface(anyString());
                .queryLocalInterface(anyString());
    }
    }


    @Test
    @SmallTest
    public void testEnableDisableSubscriptionSanity() throws Exception {
        testInsertSim();

        // Non existing subId.
        assertFalse(mSubscriptionControllerUT.isSubscriptionEnabled(2));
        assertFalse(mSubscriptionControllerUT.isSubscriptionEnabled(-1));

        // Test invalid arguments.
        try {
            mSubscriptionControllerUT.getEnabledSubscriptionId(3);
            fail("Should throw IllegalArgumentException with invalid subId.");
        } catch (IllegalArgumentException exception) {
            // Expected.
        }
    }

    @Test
    @SmallTest
    public void testEnableDisableSubscriptionSingleSim() throws Exception {
        testInsertSim();
        // UiccSlotInfo that maps logicalSlotIndex 0 to physicalSlotIndex 0.
        UiccSlotInfo slotInfo = new UiccSlotInfo(true, false, "", 0, 0, false);
        UiccSlotInfo[] slotInfos = new UiccSlotInfo[] {slotInfo};
        doReturn(slotInfos).when(mTelephonyManager).getUiccSlotsInfo();

        // Current active subscription should be the enabled one.
        assertTrue(mSubscriptionControllerUT.isSubscriptionEnabled(1));
        assertEquals(1, mSubscriptionControllerUT.getEnabledSubscriptionId(0));
        // SetSubscriptionEnabled should fail (no-op) on single SIM device.
        assertFalse(mSubscriptionControllerUT.setSubscriptionEnabled(false, 1));

        // Current active subscription should be the enabled one.
        assertTrue(mSubscriptionControllerUT.isSubscriptionEnabled(1));
        assertEquals(1, mSubscriptionControllerUT.getEnabledSubscriptionId(0));
        // TODO: test dual SIM case when SubscriptionControllerTest supports dual SIM config.
    }

    @Test
    @Test
    @SmallTest
    @SmallTest
    public void testGetActiveSubIdList() throws Exception {
    public void testGetActiveSubIdList() throws Exception {