Remove the network with empty name or NONE connection type from the network list.
In some device (e.g. Galaxy s6), the OS returns a list of network containing one that has empty network name or NONE connection type, which cannot be used and cause crash to the app. BUG= Review URL: https://codereview.webrtc.org/1655313005 Cr-Commit-Position: refs/heads/master@{#11482}
This commit is contained in:
parent
fc5fc1e9b3
commit
9031d6366f
@ -36,6 +36,7 @@ import org.webrtc.Logging;
|
||||
import android.content.Context;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Borrowed from Chromium's src/net/android/java/src/org/chromium/net/NetworkChangeNotifier.java
|
||||
@ -208,10 +209,13 @@ public class NetworkMonitor {
|
||||
}
|
||||
|
||||
private void updateActiveNetworkList() {
|
||||
NetworkInformation[] networkInfos = autoDetector.getActiveNetworkList();
|
||||
if (networkInfos.length == 0) {
|
||||
List<NetworkInformation> networkInfoList = autoDetector.getActiveNetworkList();
|
||||
if (networkInfoList == null || networkInfoList.size() == 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
NetworkInformation[] networkInfos = new NetworkInformation[networkInfoList.size()];
|
||||
networkInfos = networkInfoList.toArray(networkInfos);
|
||||
for (long nativeObserver : nativeNetworkObservers) {
|
||||
nativeNotifyOfActiveNetworkList(nativeObserver, networkInfos);
|
||||
}
|
||||
|
||||
@ -53,6 +53,9 @@ import android.net.wifi.WifiManager;
|
||||
import android.os.Build;
|
||||
import android.telephony.TelephonyManager;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Borrowed from Chromium's
|
||||
* src/net/android/java/src/org/chromium/net/NetworkChangeNotifierAutoDetect.java
|
||||
@ -241,16 +244,19 @@ public class NetworkMonitorAutoDetect extends BroadcastReceiver {
|
||||
return connectivityManager.getAllNetworks();
|
||||
}
|
||||
|
||||
NetworkInformation[] getActiveNetworkList() {
|
||||
List<NetworkInformation> getActiveNetworkList() {
|
||||
if (!supportNetworkCallback()) {
|
||||
return new NetworkInformation[0];
|
||||
return null;
|
||||
}
|
||||
Network[] networks = getAllNetworks();
|
||||
NetworkInformation[] netInfos = new NetworkInformation[networks.length];
|
||||
for (int i = 0; i < networks.length; ++i) {
|
||||
netInfos[i] = networkToInfo(networks[i]);
|
||||
ArrayList<NetworkInformation> netInfoList = new ArrayList<NetworkInformation>();
|
||||
for (Network network : getAllNetworks()) {
|
||||
NetworkInformation info = networkToInfo(network);
|
||||
if (info.name != null && info.type != ConnectionType.CONNECTION_NONE
|
||||
&& info.type != ConnectionType.CONNECTION_UNKNOWN) {
|
||||
netInfoList.add(info);
|
||||
}
|
||||
}
|
||||
return netInfos;
|
||||
return netInfoList;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -470,7 +476,7 @@ public class NetworkMonitorAutoDetect extends BroadcastReceiver {
|
||||
return isRegistered;
|
||||
}
|
||||
|
||||
NetworkInformation[] getActiveNetworkList() {
|
||||
List<NetworkInformation> getActiveNetworkList() {
|
||||
return connectivityManagerDelegate.getActiveNetworkList();
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user