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

Commit f3ace853 authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Apply *67 and *82 for carriers in Ims/GsmMmiCode as temporary CLIR...

Merge "Apply *67 and *82 for carriers in Ims/GsmMmiCode as temporary CLIR codes Supress CLIR for emergency call in GsmCdmaCallTracker" into sc-dev
parents ea6c754e ad9011e6
Loading
Loading
Loading
Loading
+14 −1
Original line number Diff line number Diff line
@@ -43,9 +43,9 @@ import android.text.TextUtils;
import android.util.EventLog;

import com.android.internal.annotations.VisibleForTesting;
import com.android.internal.telephony.PhoneInternalInterface.DialArgs;
import com.android.internal.telephony.cdma.CdmaCallWaitingNotification;
import com.android.internal.telephony.metrics.TelephonyMetrics;
import com.android.internal.telephony.PhoneInternalInterface.DialArgs;
import com.android.telephony.Rlog;

import java.io.FileDescriptor;
@@ -282,6 +282,11 @@ public class GsmCdmaCallTracker extends CallTracker {
        UUSInfo uusInfo = dialArgs.uusInfo;
        Bundle intentExtras = dialArgs.intentExtras;
        boolean isEmergencyCall = dialArgs.isEmergency;
        if (isEmergencyCall) {
            clirMode = CommandsInterface.CLIR_SUPPRESSION;
            if (Phone.DEBUG_PHONE) log("dial gsm emergency call, set clirModIe=" + clirMode);

        }

        // note that this triggers call state changed notif
        clearDisconnected();
@@ -301,6 +306,7 @@ public class GsmCdmaCallTracker extends CallTracker {
            // and we need to make sure the foreground call is clear
            // for the newly dialed connection
            switchWaitingOrHoldingAndActive();

            // This is a hack to delay DIAL so that it is sent out to RIL only after
            // EVENT_SWITCH_RESULT is received. We've seen failures when adding a new call to
            // multi-way conference calls due to DIAL being sent out before SWITCH is processed
@@ -333,6 +339,7 @@ public class GsmCdmaCallTracker extends CallTracker {
                    TelecomManager.EXTRA_IS_USER_INTENT_EMERGENCY_CALL));
        }
        mHangupPendingMO = false;

        mMetrics.writeRilDial(mPhone.getPhoneId(), mPendingMO, clirMode, uusInfo);
        mPhone.getVoiceCallSessionStats().onRilDial(mPendingMO);

