| 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.ConnectivityManager.TYPE_VPN; | 7 import static android.net.ConnectivityManager.TYPE_VPN; |
| 8 import static android.net.NetworkCapabilities.NET_CAPABILITY_INTERNET; | 8 import static android.net.NetworkCapabilities.NET_CAPABILITY_INTERNET; |
| 9 import static android.net.NetworkCapabilities.NET_CAPABILITY_NOT_VPN; | 9 import static android.net.NetworkCapabilities.NET_CAPABILITY_NOT_VPN; |
| 10 import static android.net.NetworkCapabilities.TRANSPORT_VPN; | 10 import static android.net.NetworkCapabilities.TRANSPORT_VPN; |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 87 return getNetworkState(mConnectivityManager.getActiveNetworkInfo()); | 87 return getNetworkState(mConnectivityManager.getActiveNetworkInfo()); |
| 88 } | 88 } |
| 89 | 89 |
| 90 /** | 90 /** |
| 91 * Returns connection type and status information about |network|. | 91 * Returns connection type and status information about |network|. |
| 92 * Only callable on Lollipop and newer releases. | 92 * Only callable on Lollipop and newer releases. |
| 93 */ | 93 */ |
| 94 @TargetApi(Build.VERSION_CODES.LOLLIPOP) | 94 @TargetApi(Build.VERSION_CODES.LOLLIPOP) |
| 95 NetworkState getNetworkState(Network network) { | 95 NetworkState getNetworkState(Network network) { |
| 96 final NetworkInfo networkInfo = mConnectivityManager.getNetworkInfo(
network); | 96 final NetworkInfo networkInfo = mConnectivityManager.getNetworkInfo(
network); |
| 97 if (networkInfo.getType() == TYPE_VPN) { | 97 if (networkInfo != null && networkInfo.getType() == TYPE_VPN) { |
| 98 // When a VPN is in place the underlying network type can be que
ried via | 98 // When a VPN is in place the underlying network type can be que
ried via |
| 99 // getActiveNeworkInfo() thanks to | 99 // getActiveNeworkInfo() thanks to |
| 100 // https://android.googlesource.com/platform/frameworks/base/+/d
6a7980d | 100 // https://android.googlesource.com/platform/frameworks/base/+/d
6a7980d |
| 101 return getNetworkState(); | 101 return getNetworkState(); |
| 102 } | 102 } |
| 103 return getNetworkState(networkInfo); | 103 return getNetworkState(networkInfo); |
| 104 } | 104 } |
| 105 | 105 |
| 106 /** | 106 /** |
| 107 * Returns connection type and status information gleaned from networkIn
fo. | 107 * Returns connection type and status information gleaned from networkIn
fo. |
| (...skipping 779 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 887 */ | 887 */ |
| 888 @TargetApi(Build.VERSION_CODES.LOLLIPOP) | 888 @TargetApi(Build.VERSION_CODES.LOLLIPOP) |
| 889 @VisibleForTesting | 889 @VisibleForTesting |
| 890 static int networkToNetId(Network network) { | 890 static int networkToNetId(Network network) { |
| 891 // NOTE(pauljensen): This depends on Android framework implementation de
tails. | 891 // NOTE(pauljensen): This depends on Android framework implementation de
tails. |
| 892 // Fortunately this functionality is unlikely to ever change. | 892 // Fortunately this functionality is unlikely to ever change. |
| 893 // TODO(pauljensen): When we update to Android M SDK, use Network.getNet
workHandle(). | 893 // TODO(pauljensen): When we update to Android M SDK, use Network.getNet
workHandle(). |
| 894 return Integer.parseInt(network.toString()); | 894 return Integer.parseInt(network.toString()); |
| 895 } | 895 } |
| 896 } | 896 } |
| OLD | NEW |