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

Commit bb6a63c5 authored by Chi Zhang's avatar Chi Zhang
Browse files

DO NOT MERGE

Exclude limited service from RAT durations.

Bug: 124332646
Test: build, unit tests, manual test with voice call/SMS/MMS
Change-Id: Ibd7723a05260450c1a946c4bcc0ab4634c22e839
parent 159faa2b
Loading
Loading
Loading
Loading
+15 −3
Original line number Diff line number Diff line
@@ -238,10 +238,22 @@ public class ServiceStateStats {
        if (imsPhone != null) {
            @NetworkType int imsVoiceRat = imsPhone.getImsStats().getImsVoiceRadioTech();
            if (imsVoiceRat != TelephonyManager.NETWORK_TYPE_UNKNOWN) {
                return imsVoiceRat;
                // If IMS is over WWAN but WWAN PS is not in-service, then IMS RAT is invalid
                boolean isImsVoiceRatValid =
                        (imsVoiceRat == TelephonyManager.NETWORK_TYPE_IWLAN
                                || getDataRat(state) != TelephonyManager.NETWORK_TYPE_UNKNOWN);
                return isImsVoiceRatValid ? imsVoiceRat : TelephonyManager.NETWORK_TYPE_UNKNOWN;
            }
        }
        return state.getVoiceNetworkType();

        // If WWAN CS is not in-service, we should return NETWORK_TYPE_UNKNOWN
        final NetworkRegistrationInfo wwanRegInfo =
                state.getNetworkRegistrationInfo(
                        NetworkRegistrationInfo.DOMAIN_CS,
                        AccessNetworkConstants.TRANSPORT_TYPE_WWAN);
        return wwanRegInfo != null && wwanRegInfo.isInService()
                ? wwanRegInfo.getAccessNetworkTechnology()
                : TelephonyManager.NETWORK_TYPE_UNKNOWN;
    }

    /**
@@ -263,7 +275,7 @@ public class ServiceStateStats {
                state.getNetworkRegistrationInfo(
                        NetworkRegistrationInfo.DOMAIN_PS,
                        AccessNetworkConstants.TRANSPORT_TYPE_WWAN);
        return wwanRegInfo != null
        return wwanRegInfo != null && wwanRegInfo.isInService()
                ? wwanRegInfo.getAccessNetworkTechnology()
                : TelephonyManager.NETWORK_TYPE_UNKNOWN;
    }
+1 −0
Original line number Diff line number Diff line
@@ -123,6 +123,7 @@ public class ImsStatsTest extends TelephonyTest {
        // WWAN PS RAT is LTE
        doReturn(new NetworkRegistrationInfo.Builder()
                .setAccessNetworkTechnology(TelephonyManager.NETWORK_TYPE_LTE)
                .setRegistrationState(NetworkRegistrationInfo.REGISTRATION_STATE_HOME)
                .build())
                .when(mServiceState).getNetworkRegistrationInfo(DOMAIN_PS, TRANSPORT_TYPE_WWAN);

+101 −15
Original line number Diff line number Diff line
@@ -103,6 +103,7 @@ public class ServiceStateStatsTest extends TelephonyTest {
        doReturn(TelephonyManager.NETWORK_TYPE_LTE).when(mServiceState).getVoiceNetworkType();
        doReturn(TelephonyManager.NETWORK_TYPE_LTE).when(mServiceState).getDataNetworkType();
        mockWwanPsRat(TelephonyManager.NETWORK_TYPE_LTE);
        doReturn(TelephonyManager.NETWORK_TYPE_LTE).when(mImsStats).getImsVoiceRadioTech();

        mServiceStateStats = new TestableServiceStateStats(mPhone);
    }
@@ -313,7 +314,52 @@ public class ServiceStateStatsTest extends TelephonyTest {

    @Test
    @SmallTest
    public void update_sameRats() throws Exception {
    public void onImsVoiceRegistrationChanged_wifiCallingWhileOos() throws Exception {
        doReturn(TelephonyManager.NETWORK_TYPE_UNKNOWN).when(mServiceState).getVoiceNetworkType();
        doReturn(TelephonyManager.NETWORK_TYPE_UNKNOWN).when(mServiceState).getDataNetworkType();
        doReturn(TelephonyManager.NETWORK_TYPE_UNKNOWN).when(mImsStats).getImsVoiceRadioTech();
        mockWwanCsRat(TelephonyManager.NETWORK_TYPE_UNKNOWN);
        mockWwanPsRat(TelephonyManager.NETWORK_TYPE_UNKNOWN);
        mServiceStateStats.onServiceStateChanged(mServiceState);
        doReturn(TelephonyManager.NETWORK_TYPE_IWLAN).when(mImsStats).getImsVoiceRadioTech();

        mServiceStateStats.incTimeMillis(100L);
        mServiceStateStats.onImsVoiceRegistrationChanged();
        mServiceStateStats.incTimeMillis(200L);
        mServiceStateStats.conclude();

        // There should be 2 separate service state updates, which should be different objects
        ArgumentCaptor<CellularServiceState> captor =
                ArgumentCaptor.forClass(CellularServiceState.class);
        verify(mPersistAtomsStorage, times(2))
                .addCellularServiceStateAndCellularDataServiceSwitch(captor.capture(), eq(null));
        assertNotSame(captor.getAllValues().get(0), captor.getAllValues().get(1));
        CellularServiceState state = captor.getAllValues().get(0);
        assertEquals(TelephonyManager.NETWORK_TYPE_UNKNOWN, state.voiceRat);
        assertEquals(TelephonyManager.NETWORK_TYPE_UNKNOWN, state.dataRat);
        assertEquals(ServiceState.ROAMING_TYPE_NOT_ROAMING, state.voiceRoamingType);
        assertEquals(ServiceState.ROAMING_TYPE_NOT_ROAMING, state.dataRoamingType);
        assertFalse(state.isEndc);
        assertEquals(0, state.simSlotIndex);
        assertFalse(state.isMultiSim);
        assertEquals(CARRIER1_ID, state.carrierId);
        assertEquals(100L, state.totalTimeMillis);
        state = captor.getAllValues().get(1);
        assertEquals(TelephonyManager.NETWORK_TYPE_IWLAN, state.voiceRat);
        assertEquals(TelephonyManager.NETWORK_TYPE_UNKNOWN, state.dataRat);
        assertEquals(ServiceState.ROAMING_TYPE_NOT_ROAMING, state.voiceRoamingType);
        assertEquals(ServiceState.ROAMING_TYPE_NOT_ROAMING, state.dataRoamingType);
        assertFalse(state.isEndc);
        assertEquals(0, state.simSlotIndex);
        assertFalse(state.isMultiSim);
        assertEquals(CARRIER1_ID, state.carrierId);
        assertEquals(200L, state.totalTimeMillis);
        verifyNoMoreInteractions(mPersistAtomsStorage);
    }

    @Test
    @SmallTest
    public void onServiceStateChanged_sameRats() throws Exception {
        // Using default service state for LTE

        mServiceStateStats.onServiceStateChanged(mServiceState);
@@ -340,7 +386,7 @@ public class ServiceStateStatsTest extends TelephonyTest {

    @Test
    @SmallTest
    public void update_differentDataRats() throws Exception {
    public void onServiceStateChanged_differentDataRats() throws Exception {
        doReturn(TelephonyManager.NETWORK_TYPE_UNKNOWN).when(mServiceState).getDataNetworkType();
        mockWwanPsRat(TelephonyManager.NETWORK_TYPE_UNKNOWN);

@@ -361,7 +407,7 @@ public class ServiceStateStatsTest extends TelephonyTest {
                .addCellularServiceStateAndCellularDataServiceSwitch(
                        serviceStateCaptor.capture(), serviceSwitchCaptor.capture());
        CellularServiceState state = serviceStateCaptor.getAllValues().get(0);
        assertEquals(TelephonyManager.NETWORK_TYPE_LTE, state.voiceRat);
        assertEquals(TelephonyManager.NETWORK_TYPE_UNKNOWN, state.voiceRat);
        assertEquals(TelephonyManager.NETWORK_TYPE_UNKNOWN, state.dataRat);
        assertEquals(ServiceState.ROAMING_TYPE_NOT_ROAMING, state.voiceRoamingType);
        assertEquals(ServiceState.ROAMING_TYPE_NOT_ROAMING, state.dataRoamingType);
@@ -393,7 +439,7 @@ public class ServiceStateStatsTest extends TelephonyTest {

    @Test
    @SmallTest
    public void update_differentVoiceRats() throws Exception {
    public void onServiceStateChanged_differentVoiceRats() throws Exception {
        // Using default service state for LTE

        mServiceStateStats.onServiceStateChanged(mServiceState);
@@ -435,7 +481,7 @@ public class ServiceStateStatsTest extends TelephonyTest {

    @Test
    @SmallTest
    public void update_iwlanButNotWifiCalling() throws Exception {
    public void onServiceStateChanged_iwlanButNotWifiCalling() throws Exception {
        // Using default service state for LTE as WWAN PS RAT
        doReturn(TelephonyManager.NETWORK_TYPE_IWLAN).when(mServiceState).getDataNetworkType();

@@ -462,7 +508,7 @@ public class ServiceStateStatsTest extends TelephonyTest {

    @Test
    @SmallTest
    public void update_endc() throws Exception {
    public void onServiceStateChanged_endc() throws Exception {
        // Using default service state for LTE without ENDC

        mServiceStateStats.onServiceStateChanged(mServiceState);
@@ -531,7 +577,7 @@ public class ServiceStateStatsTest extends TelephonyTest {

    @Test
    @SmallTest
    public void update_simSwapSameRat() throws Exception {
    public void onServiceStateChanged_simSwapSameRat() throws Exception {
        // Using default service state for LTE

        mServiceStateStats.onServiceStateChanged(mServiceState);
@@ -541,6 +587,17 @@ public class ServiceStateStatsTest extends TelephonyTest {
        doReturn(TelephonyManager.NETWORK_TYPE_UMTS).when(mServiceState).getVoiceNetworkType();
        doReturn(TelephonyManager.NETWORK_TYPE_UNKNOWN).when(mServiceState).getDataNetworkType();
        mockWwanPsRat(TelephonyManager.NETWORK_TYPE_UNKNOWN);
        doReturn(
                        new NetworkRegistrationInfo.Builder()
                                .setAccessNetworkTechnology(TelephonyManager.NETWORK_TYPE_UMTS)
                                .setRegistrationState(
                                        NetworkRegistrationInfo.REGISTRATION_STATE_DENIED)
                                .setEmergencyOnly(true)
                                .build())
                .when(mServiceState)
                .getNetworkRegistrationInfo(
                        NetworkRegistrationInfo.DOMAIN_CS,
                        AccessNetworkConstants.TRANSPORT_TYPE_WWAN);
        doReturn(-1).when(mPhone).getCarrierId();
        mServiceStateStats.onServiceStateChanged(mServiceState);
        mServiceStateStats.incTimeMillis(5000L);
@@ -549,6 +606,8 @@ public class ServiceStateStatsTest extends TelephonyTest {
        doReturn(TelephonyManager.NETWORK_TYPE_LTE).when(mServiceState).getVoiceNetworkType();
        doReturn(TelephonyManager.NETWORK_TYPE_LTE).when(mServiceState).getDataNetworkType();
        mockWwanPsRat(TelephonyManager.NETWORK_TYPE_LTE);
        mockWwanCsRat(TelephonyManager.NETWORK_TYPE_LTE);
        doReturn(TelephonyManager.NETWORK_TYPE_LTE).when(mImsStats).getImsVoiceRadioTech();
        doReturn(CARRIER2_ID).when(mPhone).getCarrierId();
        mServiceStateStats.onServiceStateChanged(mServiceState);
        mServiceStateStats.incTimeMillis(200L);
@@ -570,7 +629,7 @@ public class ServiceStateStatsTest extends TelephonyTest {
        assertEquals(CARRIER1_ID, state.carrierId);
        assertEquals(100L, state.totalTimeMillis);
        state = captor.getAllValues().get(1);
        assertEquals(TelephonyManager.NETWORK_TYPE_UMTS, state.voiceRat);
        assertEquals(TelephonyManager.NETWORK_TYPE_UNKNOWN, state.voiceRat);
        assertEquals(TelephonyManager.NETWORK_TYPE_UNKNOWN, state.dataRat);
        assertEquals(ServiceState.ROAMING_TYPE_NOT_ROAMING, state.voiceRoamingType);
        assertEquals(ServiceState.ROAMING_TYPE_NOT_ROAMING, state.dataRoamingType);
@@ -594,7 +653,7 @@ public class ServiceStateStatsTest extends TelephonyTest {

    @Test
    @SmallTest
    public void update_roaming() throws Exception {
    public void onServiceStateChanged_roaming() throws Exception {
        // Using default service state for LTE

        mServiceStateStats.onServiceStateChanged(mServiceState);
@@ -603,6 +662,8 @@ public class ServiceStateStatsTest extends TelephonyTest {
        doReturn(TelephonyManager.NETWORK_TYPE_UMTS).when(mServiceState).getVoiceNetworkType();
        doReturn(TelephonyManager.NETWORK_TYPE_UMTS).when(mServiceState).getDataNetworkType();
        mockWwanPsRat(TelephonyManager.NETWORK_TYPE_UMTS);
        mockWwanCsRat(TelephonyManager.NETWORK_TYPE_UMTS);
        doReturn(TelephonyManager.NETWORK_TYPE_UNKNOWN).when(mImsStats).getImsVoiceRadioTech();
        doReturn(ServiceState.ROAMING_TYPE_INTERNATIONAL).when(mServiceState).getVoiceRoamingType();
        mServiceStateStats.onServiceStateChanged(mServiceState);
        mServiceStateStats.incTimeMillis(200L);
@@ -664,7 +725,7 @@ public class ServiceStateStatsTest extends TelephonyTest {

    @Test
    @SmallTest
    public void update_dualSim() throws Exception {
    public void onServiceStateChanged_dualSim() throws Exception {
        // Using default service state for LTE
        // Only difference between the 2 slots is slot index
        mockDualSim(CARRIER1_ID);
@@ -677,7 +738,9 @@ public class ServiceStateStatsTest extends TelephonyTest {
        mSecondServiceStateStats.incTimeMillis(100L);
        doReturn(TelephonyManager.NETWORK_TYPE_UMTS).when(mServiceState).getVoiceNetworkType();
        doReturn(TelephonyManager.NETWORK_TYPE_UMTS).when(mServiceState).getDataNetworkType();
        doReturn(TelephonyManager.NETWORK_TYPE_UNKNOWN).when(mImsStats).getImsVoiceRadioTech();
        mockWwanPsRat(TelephonyManager.NETWORK_TYPE_UMTS);
        mockWwanCsRat(TelephonyManager.NETWORK_TYPE_UMTS);
        mServiceStateStats.onServiceStateChanged(mServiceState);
        mServiceStateStats.incTimeMillis(200L);
        mSecondServiceStateStats.onServiceStateChanged(mServiceState);
@@ -754,7 +817,7 @@ public class ServiceStateStatsTest extends TelephonyTest {

    @Test
    @SmallTest
    public void update_airplaneMode() throws Exception {
    public void onServiceStateChanged_airplaneMode() throws Exception {
        // Using default service state for LTE

        mServiceStateStats.onServiceStateChanged(mServiceState);
@@ -806,11 +869,34 @@ public class ServiceStateStatsTest extends TelephonyTest {
    }

    private void mockWwanPsRat(@NetworkType int rat) {
        doReturn(new NetworkRegistrationInfo.Builder().setAccessNetworkTechnology(rat).build())
                .when(mServiceState)
                .getNetworkRegistrationInfo(
        mockWwanRat(
                NetworkRegistrationInfo.DOMAIN_PS,
                        AccessNetworkConstants.TRANSPORT_TYPE_WWAN);
                rat,
                rat == TelephonyManager.NETWORK_TYPE_UNKNOWN
                        ? NetworkRegistrationInfo.REGISTRATION_STATE_NOT_REGISTERED_OR_SEARCHING
                        : NetworkRegistrationInfo.REGISTRATION_STATE_HOME);
    }

    private void mockWwanCsRat(@NetworkType int rat) {
        mockWwanRat(
                NetworkRegistrationInfo.DOMAIN_CS,
                rat,
                rat == TelephonyManager.NETWORK_TYPE_UNKNOWN
                        ? NetworkRegistrationInfo.REGISTRATION_STATE_NOT_REGISTERED_OR_SEARCHING
                        : NetworkRegistrationInfo.REGISTRATION_STATE_HOME);
    }

    private void mockWwanRat(
            @NetworkRegistrationInfo.Domain int domain,
            @NetworkType int rat,
            @NetworkRegistrationInfo.RegistrationState int regState) {
        doReturn(
                        new NetworkRegistrationInfo.Builder()
                                .setAccessNetworkTechnology(rat)
                                .setRegistrationState(regState)
                                .build())
                .when(mServiceState)
                .getNetworkRegistrationInfo(domain, AccessNetworkConstants.TRANSPORT_TYPE_WWAN);
    }

    private void mockDualSim(int carrierId) {
+16 −2
Original line number Diff line number Diff line
@@ -2072,7 +2072,14 @@ public class VoiceCallSessionStatsTest extends TelephonyTest {
        doReturn(rat).when(mock).getVoiceNetworkType();
        doReturn(rat).when(mock).getDataNetworkType();
        NetworkRegistrationInfo regInfo =
                new NetworkRegistrationInfo.Builder().setAccessNetworkTechnology(rat).build();
                new NetworkRegistrationInfo.Builder()
                        .setAccessNetworkTechnology(rat)
                        .setRegistrationState(
                                rat == TelephonyManager.NETWORK_TYPE_UNKNOWN
                                        ? NetworkRegistrationInfo
                                                .REGISTRATION_STATE_NOT_REGISTERED_OR_SEARCHING
                                        : NetworkRegistrationInfo.REGISTRATION_STATE_HOME)
                        .build();
        doReturn(regInfo).when(mock)
                .getNetworkRegistrationInfo(
                        anyInt(), eq(AccessNetworkConstants.TRANSPORT_TYPE_WWAN));
@@ -2082,7 +2089,14 @@ public class VoiceCallSessionStatsTest extends TelephonyTest {
        doReturn(rat).when(mock).getVoiceNetworkType();
        doReturn(TelephonyManager.NETWORK_TYPE_IWLAN).when(mock).getDataNetworkType();
        NetworkRegistrationInfo wwanRegInfo =
                new NetworkRegistrationInfo.Builder().setAccessNetworkTechnology(rat).build();
                new NetworkRegistrationInfo.Builder()
                        .setAccessNetworkTechnology(rat)
                        .setRegistrationState(
                                rat == TelephonyManager.NETWORK_TYPE_UNKNOWN
                                        ? NetworkRegistrationInfo
                                                .REGISTRATION_STATE_NOT_REGISTERED_OR_SEARCHING
                                        : NetworkRegistrationInfo.REGISTRATION_STATE_HOME)
                        .build();
        doReturn(wwanRegInfo).when(mock)
                .getNetworkRegistrationInfo(
                        anyInt(), eq(AccessNetworkConstants.TRANSPORT_TYPE_WWAN));