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

Commit 49c99113 authored by Jack Yu's avatar Jack Yu
Browse files

Fixed enableLocationUpdates crash

1. The EVENT_GET_LOC_DONE handler dit not handle the
   new voice registration response properly. This is a
   regression introduced in ag/1907337.

2. Make ServiceStateTracker unit tests passed again!
   Fixed a regression introduced by the Trebel change ag/1750738.
   Return value of EVENT_RESTRICTED_STATE_CHANGED now is an integer
   instead of an integer array.

Test: Telephony sanity tests
bug: 35980759
Change-Id: Idcacc4c891950913172be00daa966e7eb5be7fa6
parent ef4062e1
Loading
Loading
Loading
Loading
+97 −131
Original line number Diff line number Diff line
@@ -874,11 +874,93 @@ public class ServiceStateTracker extends Handler {
        }
    }

    private void processCellLocationInfo(CellLocation cellLocation,
                                         VoiceRegStateResult voiceRegStateResult) {
        if (mPhone.isPhoneTypeGsm()) {
            int psc = -1;
            int cid = -1;
            int lac = -1;
            switch(voiceRegStateResult.cellIdentity.cellInfoType) {
                case CellInfoType.GSM: {
                    if (voiceRegStateResult.cellIdentity.cellIdentityGsm.size() == 1) {
                        android.hardware.radio.V1_0.CellIdentityGsm cellIdentityGsm =
                                voiceRegStateResult.cellIdentity.cellIdentityGsm.get(0);
                        cid = cellIdentityGsm.cid;
                        lac = cellIdentityGsm.lac;
                    }
                    break;
                }
                case CellInfoType.WCDMA: {
                    if (voiceRegStateResult.cellIdentity.cellIdentityWcdma.size() == 1) {
                        android.hardware.radio.V1_0.CellIdentityWcdma cellIdentityWcdma =
                                voiceRegStateResult.cellIdentity.cellIdentityWcdma.get(0);
                        cid = cellIdentityWcdma.cid;
                        lac = cellIdentityWcdma.lac;
                        psc = cellIdentityWcdma.psc;
                    }
                    break;
                }
                case CellInfoType.TD_SCDMA: {
                    if (voiceRegStateResult.cellIdentity.cellIdentityTdscdma.size() == 1) {
                        android.hardware.radio.V1_0.CellIdentityTdscdma
                                cellIdentityTdscdma =
                                voiceRegStateResult.cellIdentity.cellIdentityTdscdma.get(0);
                        cid = cellIdentityTdscdma.cid;
                        lac = cellIdentityTdscdma.lac;
                    }
                    break;
                }
                default: {
                    break;
                }
            }
            // LAC and CID are -1 if not avail
            ((GsmCellLocation) cellLocation).setLacAndCid(lac, cid);
            ((GsmCellLocation) cellLocation).setPsc(psc);
        } else {
            int baseStationId = -1;
            int baseStationLatitude = CdmaCellLocation.INVALID_LAT_LONG;
            int baseStationLongitude = CdmaCellLocation.INVALID_LAT_LONG;
            int systemId = 0;
            int networkId = 0;

            switch(voiceRegStateResult.cellIdentity.cellInfoType) {
                case CellInfoType.CDMA: {
                    if (voiceRegStateResult.cellIdentity.cellIdentityCdma.size() == 1) {
                        android.hardware.radio.V1_0.CellIdentityCdma cellIdentityCdma =
                                voiceRegStateResult.cellIdentity.cellIdentityCdma.get(0);
                        baseStationId = cellIdentityCdma.baseStationId;
                        baseStationLatitude = cellIdentityCdma.latitude;
                        baseStationLongitude = cellIdentityCdma.longitude;
                        systemId = cellIdentityCdma.systemId;
                        networkId = cellIdentityCdma.networkId;
                    }
                    break;
                }
                default: {
                    break;
                }
            }

            // Some carriers only return lat-lngs of 0,0
            if (baseStationLatitude == 0 && baseStationLongitude == 0) {
                baseStationLatitude  = CdmaCellLocation.INVALID_LAT_LONG;
                baseStationLongitude = CdmaCellLocation.INVALID_LAT_LONG;
            }

            // Values are -1 if not available.
            ((CdmaCellLocation) cellLocation).setCellLocationData(baseStationId,
                    baseStationLatitude, baseStationLongitude, systemId, networkId);
        }
    }

    @Override
    public void handleMessage(Message msg) {
        AsyncResult ar;
        int[] ints;
        Message message;

        if (VDBG) log("received event " + msg.what);
        switch (msg.what) {
            case EVENT_SET_RADIO_POWER_OFF:
                synchronized(this) {
@@ -999,62 +1081,8 @@ public class ServiceStateTracker extends Handler {

            case EVENT_GET_LOC_DONE:
                ar = (AsyncResult) msg.obj;

                if (ar.exception == null) {
                    String states[] = (String[])ar.result;
                    if (mPhone.isPhoneTypeGsm()) {
                        int lac = -1;
                        int cid = -1;
                        if (states.length >= 3) {
                            try {
                                if (states[1] != null && states[1].length() > 0) {
                                    lac = (int)Long.parseLong(states[1], 16);
                                }
                                if (states[2] != null && states[2].length() > 0) {
                                    cid = (int)Long.parseLong(states[2], 16);
                                }
                            } catch (NumberFormatException ex) {
                                Rlog.w(LOG_TAG, "error parsing location: " + ex);
                            }
                        }
                        ((GsmCellLocation)mCellLoc).setLacAndCid(lac, cid);
                    } else {
                        int baseStationId = -1;
                        int baseStationLatitude = CdmaCellLocation.INVALID_LAT_LONG;
                        int baseStationLongitude = CdmaCellLocation.INVALID_LAT_LONG;
                        int systemId = -1;
                        int networkId = -1;

                        if (states.length > 9) {
                            try {
                                if (states[4] != null) {
                                    baseStationId = Integer.parseInt(states[4]);
                                }
                                if (states[5] != null) {
                                    baseStationLatitude = Integer.parseInt(states[5]);
                                }
                                if (states[6] != null) {
                                    baseStationLongitude = Integer.parseInt(states[6]);
                                }
                                // Some carriers only return lat-lngs of 0,0
                                if (baseStationLatitude == 0 && baseStationLongitude == 0) {
                                    baseStationLatitude  = CdmaCellLocation.INVALID_LAT_LONG;
                                    baseStationLongitude = CdmaCellLocation.INVALID_LAT_LONG;
                                }
                                if (states[8] != null) {
                                    systemId = Integer.parseInt(states[8]);
                                }
                                if (states[9] != null) {
                                    networkId = Integer.parseInt(states[9]);
                                }
                            } catch (NumberFormatException ex) {
                                loge("error parsing cell location data: " + ex);
                            }
                        }

                        ((CdmaCellLocation)mCellLoc).setCellLocationData(baseStationId,
                                baseStationLatitude, baseStationLongitude, systemId, networkId);
                    }
                    processCellLocationInfo(mCellLoc, (VoiceRegStateResult) ar.result);
                    mPhone.notifyLocationChanged();
                }

@@ -1637,43 +1665,6 @@ public class ServiceStateTracker extends Handler {
                //Denial reason if registrationState = 3
                int reasonForDenial = voiceRegStateResult.reasonForDenial;
                if (mPhone.isPhoneTypeGsm()) {
                    int psc = -1;
                    int cid = -1;
                    int lac = -1;
                    switch(voiceRegStateResult.cellIdentity.cellInfoType) {
                        case CellInfoType.GSM: {
                            if (voiceRegStateResult.cellIdentity.cellIdentityGsm.size() == 1) {
                                android.hardware.radio.V1_0.CellIdentityGsm cellIdentityGsm =
                                        voiceRegStateResult.cellIdentity.cellIdentityGsm.get(0);
                                cid = cellIdentityGsm.cid;
                                lac = cellIdentityGsm.lac;
                            }
                            break;
                        }
                        case CellInfoType.WCDMA: {
                            if (voiceRegStateResult.cellIdentity.cellIdentityWcdma.size() == 1) {
                                android.hardware.radio.V1_0.CellIdentityWcdma cellIdentityWcdma =
                                        voiceRegStateResult.cellIdentity.cellIdentityWcdma.get(0);
                                cid = cellIdentityWcdma.cid;
                                lac = cellIdentityWcdma.lac;
                                psc = cellIdentityWcdma.psc;
                            }
                            break;
                        }
                        case CellInfoType.TD_SCDMA: {
                            if (voiceRegStateResult.cellIdentity.cellIdentityTdscdma.size() == 1) {
                                android.hardware.radio.V1_0.CellIdentityTdscdma
                                        cellIdentityTdscdma =
                                        voiceRegStateResult.cellIdentity.cellIdentityTdscdma.get(0);
                                cid = cellIdentityTdscdma.cid;
                                lac = cellIdentityTdscdma.lac;
                            }
                            break;
                        }
                        default: {
                            break;
                        }
                    }

                    mGsmRoaming = regCodeIsRoaming(registrationState);

@@ -1692,17 +1683,7 @@ public class ServiceStateTracker extends Handler {
                    } else {
                        mEmergencyOnly = false;
                    }

                    // LAC and CID are -1 if not avail
                    ((GsmCellLocation)mNewCellLoc).setLacAndCid(lac, cid);
                    ((GsmCellLocation)mNewCellLoc).setPsc(psc);
                } else {
                    int baseStationId = -1;
                    int baseStationLatitude = CdmaCellLocation.INVALID_LAT_LONG;
                    int baseStationLongitude = CdmaCellLocation.INVALID_LAT_LONG;
                    int systemId = 0;
                    int networkId = 0;

                    //init with 0, because it is treated as a boolean
                    int cssIndicator = voiceRegStateResult.cssSupported ? 1 : 0;
                    int roamingIndicator = voiceRegStateResult.roamingIndicator;
@@ -1713,30 +1694,6 @@ public class ServiceStateTracker extends Handler {
                    //Is default roaming indicator from PRL
                    int defaultRoamingIndicator = voiceRegStateResult.defaultRoamingIndicator;

                    switch(voiceRegStateResult.cellIdentity.cellInfoType) {
                        case CellInfoType.CDMA: {
                            if (voiceRegStateResult.cellIdentity.cellIdentityCdma.size() == 1) {
                                android.hardware.radio.V1_0.CellIdentityCdma cellIdentityCdma =
                                        voiceRegStateResult.cellIdentity.cellIdentityCdma.get(0);
                                baseStationId = cellIdentityCdma.baseStationId;
                                baseStationLatitude = cellIdentityCdma.latitude;
                                baseStationLongitude = cellIdentityCdma.longitude;
                                systemId = cellIdentityCdma.systemId;
                                networkId = cellIdentityCdma.networkId;
                            }
                            break;
                        }
                        default: {
                            break;
                        }
                    }

                    // Some carriers only return lat-lngs of 0,0
                    if (baseStationLatitude == 0 && baseStationLongitude == 0) {
                        baseStationLatitude  = CdmaCellLocation.INVALID_LAT_LONG;
                        baseStationLongitude = CdmaCellLocation.INVALID_LAT_LONG;
                    }

                    mRegistrationState = registrationState;
                    // When registration state is roaming and TSB58
                    // roaming indicator is not in the carrier-specified
@@ -1747,15 +1704,20 @@ public class ServiceStateTracker extends Handler {
                                            Integer.toString(roamingIndicator));
                    mNewSS.setVoiceRoaming(cdmaRoaming);
                    mNewSS.setCssIndicator(cssIndicator);
                    mNewSS.setSystemAndNetworkId(systemId, networkId);
                    mRoamingIndicator = roamingIndicator;
                    mIsInPrl = (systemIsInPrl == 0) ? false : true;
                    mDefaultRoamingIndicator = defaultRoamingIndicator;


                    // Values are -1 if not available.
                    ((CdmaCellLocation)mNewCellLoc).setCellLocationData(baseStationId,
                            baseStationLatitude, baseStationLongitude, systemId, networkId);
                    int systemId = 0;
                    int networkId = 0;
                    if (voiceRegStateResult.cellIdentity.cellInfoType == CellInfoType.CDMA
                            && voiceRegStateResult.cellIdentity.cellIdentityCdma.size() == 1) {
                        android.hardware.radio.V1_0.CellIdentityCdma cellIdentityCdma =
                                voiceRegStateResult.cellIdentity.cellIdentityCdma.get(0);
                        systemId = cellIdentityCdma.systemId;
                        networkId = cellIdentityCdma.networkId;
                    }
                    mNewSS.setSystemAndNetworkId(systemId, networkId);

                    if (reasonForDenial == 0) {
                        mRegistrationDeniedReason = ServiceStateTracker.REGISTRATION_DENIED_GEN;
@@ -1770,6 +1732,8 @@ public class ServiceStateTracker extends Handler {
                    }
                }

                processCellLocationInfo(mNewCellLoc, voiceRegStateResult);

                if (DBG) {
                    log("handlPollVoiceRegResultMessage: regState=" + registrationState
                            + " radioTechnology=" + voiceRegStateResult.rat);
@@ -2445,6 +2409,8 @@ public class ServiceStateTracker extends Handler {
        mPollingContext = new int[1];
        mPollingContext[0] = 0;

        log("pollState: modemTriggered=" + modemTriggered);

        switch (mCi.getRadioState()) {
            case RADIO_UNAVAILABLE:
                mNewSS.setStateOutOfService();
+10 −8
Original line number Diff line number Diff line
@@ -16,6 +16,8 @@

package com.android.internal.telephony.test;

import android.hardware.radio.V1_0.DataRegStateResult;
import android.hardware.radio.V1_0.VoiceRegStateResult;
import android.os.AsyncResult;
import android.os.Handler;
import android.os.HandlerThread;
@@ -916,10 +918,10 @@ public class SimulatedCommands extends BaseCommands
    @Override
    public void getVoiceRegistrationState(Message result) {
        mGetVoiceRegistrationStateCallCount.incrementAndGet();
        String ret[] = new String[14];

        ret[0] = Integer.toString(mVoiceRegState);
        ret[3] = Integer.toString(mVoiceRadioTech);
        VoiceRegStateResult ret = new VoiceRegStateResult();
        ret.regState = mVoiceRegState;
        ret.rat = mVoiceRadioTech;

        resultSuccess(result, ret);
    }
@@ -942,10 +944,10 @@ public class SimulatedCommands extends BaseCommands
    @Override
    public void getDataRegistrationState (Message result) {
        mGetDataRegistrationStateCallCount.incrementAndGet();
        String ret[] = new String[11];

        ret[0] = Integer.toString(mDataRegState);
        ret[3] = Integer.toString(mDataRadioTech);
        DataRegStateResult ret = new DataRegStateResult();
        ret.regState = mDataRegState;
        ret.rat = mDataRadioTech;

        resultSuccess(result, ret);
    }
@@ -2105,7 +2107,7 @@ public class SimulatedCommands extends BaseCommands
    public void triggerRestrictedStateChanged(int restrictedState) {
        if (mRestrictedStateRegistrant != null) {
            mRestrictedStateRegistrant.notifyRegistrant(
                    new AsyncResult(null, new int[]{restrictedState}, null));
                    new AsyncResult(null, restrictedState, null));
        }
    }
}
 No newline at end of file
+20 −8
Original line number Diff line number Diff line
@@ -25,7 +25,6 @@ import static org.mockito.Matchers.any;
import static org.mockito.Matchers.anyLong;
import static org.mockito.Matchers.anyString;
import static org.mockito.Mockito.anyInt;
import static org.mockito.Mockito.atLeast;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.eq;
import static org.mockito.Mockito.spy;
@@ -35,6 +34,9 @@ import static org.mockito.Mockito.verify;
import android.app.IAlarmManager;
import android.content.Context;
import android.content.Intent;
import android.hardware.radio.V1_0.CellIdentityGsm;
import android.hardware.radio.V1_0.CellInfoType;
import android.hardware.radio.V1_0.VoiceRegStateResult;
import android.os.AsyncResult;
import android.os.Bundle;
import android.os.Handler;
@@ -68,6 +70,7 @@ import org.mockito.ArgumentCaptor;
import org.mockito.Mock;

import java.util.ArrayList;
import java.util.List;

public class ServiceStateTrackerTest extends TelephonyTest {

@@ -242,11 +245,16 @@ public class ServiceStateTrackerTest extends TelephonyTest {
        waitForMs(750);

        ArgumentCaptor<Intent> intentArgumentCaptor = ArgumentCaptor.forClass(Intent.class);
        verify(mContextFixture.getTestDouble(), atLeast(2)).
                sendStickyBroadcastAsUser(intentArgumentCaptor.capture(), eq(UserHandle.ALL));
        verify(mContextFixture.getTestDouble(), times(3))
                .sendStickyBroadcastAsUser(intentArgumentCaptor.capture(), eq(UserHandle.ALL));

        // We only want to verify the intent SPN_STRINGS_UPDATED_ACTION.
        Intent intent = intentArgumentCaptor.getValue();
        List<Intent> intents = intentArgumentCaptor.getAllValues();
        logd("Total " + intents.size() + " intents");
        for (Intent intent : intents) {
            logd("  " + intent.getAction());
        }
        Intent intent = intents.get(2);
        assertEquals(TelephonyIntents.SPN_STRINGS_UPDATED_ACTION, intent.getAction());

        Bundle b = intent.getExtras();
@@ -368,13 +376,17 @@ public class ServiceStateTrackerTest extends TelephonyTest {
    @MediumTest
    public void testGsmCellLocation() {

        VoiceRegStateResult result = new VoiceRegStateResult();
        result.cellIdentity.cellInfoType = CellInfoType.GSM;
        result.cellIdentity.cellIdentityGsm.add(new CellIdentityGsm());
        result.cellIdentity.cellIdentityGsm.get(0).lac = 2;
        result.cellIdentity.cellIdentityGsm.get(0).cid = 3;

        sst.sendMessage(sst.obtainMessage(ServiceStateTracker.EVENT_GET_LOC_DONE,
                new AsyncResult(null, new String[]{"1", "2", "3", "4", "5", "6", "7", "8", "9",
                        "10", "11", "12", "13", "14", "15"}, null)));
                new AsyncResult(null, result, null)));

        waitForMs(200);
        WorkSource workSource = new WorkSource(Process.myUid(),
                mContext.getPackageName());
        WorkSource workSource = new WorkSource(Process.myUid(), mContext.getPackageName());
        GsmCellLocation cl = (GsmCellLocation) sst.getCellLocation(workSource);
        assertEquals(2, cl.getLac());
        assertEquals(3, cl.getCid());