Filter out network-change event with a null interface name.
This fixes an Android native crash. This has happened occasionally. BUG= R=glaznev@webrtc.org Review URL: https://codereview.webrtc.org/1771383002 . Cr-Commit-Position: refs/heads/master@{#11919}
This commit is contained in:
@ -156,8 +156,7 @@ public class NetworkMonitorAutoDetect extends BroadcastReceiver {
|
|||||||
|
|
||||||
private void onNetworkChanged(Network network) {
|
private void onNetworkChanged(Network network) {
|
||||||
NetworkInformation networkInformation = connectivityManagerDelegate.networkToInfo(network);
|
NetworkInformation networkInformation = connectivityManagerDelegate.networkToInfo(network);
|
||||||
if (networkInformation.type != ConnectionType.CONNECTION_UNKNOWN
|
if (networkInformation != null) {
|
||||||
&& networkInformation.type != ConnectionType.CONNECTION_NONE) {
|
|
||||||
observer.onNetworkConnect(networkInformation);
|
observer.onNetworkConnect(networkInformation);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -234,8 +233,7 @@ public class NetworkMonitorAutoDetect extends BroadcastReceiver {
|
|||||||
ArrayList<NetworkInformation> netInfoList = new ArrayList<NetworkInformation>();
|
ArrayList<NetworkInformation> netInfoList = new ArrayList<NetworkInformation>();
|
||||||
for (Network network : getAllNetworks()) {
|
for (Network network : getAllNetworks()) {
|
||||||
NetworkInformation info = networkToInfo(network);
|
NetworkInformation info = networkToInfo(network);
|
||||||
if (info.name != null && info.type != ConnectionType.CONNECTION_NONE
|
if (info != null) {
|
||||||
&& info.type != ConnectionType.CONNECTION_UNKNOWN) {
|
|
||||||
netInfoList.add(info);
|
netInfoList.add(info);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -285,10 +283,27 @@ public class NetworkMonitorAutoDetect extends BroadcastReceiver {
|
|||||||
@SuppressLint("NewApi")
|
@SuppressLint("NewApi")
|
||||||
private NetworkInformation networkToInfo(Network network) {
|
private NetworkInformation networkToInfo(Network network) {
|
||||||
LinkProperties linkProperties = connectivityManager.getLinkProperties(network);
|
LinkProperties linkProperties = connectivityManager.getLinkProperties(network);
|
||||||
|
int networkId = networkToNetId(network);
|
||||||
|
if (linkProperties.getInterfaceName() == null) {
|
||||||
|
Logging.w(TAG, "Null interface name for network id " + networkId);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
ConnectionType connectionType = getConnectionType(getNetworkState(network));
|
||||||
|
if (connectionType == ConnectionType.CONNECTION_UNKNOWN
|
||||||
|
|| connectionType == ConnectionType.CONNECTION_NONE) {
|
||||||
|
// This may not be an error. The OS may signal a network event with connection type
|
||||||
|
// NONE when the network disconnects. But in some devices, the OS may incorrectly
|
||||||
|
// report an UNKNOWN connection type. In either case, it won't benefit to send down
|
||||||
|
// a network event with this connection type.
|
||||||
|
Logging.d(TAG, "Network with id " + networkId + " has connection type " + connectionType);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
NetworkInformation networkInformation = new NetworkInformation(
|
NetworkInformation networkInformation = new NetworkInformation(
|
||||||
linkProperties.getInterfaceName(),
|
linkProperties.getInterfaceName(),
|
||||||
getConnectionType(getNetworkState(network)),
|
connectionType,
|
||||||
networkToNetId(network),
|
networkId,
|
||||||
getIPAddresses(linkProperties));
|
getIPAddresses(linkProperties));
|
||||||
return networkInformation;
|
return networkInformation;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user