Builder
class Builder
kotlin.Any | |
↳ | android.os.StrictMode.ThreadPolicy.Builder |
Creates 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);
Summary
Public constructors | |
---|---|
Builder() Creates a Builder that detects nothing and has no violations. |
|
Builder(policy: StrictMode.ThreadPolicy!) Initializes a Builder from an existing ThreadPolicy. |
Public methods | |
---|---|
StrictMode.ThreadPolicy! |
build() Constructs the ThreadPolicy instance. |
StrictMode.ThreadPolicy.Builder |
Detects everything that's potentially suspect. |
StrictMode.ThreadPolicy.Builder |
Enables detection of slow calls. |
StrictMode.ThreadPolicy.Builder |
Enables detection of disk reads. |
StrictMode.ThreadPolicy.Builder |
Enables detection of disk writes. |
StrictMode.ThreadPolicy.Builder |
Detects calls to |
StrictMode.ThreadPolicy.Builder |
Enables detection of network operations. |
StrictMode.ThreadPolicy.Builder |
Enables detection of mismatches between defined resource types and getter calls. |
StrictMode.ThreadPolicy.Builder |
Detects unbuffered input/output operations. |
StrictMode.ThreadPolicy.Builder |
Crashes the whole process on violation. |
StrictMode.ThreadPolicy.Builder |
Crashes the whole process on any network usage. |
StrictMode.ThreadPolicy.Builder |
Shows an annoying dialog to the developer on detected violations, rate-limited to be only a little annoying. |
StrictMode.ThreadPolicy.Builder |
Enables detected violations log a stacktrace and timing data to the on policy violation. |
StrictMode.ThreadPolicy.Builder |
Flashes the screen during a violation. |
StrictMode.ThreadPolicy.Builder |
penaltyListener(executor: Executor, listener: StrictMode.OnThreadViolationListener) Calls # |
StrictMode.ThreadPolicy.Builder |
Logs detected violations to the system log. |
StrictMode.ThreadPolicy.Builder |
Disables the detection of everything. |
StrictMode.ThreadPolicy.Builder |
Disables detection of slow calls. |
StrictMode.ThreadPolicy.Builder |
Disables detection of disk reads. |
StrictMode.ThreadPolicy.Builder |
Disables detection of disk writes. |
StrictMode.ThreadPolicy.Builder |
Disables detection of calls to |
StrictMode.ThreadPolicy.Builder |
Disables detection of network operations. |
StrictMode.ThreadPolicy.Builder |
Disables detection of mismatches between defined resource types and getter calls. |
StrictMode.ThreadPolicy.Builder |
Disables detection of unbuffered input/output operations. |
Public constructors
Builder
Builder()
Creates a Builder that detects nothing and has no violations. (but note that build
will default to enabling penaltyLog
if no other penalties are specified)
Builder
Builder(policy: StrictMode.ThreadPolicy!)
Initializes a Builder from an existing ThreadPolicy.
Public methods
build
fun build(): StrictMode.ThreadPolicy!
Constructs the ThreadPolicy instance.
Note: if no penalties are enabled before calling build
, penaltyLog
is implicitly set.
detectAll
fun detectAll(): StrictMode.ThreadPolicy.Builder
Detects everything that's potentially suspect.
As of the Gingerbread release this includes network and disk operations but will likely expand in future releases.
Return | |
---|---|
StrictMode.ThreadPolicy.Builder |
This value cannot be null . |
detectCustomSlowCalls
fun detectCustomSlowCalls(): StrictMode.ThreadPolicy.Builder
Enables detection of slow calls.
Return | |
---|---|
StrictMode.ThreadPolicy.Builder |
This value cannot be null . |
detectDiskReads
fun detectDiskReads(): StrictMode.ThreadPolicy.Builder
Enables detection of disk reads.
Return | |
---|---|
StrictMode.ThreadPolicy.Builder |
This value cannot be null . |
detectDiskWrites
fun detectDiskWrites(): StrictMode.ThreadPolicy.Builder
Enables detection of disk writes.
Return | |
---|---|
StrictMode.ThreadPolicy.Builder |
This value cannot be null . |
detectExplicitGc
fun detectExplicitGc(): StrictMode.ThreadPolicy.Builder
Detects calls to Runtime.gc()
.
Return | |
---|---|
StrictMode.ThreadPolicy.Builder |
This value cannot be null . |
detectNetwork
fun detectNetwork(): StrictMode.ThreadPolicy.Builder
Enables detection of network operations.
Return | |
---|---|
StrictMode.ThreadPolicy.Builder |
This value cannot be null . |
detectResourceMismatches
fun detectResourceMismatches(): StrictMode.ThreadPolicy.Builder
Enables detection of mismatches between defined resource types and getter calls.
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 android.content.res.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.
Return | |
---|---|
StrictMode.ThreadPolicy.Builder |
This value cannot be null . |
detectUnbufferedIo
fun detectUnbufferedIo(): StrictMode.ThreadPolicy.Builder
Detects unbuffered input/output operations.
Return | |
---|---|
StrictMode.ThreadPolicy.Builder |
This value cannot be null . |
penaltyDeath
fun penaltyDeath(): StrictMode.ThreadPolicy.Builder
Crashes the whole process on violation. This penalty runs at the end of all enabled penalties so you'll still get see logging or other violations before the process dies.
Unlike penaltyDeathOnNetwork
, this applies to disk reads, disk writes, and network usage if their corresponding detect flags are set.
Return | |
---|---|
StrictMode.ThreadPolicy.Builder |
This value cannot be null . |
penaltyDeathOnNetwork
fun penaltyDeathOnNetwork(): StrictMode.ThreadPolicy.Builder
Crashes the whole process on any network usage. Unlike 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.
Return | |
---|---|
StrictMode.ThreadPolicy.Builder |
This value cannot be null . |
penaltyDialog
fun penaltyDialog(): StrictMode.ThreadPolicy.Builder
Shows an annoying dialog to the developer on detected violations, rate-limited to be only a little annoying.
Return | |
---|---|
StrictMode.ThreadPolicy.Builder |
This value cannot be null . |
penaltyDropBox
fun penaltyDropBox(): StrictMode.ThreadPolicy.Builder
Enables detected violations log a stacktrace and timing data to the on policy violation. Intended mostly for platform integrators doing beta user field data collection.
Return | |
---|---|
StrictMode.ThreadPolicy.Builder |
This value cannot be null . |
penaltyFlashScreen
fun penaltyFlashScreen(): StrictMode.ThreadPolicy.Builder
Flashes the screen during a violation.
Return | |
---|---|
StrictMode.ThreadPolicy.Builder |
This value cannot be null . |
penaltyListener
fun penaltyListener(
executor: Executor,
listener: StrictMode.OnThreadViolationListener
): StrictMode.ThreadPolicy.Builder
Calls #OnThreadViolationListener.onThreadViolation(Violation)
on specified executor every violation.
Parameters | |
---|---|
executor |
Executor: This value cannot be null . |
listener |
StrictMode.OnThreadViolationListener: This value cannot be null . |
Return | |
---|---|
StrictMode.ThreadPolicy.Builder |
This value cannot be null . |
penaltyLog
fun penaltyLog(): StrictMode.ThreadPolicy.Builder
Logs detected violations to the system log.
Return | |
---|---|
StrictMode.ThreadPolicy.Builder |
This value cannot be null . |
permitAll
fun permitAll(): StrictMode.ThreadPolicy.Builder
Disables the detection of everything.
Return | |
---|---|
StrictMode.ThreadPolicy.Builder |
This value cannot be null . |
permitCustomSlowCalls
fun permitCustomSlowCalls(): StrictMode.ThreadPolicy.Builder
Disables detection of slow calls.
Return | |
---|---|
StrictMode.ThreadPolicy.Builder |
This value cannot be null . |
permitDiskReads
fun permitDiskReads(): StrictMode.ThreadPolicy.Builder
Disables detection of disk reads.
Return | |
---|---|
StrictMode.ThreadPolicy.Builder |
This value cannot be null . |
permitDiskWrites
fun permitDiskWrites(): StrictMode.ThreadPolicy.Builder
Disables detection of disk writes.
Return | |
---|---|
StrictMode.ThreadPolicy.Builder |
This value cannot be null . |
permitExplicitGc
fun permitExplicitGc(): StrictMode.ThreadPolicy.Builder
Disables detection of calls to Runtime.gc()
.
Return | |
---|---|
StrictMode.ThreadPolicy.Builder |
This value cannot be null . |
permitNetwork
fun permitNetwork(): StrictMode.ThreadPolicy.Builder
Disables detection of network operations.
Return | |
---|---|
StrictMode.ThreadPolicy.Builder |
This value cannot be null . |
permitResourceMismatches
fun permitResourceMismatches(): StrictMode.ThreadPolicy.Builder
Disables detection of mismatches between defined resource types and getter calls.
Return | |
---|---|
StrictMode.ThreadPolicy.Builder |
This value cannot be null . |
permitUnbufferedIo
fun permitUnbufferedIo(): StrictMode.ThreadPolicy.Builder
Disables detection of unbuffered input/output operations.
Return | |
---|---|
StrictMode.ThreadPolicy.Builder |
This value cannot be null . |