Do not notify networkconnect if the connection type is known.

This sometimes happened with sim card has a voice plan but does not have data plan.
Renable the DCHECK.

BUG=
R=glaznev@webrtc.org, pthatcher@webrtc.org

Review URL: https://codereview.webrtc.org/1668673003 .

Cr-Commit-Position: refs/heads/master@{#11479}
This commit is contained in:
Honghai Zhang 2016-02-03 15:12:26 -08:00
parent 45b683f43f
commit 14d024d882
2 changed files with 16 additions and 10 deletions

View File

@ -132,27 +132,25 @@ public class NetworkMonitorAutoDetect extends BroadcastReceiver {
@Override
public void onAvailable(Network network) {
NetworkInformation networkInformation = connectivityManagerDelegate.networkToInfo(network);
Logging.d(TAG, "Network " + networkInformation.name + " with handle " +
networkInformation.handle + " is connected ");
observer.onNetworkConnect(networkInformation);
Logging.d(TAG, "Network becomes available: " + network.toString());
onNetworkChanged(network);
}
@Override
public void onCapabilitiesChanged(
Network network, NetworkCapabilities networkCapabilities) {
// A capabilities change may indicate the ConnectionType has changed,
// so forward the new NetworkInformation along to observer.
NetworkInformation networkInformation = connectivityManagerDelegate.networkToInfo(network);
observer.onNetworkConnect(networkInformation);
// so forward the new NetworkInformation along to the observer.
Logging.d(TAG, "capabilities changed: " + networkCapabilities.toString());
onNetworkChanged(network);
}
@Override
public void onLinkPropertiesChanged(Network network, LinkProperties linkProperties) {
// A link property change may indicate the IP address changes.
// so forward the new NetworkInformation to the observer.
NetworkInformation networkInformation = connectivityManagerDelegate.networkToInfo(network);
observer.onNetworkConnect(networkInformation);
Logging.d(TAG, "link properties changed: " + linkProperties.toString());
onNetworkChanged(network);
}
@Override
@ -169,6 +167,14 @@ public class NetworkMonitorAutoDetect extends BroadcastReceiver {
Logging.d(TAG, "Network with handle " + handle + " is disconnected");
observer.onNetworkDisconnect(handle);
}
private void onNetworkChanged(Network network) {
NetworkInformation networkInformation = connectivityManagerDelegate.networkToInfo(network);
if (networkInformation.type != ConnectionType.CONNECTION_UNKNOWN
&& networkInformation.type != ConnectionType.CONNECTION_NONE) {
observer.onNetworkConnect(networkInformation);
}
}
}
/** Queries the ConnectivityManager for information about the current connection. */

View File

@ -74,7 +74,7 @@ static NetworkType GetNetworkTypeFromJava(JNIEnv* jni, jobject j_network_type) {
static rtc::AdapterType AdapterTypeFromNetworkType(NetworkType network_type) {
switch (network_type) {
case NETWORK_UNKNOWN:
LOG(LS_WARNING) << "Unknown network type";
RTC_DCHECK(false) << "Unknown network type";
return rtc::ADAPTER_TYPE_UNKNOWN;
case NETWORK_ETHERNET:
return rtc::ADAPTER_TYPE_ETHERNET;