Android: Generate JNI code for androidnetworkmonitor_jni

Bug: webrtc:8278
Change-Id: I8447b2de5ec2610760f7112b6f86e54d94325322
Reviewed-on: https://webrtc-review.googlesource.com/24520
Reviewed-by: Sami Kalliomäki <sakal@webrtc.org>
Commit-Queue: Magnus Jedvert <magjed@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#20796}
This commit is contained in:
Magnus Jedvert
2017-11-20 14:35:51 +01:00
committed by Commit Bot
parent 202be3957d
commit 768e1c0ea1
5 changed files with 103 additions and 110 deletions

View File

@ -63,6 +63,7 @@ public class NetworkMonitor {
/**
* Returns the singleton instance.
*/
@CalledByNative
public static NetworkMonitor getInstance() {
if (instance == null) {
instance = new NetworkMonitor();
@ -77,12 +78,11 @@ public class NetworkMonitor {
}
/**
* Called by the native code.
*
* Enables auto detection of the current network state based on notifications
* from the system. Note that this requires the embedding app have the
* platform ACCESS_NETWORK_STATE permission.
*/
@CalledByNative
private void startMonitoring(long nativeObserver) {
Logging.d(TAG, "Start monitoring from native observer " + nativeObserver);
nativeNetworkObservers.add(nativeObserver);
@ -96,7 +96,7 @@ public class NetworkMonitor {
updateObserverActiveNetworkList(nativeObserver);
}
// Called by the native code.
@CalledByNative
private void stopMonitoring(long nativeObserver) {
Logging.d(TAG, "Stop monitoring from native observer " + nativeObserver);
nativeNetworkObservers.remove(nativeObserver);
@ -106,13 +106,13 @@ public class NetworkMonitor {
}
}
// Called by the native code to determine if network binding is supported
// on this platform.
// Returns true if network binding is supported on this platform.
@CalledByNative
private boolean networkBindingSupported() {
return autoDetector != null && autoDetector.supportNetworkCallback();
}
// Called by the native code to get the Android SDK version.
@CalledByNative
private static int androidSdkInt() {
return Build.VERSION.SDK_INT;
}
@ -215,9 +215,16 @@ public class NetworkMonitor {
return connectionType != ConnectionType.CONNECTION_NONE;
}
@NativeClassQualifiedName("webrtc::jni::AndroidNetworkMonitor")
private native void nativeNotifyConnectionTypeChanged(long nativePtr);
@NativeClassQualifiedName("webrtc::jni::AndroidNetworkMonitor")
private native void nativeNotifyOfNetworkConnect(long nativePtr, NetworkInformation networkInfo);
@NativeClassQualifiedName("webrtc::jni::AndroidNetworkMonitor")
private native void nativeNotifyOfNetworkDisconnect(long nativePtr, long networkHandle);
@NativeClassQualifiedName("webrtc::jni::AndroidNetworkMonitor")
private native void nativeNotifyOfActiveNetworkList(
long nativePtr, NetworkInformation[] networkInfos);

View File

@ -62,6 +62,11 @@ public class NetworkMonitorAutoDetect extends BroadcastReceiver {
public IPAddress(byte[] address) {
this.address = address;
}
@CalledByNative("IPAddress")
private byte[] getAddress() {
return address;
}
}
/** Java version of NetworkMonitor.NetworkInformation */
@ -77,6 +82,26 @@ public class NetworkMonitorAutoDetect extends BroadcastReceiver {
this.handle = handle;
this.ipAddresses = addresses;
}
@CalledByNative("NetworkInformation")
private IPAddress[] getIpAddresses() {
return ipAddresses;
}
@CalledByNative("NetworkInformation")
private ConnectionType getConnectionType() {
return type;
}
@CalledByNative("NetworkInformation")
private long getHandle() {
return handle;
}
@CalledByNative("NetworkInformation")
private String getName() {
return name;
}
};
static class NetworkState {