public static final class

StrictMode.ThreadPolicy.Builder

extends Object
java.lang.Object
   ↳ android.os.StrictMode.ThreadPolicy.Builder

Class Overview

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.VmPolicy policy = new StrictMode.VmPolicy.Builder()
     .detectAll()
     .penaltyLog()
     .build();
 StrictMode.setVmPolicy(policy);
 

Summary

Public Constructors
StrictMode.ThreadPolicy.Builder()
Create a Builder that detects nothing and has no violations.
StrictMode.ThreadPolicy.Builder(StrictMode.ThreadPolicy policy)
Initialize a Builder from an existing ThreadPolicy.
Public Methods
StrictMode.ThreadPolicy build()
Construct the ThreadPolicy instance.
StrictMode.ThreadPolicy.Builder detectAll()
Detect everything that's potentially suspect.
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 penaltyDeath()
Crash the whole process on violation.
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 penaltyLog()
Log detected violations to the system log.
StrictMode.ThreadPolicy.Builder permitAll()
Disable the detection of everything.
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.
[Expand]
Inherited Methods
From class java.lang.Object

Public Constructors

public StrictMode.ThreadPolicy.Builder ()

Since: API Level 9

Create a Builder that detects nothing and has no violations. (but note that build() will default to enabling penaltyLog() if no other penalties are specified)

public StrictMode.ThreadPolicy.Builder (StrictMode.ThreadPolicy policy)

Since: API Level 9

Initialize a Builder from an existing ThreadPolicy.

Public Methods

public StrictMode.ThreadPolicy build ()

Since: API Level 9

Construct the ThreadPolicy instance.

Note: if no penalties are enabled before calling build, penaltyLog() is implicitly set.

public StrictMode.ThreadPolicy.Builder detectAll ()

Since: API Level 9

Detect everything that's potentially suspect.

As of the Gingerbread release this includes network and disk operations but will likely expand in future releases.

public StrictMode.ThreadPolicy.Builder detectDiskReads ()

Since: API Level 9

Enable detection of disk reads.

public StrictMode.ThreadPolicy.Builder detectDiskWrites ()

Since: API Level 9

Enable detection of disk writes.

public StrictMode.ThreadPolicy.Builder detectNetwork ()

Since: API Level 9

Enable detection of network operations.

public StrictMode.ThreadPolicy.Builder penaltyDeath ()

Since: API Level 9

Crash 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.

public StrictMode.ThreadPolicy.Builder penaltyDialog ()

Since: API Level 9

Show an annoying dialog to the developer on detected violations, rate-limited to be only a little annoying.

public StrictMode.ThreadPolicy.Builder penaltyDropBox ()

Since: API Level 9

Enable detected violations log a stacktrace and timing data to the DropBox on policy violation. Intended mostly for platform integrators doing beta user field data collection.

public StrictMode.ThreadPolicy.Builder penaltyLog ()

Since: API Level 9

Log detected violations to the system log.

public StrictMode.ThreadPolicy.Builder permitAll ()

Since: API Level 9

Disable the detection of everything.

public StrictMode.ThreadPolicy.Builder permitDiskReads ()

Since: API Level 9

Disable detection of disk reads.

public StrictMode.ThreadPolicy.Builder permitDiskWrites ()

Since: API Level 9

Disable detection of disk writes.

public StrictMode.ThreadPolicy.Builder permitNetwork ()

Since: API Level 9

Disable detection of network operations.