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

Commit 68e8018a authored by Qingqi Lei's avatar Qingqi Lei Committed by Automerger Merge Worker
Browse files

Merge "Combine two getVoiceRat methods and fix return value" into tm-qpr-dev am: 0ca2a000

parents 30d8176c 0ca2a000
Loading
Loading
Loading
Loading
+0 −1
Original line number Original line Diff line number Diff line
@@ -369,7 +369,6 @@ public class ImsStats {
     * TelephonyManager#NETWORK_TYPE_UNKNOWN} if there isn't any.
     * TelephonyManager#NETWORK_TYPE_UNKNOWN} if there isn't any.
     */
     */
    @NetworkType
    @NetworkType
    @VisibleForTesting
    public synchronized int getImsVoiceRadioTech() {
    public synchronized int getImsVoiceRadioTech() {
        if (mLastRegistrationStats == null
        if (mLastRegistrationStats == null
                || !mLastAvailableFeatures.isCapable(CAPABILITY_TYPE_VOICE)) {
                || !mLastAvailableFeatures.isCapable(CAPABILITY_TYPE_VOICE)) {
+17 −23
Original line number Original line Diff line number Diff line
@@ -16,8 +16,6 @@


package com.android.internal.telephony.metrics;
package com.android.internal.telephony.metrics;


import static com.android.internal.telephony.TelephonyStatsLog.VOICE_CALL_SESSION__BEARER_AT_END__CALL_BEARER_CS;

import android.annotation.Nullable;
import android.annotation.Nullable;
import android.os.SystemClock;
import android.os.SystemClock;
import android.telephony.AccessNetworkConstants;
import android.telephony.AccessNetworkConstants;
@@ -27,6 +25,10 @@ import android.telephony.NetworkRegistrationInfo;
import android.telephony.ServiceState;
import android.telephony.ServiceState;
import android.telephony.TelephonyManager;
import android.telephony.TelephonyManager;


import static com.android.internal.telephony.TelephonyStatsLog.VOICE_CALL_SESSION__BEARER_AT_END__CALL_BEARER_CS;
import static com.android.internal.telephony.TelephonyStatsLog.VOICE_CALL_SESSION__BEARER_AT_END__CALL_BEARER_IMS;
import static com.android.internal.telephony.TelephonyStatsLog.VOICE_CALL_SESSION__BEARER_AT_END__CALL_BEARER_UNKNOWN;

import com.android.internal.annotations.VisibleForTesting;
import com.android.internal.annotations.VisibleForTesting;
import com.android.internal.telephony.Phone;
import com.android.internal.telephony.Phone;
import com.android.internal.telephony.PhoneFactory;
import com.android.internal.telephony.PhoneFactory;
@@ -244,22 +246,7 @@ public class ServiceStateStats {
     * despite that the device may have emergency service over a certain RAT.
     * despite that the device may have emergency service over a certain RAT.
     */
     */
    static @NetworkType int getVoiceRat(Phone phone, @Nullable ServiceState state) {
    static @NetworkType int getVoiceRat(Phone phone, @Nullable ServiceState state) {
        if (state == null) {
        return getVoiceRat(phone, state, VOICE_CALL_SESSION__BEARER_AT_END__CALL_BEARER_UNKNOWN);
            return TelephonyManager.NETWORK_TYPE_UNKNOWN;
        }
        ImsPhone imsPhone = (ImsPhone) phone.getImsPhone();
        if (imsPhone != null) {
            @NetworkType int imsVoiceRat = imsPhone.getImsStats().getImsVoiceRadioTech();
            if (imsVoiceRat != TelephonyManager.NETWORK_TYPE_UNKNOWN) {
                // If IMS is over WWAN but WWAN PS is not in-service, then IMS RAT is invalid
                boolean isImsVoiceRatValid =
                        (imsVoiceRat == TelephonyManager.NETWORK_TYPE_IWLAN
                                || getRat(state, NetworkRegistrationInfo.DOMAIN_PS)
                                        != TelephonyManager.NETWORK_TYPE_UNKNOWN);
                return isImsVoiceRatValid ? imsVoiceRat : TelephonyManager.NETWORK_TYPE_UNKNOWN;
            }
        }
        return getRat(state, NetworkRegistrationInfo.DOMAIN_CS);
    }
    }


    /**
    /**
@@ -268,6 +255,7 @@ public class ServiceStateStats {
     * <p>If the device is not in service, {@code TelephonyManager.NETWORK_TYPE_UNKNOWN} is returned
     * <p>If the device is not in service, {@code TelephonyManager.NETWORK_TYPE_UNKNOWN} is returned
     * despite that the device may have emergency service over a certain RAT.
     * despite that the device may have emergency service over a certain RAT.
     */
     */
    @VisibleForTesting public
    static @NetworkType int getVoiceRat(Phone phone, @Nullable ServiceState state, int bearer) {
    static @NetworkType int getVoiceRat(Phone phone, @Nullable ServiceState state, int bearer) {
        if (state == null) {
        if (state == null) {
            return TelephonyManager.NETWORK_TYPE_UNKNOWN;
            return TelephonyManager.NETWORK_TYPE_UNKNOWN;
@@ -276,16 +264,23 @@ public class ServiceStateStats {
        if (bearer != VOICE_CALL_SESSION__BEARER_AT_END__CALL_BEARER_CS && imsPhone != null) {
        if (bearer != VOICE_CALL_SESSION__BEARER_AT_END__CALL_BEARER_CS && imsPhone != null) {
            @NetworkType int imsVoiceRat = imsPhone.getImsStats().getImsVoiceRadioTech();
            @NetworkType int imsVoiceRat = imsPhone.getImsStats().getImsVoiceRadioTech();
            if (imsVoiceRat != TelephonyManager.NETWORK_TYPE_UNKNOWN) {
            if (imsVoiceRat != TelephonyManager.NETWORK_TYPE_UNKNOWN) {
                // If IMS is over WWAN but WWAN PS is not in-service, then IMS RAT is invalid
                // If IMS is registered over WWAN but WWAN PS is not in service,
                // fallback to WWAN CS RAT
                boolean isImsVoiceRatValid =
                boolean isImsVoiceRatValid =
                        (imsVoiceRat == TelephonyManager.NETWORK_TYPE_IWLAN
                        (imsVoiceRat == TelephonyManager.NETWORK_TYPE_IWLAN
                                || getRat(state, NetworkRegistrationInfo.DOMAIN_PS)
                                || getRat(state, NetworkRegistrationInfo.DOMAIN_PS)
                                        != TelephonyManager.NETWORK_TYPE_UNKNOWN);
                                        != TelephonyManager.NETWORK_TYPE_UNKNOWN);
                return isImsVoiceRatValid ? imsVoiceRat : TelephonyManager.NETWORK_TYPE_UNKNOWN;
                if (isImsVoiceRatValid) {
                    return imsVoiceRat;
                }
            }
            }
        }
        }
        if (bearer == VOICE_CALL_SESSION__BEARER_AT_END__CALL_BEARER_IMS) {
            return TelephonyManager.NETWORK_TYPE_UNKNOWN;
        } else {
            return getRat(state, NetworkRegistrationInfo.DOMAIN_CS);
            return getRat(state, NetworkRegistrationInfo.DOMAIN_CS);
        }
        }
    }


    /** Returns RAT used by WWAN if WWAN is in service. */
    /** Returns RAT used by WWAN if WWAN is in service. */
    public static @NetworkType int getRat(
    public static @NetworkType int getRat(
@@ -307,8 +302,7 @@ public class ServiceStateStats {
    }
    }


    private static boolean isEndc(ServiceState state) {
    private static boolean isEndc(ServiceState state) {
        if (getRat(state, NetworkRegistrationInfo.DOMAIN_PS)
        if (getRat(state, NetworkRegistrationInfo.DOMAIN_PS) != TelephonyManager.NETWORK_TYPE_LTE) {
                != TelephonyManager.NETWORK_TYPE_LTE) {
            return false;
            return false;
        }
        }
        int nrState = state.getNrState();
        int nrState = state.getNrState();
+30 −0
Original line number Original line Diff line number Diff line
@@ -35,6 +35,10 @@ import android.telephony.ServiceState;
import android.telephony.TelephonyManager;
import android.telephony.TelephonyManager;
import android.test.suitebuilder.annotation.SmallTest;
import android.test.suitebuilder.annotation.SmallTest;


import static com.android.internal.telephony.TelephonyStatsLog.VOICE_CALL_SESSION__BEARER_AT_END__CALL_BEARER_CS;
import static com.android.internal.telephony.TelephonyStatsLog.VOICE_CALL_SESSION__BEARER_AT_END__CALL_BEARER_IMS;
import static com.android.internal.telephony.TelephonyStatsLog.VOICE_CALL_SESSION__BEARER_AT_END__CALL_BEARER_UNKNOWN;

import com.android.internal.telephony.Phone;
import com.android.internal.telephony.Phone;
import com.android.internal.telephony.TelephonyTest;
import com.android.internal.telephony.TelephonyTest;
import com.android.internal.telephony.nano.PersistAtomsProto.CellularDataServiceSwitch;
import com.android.internal.telephony.nano.PersistAtomsProto.CellularDataServiceSwitch;
@@ -149,6 +153,7 @@ public class ServiceStateStatsTest extends TelephonyTest {
        doReturn(ServiceState.STATE_OUT_OF_SERVICE).when(mServiceState).getDataRegState();
        doReturn(ServiceState.STATE_OUT_OF_SERVICE).when(mServiceState).getDataRegState();
        doReturn(TelephonyManager.NETWORK_TYPE_UNKNOWN).when(mServiceState).getVoiceNetworkType();
        doReturn(TelephonyManager.NETWORK_TYPE_UNKNOWN).when(mServiceState).getVoiceNetworkType();
        doReturn(TelephonyManager.NETWORK_TYPE_UNKNOWN).when(mServiceState).getDataNetworkType();
        doReturn(TelephonyManager.NETWORK_TYPE_UNKNOWN).when(mServiceState).getDataNetworkType();
        mockWwanCsRat(TelephonyManager.NETWORK_TYPE_UNKNOWN);
        mockWwanPsRat(TelephonyManager.NETWORK_TYPE_UNKNOWN);
        mockWwanPsRat(TelephonyManager.NETWORK_TYPE_UNKNOWN);
        mServiceStateStats.onServiceStateChanged(mServiceState);
        mServiceStateStats.onServiceStateChanged(mServiceState);


@@ -248,6 +253,7 @@ public class ServiceStateStatsTest extends TelephonyTest {
        doReturn(ServiceState.STATE_OUT_OF_SERVICE).when(mServiceState).getDataRegState();
        doReturn(ServiceState.STATE_OUT_OF_SERVICE).when(mServiceState).getDataRegState();
        doReturn(TelephonyManager.NETWORK_TYPE_UNKNOWN).when(mServiceState).getVoiceNetworkType();
        doReturn(TelephonyManager.NETWORK_TYPE_UNKNOWN).when(mServiceState).getVoiceNetworkType();
        doReturn(TelephonyManager.NETWORK_TYPE_UNKNOWN).when(mServiceState).getDataNetworkType();
        doReturn(TelephonyManager.NETWORK_TYPE_UNKNOWN).when(mServiceState).getDataNetworkType();
        mockWwanCsRat(TelephonyManager.NETWORK_TYPE_UNKNOWN);
        mockWwanPsRat(TelephonyManager.NETWORK_TYPE_UNKNOWN);
        mockWwanPsRat(TelephonyManager.NETWORK_TYPE_UNKNOWN);
        doReturn(-1).when(mPhone).getCarrierId();
        doReturn(-1).when(mPhone).getCarrierId();
        mServiceStateStats.onServiceStateChanged(mServiceState);
        mServiceStateStats.onServiceStateChanged(mServiceState);
@@ -395,6 +401,7 @@ public class ServiceStateStatsTest extends TelephonyTest {
    @SmallTest
    @SmallTest
    public void onServiceStateChanged_differentDataRats() throws Exception {
    public void onServiceStateChanged_differentDataRats() throws Exception {
        doReturn(TelephonyManager.NETWORK_TYPE_UNKNOWN).when(mServiceState).getDataNetworkType();
        doReturn(TelephonyManager.NETWORK_TYPE_UNKNOWN).when(mServiceState).getDataNetworkType();
        mockWwanCsRat(TelephonyManager.NETWORK_TYPE_UNKNOWN);
        mockWwanPsRat(TelephonyManager.NETWORK_TYPE_UNKNOWN);
        mockWwanPsRat(TelephonyManager.NETWORK_TYPE_UNKNOWN);


        mServiceStateStats.onServiceStateChanged(mServiceState);
        mServiceStateStats.onServiceStateChanged(mServiceState);
@@ -881,6 +888,29 @@ public class ServiceStateStatsTest extends TelephonyTest {
        verifyNoMoreInteractions(mPersistAtomsStorage);
        verifyNoMoreInteractions(mPersistAtomsStorage);
    }
    }


    @Test
    @SmallTest
    public void getVoiceRat_bearer() throws Exception {
        mockWwanPsRat(TelephonyManager.NETWORK_TYPE_LTE);
        mockWwanCsRat(TelephonyManager.NETWORK_TYPE_LTE);
        doReturn(TelephonyManager.NETWORK_TYPE_UNKNOWN).when(mImsStats).getImsVoiceRadioTech();
        assertEquals(TelephonyManager.NETWORK_TYPE_UNKNOWN, mServiceStateStats.getVoiceRat(
                mPhone, mServiceState, VOICE_CALL_SESSION__BEARER_AT_END__CALL_BEARER_IMS));
        assertEquals(TelephonyManager.NETWORK_TYPE_LTE, mServiceStateStats.getVoiceRat(
                mPhone, mServiceState, VOICE_CALL_SESSION__BEARER_AT_END__CALL_BEARER_CS));
        assertEquals(TelephonyManager.NETWORK_TYPE_LTE, mServiceStateStats.getVoiceRat(
                mPhone, mServiceState, VOICE_CALL_SESSION__BEARER_AT_END__CALL_BEARER_UNKNOWN));
        mockWwanPsRat(TelephonyManager.NETWORK_TYPE_UMTS);
        mockWwanCsRat(TelephonyManager.NETWORK_TYPE_UMTS);
        doReturn(TelephonyManager.NETWORK_TYPE_LTE).when(mImsStats).getImsVoiceRadioTech();
        assertEquals(TelephonyManager.NETWORK_TYPE_LTE, mServiceStateStats.getVoiceRat(
                mPhone, mServiceState, VOICE_CALL_SESSION__BEARER_AT_END__CALL_BEARER_IMS));
        assertEquals(TelephonyManager.NETWORK_TYPE_UMTS, mServiceStateStats.getVoiceRat(
                mPhone, mServiceState, VOICE_CALL_SESSION__BEARER_AT_END__CALL_BEARER_CS));
        assertEquals(TelephonyManager.NETWORK_TYPE_LTE, mServiceStateStats.getVoiceRat(
                mPhone, mServiceState, VOICE_CALL_SESSION__BEARER_AT_END__CALL_BEARER_UNKNOWN));
    }

    private void mockWwanPsRat(@NetworkType int rat) {
    private void mockWwanPsRat(@NetworkType int rat) {
        mockWwanRat(
        mockWwanRat(
                NetworkRegistrationInfo.DOMAIN_PS,
                NetworkRegistrationInfo.DOMAIN_PS,
+59 −0

File changed.

Preview size limit exceeded, changes collapsed.