NetworkSecurityPolicy
public
class
NetworkSecurityPolicy
extends Object
| java.lang.Object | |
| ↳ | android.security.NetworkSecurityPolicy |
Network security policy.
Network stacks/components should honor this policy to make it possible to centrally control the relevant aspects of network security behavior.
Summary
Constants | |
|---|---|
int |
DOMAIN_ENCRYPTION_MODE_DISABLED
Domain encryption is disabled for the app. |
int |
DOMAIN_ENCRYPTION_MODE_ENABLED
Domain encryption is in fully enabled mode for the app. |
int |
DOMAIN_ENCRYPTION_MODE_OPPORTUNISTIC
Domain encryption is in opportunistic mode for the app. |
int |
DOMAIN_ENCRYPTION_MODE_UNKNOWN
Unknown setting for domain encryption in the app. |
Public methods | |
|---|---|
int
|
getDomainEncryptionMode(String hostname)
Returns the domain encryption mode the app has chosen for the given |
static
NetworkSecurityPolicy
|
getInstance()
Gets the policy for this process. |
boolean
|
isCertificateTransparencyVerificationRequired(String hostname)
Returns |
boolean
|
isCleartextTrafficPermitted(String hostname)
Returns whether cleartext network traffic (e.g. HTTP, FTP, XMPP, IMAP, SMTP -- without
TLS or STARTTLS) is permitted for communicating with |
boolean
|
isCleartextTrafficPermitted()
Returns whether cleartext network traffic (e.g. HTTP, FTP, WebSockets, XMPP, IMAP, SMTP -- without TLS or STARTTLS) is permitted for all network communication from this process. |
Inherited methods | |
|---|---|
Constants
DOMAIN_ENCRYPTION_MODE_DISABLED
public static final int DOMAIN_ENCRYPTION_MODE_DISABLED
Domain encryption is disabled for the app. ECH and GREASE should not be used.
Constant Value: 1 (0x00000001)
DOMAIN_ENCRYPTION_MODE_ENABLED
public static final int DOMAIN_ENCRYPTION_MODE_ENABLED
Domain encryption is in fully enabled mode for the app. ECH will be enabled when there is server support, otherwise GREASE will be used.
Constant Value: 3 (0x00000003)
DOMAIN_ENCRYPTION_MODE_OPPORTUNISTIC
public static final int DOMAIN_ENCRYPTION_MODE_OPPORTUNISTIC
Domain encryption is in opportunistic mode for the app. ECH will only be enabled when there is server support, and GREASE will not be used.
Constant Value: 2 (0x00000002)
DOMAIN_ENCRYPTION_MODE_UNKNOWN
public static final int DOMAIN_ENCRYPTION_MODE_UNKNOWN
Unknown setting for domain encryption in the app.
This is the default value returned by getDomainEncryptionMode(String) when not
overridden. Network libraries should avoid performing any domain encryption and perform a
standard TLS handshake, equivalent to DOMAIN_ENCRYPTION_MODE_DISABLED.
Constant Value: 0 (0x00000000)
Public methods
getDomainEncryptionMode
public int getDomainEncryptionMode (String hostname)
Returns the domain encryption mode the app has chosen for the given hostname,
including the setting for Encrypted Client Hello.
| Parameters | |
|---|---|
hostname |
String: hostname to check what domain encryption mode has been chosen by the app.
This value cannot be null. |
| Returns | |
|---|---|
int |
int representing the domain encryption mode.
Value is one of the following: |
getInstance
public static NetworkSecurityPolicy getInstance ()
Gets the policy for this process.
It's fine to cache this reference. Any changes to the policy will be immediately visible through the reference.
| Returns | |
|---|---|
NetworkSecurityPolicy |
This value cannot be null. |
isCertificateTransparencyVerificationRequired
public boolean isCertificateTransparencyVerificationRequired (String hostname)
Returns true if Certificate Transparency information is required to be verified by
the client in TLS connections to hostname.
See RFC6962 section 3.3 for more details.
| Parameters | |
|---|---|
hostname |
String: hostname to check whether certificate transparency verification is required.
This value cannot be null. |
| Returns | |
|---|---|
boolean |
true if certificate transparency verification is required and false
otherwise |
isCleartextTrafficPermitted
public boolean isCleartextTrafficPermitted (String hostname)
Returns whether cleartext network traffic (e.g. HTTP, FTP, XMPP, IMAP, SMTP -- without
TLS or STARTTLS) is permitted for communicating with hostname for this process.
| Parameters | |
|---|---|
hostname |
String: This value may be null. |
| Returns | |
|---|---|
boolean |
|
See also:
isCleartextTrafficPermitted
public boolean isCleartextTrafficPermitted ()
Returns whether cleartext network traffic (e.g. HTTP, FTP, WebSockets, XMPP, IMAP, SMTP -- without TLS or STARTTLS) is permitted for all network communication from this process.
When cleartext network traffic is not permitted, the platform's components (e.g. HTTP and
FTP stacks, DownloadManager, MediaPlayer) will
refuse this process's requests to use cleartext traffic. Third-party libraries are strongly
encouraged to honor this setting as well.
This flag is honored on a best effort basis because it's impossible to prevent all
cleartext traffic from Android applications given the level of access provided to them. For
example, there's no expectation that the Socket API will honor this flag
because it cannot determine whether its traffic is in cleartext. However, most network
traffic from applications is handled by higher-level network stacks/components which can
honor this aspect of the policy.
NOTE: WebView honors this flag for applications targeting API level
26 and up.
| Returns | |
|---|---|
boolean |
|