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

Commit 14a85344 authored by Treehugger Robot's avatar Treehugger Robot Committed by Gerrit Code Review
Browse files

Merge "Support CellInfoNr in LocaleTracker."

parents 2f888740 4be7bcce
Loading
Loading
Loading
Loading
+3 −32
Original line number Diff line number Diff line
@@ -32,9 +32,6 @@ import android.os.Looper;
import android.os.Message;
import android.sysprop.TelephonyProperties;
import android.telephony.CellInfo;
import android.telephony.CellInfoGsm;
import android.telephony.CellInfoLte;
import android.telephony.CellInfoWcdma;
import android.telephony.ServiceState;
import android.telephony.SubscriptionManager;
import android.telephony.TelephonyManager;
@@ -295,7 +292,7 @@ public class LocaleTracker extends Handler {
            Map<String, Integer> mccMap = new HashMap<>();
            int maxCount = 0;
            for (CellInfo cellInfo : mCellInfoList) {
                String mcc = getNetworkMcc(cellInfo);
                String mcc = cellInfo.getCellIdentity().getMccString();
                if (mcc != null) {
                    int count = 1;
                    if (mccMap.containsKey(mcc)) {
@@ -330,9 +327,9 @@ public class LocaleTracker extends Handler {
            Map<MccMnc, Integer> mccMncMap = new HashMap<>();
            int maxCount = 0;
            for (CellInfo cellInfo : mCellInfoList) {
                String mcc = getNetworkMcc(cellInfo);
                String mcc = cellInfo.getCellIdentity().getMccString();
                if (Objects.equals(mcc, mccToMatch)) {
                    String mnc = getNetworkMnc(cellInfo);
                    String mnc = cellInfo.getCellIdentity().getMncString();
                    MccMnc mccMnc = new MccMnc(mcc, mnc);
                    int count = 1;
                    if (mccMncMap.containsKey(mccMnc)) {
@@ -352,32 +349,6 @@ public class LocaleTracker extends Handler {
        return selectedMccMnc;
    }

    @Nullable
    private static String getNetworkMcc(CellInfo cellInfo) {
        String mccString = null;
        if (cellInfo instanceof CellInfoGsm) {
            mccString = ((CellInfoGsm) cellInfo).getCellIdentity().getMccString();
        } else if (cellInfo instanceof CellInfoLte) {
            mccString = ((CellInfoLte) cellInfo).getCellIdentity().getMccString();
        } else if (cellInfo instanceof CellInfoWcdma) {
            mccString = ((CellInfoWcdma) cellInfo).getCellIdentity().getMccString();
        }
        return mccString;
    }

    @Nullable
    private static String getNetworkMnc(CellInfo cellInfo) {
        String mccString = null;
        if (cellInfo instanceof CellInfoGsm) {
            mccString = ((CellInfoGsm) cellInfo).getCellIdentity().getMncString();
        } else if (cellInfo instanceof CellInfoLte) {
            mccString = ((CellInfoLte) cellInfo).getCellIdentity().getMncString();
        } else if (cellInfo instanceof CellInfoWcdma) {
            mccString = ((CellInfoWcdma) cellInfo).getCellIdentity().getMncString();
        }
        return mccString;
    }

    /**
     * Called when SIM card state changed. Only when we absolutely know the SIM is absent, we get
     * cell info from the network. Other SIM states like NOT_READY might be just a transitioning
+49 −0
Original line number Diff line number Diff line
@@ -22,11 +22,15 @@ 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.test.AndroidTestCase;
import android.test.suitebuilder.annotation.SmallTest;

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

public class CellIdentityTest extends AndroidTestCase {

@@ -46,6 +50,9 @@ public class CellIdentityTest extends AndroidTestCase {
    private static final String MNC_STR = "260";
    private static final String ALPHA_LONG = "long";
    private static final String ALPHA_SHORT = "short";
    private static final int CPID = 127;
    private static final int UARFCN = 16383;
    private static final int PSC = 511;

    // Network Id ranges from 0 to 65535.
    private static final int NETWORK_ID  = 65535;
@@ -183,4 +190,46 @@ public class CellIdentityTest extends AndroidTestCase {
                ALPHA_SHORT, Collections.emptyList());
        assertFalse(ciA.isSameCell(cellIdentityNr));
    }

    @SmallTest
    public void testGetMccMncString() {
        List<CellIdentity> identities = new ArrayList<>(5);

        CellIdentityGsm gsm = new CellIdentityGsm(MAX_LAC, MAX_CID, MAX_ARFCN, MAX_BSIC,
                MCC_STR, MNC_STR, null, null, Collections.emptyList());
        identities.add(gsm);

        CellIdentityCdma cdma = new CellIdentityCdma(NETWORK_ID, SYSTEM_ID, BASESTATION_ID,
                LONGITUDE, LATITUDE, ALPHA_LONG, ALPHA_SHORT);
        identities.add(cdma);

        CellIdentity lte = new CellIdentityLte(
                CI, PCI, TAC, EARFCN, BANDS, BANDWIDTH, MCC_STR, MNC_STR, ALPHA_LONG, ALPHA_SHORT,
                Collections.emptyList(), null);
        identities.add(lte);

        CellIdentityWcdma wcdma  = new CellIdentityWcdma(MAX_LAC, MAX_CID, PSC, UARFCN, MCC_STR,
                MNC_STR, ALPHA_LONG, ALPHA_SHORT, Collections.emptyList(), null);
        identities.add(wcdma);

        CellIdentityTdscdma tdscdma = new CellIdentityTdscdma(MCC_STR, MNC_STR, MAX_LAC, MAX_CID,
                CPID, UARFCN, ALPHA_LONG, ALPHA_SHORT, Collections.emptyList(), null);
        identities.add(tdscdma);

        CellIdentityNr nr = new CellIdentityNr(PCI, TAC, EARFCN, BANDS, MCC_STR, MNC_STR, CI,
                ALPHA_LONG, ALPHA_SHORT, Collections.emptyList());
        identities.add(nr);

        for (CellIdentity identity : identities) {
            final String mccStr = identity.getMccString();
            final String mncStr = identity.getMncString();
            if (identity instanceof CellIdentityCdma) {
                assertNull(mccStr);
                assertNull(mncStr);
            } else {
                assertEquals(MCC_STR, mccStr);
                assertEquals(MNC_STR, mncStr);
            }
        }
    }
}