public class NetworkSecurityPolicy extends Object
Network stacks/components are expected to honor this policy. Components which can use the
Android framework API should be accessing this policy via the framework's
android.security.NetworkSecurityPolicy instead of via this class.
The policy currently consists of a single flag: whether cleartext network traffic is
permitted. See isCleartextTrafficPermitted().
| Constructor and Description |
|---|
NetworkSecurityPolicy() |
| Modifier and Type | Method and Description |
|---|---|
static boolean |
isCleartextTrafficPermitted()
Returns whether cleartext network traffic (e.g.
|
static void |
setCleartextTrafficPermitted(boolean permitted)
Sets whether cleartext network traffic (e.g.
|
public static boolean isCleartextTrafficPermitted()
When cleartext network traffic is not permitted, the platform's components (e.g. HTTP
stacks, WebView, MediaPlayer) will refuse this process's requests to use
cleartext traffic. Third-party libraries are encouraged to do the same.
This flag is honored on a best effort basis because it's impossible to prevent all
cleartext traffic from an application given the level of access provided to applications on
Android. For example, there's no expectation that Socket API will honor this
flag. Luckily, most network traffic from apps is handled by higher-level network stacks which
can be made to honor this flag. Platform-provided network stacks (e.g. HTTP and FTP) honor
this flag from day one, and well-established third-party network stacks will eventually
honor it.
See FtpURLConnection for an example of honoring this flag.
public static void setCleartextTrafficPermitted(boolean permitted)
isCleartextTrafficPermitted()