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

Commit 46ac1d63 authored by Brad Ebinger's avatar Brad Ebinger
Browse files

Use TelephonyManager.NETWORK_TYPE_* for IMS APIs

IMS APIs were using ServiceState, which is @hide. Instead we
will use TelephonyManager.NETWORK_TYPE_* constants, which are
visible.

Bug: 147726372
Test: atest FrameworksTelephonyTests
Change-Id: Id94f6150e4df57e51d170e3771b9fff3d2a994c7
parent 6d4431b0
Loading
Loading
Loading
Loading
+2 −1
Original line number Original line Diff line number Diff line
@@ -26,6 +26,7 @@ import android.os.Bundle;
import android.telephony.AccessNetworkConstants;
import android.telephony.AccessNetworkConstants;
import com.android.telephony.Rlog;
import com.android.telephony.Rlog;
import android.telephony.ServiceState;
import android.telephony.ServiceState;
import android.telephony.TelephonyManager;
import android.telephony.ims.ImsCallProfile;
import android.telephony.ims.ImsCallProfile;
import android.telephony.ims.ImsConferenceState;
import android.telephony.ims.ImsConferenceState;
import android.telephony.ims.ImsExternalCallState;
import android.telephony.ims.ImsExternalCallState;
@@ -260,7 +261,7 @@ public class TelephonyTester {
        }
        }


        imsCall.getImsCallSessionListenerProxy().callSessionHandoverFailed(imsCall.getCallSession(),
        imsCall.getImsCallSessionListenerProxy().callSessionHandoverFailed(imsCall.getCallSession(),
                ServiceState.RIL_RADIO_TECHNOLOGY_LTE, ServiceState.RIL_RADIO_TECHNOLOGY_IWLAN,
                TelephonyManager.NETWORK_TYPE_LTE, TelephonyManager.NETWORK_TYPE_IWLAN,
                new ImsReasonInfo());
                new ImsReasonInfo());
    }
    }


