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

Commit 0406b378 authored by sqian's avatar sqian Committed by Shuo Qian
Browse files

Migrate Emergency call profile

In some situation, such as Single Radio Voice Call Continuity (SRVCC)
completed, connection is switched between ImsPhoneConnection and
 GsmCdmaConnection, and we should migrate the information that
 includes emergency call information we added in Q.

Without this, the migrated connection does not have the correct
emergency information to do further functionalities, and the metrics
 are not accurate.

Test: Manual; Treehugger
Bug: 134067115
Change-Id: I2aba48fa87b2de79770a969a9776f539e4a5cf9b
Merged-In: I2aba48fa87b2de79770a969a9776f539e4a5cf9b
(cherry picked from commit 6cc96731)
parent 1c25c6fa
Loading
Loading
Loading
Loading
+5 −0
Original line number Diff line number Diff line
@@ -799,6 +799,11 @@ public abstract class Connection {
        mPostDialString = c.mPostDialString;
        mNextPostDialChar = c.mNextPostDialChar;
        mPostDialState = c.mPostDialState;

        // Migrate Emergency call parameters
        mIsEmergencyCall = c.isEmergencyCall();
        mEmergencyNumberInfo = c.getEmergencyNumberInfo();
        mHasKnownUserIntentEmergency = c.hasKnownUserIntentEmergency();
    }

    /**
+152 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2019 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;

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

import android.os.Handler;
import android.os.Looper;

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

/**
 * Unit test verifying the methods of the connection class.
 */
public class ConnectionTest extends TelephonyTest {

    private static final int TEST_PHONE_TYPE = 1;

    @Mock
    protected Call mCall;

    private class TestConnection extends Connection {

        private TestConnection(int phoneType) {
            super(phoneType);
        }

        @Override
        public Call getCall() {
            return mCall;
        }

        @Override
        public long getDisconnectTime() {
            return 0;
        }

        @Override
        public long getHoldDurationMillis() {
            return 0;
        }

        @Override
        public String getVendorDisconnectCause() {
            return "";
        }

        @Override
        public void deflect(String number) throws CallStateException {}

        @Override
        public void hangup() throws CallStateException {}

        @Override
        public void separate() throws CallStateException {}

        @Override
        public void proceedAfterWaitChar() {}

        @Override
        public void proceedAfterWildChar(String str) {}

        @Override
        public void cancelPostDial() {}

        @Override
        public int getNumberPresentation() {
            return 0;
        }

        @Override
        public UUSInfo getUUSInfo() {
            return null;
        }

        @Override
        public int getPreciseDisconnectCause() {
            return 0;
        }

        @Override
        public boolean isMultiparty() {
            return false;
        }
    }

    @Before
    public void setUp() throws Exception {
        super.setUp(getClass().getSimpleName());
        doReturn(mPhone).when(mCall).getPhone();
        replaceInstance(Handler.class, "mLooper", mCT, Looper.getMainLooper());
    }

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

    @Test
    public void testMigrateFrom() {
        Connection connection1 = new TestConnection(TEST_PHONE_TYPE);
        Connection connection2 = new TestConnection(TEST_PHONE_TYPE);

        // Verify Emergency Call info is migrated
        assertFalse(connection1.isEmergencyCall());
        assertNull(connection1.getEmergencyNumberInfo());
        assertFalse(connection1.hasKnownUserIntentEmergency());

        connection2.setEmergencyCallInfo();
        connection2.setHasKnownUserIntentEmergency(true);
        connection1.migrateFrom(connection2);

        assertTrue(connection1.isEmergencyCall());
        assertEquals(getTestEmergencyNumber(), connection1.getEmergencyNumberInfo());
        assertTrue(connection1.hasKnownUserIntentEmergency());

        // TODO Verify more fields during the migration
    }

    @Test
    public void testEmergencyCallParameters() {
        Connection connection = new TestConnection(TEST_PHONE_TYPE);
        connection.setEmergencyCallInfo();
        assertTrue(connection.isEmergencyCall());
        assertEquals(getTestEmergencyNumber(), connection.getEmergencyNumberInfo());
        connection.setHasKnownUserIntentEmergency(true);
        assertTrue(connection.hasKnownUserIntentEmergency());
    }

    // TODO Verify more methods in Connection
}
+15 −0
Original line number Diff line number Diff line
@@ -21,6 +21,7 @@ import static org.junit.Assert.fail;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.Matchers.anyBoolean;
import static org.mockito.Matchers.nullable;
import static org.mockito.Mockito.any;
import static org.mockito.Mockito.anyInt;
import static org.mockito.Mockito.doAnswer;
import static org.mockito.Mockito.doReturn;
@@ -49,6 +50,7 @@ import android.telephony.NetworkRegistrationInfo;
import android.telephony.ServiceState;
import android.telephony.SubscriptionManager;
import android.telephony.TelephonyManager;
import android.telephony.emergency.EmergencyNumber;
import android.telephony.euicc.EuiccManager;
import android.telephony.ims.ImsCallProfile;
import android.test.mock.MockContentProvider;
@@ -88,6 +90,7 @@ import org.mockito.stubbing.Answer;
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
@@ -101,6 +104,12 @@ public abstract class TelephonyTest {

    private static final int MAX_INIT_WAIT_MS = 30000; // 30 seconds

    private static final EmergencyNumber SAMPLE_EMERGENCY_NUMBER =
            new EmergencyNumber("911", "us", "30",
                    EmergencyNumber.EMERGENCY_SERVICE_CATEGORY_UNSPECIFIED,
            new ArrayList<String>(), EmergencyNumber.EMERGENCY_NUMBER_SOURCE_NETWORK_SIGNALING,
            EmergencyNumber.EMERGENCY_CALL_ROUTING_NORMAL);

    @Mock
    protected GsmCdmaPhone mPhone;
    @Mock
@@ -368,6 +377,8 @@ public abstract class TelephonyTest {
        doReturn(mEmergencyNumberTracker).when(mTelephonyComponentFactory)
                .makeEmergencyNumberTracker(nullable(Phone.class),
                        nullable(CommandsInterface.class));
        doReturn(getTestEmergencyNumber()).when(mEmergencyNumberTracker)
                .getEmergencyNumber(any());
        doReturn(mUiccProfile).when(mTelephonyComponentFactory)
                .makeUiccProfile(nullable(Context.class), nullable(CommandsInterface.class),
                        nullable(IccCardStatus.class), anyInt(), nullable(UiccCard.class),
@@ -639,6 +650,10 @@ public abstract class TelephonyTest {
        }
    }

    protected final EmergencyNumber getTestEmergencyNumber() {
        return SAMPLE_EMERGENCY_NUMBER;
    }

    public static Object invokeMethod(
            Object instance, String methodName, Class<?>[] parameterClasses, Object[] parameters) {
        try {