public static final class StrictMode.ThreadPolicy.Builder extends Object
StrictMode.ThreadPolicy
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.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder() .detectAll() .penaltyLog() .build(); StrictMode.setThreadPolicy(policy);
Constructor and Description |
---|
Builder()
Create a Builder that detects nothing and has no
violations.
|
Builder(StrictMode.ThreadPolicy policy)
Initialize a Builder from an existing ThreadPolicy.
|
Modifier and Type | Method and Description |
---|---|
StrictMode.ThreadPolicy |
build()
Construct the ThreadPolicy instance.
|
StrictMode.ThreadPolicy.Builder |
detectAll()
Detect everything that's potentially suspect.
|
StrictMode.ThreadPolicy.Builder |
detectCustomSlowCalls()
Enable detection of slow calls.
|
StrictMode.ThreadPolicy.Builder |
detectDiskReads()
Enable detection of disk reads.
|
StrictMode.ThreadPolicy.Builder |
detectDiskWrites()
Enable detection of disk writes.
|
StrictMode.ThreadPolicy.Builder |
detectNetwork()
Enable detection of network operations.
|
StrictMode.ThreadPolicy.Builder |
detectResourceMismatches()
Enables detection of mismatches between defined resource types
and getter calls.
|
StrictMode.ThreadPolicy.Builder |
penaltyDeath()
Crash the whole process on violation.
|
StrictMode.ThreadPolicy.Builder |
penaltyDeathOnNetwork()
Crash the whole process on any network usage.
|
StrictMode.ThreadPolicy.Builder |
penaltyDialog()
Show an annoying dialog to the developer on detected
violations, rate-limited to be only a little annoying.
|
StrictMode.ThreadPolicy.Builder |
penaltyDropBox()
Enable detected violations log a stacktrace and timing data
to the
DropBox on policy
violation. |
StrictMode.ThreadPolicy.Builder |
penaltyFlashScreen()
Flash the screen during a violation.
|
StrictMode.ThreadPolicy.Builder |
penaltyLog()
Log detected violations to the system log.
|
StrictMode.ThreadPolicy.Builder |
permitAll()
Disable the detection of everything.
|
StrictMode.ThreadPolicy.Builder |
permitCustomSlowCalls()
Disable detection of slow calls.
|
StrictMode.ThreadPolicy.Builder |
permitDiskReads()
Disable detection of disk reads.
|
StrictMode.ThreadPolicy.Builder |
permitDiskWrites()
Disable detection of disk writes.
|
StrictMode.ThreadPolicy.Builder |
permitNetwork()
Disable detection of network operations.
|
StrictMode.ThreadPolicy.Builder |
permitResourceMismatches()
Disable detection of mismatches between defined resource types
and getter calls.
|
public Builder()
build()
will default
to enabling penaltyLog()
if no other penalties
are specified)public Builder(StrictMode.ThreadPolicy policy)
public StrictMode.ThreadPolicy.Builder detectAll()
As of the Gingerbread release this includes network and disk operations but will likely expand in future releases.
public StrictMode.ThreadPolicy.Builder permitAll()
public StrictMode.ThreadPolicy.Builder detectNetwork()
public StrictMode.ThreadPolicy.Builder permitNetwork()
public StrictMode.ThreadPolicy.Builder detectDiskReads()
public StrictMode.ThreadPolicy.Builder permitDiskReads()
public StrictMode.ThreadPolicy.Builder detectCustomSlowCalls()
public StrictMode.ThreadPolicy.Builder permitCustomSlowCalls()
public StrictMode.ThreadPolicy.Builder permitResourceMismatches()
public StrictMode.ThreadPolicy.Builder detectResourceMismatches()
This helps detect accidental type mismatches and potentially expensive type conversions when obtaining typed resources.
For example, a strict mode violation would be thrown when
calling TypedArray.getInt(int, int)
on an index that contains a String-type resource. If the string
value can be parsed as an integer, this method call will return
a value without crashing; however, the developer should format
the resource as an integer to avoid unnecessary type conversion.
public StrictMode.ThreadPolicy.Builder detectDiskWrites()
public StrictMode.ThreadPolicy.Builder permitDiskWrites()
public StrictMode.ThreadPolicy.Builder penaltyDialog()
public StrictMode.ThreadPolicy.Builder penaltyDeath()
Unlike penaltyDeathOnNetwork()
, this applies
to disk reads, disk writes, and network usage if their
corresponding detect flags are set.
public StrictMode.ThreadPolicy.Builder penaltyDeathOnNetwork()
penaltyDeath()
, this penalty runs
before anything else. You must still have
called detectNetwork()
to enable this.
In the Honeycomb or later SDKs, this is on by default.
public StrictMode.ThreadPolicy.Builder penaltyFlashScreen()
public StrictMode.ThreadPolicy.Builder penaltyLog()
public StrictMode.ThreadPolicy.Builder penaltyDropBox()
DropBox
on policy
violation. Intended mostly for platform integrators doing
beta user field data collection.public StrictMode.ThreadPolicy build()
Note: if no penalties are enabled before calling
build
, penaltyLog()
is implicitly
set.