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

Commit 0ca2a000 authored by Qingqi Lei's avatar Qingqi Lei Committed by Android (Google) Code Review
Browse files

Merge "Combine two getVoiceRat methods and fix return value" into tm-qpr-dev

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

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.os.SystemClock;
import android.telephony.AccessNetworkConstants;
@@ -27,6 +25,10 @@ import android.telephony.NetworkRegistrationInfo;
import android.telephony.ServiceState;
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.telephony.Phone;
import com.android.internal.telephony.PhoneFactory;
@@ -241,22 +243,7 @@ public class ServiceStateStats {
     * despite that the device may have emergency service over a certain RAT.
     */
    static @NetworkType int getVoiceRat(Phone phone, @Nullable ServiceState state) {
        if (state == null) {
            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);
        return getVoiceRat(phone, state, VOICE_CALL_SESSION__BEARER_AT_END__CALL_BEARER_UNKNOWN);
    }

    /**
@@ -265,6 +252,7 @@ public class ServiceStateStats {
     * <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.
     */
    @VisibleForTesting public
    static @NetworkType int getVoiceRat(Phone phone, @Nullable ServiceState state, int bearer) {
        if (state == null) {
            return TelephonyManager.NETWORK_TYPE_UNKNOWN;
@@ -273,16 +261,23 @@ public class ServiceStateStats {
        if (bearer != VOICE_CALL_SESSION__BEARER_AT_END__CALL_BEARER_CS && 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
                // If IMS is registered over WWAN but WWAN PS is not in service,
                // fallback to WWAN CS RAT
                boolean isImsVoiceRatValid =
                        (imsVoiceRat == TelephonyManager.NETWORK_TYPE_IWLAN
                                || getRat(state, NetworkRegistrationInfo.DOMAIN_PS)
                                        != 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);
        }
    }

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

    private static boolean isEndc(ServiceState state) {
        if (getRat(state, NetworkRegistrationInfo.DOMAIN_PS)
                != TelephonyManager.NETWORK_TYPE_LTE) {
        if (getRat(state, NetworkRegistrationInfo.DOMAIN_PS) != TelephonyManager.NETWORK_TYPE_LTE) {
            return false;
        }
        int nrState = state.getNrState();
+30 −0
Original line number Diff line number Diff line
@@ -35,6 +35,10 @@ import android.telephony.ServiceState;
import android.telephony.TelephonyManager;
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.TelephonyTest;
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(TelephonyManager.NETWORK_TYPE_UNKNOWN).when(mServiceState).getVoiceNetworkType();
        doReturn(TelephonyManager.NETWORK_TYPE_UNKNOWN).when(mServiceState).getDataNetworkType();
        mockWwanCsRat(TelephonyManager.NETWORK_TYPE_UNKNOWN);
        mockWwanPsRat(TelephonyManager.NETWORK_TYPE_UNKNOWN);
        mServiceStateStats.onServiceStateChanged(mServiceState);

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

        mServiceStateStats.onServiceStateChanged(mServiceState);
@@ -881,6 +888,29 @@ public class ServiceStateStatsTest extends TelephonyTest {
        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) {
        mockWwanRat(
                NetworkRegistrationInfo.DOMAIN_PS,
+59 −0

File changed.

Preview size limit exceeded, changes collapsed.