+1 −2
Original line number Original line Diff line number Diff line
@@ -3158,8 +3158,7 @@ public class ImsPhoneCallTracker extends CallTracker implements ImsPullCall {
        @Override
        @Override
        public void onCallQualityChanged(ImsCall imsCall, CallQuality callQuality) {
        public void onCallQualityChanged(ImsCall imsCall, CallQuality callQuality) {
            // convert ServiceState.radioTech to TelephonyManager.NetworkType constant
            // convert ServiceState.radioTech to TelephonyManager.NetworkType constant
            mPhone.onCallQualityChanged(callQuality,
            mPhone.onCallQualityChanged(callQuality, imsCall.getNetworkType());
                    ServiceState.rilRadioTechnologyToNetworkType(imsCall.getRadioTechnology()));
            String callId = imsCall.getSession().getCallId();
            String callId = imsCall.getSession().getCallId();
            CallQualityMetrics cqm = mCallQualityMetrics.get(callId);
            CallQualityMetrics cqm = mCallQualityMetrics.get(callId);
            if (cqm == null) {
            if (cqm == null) {
+8 −6
Original line number Original line Diff line number Diff line
@@ -35,6 +35,7 @@ import android.telephony.DisconnectCause;
import android.telephony.PhoneNumberUtils;
import android.telephony.PhoneNumberUtils;
import com.android.telephony.Rlog;
import com.android.telephony.Rlog;
import android.telephony.ServiceState;
import android.telephony.ServiceState;
import android.telephony.TelephonyManager;
import android.telephony.ims.ImsCallProfile;
import android.telephony.ims.ImsCallProfile;
import android.telephony.ims.ImsStreamMediaProfile;
import android.telephony.ims.ImsStreamMediaProfile;
import android.text.TextUtils;
import android.text.TextUtils;
@@ -1160,17 +1161,18 @@ public class ImsPhoneConnection extends Connection implements
     * @param extras The ImsCallProfile extras.
     * @param extras The ImsCallProfile extras.
     */
     */
    private void updateImsCallRatFromExtras(Bundle extras) {
    private void updateImsCallRatFromExtras(Bundle extras) {
        if (extras.containsKey(ImsCallProfile.EXTRA_CALL_RAT_TYPE) ||
        if (extras.containsKey(ImsCallProfile.EXTRA_CALL_NETWORK_TYPE)
                extras.containsKey(ImsCallProfile.EXTRA_CALL_RAT_TYPE_ALT)) {
                || extras.containsKey(ImsCallProfile.EXTRA_CALL_RAT_TYPE)
                || extras.containsKey(ImsCallProfile.EXTRA_CALL_RAT_TYPE_ALT)) {


            ImsCall call = getImsCall();
            ImsCall call = getImsCall();
            int callTech = ServiceState.RIL_RADIO_TECHNOLOGY_UNKNOWN;
            int networkType = TelephonyManager.NETWORK_TYPE_UNKNOWN;
            if (call != null) {
            if (call != null) {
                callTech = call.getRadioTechnology();
                networkType = call.getNetworkType();
            }
            }


            // Report any changes for call tech change
            // Report any changes for network type change
            setCallRadioTech(callTech);
            setCallRadioTech(ServiceState.networkTypeToRilRadioTechnology(networkType));
        }
        }
    }
    }


+78 −0
Original line number Original line Diff line number Diff line
/*
 * Copyright (C) 2020 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package android.telephony.ims;

import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.verify;

import android.telephony.ServiceState;
import android.telephony.TelephonyManager;
import android.telephony.ims.aidl.IImsCallSessionListener;

import androidx.test.runner.AndroidJUnit4;

import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;

@RunWith(AndroidJUnit4.class)
public class ImsCallSessionListenerTests {

    @Mock
    IImsCallSessionListener mMockListener;

    @Before
    public void setUp() {
        MockitoAnnotations.initMocks(this);
    }

    @Test
    public void testListenerMayHandoverDeprecated() throws Exception {
        ImsCallSessionListener mTestListener = new ImsCallSessionListener(mMockListener);
        mTestListener.callSessionMayHandover(ServiceState.RIL_RADIO_TECHNOLOGY_LTE,
                ServiceState.RIL_RADIO_TECHNOLOGY_IWLAN);
        // verify we get the correct network type equivalent of this param.
        verify(mMockListener).callSessionMayHandover(TelephonyManager.NETWORK_TYPE_LTE,
                TelephonyManager.NETWORK_TYPE_IWLAN);
    }

    @Test
    public void testListenerHandoverDeprecated() throws Exception {
        ImsReasonInfo imsReasonInfo = new ImsReasonInfo();
        ImsCallSessionListener mTestListener = new ImsCallSessionListener(mMockListener);
        mTestListener.callSessionHandover(ServiceState.RIL_RADIO_TECHNOLOGY_LTE,
                ServiceState.RIL_RADIO_TECHNOLOGY_IWLAN, imsReasonInfo);
        // verify we get the correct network type equivalent of this param.
        verify(mMockListener).callSessionHandover(eq(TelephonyManager.NETWORK_TYPE_LTE),
                eq(TelephonyManager.NETWORK_TYPE_IWLAN), eq(imsReasonInfo));
    }

    @Test
    public void testListenerHandoverFailedDeprecated() throws Exception {
        ImsReasonInfo imsReasonInfo = new ImsReasonInfo(
                ImsReasonInfo.CODE_REJECT_ONGOING_HANDOVER, 0 /*extraCode*/);
        ImsCallSessionListener mTestListener = new ImsCallSessionListener(mMockListener);
        mTestListener.callSessionHandoverFailed(ServiceState.RIL_RADIO_TECHNOLOGY_LTE,
                ServiceState.RIL_RADIO_TECHNOLOGY_IWLAN, imsReasonInfo);
        // verify we get the correct network type equivalent of this param.
        verify(mMockListener).callSessionHandoverFailed(eq(TelephonyManager.NETWORK_TYPE_LTE),
                eq(TelephonyManager.NETWORK_TYPE_IWLAN), eq(imsReasonInfo));
    }

}
+42 −18
Original line number Original line Diff line number Diff line
@@ -16,25 +16,24 @@


package com.android.internal.telephony.imsphone;
package com.android.internal.telephony.imsphone;


import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotEquals;
import static org.junit.Assert.assertTrue;

import android.os.Bundle;
import android.os.Bundle;
import android.telephony.ServiceState;
import android.telephony.ServiceState;
import android.telephony.TelephonyManager;
import android.telephony.ims.ImsCallProfile;
import android.test.suitebuilder.annotation.SmallTest;
import android.test.suitebuilder.annotation.SmallTest;


import com.android.ims.ImsCall;
import com.android.ims.ImsCall;
import android.telephony.ims.ImsCallProfile;

import com.android.internal.telephony.TelephonyTest;
import com.android.internal.telephony.TelephonyTest;


import org.junit.After;
import org.junit.After;
import org.junit.Before;
import org.junit.Before;
import org.junit.Test;
import org.junit.Test;


import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotEquals;
import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.doReturn;

public class ImsCallTest extends TelephonyTest {
public class ImsCallTest extends TelephonyTest {


    private Bundle mBundle;
    private Bundle mBundle;
@@ -54,14 +53,27 @@ public class ImsCallTest extends TelephonyTest {


    @Test
    @Test
    @SmallTest
    @SmallTest
    public void testSetWifi() {
    public void testSetWifiDeprecated() {
        ImsCall mTestImsCall = new ImsCall(mContext, mTestCallProfile);
        ImsCall mTestImsCall = new ImsCall(mContext, mTestCallProfile);
        assertFalse(mTestImsCall.isWifiCall());
        assertFalse(mTestImsCall.isWifiCall());
        assertNotEquals(mTestImsCall.getRadioTechnology(), ServiceState.RIL_RADIO_TECHNOLOGY_LTE);
        assertNotEquals(mTestImsCall.getNetworkType(), TelephonyManager.NETWORK_TYPE_LTE);
        // use deprecated API
        mBundle.putString(ImsCallProfile.EXTRA_CALL_RAT_TYPE,
        mBundle.putString(ImsCallProfile.EXTRA_CALL_RAT_TYPE,
                ServiceState.RIL_RADIO_TECHNOLOGY_IWLAN + "");
                ServiceState.RIL_RADIO_TECHNOLOGY_IWLAN + "");
        assertTrue(mTestImsCall.isWifiCall());
        assertTrue(mTestImsCall.isWifiCall());
        assertNotEquals(mTestImsCall.getRadioTechnology(), ServiceState.RIL_RADIO_TECHNOLOGY_LTE);
        assertNotEquals(mTestImsCall.getNetworkType(), TelephonyManager.NETWORK_TYPE_LTE);
    }

    @Test
    @SmallTest
    public void testSetWifi() {
        ImsCall mTestImsCall = new ImsCall(mContext, mTestCallProfile);
        assertFalse(mTestImsCall.isWifiCall());
        assertNotEquals(mTestImsCall.getNetworkType(), TelephonyManager.NETWORK_TYPE_LTE);
        mBundle.putInt(ImsCallProfile.EXTRA_CALL_NETWORK_TYPE,
                TelephonyManager.NETWORK_TYPE_IWLAN);
        assertTrue(mTestImsCall.isWifiCall());
        assertNotEquals(mTestImsCall.getNetworkType(), TelephonyManager.NETWORK_TYPE_LTE);
    }
    }


    @Test
    @Test
@@ -69,23 +81,35 @@ public class ImsCallTest extends TelephonyTest {
    public void testSetWifiAlt() {
    public void testSetWifiAlt() {
        ImsCall mTestImsCall = new ImsCall(mContext, mTestCallProfile);
        ImsCall mTestImsCall = new ImsCall(mContext, mTestCallProfile);
        assertFalse(mTestImsCall.isWifiCall());
        assertFalse(mTestImsCall.isWifiCall());
        assertNotEquals(mTestImsCall.getRadioTechnology(), ServiceState.RIL_RADIO_TECHNOLOGY_LTE);
        assertNotEquals(mTestImsCall.getNetworkType(), TelephonyManager.NETWORK_TYPE_LTE);
        mBundle.putString(ImsCallProfile.EXTRA_CALL_RAT_TYPE_ALT,
        mBundle.putString(ImsCallProfile.EXTRA_CALL_RAT_TYPE_ALT,
                ServiceState.RIL_RADIO_TECHNOLOGY_IWLAN + "");
                ServiceState.RIL_RADIO_TECHNOLOGY_IWLAN + "");
        assertTrue(mTestImsCall.isWifiCall());
        assertTrue(mTestImsCall.isWifiCall());
        assertNotEquals(mTestImsCall.getRadioTechnology(), ServiceState.RIL_RADIO_TECHNOLOGY_LTE);
        assertNotEquals(mTestImsCall.getNetworkType(), TelephonyManager.NETWORK_TYPE_LTE);
    }
    }


    @Test
    @Test
    @SmallTest
    @SmallTest
    public void testSetLteNoWifi() {
    public void testSetLteNoWifiDeprecated() {
        ImsCall mTestImsCall = new ImsCall(mContext, mTestCallProfile);
        ImsCall mTestImsCall = new ImsCall(mContext, mTestCallProfile);
        assertFalse(mTestImsCall.isWifiCall());
        assertFalse(mTestImsCall.isWifiCall());
        assertNotEquals(mTestImsCall.getRadioTechnology(), ServiceState.RIL_RADIO_TECHNOLOGY_LTE);
        assertNotEquals(mTestImsCall.getNetworkType(), TelephonyManager.NETWORK_TYPE_LTE);
        mBundle.putString(ImsCallProfile.EXTRA_CALL_RAT_TYPE,
        mBundle.putString(ImsCallProfile.EXTRA_CALL_RAT_TYPE,
                ServiceState.RIL_RADIO_TECHNOLOGY_LTE + "");
                ServiceState.RIL_RADIO_TECHNOLOGY_LTE + "");
        assertFalse(mTestImsCall.isWifiCall());
        assertFalse(mTestImsCall.isWifiCall());
        assertEquals(mTestImsCall.getRadioTechnology(), ServiceState.RIL_RADIO_TECHNOLOGY_LTE);
        assertEquals(mTestImsCall.getNetworkType(), TelephonyManager.NETWORK_TYPE_LTE);
    }

    @Test
    @SmallTest
    public void testSetLteNoWifi() {
        ImsCall mTestImsCall = new ImsCall(mContext, mTestCallProfile);
        assertFalse(mTestImsCall.isWifiCall());
        assertNotEquals(mTestImsCall.getNetworkType(), TelephonyManager.NETWORK_TYPE_LTE);
        mBundle.putInt(ImsCallProfile.EXTRA_CALL_NETWORK_TYPE,
                TelephonyManager.NETWORK_TYPE_LTE);
        assertFalse(mTestImsCall.isWifiCall());
        assertEquals(mTestImsCall.getNetworkType(), TelephonyManager.NETWORK_TYPE_LTE);
    }
    }


    @Test
    @Test
@@ -93,10 +117,10 @@ public class ImsCallTest extends TelephonyTest {
    public void testSetLteNoWifiAlt() {
    public void testSetLteNoWifiAlt() {
        ImsCall mTestImsCall = new ImsCall(mContext, mTestCallProfile);
        ImsCall mTestImsCall = new ImsCall(mContext, mTestCallProfile);
        assertFalse(mTestImsCall.isWifiCall());
        assertFalse(mTestImsCall.isWifiCall());
        assertNotEquals(mTestImsCall.getRadioTechnology(), ServiceState.RIL_RADIO_TECHNOLOGY_LTE);
        assertNotEquals(mTestImsCall.getNetworkType(), TelephonyManager.NETWORK_TYPE_LTE);
        mBundle.putString(ImsCallProfile.EXTRA_CALL_RAT_TYPE_ALT,
        mBundle.putString(ImsCallProfile.EXTRA_CALL_RAT_TYPE_ALT,
                ServiceState.RIL_RADIO_TECHNOLOGY_LTE + "");
                ServiceState.RIL_RADIO_TECHNOLOGY_LTE + "");
        assertFalse(mTestImsCall.isWifiCall());
        assertFalse(mTestImsCall.isWifiCall());
        assertEquals(mTestImsCall.getRadioTechnology(), ServiceState.RIL_RADIO_TECHNOLOGY_LTE);
        assertEquals(mTestImsCall.getNetworkType(), TelephonyManager.NETWORK_TYPE_LTE);
    }
    }
}
}
Loading