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

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

Issue 2546213003: Implement net/ support for Android's NetworkSecurityPolicy (Closed)
Patch Set: More comments Created 4 years 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') | net/url_request/url_request_http_job.cc » ('J')
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 1656e2c38565ed038441a860e007ae0f9eb28304..67c988264d0f85c5905b5f3ad32f5731077ecd7d 100644
--- a/net/android/java/src/org/chromium/net/AndroidNetworkLibrary.java
+++ b/net/android/java/src/org/chromium/net/AndroidNetworkLibrary.java
@@ -17,12 +17,14 @@ import android.net.wifi.WifiInfo;
import android.net.wifi.WifiManager;
import android.os.Build;
import android.security.KeyChain;
+import android.security.NetworkSecurityPolicy;
import android.telephony.TelephonyManager;
import android.util.Log;
import org.chromium.base.annotations.CalledByNative;
import org.chromium.base.annotations.CalledByNativeUnchecked;
+import java.lang.reflect.Method;
import java.net.NetworkInterface;
import java.net.SocketException;
import java.net.URLConnection;
@@ -243,4 +245,34 @@ class AndroidNetworkLibrary {
}
return "";
}
+
+ /**
+ * Returns true if cleartext traffic to |host| is allowed by the current app. Always true on L
+ * and older.
+ */
+ @TargetApi(Build.VERSION_CODES.N)
+ @CalledByNative
+ private static boolean isCleartextPermitted(String host) {
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
+ NetworkSecurityPolicy policy = NetworkSecurityPolicy.getInstance();
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
+ return policy.isCleartextTrafficPermitted(host);
+ }
+ return policy.isCleartextTrafficPermitted();
+ }
+ return true;
+ }
+
+ /**
+ * Helper for tests that simulates an app disallowing cleartext traffic entirely.
+ */
+ @TargetApi(Build.VERSION_CODES.M)
+ @CalledByNative
+ private static void setUpSecurityPolicyForTesting() throws Exception {
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
+ Method setCleartextTrafficPermitted = NetworkSecurityPolicy.class.getDeclaredMethod(
+ "setCleartextTrafficPermitted", boolean.class);
+ setCleartextTrafficPermitted.invoke(NetworkSecurityPolicy.getInstance(), false);
+ }
+ }
}
« no previous file with comments | « no previous file | net/android/network_library.h » ('j') | net/url_request/url_request_http_job.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698