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

Commit 60d720f2 authored by Jack Yu's avatar Jack Yu Committed by Gerrit Code Review
Browse files

Merge "Added Cell identity for TD-SCDMA and a base class CellIdentity"

parents 4c5c4510 7aa0254d
Loading
Loading
Loading
Loading
+13 −6
Original line number Diff line number Diff line
@@ -68,6 +68,7 @@ import android.os.SystemProperties;
import android.os.WorkSource;
import android.service.carrier.CarrierIdentifier;
import android.telephony.AccessNetworkConstants.AccessNetworkType;
import android.telephony.CellIdentity;
import android.telephony.CellInfo;
import android.telephony.ClientRequestStats;
import android.telephony.ImsiEncryptionInfo;
@@ -5007,12 +5008,13 @@ public class RIL extends BaseCommands implements CommandsInterface {
    private static void writeToParcelForGsm(
            Parcel p, int lac, int cid, int arfcn, int bsic, String mcc, String mnc,
            String al, String as, int ss, int ber, int ta) {
        p.writeInt(CellIdentity.TYPE_GSM);
        p.writeString(mcc);
        p.writeString(mnc);
        p.writeInt(lac);
        p.writeInt(cid);
        p.writeInt(arfcn);
        p.writeInt(bsic);
        p.writeString(mcc);
        p.writeString(mnc);
        p.writeString(al);
        p.writeString(as);
        p.writeInt(ss);
@@ -5023,6 +5025,9 @@ public class RIL extends BaseCommands implements CommandsInterface {
    private static void writeToParcelForCdma(
            Parcel p, int ni, int si, int bsi, int lon, int lat, String al, String as,
            int dbm, int ecio, int eDbm, int eEcio, int eSnr) {
        p.writeInt(CellIdentity.TYPE_CDMA);
        p.writeString(null);
        p.writeString(null);
        p.writeInt(ni);
        p.writeInt(si);
        p.writeInt(bsi);
@@ -5040,12 +5045,13 @@ public class RIL extends BaseCommands implements CommandsInterface {
    private static void writeToParcelForLte(
            Parcel p, int ci, int pci, int tac, int earfcn, String mcc, String mnc, String al,
            String as, int ss, int rsrp, int rsrq, int rssnr, int cqi, int ta) {
        p.writeInt(CellIdentity.TYPE_LTE);
        p.writeString(mcc);
        p.writeString(mnc);
        p.writeInt(ci);
        p.writeInt(pci);
        p.writeInt(tac);
        p.writeInt(earfcn);
        p.writeString(mcc);
        p.writeString(mnc);
        p.writeString(al);
        p.writeString(as);
        p.writeInt(ss);
@@ -5059,12 +5065,13 @@ public class RIL extends BaseCommands implements CommandsInterface {
    private static void writeToParcelForWcdma(
            Parcel p, int lac, int cid, int psc, int uarfcn, String mcc, String mnc,
            String al, String as, int ss, int ber) {
        p.writeInt(CellIdentity.TYPE_WCDMA);
        p.writeString(mcc);
        p.writeString(mnc);
        p.writeInt(lac);
        p.writeInt(cid);
        p.writeInt(psc);
        p.writeInt(uarfcn);
        p.writeString(mcc);
        p.writeString(mnc);
        p.writeString(al);
        p.writeString(as);
        p.writeInt(ss);
+7 −8
Original line number Diff line number Diff line
@@ -16,11 +16,8 @@

package com.android.internal.telephony;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;

import android.os.Parcel;
import android.telephony.CellIdentity;
import android.telephony.CellIdentityGsm;
import android.test.AndroidTestCase;
import android.test.suitebuilder.annotation.SmallTest;
@@ -186,12 +183,13 @@ public class CellIdentityGsmTest extends AndroidTestCase {
        CellIdentityGsm ci = new CellIdentityGsm(LAC, CID, ARFCN, BSIC, null, null, null, null);

        Parcel p = Parcel.obtain();
        p.writeInt(CellIdentityGsm.TYPE_GSM);
        p.writeString(String.valueOf(Integer.MAX_VALUE));
        p.writeString(String.valueOf(Integer.MAX_VALUE));
        p.writeInt(LAC);
        p.writeInt(CID);
        p.writeInt(ARFCN);
        p.writeInt(BSIC);
        p.writeString(String.valueOf(Integer.MAX_VALUE));
        p.writeString(String.valueOf(Integer.MAX_VALUE));
        p.setDataPosition(0);

        CellIdentityGsm newCi = CellIdentityGsm.CREATOR.createFromParcel(p);
@@ -205,12 +203,13 @@ public class CellIdentityGsmTest extends AndroidTestCase {
        CellIdentityGsm ci = new CellIdentityGsm(LAC, CID, ARFCN, BSIC, null, null, null, null);

        Parcel p = Parcel.obtain();
        p.writeInt(CellIdentity.TYPE_GSM);
        p.writeString(invalidMcc);
        p.writeString(invalidMnc);
        p.writeInt(LAC);
        p.writeInt(CID);
        p.writeInt(ARFCN);
        p.writeInt(BSIC);
        p.writeString(invalidMcc);
        p.writeString(invalidMnc);
        p.setDataPosition(0);

        CellIdentityGsm newCi = CellIdentityGsm.CREATOR.createFromParcel(p);
+7 −6
Original line number Diff line number Diff line
@@ -16,9 +16,8 @@

package com.android.internal.telephony;

import static org.junit.Assert.assertEquals;

import android.os.Parcel;
import android.telephony.CellIdentity;
import android.telephony.CellIdentityLte;
import android.test.AndroidTestCase;
import android.test.suitebuilder.annotation.SmallTest;
@@ -182,12 +181,13 @@ public class CellIdentityLteTest extends AndroidTestCase {
        CellIdentityLte ci = new CellIdentityLte(CI, PCI, TAC, EARFCN, null, null, null, null);

        Parcel p = Parcel.obtain();
        p.writeInt(CellIdentity.TYPE_LTE);
        p.writeString(String.valueOf(Integer.MAX_VALUE));
        p.writeString(String.valueOf(Integer.MAX_VALUE));
        p.writeInt(CI);
        p.writeInt(PCI);
        p.writeInt(TAC);
        p.writeInt(EARFCN);
        p.writeString(String.valueOf(Integer.MAX_VALUE));
        p.writeString(String.valueOf(Integer.MAX_VALUE));
        p.setDataPosition(0);

        CellIdentityLte newCi = CellIdentityLte.CREATOR.createFromParcel(p);
@@ -201,12 +201,13 @@ public class CellIdentityLteTest extends AndroidTestCase {
        CellIdentityLte ci = new CellIdentityLte(CI, PCI, TAC, EARFCN, null, null, null, null);

        Parcel p = Parcel.obtain();
        p.writeInt(CellIdentity.TYPE_LTE);
        p.writeString(invalidMcc);
        p.writeString(invalidMnc);
        p.writeInt(CI);
        p.writeInt(PCI);
        p.writeInt(TAC);
        p.writeInt(EARFCN);
        p.writeString(invalidMcc);
        p.writeString(invalidMnc);
        p.setDataPosition(0);

        CellIdentityLte newCi = CellIdentityLte.CREATOR.createFromParcel(p);
+134 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2017 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.android.internal.telephony;

import android.os.Parcel;
import android.telephony.CellIdentity;
import android.telephony.CellIdentityTdscdma;
import android.test.AndroidTestCase;
import android.test.suitebuilder.annotation.SmallTest;

/** Unit tests for {@link CellIdentityTdscdma}. */

public class CellIdentityTdscdmaTest extends AndroidTestCase {

    // Cell identity ranges from 0 to 268435456.
    private static final int CI = 268435456;
    // Physical cell id ranges from 0 to 503.
    private static final int PCI = 503;
    // Tracking area code ranges from 0 to 65535.
    private static final int TAC = 65535;
    // Absolute RF Channel Number ranges from 0 to 262140.
    private static final int EARFCN = 262140;
    private static final int MCC = 120;
    private static final int MNC = 260;
    private static final String MCC_STR = "120";
    private static final String MNC_STR = "260";
    private static final String ALPHA_LONG = "long";
    private static final String ALPHA_SHORT = "short";

    // Location Area Code ranges from 0 to 65535.
    private static final int LAC = 65535;
    // UMTS Cell Identity ranges from 0 to 268435455.
    private static final int CID = 268435455;

    private static final int CPID = 12345;


    @SmallTest
    public void testDefaultConstructor() {
        CellIdentityTdscdma ci =
                new CellIdentityTdscdma(MCC_STR, MNC_STR, LAC, CID, CPID);

        assertEquals(MCC_STR, ci.getMccStr());
        assertEquals(MNC_STR, ci.getMncStr());
        assertEquals(LAC, ci.getLac());
        assertEquals(CID, ci.getCid());
        assertEquals(CPID, ci.getCpid());
    }

    @SmallTest
    public void testConstructorWithEmptyMccMnc() {
        CellIdentityTdscdma ci = new CellIdentityTdscdma(null, null, LAC, CID, CPID);

        assertNull(ci.getMccStr());
        assertNull(ci.getMncStr());

        ci = new CellIdentityTdscdma(MCC_STR, null, LAC, CID, CPID);

        assertEquals(MCC_STR, ci.getMccStr());
        assertNull(ci.getMncStr());

        ci = new CellIdentityTdscdma(null, MNC_STR, LAC, CID, CPID);

        assertEquals(MNC_STR, ci.getMncStr());
        assertNull(ci.getMccStr());

        ci = new CellIdentityTdscdma("", "", LAC, CID, CPID);

        assertNull(ci.getMccStr());
        assertNull(ci.getMncStr());
    }

    @SmallTest
    public void testParcel() {
        CellIdentityTdscdma ci = new CellIdentityTdscdma(MCC_STR, MNC_STR, LAC, CID, CPID);

        Parcel p = Parcel.obtain();
        ci.writeToParcel(p, 0);
        p.setDataPosition(0);

        CellIdentityTdscdma newCi = CellIdentityTdscdma.CREATOR.createFromParcel(p);
        assertEquals(ci, newCi);
    }

    @SmallTest
    public void testParcelWithUnknowMccMnc() {
        CellIdentityTdscdma ci = new CellIdentityTdscdma(null, null, LAC, CID, CPID);

        Parcel p = Parcel.obtain();
        p.writeInt(CellIdentity.TYPE_TDSCDMA);
        p.writeString(String.valueOf(Integer.MAX_VALUE));
        p.writeString(String.valueOf(Integer.MAX_VALUE));
        p.writeInt(LAC);
        p.writeInt(CID);
        p.writeInt(CPID);
        p.setDataPosition(0);

        CellIdentityTdscdma newCi = CellIdentityTdscdma.CREATOR.createFromParcel(p);
        assertEquals(ci, newCi);
    }

    @SmallTest
    public void testParcelWithInvalidMccMnc() {
        final String invalidMcc = "randomStuff";
        final String invalidMnc = "randomStuff";
        CellIdentityTdscdma ci = new CellIdentityTdscdma(null, null, LAC, CID, CPID);

        Parcel p = Parcel.obtain();
        p.writeInt(CellIdentity.TYPE_TDSCDMA);
        p.writeString(invalidMcc);
        p.writeString(invalidMnc);
        p.writeInt(LAC);
        p.writeInt(CID);
        p.writeInt(CPID);
        p.setDataPosition(0);

        CellIdentityTdscdma newCi = CellIdentityTdscdma.CREATOR.createFromParcel(p);
        assertEquals(ci, newCi);
    }
}
+96 −0
Original line number Diff line number Diff line
/*
 * Copyright 2017 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.android.internal.telephony;

import android.os.Parcel;
import android.telephony.CellIdentity;
import android.telephony.CellIdentityCdma;
import android.telephony.CellIdentityLte;
import android.test.AndroidTestCase;
import android.test.suitebuilder.annotation.SmallTest;

public class CellIdentityTest extends AndroidTestCase {

    // Cell identity ranges from 0 to 268435456.
    private static final int CI = 268435456;
    // Physical cell id ranges from 0 to 503.
    private static final int PCI = 503;
    // Tracking area code ranges from 0 to 65535.
    private static final int TAC = 65535;
    // Absolute RF Channel Number ranges from 0 to 262140.
    private static final int EARFCN = 262140;
    private static final int MCC = 120;
    private static final int MNC = 260;
    private static final String MCC_STR = "120";
    private static final String MNC_STR = "260";
    private static final String ALPHA_LONG = "long";
    private static final String ALPHA_SHORT = "short";

    // Network Id ranges from 0 to 65535.
    private static final int NETWORK_ID  = 65535;
    // CDMA System Id ranges from 0 to 32767
    private static final int SYSTEM_ID = 32767;
    // Base Station Id ranges from 0 to 65535
    private static final int BASESTATION_ID = 65535;
    // Longitude ranges from -2592000 to 2592000.
    private static final int LONGITUDE = 2592000;
    // Latitude ranges from -1296000 to 1296000.
    private static final int LATITUDE = 1296000;

    @SmallTest
    public void testEquals() {
        CellIdentity ciA = new CellIdentityLte(
                CI, PCI, TAC, EARFCN, MCC_STR, MNC_STR, ALPHA_LONG, ALPHA_SHORT);
        CellIdentity ciB = new CellIdentityLte(
                CI, PCI, TAC, EARFCN, MCC_STR, MNC_STR, ALPHA_LONG, ALPHA_SHORT);

        assertTrue(ciA.equals(ciB));

        ciA = new CellIdentityLte(CI, PCI, TAC, EARFCN, null, null, ALPHA_LONG, ALPHA_SHORT);
        ciB = new CellIdentityLte(CI, PCI, TAC, EARFCN, null, null, ALPHA_LONG, ALPHA_SHORT);

        assertTrue(ciA.equals(ciB));

        ciA = new CellIdentityLte(CI, PCI, TAC, EARFCN, MCC_STR, null, ALPHA_LONG, ALPHA_SHORT);
        ciB = new CellIdentityLte(CI, PCI, TAC, EARFCN, null, null, ALPHA_LONG, ALPHA_SHORT);

        assertFalse(ciA.equals(ciB));
    }

    @SmallTest
    public void testParcel() {
        CellIdentity ci = new CellIdentityLte(CI, PCI, TAC, EARFCN, MCC_STR, MNC_STR, ALPHA_LONG,
                ALPHA_SHORT);

        Parcel p = Parcel.obtain();
        ci.writeToParcel(p, 0);
        p.setDataPosition(0);

        CellIdentity newCi = CellIdentity.CREATOR.createFromParcel(p);
        assertEquals(ci, newCi);

        ci = new CellIdentityCdma(NETWORK_ID, SYSTEM_ID, BASESTATION_ID, LONGITUDE, LATITUDE,
                        ALPHA_LONG, ALPHA_SHORT);

        p = Parcel.obtain();
        ci.writeToParcel(p, 0);
        p.setDataPosition(0);

        newCi = CellIdentity.CREATOR.createFromParcel(p);
        assertEquals(ci, newCi);
    }
}
Loading