blob: 21f39b83bf867d877292ba3e4d6f7e6c0057dc1c [file] [log] [blame]
// Copyright 2016 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
package org.chromium.net;
import android.annotation.TargetApi;
import android.os.Build;
import android.security.NetworkSecurityPolicy;
import org.chromium.base.annotations.CalledByNative;
import java.lang.reflect.Method;
/**
* Utility functions for testing features implemented in AndroidNetworkLibrary.
*/
public class AndroidNetworkLibraryTestUtil {
/**
* Helper for tests that simulates an app disallowing cleartext traffic entirely on M and newer.
*/
@TargetApi(Build.VERSION_CODES.M)
@CalledByNative
private static void setUpSecurityPolicyForTesting(boolean cleartextPermitted) throws Exception {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
Method setCleartextTrafficPermitted = NetworkSecurityPolicy.class.getDeclaredMethod(
"setCleartextTrafficPermitted", boolean.class);
setCleartextTrafficPermitted.invoke(
NetworkSecurityPolicy.getInstance(), cleartextPermitted);
}
}
}