Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(27)

Side by Side Diff: webrtc/api/android/jni/androidnetworkmonitor_jni.h

Issue 2189753002: Use a newer method to bind socket to network in Android M and later. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Fix a test Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright 2015 The WebRTC project authors. All Rights Reserved. 2 * Copyright 2015 The WebRTC project authors. All Rights Reserved.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license 4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source 5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found 6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may 7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree. 8 * be found in the AUTHORS file in the root of the source tree.
9 */ 9 */
10 10
11 #ifndef WEBRTC_API_JAVA_JNI_ANDROIDNETWORKMONITOR_JNI_H_ 11 #ifndef WEBRTC_API_JAVA_JNI_ANDROIDNETWORKMONITOR_JNI_H_
12 #define WEBRTC_API_JAVA_JNI_ANDROIDNETWORKMONITOR_JNI_H_ 12 #define WEBRTC_API_JAVA_JNI_ANDROIDNETWORKMONITOR_JNI_H_
13 13
14 #include "webrtc/base/networkmonitor.h" 14 #include "webrtc/base/networkmonitor.h"
15 15
16 #include <map> 16 #include <map>
17 17
18 #include "webrtc/api/android/jni/jni_helpers.h" 18 #include "webrtc/api/android/jni/jni_helpers.h"
19 #include "webrtc/base/basictypes.h" 19 #include "webrtc/base/basictypes.h"
20 #include "webrtc/base/thread_checker.h" 20 #include "webrtc/base/thread_checker.h"
21 21
22 namespace webrtc_jni { 22 namespace webrtc_jni {
23 23
24 typedef uint32_t NetworkHandle; 24 typedef long NetworkHandle;
25 25
26 // c++ equivalent of java NetworkMonitorAutoDetect.ConnectionType. 26 // c++ equivalent of java NetworkMonitorAutoDetect.ConnectionType.
27 enum NetworkType { 27 enum NetworkType {
28 NETWORK_UNKNOWN, 28 NETWORK_UNKNOWN,
29 NETWORK_ETHERNET, 29 NETWORK_ETHERNET,
30 NETWORK_WIFI, 30 NETWORK_WIFI,
31 NETWORK_4G, 31 NETWORK_4G,
32 NETWORK_3G, 32 NETWORK_3G,
33 NETWORK_2G, 33 NETWORK_2G,
34 NETWORK_UNKNOWN_CELLULAR, 34 NETWORK_UNKNOWN_CELLULAR,
(...skipping 23 matching lines...) Expand all
58 void Stop() override; 58 void Stop() override;
59 59
60 int BindSocketToNetwork(int socket_fd, 60 int BindSocketToNetwork(int socket_fd,
61 const rtc::IPAddress& address) override; 61 const rtc::IPAddress& address) override;
62 rtc::AdapterType GetAdapterType(const std::string& if_name) override; 62 rtc::AdapterType GetAdapterType(const std::string& if_name) override;
63 void OnNetworkConnected(const NetworkInformation& network_info); 63 void OnNetworkConnected(const NetworkInformation& network_info);
64 void OnNetworkDisconnected(NetworkHandle network_handle); 64 void OnNetworkDisconnected(NetworkHandle network_handle);
65 void SetNetworkInfos(const std::vector<NetworkInformation>& network_infos); 65 void SetNetworkInfos(const std::vector<NetworkInformation>& network_infos);
66 66
67 private: 67 private:
68 static jobject application_context_;
69 static int android_sdk_int_;
68 JNIEnv* jni() { return AttachCurrentThreadIfNeeded(); } 70 JNIEnv* jni() { return AttachCurrentThreadIfNeeded(); }
69 71
70 void OnNetworkConnected_w(const NetworkInformation& network_info); 72 void OnNetworkConnected_w(const NetworkInformation& network_info);
71 void OnNetworkDisconnected_w(NetworkHandle network_handle); 73 void OnNetworkDisconnected_w(NetworkHandle network_handle);
72 74
73 ScopedGlobalRef<jclass> j_network_monitor_class_; 75 ScopedGlobalRef<jclass> j_network_monitor_class_;
74 ScopedGlobalRef<jobject> j_network_monitor_; 76 ScopedGlobalRef<jobject> j_network_monitor_;
75 rtc::ThreadChecker thread_checker_; 77 rtc::ThreadChecker thread_checker_;
76 static jobject application_context_;
77 bool started_ = false; 78 bool started_ = false;
78 std::map<std::string, rtc::AdapterType> adapter_type_by_name_; 79 std::map<std::string, rtc::AdapterType> adapter_type_by_name_;
79 std::map<rtc::IPAddress, NetworkHandle> network_handle_by_address_; 80 std::map<rtc::IPAddress, NetworkHandle> network_handle_by_address_;
80 std::map<NetworkHandle, NetworkInformation> network_info_by_handle_; 81 std::map<NetworkHandle, NetworkInformation> network_info_by_handle_;
81 }; 82 };
82 83
83 class AndroidNetworkMonitorFactory : public rtc::NetworkMonitorFactory { 84 class AndroidNetworkMonitorFactory : public rtc::NetworkMonitorFactory {
84 public: 85 public:
85 AndroidNetworkMonitorFactory() {} 86 AndroidNetworkMonitorFactory() {}
86 87
87 rtc::NetworkMonitorInterface* CreateNetworkMonitor() override; 88 rtc::NetworkMonitorInterface* CreateNetworkMonitor() override;
88 }; 89 };
89 90
90 } // namespace webrtc_jni 91 } // namespace webrtc_jni
91 92
92 #endif // WEBRTC_API_JAVA_JNI_ANDROIDNETWORKMONITOR_JNI_H_ 93 #endif // WEBRTC_API_JAVA_JNI_ANDROIDNETWORKMONITOR_JNI_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698