| OLD | NEW |
| 1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 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 package org.chromium.net; | 5 package org.chromium.net; |
| 6 | 6 |
| 7 import static android.net.NetworkCapabilities.NET_CAPABILITY_INTERNET; | 7 import static android.net.NetworkCapabilities.NET_CAPABILITY_INTERNET; |
| 8 import static android.net.NetworkCapabilities.TRANSPORT_CELLULAR; | 8 import static android.net.NetworkCapabilities.TRANSPORT_CELLULAR; |
| 9 import static android.net.NetworkCapabilities.TRANSPORT_VPN; | 9 import static android.net.NetworkCapabilities.TRANSPORT_VPN; |
| 10 import static android.net.NetworkCapabilities.TRANSPORT_WIFI; | 10 import static android.net.NetworkCapabilities.TRANSPORT_WIFI; |
| 11 | 11 |
| 12 import android.annotation.SuppressLint; | 12 import android.annotation.SuppressLint; |
| 13 import android.content.Context; | 13 import android.content.Context; |
| 14 import android.content.Intent; | 14 import android.content.Intent; |
| 15 import android.net.ConnectivityManager; | 15 import android.net.ConnectivityManager; |
| 16 import android.net.ConnectivityManager.NetworkCallback; | 16 import android.net.ConnectivityManager.NetworkCallback; |
| 17 import android.net.Network; | 17 import android.net.Network; |
| 18 import android.net.NetworkCapabilities; | 18 import android.net.NetworkCapabilities; |
| 19 import android.net.NetworkRequest; | 19 import android.net.NetworkRequest; |
| 20 import android.net.wifi.WifiInfo; |
| 20 import android.net.wifi.WifiManager; | 21 import android.net.wifi.WifiManager; |
| 21 import android.os.Build; | 22 import android.os.Build; |
| 22 import android.telephony.TelephonyManager; | 23 import android.telephony.TelephonyManager; |
| 23 import android.test.InstrumentationTestCase; | 24 import android.test.InstrumentationTestCase; |
| 24 import android.test.UiThreadTest; | 25 import android.test.UiThreadTest; |
| 25 import android.test.suitebuilder.annotation.MediumTest; | 26 import android.test.suitebuilder.annotation.MediumTest; |
| 26 | 27 |
| 27 import org.chromium.base.ApplicationState; | 28 import org.chromium.base.ApplicationState; |
| 28 import org.chromium.base.ThreadUtils; | 29 import org.chromium.base.ThreadUtils; |
| 29 import org.chromium.base.library_loader.LibraryLoader; | 30 import org.chromium.base.library_loader.LibraryLoader; |
| (...skipping 224 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 254 | 255 |
| 255 /** | 256 /** |
| 256 * Mocks out calls to the WifiManager. | 257 * Mocks out calls to the WifiManager. |
| 257 */ | 258 */ |
| 258 private static class MockWifiManagerDelegate | 259 private static class MockWifiManagerDelegate |
| 259 extends NetworkChangeNotifierAutoDetect.WifiManagerDelegate { | 260 extends NetworkChangeNotifierAutoDetect.WifiManagerDelegate { |
| 260 private String mWifiSSID; | 261 private String mWifiSSID; |
| 261 private int mLinkSpeedMbps; | 262 private int mLinkSpeedMbps; |
| 262 | 263 |
| 263 @Override | 264 @Override |
| 264 public String getWifiSSID() { | 265 public String getWifiSSID(WifiInfo wifiInfo) { |
| 265 return mWifiSSID; | 266 return mWifiSSID; |
| 266 } | 267 } |
| 267 | 268 |
| 268 public void setWifiSSID(String wifiSSID) { | 269 public void setWifiSSID(String wifiSSID) { |
| 269 mWifiSSID = wifiSSID; | 270 mWifiSSID = wifiSSID; |
| 270 } | 271 } |
| 271 | 272 |
| 272 @Override | 273 @Override |
| 273 public int getLinkSpeedInMbps() { | 274 public int getLinkSpeedInMbps(WifiInfo wifiInfo) { |
| 274 return mLinkSpeedMbps; | 275 return mLinkSpeedMbps; |
| 275 } | 276 } |
| 276 | 277 |
| 277 public void setLinkSpeedInMbps(int linkSpeedInMbps) { | 278 public void setLinkSpeedInMbps(int linkSpeedInMbps) { |
| 278 mLinkSpeedMbps = linkSpeedInMbps; | 279 mLinkSpeedMbps = linkSpeedInMbps; |
| 279 } | 280 } |
| 280 } | 281 } |
| 281 | 282 |
| 282 private static int demungeNetId(long netId) { | 283 private static int demungeNetId(long netId) { |
| 283 // On Marshmallow, demunge the NetID to undo munging done in Network.get
NetworkHandle(). | 284 // On Marshmallow, demunge the NetID to undo munging done in Network.get
NetworkHandle(). |
| (...skipping 663 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 947 mConnectivityDelegate.setActiveNetworkExists(true); | 948 mConnectivityDelegate.setActiveNetworkExists(true); |
| 948 mConnectivityDelegate.setNetworkType(i); | 949 mConnectivityDelegate.setNetworkType(i); |
| 949 mReceiver.onReceive(getInstrumentation().getTargetContext(), intent)
; | 950 mReceiver.onReceive(getInstrumentation().getTargetContext(), intent)
; |
| 950 assertTrue(NetworkChangeNotifier.isOnline()); | 951 assertTrue(NetworkChangeNotifier.isOnline()); |
| 951 } | 952 } |
| 952 mConnectivityDelegate.setActiveNetworkExists(false); | 953 mConnectivityDelegate.setActiveNetworkExists(false); |
| 953 mReceiver.onReceive(getInstrumentation().getTargetContext(), intent); | 954 mReceiver.onReceive(getInstrumentation().getTargetContext(), intent); |
| 954 assertFalse(NetworkChangeNotifier.isOnline()); | 955 assertFalse(NetworkChangeNotifier.isOnline()); |
| 955 } | 956 } |
| 956 } | 957 } |
| OLD | NEW |