| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "net/android/network_change_notifier_delegate_android.h" | 5 #include "net/android/network_change_notifier_delegate_android.h" |
| 6 | 6 |
| 7 #include "base/android/context_utils.h" | 7 #include "base/android/context_utils.h" |
| 8 #include "base/android/jni_array.h" | 8 #include "base/android/jni_array.h" |
| 9 #include "base/android/jni_string.h" |
| 9 #include "base/logging.h" | 10 #include "base/logging.h" |
| 10 #include "jni/NetworkChangeNotifier_jni.h" | 11 #include "jni/NetworkChangeNotifier_jni.h" |
| 11 #include "net/android/network_change_notifier_android.h" | 12 #include "net/android/network_change_notifier_android.h" |
| 12 | 13 |
| 13 namespace net { | 14 namespace net { |
| 14 | 15 |
| 15 namespace { | 16 namespace { |
| 16 | 17 |
| 17 // Converts a Java side connection type (integer) to | 18 // Converts a Java side connection type (integer) to |
| 18 // the native side NetworkChangeNotifier::ConnectionType. | 19 // the native side NetworkChangeNotifier::ConnectionType. |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 74 java_network_change_notifier_.Reset( | 75 java_network_change_notifier_.Reset( |
| 75 Java_NetworkChangeNotifier_init( | 76 Java_NetworkChangeNotifier_init( |
| 76 env, base::android::GetApplicationContext())); | 77 env, base::android::GetApplicationContext())); |
| 77 Java_NetworkChangeNotifier_addNativeObserver( | 78 Java_NetworkChangeNotifier_addNativeObserver( |
| 78 env, java_network_change_notifier_.obj(), | 79 env, java_network_change_notifier_.obj(), |
| 79 reinterpret_cast<intptr_t>(this)); | 80 reinterpret_cast<intptr_t>(this)); |
| 80 SetCurrentConnectionType( | 81 SetCurrentConnectionType( |
| 81 ConvertConnectionType( | 82 ConvertConnectionType( |
| 82 Java_NetworkChangeNotifier_getCurrentConnectionType( | 83 Java_NetworkChangeNotifier_getCurrentConnectionType( |
| 83 env, java_network_change_notifier_.obj()))); | 84 env, java_network_change_notifier_.obj()))); |
| 85 SetCurrentSSID(base::android::ConvertJavaStringToUTF8( |
| 86 env, Java_NetworkChangeNotifier_getCurrentWifiSSID( |
| 87 env, java_network_change_notifier_.obj()))); |
| 84 SetCurrentMaxBandwidth( | 88 SetCurrentMaxBandwidth( |
| 85 Java_NetworkChangeNotifier_getCurrentMaxBandwidthInMbps( | 89 Java_NetworkChangeNotifier_getCurrentMaxBandwidthInMbps( |
| 86 env, java_network_change_notifier_.obj())); | 90 env, java_network_change_notifier_.obj())); |
| 87 SetCurrentDefaultNetwork(Java_NetworkChangeNotifier_getCurrentDefaultNetId( | 91 SetCurrentDefaultNetwork(Java_NetworkChangeNotifier_getCurrentDefaultNetId( |
| 88 env, java_network_change_notifier_.obj())); | 92 env, java_network_change_notifier_.obj())); |
| 89 NetworkMap network_map; | 93 NetworkMap network_map; |
| 90 ScopedJavaLocalRef<jintArray> networks_and_types = | 94 ScopedJavaLocalRef<jintArray> networks_and_types = |
| 91 Java_NetworkChangeNotifier_getCurrentNetworksAndTypes( | 95 Java_NetworkChangeNotifier_getCurrentNetworksAndTypes( |
| 92 env, java_network_change_notifier_.obj()); | 96 env, java_network_change_notifier_.obj()); |
| 93 JavaIntArrayToNetworkMap(env, networks_and_types.obj(), &network_map); | 97 JavaIntArrayToNetworkMap(env, networks_and_types.obj(), &network_map); |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 144 } | 148 } |
| 145 | 149 |
| 146 void NetworkChangeNotifierDelegateAndroid::GetCurrentlyConnectedNetworks( | 150 void NetworkChangeNotifierDelegateAndroid::GetCurrentlyConnectedNetworks( |
| 147 NetworkList* network_list) const { | 151 NetworkList* network_list) const { |
| 148 network_list->clear(); | 152 network_list->clear(); |
| 149 base::AutoLock auto_lock(connection_lock_); | 153 base::AutoLock auto_lock(connection_lock_); |
| 150 for (auto i : network_map_) | 154 for (auto i : network_map_) |
| 151 network_list->push_back(i.first); | 155 network_list->push_back(i.first); |
| 152 } | 156 } |
| 153 | 157 |
| 158 std::string NetworkChangeNotifierDelegateAndroid::GetCurrentWiFiSSID() const { |
| 159 base::AutoLock auto_lock(connection_lock_); |
| 160 return current_ssid_; |
| 161 } |
| 162 |
| 154 void NetworkChangeNotifierDelegateAndroid::NotifyConnectionTypeChanged( | 163 void NetworkChangeNotifierDelegateAndroid::NotifyConnectionTypeChanged( |
| 155 JNIEnv* env, | 164 JNIEnv* env, |
| 156 const JavaParamRef<jobject>& obj, | 165 const JavaParamRef<jobject>& obj, |
| 157 jint new_connection_type, | 166 jint new_connection_type, |
| 158 jint default_netid) { | 167 jint default_netid) { |
| 159 DCHECK(thread_checker_.CalledOnValidThread()); | 168 DCHECK(thread_checker_.CalledOnValidThread()); |
| 160 const ConnectionType actual_connection_type = ConvertConnectionType( | 169 const ConnectionType actual_connection_type = ConvertConnectionType( |
| 161 new_connection_type); | 170 new_connection_type); |
| 162 SetCurrentConnectionType(actual_connection_type); | 171 SetCurrentConnectionType(actual_connection_type); |
| 172 SetCurrentSSID(base::android::ConvertJavaStringToUTF8( |
| 173 env, Java_NetworkChangeNotifier_getCurrentWifiSSID( |
| 174 env, java_network_change_notifier_.obj()))); |
| 175 |
| 163 NetworkHandle default_network = default_netid; | 176 NetworkHandle default_network = default_netid; |
| 164 if (default_network != GetCurrentDefaultNetwork()) { | 177 if (default_network != GetCurrentDefaultNetwork()) { |
| 165 SetCurrentDefaultNetwork(default_network); | 178 SetCurrentDefaultNetwork(default_network); |
| 166 bool default_exists; | 179 bool default_exists; |
| 167 { | 180 { |
| 168 base::AutoLock auto_lock(connection_lock_); | 181 base::AutoLock auto_lock(connection_lock_); |
| 169 // |default_network| may be an invalid value (i.e. -1) in cases where | 182 // |default_network| may be an invalid value (i.e. -1) in cases where |
| 170 // the device is disconnected or when run on Android versions prior to L, | 183 // the device is disconnected or when run on Android versions prior to L, |
| 171 // in which case |default_exists| will correctly be false and no | 184 // in which case |default_exists| will correctly be false and no |
| 172 // OnNetworkMadeDefault notification will be sent. | 185 // OnNetworkMadeDefault notification will be sent. |
| (...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 297 bool NetworkChangeNotifierDelegateAndroid::Register(JNIEnv* env) { | 310 bool NetworkChangeNotifierDelegateAndroid::Register(JNIEnv* env) { |
| 298 return RegisterNativesImpl(env); | 311 return RegisterNativesImpl(env); |
| 299 } | 312 } |
| 300 | 313 |
| 301 void NetworkChangeNotifierDelegateAndroid::SetCurrentConnectionType( | 314 void NetworkChangeNotifierDelegateAndroid::SetCurrentConnectionType( |
| 302 ConnectionType new_connection_type) { | 315 ConnectionType new_connection_type) { |
| 303 base::AutoLock auto_lock(connection_lock_); | 316 base::AutoLock auto_lock(connection_lock_); |
| 304 connection_type_ = new_connection_type; | 317 connection_type_ = new_connection_type; |
| 305 } | 318 } |
| 306 | 319 |
| 320 void NetworkChangeNotifierDelegateAndroid::SetCurrentSSID( |
| 321 const std::string& new_ssid) { |
| 322 base::AutoLock auto_lock(connection_lock_); |
| 323 current_ssid_ = new_ssid; |
| 324 } |
| 325 |
| 307 void NetworkChangeNotifierDelegateAndroid::SetCurrentMaxBandwidth( | 326 void NetworkChangeNotifierDelegateAndroid::SetCurrentMaxBandwidth( |
| 308 double max_bandwidth) { | 327 double max_bandwidth) { |
| 309 base::AutoLock auto_lock(connection_lock_); | 328 base::AutoLock auto_lock(connection_lock_); |
| 310 connection_max_bandwidth_ = max_bandwidth; | 329 connection_max_bandwidth_ = max_bandwidth; |
| 311 } | 330 } |
| 312 | 331 |
| 313 void NetworkChangeNotifierDelegateAndroid::SetCurrentDefaultNetwork( | 332 void NetworkChangeNotifierDelegateAndroid::SetCurrentDefaultNetwork( |
| 314 NetworkHandle default_network) { | 333 NetworkHandle default_network) { |
| 315 base::AutoLock auto_lock(connection_lock_); | 334 base::AutoLock auto_lock(connection_lock_); |
| 316 default_network_ = default_network; | 335 default_network_ = default_network; |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 365 Java_NetworkChangeNotifier_fakeDefaultNetwork(env, network, type); | 384 Java_NetworkChangeNotifier_fakeDefaultNetwork(env, network, type); |
| 366 } | 385 } |
| 367 | 386 |
| 368 void NetworkChangeNotifierDelegateAndroid::FakeMaxBandwidthChanged( | 387 void NetworkChangeNotifierDelegateAndroid::FakeMaxBandwidthChanged( |
| 369 double max_bandwidth_mbps) { | 388 double max_bandwidth_mbps) { |
| 370 JNIEnv* env = base::android::AttachCurrentThread(); | 389 JNIEnv* env = base::android::AttachCurrentThread(); |
| 371 Java_NetworkChangeNotifier_fakeMaxBandwidthChanged(env, max_bandwidth_mbps); | 390 Java_NetworkChangeNotifier_fakeMaxBandwidthChanged(env, max_bandwidth_mbps); |
| 372 } | 391 } |
| 373 | 392 |
| 374 } // namespace net | 393 } // namespace net |
| OLD | NEW |