From 97aacee11d21caa4ca9c40c493aeba6940a7c063 Mon Sep 17 00:00:00 2001 From: honghaiz Date: Tue, 8 Mar 2016 20:50:00 -0800 Subject: [PATCH] Filter out the network in networkmonitor if the linkProperties is null. It may be null if the network is unknown. Also revised the logging to replace network id with network.toString(). They are pretty much the same for logging but network.toString does not need to parse the int value. BUG= Review URL: https://codereview.webrtc.org/1774343002 Cr-Commit-Position: refs/heads/master@{#11925} --- .../org/webrtc/NetworkMonitorAutoDetect.java | 21 +++++++++++-------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/webrtc/api/java/android/org/webrtc/NetworkMonitorAutoDetect.java b/webrtc/api/java/android/org/webrtc/NetworkMonitorAutoDetect.java index 3045280cc4..e0af09ba86 100644 --- a/webrtc/api/java/android/org/webrtc/NetworkMonitorAutoDetect.java +++ b/webrtc/api/java/android/org/webrtc/NetworkMonitorAutoDetect.java @@ -143,15 +143,14 @@ public class NetworkMonitorAutoDetect extends BroadcastReceiver { public void onLosing(Network network, int maxMsToLive) { // Tell the network is going to lose in MaxMsToLive milliseconds. // We may use this signal later. - Logging.d(TAG, "Network with handle " + networkToNetId(network) + - " is about to lose in " + maxMsToLive + "ms"); + Logging.d(TAG, + "Network " + network.toString() + " is about to lose in " + maxMsToLive + "ms"); } @Override public void onLost(Network network) { - int handle = networkToNetId(network); - Logging.d(TAG, "Network with handle " + handle + " is disconnected"); - observer.onNetworkDisconnect(handle); + Logging.d(TAG, "Network " + network.toString() + " is disconnected"); + observer.onNetworkDisconnect(networkToNetId(network)); } private void onNetworkChanged(Network network) { @@ -283,9 +282,13 @@ public class NetworkMonitorAutoDetect extends BroadcastReceiver { @SuppressLint("NewApi") private NetworkInformation networkToInfo(Network network) { LinkProperties linkProperties = connectivityManager.getLinkProperties(network); - int networkId = networkToNetId(network); + // getLinkProperties will return null if the network is unknown. + if (linkProperties == null) { + Logging.w(TAG, "Detected unknown network: " + network.toString()); + return null; + } if (linkProperties.getInterfaceName() == null) { - Logging.w(TAG, "Null interface name for network id " + networkId); + Logging.w(TAG, "Null interface name for network " + network.toString()); return null; } @@ -296,14 +299,14 @@ public class NetworkMonitorAutoDetect extends BroadcastReceiver { // 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); + Logging.d(TAG, "Network " + network.toString() + " has connection type " + connectionType); return null; } NetworkInformation networkInformation = new NetworkInformation( linkProperties.getInterfaceName(), connectionType, - networkId, + networkToNetId(network), getIPAddresses(linkProperties)); return networkInformation; }