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

Commit 6931c9eb authored by Jack Yu's avatar Jack Yu
Browse files

Migrated unit test to the new subscription manager

Bug: 268654362
Test: atest FrameworksTelephonyTests
Change-Id: I355103117c0ad00bb6c6192c3f4c6585fbaf10a8
parent 84e67f38
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -814,6 +814,7 @@ public class MultiSimSettingController extends Handler {
        @TelephonyManager.DefaultSubscriptionSelectType
        int simSelectDialogType = getSimSelectDialogType(
                change, dataSelected, voiceSelected, smsSelected);
        log("sendSubChangeNotificationIfNeeded: simSelectDialogType=" + simSelectDialogType);
        SimCombinationWarningParams simCombinationParams = getSimCombinationWarningParams(change);

        if (simSelectDialogType != EXTRA_DEFAULT_SUBSCRIPTION_SELECT_TYPE_NONE
+1 −2
Original line number Diff line number Diff line
@@ -27,6 +27,7 @@ import static org.mockito.Mockito.when;

import android.os.Handler;
import android.os.Looper;

import com.android.internal.telephony.emergency.EmergencyNumberTracker;

import org.junit.After;
@@ -42,7 +43,6 @@ public class ConnectionTest extends TelephonyTest {

    // Mocked classes
    protected Call mCall;
    protected GsmCdmaPhone mPhone2;  // mPhone as phone 1 is already defined in TelephonyTest.
    protected EmergencyNumberTracker mEmergencyNumberTracker2;
    protected Connection.PhoneFactoryProxy mPhoneFactoryProxy;
    protected Connection mTestConnection;
@@ -127,7 +127,6 @@ public class ConnectionTest extends TelephonyTest {
        doReturn(mPhone).when(mCT).getPhone();
        replaceInstance(Handler.class, "mLooper", mCT, Looper.getMainLooper());

        mPhone2 = mock(GsmCdmaPhone.class);
        mEmergencyNumberTracker2 = mock(EmergencyNumberTracker.class);
        doReturn(mEmergencyNumberTracker2).when(mPhone2).getEmergencyNumberTracker();

+58 −13
Original line number Diff line number Diff line
@@ -79,7 +79,6 @@ import android.telephony.NetworkRegistrationInfo;
import android.telephony.RadioAccessFamily;
import android.telephony.ServiceState;
import android.telephony.SmsCbMessage;
import android.telephony.SubscriptionInfo;
import android.telephony.SubscriptionManager;
import android.telephony.TelephonyManager;
import android.telephony.ims.ImsCallProfile;
@@ -95,6 +94,7 @@ import com.android.internal.telephony.cdma.CdmaSmsBroadcastConfigInfo;
import com.android.internal.telephony.domainselection.DomainSelectionResolver;
import com.android.internal.telephony.gsm.SmsBroadcastConfigInfo;
import com.android.internal.telephony.imsphone.ImsPhone;
import com.android.internal.telephony.subscription.SubscriptionInfoInternal;
import com.android.internal.telephony.subscription.SubscriptionManagerService;
import com.android.internal.telephony.test.SimulatedCommands;
import com.android.internal.telephony.test.SimulatedCommandsVerifier;
@@ -1099,12 +1099,15 @@ public class GsmCdmaPhoneTest extends TelephonyTest {
        // invalid subId
        doReturn(SubscriptionManager.INVALID_SUBSCRIPTION_ID).when(mSubscriptionController).
                getSubId(anyInt());
        doReturn(SubscriptionManager.INVALID_SUBSCRIPTION_ID).when(mSubscriptionManagerService)
                .getSubId(anyInt());
        assertEquals(false, mPhoneUT.getCallForwardingIndicator());

        // valid subId, sharedPreference not present
        int subId1 = 0;
        int subId2 = 1;
        doReturn(subId1).when(mSubscriptionController).getSubId(anyInt());
        doReturn(subId1).when(mSubscriptionManagerService).getSubId(anyInt());
        assertEquals(false, mPhoneUT.getCallForwardingIndicator());

        // old sharedPreference present
@@ -1127,6 +1130,7 @@ public class GsmCdmaPhoneTest extends TelephonyTest {

        // check for another subId
        doReturn(subId2).when(mSubscriptionController).getSubId(anyInt());
        doReturn(subId2).when(mSubscriptionManagerService).getSubId(anyInt());
        assertEquals(false, mPhoneUT.getCallForwardingIndicator());

        // set value for the new subId in sharedPreference
@@ -1136,6 +1140,7 @@ public class GsmCdmaPhoneTest extends TelephonyTest {

        // switching back to previous subId, stored value should still be available
        doReturn(subId1).when(mSubscriptionController).getSubId(anyInt());
        doReturn(subId1).when(mSubscriptionManagerService).getSubId(anyInt());
        assertEquals(true, mPhoneUT.getCallForwardingIndicator());

        // cleanup
@@ -1295,6 +1300,8 @@ public class GsmCdmaPhoneTest extends TelephonyTest {
        Message.obtain(mPhoneUT, EVENT_UICC_APPS_ENABLEMENT_STATUS_CHANGED,
                new AsyncResult(null, true, null)).sendToTarget();
        processAllMessages();

        verify(mSubscriptionManagerService, never()).getAllSubInfoList(anyString(), anyString());
        verify(mSubscriptionController, never()).getSubInfoForIccId(any());

        // Have IccId defined. But expected value and current value are the same. So no RIL command
@@ -1303,7 +1310,12 @@ public class GsmCdmaPhoneTest extends TelephonyTest {
        doReturn(iccId).when(mUiccSlot).getIccId(anyInt());
        Message.obtain(mPhoneUT, EVENT_ICC_CHANGED, null).sendToTarget();
        processAllMessages();
        if (isSubscriptionManagerServiceEnabled()) {
            verify(mSubscriptionManagerService).getAllSubInfoList(anyString(),
                    nullable(String.class));
        } else {
            verify(mSubscriptionController).getSubInfoForIccId(iccId);
        }
        verify(mMockCi, never()).enableUiccApplications(anyBoolean(), any());
    }

@@ -1475,6 +1487,8 @@ public class GsmCdmaPhoneTest extends TelephonyTest {
    public void testEventCarrierConfigChanged() {
        doReturn(null).when(mSubscriptionController).getSubscriptionProperty(anyInt(),
                eq(SubscriptionManager.NR_ADVANCED_CALLING_ENABLED));
        doReturn(null).when(mSubscriptionManagerService).getSubscriptionProperty(anyInt(),
                eq(SubscriptionManager.NR_ADVANCED_CALLING_ENABLED), anyString(), anyString());

        mPhoneUT.mCi = mMockCi;
        mPhoneUT.sendMessage(mPhoneUT.obtainMessage(Phone.EVENT_CARRIER_CONFIG_CHANGED));
@@ -1544,9 +1558,12 @@ public class GsmCdmaPhoneTest extends TelephonyTest {
    public void testLoadAllowedNetworksFromSubscriptionDatabase_loadTheNullValue_isLoadedTrue() {
        int subId = 1;
        doReturn(subId).when(mSubscriptionController).getSubId(anyInt());
        doReturn(subId).when(mSubscriptionManagerService).getSubId(anyInt());

        doReturn(null).when(mSubscriptionController).getSubscriptionProperty(anyInt(),
                eq(SubscriptionManager.ALLOWED_NETWORK_TYPES));
        doReturn(null).when(mSubscriptionManagerService).getSubscriptionProperty(anyInt(),
                eq(SubscriptionManager.ALLOWED_NETWORK_TYPES), anyString(), anyString());

        mPhoneUT.loadAllowedNetworksFromSubscriptionDatabase();

@@ -1558,10 +1575,13 @@ public class GsmCdmaPhoneTest extends TelephonyTest {
    public void testLoadAllowedNetworksFromSubscriptionDatabase_subIdNotValid_isLoadedFalse() {
        int subId = -1;
        doReturn(subId).when(mSubscriptionController).getSubId(anyInt());
        doReturn(subId).when(mSubscriptionManagerService).getSubId(anyInt());

        when(mSubscriptionController.getSubscriptionProperty(anyInt(),
                eq(SubscriptionManager.ALLOWED_NETWORK_TYPES))).thenReturn(null);

        when(mSubscriptionManagerService.getSubscriptionProperty(anyInt(),
                eq(SubscriptionManager.ALLOWED_NETWORK_TYPES), anyString(), anyString()))
                .thenReturn(null);

        mPhoneUT.loadAllowedNetworksFromSubscriptionDatabase();

@@ -1572,12 +1592,18 @@ public class GsmCdmaPhoneTest extends TelephonyTest {
    public void testLoadAllowedNetworksFromSubscriptionDatabase_allValidData() {
        int subId = 1;
        doReturn(subId).when(mSubscriptionController).getSubId(anyInt());
        doReturn(subId).when(mSubscriptionManagerService).getSubId(anyInt());

        // 13 == TelephonyManager.NETWORK_TYPE_LTE
        // NR_BITMASK == 4096 == 1 << (13 - 1)
        String validSerializedNetworkMap = "user=4096,power=4096,carrier=4096,enable_2g=4096";
        doReturn(validSerializedNetworkMap).when(mSubscriptionController).getSubscriptionProperty(
                anyInt(), eq(SubscriptionManager.ALLOWED_NETWORK_TYPES));
        SubscriptionInfoInternal si = new SubscriptionInfoInternal.Builder()
                .setId(1)
                .setAllowedNetworkTypesForReasons(validSerializedNetworkMap)
                .build();
        doReturn(si).when(mSubscriptionManagerService).getSubscriptionInfoInternal(eq(1));

        assertFalse(mPhoneUT.isAllowedNetworkTypesLoadedFromDb());
        mPhoneUT.loadAllowedNetworksFromSubscriptionDatabase();
@@ -1593,6 +1619,7 @@ public class GsmCdmaPhoneTest extends TelephonyTest {
    public void testLoadAllowedNetworksFromSubscriptionDatabase_invalidKeys() {
        int subId = 1;
        doReturn(subId).when(mSubscriptionController).getSubId(anyInt());
        doReturn(subId).when(mSubscriptionManagerService).getSubId(anyInt());

        // 13 == TelephonyManager.NETWORK_TYPE_LTE
        // NR_BITMASK == 4096 == 1 << (13 - 1)
@@ -1600,6 +1627,11 @@ public class GsmCdmaPhoneTest extends TelephonyTest {
                "user=4096,power=4096,carrier=4096,enable_2g=4096,-1=4096";
        doReturn(validSerializedNetworkMap).when(mSubscriptionController).getSubscriptionProperty(
                anyInt(), eq(SubscriptionManager.ALLOWED_NETWORK_TYPES));
        SubscriptionInfoInternal si = new SubscriptionInfoInternal.Builder()
                .setId(1)
                .setAllowedNetworkTypesForReasons(validSerializedNetworkMap)
                .build();
        doReturn(si).when(mSubscriptionManagerService).getSubscriptionInfoInternal(eq(1));

        assertFalse(mPhoneUT.isAllowedNetworkTypesLoadedFromDb());
        mPhoneUT.loadAllowedNetworksFromSubscriptionDatabase();
@@ -1615,12 +1647,18 @@ public class GsmCdmaPhoneTest extends TelephonyTest {
    public void testLoadAllowedNetworksFromSubscriptionDatabase_invalidValues() {
        int subId = 1;
        doReturn(subId).when(mSubscriptionController).getSubId(anyInt());
        doReturn(subId).when(mSubscriptionManagerService).getSubId(anyInt());

        // 19 == TelephonyManager.NETWORK_TYPE_NR
        // NR_BITMASK == 524288 == 1 << 19
        String validSerializedNetworkMap = "user=4096,power=4096,carrier=4096,enable_2g=-1";
        doReturn(validSerializedNetworkMap).when(mSubscriptionController).getSubscriptionProperty(
                anyInt(), eq(SubscriptionManager.ALLOWED_NETWORK_TYPES));
        SubscriptionInfoInternal si = new SubscriptionInfoInternal.Builder()
                .setId(1)
                .setAllowedNetworkTypesForReasons(validSerializedNetworkMap)
                .build();
        doReturn(si).when(mSubscriptionManagerService).getSubscriptionInfoInternal(eq(1));

        mPhoneUT.loadAllowedNetworksFromSubscriptionDatabase();

@@ -1767,8 +1805,9 @@ public class GsmCdmaPhoneTest extends TelephonyTest {
    }


    private SubscriptionInfo makeSubscriptionInfo(boolean isOpportunistic, int usageSetting) {
        return new SubscriptionInfo.Builder()
    private SubscriptionInfoInternal makeSubscriptionInfoInternal(
            boolean isOpportunistic, int usageSetting) {
        return new SubscriptionInfoInternal.Builder()
                .setId(1)
                .setIccId("xxxxxxxxx")
                .setSimSlotIndex(1)
@@ -1779,8 +1818,8 @@ public class GsmCdmaPhoneTest extends TelephonyTest {
                .setMcc("001")
                .setMnc("01")
                .setCountryIso("us")
                .setEmbedded(true)
                .setOpportunistic(isOpportunistic)
                .setEmbedded(1)
                .setOpportunistic(isOpportunistic ? 1 : 0)
                .setCarrierId(1)
                .setProfileClass(SubscriptionManager.PROFILE_CLASS_PROVISIONING)
                .setUsageSetting(usageSetting)
@@ -1793,10 +1832,12 @@ public class GsmCdmaPhoneTest extends TelephonyTest {
        setupUsageSettingResources();
        mPhoneUT.mCi = mMockCi;

        final SubscriptionInfo si = makeSubscriptionInfo(
        final SubscriptionInfoInternal si = makeSubscriptionInfoInternal(
                false, SubscriptionManager.USAGE_SETTING_DATA_CENTRIC);

        doReturn(si).when(mSubscriptionController).getSubscriptionInfo(anyInt());
        doReturn(si.toSubscriptionInfo()).when(mSubscriptionController)
                .getSubscriptionInfo(anyInt());
        doReturn(si).when(mSubscriptionManagerService).getSubscriptionInfoInternal(anyInt());

        mPhoneUT.updateUsageSetting();
        processAllMessages();
@@ -1817,9 +1858,11 @@ public class GsmCdmaPhoneTest extends TelephonyTest {
        setupUsageSettingResources();
        mPhoneUT.mCi = mMockCi;

        final SubscriptionInfo si = makeSubscriptionInfo(
        final SubscriptionInfoInternal si = makeSubscriptionInfoInternal(
                true, SubscriptionManager.USAGE_SETTING_DEFAULT);
        doReturn(si).when(mSubscriptionController).getSubscriptionInfo(anyInt());
        doReturn(si.toSubscriptionInfo()).when(mSubscriptionController)
                .getSubscriptionInfo(anyInt());
        doReturn(si).when(mSubscriptionManagerService).getSubscriptionInfoInternal(anyInt());

        mPhoneUT.updateUsageSetting();
        processAllMessages();
@@ -1840,11 +1883,13 @@ public class GsmCdmaPhoneTest extends TelephonyTest {
        setupUsageSettingResources();
        mPhoneUT.mCi = mMockCi;

        final SubscriptionInfo si = makeSubscriptionInfo(
        final SubscriptionInfoInternal si = makeSubscriptionInfoInternal(
                false, SubscriptionManager.USAGE_SETTING_DEFAULT);

        assertNotNull(si);
        doReturn(si).when(mSubscriptionController).getSubscriptionInfo(anyInt());
        doReturn(si.toSubscriptionInfo()).when(mSubscriptionController)
                .getSubscriptionInfo(anyInt());
        doReturn(si).when(mSubscriptionManagerService).getSubscriptionInfoInternal(anyInt());

        mPhoneUT.updateUsageSetting();
        processAllMessages();
+7 −9
Original line number Diff line number Diff line
@@ -18,13 +18,6 @@ package com.android.internal.telephony;

import static com.android.internal.telephony.TelephonyTestUtils.waitForMs;

import android.os.AsyncResult;
import android.os.Message;
import android.testing.AndroidTestingRunner;
import android.testing.TestableLooper;

import androidx.test.filters.SmallTest;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.fail;
import static org.mockito.ArgumentMatchers.any;
@@ -34,6 +27,13 @@ import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;

import android.os.AsyncResult;
import android.os.Message;
import android.testing.AndroidTestingRunner;
import android.testing.TestableLooper;

import androidx.test.filters.SmallTest;

import com.android.internal.telephony.emergency.EmergencyNumberTracker;

import org.junit.After;
@@ -53,7 +53,6 @@ public class IccSmsInterfaceManagerTest extends TelephonyTest {

    // Mocked classes
    private SmsPermissions mMockSmsPermissions;
    protected GsmCdmaPhone mPhone2;  // mPhone as phone 1 is already defined in TelephonyTest.
    protected EmergencyNumberTracker mEmergencyNumberTracker2;
    protected IccSmsInterfaceManager.PhoneFactoryProxy mPhoneFactoryProxy;

@@ -67,7 +66,6 @@ public class IccSmsInterfaceManagerTest extends TelephonyTest {
        mPhoneFactoryProxy = mock(IccSmsInterfaceManager.PhoneFactoryProxy.class);
        mIccSmsInterfaceManager.setPhoneFactoryProxy(mPhoneFactoryProxy);

        mPhone2 = mock(GsmCdmaPhone.class);
        mEmergencyNumberTracker2 = mock(EmergencyNumberTracker.class);
        doReturn(mEmergencyNumberTracker2).when(mPhone2).getEmergencyNumberTracker();
    }
+256 −334

File changed.

Preview size limit exceeded, changes collapsed.

Loading