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

Commit 9411d0e8 authored by Sarah Chin's avatar Sarah Chin Committed by Gerrit Code Review
Browse files

Merge "Add TYPE_NR to getCidFromCellIdentity"

parents f672253b 9de84cd2
Loading
Loading
Loading
Loading
+5 −3
Original line number Diff line number Diff line
@@ -64,6 +64,7 @@ import android.telephony.CellIdentity;
import android.telephony.CellIdentityCdma;
import android.telephony.CellIdentityGsm;
import android.telephony.CellIdentityLte;
import android.telephony.CellIdentityNr;
import android.telephony.CellIdentityTdscdma;
import android.telephony.CellIdentityWcdma;
import android.telephony.CellInfo;
@@ -2384,14 +2385,15 @@ public class ServiceStateTracker extends Handler {
     *
     * @returns the cell ID (unique within a PLMN for a given tech) or -1 if invalid
     */
    private static int getCidFromCellIdentity(CellIdentity id) {
    private static long getCidFromCellIdentity(CellIdentity id) {
        if (id == null) return -1;
        int cid = -1;
        long cid = -1;
        switch(id.getType()) {
            case CellInfo.TYPE_GSM: cid = ((CellIdentityGsm) id).getCid(); break;
            case CellInfo.TYPE_WCDMA: cid = ((CellIdentityWcdma) id).getCid(); break;
            case CellInfo.TYPE_TDSCDMA: cid = ((CellIdentityTdscdma) id).getCid(); break;
            case CellInfo.TYPE_LTE: cid = ((CellIdentityLte) id).getCi(); break;
            case CellInfo.TYPE_NR: cid = ((CellIdentityNr) id).getNci(); break;
            default: break;
        }
        // If the CID is unreported
@@ -3391,7 +3393,7 @@ public class ServiceStateTracker extends Handler {
            // TODO: we may add filtering to reduce the event logged,
            // i.e. check preferred network setting, only switch to 2G, etc
            if (hasRilVoiceRadioTechnologyChanged) {
                int cid = getCidFromCellIdentity(primaryCellIdentity);
                long cid = getCidFromCellIdentity(primaryCellIdentity);
                // NOTE: this code was previously located after mSS and mNewSS are swapped, so
                // existing logs were incorrectly using the new state for "network_from"
                // and STATE_OUT_OF_SERVICE for "network_to". To avoid confusion, use a new log tag
+26 −0
Original line number Diff line number Diff line
@@ -65,6 +65,9 @@ import android.telephony.CellIdentity;
import android.telephony.CellIdentityCdma;
import android.telephony.CellIdentityGsm;
import android.telephony.CellIdentityLte;
import android.telephony.CellIdentityNr;
import android.telephony.CellIdentityTdscdma;
import android.telephony.CellIdentityWcdma;
import android.telephony.CellInfo;
import android.telephony.CellInfoGsm;
import android.telephony.CellSignalStrength;
@@ -107,6 +110,7 @@ import org.mockito.ArgumentCaptor;
import org.mockito.Mock;
import org.mockito.Mockito;

import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
@@ -2641,4 +2645,26 @@ public class ServiceStateTrackerTest extends TelephonyTest {
        assertEquals(cids.get(0), cellIdentityLte);
        assertEquals(cids.get(1), cellIdentityGsm);
    }

    @Test
    public void testGetCidFromCellIdentity() throws Exception {
        CellIdentity gsmCi = new CellIdentityGsm(
                0, 1, 0, 0, "", "", "", "", Collections.emptyList());
        CellIdentity wcdmaCi = new CellIdentityWcdma(
                0, 2, 0, 0, "", "", "", "", Collections.emptyList(), null);
        CellIdentity tdscdmaCi = new CellIdentityTdscdma(
                "", "", 0, 3, 0, 0, "", "", Collections.emptyList(), null);
        CellIdentity lteCi = new CellIdentityLte(0, 0, 4, 0, 0);
        CellIdentity nrCi = new CellIdentityNr(
                0, 0, 0, new int[] {}, "", "", 5, "", "", Collections.emptyList());

        Method method = ServiceStateTracker.class.getDeclaredMethod(
                "getCidFromCellIdentity", CellIdentity.class);
        method.setAccessible(true);
        assertEquals(1, (long) method.invoke(mSST, gsmCi));
        assertEquals(2, (long) method.invoke(mSST, wcdmaCi));
        assertEquals(3, (long) method.invoke(mSST, tdscdmaCi));
        assertEquals(4, (long) method.invoke(mSST, lteCi));
        assertEquals(5, (long) method.invoke(mSST, nrCi));
    }
}