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

Commit 03576022 authored by Mingming Cai's avatar Mingming Cai Committed by Android (Google) Code Review
Browse files

Merge "Use new global cell ID for hasLocationChanged" into rvc-dev

parents d4da586c 69655333
Loading
Loading
Loading
Loading
+2 −6
Original line number Original line Diff line number Diff line
@@ -122,7 +122,6 @@ import java.util.Arrays;
import java.util.HashSet;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.LinkedList;
import java.util.List;
import java.util.List;
import java.util.Objects;
import java.util.Set;
import java.util.Set;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.atomic.AtomicInteger;
@@ -3227,11 +3226,8 @@ public class ServiceStateTracker extends Handler {
                mNewSS.getNetworkRegistrationInfo(
                mNewSS.getNetworkRegistrationInfo(
                        NetworkRegistrationInfo.DOMAIN_PS, AccessNetworkType.EUTRAN));
                        NetworkRegistrationInfo.DOMAIN_PS, AccessNetworkType.EUTRAN));


        // TODO: loosen this restriction to exempt fields that are provided through system
        boolean hasLocationChanged = (mCellIdentity == null ? mNewCellIdentity != null
        // information; otherwise, we will get false positives when things like the operator
                : !mCellIdentity.isSameCell(mNewCellIdentity));
        // alphas are provided later - that's better than missing location changes, but
        // still not ideal.
        boolean hasLocationChanged = !Objects.equals(mNewCellIdentity, mCellIdentity);


        // ratchet the new tech up through its rat family but don't drop back down
        // ratchet the new tech up through its rat family but don't drop back down
        // until cell change or device is OOS
        // until cell change or device is OOS
+5 −0
Original line number Original line Diff line number Diff line
@@ -26,6 +26,7 @@ import android.test.suitebuilder.annotation.SmallTest;
/** Unit tests for {@link CellIdentityCdma}. */
/** Unit tests for {@link CellIdentityCdma}. */


public class CellIdentityCdmaTest extends AndroidTestCase {
public class CellIdentityCdmaTest extends AndroidTestCase {
    private static final String LOG_TAG = "CellIdentityCdmaTest";


    // Network Id ranges from 0 to 65535.
    // Network Id ranges from 0 to 65535.
    private static final int NETWORK_ID  = 65535;
    private static final int NETWORK_ID  = 65535;
@@ -51,6 +52,10 @@ public class CellIdentityCdmaTest extends AndroidTestCase {
        assertEquals(LONGITUDE, ci.getLongitude());
        assertEquals(LONGITUDE, ci.getLongitude());
        assertEquals(ALPHA_LONG, ci.getOperatorAlphaLong());
        assertEquals(ALPHA_LONG, ci.getOperatorAlphaLong());
        assertEquals(ALPHA_SHORT, ci.getOperatorAlphaShort());
        assertEquals(ALPHA_SHORT, ci.getOperatorAlphaShort());

        String globalCi = Integer.toString(SYSTEM_ID, 16) + Integer.toString(NETWORK_ID, 16)
                + Integer.toString(BASESTATION_ID, 16);
        assertEquals(globalCi, ci.getGlobalCellId());
    }
    }


    @SmallTest
    @SmallTest
+44 −0
Original line number Original line Diff line number Diff line
@@ -25,6 +25,7 @@ import java.util.Collections;


/** Unit tests for {@link CellIdentityGsm}. */
/** Unit tests for {@link CellIdentityGsm}. */
public class CellIdentityGsmTest extends AndroidTestCase {
public class CellIdentityGsmTest extends AndroidTestCase {
    private static final String LOG_TAG = "CellIdentityGsmTest";


