This helps recognize more network types
and even if the "unknown" network type is not helpful for identifying the network type, it helps bind sockets to the network. BUG= R=glaznev@webrtc.org Review URL: https://codereview.webrtc.org/2112963002 . Cr-Commit-Position: refs/heads/master@{#13351}
This commit is contained in:
parent
b59ff8952f
commit
e59122889f
@ -231,8 +231,7 @@ public class NetworkMonitor {
|
||||
*/
|
||||
public static boolean isOnline() {
|
||||
ConnectionType connectionType = getInstance().getCurrentConnectionType();
|
||||
return connectionType != ConnectionType.CONNECTION_UNKNOWN
|
||||
&& connectionType != ConnectionType.CONNECTION_NONE;
|
||||
return connectionType != ConnectionType.CONNECTION_NONE;
|
||||
}
|
||||
|
||||
private native void nativeNotifyConnectionTypeChanged(long nativePtr);
|
||||
|
||||
@ -55,6 +55,7 @@ public class NetworkMonitorAutoDetect extends BroadcastReceiver {
|
||||
CONNECTION_4G,
|
||||
CONNECTION_3G,
|
||||
CONNECTION_2G,
|
||||
CONNECTION_UNKNOWN_CELLULAR,
|
||||
CONNECTION_BLUETOOTH,
|
||||
CONNECTION_NONE
|
||||
}
|
||||
@ -292,17 +293,24 @@ public class NetworkMonitorAutoDetect extends BroadcastReceiver {
|
||||
return null;
|
||||
}
|
||||
|
||||
ConnectionType connectionType = getConnectionType(getNetworkState(network));
|
||||
if (connectionType == ConnectionType.CONNECTION_UNKNOWN
|
||||
|| connectionType == ConnectionType.CONNECTION_NONE) {
|
||||
NetworkState networkState = getNetworkState(network);
|
||||
ConnectionType connectionType = getConnectionType(networkState);
|
||||
if (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 " + network.toString() + " has connection type " + connectionType);
|
||||
// NONE when the network disconnects.
|
||||
Logging.d(TAG, "Network " + network.toString() + " is disconnected");
|
||||
return null;
|
||||
}
|
||||
|
||||
// Some android device may return a CONNECTION_UNKNOWN_CELLULAR or CONNECTION_UNKNOWN type,
|
||||
// which appears to be usable. Just log them here.
|
||||
if (connectionType == ConnectionType.CONNECTION_UNKNOWN
|
||||
|| connectionType == ConnectionType.CONNECTION_UNKNOWN_CELLULAR) {
|
||||
Logging.d(TAG, "Network " + network.toString() + " connection type is " + connectionType
|
||||
+ " because it has type " + networkState.getNetworkType()
|
||||
+ " and subtype " + networkState.getNetworkSubType());
|
||||
}
|
||||
|
||||
NetworkInformation networkInformation = new NetworkInformation(
|
||||
linkProperties.getInterfaceName(),
|
||||
connectionType,
|
||||
@ -569,7 +577,7 @@ public class NetworkMonitorAutoDetect extends BroadcastReceiver {
|
||||
case TelephonyManager.NETWORK_TYPE_LTE:
|
||||
return ConnectionType.CONNECTION_4G;
|
||||
default:
|
||||
return ConnectionType.CONNECTION_UNKNOWN;
|
||||
return ConnectionType.CONNECTION_UNKNOWN_CELLULAR;
|
||||
}
|
||||
default:
|
||||
return ConnectionType.CONNECTION_UNKNOWN;
|
||||
|
||||
@ -44,6 +44,9 @@ static NetworkType GetNetworkTypeFromJava(JNIEnv* jni, jobject j_network_type) {
|
||||
if (enum_name == "CONNECTION_2G") {
|
||||
return NetworkType::NETWORK_2G;
|
||||
}
|
||||
if (enum_name == "CONNECTION_UNKNOWN_CELLULAR") {
|
||||
return NetworkType::NETWORK_UNKNOWN_CELLULAR;
|
||||
}
|
||||
if (enum_name == "CONNECTION_BLUETOOTH") {
|
||||
return NetworkType::NETWORK_BLUETOOTH;
|
||||
}
|
||||
@ -57,7 +60,6 @@ static NetworkType GetNetworkTypeFromJava(JNIEnv* jni, jobject j_network_type) {
|
||||
static rtc::AdapterType AdapterTypeFromNetworkType(NetworkType network_type) {
|
||||
switch (network_type) {
|
||||
case NETWORK_UNKNOWN:
|
||||
RTC_DCHECK(false) << "Unknown network type";
|
||||
return rtc::ADAPTER_TYPE_UNKNOWN;
|
||||
case NETWORK_ETHERNET:
|
||||
return rtc::ADAPTER_TYPE_ETHERNET;
|
||||
@ -66,6 +68,7 @@ static rtc::AdapterType AdapterTypeFromNetworkType(NetworkType network_type) {
|
||||
case NETWORK_4G:
|
||||
case NETWORK_3G:
|
||||
case NETWORK_2G:
|
||||
case NETWORK_UNKNOWN_CELLULAR:
|
||||
return rtc::ADAPTER_TYPE_CELLULAR;
|
||||
case NETWORK_BLUETOOTH:
|
||||
// There is no corresponding mapping for bluetooth networks.
|
||||
|
||||
@ -31,6 +31,7 @@ enum NetworkType {
|
||||
NETWORK_4G,
|
||||
NETWORK_3G,
|
||||
NETWORK_2G,
|
||||
NETWORK_UNKNOWN_CELLULAR,
|
||||
NETWORK_BLUETOOTH,
|
||||
NETWORK_NONE
|
||||
};
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user