Create NetworkScanRepository

And migrate network scan to flow for better maintenance and prevent ANR.

Fix: 323105271
Test: manual - Choose network
Test: unit test
Change-Id: I5c49d195fc202143c0131ffd78bc3adc168b119c
Merged-In: I5c49d195fc202143c0131ffd78bc3adc168b119c
This commit is contained in:
Chaohui Wang
2024-03-04 19:14:52 +08:00
parent b9a0722d20
commit 12158eb1fe
7 changed files with 495 additions and 881 deletions

View File

@@ -0,0 +1,265 @@
/*
* Copyright (C) 2024 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.settings.network.telephony.scan
import android.content.Context
import android.telephony.AccessNetworkConstants.AccessNetworkType
import android.telephony.CellIdentityCdma
import android.telephony.CellIdentityGsm
import android.telephony.CellIdentityLte
import android.telephony.CellInfoCdma
import android.telephony.CellInfoGsm
import android.telephony.CellInfoLte
import android.telephony.NetworkScan
import android.telephony.NetworkScanRequest
import android.telephony.PhoneCapability
import android.telephony.TelephonyManager
import android.telephony.TelephonyManager.NETWORK_CLASS_BITMASK_5G
import android.telephony.TelephonyScanManager
import androidx.test.core.app.ApplicationProvider
import androidx.test.ext.junit.runners.AndroidJUnit4
import com.android.settings.network.telephony.scan.NetworkScanRepository.NetworkScanCellInfos
import com.android.settings.network.telephony.scan.NetworkScanRepository.NetworkScanComplete
import com.android.settings.network.telephony.scan.NetworkScanRepository.NetworkScanError
import com.android.settingslib.spa.testutils.firstWithTimeoutOrNull
import com.android.settingslib.spa.testutils.toListWithTimeout
import com.google.common.truth.Truth.assertThat
import kotlinx.coroutines.async
import kotlinx.coroutines.delay
import kotlinx.coroutines.runBlocking
import org.junit.Test
import org.junit.runner.RunWith
import org.mockito.kotlin.any
import org.mockito.kotlin.argThat
import org.mockito.kotlin.doAnswer
import org.mockito.kotlin.doReturn
import org.mockito.kotlin.mock
import org.mockito.kotlin.spy
import org.mockito.kotlin.stub
import org.mockito.kotlin.verify
@RunWith(AndroidJUnit4::class)
class NetworkScanRepositoryTest {
private var callback: TelephonyScanManager.NetworkScanCallback? = null
private val mockTelephonyManager = mock<TelephonyManager> {
on { createForSubscriptionId(SUB_ID) } doReturn mock
on { requestNetworkScan(any(), any(), any()) } doAnswer {
callback = it.arguments[2] as TelephonyScanManager.NetworkScanCallback
mock<NetworkScan>()
}
}
private val context: Context = spy(ApplicationProvider.getApplicationContext()) {
on { getSystemService(TelephonyManager::class.java) } doReturn mockTelephonyManager
}
private val repository = NetworkScanRepository(context, SUB_ID)
@Test
fun networkScanFlow_initial() = runBlocking {
val result = repository.networkScanFlow().firstWithTimeoutOrNull()
assertThat(result).isNull()
}
@Test
fun networkScanFlow_onResults(): Unit = runBlocking {
val cellInfos = listOf(CellInfoCdma().apply { cellIdentity = CELL_IDENTITY_CDMA })
val listDeferred = async {
repository.networkScanFlow().toListWithTimeout()
}
delay(100)
callback?.onResults(cellInfos)
assertThat(listDeferred.await()).containsExactly(NetworkScanCellInfos(cellInfos))
}
@Test
fun networkScanFlow_onComplete(): Unit = runBlocking {
val listDeferred = async {
repository.networkScanFlow().toListWithTimeout()
}
delay(100)
callback?.onComplete()
assertThat(listDeferred.await()).containsExactly(NetworkScanComplete)
}
@Test
fun networkScanFlow_onError(): Unit = runBlocking {
val listDeferred = async {
repository.networkScanFlow().toListWithTimeout()
}
delay(100)
callback?.onError(1)
assertThat(listDeferred.await()).containsExactly(NetworkScanError(1))
}
@Test
fun networkScanFlow_hasDuplicateItems(): Unit = runBlocking {
val cellInfos = listOf(
createCellInfoLte("123", false),
createCellInfoLte("123", false),
createCellInfoLte("124", true),
createCellInfoLte("124", true),
createCellInfoGsm("123", false),
createCellInfoGsm("123", false),
)
val listDeferred = async {
repository.networkScanFlow().toListWithTimeout()
}
delay(100)
callback?.onResults(cellInfos)
assertThat(listDeferred.await()).containsExactly(
NetworkScanCellInfos(
listOf(
createCellInfoLte("123", false),
createCellInfoLte("124", true),
createCellInfoGsm("123", false),
)
)
)
}
@Test
fun networkScanFlow_noDuplicateItems(): Unit = runBlocking {
val cellInfos = listOf(
createCellInfoLte("123", false),
createCellInfoLte("123", true),
createCellInfoLte("124", false),
createCellInfoLte("124", true),
createCellInfoGsm("456", false),
createCellInfoGsm("456", true),
)
val listDeferred = async {
repository.networkScanFlow().toListWithTimeout()
}
delay(100)
callback?.onResults(cellInfos)
assertThat(listDeferred.await()).containsExactly(
NetworkScanCellInfos(
listOf(
createCellInfoLte("123", false),
createCellInfoLte("123", true),
createCellInfoLte("124", false),
createCellInfoLte("124", true),
createCellInfoGsm("456", false),
createCellInfoGsm("456", true),
)
)
)
}
@Test
fun createNetworkScan_deviceHasNrSa_requestNgran(): Unit = runBlocking {
mockTelephonyManager.stub {
on { getAllowedNetworkTypesBitmask() } doReturn NETWORK_CLASS_BITMASK_5G
on { getPhoneCapability() } doReturn
createPhoneCapability(intArrayOf(PhoneCapability.DEVICE_NR_CAPABILITY_SA))
}
repository.networkScanFlow().firstWithTimeoutOrNull()
verify(mockTelephonyManager).requestNetworkScan(argThat<NetworkScanRequest> {
specifiers.any { it.radioAccessNetwork == AccessNetworkType.NGRAN }
}, any(), any())
}
@Test
fun createNetworkScan_deviceNoNrSa_noNgran(): Unit = runBlocking {
mockTelephonyManager.stub {
on { getAllowedNetworkTypesBitmask() } doReturn NETWORK_CLASS_BITMASK_5G
on { getPhoneCapability() } doReturn
createPhoneCapability(intArrayOf(PhoneCapability.DEVICE_NR_CAPABILITY_NSA))
}
repository.networkScanFlow().firstWithTimeoutOrNull()
verify(mockTelephonyManager).requestNetworkScan(argThat<NetworkScanRequest> {
specifiers.none { it.radioAccessNetwork == AccessNetworkType.NGRAN }
}, any(), any())
}
private companion object {
const val SUB_ID = 1
const val LONG = "Long"
const val SHORT = "Short"
val CELL_IDENTITY_CDMA = CellIdentityCdma(
/* nid = */ 1,
/* sid = */ 2,
/* bid = */ 3,
/* lon = */ 4,
/* lat = */ 5,
/* alphal = */ LONG,
/* alphas = */ SHORT,
)
private fun createCellInfoLte(alphaLong: String, registered: Boolean): CellInfoLte {
val cellIdentityLte = CellIdentityLte(
/* ci = */ 1,
/* pci = */ 2,
/* tac = */ 3,
/* earfcn = */ 4,
/* bands = */ intArrayOf(1, 2),
/* bandwidth = */ 10000,
/* mccStr = */ null,
/* mncStr = */ null,
/* alphal = */ alphaLong,
/* alphas = */ null,
/* additionalPlmns = */ emptyList(),
/* csgInfo = */ null,
)
return CellInfoLte().apply {
cellIdentity = cellIdentityLte
isRegistered = registered
}
}
private fun createCellInfoGsm(alphaLong: String, registered: Boolean): CellInfoGsm {
val cellIdentityGsm = CellIdentityGsm(
/* lac = */ 1,
/* cid = */ 2,
/* arfcn = */ 3,
/* bsic = */ 4,
/* mccStr = */ "123",
/* mncStr = */ "01",
/* alphal = */ alphaLong,
/* alphas = */ null,
/* additionalPlmns = */ emptyList(),
)
return CellInfoGsm().apply {
cellIdentity = cellIdentityGsm
isRegistered = registered
}
}
private fun createPhoneCapability(deviceNrCapabilities: IntArray) =
PhoneCapability.Builder().setDeviceNrCapabilities(deviceNrCapabilities).build()
}
}