    // Location Area Code ranges from 0 to 65535.
    // Location Area Code ranges from 0 to 65535.
    private static final int LAC = 65535;
    private static final int LAC = 65535;
@@ -60,6 +61,10 @@ public class CellIdentityGsmTest extends AndroidTestCase {
        assertEquals(MCC_STR + MNC_STR, ci.getMobileNetworkOperator());
        assertEquals(MCC_STR + MNC_STR, ci.getMobileNetworkOperator());
        assertEquals(ALPHA_LONG, ci.getOperatorAlphaLong());
        assertEquals(ALPHA_LONG, ci.getOperatorAlphaLong());
        assertEquals(ALPHA_SHORT, ci.getOperatorAlphaShort());
        assertEquals(ALPHA_SHORT, ci.getOperatorAlphaShort());

        String globalCi = MCC_STR + MNC_STR + Integer.toString(LAC, 16)
                + Integer.toString(CID, 16);
        assertTrue(globalCi.equals(ci.getGlobalCellId()));
    }
    }


    @SmallTest
    @SmallTest
@@ -74,6 +79,10 @@ public class CellIdentityGsmTest extends AndroidTestCase {
        assertEquals(MCC_STR, ci.getMccString());
        assertEquals(MCC_STR, ci.getMccString());
        assertEquals(mncWithThreeDigit, ci.getMncString());
        assertEquals(mncWithThreeDigit, ci.getMncString());
        assertEquals(MCC_STR + mncWithThreeDigit, ci.getMobileNetworkOperator());
        assertEquals(MCC_STR + mncWithThreeDigit, ci.getMobileNetworkOperator());

        String globalCi = MCC_STR + mncWithThreeDigit + Integer.toString(LAC, 16)
                + Integer.toString(CID, 16);
        assertEquals(globalCi, ci.getGlobalCellId());
    }
    }


    @SmallTest
    @SmallTest
@@ -88,6 +97,10 @@ public class CellIdentityGsmTest extends AndroidTestCase {
        assertEquals(MCC_STR, ci.getMccString());
        assertEquals(MCC_STR, ci.getMccString());
        assertEquals(mncWithTwoDigit, ci.getMncString());
        assertEquals(mncWithTwoDigit, ci.getMncString());
        assertEquals(MCC_STR + mncWithTwoDigit, ci.getMobileNetworkOperator());
        assertEquals(MCC_STR + mncWithTwoDigit, ci.getMobileNetworkOperator());

        String globalCi = MCC_STR + mncWithTwoDigit + Integer.toString(LAC, 16)
                + Integer.toString(CID, 16);
        assertEquals(globalCi, ci.getGlobalCellId());
    }
    }


    @SmallTest
    @SmallTest
