public static final class StrictMode.VmPolicy.Builder extends Object
StrictMode.VmPolicy
instances. Methods whose names start
with detect
specify what problems we should look
for. Methods whose names start with penalty
specify what
we should do when we detect a problem.
You can call as many detect
and penalty
methods as you like. Currently order is insignificant: all
penalties apply to all detected problems.
For example, detect everything and log anything that's found:
StrictMode.VmPolicy policy = new StrictMode.VmPolicy.Builder() .detectAll() .penaltyLog() .build(); StrictMode.setVmPolicy(policy);
Constructor and Description |
---|
Builder() |
Builder(StrictMode.VmPolicy base)
Build upon an existing VmPolicy.
|
Modifier and Type | Method and Description |
---|---|
StrictMode.VmPolicy |
build()
Construct the VmPolicy instance.
|
StrictMode.VmPolicy.Builder |
detectActivityLeaks()
Detect leaks of
Activity subclasses. |
StrictMode.VmPolicy.Builder |
detectAll()
Detect everything that's potentially suspect.
|
StrictMode.VmPolicy.Builder |
detectCleartextNetwork()
Detect any network traffic from the calling app which is not
wrapped in SSL/TLS.
|
StrictMode.VmPolicy.Builder |
detectFileUriExposure()
Detect when this application exposes a
file://
Uri to another app. |
StrictMode.VmPolicy.Builder |
detectLeakedClosableObjects()
Detect when an
Closeable or other
object with a explict termination method is finalized
without having been closed. |
StrictMode.VmPolicy.Builder |
detectLeakedRegistrationObjects()
|
StrictMode.VmPolicy.Builder |
detectLeakedSqlLiteObjects()
Detect when an
SQLiteCursor or other
SQLite object is finalized without having been closed. |
StrictMode.VmPolicy.Builder |
penaltyDeath()
Crashes the whole process on violation.
|
StrictMode.VmPolicy.Builder |
penaltyDeathOnCleartextNetwork()
Crashes the whole process when cleartext network traffic is
detected.
|
StrictMode.VmPolicy.Builder |
penaltyDeathOnFileUriExposure()
Crashes the whole process when a
file://
Uri is exposed beyond this app. |
StrictMode.VmPolicy.Builder |
penaltyDropBox()
Enable detected violations log a stacktrace and timing data
to the
DropBox on policy
violation. |
StrictMode.VmPolicy.Builder |
penaltyLog()
Log detected violations to the system log.
|
StrictMode.VmPolicy.Builder |
setClassInstanceLimit(Class klass,
int instanceLimit)
Set an upper bound on how many instances of a class can be in memory
at once.
|
public Builder()
public Builder(StrictMode.VmPolicy base)
public StrictMode.VmPolicy.Builder setClassInstanceLimit(Class klass, int instanceLimit)
public StrictMode.VmPolicy.Builder detectActivityLeaks()
Activity
subclasses.public StrictMode.VmPolicy.Builder detectAll()
In the Honeycomb release this includes leaks of SQLite cursors, Activities, and other closable objects but will likely expand in future releases.
public StrictMode.VmPolicy.Builder detectLeakedSqlLiteObjects()
SQLiteCursor
or other
SQLite object is finalized without having been closed.
You always want to explicitly close your SQLite cursors to avoid unnecessary database contention and temporary memory leaks.
public StrictMode.VmPolicy.Builder detectLeakedClosableObjects()
Closeable
or other
object with a explict termination method is finalized
without having been closed.
You always want to explicitly close such objects to avoid unnecessary resources leaks.
public StrictMode.VmPolicy.Builder detectLeakedRegistrationObjects()
public StrictMode.VmPolicy.Builder detectFileUriExposure()
file://
Uri
to another app.
This exposure is discouraged since the receiving app may not have
access to the shared path. For example, the receiving app may not
have requested the
android.Manifest.permission#READ_EXTERNAL_STORAGE
runtime
permission, or the platform may be sharing the
Uri
across user profile boundaries.
Instead, apps should use content://
Uris so the platform
can extend temporary permission for the receiving app to access
the resource.
public StrictMode.VmPolicy.Builder detectCleartextNetwork()
Using penaltyDeath()
or
penaltyDeathOnCleartextNetwork()
will block further
traffic on that socket to prevent accidental data leakage, in
addition to crashing your process.
Using penaltyDropBox()
will log the raw contents of the
packet that triggered the violation.
This inspects both IPv4/IPv6 and TCP/UDP network traffic, but it may be subject to false positives, such as when STARTTLS protocols or HTTP proxies are used.
public StrictMode.VmPolicy.Builder penaltyDeath()
public StrictMode.VmPolicy.Builder penaltyDeathOnCleartextNetwork()
detectCleartextNetwork()
public StrictMode.VmPolicy.Builder penaltyDeathOnFileUriExposure()
file://
Uri
is exposed beyond this app.detectFileUriExposure()
public StrictMode.VmPolicy.Builder penaltyLog()
public StrictMode.VmPolicy.Builder penaltyDropBox()
DropBox
on policy
violation. Intended mostly for platform integrators doing
beta user field data collection.public StrictMode.VmPolicy build()
Note: if no penalties are enabled before calling
build
, penaltyLog()
is implicitly
set.