@@ -345,6 +352,7 @@ public class GsmCdmaCallTracker extends CallTracker {
            // and will mark it as dropped.
            pollCallsWhenSafe();
        } else {

            // Always unmute when initiating a new call
            setMute(false);

@@ -405,6 +413,11 @@ public class GsmCdmaCallTracker extends CallTracker {
        Bundle intentExtras = dialArgs.intentExtras;
        boolean isEmergencyCall = dialArgs.isEmergency;

        if (isEmergencyCall) {
            clirMode = CommandsInterface.CLIR_SUPPRESSION;
            if (Phone.DEBUG_PHONE) log("dial cdma emergency call, set clirModIe=" + clirMode);
        }

        // note that this triggers call state changed notif
        clearDisconnected();

+46 −12
Original line number Diff line number Diff line
@@ -46,6 +46,7 @@ import android.text.SpannableStringBuilder;
import android.text.TextDirectionHeuristics;
import android.text.TextUtils;

import com.android.internal.annotations.VisibleForTesting;
import com.android.internal.telephony.CallForwardInfo;
import com.android.internal.telephony.CallStateException;
import com.android.internal.telephony.CommandException;
@@ -235,10 +236,14 @@ public final class GsmMmiCode extends Handler implements MmiCode {
        Matcher m;
        GsmMmiCode ret = null;

        if (phone.getServiceState().getVoiceRoaming()
                && phone.supportsConversionOfCdmaCallerIdMmiCodesWhileRoaming()) {
        if ((phone.getServiceState().getVoiceRoaming()
                && phone.supportsConversionOfCdmaCallerIdMmiCodesWhileRoaming())
                        || (isEmergencyNumber(phone, dialString)
                                && isCarrierSupportCallerIdVerticalServiceCodes(phone))) {
            /* The CDMA MMI coded dialString will be converted to a 3GPP MMI Coded dialString
               so that it can be processed by the matcher and code below
               so that it can be processed by the matcher and code below. This can be triggered if
               the dialing string is an emergency number and carrier supports caller ID vertical
               service codes *67, *82.
             */
            dialString = convertCdmaMmiCodesTo3gppMmiCodes(dialString);
        }
@@ -779,9 +784,7 @@ public final class GsmMmiCode extends Handler implements MmiCode {
            return false;
        }

        TelephonyManager tm =
                (TelephonyManager) phone.getContext().getSystemService(Context.TELEPHONY_SERVICE);
        if (tm.isEmergencyNumber(dialString)) {
        if (isEmergencyNumber(phone, dialString)) {
            return false;
        } else {
            return isShortCodeUSSD(dialString, phone);
@@ -833,10 +836,42 @@ public final class GsmMmiCode extends Handler implements MmiCode {
     *       " # 31 # [called number] SEND "
     */
    @UnsupportedAppUsage
    public boolean
    isTemporaryModeCLIR() {
        return mSc != null && mSc.equals(SC_CLIR) && mDialingNumber != null
                && (isActivate() || isDeactivate());
    public boolean isTemporaryModeCLIR() {
        return mSc != null && mSc.equals(SC_CLIR)
                && mDialingNumber != null && (isActivate() || isDeactivate());
    }

    /**
     * Checks if the dialing string is an emergency number.
     */
    @VisibleForTesting
    public static boolean isEmergencyNumber(Phone phone, String dialString) {
        try {
            TelephonyManager tm = phone.getContext().getSystemService(TelephonyManager.class);
            return tm.isEmergencyNumber(dialString);
        } catch (RuntimeException ex) {
            return false;
        }
    }

    /**
     * Checks if carrier supports caller id vertical service codes by checking with
     * {@link CarrierConfigManager#KEY_CARRIER_SUPPORTS_CALLER_ID_VERTICAL_SERVICE_CODES_BOOL}.
     */
    @VisibleForTesting
    public static boolean isCarrierSupportCallerIdVerticalServiceCodes(Phone phone) {
        CarrierConfigManager configManager = phone.getContext().getSystemService(
                CarrierConfigManager.class);
        PersistableBundle b = null;
        if (configManager != null) {
            // If an invalid subId is used, this bundle will contain default values.
            b = configManager.getConfigForSubId(phone.getSubId());
        }
        if (b != null) {
            return b == null ? false : b.getBoolean(CarrierConfigManager
                    .KEY_CARRIER_SUPPORTS_CALLER_ID_VERTICAL_SERVICE_CODES_BOOL);
        }
        return false;
    }

    /**
@@ -1772,8 +1807,7 @@ public final class GsmMmiCode extends Handler implements MmiCode {
     * @return integer value of corresponding key.
     */
    private int getIntCarrierConfig(String key) {
        CarrierConfigManager ConfigManager =
                (CarrierConfigManager) mContext.getSystemService(Context.CARRIER_CONFIG_SERVICE);
        CarrierConfigManager ConfigManager = mContext.getSystemService(CarrierConfigManager.class);
        PersistableBundle b = null;
        if (ConfigManager != null) {
            // If an invalid subId is used, this bundle will contain default values.
+49 −13
Original line number Diff line number Diff line
@@ -55,6 +55,7 @@ import android.text.SpannableStringBuilder;
import android.text.TextUtils;

import com.android.ims.ImsException;
import com.android.internal.annotations.VisibleForTesting;
import com.android.internal.telephony.CallForwardInfo;
import com.android.internal.telephony.CallStateException;
import com.android.internal.telephony.CommandException;
@@ -259,7 +260,8 @@ public final class ImsPhoneMmiCode extends Handler implements MmiCode {
     */

    @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553)
    static ImsPhoneMmiCode newFromDialString(String dialString, ImsPhone phone) {
    @VisibleForTesting
    public static ImsPhoneMmiCode newFromDialString(String dialString, ImsPhone phone) {
       return newFromDialString(dialString, phone, null);
    }

@@ -268,10 +270,14 @@ public final class ImsPhoneMmiCode extends Handler implements MmiCode {
        Matcher m;
        ImsPhoneMmiCode ret = null;

        if (phone.getDefaultPhone().getServiceState().getVoiceRoaming()
                && phone.getDefaultPhone().supportsConversionOfCdmaCallerIdMmiCodesWhileRoaming()) {
        if ((phone.getDefaultPhone().getServiceState().getVoiceRoaming()
                && phone.getDefaultPhone().supportsConversionOfCdmaCallerIdMmiCodesWhileRoaming())
                        || (isEmergencyNumber(phone, dialString)
                                && isCarrierSupportCallerIdVerticalServiceCodes(phone))) {
            /* The CDMA MMI coded dialString will be converted to a 3GPP MMI Coded dialString
               so that it can be processed by the matcher and code below
               so that it can be processed by the matcher and code below. This can be triggered if
               the dialing string is an emergency number and carrier supports caller ID vertical
               service codes *67, *82.
             */
            dialString = convertCdmaMmiCodesTo3gppMmiCodes(dialString);
        }
@@ -317,13 +323,13 @@ public final class ImsPhoneMmiCode extends Handler implements MmiCode {
            ret = new ImsPhoneMmiCode(phone);
            ret.mDialingNumber = dialString;
        }

        return ret;
    }

    private static String convertCdmaMmiCodesTo3gppMmiCodes(String dialString) {
        Matcher m;
        m = sPatternCdmaMmiCodeWhileRoaming.matcher(dialString);

        if (m.matches()) {
            String serviceCode = makeEmptyNull(m.group(MATCH_GROUP_CDMA_MMI_CODE_SERVICE_CODE));
            String prefix = m.group(MATCH_GROUP_CDMA_MMI_CODE_NUMBER_PREFIX);
@@ -672,10 +678,7 @@ public final class ImsPhoneMmiCode extends Handler implements MmiCode {
        if (dialString.length() == 0) {
            return false;
        }

        TelephonyManager tm =
                (TelephonyManager) phone.getContext().getSystemService(Context.TELEPHONY_SERVICE);
        if (tm.isEmergencyNumber(dialString)) {
        if (isEmergencyNumber(phone, dialString)) {
            return false;
        } else {
            return isShortCodeUSSD(dialString, phone);
@@ -726,10 +729,43 @@ public final class ImsPhoneMmiCode extends Handler implements MmiCode {
     *       " # 31 # [called number] SEND "
     */
    @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553)
    boolean
    isTemporaryModeCLIR() {
        return mSc != null && mSc.equals(SC_CLIR) && mDialingNumber != null
                && (isActivate() || isDeactivate());
    @VisibleForTesting
    public boolean isTemporaryModeCLIR() {
        return mSc != null && mSc.equals(SC_CLIR)
                && mDialingNumber != null && (isActivate() || isDeactivate());
    }

    /**
     * Checks if the dialing string is an emergency number.
     */
    @VisibleForTesting
    public static boolean isEmergencyNumber(Phone phone, String dialString) {
        try {
            TelephonyManager tm = phone.getContext().getSystemService(TelephonyManager.class);
            return tm.isEmergencyNumber(dialString);
        } catch (RuntimeException ex) {
            return false;
        }
    }

    /**
     * Checks if carrier supports caller id vertical service codes by checking with
     * {@link CarrierConfigManager#KEY_CARRIER_SUPPORTS_CALLER_ID_VERTICAL_SERVICE_CODES_BOOL}.
     */
    @VisibleForTesting
    public static boolean isCarrierSupportCallerIdVerticalServiceCodes(Phone phone) {
        CarrierConfigManager configManager = phone.getContext().getSystemService(
                CarrierConfigManager.class);
        PersistableBundle b = null;
        if (configManager != null) {
            // If an invalid subId is used, this bundle will contain default values.
            b = configManager.getConfigForSubId(phone.getSubId());
        }
        if (b != null) {
            return b == null ? false : b.getBoolean(CarrierConfigManager
                .KEY_CARRIER_SUPPORTS_CALLER_ID_VERTICAL_SERVICE_CODES_BOOL);
        }
        return false;
    }

    /**
+12 −0
Original line number Diff line number Diff line
@@ -32,6 +32,7 @@ import android.os.Message;
import android.telephony.DisconnectCause;
import android.telephony.PhoneNumberUtils;
import android.telephony.ServiceState;
import android.telephony.emergency.EmergencyNumber;
import android.test.suitebuilder.annotation.MediumTest;
import android.test.suitebuilder.annotation.SmallTest;
import android.testing.AndroidTestingRunner;
@@ -55,6 +56,7 @@ import org.mockito.Mock;
public class GsmCdmaCallTrackerTest extends TelephonyTest {
    private static final int VOICE_CALL_STARTED_EVENT = 0;
    private static final int VOICE_CALL_ENDED_EVENT = 1;
    private static final String TEST_DIAL_STRING = "54321";
    private String mDialString = PhoneNumberUtils.stripSeparators("+17005554141");
    /* Handler class initiated at the HandlerThread */
    private GsmCdmaCallTracker mCTUT;
@@ -83,6 +85,16 @@ public class GsmCdmaCallTrackerTest extends TelephonyTest {
        super.tearDown();
    }

    @Test
    @SmallTest
    public void testCLIRMode() throws Exception {
        DialArgs dialArgs = new DialArgs.Builder().setIsEmergency(true).build();
        mCTUT.dialGsm(TEST_DIAL_STRING, dialArgs);
        verify(mSimulatedCommandsVerifier).dial(eq(TEST_DIAL_STRING), eq(true),
                isA(EmergencyNumber.class), eq(false), eq(CommandsInterface.CLIR_SUPPRESSION),
                        eq((UUSInfo) null), isA(Message.class));
    }

    @Test
    @SmallTest
    public void testMOCallDial() {
+104 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2021 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 com.android.internal.telephony.gsm;

import static org.junit.Assert.assertTrue;
import static org.mockito.ArgumentMatchers.anyInt;
import static org.mockito.Mockito.doReturn;

import android.os.PersistableBundle;
import android.telephony.CarrierConfigManager;
import android.testing.AndroidTestingRunner;
import android.testing.TestableLooper;

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

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

import java.util.concurrent.Executor;

/**
 * Unit tests for the {@link GsmMmiCodeTest}.
 */
@RunWith(AndroidTestingRunner.class)
@TestableLooper.RunWithLooper
public class GsmMmiCodeTest extends TelephonyTest {
    private static final String TEST_DIAL_STRING_SERVICE_CODE = "*67911";
    private static final String TEST_DIAL_STRING_NO_SERVICE_CODE = "*767911";
    private static final String TEST_DIAL_STRING_NON_EMERGENCY_NUMBER = "11976";
    private GsmMmiCode mGsmMmiCode;
    private GsmCdmaPhone mGsmCdmaPhoneUT;

    private Executor mExecutor = new Executor() {
        @Override
        public void execute(Runnable r) {
            r.run();
        }
    };

    @Before
    public void setUp() throws Exception {
        super.setUp(getClass().getSimpleName());
        doReturn(mExecutor).when(mContext).getMainExecutor();
        mGsmCdmaPhoneUT = new GsmCdmaPhone(mContext, mSimulatedCommands, mNotifier, true, 0,
                PhoneConstants.PHONE_TYPE_GSM, mTelephonyComponentFactory, (c, p) -> mImsManager);
        setCarrierSupportsCallerIdVerticalServiceCodesCarrierConfig();
    }

    @After
    public void tearDown() throws Exception {
        super.tearDown();
    }

    @Test
    public void testIsTemporaryModeCLIRFromCarrierConfig() {
        // Test *67911 is treated as temporary mode CLIR
        doReturn(true).when(mTelephonyManager).isEmergencyNumber(TEST_DIAL_STRING_SERVICE_CODE);
        mGsmMmiCode = GsmMmiCode.newFromDialString(TEST_DIAL_STRING_SERVICE_CODE, mGsmCdmaPhoneUT,
                null, null);
        assertTrue(mGsmMmiCode.isTemporaryModeCLIR());
    }

    @Test
    public void testIsTemporaryModeCLIRForNonServiceCode() {
        // Test if prefix isn't *67 or *82
        doReturn(true).when(mTelephonyManager).isEmergencyNumber(TEST_DIAL_STRING_NO_SERVICE_CODE);
        mGsmMmiCode = GsmMmiCode.newFromDialString(TEST_DIAL_STRING_NO_SERVICE_CODE,
                mGsmCdmaPhoneUT, null, null);
        assertTrue(mGsmMmiCode == null);
    }

    @Test
    public void testIsTemporaryModeCLIRForNonEmergencyNumber() {
        // Test if dialing string isn't an emergency number
        mGsmMmiCode = GsmMmiCode.newFromDialString(TEST_DIAL_STRING_NON_EMERGENCY_NUMBER,
                mGsmCdmaPhoneUT, null, null);
        assertTrue(mGsmMmiCode == null);
    }

    private void setCarrierSupportsCallerIdVerticalServiceCodesCarrierConfig() {
        final PersistableBundle bundle = new PersistableBundle();
        bundle.putBoolean(CarrierConfigManager
                .KEY_CARRIER_SUPPORTS_CALLER_ID_VERTICAL_SERVICE_CODES_BOOL, true);
        doReturn(bundle).when(mCarrierConfigManager).getConfigForSubId(anyInt());
    }
}
Loading