@@ -101,6 +114,7 @@ public class CellIdentityGsmTest extends AndroidTestCase {
        assertNull(ci.getMccString());
        assertNull(ci.getMccString());
        assertNull(ci.getMncString());
        assertNull(ci.getMncString());
        assertNull(ci.getMobileNetworkOperator());
        assertNull(ci.getMobileNetworkOperator());
        assertNull(ci.getGlobalCellId());


        ci = new CellIdentityGsm(LAC, CID, ARFCN, BSIC, MCC_STR, null, ALPHA_LONG, ALPHA_SHORT,
        ci = new CellIdentityGsm(LAC, CID, ARFCN, BSIC, MCC_STR, null, ALPHA_LONG, ALPHA_SHORT,
                Collections.emptyList());
                Collections.emptyList());
@@ -110,6 +124,7 @@ public class CellIdentityGsmTest extends AndroidTestCase {
        assertEquals(MCC_STR, ci.getMccString());
        assertEquals(MCC_STR, ci.getMccString());
        assertNull(ci.getMncString());
        assertNull(ci.getMncString());
        assertNull(ci.getMobileNetworkOperator());
        assertNull(ci.getMobileNetworkOperator());
        assertNull(ci.getGlobalCellId());


        ci = new CellIdentityGsm(LAC, CID, ARFCN, BSIC, null, MNC_STR, ALPHA_LONG, ALPHA_SHORT,
        ci = new CellIdentityGsm(LAC, CID, ARFCN, BSIC, null, MNC_STR, ALPHA_LONG, ALPHA_SHORT,
                Collections.emptyList());
                Collections.emptyList());
@@ -119,6 +134,7 @@ public class CellIdentityGsmTest extends AndroidTestCase {
        assertEquals(MNC_STR, ci.getMncString());
        assertEquals(MNC_STR, ci.getMncString());
        assertNull(ci.getMccString());
        assertNull(ci.getMccString());
        assertNull(ci.getMobileNetworkOperator());
        assertNull(ci.getMobileNetworkOperator());
        assertNull(ci.getGlobalCellId());


        ci = new CellIdentityGsm(LAC, CID, ARFCN, BSIC, "", "", ALPHA_LONG, ALPHA_SHORT,
        ci = new CellIdentityGsm(LAC, CID, ARFCN, BSIC, "", "", ALPHA_LONG, ALPHA_SHORT,
                Collections.emptyList());
                Collections.emptyList());
@@ -128,6 +144,7 @@ public class CellIdentityGsmTest extends AndroidTestCase {
        assertNull(ci.getMccString());
        assertNull(ci.getMccString());
        assertNull(ci.getMncString());
        assertNull(ci.getMncString());
        assertNull(ci.getMobileNetworkOperator());
        assertNull(ci.getMobileNetworkOperator());
        assertNull(ci.getGlobalCellId());
    }
    }


    @SmallTest
    @SmallTest
@@ -200,4 +217,31 @@ public class CellIdentityGsmTest extends AndroidTestCase {
        CellIdentityGsm newCi = CellIdentityGsm.CREATOR.createFromParcel(p);
        CellIdentityGsm newCi = CellIdentityGsm.CREATOR.createFromParcel(p);
        assertEquals(ci, newCi);
        assertEquals(ci, newCi);
    }
    }

    @SmallTest
    public void testgetGlobalCellId() {
        CellIdentityGsm ci = new CellIdentityGsm(
                LAC + 1, CID, ARFCN, BSIC, MCC_STR, MNC_STR, ALPHA_LONG, ALPHA_SHORT,
                Collections.emptyList());
        assertNull(ci.getGlobalCellId());

        ci = new CellIdentityGsm(
                LAC, CID + 1, ARFCN, BSIC, MCC_STR, MNC_STR, ALPHA_LONG, ALPHA_SHORT,
                Collections.emptyList());
        assertNull(ci.getGlobalCellId());

        ci = new CellIdentityGsm(
                LAC, -1, ARFCN, BSIC, MCC_STR, MNC_STR, ALPHA_LONG, ALPHA_SHORT,
                Collections.emptyList());
        assertNull(ci.getGlobalCellId());

        // Test id with one digit and corresponding zero padding
        int cid = 1;
        ci = new CellIdentityGsm(
                LAC, cid, ARFCN, BSIC, MCC_STR, MNC_STR, ALPHA_LONG, ALPHA_SHORT,
                Collections.emptyList());
        String globalCi = MCC_STR + MNC_STR + Integer.toString(LAC, 16)
                + "000" + Integer.toString(cid, 16);
        assertEquals(globalCi, ci.getGlobalCellId());
    }
}
}
+4 −0
Original line number Original line Diff line number Diff line
@@ -27,6 +27,7 @@ import java.util.Collections;
/** Unit tests for {@link CellIdentityLte}. */
/** Unit tests for {@link CellIdentityLte}. */


public class CellIdentityLteTest extends AndroidTestCase {
public class CellIdentityLteTest extends AndroidTestCase {
    private static final String LOG_TAG = "CellIdentityLteTest";


    // Cell identity ranges from 0 to 268435455.
    // Cell identity ranges from 0 to 268435455.
    private static final int CI = 268435455;
    private static final int CI = 268435455;
@@ -64,6 +65,9 @@ public class CellIdentityLteTest extends AndroidTestCase {
        assertEquals(MCC_STR + MNC_STR, ci.getMobileNetworkOperator());
        assertEquals(MCC_STR + MNC_STR, ci.getMobileNetworkOperator());
        assertEquals(ALPHA_LONG, ci.getOperatorAlphaLong());
        assertEquals(ALPHA_LONG, ci.getOperatorAlphaLong());
        assertEquals(ALPHA_SHORT, ci.getOperatorAlphaShort());
        assertEquals(ALPHA_SHORT, ci.getOperatorAlphaShort());

        String globalCi = MCC_STR + MNC_STR + Integer.toString(CI, 16);
        assertEquals(globalCi, ci.getGlobalCellId());
    }
    }


