Merge "Network selection add NGRAN when device support SA" into sc-dev am: a73d199d5e

Original change: https://googleplex-android-review.googlesource.com/c/platform/packages/apps/Settings/+/15210394

Change-Id: I1dfb9507da126f8e25ba12535581d40801837d89
This commit is contained in:
SongFerng Wang
2021-07-08 08:30:06 +00:00
committed by Automerger Merge Worker
2 changed files with 119 additions and 19 deletions

View File

@@ -21,11 +21,14 @@ import android.telephony.AccessNetworkConstants.AccessNetworkType;
import android.telephony.CellInfo; import android.telephony.CellInfo;
import android.telephony.NetworkScan; import android.telephony.NetworkScan;
import android.telephony.NetworkScanRequest; import android.telephony.NetworkScanRequest;
import android.telephony.PhoneCapability;
import android.telephony.RadioAccessSpecifier; import android.telephony.RadioAccessSpecifier;
import android.telephony.TelephonyManager; import android.telephony.TelephonyManager;
import android.telephony.TelephonyScanManager; import android.telephony.TelephonyScanManager;
import android.util.Log; import android.util.Log;
import androidx.annotation.VisibleForTesting;
import com.android.internal.telephony.CellNetworkScanResult; import com.android.internal.telephony.CellNetworkScanResult;
import com.google.common.util.concurrent.FutureCallback; import com.google.common.util.concurrent.FutureCallback;
@@ -37,6 +40,7 @@ import com.google.common.util.concurrent.SettableFuture;
import java.lang.annotation.Retention; import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy; import java.lang.annotation.RetentionPolicy;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays;
import java.util.List; import java.util.List;
import java.util.concurrent.CancellationException; import java.util.concurrent.CancellationException;
import java.util.concurrent.Executor; import java.util.concurrent.Executor;
@@ -111,10 +115,14 @@ public class NetworkScanHelper {
public static final int NETWORK_SCAN_TYPE_INCREMENTAL_RESULTS = 2; public static final int NETWORK_SCAN_TYPE_INCREMENTAL_RESULTS = 2;
/** The constants below are used in the async network scan. */ /** The constants below are used in the async network scan. */
private static final boolean INCREMENTAL_RESULTS = true; @VisibleForTesting
private static final int SEARCH_PERIODICITY_SEC = 5; static final boolean INCREMENTAL_RESULTS = true;
private static final int MAX_SEARCH_TIME_SEC = 300; @VisibleForTesting
private static final int INCREMENTAL_RESULTS_PERIODICITY_SEC = 3; static final int SEARCH_PERIODICITY_SEC = 5;
@VisibleForTesting
static final int MAX_SEARCH_TIME_SEC = 300;
@VisibleForTesting
static final int INCREMENTAL_RESULTS_PERIODICITY_SEC = 3;
private final NetworkScanCallback mNetworkScanCallback; private final NetworkScanCallback mNetworkScanCallback;
private final TelephonyManager mTelephonyManager; private final TelephonyManager mTelephonyManager;
@@ -133,7 +141,8 @@ public class NetworkScanHelper {
mExecutor = executor; mExecutor = executor;
} }
private NetworkScanRequest createNetworkScanForPreferredAccessNetworks() { @VisibleForTesting
NetworkScanRequest createNetworkScanForPreferredAccessNetworks() {
long networkTypeBitmap3gpp = mTelephonyManager.getPreferredNetworkTypeBitmask() long networkTypeBitmap3gpp = mTelephonyManager.getPreferredNetworkTypeBitmask()
& TelephonyManager.NETWORK_STANDARDS_FAMILY_BITMASK_3GPP; & TelephonyManager.NETWORK_STANDARDS_FAMILY_BITMASK_3GPP;
@@ -161,14 +170,13 @@ public class NetworkScanHelper {
// a 5G network, which means that it shouldn't scan for 5G at the expense of battery as // a 5G network, which means that it shouldn't scan for 5G at the expense of battery as
// part of the manual network selection process. // part of the manual network selection process.
// //
// FIXME(b/151119451): re-enable this code once there is a way to distinguish SA from NSA if (networkTypeBitmap3gpp == 0
// support in the modem. || (hasNrSaCapability()
// && (networkTypeBitmap3gpp & TelephonyManager.NETWORK_CLASS_BITMASK_5G) != 0)) {
// if (networkTypeBitmap3gpp == 0 radioAccessSpecifiers.add(
// || (networkTypeBitmap3gpp & TelephonyManager.NETWORK_CLASS_BITMASK_5G) != 0) { new RadioAccessSpecifier(AccessNetworkType.NGRAN, null, null));
// radioAccessSpecifiers.add( Log.d(TAG, "radioAccessSpecifiers add NGRAN.");
// new RadioAccessSpecifier(AccessNetworkType.NGRAN, null, null)); }
// }
return new NetworkScanRequest( return new NetworkScanRequest(
NetworkScanRequest.SCAN_TYPE_ONE_SHOT, NetworkScanRequest.SCAN_TYPE_ONE_SHOT,
@@ -253,6 +261,12 @@ public class NetworkScanHelper {
mNetworkScanCallback.onError(errCode); mNetworkScanCallback.onError(errCode);
} }
private boolean hasNrSaCapability() {
return Arrays.stream(
mTelephonyManager.getPhoneCapability().getDeviceNrCapabilities())
.anyMatch(i -> i == PhoneCapability.DEVICE_NR_CAPABILITY_SA);
}
/** /**
* Converts the status code of {@link CellNetworkScanResult} to one of the * Converts the status code of {@link CellNetworkScanResult} to one of the
* {@link NetworkScan.ScanErrorCode}. * {@link NetworkScan.ScanErrorCode}.

View File

@@ -1,5 +1,5 @@
/* /*
* Copyright (C) 2019 The Android Open Source Project * Copyright (C) 2021 The Android Open Source Project
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@@ -18,6 +18,7 @@ package com.android.settings.network.telephony;
import static com.google.common.truth.Truth.assertThat; 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.any;
import static org.mockito.ArgumentMatchers.anyInt; import static org.mockito.ArgumentMatchers.anyInt;
import static org.mockito.Mockito.doAnswer; import static org.mockito.Mockito.doAnswer;
@@ -27,12 +28,18 @@ import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify; import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when; import static org.mockito.Mockito.when;
import android.telephony.AccessNetworkConstants;
import android.telephony.CellInfo; import android.telephony.CellInfo;
import android.telephony.ModemInfo;
import android.telephony.NetworkScan; import android.telephony.NetworkScan;
import android.telephony.NetworkScanRequest; import android.telephony.NetworkScanRequest;
import android.telephony.PhoneCapability;
import android.telephony.RadioAccessSpecifier;
import android.telephony.TelephonyManager; import android.telephony.TelephonyManager;
import android.telephony.TelephonyScanManager; import android.telephony.TelephonyScanManager;
import androidx.test.ext.junit.runners.AndroidJUnit4;
import org.junit.Before; import org.junit.Before;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
@@ -41,22 +48,20 @@ import org.mockito.Mock;
import org.mockito.MockitoAnnotations; import org.mockito.MockitoAnnotations;
import org.mockito.invocation.InvocationOnMock; import org.mockito.invocation.InvocationOnMock;
import org.mockito.stubbing.Answer; import org.mockito.stubbing.Answer;
import org.robolectric.RobolectricTestRunner;
import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.concurrent.Executor; import java.util.concurrent.Executor;
import java.util.concurrent.ExecutorService; import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors; import java.util.concurrent.Executors;
@RunWith(RobolectricTestRunner.class) @RunWith(AndroidJUnit4.class)
public class NetworkScanHelperTest { public class NetworkScanHelperTest {
@Mock @Mock
private TelephonyManager mTelephonyManager; private TelephonyManager mTelephonyManager;
@Mock @Mock
private List<CellInfo> mCellInfos; private List<CellInfo> mCellInfos;
@Mock @Mock
private NetworkScanHelper.NetworkScanCallback mNetworkScanCallback; private NetworkScanHelper.NetworkScanCallback mNetworkScanCallback;
@@ -70,7 +75,7 @@ public class NetworkScanHelperTest {
private NetworkScan mNetworkScan; private NetworkScan mNetworkScan;
private class NetworkScanMock extends NetworkScan { public class NetworkScanMock extends NetworkScan {
NetworkScanMock(int scanId, int subId) { NetworkScanMock(int scanId, int subId) {
super(scanId, subId); super(scanId, subId);
} }
@@ -163,6 +168,87 @@ public class NetworkScanHelperTest {
verify(mNetworkScan, times(1)).stopScan(); 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) { private void startNetworkScan_incremental(boolean waitForCompletion) {
mNetworkScanHelper.startNetworkScan( mNetworkScanHelper.startNetworkScan(
NetworkScanHelper.NETWORK_SCAN_TYPE_INCREMENTAL_RESULTS); NetworkScanHelper.NETWORK_SCAN_TYPE_INCREMENTAL_RESULTS);