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

Commit 0b8eeb90 authored by Hunsuk Choi's avatar Hunsuk Choi
Browse files

Refactoring for the domain selection service of emergency calls

Bug: 243344927
Test: atest GsmCdmaPhoneTest
Change-Id: If2ae9a2a5e383b8597478643eac1c8008f2349b8
parent 9203ba4d
Loading
Loading
Loading
Loading
+29 −0
Original line number Diff line number Diff line
@@ -16,6 +16,8 @@

package com.android.internal.telephony;

import static android.telephony.NetworkRegistrationInfo.DOMAIN_PS;

import static com.android.internal.telephony.CommandException.Error.GENERIC_FAILURE;
import static com.android.internal.telephony.CommandException.Error.SIM_BUSY;
import static com.android.internal.telephony.CommandsInterface.CF_ACTION_DISABLE;
@@ -1350,6 +1352,12 @@ public class GsmCdmaPhone extends Phone {
            logi("dial; isEmergency=" + isEmergency + " (based on all phones)");
        }

        // Undetectable emergeny number indicated by new domain selection service
        if (dialArgs.isEmergency) {
            logi("dial; isEmergency=" + isEmergency + " (domain selection module)");
            isEmergency = true;
        }

        /** Check if the call is Wireless Priority Service call */
        boolean isWpsCall = dialString != null ? (dialString.startsWith(PREFIX_WPS)
                || dialString.startsWith(PREFIX_WPS_CLIR_ACTIVATE)
@@ -1375,6 +1383,27 @@ public class GsmCdmaPhone extends Phone {
        boolean useImsForCall = useImsForCall(dialArgs)
                && (isWpsCall ? allowWpsOverIms : true);

        Bundle extras = dialArgs.intentExtras;
        // Only when the domain selection service is supported, EXTRA_DIAL_DOMAIN extra shall exist.
        if (extras != null && extras.containsKey(PhoneConstants.EXTRA_DIAL_DOMAIN)) {
            int domain = extras.getInt(PhoneConstants.EXTRA_DIAL_DOMAIN);
            logi("dial domain=" + domain);
            useImsForCall = false;
            useImsForUt = false;
            useImsForEmergency = false;
            if (domain == DOMAIN_PS) {
                if (isEmergency) {
                    useImsForEmergency = true;
                } else if (!isMmiCode || isPotentialUssdCode) {
                    useImsForCall = true;
                } else {
                    // should not reach here
                    loge("dial unexpected Ut domain selection, ignored");
                }
            }
            extras.remove(PhoneConstants.EXTRA_DIAL_DOMAIN);
        }

        if (DBG) {
            logi("useImsForCall=" + useImsForCall
                    + ", useOnlyDialedSimEccList=" + useOnlyDialedSimEccList
+8 −1
Original line number Diff line number Diff line
@@ -1543,7 +1543,7 @@ public class ImsPhoneCallTracker extends CallTracker implements ImsPullCall {
            mLastDialString = dialString;
            mLastDialArgs = dialArgs;
            mPendingMO = new ImsPhoneConnection(mPhone, dialString, this, mForegroundCall,
                    isEmergencyNumber, isWpsCall);
                    isEmergencyNumber, isWpsCall, dialArgs);
            mOperationLocalLog.log("dial requested. connId=" + System.identityHashCode(mPendingMO));
            if (isEmergencyNumber && dialArgs != null && dialArgs.intentExtras != null) {
                Rlog.i(LOG_TAG, "dial ims emergency dialer: " + dialArgs.intentExtras.getBoolean(
@@ -3272,6 +3272,13 @@ public class ImsPhoneCallTracker extends CallTracker implements ImsPullCall {
                eccCategory = imsCall.getCallProfile().getEmergencyServiceCategories();
            }

            if (reasonInfo.getCode() == ImsReasonInfo.CODE_SIP_ALTERNATE_EMERGENCY_CALL) {
                ImsPhoneConnection conn = findConnection(imsCall);
                if (conn != null) {
                    conn.setNonDetectableEmergencyCallInfo(eccCategory);
                }
            }

            if (mHoldSwitchingState == HoldSwapState.HOLDING_TO_ANSWER_INCOMING) {
                // If we put a call on hold to answer an incoming call, we should reset the
                // variables that keep track of the switch here.
+9 −1
Original line number Diff line number Diff line
@@ -244,7 +244,8 @@ public class ImsPhoneConnection extends Connection implements

    /** This is an MO call, created when dialing */
    public ImsPhoneConnection(Phone phone, String dialString, ImsPhoneCallTracker ct,
            ImsPhoneCall parent, boolean isEmergency, boolean isWpsCall) {
            ImsPhoneCall parent, boolean isEmergency, boolean isWpsCall,
            ImsPhone.ImsDialArgs dialArgs) {
        super(PhoneConstants.PHONE_TYPE_IMS);
        createWakeLock(phone.getContext());
        acquireWakeLock();
@@ -272,6 +273,13 @@ public class ImsPhoneConnection extends Connection implements
        mIsEmergency = isEmergency;
        if (isEmergency) {
            setEmergencyCallInfo(mOwner);

            if (getEmergencyNumberInfo() == null) {
                // There was no emergency number info found for this call, however it is
                // still marked as an emergency number. This may happen if it was a redialed
                // non-detectable emergency call from IMS.
                setNonDetectableEmergencyCallInfo(dialArgs.eccCategory);
            }
        }

        mIsWpsCall = isWpsCall;
+74 −0
Original line number Diff line number Diff line
@@ -52,6 +52,7 @@ import static org.mockito.Mockito.when;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.AsyncResult;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.os.PersistableBundle;
@@ -2108,4 +2109,77 @@ public class GsmCdmaPhoneTest extends TelephonyTest {
        verify(mImsPhone, times(1)).triggerImsDeregistration(
                eq(ImsRegistrationImplBase.REASON_SIM_REFRESH));
    }

    @Test
    public void testDomainSelectionEmergencyCallCs() throws CallStateException {
        setupEmergencyCallScenario(false /* USE_ONLY_DIALED_SIM_ECC_LIST */,
                false /* isEmergencyOnDialedSim */);

        Bundle extras = new Bundle();
        extras.putInt(PhoneConstants.EXTRA_DIAL_DOMAIN, NetworkRegistrationInfo.DOMAIN_CS);
        ImsPhone.ImsDialArgs dialArgs = new ImsPhone.ImsDialArgs.Builder()
                .setIntentExtras(extras)
                .build();
        mPhoneUT.dial(TEST_EMERGENCY_NUMBER, dialArgs);

        verify(mCT).dialGsm(anyString(), any(PhoneInternalInterface.DialArgs.class));
    }

    @Test
    public void testDomainSelectionEmergencyCallPs() throws CallStateException {
        setupEmergencyCallScenario(false /* USE_ONLY_DIALED_SIM_ECC_LIST */,
                false /* isEmergencyOnDialedSim */);

        doReturn(false).when(mImsPhone).isImsAvailable();

        Bundle extras = new Bundle();
        extras.putInt(PhoneConstants.EXTRA_DIAL_DOMAIN, NetworkRegistrationInfo.DOMAIN_PS);
        ImsPhone.ImsDialArgs dialArgs = new ImsPhone.ImsDialArgs.Builder()
                .setIntentExtras(extras)
                .build();
        mPhoneUT.dial(TEST_EMERGENCY_NUMBER, dialArgs);

        verify(mImsPhone).dial(anyString(), any(PhoneInternalInterface.DialArgs.class));
    }

    @Test
    public void testDomainSelectionDialCs() throws Exception {
        doReturn(true).when(mImsPhone).isImsAvailable();
        doReturn(true).when(mImsManager).isVolteEnabledByPlatform();
        doReturn(true).when(mImsManager).isEnhanced4gLteModeSettingEnabledByUser();
        doReturn(true).when(mImsManager).isNonTtyOrTtyOnVolteEnabled();
        doReturn(true).when(mImsPhone).isVoiceOverCellularImsEnabled();
        doReturn(true).when(mImsPhone).isUtEnabled();

        replaceInstance(Phone.class, "mImsPhone", mPhoneUT, mImsPhone);

        Bundle extras = new Bundle();
        extras.putInt(PhoneConstants.EXTRA_DIAL_DOMAIN, NetworkRegistrationInfo.DOMAIN_CS);
        ImsPhone.ImsDialArgs dialArgs = new ImsPhone.ImsDialArgs.Builder()
                .setIntentExtras(extras)
                .build();
        Connection connection = mPhoneUT.dial("1234567890", dialArgs);
        verify(mCT).dialGsm(eq("1234567890"), any(PhoneInternalInterface.DialArgs.class));
    }

    @Test
    public void testDomainSelectionDialPs() throws Exception {
        mSST.mSS = mServiceState;
        doReturn(ServiceState.STATE_IN_SERVICE).when(mServiceState).getState();

        mCT.mForegroundCall = mGsmCdmaCall;
        mCT.mBackgroundCall = mGsmCdmaCall;
        mCT.mRingingCall = mGsmCdmaCall;
        doReturn(GsmCdmaCall.State.IDLE).when(mGsmCdmaCall).getState();

        replaceInstance(Phone.class, "mImsPhone", mPhoneUT, mImsPhone);

        Bundle extras = new Bundle();
        extras.putInt(PhoneConstants.EXTRA_DIAL_DOMAIN, NetworkRegistrationInfo.DOMAIN_PS);
        ImsPhone.ImsDialArgs dialArgs = new ImsPhone.ImsDialArgs.Builder()
                .setIntentExtras(extras)
                .build();
        Connection connection = mPhoneUT.dial("1234567890", dialArgs);
        verify(mImsPhone).dial(eq("1234567890"), any(PhoneInternalInterface.DialArgs.class));
    }
}
+17 −0
Original line number Diff line number Diff line
@@ -33,6 +33,7 @@ import static android.telephony.TelephonyManager.SRVCC_STATE_HANDOVER_CANCELED;
import static android.telephony.TelephonyManager.SRVCC_STATE_HANDOVER_COMPLETED;
import static android.telephony.TelephonyManager.SRVCC_STATE_HANDOVER_FAILED;
import static android.telephony.TelephonyManager.SRVCC_STATE_HANDOVER_STARTED;
import static android.telephony.emergency.EmergencyNumber.EMERGENCY_SERVICE_CATEGORY_AMBULANCE;
import static android.telephony.ims.ImsStreamMediaProfile.DIRECTION_INACTIVE;
import static android.telephony.ims.ImsStreamMediaProfile.DIRECTION_SEND_RECEIVE;

@@ -84,6 +85,7 @@ import android.telephony.DisconnectCause;
import android.telephony.PhoneNumberUtils;
import android.telephony.ServiceState;
import android.telephony.TelephonyManager;
import android.telephony.emergency.EmergencyNumber;
import android.telephony.ims.ImsCallProfile;
import android.telephony.ims.ImsCallSession;
import android.telephony.ims.ImsConferenceState;
@@ -2348,6 +2350,21 @@ public class ImsPhoneCallTrackerTest extends TelephonyTest {
                eq(CommandsInterface.IMS_MMTEL_CAPABILITY_SMS));
    }

    @Test
    @SmallTest
    public void testDomainSelectionAlternateService() {
        startOutgoingCall();
        ImsPhoneConnection c = mCTUT.mForegroundCall.getFirstConnection();
        mImsCallProfile.setEmergencyServiceCategories(EMERGENCY_SERVICE_CATEGORY_AMBULANCE);
        mImsCallListener.onCallStartFailed(mSecondImsCall,
                new ImsReasonInfo(ImsReasonInfo.CODE_SIP_ALTERNATE_EMERGENCY_CALL, -1));
        processAllMessages();
        EmergencyNumber emergencyNumber = c.getEmergencyNumberInfo();
        assertNotNull(emergencyNumber);
        assertEquals(EMERGENCY_SERVICE_CATEGORY_AMBULANCE,
                emergencyNumber.getEmergencyServiceCategoryBitmask());
    }

    private void sendCarrierConfigChanged() {
        Intent intent = new Intent(CarrierConfigManager.ACTION_CARRIER_CONFIG_CHANGED);
        intent.putExtra(CarrierConfigManager.EXTRA_SUBSCRIPTION_INDEX, mPhone.getSubId());
Loading