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

Commit 397a0416 authored by Sooraj Sasindran's avatar Sooraj Sasindran
Browse files

Provide last known cell id for emergency call

Provide last known cell id to connection service
for emergency calls.

Bug: 198533763
Test: unit test
Change-Id: I59a8b88954122ccb68fe716456d1c68a41d02fe3
parent fc3cfe43
Loading
Loading
Loading
Loading
+32 −1
Original line number Diff line number Diff line
@@ -124,6 +124,7 @@ import java.util.HashSet;
import java.util.LinkedList;
import java.util.List;
import java.util.Set;
import java.util.concurrent.TimeUnit;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
@@ -274,6 +275,7 @@ public class ServiceStateTracker extends Handler {
    private static final int EVENT_POLL_STATE_REQUEST                  = 58;
    // Timeout event used when delaying radio power off to wait for IMS deregistration to happen.
    private static final int EVENT_POWER_OFF_RADIO_IMS_DEREG_TIMEOUT   = 62;
    protected static final int EVENT_RESET_LAST_KNOWN_CELL_IDENTITY    = 63;

    /**
     * The current service state.
@@ -455,6 +457,7 @@ public class ServiceStateTracker extends Handler {
    protected final GsmCdmaPhone mPhone;

    private CellIdentity mCellIdentity;
    @Nullable private CellIdentity mLastKnownCellIdentity;
    private static final int MS_PER_HOUR = 60 * 60 * 1000;
    private final NitzStateMachine mNitzState;

@@ -748,6 +751,7 @@ public class ServiceStateTracker extends Handler {
        mNitzState.handleNetworkUnavailable();
        mCellIdentity = null;
        mPhone.getSignalStrengthController().setSignalStrengthDefaultValues();
        mLastKnownCellIdentity = null;

        //cancel any pending pollstate request on voice tech switching
        cancelPollState();
@@ -1672,6 +1676,12 @@ public class ServiceStateTracker extends Handler {
                break;
            }

            case EVENT_RESET_LAST_KNOWN_CELL_IDENTITY: {
                if (DBG) log("EVENT_RESET_LAST_KNOWN_CELL_IDENTITY triggered");
                mLastKnownCellIdentity = null;
                break;
            }

            default:
                log("Unhandled message with number: " + msg.what);
                break;
@@ -3568,6 +3578,15 @@ public class ServiceStateTracker extends Handler {
        mNewSS.setStateOutOfService();

        mCellIdentity = primaryCellIdentity;
        if (mSS.getState() == ServiceState.STATE_IN_SERVICE && primaryCellIdentity != null) {
            mLastKnownCellIdentity = mCellIdentity;
            removeMessages(EVENT_RESET_LAST_KNOWN_CELL_IDENTITY);
        }

        if (hasDeregistered && !hasMessages(EVENT_RESET_LAST_KNOWN_CELL_IDENTITY)) {
            sendEmptyMessageDelayed(EVENT_RESET_LAST_KNOWN_CELL_IDENTITY,
                    TimeUnit.DAYS.toMillis(1));
        }

        int areaCode = getAreaCodeFromCellIdentity(mCellIdentity);
        if (areaCode != mLastKnownAreaCode && areaCode != CellInfo.UNAVAILABLE) {
@@ -5850,4 +5869,16 @@ public class ServiceStateTracker extends Handler {
    public void unregisterForAreaCodeChanged(Handler h) {
        mAreaCodeChangedRegistrants.remove(h);
    }

    /**
     * get last known cell identity
     * If there is current registered network this value will be same as the registered cell
     * identity. If the device goes out of service the previous cell identity is cached and
     * will be returned. If the cache age of the cell identity is more than 24 hours
     * it will be cleared and null will be returned.
     * @return last known cell identity.
     */
    public @Nullable CellIdentity getLastKnownCellIdentity() {
        return mLastKnownCellIdentity;
    }
}
+47 −0
Original line number Diff line number Diff line
@@ -20,6 +20,7 @@ import static com.google.common.truth.Truth.assertThat;

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.Matchers.any;
import static org.mockito.Matchers.anyLong;
@@ -2121,6 +2122,30 @@ public class ServiceStateTrackerTest extends TelephonyTest {
        waitForLastHandlerAction(mSSTTestHandler.getThreadHandler());
    }

    private void sendRegStateUpdateForLteOnOos() throws Exception {
        LteVopsSupportInfo lteVopsSupportInfo =
                new LteVopsSupportInfo(LteVopsSupportInfo.LTE_STATUS_NOT_AVAILABLE,
                        LteVopsSupportInfo.LTE_STATUS_NOT_AVAILABLE);
        NetworkRegistrationInfo dataResult = new NetworkRegistrationInfo(
                NetworkRegistrationInfo.DOMAIN_PS, AccessNetworkConstants.TRANSPORT_TYPE_WWAN,
                NetworkRegistrationInfo.REGISTRATION_STATE_NOT_REGISTERED_OR_SEARCHING,
                TelephonyManager.NETWORK_TYPE_UNKNOWN, 0, false, null, null, "", 1, false, false,
                false, lteVopsSupportInfo);
        NetworkRegistrationInfo voiceResult = new NetworkRegistrationInfo(
                NetworkRegistrationInfo.DOMAIN_CS, AccessNetworkConstants.TRANSPORT_TYPE_WWAN,
                NetworkRegistrationInfo.REGISTRATION_STATE_NOT_REGISTERED_OR_SEARCHING,
                TelephonyManager.NETWORK_TYPE_UNKNOWN, 0, false, null, null, "", false, 0, 0, 0);
        sst.mPollingContext[0] = 2;
        sst.sendMessage(sst.obtainMessage(
                ServiceStateTracker.EVENT_POLL_STATE_PS_CELLULAR_REGISTRATION,
                new AsyncResult(sst.mPollingContext, dataResult, null)));
        waitForLastHandlerAction(mSSTTestHandler.getThreadHandler());
        sst.sendMessage(sst.obtainMessage(
                ServiceStateTracker.EVENT_POLL_STATE_CS_CELLULAR_REGISTRATION,
                new AsyncResult(sst.mPollingContext, voiceResult, null)));
        waitForLastHandlerAction(mSSTTestHandler.getThreadHandler());
    }

    @Test
    public void testPhyChanBandwidthUpdatedOnDataRegState() throws Exception {
        // Cell ID change should trigger hasLocationChanged.
@@ -2501,6 +2526,28 @@ public class ServiceStateTrackerTest extends TelephonyTest {
        verify(mEriManager, times(1)).loadEriFile();
    }

    @Test
    public void testLastKnownCellIdentity() throws Exception {
        CellIdentityLte cellIdentity =
                new CellIdentityLte(1, 1, 5, 1, new int[] {1, 2}, 5000, "001", "01", "test",
                        "tst", Collections.emptyList(), null);

        sendPhyChanConfigChange(new int[] {10000}, TelephonyManager.NETWORK_TYPE_LTE, 1);
        sendRegStateUpdateForLteCellId(cellIdentity);
        assertEquals(ServiceState.STATE_IN_SERVICE, sst.mSS.getState());
        assertEquals(cellIdentity, sst.getLastKnownCellIdentity());
        assertFalse(sst.hasMessages(sst.EVENT_RESET_LAST_KNOWN_CELL_IDENTITY));

        sendRegStateUpdateForLteOnOos();
        assertEquals(ServiceState.STATE_OUT_OF_SERVICE, sst.mSS.getState());
        assertEquals(cellIdentity, sst.getLastKnownCellIdentity());
        assertTrue(sst.hasMessages(sst.EVENT_RESET_LAST_KNOWN_CELL_IDENTITY));

        sst.obtainMessage(sst.EVENT_RESET_LAST_KNOWN_CELL_IDENTITY, null).sendToTarget();
        waitForLastHandlerAction(mSSTTestHandler.getThreadHandler());
        assertNull(sst.getLastKnownCellIdentity());
    }

    @Test
    public void testUpdateSpnDisplay_noService_displayEmergencyCallOnly() {
        // GSM phone