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

Side by Side Diff: talk/app/webrtc/java/jni/androidnetworkmonitor_jni.cc

Issue 1535943004: Multi-networking with Android L. Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Created 5 years 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 * 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 14 matching lines...) Expand all
25 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */ 26 */
27 27
28 #include "talk/app/webrtc/java/jni/androidnetworkmonitor_jni.h" 28 #include "talk/app/webrtc/java/jni/androidnetworkmonitor_jni.h"
29 29
30 #include "webrtc/base/common.h" 30 #include "webrtc/base/common.h"
31 #include "talk/app/webrtc/java/jni/classreferenceholder.h" 31 #include "talk/app/webrtc/java/jni/classreferenceholder.h"
32 #include "talk/app/webrtc/java/jni/jni_helpers.h" 32 #include "talk/app/webrtc/java/jni/jni_helpers.h"
33 33
34 namespace webrtc_jni { 34 namespace webrtc_jni {
35
35 jobject AndroidNetworkMonitor::application_context_ = nullptr; 36 jobject AndroidNetworkMonitor::application_context_ = nullptr;
36 37
38 static rtc::NetworkType GetNetworkTypeFromJava(
39 JNIEnv* jni, jobject j_network_type) {
40 std::string enum_name = GetJavaEnumName(
41 jni, "org/webrtc/NetworkMonitorAutoDetect$ConnectionType",
42 j_network_type);
43 if (enum_name == "CONNECTION_UNKNOWN") {
44 return rtc::NetworkType::NETWORK_UNKNOWN;
45 }
46 if (enum_name == "CONNECTION_ETHERNET") {
47 return rtc::NetworkType::NETWORK_ETHERNET;
48 }
49 if (enum_name == "CONNECTION_WIFI") {
50 return rtc::NetworkType::NETWORK_WIFI;
51 }
52 if (enum_name == "CONNECTION_4G") {
53 return rtc::NetworkType::NETWORK_4G;
54 }
55 if (enum_name == "CONNECTION_3G") {
56 return rtc::NetworkType::NETWORK_3G;
57 }
58 if (enum_name == "CONNECTION_2G") {
59 return rtc::NetworkType::NETWORK_2G;
60 }
61 if (enum_name == "CONNECTION_BLUETOOTH") {
62 return rtc::NetworkType::NETWORK_BLUETOOTH;
63 }
64 if (enum_name == "CONNECTION_NONE") {
65 return rtc::NetworkType::NETWORK_NONE;
66 }
67 return rtc::NetworkType::NETWORK_UNKNOWN;
68 }
69
70 static rtc::NetworkInformation GetNetworkInformationFromJava(
71 JNIEnv* jni, jobject j_network_info) {
72 rtc::NetworkInformation network_info;
73 jclass j_network_info_class = GetObjectClass(jni, j_network_info);
74 jfieldID j_interface_name_id =
75 GetFieldID(jni, j_network_info_class, "name", "Ljava/lang/String;");
76 jfieldID j_handle_id = GetFieldID(jni, j_network_info_class, "handle", "I");
77 jfieldID j_type_id =
78 GetFieldID(jni, j_network_info_class, "type",
79 "Lorg/webrtc/NetworkMonitorAutoDetect$ConnectionType;");
80
81 network_info.interface_name = JavaToStdString(
82 jni, GetStringField(jni, j_network_info, j_interface_name_id));
83 network_info.handle = static_cast<uint32_t>(GetIntField(jni, j_network_info, j _handle_id));
84 network_info.type =
85 GetNetworkTypeFromJava(jni, GetObjectField(jni, j_network_info, j_type_id) );
86 CHECK_EXCEPTION(jni) << "Error during NetworkMonitor.GetNetworkInfoFromJava";
87 return network_info;
88 }
89
90
37 // static 91 // static
38 void AndroidNetworkMonitor::SetAndroidContext(JNIEnv* jni, jobject context) { 92 void AndroidNetworkMonitor::SetAndroidContext(JNIEnv* jni, jobject context) {
39 if (application_context_) { 93 if (application_context_) {
40 jni->DeleteGlobalRef(application_context_); 94 jni->DeleteGlobalRef(application_context_);
41 } 95 }
42 application_context_ = NewGlobalRef(jni, context); 96 application_context_ = NewGlobalRef(jni, context);
43 } 97 }
44 98
45 AndroidNetworkMonitor::AndroidNetworkMonitor() 99 AndroidNetworkMonitor::AndroidNetworkMonitor()
46 : j_network_monitor_class_(jni(), 100 : j_network_monitor_class_(jni(),
(...skipping 21 matching lines...) Expand all
68 } 122 }
69 123
70 void AndroidNetworkMonitor::Stop() { 124 void AndroidNetworkMonitor::Stop() {
71 RTC_CHECK(thread_checker_.CalledOnValidThread()); 125 RTC_CHECK(thread_checker_.CalledOnValidThread());
72 jmethodID m = 126 jmethodID m =
73 GetMethodID(jni(), *j_network_monitor_class_, "stopMonitoring", "(J)V"); 127 GetMethodID(jni(), *j_network_monitor_class_, "stopMonitoring", "(J)V");
74 jni()->CallVoidMethod(*j_network_monitor_, m, jlongFromPointer(this)); 128 jni()->CallVoidMethod(*j_network_monitor_, m, jlongFromPointer(this));
75 CHECK_EXCEPTION(jni()) << "Error during NetworkMonitor.stopMonitoring"; 129 CHECK_EXCEPTION(jni()) << "Error during NetworkMonitor.stopMonitoring";
76 } 130 }
77 131
132 bool AndroidNetworkMonitor::GetAllNetworkInfos(
133 std::vector<rtc::NetworkInformation>* network_infos) {
134 RTC_CHECK(thread_checker_.CalledOnValidThread());
135 network_infos->clear();
136 jmethodID m = GetMethodID(jni(), *j_network_monitor_class_,
137 "getAllNetworkInfos",
138 "()[Lorg/webrtc/NetworkMonitorAutoDetect$NetworkInfo rmation;");
139 jobjectArray j_network_infos = static_cast<jobjectArray>(
140 jni()->CallObjectMethod(*j_network_monitor_, m));
141 size_t num_infos = jni()->GetArrayLength(j_network_infos);
142 for (size_t i = 0; i < num_infos; ++i) {
143 jobject j_network_info = jni()->GetObjectArrayElement(j_network_infos, i);
144 network_infos->push_back(GetNetworkInformationFromJava(jni(), j_network_info ));
145 }
146 return true;
147 }
148
78 JOW(void, NetworkMonitor_nativeNotifyConnectionTypeChanged)( 149 JOW(void, NetworkMonitor_nativeNotifyConnectionTypeChanged)(
79 JNIEnv* jni, jobject j_monitor, jlong j_native_monitor) { 150 JNIEnv* jni, jobject j_monitor, jlong j_native_monitor) {
80 rtc::NetworkMonitorInterface* network_monitor = 151 rtc::NetworkMonitorInterface* network_monitor =
81 reinterpret_cast<rtc::NetworkMonitorInterface*>(j_native_monitor); 152 reinterpret_cast<rtc::NetworkMonitorInterface*>(j_native_monitor);
82 network_monitor->OnNetworksChanged(); 153 network_monitor->OnNetworksChanged();
83 } 154 }
84 155
156 JOW(void, NetworkMonitor_nativeUpdateNetworkInformation)(
157 JNIEnv* jni, jobject j_monitor, jlong j_native_monitor, jobject j_network_in fo) {
158 rtc::NetworkMonitorInterface* network_monitor =
159 reinterpret_cast<rtc::NetworkMonitorInterface*>(j_native_monitor);
160 rtc::NetworkInformation network_info = GetNetworkInformationFromJava(jni, j_ne twork_info);
161 network_monitor->OnNetworkAvailable(network_info);
162 }
163
85 } // namespace webrtc_jni 164 } // namespace webrtc_jni
OLDNEW
« no previous file with comments | « talk/app/webrtc/java/jni/androidnetworkmonitor_jni.h ('k') | talk/app/webrtc/java/jni/classreferenceholder.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698