| OLD | NEW |
| 1 /* | 1 /* |
| 2 * libjingle | 2 * libjingle |
| 3 * Copyright 2015 Google Inc. | 3 * Copyright 2015 Google Inc. |
| 4 * | 4 * |
| 5 * Redistribution and use in source and binary forms, with or without | 5 * Redistribution and use in source and binary forms, with or without |
| 6 * modification, are permitted provided that the following conditions are met: | 6 * modification, are permitted provided that the following conditions are met: |
| 7 * | 7 * |
| 8 * 1. Redistributions of source code must retain the above copyright notice, | 8 * 1. Redistributions of source code must retain the above copyright notice, |
| 9 * this list of conditions and the following disclaimer. | 9 * this list of conditions and the following disclaimer. |
| 10 * 2. Redistributions in binary form must reproduce the above copyright notice, | 10 * 2. Redistributions in binary form must reproduce the above copyright notice, |
| (...skipping 12 matching lines...) Expand all Loading... |
| 23 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR | 23 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR |
| 24 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF | 24 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF |
| 25 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 25 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 26 */ | 26 */ |
| 27 | 27 |
| 28 #ifndef TALK_APP_WEBRTC_JAVA_JNI_ANDROIDNETWORKMONITOR_JNI_H_ | 28 #ifndef TALK_APP_WEBRTC_JAVA_JNI_ANDROIDNETWORKMONITOR_JNI_H_ |
| 29 #define TALK_APP_WEBRTC_JAVA_JNI_ANDROIDNETWORKMONITOR_JNI_H_ | 29 #define TALK_APP_WEBRTC_JAVA_JNI_ANDROIDNETWORKMONITOR_JNI_H_ |
| 30 | 30 |
| 31 #include "webrtc/base/networkmonitor.h" | 31 #include "webrtc/base/networkmonitor.h" |
| 32 | 32 |
| 33 #include <map> |
| 34 |
| 33 #include "webrtc/base/thread_checker.h" | 35 #include "webrtc/base/thread_checker.h" |
| 34 #include "talk/app/webrtc/java/jni/jni_helpers.h" | 36 #include "talk/app/webrtc/java/jni/jni_helpers.h" |
| 35 | 37 |
| 36 namespace webrtc_jni { | 38 namespace webrtc_jni { |
| 37 | 39 |
| 40 typedef uint32_t NetworkHandle; |
| 41 |
| 42 // c++ equivalent of java NetworkMonitorAutoDetect.ConnectionType. |
| 43 enum NetworkType { |
| 44 NETWORK_UNKNOWN, |
| 45 NETWORK_ETHERNET, |
| 46 NETWORK_WIFI, |
| 47 NETWORK_4G, |
| 48 NETWORK_3G, |
| 49 NETWORK_2G, |
| 50 NETWORK_BLUETOOTH, |
| 51 NETWORK_NONE |
| 52 }; |
| 53 |
| 54 // The information is collected from Android OS so that the native code can get |
| 55 // the network type and handle (Android network ID) for each interface. |
| 56 struct NetworkInformation { |
| 57 std::string interface_name; |
| 58 NetworkHandle handle; |
| 59 NetworkType type; |
| 60 std::vector<rtc::IPAddress> ip_addresses; |
| 61 |
| 62 std::string ToString() const; |
| 63 }; |
| 64 |
| 38 class AndroidNetworkMonitor : public rtc::NetworkMonitorBase { | 65 class AndroidNetworkMonitor : public rtc::NetworkMonitorBase { |
| 39 public: | 66 public: |
| 40 AndroidNetworkMonitor(); | 67 AndroidNetworkMonitor(); |
| 41 | 68 |
| 42 static void SetAndroidContext(JNIEnv* jni, jobject context); | 69 static void SetAndroidContext(JNIEnv* jni, jobject context); |
| 43 | 70 |
| 44 void Start() override; | 71 void Start() override; |
| 45 void Stop() override; | 72 void Stop() override; |
| 46 | 73 |
| 74 int BindSocketToNetwork(int socket_fd, |
| 75 const rtc::IPAddress& address) override; |
| 76 void OnNetworkAvailable(const NetworkInformation& network_info); |
| 77 |
| 47 private: | 78 private: |
| 48 JNIEnv* jni() { return AttachCurrentThreadIfNeeded(); } | 79 JNIEnv* jni() { return AttachCurrentThreadIfNeeded(); } |
| 49 | 80 |
| 81 void OnNetworkAvailable_w(const NetworkInformation& network_info); |
| 82 |
| 50 ScopedGlobalRef<jclass> j_network_monitor_class_; | 83 ScopedGlobalRef<jclass> j_network_monitor_class_; |
| 51 ScopedGlobalRef<jobject> j_network_monitor_; | 84 ScopedGlobalRef<jobject> j_network_monitor_; |
| 52 rtc::ThreadChecker thread_checker_; | 85 rtc::ThreadChecker thread_checker_; |
| 53 static jobject application_context_; | 86 static jobject application_context_; |
| 87 bool started_ = false; |
| 88 std::map<rtc::IPAddress, NetworkInformation> network_info_by_address_; |
| 54 }; | 89 }; |
| 55 | 90 |
| 56 class AndroidNetworkMonitorFactory : public rtc::NetworkMonitorFactory { | 91 class AndroidNetworkMonitorFactory : public rtc::NetworkMonitorFactory { |
| 57 public: | 92 public: |
| 58 AndroidNetworkMonitorFactory() {} | 93 AndroidNetworkMonitorFactory() {} |
| 59 | 94 |
| 60 rtc::NetworkMonitorInterface* CreateNetworkMonitor() override { | 95 rtc::NetworkMonitorInterface* CreateNetworkMonitor() override; |
| 61 return new AndroidNetworkMonitor(); | |
| 62 } | |
| 63 }; | 96 }; |
| 64 | 97 |
| 65 } // namespace webrtc_jni | 98 } // namespace webrtc_jni |
| 66 | 99 |
| 67 #endif // TALK_APP_WEBRTC_JAVA_JNI_ANDROIDNETWORKMONITOR_JNI_H_ | 100 #endif // TALK_APP_WEBRTC_JAVA_JNI_ANDROIDNETWORKMONITOR_JNI_H_ |
| OLD | NEW |