View File

@@ -1,260 +0,0 @@
/*
* Copyright (C) 2021 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.settings.network.telephony;
import static com.google.common.truth.Truth.assertThat;
import static org.junit.Assert.assertEquals;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyInt;
import static org.mockito.Mockito.doAnswer;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import android.telephony.AccessNetworkConstants;
import android.telephony.CellInfo;
import android.telephony.ModemInfo;
import android.telephony.NetworkScan;
import android.telephony.NetworkScanRequest;
import android.telephony.PhoneCapability;
import android.telephony.RadioAccessSpecifier;
import android.telephony.TelephonyManager;
import android.telephony.TelephonyScanManager;
import androidx.test.ext.junit.runners.AndroidJUnit4;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.ArgumentCaptor;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.mockito.invocation.InvocationOnMock;
import org.mockito.stubbing.Answer;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.Executor;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
@RunWith(AndroidJUnit4.class)
public class NetworkScanHelperTest {
@Mock
private TelephonyManager mTelephonyManager;
@Mock
private List<CellInfo> mCellInfos;
@Mock
private NetworkScanHelper.NetworkScanCallback mNetworkScanCallback;
private static final long THREAD_EXECUTION_TIMEOUT_MS = 3000L;
private ExecutorService mNetworkScanExecutor;
private NetworkScanHelper mNetworkScanHelper;
private static final int SCAN_ID = 1234;
private static final int SUB_ID = 1;
private NetworkScan mNetworkScan;
public class NetworkScanMock extends NetworkScan {
NetworkScanMock(int scanId, int subId) {
super(scanId, subId);
}
@Override
public void stopScan() {
return;
}
}
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
mNetworkScanExecutor = Executors.newFixedThreadPool(1);
mNetworkScanHelper = new NetworkScanHelper(mTelephonyManager,
mNetworkScanCallback, mNetworkScanExecutor);
mNetworkScan = spy(new NetworkScanMock(SCAN_ID, SUB_ID));
}
@Test
public void startNetworkScan_incrementalAndSuccess_completionWithResult() {
when(mCellInfos.size()).thenReturn(1);
doAnswer(new Answer() {
@Override
public Object answer(InvocationOnMock invocation) throws Throwable {
TelephonyScanManager.NetworkScanCallback callback =
(TelephonyScanManager.NetworkScanCallback)
(invocation.getArguments()[2]);
callback.onResults(mCellInfos);
callback.onComplete();
return mNetworkScan;
}
}).when(mTelephonyManager).requestNetworkScan(
any(NetworkScanRequest.class), any(Executor.class),
any(TelephonyScanManager.NetworkScanCallback.class));
ArgumentCaptor<List<CellInfo>> argument = ArgumentCaptor.forClass(List.class);
startNetworkScan_incremental(true);
verify(mNetworkScanCallback, times(1)).onResults(argument.capture());
List<CellInfo> actualResult = argument.getValue();
assertThat(actualResult.size()).isEqualTo(mCellInfos.size());
verify(mNetworkScanCallback, times(1)).onComplete();
}
@Test
public void startNetworkScan_incrementalAndImmediateFailure_failureWithErrorCode() {
doReturn(null).when(mTelephonyManager).requestNetworkScan(
any(NetworkScanRequest.class), any(Executor.class),
any(TelephonyScanManager.NetworkScanCallback.class));
startNetworkScan_incremental(true);
verify(mNetworkScanCallback, times(1)).onError(anyInt());
}
@Test
public void startNetworkScan_incrementalAndFailure_failureWithErrorCode() {
doAnswer(new Answer() {
@Override
public Object answer(InvocationOnMock invocation) throws Throwable {
TelephonyScanManager.NetworkScanCallback callback =
(TelephonyScanManager.NetworkScanCallback)
(invocation.getArguments()[2]);
callback.onError(NetworkScan.ERROR_MODEM_ERROR);
return mNetworkScan;
}
}).when(mTelephonyManager).requestNetworkScan(
any(NetworkScanRequest.class), any(Executor.class),
any(TelephonyScanManager.NetworkScanCallback.class));
startNetworkScan_incremental(true);
verify(mNetworkScanCallback, times(1)).onError(anyInt());
}
@Test
public void startNetworkScan_incrementalAndAbort_doStop() {
doReturn(mNetworkScan).when(mTelephonyManager).requestNetworkScan(
any(NetworkScanRequest.class), any(Executor.class),
any(TelephonyScanManager.NetworkScanCallback.class));
startNetworkScan_incremental(false);
verify(mNetworkScan, times(1)).stopScan();
}
@Test
public void createNetworkScanForPreferredAccessNetworks_deviceNoNrSa_noNgran() {
int[] deviceNrCapabilities = new int[]{PhoneCapability.DEVICE_NR_CAPABILITY_NSA};
PhoneCapability phoneCapability = createPhoneCapability(deviceNrCapabilities);
doReturn(TelephonyManager.NETWORK_CLASS_BITMASK_2G
| TelephonyManager.NETWORK_CLASS_BITMASK_3G
| TelephonyManager.NETWORK_CLASS_BITMASK_4G
| TelephonyManager.NETWORK_CLASS_BITMASK_5G).when(
mTelephonyManager).getPreferredNetworkTypeBitmask();
doReturn(phoneCapability).when(mTelephonyManager).getPhoneCapability();
List<RadioAccessSpecifier> radioAccessSpecifiers = new ArrayList<>();
radioAccessSpecifiers.add(
new RadioAccessSpecifier(AccessNetworkConstants.AccessNetworkType.GERAN, null,
null));
radioAccessSpecifiers.add(
new RadioAccessSpecifier(AccessNetworkConstants.AccessNetworkType.UTRAN, null,
null));
radioAccessSpecifiers.add(
new RadioAccessSpecifier(AccessNetworkConstants.AccessNetworkType.EUTRAN, null,
null));
NetworkScanRequest expectedNetworkScanRequest = createNetworkScanRequest(
radioAccessSpecifiers);
assertEquals(expectedNetworkScanRequest,
mNetworkScanHelper.createNetworkScanForPreferredAccessNetworks());
}
@Test
public void createNetworkScanForPreferredAccessNetworks_deviceHasNrSa_hasNgran() {
int[] deviceNrCapabilities = new int[]{PhoneCapability.DEVICE_NR_CAPABILITY_NSA,
PhoneCapability.DEVICE_NR_CAPABILITY_SA};
PhoneCapability phoneCapability = createPhoneCapability(deviceNrCapabilities);
doReturn(TelephonyManager.NETWORK_CLASS_BITMASK_2G
| TelephonyManager.NETWORK_CLASS_BITMASK_3G
| TelephonyManager.NETWORK_CLASS_BITMASK_4G
| TelephonyManager.NETWORK_CLASS_BITMASK_5G).when(
mTelephonyManager).getPreferredNetworkTypeBitmask();
doReturn(phoneCapability).when(mTelephonyManager).getPhoneCapability();
List<RadioAccessSpecifier> radioAccessSpecifiers = new ArrayList<>();
radioAccessSpecifiers.add(
new RadioAccessSpecifier(AccessNetworkConstants.AccessNetworkType.GERAN, null,
null));
radioAccessSpecifiers.add(
new RadioAccessSpecifier(AccessNetworkConstants.AccessNetworkType.UTRAN, null,
null));
radioAccessSpecifiers.add(
new RadioAccessSpecifier(AccessNetworkConstants.AccessNetworkType.EUTRAN, null,
null));
radioAccessSpecifiers.add(
new RadioAccessSpecifier(AccessNetworkConstants.AccessNetworkType.NGRAN, null,
null));
NetworkScanRequest expectedNetworkScanRequest = createNetworkScanRequest(
radioAccessSpecifiers);
assertEquals(expectedNetworkScanRequest,
mNetworkScanHelper.createNetworkScanForPreferredAccessNetworks());
}
private PhoneCapability createPhoneCapability(int[] deviceNrCapabilities) {
int maxActiveVoiceCalls = 1;
int maxActiveData = 2;
ModemInfo modemInfo = new ModemInfo(1, 2, true, false);
List<ModemInfo> logicalModemList = new ArrayList<>();
logicalModemList.add(modemInfo);
return new PhoneCapability(maxActiveVoiceCalls, maxActiveData,
logicalModemList, false, deviceNrCapabilities);
}
private NetworkScanRequest createNetworkScanRequest(
List<RadioAccessSpecifier> radioAccessSpecifiers) {
return new NetworkScanRequest(
NetworkScanRequest.SCAN_TYPE_ONE_SHOT,
radioAccessSpecifiers.toArray(
new RadioAccessSpecifier[radioAccessSpecifiers.size()]),
mNetworkScanHelper.SEARCH_PERIODICITY_SEC,
mNetworkScanHelper.MAX_SEARCH_TIME_SEC,
mNetworkScanHelper.INCREMENTAL_RESULTS,
mNetworkScanHelper.INCREMENTAL_RESULTS_PERIODICITY_SEC,
null /* List of PLMN ids (MCC-MNC) */);
}
private void startNetworkScan_incremental(boolean waitForCompletion) {
mNetworkScanHelper.startNetworkScan(
NetworkScanHelper.NETWORK_SCAN_TYPE_INCREMENTAL_RESULTS);
if (!waitForCompletion) {
mNetworkScanHelper.stopNetworkQuery();
}
}
}

