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

Commit c2c8f45c authored by Jack Yu's avatar Jack Yu
Browse files

Migrated unit test to the new subscription manager

Bug: 268654362
Test: atest FrameworksTelephonyTests
Merged-In: I355103117c0ad00bb6c6192c3f4c6585fbaf10a8
Change-Id: I355103117c0ad00bb6c6192c3f4c6585fbaf10a8
parent 4d167cc5
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -839,6 +839,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
+40 −13
Original line number Diff line number Diff line
@@ -65,7 +65,6 @@ import android.telephony.CellIdentityGsm;
import android.telephony.LinkCapacityEstimate;
import android.telephony.NetworkRegistrationInfo;
import android.telephony.ServiceState;
import android.telephony.SubscriptionInfo;
import android.telephony.SubscriptionManager;
import android.telephony.TelephonyManager;
import android.test.suitebuilder.annotation.SmallTest;
@@ -75,6 +74,7 @@ import android.testing.TestableLooper;
import androidx.test.filters.FlakyTest;

import com.android.internal.telephony.imsphone.ImsPhone;
import com.android.internal.telephony.subscription.SubscriptionInfoInternal;
import com.android.internal.telephony.test.SimulatedCommands;
import com.android.internal.telephony.test.SimulatedCommandsVerifier;
import com.android.internal.telephony.uicc.AdnRecord;
@@ -1057,12 +1057,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
@@ -1085,6 +1088,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
@@ -1094,6 +1098,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
@@ -1253,6 +1258,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
@@ -1261,7 +1268,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());
    }

@@ -1432,6 +1444,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));
@@ -1501,9 +1515,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();

@@ -1515,10 +1532,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();

@@ -1656,8 +1676,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)
@@ -1668,8 +1689,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)
@@ -1682,10 +1703,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();
@@ -1706,9 +1729,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();
@@ -1729,11 +1754,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 −7
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;
@@ -33,6 +26,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 org.junit.After;
import org.junit.Before;
import org.junit.Test;
+255 −333

File changed.

Preview size limit exceeded, changes collapsed.

+37 −10
Original line number Diff line number Diff line
@@ -199,9 +199,17 @@ public class PhoneConfigurationManagerTest extends TelephonyTest {

        // Verify clearSubInfoRecord() and onSlotActiveStatusChange() are called for second phone,
        // and not for the first one
        if (isSubscriptionManagerServiceEnabled()) {
            verify(mSubscriptionManagerService).markSubscriptionsInactive(1);
        } else {
            verify(mSubscriptionController).clearSubInfoRecord(1);
        }
        verify(mMockCi1).onSlotActiveStatusChange(anyBoolean());
        if (isSubscriptionManagerServiceEnabled()) {
            verify(mSubscriptionManagerService, never()).markSubscriptionsInactive(0);
        } else {
            verify(mSubscriptionController, never()).clearSubInfoRecord(0);
        }
        verify(mMockCi0, never()).onSlotActiveStatusChange(anyBoolean());

        // Verify onPhoneRemoved() gets called on MultiSimSettingController phone
@@ -229,28 +237,47 @@ public class PhoneConfigurationManagerTest extends TelephonyTest {
            ex.)    object.set( 2 )   --> next call to object.get() will return 2
         */

        // setup mocks for  VOICE mSubscriptionController. getter/setter
        // setup mocks for  VOICE mSubscriptionManagerService. getter/setter
        doAnswer(invocation -> {
            Integer value = (Integer) invocation.getArguments()[0];
            Mockito.when(mSubscriptionController.getDefaultVoiceSubId()).thenReturn(value);
            return null;
        }).when(mSubscriptionController).setDefaultVoiceSubId(anyInt());

        doAnswer(invocation -> {
            Integer value = (Integer) invocation.getArguments()[0];
            Mockito.when(mSubscriptionManagerService.getDefaultVoiceSubId()).thenReturn(value);
            return null;
        }).when(mSubscriptionManagerService).setDefaultVoiceSubId(anyInt());


        // start off the phone stat with 1 active sim. reset values for new test.
        init(1);

        if (isSubscriptionManagerServiceEnabled()) {
            mSubscriptionManagerService.setDefaultVoiceSubId(startingDefaultSubscriptionId);
            assertEquals(startingDefaultSubscriptionId,
                    mSubscriptionManagerService.getDefaultVoiceSubId());
        } else {
            mSubscriptionController.setDefaultVoiceSubId(startingDefaultSubscriptionId);

        // assert the mSubscriptionController registers the change
        assertEquals(startingDefaultSubscriptionId, mSubscriptionController.getDefaultVoiceSubId());
            assertEquals(startingDefaultSubscriptionId,
                    mSubscriptionController.getDefaultVoiceSubId());
        }

        // Perform the switch to DSDS mode and ensure all existing checks are not altered
        testSwitchFromSingleToDualSimModeNoReboot();

        // VOICE check
        if (isSubscriptionManagerServiceEnabled()) {
            assertEquals(SubscriptionManager.INVALID_SUBSCRIPTION_ID /* No CALL Preference value */,
                mSubscriptionController.getDefaultVoiceSubId()); //  Now, when the user goes to
        // place a CALL, they will be prompted on which sim to use.
                    mSubscriptionManagerService.getDefaultVoiceSubId());
            // Now, when the user goes to place a CALL, they will be prompted on which sim to use.
        } else {
            assertEquals(SubscriptionManager.INVALID_SUBSCRIPTION_ID /* No CALL Preference value */,
                    mSubscriptionController.getDefaultVoiceSubId());
            // Now, when the user goes to place a CALL, they will be prompted on which sim to use.
        }

    }

    /**
Loading