Optimize NetworkScan for only User-Enabled RANs

Network scans comprise multiple different access
technologies, and scanning each of those techs can
be very time consuming. Worse, depending on a user's
settings, the device may only be allowed to connect
to 2G, 2G+3G, or 2G+3G+4G networks. If a scan finds
network types that a user can't connect to, it also
creates a poor user experience if a user tries to
select those network types.

This CL restricts the scans to only find and return
results that a user can select based on the other
user settings.

Bug: 128572818
Test: manual (crosshatch) - set allowed networks to
 2G+3G and verify that LTE networks are not returned.
 Set allowed networks to 2G+3G+4G and verify that LTE
 networks are returned.

Merged-In: Ic855100723b8604c1e872457a70fd8f25d225278
Change-Id: Ic855100723b8604c1e872457a70fd8f25d225278
(cherry picked from commit bda277b3b6)
This commit is contained in:
Nathan Harold
2019-10-01 18:01:51 -07:00
parent 7b9101e6a8
commit b10babebd0

View File

@@ -25,6 +25,7 @@ import android.telephony.TelephonyManager;
import android.telephony.TelephonyScanManager;
import android.util.Log;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.Executor;
@@ -75,37 +76,6 @@ public class NetworkScanHelper {
private static final int MAX_SEARCH_TIME_SEC = 300;
private static final int INCREMENTAL_RESULTS_PERIODICITY_SEC = 3;
private static final NetworkScanRequest NETWORK_SCAN_REQUEST =
new NetworkScanRequest(
NetworkScanRequest.SCAN_TYPE_ONE_SHOT,
new RadioAccessSpecifier[]{
// GSM
new RadioAccessSpecifier(
AccessNetworkType.GERAN,
null /* bands */,
null /* channels */),
// LTE
new RadioAccessSpecifier(
AccessNetworkType.EUTRAN,
null /* bands */,
null /* channels */),
// WCDMA
new RadioAccessSpecifier(
AccessNetworkType.UTRAN,
null /* bands */,
null /* channels */),
// NR
new RadioAccessSpecifier(
AccessNetworkType.NGRAN,
null /* bands */,
null /* channels */)
},
SEARCH_PERIODICITY_SEC,
MAX_SEARCH_TIME_SEC,
INCREMENTAL_RESULTS,
INCREMENTAL_RESULTS_PERIODICITY_SEC,
null /* List of PLMN ids (MCC-MNC) */);
private final NetworkScanCallback mNetworkScanCallback;
private final TelephonyManager mTelephonyManager;
private final TelephonyScanManager.NetworkScanCallback mInternalNetworkScanCallback;
@@ -120,6 +90,47 @@ public class NetworkScanHelper {
mExecutor = executor;
}
private NetworkScanRequest createNetworkScanForPreferredAccessNetworks() {
long networkTypeBitmap3gpp = mTelephonyManager.getPreferredNetworkTypeBitmask()
& TelephonyManager.NETWORK_STANDARDS_FAMILY_BITMASK_3GPP;
List<RadioAccessSpecifier> radioAccessSpecifiers = new ArrayList<>();
// If the allowed network types are unknown or if they are of the right class, scan for
// them; otherwise, skip them to save scan time and prevent users from being shown networks
// that they can't connect to.
if (networkTypeBitmap3gpp == 0
|| (networkTypeBitmap3gpp & TelephonyManager.NETWORK_CLASS_BITMASK_2G) != 0) {
radioAccessSpecifiers.add(
new RadioAccessSpecifier(AccessNetworkType.GERAN, null, null));
}
if (networkTypeBitmap3gpp == 0
|| (networkTypeBitmap3gpp & TelephonyManager.NETWORK_CLASS_BITMASK_3G) != 0) {
radioAccessSpecifiers.add(
new RadioAccessSpecifier(AccessNetworkType.UTRAN, null, null));
}
if (networkTypeBitmap3gpp == 0
|| (networkTypeBitmap3gpp & TelephonyManager.NETWORK_CLASS_BITMASK_4G) != 0) {
radioAccessSpecifiers.add(
new RadioAccessSpecifier(AccessNetworkType.EUTRAN, null, null));
}
if (networkTypeBitmap3gpp == 0
|| (networkTypeBitmap3gpp & TelephonyManager.NETWORK_CLASS_BITMASK_5G) != 0) {
radioAccessSpecifiers.add(
new RadioAccessSpecifier(AccessNetworkType.NGRAN, null, null));
}
return new NetworkScanRequest(
NetworkScanRequest.SCAN_TYPE_ONE_SHOT,
radioAccessSpecifiers.toArray(
new RadioAccessSpecifier[radioAccessSpecifiers.size()]),
SEARCH_PERIODICITY_SEC,
MAX_SEARCH_TIME_SEC,
INCREMENTAL_RESULTS,
INCREMENTAL_RESULTS_PERIODICITY_SEC,
null /* List of PLMN ids (MCC-MNC) */);
}
/**
* Request a network scan.
*
@@ -134,7 +145,7 @@ public class NetworkScanHelper {
return;
}
mNetworkScanRequester = mTelephonyManager.requestNetworkScan(
NETWORK_SCAN_REQUEST,
createNetworkScanForPreferredAccessNetworks(),
mExecutor,
mInternalNetworkScanCallback);
if (mNetworkScanRequester == null) {