| 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);
|
| + }
|
| + }
|
| }
|
|
|