Return "not implemented" error from BindSocketToNetwork properly.
Previously, was only checking the Android SDK version. But it also needs to check for the presence of the connectivity manager service. BUG=webrtc:7026 Review-Url: https://codereview.webrtc.org/2697943002 Cr-Commit-Position: refs/heads/master@{#16631}
This commit is contained in:
@ -114,6 +114,12 @@ public class NetworkMonitor {
|
|||||||
nativeNetworkObservers.remove(nativeObserver);
|
nativeNetworkObservers.remove(nativeObserver);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Called by the native code to determine if network binding is supported
|
||||||
|
// on this platform.
|
||||||
|
private boolean networkBindingSupported() {
|
||||||
|
return autoDetector != null && autoDetector.supportNetworkCallback();
|
||||||
|
}
|
||||||
|
|
||||||
// Called by the native code to get the Android SDK version.
|
// Called by the native code to get the Android SDK version.
|
||||||
private static int androidSdkInt() {
|
private static int androidSdkInt() {
|
||||||
return Build.VERSION.SDK_INT;
|
return Build.VERSION.SDK_INT;
|
||||||
|
|||||||
@ -469,6 +469,10 @@ public class NetworkMonitorAutoDetect extends BroadcastReceiver {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean supportNetworkCallback() {
|
||||||
|
return connectivityManagerDelegate.supportNetworkCallback();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Allows overriding the ConnectivityManagerDelegate for tests.
|
* Allows overriding the ConnectivityManagerDelegate for tests.
|
||||||
*/
|
*/
|
||||||
|
|||||||
@ -240,13 +240,18 @@ rtc::NetworkBindingResult AndroidNetworkMonitor::BindSocketToNetwork(
|
|||||||
int socket_fd,
|
int socket_fd,
|
||||||
const rtc::IPAddress& address) {
|
const rtc::IPAddress& address) {
|
||||||
RTC_CHECK(thread_checker_.CalledOnValidThread());
|
RTC_CHECK(thread_checker_.CalledOnValidThread());
|
||||||
|
|
||||||
|
jmethodID network_binding_supported_id = GetMethodID(
|
||||||
|
jni(), *j_network_monitor_class_, "networkBindingSupported", "()Z");
|
||||||
// Android prior to Lollipop didn't have support for binding sockets to
|
// Android prior to Lollipop didn't have support for binding sockets to
|
||||||
// networks. In that case it should not have reached here because
|
// networks. This may also occur if there is no connectivity manager service.
|
||||||
// |network_handle_by_address_| is only populated in Android Lollipop
|
bool network_binding_supported = jni()->CallBooleanMethod(
|
||||||
// and above.
|
*j_network_monitor_, network_binding_supported_id);
|
||||||
if (android_sdk_int_ < SDK_VERSION_LOLLIPOP) {
|
CHECK_EXCEPTION(jni())
|
||||||
LOG(LS_ERROR) << "BindSocketToNetwork is not supported in Android SDK "
|
<< "Error during NetworkMonitor.networkBindingSupported";
|
||||||
<< android_sdk_int_;
|
if (!network_binding_supported) {
|
||||||
|
LOG(LS_WARNING) << "BindSocketToNetwork is not supported on this platform "
|
||||||
|
<< "(Android SDK: " << android_sdk_int_ << ")";
|
||||||
return rtc::NetworkBindingResult::NOT_IMPLEMENTED;
|
return rtc::NetworkBindingResult::NOT_IMPLEMENTED;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user