StrictMode.VmPolicy.Builder
public
static
final
class
StrictMode.VmPolicy.Builder
extends Object
| java.lang.Object | |
| ↳ | android.os.StrictMode.VmPolicy.Builder |
Creates 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);
Summary
Public constructors | |
|---|---|
StrictMode.VmPolicy.Builder()
|
|
StrictMode.VmPolicy.Builder(StrictMode.VmPolicy base)
Build upon an existing VmPolicy. |
|
Public methods | |
|---|---|
StrictMode.VmPolicy
|
build()
Construct the VmPolicy instance. |
StrictMode.VmPolicy.Builder
|
detectActivityLeaks()
Detect leaks of |
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
|
detectContentUriWithoutPermission()
Detect when the calling application sends a |
StrictMode.VmPolicy.Builder
|
detectFileUriExposure()
Detect when the calling application exposes a |
StrictMode.VmPolicy.Builder
|
detectLeakedClosableObjects()
Detect when an |
StrictMode.VmPolicy.Builder
|
detectLeakedRegistrationObjects()
Detect when a |
StrictMode.VmPolicy.Builder
|
detectLeakedSqlLiteObjects()
Detect when an |
StrictMode.VmPolicy.Builder
|
detectUntaggedSockets()
Detect any sockets in the calling app which have not been tagged using |
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 |
StrictMode.VmPolicy.Builder
|
penaltyDropBox()
Enable detected violations log a stacktrace and timing data to the |
StrictMode.VmPolicy.Builder
|
penaltyListener(StrictMode.OnVmViolationListener listener, Executor executor)
Call # |
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. |
Inherited methods | |
|---|---|
Public constructors
StrictMode.VmPolicy.Builder
StrictMode.VmPolicy.Builder (StrictMode.VmPolicy base)
Build upon an existing VmPolicy.
| Parameters | |
|---|---|
base |
StrictMode.VmPolicy |
Public methods
build
StrictMode.VmPolicy build ()
Construct the VmPolicy instance.
Note: if no penalties are enabled before calling build, penaltyLog() is implicitly set.
| Returns | |
|---|---|
StrictMode.VmPolicy |
|
detectActivityLeaks
StrictMode.VmPolicy.Builder detectActivityLeaks ()
Detect leaks of Activity subclasses.
| Returns | |
|---|---|
StrictMode.VmPolicy.Builder |
|
detectAll
StrictMode.VmPolicy.Builder detectAll ()
Detect everything that's potentially suspect.
In the Honeycomb release this includes leaks of SQLite cursors, Activities, and other closable objects but will likely expand in future releases.
| Returns | |
|---|---|
StrictMode.VmPolicy.Builder |
|
detectCleartextNetwork
StrictMode.VmPolicy.Builder detectCleartextNetwork ()
Detect any network traffic from the calling app which is not wrapped in SSL/TLS. This can help you detect places that your app is inadvertently sending cleartext data across the network.
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.
| Returns | |
|---|---|
StrictMode.VmPolicy.Builder |
|
detectContentUriWithoutPermission
StrictMode.VmPolicy.Builder detectContentUriWithoutPermission ()
Detect when the calling application sends a content:// Uri to another app without setting FLAG_GRANT_READ_URI_PERMISSION or FLAG_GRANT_WRITE_URI_PERMISSION.
Forgetting to include one or more of these flags when sending an intent is typically an app bug.
| Returns | |
|---|---|
StrictMode.VmPolicy.Builder |
|
detectFileUriExposure
StrictMode.VmPolicy.Builder detectFileUriExposure ()
Detect when the calling application exposes a 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 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.
| Returns | |
|---|---|
StrictMode.VmPolicy.Builder |
|
detectLeakedClosableObjects
StrictMode.VmPolicy.Builder detectLeakedClosableObjects ()
Detect when an Closeable or other object with an explicit termination
method is finalized without having been closed.
You always want to explicitly close such objects to avoid unnecessary resources leaks.
| Returns | |
|---|---|
StrictMode.VmPolicy.Builder |
|
detectLeakedRegistrationObjects
StrictMode.VmPolicy.Builder detectLeakedRegistrationObjects ()
Detect when a BroadcastReceiver or ServiceConnection is leaked during
Context teardown.
| Returns | |
|---|---|
StrictMode.VmPolicy.Builder |
|
detectLeakedSqlLiteObjects
StrictMode.VmPolicy.Builder detectLeakedSqlLiteObjects ()
Detect when an 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.
| Returns | |
|---|---|
StrictMode.VmPolicy.Builder |
|
detectUntaggedSockets
StrictMode.VmPolicy.Builder detectUntaggedSockets ()
Detect any sockets in the calling app which have not been tagged using TrafficStats. Tagging sockets can help you investigate network usage inside your
app, such as a narrowing down heavy usage to a specific library or component.
This currently does not detect sockets created in native code.
| Returns | |
|---|---|
StrictMode.VmPolicy.Builder |
|
penaltyDeath
StrictMode.VmPolicy.Builder penaltyDeath ()
Crashes the whole process on violation. This penalty runs at the end of all enabled penalties so you'll still get your logging or other violations before the process dies.
| Returns | |
|---|---|
StrictMode.VmPolicy.Builder |
|
penaltyDeathOnCleartextNetwork
StrictMode.VmPolicy.Builder penaltyDeathOnCleartextNetwork ()
Crashes the whole process when cleartext network traffic is detected.
| Returns | |
|---|---|
StrictMode.VmPolicy.Builder |
|
See also:
penaltyDeathOnFileUriExposure
StrictMode.VmPolicy.Builder penaltyDeathOnFileUriExposure ()
Crashes the whole process when a file:// Uri is exposed
beyond this app.
| Returns | |
|---|---|
StrictMode.VmPolicy.Builder |
|
See also:
penaltyDropBox
StrictMode.VmPolicy.Builder penaltyDropBox ()
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.
| Returns | |
|---|---|
StrictMode.VmPolicy.Builder |
|
penaltyListener
StrictMode.VmPolicy.Builder penaltyListener (StrictMode.OnVmViolationListener listener, Executor executor)
Call #onVmViolation(Violation) on every violation.
| Parameters | |
|---|---|
listener |
StrictMode.OnVmViolationListener This value must never be |
executor |
Executor This value must never be |
| Returns | |
|---|---|
StrictMode.VmPolicy.Builder |
|
penaltyLog
StrictMode.VmPolicy.Builder penaltyLog ()
Log detected violations to the system log.
| Returns | |
|---|---|
StrictMode.VmPolicy.Builder |
|
setClassInstanceLimit
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. Helps to prevent object leaks.
| Parameters | |
|---|---|
klass |
Class |
instanceLimit |
int |
| Returns | |
|---|---|
StrictMode.VmPolicy.Builder |
|
Interfaces
- CancellationSignal.OnCancelListener
- Handler.Callback
- IBinder
- IBinder.DeathRecipient
- IInterface
- MessageQueue.IdleHandler
- MessageQueue.OnFileDescriptorEventListener
- Parcelable
- Parcelable.ClassLoaderCreator
- Parcelable.Creator
- ParcelFileDescriptor.OnCloseListener
- RecoverySystem.ProgressListener
- StrictMode.OnThreadViolationListener
- StrictMode.OnVmViolationListener
Classes
- AsyncTask
- BaseBundle
- BatteryManager
- Binder
- Build
- Build.VERSION
- Build.VERSION_CODES
- Bundle
- CancellationSignal
- ConditionVariable
- CountDownTimer
- CpuUsageInfo
- Debug
- Debug.InstructionCount
- Debug.MemoryInfo
- DropBoxManager
- DropBoxManager.Entry
- Environment
- FileObserver
- Handler
- HandlerThread
- HardwarePropertiesManager
- LocaleList
- Looper
- MemoryFile
- Message
- MessageQueue
- Messenger
- Parcel
- ParcelFileDescriptor
- ParcelFileDescriptor.AutoCloseInputStream
- ParcelFileDescriptor.AutoCloseOutputStream
- ParcelUuid
- PatternMatcher
- PersistableBundle
- PowerManager
- PowerManager.WakeLock
- Process
- ProxyFileDescriptorCallback
- RecoverySystem
- RemoteCallbackList
- ResultReceiver
- SharedMemory
- StatFs
- StrictMode
- StrictMode.ThreadPolicy
- StrictMode.ThreadPolicy.Builder
- StrictMode.VmPolicy
- StrictMode.VmPolicy.Builder
- SystemClock
- TestLooperManager
- TokenWatcher
- Trace
- UserHandle
- UserManager
- VibrationEffect
- Vibrator
- WorkSource
Enums
Exceptions


