Reland "Android: Generate JNI code for androidnetworkmonitor_jni"

This reverts commit 522c1bc6bb945d66bf77f175da48e1644d74511e.

Reason for revert: Reland with a temporary fix.

Original change's description:
> Revert "Android: Generate JNI code for androidnetworkmonitor_jni"
> 
> This reverts commit 768e1c0ea1f2077675df31915132a0557aca400e.
> 
> Reason for revert: Breaks AppRTCMobile.
> 
> Original change's description:
> > 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}
> 
> TBR=magjed@webrtc.org,sakal@webrtc.org
> 
> Change-Id: I45f8d19abd81386872b7c095ac7eca21fa06077c
> No-Presubmit: true
> No-Tree-Checks: true
> No-Try: true
> Bug: webrtc:8278,webrtc:8556
> Reviewed-on: https://webrtc-review.googlesource.com/24622
> Reviewed-by: Magnus Jedvert <magjed@webrtc.org>
> Commit-Queue: Magnus Jedvert <magjed@webrtc.org>
> Cr-Commit-Position: refs/heads/master@{#20800}

TBR=magjed@webrtc.org,sakal@webrtc.org

Change-Id: I7cc404993addb17f0397127a10aac67476ef6ff4
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Bug: webrtc:8278, webrtc:8556
Reviewed-on: https://webrtc-review.googlesource.com/24623
Commit-Queue: Magnus Jedvert <magjed@webrtc.org>
Reviewed-by: Magnus Jedvert <magjed@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#20801}
This commit is contained in:
Magnus Jedvert
2017-11-20 21:55:27 +01:00
committed by Commit Bot
parent 522c1bc6bb
commit cada60193d
5 changed files with 104 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

@ -35,6 +35,7 @@ import java.net.SocketException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import org.webrtc.NetworkMonitorAutoDetect;
/**
* Borrowed from Chromium's
@ -62,6 +63,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 +83,26 @@ public class NetworkMonitorAutoDetect extends BroadcastReceiver {
this.handle = handle;
this.ipAddresses = addresses;
}
@CalledByNative("NetworkInformation")
private IPAddress[] getIpAddresses() {
return ipAddresses;
}
@CalledByNative("NetworkInformation")
private NetworkMonitorAutoDetect.ConnectionType getConnectionType() {
return type;
}
@CalledByNative("NetworkInformation")
private long getHandle() {
return handle;
}
@CalledByNative("NetworkInformation")
private String getName() {
return name;
}
};
static class NetworkState {