View File

@@ -83,7 +83,6 @@ public class NetworkSelectSettingsTest {
public Context mContext;
public PreferenceCategory mPreferenceCategory;
public boolean mIsAggregationEnabled = true;
private TargetClass mNetworkSelectSettings;
@@ -104,12 +103,13 @@ public class NetworkSelectSettingsTest {
doReturn(mCellId2).when(mCellInfo2).getCellIdentity();
doReturn(mock(CellSignalStrength.class)).when(mCellInfo2).getCellSignalStrength();
doReturn(CARRIER_NAME2).when(mCellId2).getOperatorAlphaLong();
mIsAggregationEnabled = true;
mNetworkSelectSettings = spy(new TargetClass(this));
PersistableBundle config = new PersistableBundle();
config.putBoolean(CarrierConfigManager.KEY_SHOW_4G_FOR_LTE_DATA_ICON_BOOL, true);
doReturn(config).when(mCarrierConfigManager).getConfigForSubId(SUB_ID);
doReturn(config).when(mCarrierConfigManager).getConfigForSubId(SUB_ID,
CarrierConfigManager.KEY_SHOW_4G_FOR_LTE_DATA_ICON_BOOL,
CarrierConfigManager.KEY_REMOVE_SATELLITE_PLMN_IN_MANUAL_NETWORK_SCAN_BOOL);
doReturn(TelephonyManager.DATA_CONNECTED).when(mTelephonyManager).getDataState();
}
@@ -174,11 +174,6 @@ public class NetworkSelectSettingsTest {
return pref;
}
@Override
protected boolean enableAggregation(Context context) {
return mTestEnv.mIsAggregationEnabled;
}
@Override
protected int getSubId() {
return SUB_ID;
@@ -210,77 +205,7 @@ public class NetworkSelectSettingsTest {
}
@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);
}
@Test
public void doAggregation_hasDuplicateItemsDiffMccMncCase3_removeSamePlmnRatItem() {
mNetworkSelectSettings.onCreateInitialization();
List<CellInfo> testList = Arrays.asList(
createLteCellInfo(false, 123, "123", "232", "CarrierA"),
createLteCellInfo(false, 124, "123", "233", "CarrierA"),
createLteCellInfo(true, 125, "123", "234", "CarrierA"),
createGsmCellInfo(false, 126, "456", "232", "CarrierA"));
List<CellInfo> expected = Arrays.asList(
createLteCellInfo(true, 125, "123", "234", "CarrierA"),
createGsmCellInfo(false, 126, "456", "232", "CarrierA"));
assertThat(mNetworkSelectSettings.doAggregation(testList)).isEqualTo(expected);
}
@Test
public void doAggregation_filterOutSatellitePlmn_whenKeyIsTrue() {
public void filterOutSatellitePlmn_filterOutSatellitePlmn_whenKeyIsTrue() {
PersistableBundle config = new PersistableBundle();
config.putBoolean(
CarrierConfigManager.KEY_REMOVE_SATELLITE_PLMN_IN_MANUAL_NETWORK_SCAN_BOOL, true);
@@ -304,11 +229,11 @@ public class NetworkSelectSettingsTest {
List<CellInfo> expected = Arrays.asList(
createGsmCellInfo(false, 123, "123", "233", "CarrierB"),
createLteCellInfo(false, 1234, "123", "234", "CarrierC"));
assertThat(mNetworkSelectSettings.doAggregation(testList)).isEqualTo(expected);
assertThat(mNetworkSelectSettings.filterOutSatellitePlmn(testList)).isEqualTo(expected);
}
@Test
public void doAggregation_filterOutSatellitePlmn_whenNoSatellitePlmnIsAvailable() {
public void filterOutSatellitePlmn_filterOutSatellitePlmn_whenNoSatellitePlmnIsAvailable() {
PersistableBundle config = new PersistableBundle();
config.putBoolean(
CarrierConfigManager.KEY_REMOVE_SATELLITE_PLMN_IN_MANUAL_NETWORK_SCAN_BOOL, true);
@@ -336,17 +261,17 @@ public class NetworkSelectSettingsTest {
createGsmCellInfo(false, 123, "123", "233", "CarrierB"),
createLteCellInfo(false, 1234, "123", "234", "CarrierC"),
createGsmCellInfo(false, 12345, "123", "235", "CarrierD"));
assertThat(mNetworkSelectSettings.doAggregation(testList)).isEqualTo(expected);
assertThat(mNetworkSelectSettings.filterOutSatellitePlmn(testList)).isEqualTo(expected);
// Expect no filter out when KEY_REMOVE_SATELLITE_PLMN_IN_MANUAL_NETWORK_SCAN_BOOL is false.
config.putBoolean(
CarrierConfigManager.KEY_REMOVE_SATELLITE_PLMN_IN_MANUAL_NETWORK_SCAN_BOOL, false);
mNetworkSelectSettings.onCreateInitialization();
assertThat(mNetworkSelectSettings.doAggregation(testList)).isEqualTo(expected);
assertThat(mNetworkSelectSettings.filterOutSatellitePlmn(testList)).isEqualTo(expected);
}
@Test
public void doAggregation_filterOutSatellitePlmn_whenKeyIsFalse() {
public void filterOutSatellitePlmn_filterOutSatellitePlmn_whenKeyIsFalse() {
PersistableBundle config = new PersistableBundle();
config.putBoolean(
CarrierConfigManager.KEY_REMOVE_SATELLITE_PLMN_IN_MANUAL_NETWORK_SCAN_BOOL, true);
@@ -372,7 +297,7 @@ public class NetworkSelectSettingsTest {
createGsmCellInfo(false, 123, "123", "233", "CarrierB"),
createLteCellInfo(false, 1234, "123", "234", "CarrierC"),
createGsmCellInfo(false, 12345, "123", "235", "CarrierD"));
assertThat(mNetworkSelectSettings.doAggregation(testList)).isEqualTo(expected);
assertThat(mNetworkSelectSettings.filterOutSatellitePlmn(testList)).isEqualTo(expected);
}
private CellInfoLte createLteCellInfo(boolean registered, int cellId, String mcc, String mnc,