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

Commit d7826fe1 authored by Nathan Harold's avatar Nathan Harold Committed by Gerrit Code Review
Browse files

Merge "Unit Tests for CellInfo Timestamp"

parents dbd5e56f ed35cf6e
Loading
Loading
Loading
Loading
+86 −20
Original line number Original line Diff line number Diff line
@@ -151,6 +151,7 @@ import org.mockito.MockitoAnnotations;


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


public class RILTest extends TelephonyTest {
public class RILTest extends TelephonyTest {


@@ -212,7 +213,7 @@ public class RILTest extends TelephonyTest {
    private static final int RSSI_ASU = 24;
    private static final int RSSI_ASU = 24;
    private static final int SYSTEM_ID = 65533;
    private static final int SYSTEM_ID = 65533;
    private static final int TAC = 65535;
    private static final int TAC = 65535;
    private static final int TIME_ADVANCE = 4;
    private static final int TIMING_ADVANCE = 4;
    private static final long TIMESTAMP = 215924934;
    private static final long TIMESTAMP = 215924934;
    private static final int UARFCN = 690;
    private static final int UARFCN = 690;
    private static final int TYPE_CDMA = 2;
    private static final int TYPE_CDMA = 2;
@@ -1099,7 +1100,7 @@ public class RILTest extends TelephonyTest {
        lte.signalStrengthLte.rsrq = -RSRQ;
        lte.signalStrengthLte.rsrq = -RSRQ;
        lte.signalStrengthLte.rssnr = RSSNR;
        lte.signalStrengthLte.rssnr = RSSNR;
        lte.signalStrengthLte.cqi = CQI;
        lte.signalStrengthLte.cqi = CQI;
        lte.signalStrengthLte.timingAdvance = TIME_ADVANCE;
        lte.signalStrengthLte.timingAdvance = TIMING_ADVANCE;
        android.hardware.radio.V1_0.CellInfo record = new android.hardware.radio.V1_0.CellInfo();
        android.hardware.radio.V1_0.CellInfo record = new android.hardware.radio.V1_0.CellInfo();
        record.cellInfoType = TYPE_LTE;
        record.cellInfoType = TYPE_LTE;
        record.registered = false;
        record.registered = false;
@@ -1120,7 +1121,7 @@ public class RILTest extends TelephonyTest {
        CellIdentityLte cil = new CellIdentityLte(CI, PCI, TAC, EARFCN, Integer.MAX_VALUE, MCC_STR,
        CellIdentityLte cil = new CellIdentityLte(CI, PCI, TAC, EARFCN, Integer.MAX_VALUE, MCC_STR,
                MNC_STR, EMPTY_ALPHA_LONG, EMPTY_ALPHA_SHORT);
                MNC_STR, EMPTY_ALPHA_LONG, EMPTY_ALPHA_SHORT);
        CellSignalStrengthLte css = new CellSignalStrengthLte(
        CellSignalStrengthLte css = new CellSignalStrengthLte(
                RSSI, RSRP, RSRQ, RSSNR, CQI, TIME_ADVANCE);
                RSSI, RSRP, RSRQ, RSSNR, CQI, TIMING_ADVANCE);
        expected.setCellIdentity(cil);
        expected.setCellIdentity(cil);
        expected.setCellSignalStrength(css);
        expected.setCellSignalStrength(css);
        expected.setCellConnectionStatus(CellInfo.CONNECTION_UNKNOWN);
        expected.setCellConnectionStatus(CellInfo.CONNECTION_UNKNOWN);
@@ -1140,7 +1141,7 @@ public class RILTest extends TelephonyTest {
        cellinfo.cellIdentityGsm.mnc = MNC_STR;
        cellinfo.cellIdentityGsm.mnc = MNC_STR;
        cellinfo.signalStrengthGsm.signalStrength = RSSI_ASU;
        cellinfo.signalStrengthGsm.signalStrength = RSSI_ASU;
        cellinfo.signalStrengthGsm.bitErrorRate = BIT_ERROR_RATE;
        cellinfo.signalStrengthGsm.bitErrorRate = BIT_ERROR_RATE;
        cellinfo.signalStrengthGsm.timingAdvance = TIME_ADVANCE;
        cellinfo.signalStrengthGsm.timingAdvance = TIMING_ADVANCE;
        android.hardware.radio.V1_0.CellInfo record = new android.hardware.radio.V1_0.CellInfo();
        android.hardware.radio.V1_0.CellInfo record = new android.hardware.radio.V1_0.CellInfo();
        record.cellInfoType = TYPE_GSM;
        record.cellInfoType = TYPE_GSM;
        record.registered = false;
        record.registered = false;
@@ -1161,7 +1162,7 @@ public class RILTest extends TelephonyTest {
        CellIdentityGsm ci = new CellIdentityGsm(
        CellIdentityGsm ci = new CellIdentityGsm(
                LAC, CID, ARFCN, BSIC, MCC_STR, MNC_STR, EMPTY_ALPHA_LONG, EMPTY_ALPHA_SHORT);
                LAC, CID, ARFCN, BSIC, MCC_STR, MNC_STR, EMPTY_ALPHA_LONG, EMPTY_ALPHA_SHORT);
        CellSignalStrengthGsm cs = new CellSignalStrengthGsm(
        CellSignalStrengthGsm cs = new CellSignalStrengthGsm(
                RSSI, BIT_ERROR_RATE, TIME_ADVANCE);
                RSSI, BIT_ERROR_RATE, TIMING_ADVANCE);
        expected.setCellIdentity(ci);
        expected.setCellIdentity(ci);
        expected.setCellSignalStrength(cs);
        expected.setCellSignalStrength(cs);
        expected.setCellConnectionStatus(CellInfo.CONNECTION_UNKNOWN);
        expected.setCellConnectionStatus(CellInfo.CONNECTION_UNKNOWN);
@@ -1305,7 +1306,7 @@ public class RILTest extends TelephonyTest {
        CellIdentityLte cil = new CellIdentityLte(
        CellIdentityLte cil = new CellIdentityLte(
                CI, PCI, TAC, EARFCN, BANDWIDTH, MCC_STR, MNC_STR, ALPHA_LONG, ALPHA_SHORT);
                CI, PCI, TAC, EARFCN, BANDWIDTH, MCC_STR, MNC_STR, ALPHA_LONG, ALPHA_SHORT);
        CellSignalStrengthLte css = new CellSignalStrengthLte(
        CellSignalStrengthLte css = new CellSignalStrengthLte(
                RSSI, RSRP, RSRQ, RSSNR, CQI, TIME_ADVANCE);
                RSSI, RSRP, RSRQ, RSSNR, CQI, TIMING_ADVANCE);
        expected.setCellIdentity(cil);
        expected.setCellIdentity(cil);
        expected.setCellSignalStrength(css);
        expected.setCellSignalStrength(css);
        expected.setCellConnectionStatus(CellInfo.CONNECTION_NONE);
        expected.setCellConnectionStatus(CellInfo.CONNECTION_NONE);
@@ -1326,7 +1327,7 @@ public class RILTest extends TelephonyTest {
        CellIdentityLte cil = new CellIdentityLte(CI, PCI, TAC, EARFCN, BANDWIDTH, MCC_STR, MNC_STR,
        CellIdentityLte cil = new CellIdentityLte(CI, PCI, TAC, EARFCN, BANDWIDTH, MCC_STR, MNC_STR,
                EMPTY_ALPHA_LONG, EMPTY_ALPHA_SHORT);
                EMPTY_ALPHA_LONG, EMPTY_ALPHA_SHORT);
        CellSignalStrengthLte css = new CellSignalStrengthLte(
        CellSignalStrengthLte css = new CellSignalStrengthLte(
                RSSI, RSRP, RSRQ, RSSNR, CQI, TIME_ADVANCE);
                RSSI, RSRP, RSRQ, RSSNR, CQI, TIMING_ADVANCE);
        expected.setCellIdentity(cil);
        expected.setCellIdentity(cil);
        expected.setCellSignalStrength(css);
        expected.setCellSignalStrength(css);
        expected.setCellConnectionStatus(CellInfo.CONNECTION_NONE);
        expected.setCellConnectionStatus(CellInfo.CONNECTION_NONE);
@@ -1349,7 +1350,7 @@ public class RILTest extends TelephonyTest {
        CellIdentityLte cil = new CellIdentityLte(
        CellIdentityLte cil = new CellIdentityLte(
                CI, PCI, TAC, EARFCN, BANDWIDTH, null, null, ALPHA_LONG, ALPHA_SHORT);
                CI, PCI, TAC, EARFCN, BANDWIDTH, null, null, ALPHA_LONG, ALPHA_SHORT);
        CellSignalStrengthLte css = new CellSignalStrengthLte(
        CellSignalStrengthLte css = new CellSignalStrengthLte(
                RSSI, RSRP, RSRQ, RSSNR, CQI, TIME_ADVANCE);
                RSSI, RSRP, RSRQ, RSSNR, CQI, TIMING_ADVANCE);
        expected.setCellIdentity(cil);
        expected.setCellIdentity(cil);
        expected.setCellSignalStrength(css);
        expected.setCellSignalStrength(css);
        expected.setCellConnectionStatus(CellInfo.CONNECTION_NONE);
        expected.setCellConnectionStatus(CellInfo.CONNECTION_NONE);
@@ -1369,7 +1370,7 @@ public class RILTest extends TelephonyTest {
        CellIdentityGsm ci = new CellIdentityGsm(
        CellIdentityGsm ci = new CellIdentityGsm(
                LAC, CID, ARFCN, BSIC, MCC_STR, MNC_STR, ALPHA_LONG, ALPHA_SHORT);
                LAC, CID, ARFCN, BSIC, MCC_STR, MNC_STR, ALPHA_LONG, ALPHA_SHORT);
        CellSignalStrengthGsm cs = new CellSignalStrengthGsm(
        CellSignalStrengthGsm cs = new CellSignalStrengthGsm(
                RSSI, BIT_ERROR_RATE, TIME_ADVANCE);
                RSSI, BIT_ERROR_RATE, TIMING_ADVANCE);
        expected.setCellIdentity(ci);
        expected.setCellIdentity(ci);
        expected.setCellSignalStrength(cs);
        expected.setCellSignalStrength(cs);
        expected.setCellConnectionStatus(CellInfo.CONNECTION_NONE);
        expected.setCellConnectionStatus(CellInfo.CONNECTION_NONE);
@@ -1390,7 +1391,7 @@ public class RILTest extends TelephonyTest {
        CellIdentityGsm ci = new CellIdentityGsm(
        CellIdentityGsm ci = new CellIdentityGsm(
                LAC, CID, ARFCN, BSIC, MCC_STR, MNC_STR, EMPTY_ALPHA_LONG, EMPTY_ALPHA_SHORT);
                LAC, CID, ARFCN, BSIC, MCC_STR, MNC_STR, EMPTY_ALPHA_LONG, EMPTY_ALPHA_SHORT);
        CellSignalStrengthGsm cs = new CellSignalStrengthGsm(
        CellSignalStrengthGsm cs = new CellSignalStrengthGsm(
                RSSI, BIT_ERROR_RATE, TIME_ADVANCE);
                RSSI, BIT_ERROR_RATE, TIMING_ADVANCE);
        expected.setCellIdentity(ci);
        expected.setCellIdentity(ci);
        expected.setCellSignalStrength(cs);
        expected.setCellSignalStrength(cs);
        expected.setCellConnectionStatus(CellInfo.CONNECTION_NONE);
        expected.setCellConnectionStatus(CellInfo.CONNECTION_NONE);
@@ -1413,7 +1414,7 @@ public class RILTest extends TelephonyTest {
        CellIdentityGsm ci = new CellIdentityGsm(
        CellIdentityGsm ci = new CellIdentityGsm(
                LAC, CID, ARFCN, BSIC, null, null, ALPHA_LONG, ALPHA_SHORT);
                LAC, CID, ARFCN, BSIC, null, null, ALPHA_LONG, ALPHA_SHORT);
        CellSignalStrengthGsm cs = new CellSignalStrengthGsm(
        CellSignalStrengthGsm cs = new CellSignalStrengthGsm(
                RSSI, BIT_ERROR_RATE, TIME_ADVANCE);
                RSSI, BIT_ERROR_RATE, TIMING_ADVANCE);
        expected.setCellIdentity(ci);
        expected.setCellIdentity(ci);
        expected.setCellConnectionStatus(CellInfo.CONNECTION_NONE);
        expected.setCellConnectionStatus(CellInfo.CONNECTION_NONE);
        expected.setCellSignalStrength(cs);
        expected.setCellSignalStrength(cs);
@@ -1603,24 +1604,89 @@ public class RILTest extends TelephonyTest {
        assertEquals("100:foo", request.getWorkSourceClientId());
        assertEquals("100:foo", request.getWorkSourceClientId());
    }
    }


    private ArrayList<CellInfo> getCellInfoListForLTE(
    @Test
            String mcc, String mnc, String alphaLong, String alphaShort) {
    public void testCellInfoTimestamp_1_4() {
        android.hardware.radio.V1_2.CellInfoLte lte = new android.hardware.radio.V1_2.CellInfoLte();
        ArrayList<android.hardware.radio.V1_4.CellInfo> records =
                new ArrayList<android.hardware.radio.V1_4.CellInfo>();

        for (int i = 0; i < 5 /* arbitrary */; i++) {
            android.hardware.radio.V1_4.CellInfo record =
                    new android.hardware.radio.V1_4.CellInfo();
            record.info = new android.hardware.radio.V1_4.CellInfo.Info();
            record.info.lte(new android.hardware.radio.V1_4.CellInfoLte());
            initializeCellInfoLte_1_2(record.info.lte().base);
            record.info.lte().base.cellIdentityLte.base.ci += i; // make them marginally unique

            records.add(record);
        }
        List<CellInfo> cil = RIL.convertHalCellInfoList_1_4(records);

        // Check that all timestamps are set to a valid number and are equal
        final long ts = cil.get(0).getTimeStamp();
        for (CellInfo ci : cil) {
            assertTrue(ci.getTimeStamp() > 0 && ci.getTimeStamp() != Long.MAX_VALUE);
            assertEquals(ci.getTimeStamp(), ts);
        }
    }

    @Test
    public void testCellInfoTimestamp_1_2() {
        ArrayList<android.hardware.radio.V1_2.CellInfo> records =
                new ArrayList<android.hardware.radio.V1_2.CellInfo>();

        for (int i = 0; i < 5 /* arbitrary */; i++) {
            android.hardware.radio.V1_2.CellInfo record =
                    new android.hardware.radio.V1_2.CellInfo();
            record.cellInfoType = TYPE_LTE;
            record.timeStamp = Long.MAX_VALUE;
            record.registered = false;
            record.timeStampType = RIL_TIMESTAMP_TYPE_OEM_RIL;
            record.lte.add(new android.hardware.radio.V1_2.CellInfoLte());
            initializeCellInfoLte_1_2(record.lte.get(0));
            record.lte.get(0).cellIdentityLte.base.ci += i; // make them marginally unique

            records.add(record);
        }
        List<CellInfo> cil = RIL.convertHalCellInfoList_1_2(records);

        // Check that all timestamps are set to a valid number and are equal
        final long ts = cil.get(0).getTimeStamp();
        for (CellInfo ci : cil) {
            assertTrue(ci.getTimeStamp() > 0 && ci.getTimeStamp() != Long.MAX_VALUE);
            assertEquals(ci.getTimeStamp(), ts);
        }
    }

    private static void initializeCellInfoLte_1_2(android.hardware.radio.V1_2.CellInfoLte lte) {
        lte.cellIdentityLte.base.ci = CI;
        lte.cellIdentityLte.base.ci = CI;
        lte.cellIdentityLte.base.pci = PCI;
        lte.cellIdentityLte.base.pci = PCI;
        lte.cellIdentityLte.base.tac = TAC;
        lte.cellIdentityLte.base.tac = TAC;
        lte.cellIdentityLte.base.earfcn = EARFCN;
        lte.cellIdentityLte.base.earfcn = EARFCN;
        lte.cellIdentityLte.bandwidth = BANDWIDTH;
        lte.cellIdentityLte.bandwidth = BANDWIDTH;
        lte.cellIdentityLte.base.mcc = mcc;
        lte.cellIdentityLte.base.mnc = mnc;
        lte.cellIdentityLte.operatorNames.alphaLong = alphaLong;
        lte.cellIdentityLte.operatorNames.alphaShort = alphaShort;
        lte.signalStrengthLte.signalStrength = RSSI_ASU;
        lte.signalStrengthLte.signalStrength = RSSI_ASU;
        lte.signalStrengthLte.rsrp = -RSRP;
        lte.signalStrengthLte.rsrp = -RSRP;
        lte.signalStrengthLte.rsrq = -RSRQ;
        lte.signalStrengthLte.rsrq = -RSRQ;
        lte.signalStrengthLte.rssnr = RSSNR;
        lte.signalStrengthLte.rssnr = RSSNR;
        lte.signalStrengthLte.cqi = CQI;
        lte.signalStrengthLte.cqi = CQI;
        lte.signalStrengthLte.timingAdvance = TIME_ADVANCE;
        lte.signalStrengthLte.timingAdvance = TIMING_ADVANCE;

        lte.cellIdentityLte.operatorNames.alphaLong = ALPHA_LONG;
        lte.cellIdentityLte.operatorNames.alphaShort = ALPHA_SHORT;
        lte.cellIdentityLte.base.mcc = MCC_STR;
        lte.cellIdentityLte.base.mnc = MNC_STR;
    }

    private ArrayList<CellInfo> getCellInfoListForLTE(
            String mcc, String mnc, String alphaLong, String alphaShort) {
        android.hardware.radio.V1_2.CellInfoLte lte = new android.hardware.radio.V1_2.CellInfoLte();

        initializeCellInfoLte_1_2(lte);
        // Override the defaults for test-specific purposes
        lte.cellIdentityLte.operatorNames.alphaLong = alphaLong;
        lte.cellIdentityLte.operatorNames.alphaShort = alphaShort;
        lte.cellIdentityLte.base.mcc = mcc;
        lte.cellIdentityLte.base.mnc = mnc;

        android.hardware.radio.V1_2.CellInfo record = new android.hardware.radio.V1_2.CellInfo();
        android.hardware.radio.V1_2.CellInfo record = new android.hardware.radio.V1_2.CellInfo();
        record.cellInfoType = TYPE_LTE;
        record.cellInfoType = TYPE_LTE;
        record.registered = false;
        record.registered = false;
@@ -1648,7 +1714,7 @@ public class RILTest extends TelephonyTest {
        cellinfo.cellIdentityGsm.operatorNames.alphaShort = alphaShort;
        cellinfo.cellIdentityGsm.operatorNames.alphaShort = alphaShort;
        cellinfo.signalStrengthGsm.signalStrength = RSSI_ASU;
        cellinfo.signalStrengthGsm.signalStrength = RSSI_ASU;
        cellinfo.signalStrengthGsm.bitErrorRate = BIT_ERROR_RATE;
        cellinfo.signalStrengthGsm.bitErrorRate = BIT_ERROR_RATE;
        cellinfo.signalStrengthGsm.timingAdvance = TIME_ADVANCE;
        cellinfo.signalStrengthGsm.timingAdvance = TIMING_ADVANCE;
        android.hardware.radio.V1_2.CellInfo record = new android.hardware.radio.V1_2.CellInfo();
        android.hardware.radio.V1_2.CellInfo record = new android.hardware.radio.V1_2.CellInfo();
        record.cellInfoType = TYPE_GSM;
        record.cellInfoType = TYPE_GSM;
        record.registered = false;
        record.registered = false;