    @SmallTest
    @SmallTest
+18 −15
Original line number Original line Diff line number Diff line
@@ -30,10 +30,11 @@ import java.util.Arrays;
import java.util.Collections;
import java.util.Collections;


public class CellIdentityNrTest extends AndroidTestCase {
public class CellIdentityNrTest extends AndroidTestCase {
    private static final String MCC = "310";
    private static final String LOG_TAG = "CellIdentityNrTest";
    private static final String MNC = "260";
    private static final String MCC_STR = "310";
    private static final String ANOTHER_MCC = "134";
    private static final String MNC_STR = "260";
    private static final String ANOTHER_MNC = "256";
    private static final String ANOTHER_MCC_STR = "134";
    private static final String ANOTHER_MNC_STR = "256";
    private static final String ALPHAL = "long operator name";
    private static final String ALPHAL = "long operator name";
    private static final String ALPHAS = "lon";
    private static final String ALPHAS = "lon";
    private static final int NRARFCN = 13456;
    private static final int NRARFCN = 13456;
@@ -49,7 +50,7 @@ public class CellIdentityNrTest extends AndroidTestCase {
    public void testGetMethod() {
    public void testGetMethod() {
        // GIVEN an instance of CellIdentityNr
        // GIVEN an instance of CellIdentityNr
        CellIdentityNr cellIdentityNr =
        CellIdentityNr cellIdentityNr =
                new CellIdentityNr(PCI, TAC, NRARFCN, BANDS, MCC, MNC, NCI, ALPHAL, ALPHAS,
                new CellIdentityNr(PCI, TAC, NRARFCN, BANDS, MCC_STR, MNC_STR, NCI, ALPHAL, ALPHAS,
                        Collections.emptyList());
                        Collections.emptyList());


        // THEN the get method should return correct value
        // THEN the get method should return correct value
@@ -59,20 +60,22 @@ public class CellIdentityNrTest extends AndroidTestCase {
        assertThat(cellIdentityNr.getTac()).isEqualTo(TAC);
        assertThat(cellIdentityNr.getTac()).isEqualTo(TAC);
        assertThat(cellIdentityNr.getOperatorAlphaLong()).isEqualTo(ALPHAL);
        assertThat(cellIdentityNr.getOperatorAlphaLong()).isEqualTo(ALPHAL);
        assertThat(cellIdentityNr.getOperatorAlphaShort()).isEqualTo(ALPHAS);
        assertThat(cellIdentityNr.getOperatorAlphaShort()).isEqualTo(ALPHAS);
        assertThat(cellIdentityNr.getMccString()).isEqualTo(MCC);
        assertThat(cellIdentityNr.getMccString()).isEqualTo(MCC_STR);
        assertThat(cellIdentityNr.getMncString()).isEqualTo(MNC);
        assertThat(cellIdentityNr.getMncString()).isEqualTo(MNC_STR);
        assertThat(cellIdentityNr.getMncString()).isEqualTo(MNC);
        assertThat(cellIdentityNr.getNci()).isEqualTo(NCI);
        assertThat(cellIdentityNr.getNci()).isEqualTo(NCI);

        String globalCi = MCC_STR + MNC_STR + "000" + Integer.toString(NCI, 16);
        assertEquals(globalCi, cellIdentityNr.getGlobalCellId());
    }
    }


    @Test
    @Test
    public void testEquals_sameParameters() {
    public void testEquals_sameParameters() {
        // GIVEN an instance of CellIdentityNr, and create another object with the same parameters
        // GIVEN an instance of CellIdentityNr, and create another object with the same parameters
        CellIdentityNr cellIdentityNr =
        CellIdentityNr cellIdentityNr =
                new CellIdentityNr(PCI, TAC, NRARFCN, BANDS, MCC, MNC, NCI,
                new CellIdentityNr(PCI, TAC, NRARFCN, BANDS, MCC_STR, MNC_STR, NCI,
                        ALPHAL, ALPHAS, Collections.emptyList());
                        ALPHAL, ALPHAS, Collections.emptyList());
        CellIdentityNr anotherCellIdentityNr =
        CellIdentityNr anotherCellIdentityNr =
                new CellIdentityNr(PCI, TAC, NRARFCN, BANDS, MCC, MNC, NCI,
                new CellIdentityNr(PCI, TAC, NRARFCN, BANDS, MCC_STR, MNC_STR, NCI,
                        ALPHAL, ALPHAS, Collections.emptyList());
                        ALPHAL, ALPHAS, Collections.emptyList());


        // THEN this two objects are equivalent
        // THEN this two objects are equivalent
@@ -83,10 +86,10 @@ public class CellIdentityNrTest extends AndroidTestCase {
    public void testEquals_differentParameters() {
    public void testEquals_differentParameters() {
        // GIVEN an instance of CellIdentityNr, and create another object with different parameters
        // GIVEN an instance of CellIdentityNr, and create another object with different parameters
        CellIdentityNr cellIdentityNr =
        CellIdentityNr cellIdentityNr =
                new CellIdentityNr(PCI, TAC, NRARFCN, BANDS, MCC, MNC, NCI,
                new CellIdentityNr(PCI, TAC, NRARFCN, BANDS, MCC_STR, MNC_STR, NCI,
                        ALPHAL, ALPHAS, Collections.emptyList());
                        ALPHAL, ALPHAS, Collections.emptyList());
        CellIdentityNr anotherCellIdentityNr =
        CellIdentityNr anotherCellIdentityNr =
                new CellIdentityNr(PCI, TAC, NRARFCN, BANDS, MCC, MNC, NCI + 1,
                new CellIdentityNr(PCI, TAC, NRARFCN, BANDS, MCC_STR, MNC_STR, NCI + 1,
                        ALPHAL, ALPHAS, Collections.emptyList());
                        ALPHAL, ALPHAS, Collections.emptyList());


        // THEN this two objects are different
        // THEN this two objects are different
@@ -97,7 +100,7 @@ public class CellIdentityNrTest extends AndroidTestCase {
    public void testParcel() {
    public void testParcel() {
        // GIVEN an instance of CellIdentityNr
        // GIVEN an instance of CellIdentityNr
        CellIdentityNr cellIdentityNr =
        CellIdentityNr cellIdentityNr =
                new CellIdentityNr(PCI, TAC, NRARFCN, BANDS, MCC, MNC, NCI,
                new CellIdentityNr(PCI, TAC, NRARFCN, BANDS, MCC_STR, MNC_STR, NCI,
                        ALPHAL, ALPHAS, Collections.emptyList());
                        ALPHAL, ALPHAS, Collections.emptyList());


        // WHEN write the object to parcel and create another object with that parcel
        // WHEN write the object to parcel and create another object with that parcel
@@ -115,8 +118,8 @@ public class CellIdentityNrTest extends AndroidTestCase {
        assertTrue(Arrays.equals(anotherCellIdentityNr.getBands(), BANDS));
        assertTrue(Arrays.equals(anotherCellIdentityNr.getBands(), BANDS));
        assertThat(anotherCellIdentityNr.getOperatorAlphaLong()).isEqualTo(ALPHAL);
        assertThat(anotherCellIdentityNr.getOperatorAlphaLong()).isEqualTo(ALPHAL);
        assertThat(anotherCellIdentityNr.getOperatorAlphaShort()).isEqualTo(ALPHAS);
        assertThat(anotherCellIdentityNr.getOperatorAlphaShort()).isEqualTo(ALPHAS);
        assertThat(anotherCellIdentityNr.getMccString()).isEqualTo(MCC);
        assertThat(anotherCellIdentityNr.getMccString()).isEqualTo(MCC_STR);
        assertThat(anotherCellIdentityNr.getMncString()).isEqualTo(MNC);
        assertThat(anotherCellIdentityNr.getMncString()).isEqualTo(MNC_STR);
        assertThat(anotherCellIdentityNr.getNci()).isEqualTo(NCI);
        assertThat(anotherCellIdentityNr.getNci()).isEqualTo(NCI);
    }
    }
}
}
Loading