Loading src/java/com/android/internal/telephony/LocaleTracker.java +3 −32 Original line number Original line Diff line number Diff line Loading @@ -32,9 +32,6 @@ import android.os.Looper; import android.os.Message; import android.os.Message; import android.sysprop.TelephonyProperties; import android.sysprop.TelephonyProperties; import android.telephony.CellInfo; import android.telephony.CellInfo; import android.telephony.CellInfoGsm; import android.telephony.CellInfoLte; import android.telephony.CellInfoWcdma; import android.telephony.ServiceState; import android.telephony.ServiceState; import android.telephony.SubscriptionManager; import android.telephony.SubscriptionManager; import android.telephony.TelephonyManager; import android.telephony.TelephonyManager; Loading Loading @@ -295,7 +292,7 @@ public class LocaleTracker extends Handler { Map<String, Integer> mccMap = new HashMap<>(); Map<String, Integer> mccMap = new HashMap<>(); int maxCount = 0; int maxCount = 0; for (CellInfo cellInfo : mCellInfoList) { for (CellInfo cellInfo : mCellInfoList) { String mcc = getNetworkMcc(cellInfo); String mcc = cellInfo.getCellIdentity().getMccString(); if (mcc != null) { if (mcc != null) { int count = 1; int count = 1; if (mccMap.containsKey(mcc)) { if (mccMap.containsKey(mcc)) { Loading Loading @@ -330,9 +327,9 @@ public class LocaleTracker extends Handler { Map<MccMnc, Integer> mccMncMap = new HashMap<>(); Map<MccMnc, Integer> mccMncMap = new HashMap<>(); int maxCount = 0; int maxCount = 0; for (CellInfo cellInfo : mCellInfoList) { for (CellInfo cellInfo : mCellInfoList) { String mcc = getNetworkMcc(cellInfo); String mcc = cellInfo.getCellIdentity().getMccString(); if (Objects.equals(mcc, mccToMatch)) { if (Objects.equals(mcc, mccToMatch)) { String mnc = getNetworkMnc(cellInfo); String mnc = cellInfo.getCellIdentity().getMncString(); MccMnc mccMnc = new MccMnc(mcc, mnc); MccMnc mccMnc = new MccMnc(mcc, mnc); int count = 1; int count = 1; if (mccMncMap.containsKey(mccMnc)) { if (mccMncMap.containsKey(mccMnc)) { Loading @@ -352,32 +349,6 @@ public class LocaleTracker extends Handler { return selectedMccMnc; 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 * 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 * cell info from the network. Other SIM states like NOT_READY might be just a transitioning Loading tests/telephonytests/src/com/android/internal/telephony/CellIdentityTest.java +49 −0 Original line number Original line Diff line number Diff line Loading @@ -22,11 +22,15 @@ import android.telephony.CellIdentityCdma; import android.telephony.CellIdentityGsm; import android.telephony.CellIdentityGsm; import android.telephony.CellIdentityLte; import android.telephony.CellIdentityLte; import android.telephony.CellIdentityNr; import android.telephony.CellIdentityNr; import android.telephony.CellIdentityTdscdma; import android.telephony.CellIdentityWcdma; import android.telephony.CellInfo; import android.telephony.CellInfo; import android.test.AndroidTestCase; import android.test.AndroidTestCase; import android.test.suitebuilder.annotation.SmallTest; import android.test.suitebuilder.annotation.SmallTest; import java.util.ArrayList; import java.util.Collections; import java.util.Collections; import java.util.List; public class CellIdentityTest extends AndroidTestCase { public class CellIdentityTest extends AndroidTestCase { Loading @@ -46,6 +50,9 @@ public class CellIdentityTest extends AndroidTestCase { private static final String MNC_STR = "260"; private static final String MNC_STR = "260"; private static final String ALPHA_LONG = "long"; private static final String ALPHA_LONG = "long"; private static final String ALPHA_SHORT = "short"; 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. // Network Id ranges from 0 to 65535. private static final int NETWORK_ID = 65535; private static final int NETWORK_ID = 65535; Loading Loading @@ -183,4 +190,46 @@ public class CellIdentityTest extends AndroidTestCase { ALPHA_SHORT, Collections.emptyList()); ALPHA_SHORT, Collections.emptyList()); assertFalse(ciA.isSameCell(cellIdentityNr)); 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); } } } } } Loading
src/java/com/android/internal/telephony/LocaleTracker.java +3 −32 Original line number Original line Diff line number Diff line Loading @@ -32,9 +32,6 @@ import android.os.Looper; import android.os.Message; import android.os.Message; import android.sysprop.TelephonyProperties; import android.sysprop.TelephonyProperties; import android.telephony.CellInfo; import android.telephony.CellInfo; import android.telephony.CellInfoGsm; import android.telephony.CellInfoLte; import android.telephony.CellInfoWcdma; import android.telephony.ServiceState; import android.telephony.ServiceState; import android.telephony.SubscriptionManager; import android.telephony.SubscriptionManager; import android.telephony.TelephonyManager; import android.telephony.TelephonyManager; Loading Loading @@ -295,7 +292,7 @@ public class LocaleTracker extends Handler { Map<String, Integer> mccMap = new HashMap<>(); Map<String, Integer> mccMap = new HashMap<>(); int maxCount = 0; int maxCount = 0; for (CellInfo cellInfo : mCellInfoList) { for (CellInfo cellInfo : mCellInfoList) { String mcc = getNetworkMcc(cellInfo); String mcc = cellInfo.getCellIdentity().getMccString(); if (mcc != null) { if (mcc != null) { int count = 1; int count = 1; if (mccMap.containsKey(mcc)) { if (mccMap.containsKey(mcc)) { Loading Loading @@ -330,9 +327,9 @@ public class LocaleTracker extends Handler { Map<MccMnc, Integer> mccMncMap = new HashMap<>(); Map<MccMnc, Integer> mccMncMap = new HashMap<>(); int maxCount = 0; int maxCount = 0; for (CellInfo cellInfo : mCellInfoList) { for (CellInfo cellInfo : mCellInfoList) { String mcc = getNetworkMcc(cellInfo); String mcc = cellInfo.getCellIdentity().getMccString(); if (Objects.equals(mcc, mccToMatch)) { if (Objects.equals(mcc, mccToMatch)) { String mnc = getNetworkMnc(cellInfo); String mnc = cellInfo.getCellIdentity().getMncString(); MccMnc mccMnc = new MccMnc(mcc, mnc); MccMnc mccMnc = new MccMnc(mcc, mnc); int count = 1; int count = 1; if (mccMncMap.containsKey(mccMnc)) { if (mccMncMap.containsKey(mccMnc)) { Loading @@ -352,32 +349,6 @@ public class LocaleTracker extends Handler { return selectedMccMnc; 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 * 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 * cell info from the network. Other SIM states like NOT_READY might be just a transitioning Loading
tests/telephonytests/src/com/android/internal/telephony/CellIdentityTest.java +49 −0 Original line number Original line Diff line number Diff line Loading @@ -22,11 +22,15 @@ import android.telephony.CellIdentityCdma; import android.telephony.CellIdentityGsm; import android.telephony.CellIdentityGsm; import android.telephony.CellIdentityLte; import android.telephony.CellIdentityLte; import android.telephony.CellIdentityNr; import android.telephony.CellIdentityNr; import android.telephony.CellIdentityTdscdma; import android.telephony.CellIdentityWcdma; import android.telephony.CellInfo; import android.telephony.CellInfo; import android.test.AndroidTestCase; import android.test.AndroidTestCase; import android.test.suitebuilder.annotation.SmallTest; import android.test.suitebuilder.annotation.SmallTest; import java.util.ArrayList; import java.util.Collections; import java.util.Collections; import java.util.List; public class CellIdentityTest extends AndroidTestCase { public class CellIdentityTest extends AndroidTestCase { Loading @@ -46,6 +50,9 @@ public class CellIdentityTest extends AndroidTestCase { private static final String MNC_STR = "260"; private static final String MNC_STR = "260"; private static final String ALPHA_LONG = "long"; private static final String ALPHA_LONG = "long"; private static final String ALPHA_SHORT = "short"; 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. // Network Id ranges from 0 to 65535. private static final int NETWORK_ID = 65535; private static final int NETWORK_ID = 65535; Loading Loading @@ -183,4 +190,46 @@ public class CellIdentityTest extends AndroidTestCase { ALPHA_SHORT, Collections.emptyList()); ALPHA_SHORT, Collections.emptyList()); assertFalse(ciA.isSameCell(cellIdentityNr)); 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); } } } } }