Loading res/values/config.xml +3 −0 Original line number Diff line number Diff line Loading @@ -545,4 +545,7 @@ <item>2</item> <item>3</item> </integer-array> <!-- Whether to aggregate for network selection list--> <bool name="config_network_selection_list_aggregation_enabled">false</bool> </resources> src/com/android/settings/network/telephony/CellInfoUtil.java +56 −13 Original line number Diff line number Diff line Loading @@ -143,34 +143,77 @@ public final class CellInfoUtil { public static String cellInfoToString(CellInfo cellInfo) { final String cellType = cellInfo.getClass().getSimpleName(); final CellIdentity cid = getCellIdentity(cellInfo); String mcc = null; String mnc = null; String mcc = getCellIdentityMcc(cid); String mnc = getCellIdentityMnc(cid); CharSequence alphaLong = null; CharSequence alphaShort = null; if (cid != null) { alphaLong = cid.getOperatorAlphaLong(); alphaShort = cid.getOperatorAlphaShort(); } return String.format( "{CellType = %s, isRegistered = %b, mcc = %s, mnc = %s, alphaL = %s, alphaS = %s}", cellType, cellInfo.isRegistered(), mcc, mnc, alphaLong, alphaShort); } /** * Returns the MccMnc. * * @param cid contains the identity of the network. * @return MccMnc string. */ public static String getCellIdentityMccMnc(CellIdentity cid) { String mcc = getCellIdentityMcc(cid); String mnc = getCellIdentityMnc(cid); return (mcc == null || mnc == null) ? null : mcc + mnc; } /** * Returns the Mcc. * * @param cid contains the identity of the network. * @return Mcc string. */ public static String getCellIdentityMcc(CellIdentity cid) { String mcc = null; if (cid != null) { if (cid instanceof CellIdentityGsm) { mcc = ((CellIdentityGsm) cid).getMccString(); mnc = ((CellIdentityGsm) cid).getMncString(); } else if (cid instanceof CellIdentityWcdma) { mcc = ((CellIdentityWcdma) cid).getMccString(); mnc = ((CellIdentityWcdma) cid).getMncString(); } else if (cid instanceof CellIdentityTdscdma) { mcc = ((CellIdentityTdscdma) cid).getMccString(); mnc = ((CellIdentityTdscdma) cid).getMncString(); } else if (cid instanceof CellIdentityLte) { mcc = ((CellIdentityLte) cid).getMccString(); mnc = ((CellIdentityLte) cid).getMncString(); } else if (cid instanceof CellIdentityNr) { mcc = ((CellIdentityNr) cid).getMccString(); mnc = ((CellIdentityNr) cid).getMncString(); } } return (mcc == null) ? null : mcc; } alphaLong = cid.getOperatorAlphaLong(); alphaShort = cid.getOperatorAlphaShort(); /** * Returns the Mnc. * * @param cid contains the identity of the network. * @return Mcc string. */ public static String getCellIdentityMnc(CellIdentity cid) { String mnc = null; if (cid != null) { if (cid instanceof CellIdentityGsm) { mnc = ((CellIdentityGsm) cid).getMncString(); } else if (cid instanceof CellIdentityWcdma) { mnc = ((CellIdentityWcdma) cid).getMncString(); } else if (cid instanceof CellIdentityTdscdma) { mnc = ((CellIdentityTdscdma) cid).getMncString(); } else if (cid instanceof CellIdentityLte) { mnc = ((CellIdentityLte) cid).getMncString(); } else if (cid instanceof CellIdentityNr) { mnc = ((CellIdentityNr) cid).getMncString(); } return String.format( "{CellType = %s, isRegistered = %b, mcc = %s, mnc = %s, alphaL = %s, alphaS = %s}", cellType, cellInfo.isRegistered(), mcc, mnc, alphaLong, alphaShort); } return (mnc == null) ? null : mnc; } } src/com/android/settings/network/telephony/NetworkSelectSettings.java +39 −3 Original line number Diff line number Diff line Loading @@ -68,6 +68,7 @@ public class NetworkSelectSettings extends DashboardFragment { private static final int EVENT_NETWORK_SCAN_COMPLETED = 4; private static final String PREF_KEY_NETWORK_OPERATORS = "network_operators_preference"; private static final int MIN_NUMBER_OF_SCAN_REQUIRED = 2; private PreferenceCategory mPreferenceCategory; @VisibleForTesting Loading @@ -87,8 +88,8 @@ public class NetworkSelectSettings extends DashboardFragment { private long mRequestIdManualNetworkSelect; private long mRequestIdManualNetworkScan; private long mWaitingForNumberOfScanResults; private static final int MIN_NUMBER_OF_SCAN_REQUIRED = 2; @VisibleForTesting boolean mIsAggregationEnabled = false; @Override public void onCreate(Bundle icicle) { Loading Loading @@ -117,6 +118,9 @@ public class NetworkSelectSettings extends DashboardFragment { } mMetricsFeatureProvider = getMetricsFeatureProvider(getContext()); mIsAggregationEnabled = enableAggregation(getContext()); Log.d(TAG, "init: mUseNewApi:" + mUseNewApi + " ,mIsAggregationEnabled:" + mIsAggregationEnabled); } @Keep Loading @@ -126,6 +130,13 @@ public class NetworkSelectSettings extends DashboardFragment { com.android.internal.R.bool.config_enableNewAutoSelectNetworkUI); } @Keep @VisibleForTesting protected boolean enableAggregation(Context context) { return context.getResources().getBoolean( R.bool.config_network_selection_list_aggregation_enabled); } @Keep @VisibleForTesting protected PreferenceCategory getPreferenceCategory(String preferenceKey) { Loading Loading @@ -324,6 +335,31 @@ public class NetworkSelectSettings extends DashboardFragment { } }; @VisibleForTesting List<CellInfo> doAggregation(List<CellInfo> cellInfoListInput) { if (!mIsAggregationEnabled) { Log.d(TAG, "no aggregation"); return new ArrayList<>(cellInfoListInput); } ArrayList<CellInfo> aggregatedList = new ArrayList<>(); for (CellInfo cellInfo : cellInfoListInput) { String plmn = CellInfoUtil.getNetworkTitle(cellInfo.getCellIdentity(), CellInfoUtil.getCellIdentityMccMnc(cellInfo.getCellIdentity())); Class className = cellInfo.getClass(); if (aggregatedList.stream().anyMatch( i -> { return (CellInfoUtil.getNetworkTitle(i.getCellIdentity(), CellInfoUtil.getCellIdentityMccMnc(i.getCellIdentity())) == plmn) && i.getClass().equals(className); })) { continue; } aggregatedList.add(cellInfo); } return aggregatedList; } private final NetworkScanHelper.NetworkScanCallback mCallback = new NetworkScanHelper.NetworkScanCallback() { public void onResults(List<CellInfo> results) { Loading Loading @@ -356,7 +392,7 @@ public class NetworkSelectSettings extends DashboardFragment { stopNetworkQuery(); } mCellInfoList = new ArrayList<>(results); mCellInfoList = doAggregation(results); Log.d(TAG, "CellInfoList: " + CellInfoUtil.cellInfoListToString(mCellInfoList)); if (mCellInfoList != null && mCellInfoList.size() != 0) { final NetworkOperatorPreference connectedPref = Loading tests/unit/src/com/android/settings/network/telephony/NetworkSelectSettingsTest.java +103 −3 Original line number Diff line number Diff line Loading @@ -28,7 +28,13 @@ import android.os.PersistableBundle; import android.provider.Settings; import android.telephony.CarrierConfigManager; import android.telephony.CellIdentity; import android.telephony.CellIdentityGsm; import android.telephony.CellIdentityLte; import android.telephony.CellInfo; import android.telephony.CellInfoGsm; import android.telephony.CellInfoLte; import android.telephony.CellSignalStrengthGsm; import android.telephony.CellSignalStrengthLte; import android.telephony.TelephonyManager; import androidx.preference.PreferenceCategory; Loading @@ -45,6 +51,8 @@ import org.mockito.Mock; import org.mockito.MockitoAnnotations; import java.util.Arrays; import java.util.Collections; import java.util.List; public class NetworkSelectSettingsTest { private static final int SUB_ID = 2; Loading Loading @@ -78,6 +86,7 @@ public class NetworkSelectSettingsTest { public Context mContext; public PreferenceCategory mPreferenceCategory; public boolean mIsAggregationEnabled = true; private Bundle mInitArguments; private TargetClass mNetworkSelectSettings; Loading @@ -93,10 +102,11 @@ public class NetworkSelectSettingsTest { mPreferenceCategory = spy(new PreferenceCategory(mContext)); doReturn(mPreferenceManager).when(mPreferenceCategory).getPreferenceManager(); doReturn(mCellId1).when(mCellInfo1).getCellIdentity(); doReturn(CARRIER_NAME1).when(mCellId1).getOperatorAlphaLong(); doReturn(mCellId2).when(mCellInfo2).getCellIdentity(); doReturn(CARRIER_NAME2).when(mCellId2).getOperatorAlphaLong(); mIsAggregationEnabled = true; mNetworkSelectSettings = spy(new TargetClass(this)); PersistableBundle config = new PersistableBundle(); Loading Loading @@ -169,6 +179,11 @@ public class NetworkSelectSettingsTest { } return pref; } @Override protected boolean enableAggregation(Context context) { return mTestEnv.mIsAggregationEnabled; } } @Test Loading @@ -177,7 +192,6 @@ public class NetworkSelectSettingsTest { mNetworkSelectSettings.onCreateInitialization(); mNetworkSelectSettings.enablePreferenceScreen(true); mNetworkSelectSettings.scanResultHandler(Arrays.asList(mCellInfo1, mCellInfo2)); assertThat(mPreferenceCategory.getPreferenceCount()).isEqualTo(2); final NetworkOperatorPreference preference = (NetworkOperatorPreference) mPreferenceCategory.getPreference(1); Loading @@ -195,4 +209,90 @@ public class NetworkSelectSettingsTest { // Should not Crash mNetworkSelectSettings.updateForbiddenPlmns(); } @Test public void doAggregation_hasDuplicateItemsDiffCellIdCase1_removeSamePlmnRatItem() { mNetworkSelectSettings.onCreateInitialization(); List<CellInfo> testList = Arrays.asList( createLteCellInfo(true, 123, "123", "232", "CarrierA"), createLteCellInfo(true, 1234, "123", "232", "CarrierA"), createGsmCellInfo(false, 123, "123", "232", "CarrierB")); List<CellInfo> expected = Arrays.asList( createLteCellInfo(true, 123, "123", "232", "CarrierA"), createGsmCellInfo(false, 123, "123", "232", "CarrierB")); assertThat(mNetworkSelectSettings.doAggregation(testList)).isEqualTo(expected); } @Test public void doAggregation_hasDuplicateItemsDiffCellIdCase2_removeSamePlmnRatItem() { mNetworkSelectSettings.onCreateInitialization(); List<CellInfo> testList = Arrays.asList( createLteCellInfo(true, 123, "123", "232", "CarrierA"), createGsmCellInfo(false, 123, "123", "232", "CarrierB"), createLteCellInfo(false, 1234, "123", "232", "CarrierB"), createGsmCellInfo(false, 1234, "123", "232", "CarrierB")); List<CellInfo> expected = Arrays.asList( createLteCellInfo(true, 123, "123", "232", "CarrierA"), createGsmCellInfo(false, 123, "123", "232", "CarrierB"), createLteCellInfo(false, 1234, "123", "232", "CarrierB")); assertThat(mNetworkSelectSettings.doAggregation(testList)).isEqualTo(expected); } @Test public void doAggregation_hasDuplicateItemsDiffMccMncCase1_removeSamePlmnRatItem() { mNetworkSelectSettings.onCreateInitialization(); List<CellInfo> testList = Arrays.asList( createLteCellInfo(true, 123, "123", "232", "CarrierA"), createLteCellInfo(true, 123, "456", "232", "CarrierA"), createGsmCellInfo(false, 123, "123", "232", "CarrierB")); List<CellInfo> expected = Arrays.asList( createLteCellInfo(true, 123, "123", "232", "CarrierA"), createGsmCellInfo(false, 123, "123", "232", "CarrierB")); assertThat(mNetworkSelectSettings.doAggregation(testList)).isEqualTo(expected); } @Test public void doAggregation_hasDuplicateItemsDiffMccMncCase2_removeSamePlmnRatItem() { mNetworkSelectSettings.onCreateInitialization(); List<CellInfo> testList = Arrays.asList( createLteCellInfo(true, 123, "123", "232", "CarrierA"), createGsmCellInfo(false, 123, "123", "232", "CarrierB"), createLteCellInfo(false, 1234, "123", "232", "CarrierB"), createGsmCellInfo(false, 123, "456", "232", "CarrierB")); List<CellInfo> expected = Arrays.asList( createLteCellInfo(true, 123, "123", "232", "CarrierA"), createGsmCellInfo(false, 123, "123", "232", "CarrierB"), createLteCellInfo(false, 1234, "123", "232", "CarrierB")); assertThat(mNetworkSelectSettings.doAggregation(testList)).isEqualTo(expected); } private CellInfoLte createLteCellInfo(boolean registered, int cellId, String mcc, String mnc, String plmnName) { CellIdentityLte cil = new CellIdentityLte( cellId, 5, 200, 2000, new int[]{1, 2}, 10000, mcc, mnc, plmnName, plmnName, Collections.emptyList(), null); CellSignalStrengthLte cssl = new CellSignalStrengthLte(15, 16, 17, 18, 19, 20); CellInfoLte cellInfoLte = new CellInfoLte(); cellInfoLte.setRegistered(registered); cellInfoLte.setTimeStamp(22); cellInfoLte.setCellIdentity(cil); cellInfoLte.setCellSignalStrength(cssl); return cellInfoLte; } private CellInfoGsm createGsmCellInfo(boolean registered, int cellId, String mcc, String mnc, String plmnName) { CellIdentityGsm cig = new CellIdentityGsm(1, cellId, 40, 5, mcc, mnc, plmnName, plmnName, Collections.emptyList()); CellSignalStrengthGsm cssg = new CellSignalStrengthGsm(5, 6, 7); CellInfoGsm cellInfoGsm = new CellInfoGsm(); cellInfoGsm.setRegistered(registered); cellInfoGsm.setTimeStamp(9); cellInfoGsm.setCellIdentity(cig); cellInfoGsm.setCellSignalStrength(cssg); return cellInfoGsm; } } Loading
res/values/config.xml +3 −0 Original line number Diff line number Diff line Loading @@ -545,4 +545,7 @@ <item>2</item> <item>3</item> </integer-array> <!-- Whether to aggregate for network selection list--> <bool name="config_network_selection_list_aggregation_enabled">false</bool> </resources>
src/com/android/settings/network/telephony/CellInfoUtil.java +56 −13 Original line number Diff line number Diff line Loading @@ -143,34 +143,77 @@ public final class CellInfoUtil { public static String cellInfoToString(CellInfo cellInfo) { final String cellType = cellInfo.getClass().getSimpleName(); final CellIdentity cid = getCellIdentity(cellInfo); String mcc = null; String mnc = null; String mcc = getCellIdentityMcc(cid); String mnc = getCellIdentityMnc(cid); CharSequence alphaLong = null; CharSequence alphaShort = null; if (cid != null) { alphaLong = cid.getOperatorAlphaLong(); alphaShort = cid.getOperatorAlphaShort(); } return String.format( "{CellType = %s, isRegistered = %b, mcc = %s, mnc = %s, alphaL = %s, alphaS = %s}", cellType, cellInfo.isRegistered(), mcc, mnc, alphaLong, alphaShort); } /** * Returns the MccMnc. * * @param cid contains the identity of the network. * @return MccMnc string. */ public static String getCellIdentityMccMnc(CellIdentity cid) { String mcc = getCellIdentityMcc(cid); String mnc = getCellIdentityMnc(cid); return (mcc == null || mnc == null) ? null : mcc + mnc; } /** * Returns the Mcc. * * @param cid contains the identity of the network. * @return Mcc string. */ public static String getCellIdentityMcc(CellIdentity cid) { String mcc = null; if (cid != null) { if (cid instanceof CellIdentityGsm) { mcc = ((CellIdentityGsm) cid).getMccString(); mnc = ((CellIdentityGsm) cid).getMncString(); } else if (cid instanceof CellIdentityWcdma) { mcc = ((CellIdentityWcdma) cid).getMccString(); mnc = ((CellIdentityWcdma) cid).getMncString(); } else if (cid instanceof CellIdentityTdscdma) { mcc = ((CellIdentityTdscdma) cid).getMccString(); mnc = ((CellIdentityTdscdma) cid).getMncString(); } else if (cid instanceof CellIdentityLte) { mcc = ((CellIdentityLte) cid).getMccString(); mnc = ((CellIdentityLte) cid).getMncString(); } else if (cid instanceof CellIdentityNr) { mcc = ((CellIdentityNr) cid).getMccString(); mnc = ((CellIdentityNr) cid).getMncString(); } } return (mcc == null) ? null : mcc; } alphaLong = cid.getOperatorAlphaLong(); alphaShort = cid.getOperatorAlphaShort(); /** * Returns the Mnc. * * @param cid contains the identity of the network. * @return Mcc string. */ public static String getCellIdentityMnc(CellIdentity cid) { String mnc = null; if (cid != null) { if (cid instanceof CellIdentityGsm) { mnc = ((CellIdentityGsm) cid).getMncString(); } else if (cid instanceof CellIdentityWcdma) { mnc = ((CellIdentityWcdma) cid).getMncString(); } else if (cid instanceof CellIdentityTdscdma) { mnc = ((CellIdentityTdscdma) cid).getMncString(); } else if (cid instanceof CellIdentityLte) { mnc = ((CellIdentityLte) cid).getMncString(); } else if (cid instanceof CellIdentityNr) { mnc = ((CellIdentityNr) cid).getMncString(); } return String.format( "{CellType = %s, isRegistered = %b, mcc = %s, mnc = %s, alphaL = %s, alphaS = %s}", cellType, cellInfo.isRegistered(), mcc, mnc, alphaLong, alphaShort); } return (mnc == null) ? null : mnc; } }
src/com/android/settings/network/telephony/NetworkSelectSettings.java +39 −3 Original line number Diff line number Diff line Loading @@ -68,6 +68,7 @@ public class NetworkSelectSettings extends DashboardFragment { private static final int EVENT_NETWORK_SCAN_COMPLETED = 4; private static final String PREF_KEY_NETWORK_OPERATORS = "network_operators_preference"; private static final int MIN_NUMBER_OF_SCAN_REQUIRED = 2; private PreferenceCategory mPreferenceCategory; @VisibleForTesting Loading @@ -87,8 +88,8 @@ public class NetworkSelectSettings extends DashboardFragment { private long mRequestIdManualNetworkSelect; private long mRequestIdManualNetworkScan; private long mWaitingForNumberOfScanResults; private static final int MIN_NUMBER_OF_SCAN_REQUIRED = 2; @VisibleForTesting boolean mIsAggregationEnabled = false; @Override public void onCreate(Bundle icicle) { Loading Loading @@ -117,6 +118,9 @@ public class NetworkSelectSettings extends DashboardFragment { } mMetricsFeatureProvider = getMetricsFeatureProvider(getContext()); mIsAggregationEnabled = enableAggregation(getContext()); Log.d(TAG, "init: mUseNewApi:" + mUseNewApi + " ,mIsAggregationEnabled:" + mIsAggregationEnabled); } @Keep Loading @@ -126,6 +130,13 @@ public class NetworkSelectSettings extends DashboardFragment { com.android.internal.R.bool.config_enableNewAutoSelectNetworkUI); } @Keep @VisibleForTesting protected boolean enableAggregation(Context context) { return context.getResources().getBoolean( R.bool.config_network_selection_list_aggregation_enabled); } @Keep @VisibleForTesting protected PreferenceCategory getPreferenceCategory(String preferenceKey) { Loading Loading @@ -324,6 +335,31 @@ public class NetworkSelectSettings extends DashboardFragment { } }; @VisibleForTesting List<CellInfo> doAggregation(List<CellInfo> cellInfoListInput) { if (!mIsAggregationEnabled) { Log.d(TAG, "no aggregation"); return new ArrayList<>(cellInfoListInput); } ArrayList<CellInfo> aggregatedList = new ArrayList<>(); for (CellInfo cellInfo : cellInfoListInput) { String plmn = CellInfoUtil.getNetworkTitle(cellInfo.getCellIdentity(), CellInfoUtil.getCellIdentityMccMnc(cellInfo.getCellIdentity())); Class className = cellInfo.getClass(); if (aggregatedList.stream().anyMatch( i -> { return (CellInfoUtil.getNetworkTitle(i.getCellIdentity(), CellInfoUtil.getCellIdentityMccMnc(i.getCellIdentity())) == plmn) && i.getClass().equals(className); })) { continue; } aggregatedList.add(cellInfo); } return aggregatedList; } private final NetworkScanHelper.NetworkScanCallback mCallback = new NetworkScanHelper.NetworkScanCallback() { public void onResults(List<CellInfo> results) { Loading Loading @@ -356,7 +392,7 @@ public class NetworkSelectSettings extends DashboardFragment { stopNetworkQuery(); } mCellInfoList = new ArrayList<>(results); mCellInfoList = doAggregation(results); Log.d(TAG, "CellInfoList: " + CellInfoUtil.cellInfoListToString(mCellInfoList)); if (mCellInfoList != null && mCellInfoList.size() != 0) { final NetworkOperatorPreference connectedPref = Loading
tests/unit/src/com/android/settings/network/telephony/NetworkSelectSettingsTest.java +103 −3 Original line number Diff line number Diff line Loading @@ -28,7 +28,13 @@ import android.os.PersistableBundle; import android.provider.Settings; import android.telephony.CarrierConfigManager; import android.telephony.CellIdentity; import android.telephony.CellIdentityGsm; import android.telephony.CellIdentityLte; import android.telephony.CellInfo; import android.telephony.CellInfoGsm; import android.telephony.CellInfoLte; import android.telephony.CellSignalStrengthGsm; import android.telephony.CellSignalStrengthLte; import android.telephony.TelephonyManager; import androidx.preference.PreferenceCategory; Loading @@ -45,6 +51,8 @@ import org.mockito.Mock; import org.mockito.MockitoAnnotations; import java.util.Arrays; import java.util.Collections; import java.util.List; public class NetworkSelectSettingsTest { private static final int SUB_ID = 2; Loading Loading @@ -78,6 +86,7 @@ public class NetworkSelectSettingsTest { public Context mContext; public PreferenceCategory mPreferenceCategory; public boolean mIsAggregationEnabled = true; private Bundle mInitArguments; private TargetClass mNetworkSelectSettings; Loading @@ -93,10 +102,11 @@ public class NetworkSelectSettingsTest { mPreferenceCategory = spy(new PreferenceCategory(mContext)); doReturn(mPreferenceManager).when(mPreferenceCategory).getPreferenceManager(); doReturn(mCellId1).when(mCellInfo1).getCellIdentity(); doReturn(CARRIER_NAME1).when(mCellId1).getOperatorAlphaLong(); doReturn(mCellId2).when(mCellInfo2).getCellIdentity(); doReturn(CARRIER_NAME2).when(mCellId2).getOperatorAlphaLong(); mIsAggregationEnabled = true; mNetworkSelectSettings = spy(new TargetClass(this)); PersistableBundle config = new PersistableBundle(); Loading Loading @@ -169,6 +179,11 @@ public class NetworkSelectSettingsTest { } return pref; } @Override protected boolean enableAggregation(Context context) { return mTestEnv.mIsAggregationEnabled; } } @Test Loading @@ -177,7 +192,6 @@ public class NetworkSelectSettingsTest { mNetworkSelectSettings.onCreateInitialization(); mNetworkSelectSettings.enablePreferenceScreen(true); mNetworkSelectSettings.scanResultHandler(Arrays.asList(mCellInfo1, mCellInfo2)); assertThat(mPreferenceCategory.getPreferenceCount()).isEqualTo(2); final NetworkOperatorPreference preference = (NetworkOperatorPreference) mPreferenceCategory.getPreference(1); Loading @@ -195,4 +209,90 @@ public class NetworkSelectSettingsTest { // Should not Crash mNetworkSelectSettings.updateForbiddenPlmns(); } @Test public void doAggregation_hasDuplicateItemsDiffCellIdCase1_removeSamePlmnRatItem() { mNetworkSelectSettings.onCreateInitialization(); List<CellInfo> testList = Arrays.asList( createLteCellInfo(true, 123, "123", "232", "CarrierA"), createLteCellInfo(true, 1234, "123", "232", "CarrierA"), createGsmCellInfo(false, 123, "123", "232", "CarrierB")); List<CellInfo> expected = Arrays.asList( createLteCellInfo(true, 123, "123", "232", "CarrierA"), createGsmCellInfo(false, 123, "123", "232", "CarrierB")); assertThat(mNetworkSelectSettings.doAggregation(testList)).isEqualTo(expected); } @Test public void doAggregation_hasDuplicateItemsDiffCellIdCase2_removeSamePlmnRatItem() { mNetworkSelectSettings.onCreateInitialization(); List<CellInfo> testList = Arrays.asList( createLteCellInfo(true, 123, "123", "232", "CarrierA"), createGsmCellInfo(false, 123, "123", "232", "CarrierB"), createLteCellInfo(false, 1234, "123", "232", "CarrierB"), createGsmCellInfo(false, 1234, "123", "232", "CarrierB")); List<CellInfo> expected = Arrays.asList( createLteCellInfo(true, 123, "123", "232", "CarrierA"), createGsmCellInfo(false, 123, "123", "232", "CarrierB"), createLteCellInfo(false, 1234, "123", "232", "CarrierB")); assertThat(mNetworkSelectSettings.doAggregation(testList)).isEqualTo(expected); } @Test public void doAggregation_hasDuplicateItemsDiffMccMncCase1_removeSamePlmnRatItem() { mNetworkSelectSettings.onCreateInitialization(); List<CellInfo> testList = Arrays.asList( createLteCellInfo(true, 123, "123", "232", "CarrierA"), createLteCellInfo(true, 123, "456", "232", "CarrierA"), createGsmCellInfo(false, 123, "123", "232", "CarrierB")); List<CellInfo> expected = Arrays.asList( createLteCellInfo(true, 123, "123", "232", "CarrierA"), createGsmCellInfo(false, 123, "123", "232", "CarrierB")); assertThat(mNetworkSelectSettings.doAggregation(testList)).isEqualTo(expected); } @Test public void doAggregation_hasDuplicateItemsDiffMccMncCase2_removeSamePlmnRatItem() { mNetworkSelectSettings.onCreateInitialization(); List<CellInfo> testList = Arrays.asList( createLteCellInfo(true, 123, "123", "232", "CarrierA"), createGsmCellInfo(false, 123, "123", "232", "CarrierB"), createLteCellInfo(false, 1234, "123", "232", "CarrierB"), createGsmCellInfo(false, 123, "456", "232", "CarrierB")); List<CellInfo> expected = Arrays.asList( createLteCellInfo(true, 123, "123", "232", "CarrierA"), createGsmCellInfo(false, 123, "123", "232", "CarrierB"), createLteCellInfo(false, 1234, "123", "232", "CarrierB")); assertThat(mNetworkSelectSettings.doAggregation(testList)).isEqualTo(expected); } private CellInfoLte createLteCellInfo(boolean registered, int cellId, String mcc, String mnc, String plmnName) { CellIdentityLte cil = new CellIdentityLte( cellId, 5, 200, 2000, new int[]{1, 2}, 10000, mcc, mnc, plmnName, plmnName, Collections.emptyList(), null); CellSignalStrengthLte cssl = new CellSignalStrengthLte(15, 16, 17, 18, 19, 20); CellInfoLte cellInfoLte = new CellInfoLte(); cellInfoLte.setRegistered(registered); cellInfoLte.setTimeStamp(22); cellInfoLte.setCellIdentity(cil); cellInfoLte.setCellSignalStrength(cssl); return cellInfoLte; } private CellInfoGsm createGsmCellInfo(boolean registered, int cellId, String mcc, String mnc, String plmnName) { CellIdentityGsm cig = new CellIdentityGsm(1, cellId, 40, 5, mcc, mnc, plmnName, plmnName, Collections.emptyList()); CellSignalStrengthGsm cssg = new CellSignalStrengthGsm(5, 6, 7); CellInfoGsm cellInfoGsm = new CellInfoGsm(); cellInfoGsm.setRegistered(registered); cellInfoGsm.setTimeStamp(9); cellInfoGsm.setCellIdentity(cig); cellInfoGsm.setCellSignalStrength(cssg); return cellInfoGsm; } }