Chromium Code Reviews| Index: net/android/java/src/org/chromium/net/NetworkChangeNotifierAutoDetect.java |
| diff --git a/net/android/java/src/org/chromium/net/NetworkChangeNotifierAutoDetect.java b/net/android/java/src/org/chromium/net/NetworkChangeNotifierAutoDetect.java |
| index f3c743c8bfa16d99d9562ccf2d69303b233ec68a..5903ae410d80b9122f65c402eb67f86971405516 100644 |
| --- a/net/android/java/src/org/chromium/net/NetworkChangeNotifierAutoDetect.java |
| +++ b/net/android/java/src/org/chromium/net/NetworkChangeNotifierAutoDetect.java |
| @@ -221,22 +221,21 @@ public class NetworkChangeNotifierAutoDetect extends BroadcastReceiver { |
| } |
| /** |
| - * Returns the NetID of the current default network. Returns |
| - * NetId.INVALID if no current default network connected. |
| - * Only callable on Lollipop and newer releases. |
| + * Returns the current default network. Returns null if no current default network |
|
pauljensen
2016/11/16 16:10:23
null->{@code null}
|
| + * is connected. Only callable on Lollipop and newer releases. |
| */ |
| @TargetApi(Build.VERSION_CODES.LOLLIPOP) |
| - long getDefaultNetId() { |
| + Network getDefaultNet() { |
|
pauljensen
2016/11/16 16:10:23
private
pauljensen
2016/11/16 16:10:23
Net->Network
|
| // Android Lollipop had no API to get the default network; only an |
| // API to return the NetworkInfo for the default network. To |
| // determine the default network one can find the network with |
| // type matching that of the default network. |
| final NetworkInfo defaultNetworkInfo = mConnectivityManager.getActiveNetworkInfo(); |
| if (defaultNetworkInfo == null) { |
| - return NetId.INVALID; |
| + return null; |
| } |
| final Network[] networks = getAllNetworksFiltered(this, null); |
| - long defaultNetId = NetId.INVALID; |
| + Network defaultNetwork = null; |
| for (Network network : networks) { |
| final NetworkInfo networkInfo = getNetworkInfo(network); |
| if (networkInfo != null |
| @@ -253,11 +252,41 @@ public class NetworkChangeNotifierAutoDetect extends BroadcastReceiver { |
| // not supported. If this becomes supported this assertion |
| // may trigger. At that point ConnectivityManager.getDefaultNetwork() |
| // could be used though it's only available with Android Marshmallow. |
| - assert defaultNetId == NetId.INVALID; |
| - defaultNetId = networkToNetId(network); |
| + assert defaultNetwork == null; |
| + defaultNetwork = network; |
| } |
| } |
| - return defaultNetId; |
| + return defaultNetwork; |
| + } |
| + |
| + /** |
| + * Returns the NetID of the current default network. Returns |
| + * NetId.INVALID if no current default network is connected. |
| + * Only callable on Lollipop and newer releases. |
| + */ |
| + @TargetApi(Build.VERSION_CODES.LOLLIPOP) |
| + long getDefaultNetId() { |
| + Network network = getDefaultNet(); |
| + return network == null ? NetId.INVALID : networkToNetId(network); |
| + } |
| + |
| + /** |
| + * Returns true if the captive portal probe was blocked for the current network. |
| + * May incorrectly return true if the user has signed into the captive portal since the |
| + * network was last probed. |
| + * Only available on Lollipop and newer releases. |
|
pauljensen
2016/11/16 16:10:23
Mention what is returned on older releases.
pauljensen
2016/11/16 16:10:23
Lollipop->Marshmallow
NET_CAPABILITIES was only ad
|
| + */ |
| + @TargetApi(Build.VERSION_CODES.LOLLIPOP) |
|
pauljensen
2016/11/16 16:10:23
LOLLIPOP->MARSHMALLOW
|
| + boolean getCurrentNetworkCaptivePortal() { |
| + Network network = getDefaultNet(); |
| + if (network == null) { |
| + return false; |
| + } |
| + |
| + NetworkCapabilities capabilities = mConnectivityManager.getNetworkCapabilities(network); |
| + return capabilities != null |
| + && capabilities.hasCapability( |
| + NetworkCapabilities.NET_CAPABILITY_CAPTIVE_PORTAL); |
| } |
| } |
| @@ -811,6 +840,19 @@ public class NetworkChangeNotifierAutoDetect extends BroadcastReceiver { |
| } |
| /** |
| + * Returns true if the captive portal probe was blocked for the current network. |
| + * May incorrectly return true if the user has signed into the captive portal since the |
| + * network was last probed. |
| + * Only available on Lollipop and newer releases. |
| + */ |
| + public boolean getCurrentNetworkCaptivePortal() { |
| + if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) { |
|
pauljensen
2016/11/16 16:10:23
LOLLIPOP->MARSHMALLOW
|
| + return false; |
| + } |
| + return mConnectivityManagerDelegate.getCurrentNetworkCaptivePortal(); |
| + } |
| + |
| + /** |
| * Returns the connection type for the given NetworkState. |
| */ |
| @ConnectionTypeEnum |