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

Unified Diff: net/android/java/src/org/chromium/net/AndroidNetworkLibrary.java

Issue 2486393004: Expose API to detect when captive portal probe was blocked on Android (Closed)
Patch Set: Add permission to AndroidManifest.xml for running the unittest Created 4 years, 1 month 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | net/android/network_library.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: net/android/java/src/org/chromium/net/AndroidNetworkLibrary.java
diff --git a/net/android/java/src/org/chromium/net/AndroidNetworkLibrary.java b/net/android/java/src/org/chromium/net/AndroidNetworkLibrary.java
index 9b45d982a6bc200d4a6f27720d664fe145f1d6a4..1656e2c38565ed038441a860e007ae0f9eb28304 100644
--- a/net/android/java/src/org/chromium/net/AndroidNetworkLibrary.java
+++ b/net/android/java/src/org/chromium/net/AndroidNetworkLibrary.java
@@ -4,14 +4,18 @@
package org.chromium.net;
+import android.annotation.TargetApi;
import android.content.ActivityNotFoundException;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.net.ConnectivityManager;
+import android.net.Network;
+import android.net.NetworkCapabilities;
import android.net.NetworkInfo;
import android.net.wifi.WifiInfo;
import android.net.wifi.WifiManager;
+import android.os.Build;
import android.security.KeyChain;
import android.telephony.TelephonyManager;
import android.util.Log;
@@ -193,6 +197,31 @@ class AndroidNetworkLibrary {
}
/**
+ * Returns true if the system's captive portal probe was blocked for the current default data
+ * network. The method will return false if the captive portal probe was not blocked, the login
+ * process to the captive portal has been successfully completed, or if the captive portal
+ * status can't be determined. Requires ACCESS_NETWORK_STATE permission. Only available on
+ * Android Marshmallow and later versions. Returns false on earlier versions.
+ */
+ @TargetApi(Build.VERSION_CODES.M)
+ @CalledByNative
+ private static boolean getIsCaptivePortal(Context context) {
+ // NetworkCapabilities.NET_CAPABILITY_CAPTIVE_PORTAL is only available on Marshmallow and
+ // later versions.
+ if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) return false;
+ ConnectivityManager connectivityManager =
+ (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
+ if (connectivityManager == null) return false;
+
+ Network network = connectivityManager.getActiveNetwork();
+ if (network == null) return false;
+
+ NetworkCapabilities capabilities = connectivityManager.getNetworkCapabilities(network);
+ return capabilities != null
+ && capabilities.hasCapability(NetworkCapabilities.NET_CAPABILITY_CAPTIVE_PORTAL);
+ }
+
+ /**
* Gets the SSID of the currently associated WiFi access point if there is one. Otherwise,
* returns empty string.
*/
« no previous file with comments | « no previous file | net/android/network_library.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698