# StrictMode.VmPolicy.Builder

Added in[API level 9](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  
Summary:[Ctors](https://developer.android.com/reference/android/os/StrictMode.VmPolicy.Builder#pubctors)\|[Methods](https://developer.android.com/reference/android/os/StrictMode.VmPolicy.Builder#pubmethods)\|[Inherited Methods](https://developer.android.com/reference/android/os/StrictMode.VmPolicy.Builder#inhmethods)  

# StrictMode.VmPolicy.Builder

*** ** * ** ***

[Kotlin](https://developer.android.com/reference/kotlin/android/os/StrictMode.VmPolicy.Builder "View this page in Kotlin")\|Java

`
public
static
final

class
StrictMode.VmPolicy.Builder
`  
`

extends `[Object](https://developer.android.com/reference/java/lang/Object)`


``


`

|---|----------------------------------------|
| [java.lang.Object](https://developer.android.com/reference/java/lang/Object) ||
| ↳ | android.os.StrictMode.VmPolicy.Builder |

<br />

*** ** * ** ***

Creates[VmPolicy](https://developer.android.com/reference/android/os/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);
 
```

<br />

## Summary

|                                                                                                                              ### Public constructors                                                                                                                               ||
|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|---|
| ` `[Builder](https://developer.android.com/reference/android/os/StrictMode.VmPolicy.Builder#Builder())`() `                                                                                                                                                                     |
| ` `[Builder](https://developer.android.com/reference/android/os/StrictMode.VmPolicy.Builder#Builder(android.os.StrictMode.VmPolicy))`(`[StrictMode.VmPolicy](https://developer.android.com/reference/android/os/StrictMode.VmPolicy)` base) ` Builds upon an existing VmPolicy. |

|                                                                                                                                                                                                                                                                                                                                                                            ### Public methods                                                                                                                                                                                                                                                                                                                                                                            ||
|------------------------------------------------------------------------------------------------------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| ` `[StrictMode.VmPolicy](https://developer.android.com/reference/android/os/StrictMode.VmPolicy)                 | ` `[build](https://developer.android.com/reference/android/os/StrictMode.VmPolicy.Builder#build())`() ` Constructs the VmPolicy instance.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                              |
| ` `[StrictMode.VmPolicy.Builder](https://developer.android.com/reference/android/os/StrictMode.VmPolicy.Builder) | ` `[detectActivityLeaks](https://developer.android.com/reference/android/os/StrictMode.VmPolicy.Builder#detectActivityLeaks())`() ` Detects leaks of[Activity](https://developer.android.com/reference/android/app/Activity)subclasses.                                                                                                                                                                                                                                                                                                                                                                                                                |
| ` `[StrictMode.VmPolicy.Builder](https://developer.android.com/reference/android/os/StrictMode.VmPolicy.Builder) | ` `[detectAll](https://developer.android.com/reference/android/os/StrictMode.VmPolicy.Builder#detectAll())`() ` Detects everything that's potentially suspect.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                         |
| ` `[StrictMode.VmPolicy.Builder](https://developer.android.com/reference/android/os/StrictMode.VmPolicy.Builder) | ` `[detectBlockedBackgroundActivityLaunch](https://developer.android.com/reference/android/os/StrictMode.VmPolicy.Builder#detectBlockedBackgroundActivityLaunch())`() ` Detects when your app is blocked from launching a background activity or a PendingIntent created by your app cannot be launched.                                                                                                                                                                                                                                                                                                                                               |
| ` `[StrictMode.VmPolicy.Builder](https://developer.android.com/reference/android/os/StrictMode.VmPolicy.Builder) | ` `[detectCleartextNetwork](https://developer.android.com/reference/android/os/StrictMode.VmPolicy.Builder#detectCleartextNetwork())`() ` Detects any network traffic from the calling app which is not wrapped in SSL/TLS.                                                                                                                                                                                                                                                                                                                                                                                                                            |
| ` `[StrictMode.VmPolicy.Builder](https://developer.android.com/reference/android/os/StrictMode.VmPolicy.Builder) | ` `[detectContentUriWithoutPermission](https://developer.android.com/reference/android/os/StrictMode.VmPolicy.Builder#detectContentUriWithoutPermission())`() ` Detects when the calling application sends a`content://`[Uri](https://developer.android.com/reference/android/net/Uri)to another app without setting[Intent.FLAG_GRANT_READ_URI_PERMISSION](https://developer.android.com/reference/android/content/Intent#FLAG_GRANT_READ_URI_PERMISSION)or[Intent.FLAG_GRANT_WRITE_URI_PERMISSION](https://developer.android.com/reference/android/content/Intent#FLAG_GRANT_WRITE_URI_PERMISSION).                                                  |
| ` `[StrictMode.VmPolicy.Builder](https://developer.android.com/reference/android/os/StrictMode.VmPolicy.Builder) | ` `[detectCredentialProtectedWhileLocked](https://developer.android.com/reference/android/os/StrictMode.VmPolicy.Builder#detectCredentialProtectedWhileLocked())`() ` Detects access to filesystem paths stored in credential protected storage areas while the user is locked.                                                                                                                                                                                                                                                                                                                                                                        |
| ` `[StrictMode.VmPolicy.Builder](https://developer.android.com/reference/android/os/StrictMode.VmPolicy.Builder) | ` `[detectFileUriExposure](https://developer.android.com/reference/android/os/StrictMode.VmPolicy.Builder#detectFileUriExposure())`() ` Detects when the calling application exposes a`file://`[Uri](https://developer.android.com/reference/android/net/Uri)to another app.                                                                                                                                                                                                                                                                                                                                                                           |
| ` `[StrictMode.VmPolicy.Builder](https://developer.android.com/reference/android/os/StrictMode.VmPolicy.Builder) | ` `[detectImplicitDirectBoot](https://developer.android.com/reference/android/os/StrictMode.VmPolicy.Builder#detectImplicitDirectBoot())`() ` Detects any implicit reliance on Direct Boot automatic filtering of[PackageManager](https://developer.android.com/reference/android/content/pm/PackageManager)values.                                                                                                                                                                                                                                                                                                                                    |
| ` `[StrictMode.VmPolicy.Builder](https://developer.android.com/reference/android/os/StrictMode.VmPolicy.Builder) | ` `[detectIncorrectContextUse](https://developer.android.com/reference/android/os/StrictMode.VmPolicy.Builder#detectIncorrectContextUse())`() ` Detects attempts to invoke a method on a[Context](https://developer.android.com/reference/android/content/Context)that is not suited for such operation.                                                                                                                                                                                                                                                                                                                                               |
| ` `[StrictMode.VmPolicy.Builder](https://developer.android.com/reference/android/os/StrictMode.VmPolicy.Builder) | ` `[detectLeakedClosableObjects](https://developer.android.com/reference/android/os/StrictMode.VmPolicy.Builder#detectLeakedClosableObjects())`() ` Detects when an[Closeable](https://developer.android.com/reference/java/io/Closeable)or other object with an explicit termination method is finalized without having been closed.                                                                                                                                                                                                                                                                                                                  |
| ` `[StrictMode.VmPolicy.Builder](https://developer.android.com/reference/android/os/StrictMode.VmPolicy.Builder) | ` `[detectLeakedRegistrationObjects](https://developer.android.com/reference/android/os/StrictMode.VmPolicy.Builder#detectLeakedRegistrationObjects())`() ` Detects when a[BroadcastReceiver](https://developer.android.com/reference/android/content/BroadcastReceiver)or[ServiceConnection](https://developer.android.com/reference/android/content/ServiceConnection)is leaked during[Context](https://developer.android.com/reference/android/content/Context)teardown.                                                                                                                                                                            |
| ` `[StrictMode.VmPolicy.Builder](https://developer.android.com/reference/android/os/StrictMode.VmPolicy.Builder) | ` `[detectLeakedSqlLiteObjects](https://developer.android.com/reference/android/os/StrictMode.VmPolicy.Builder#detectLeakedSqlLiteObjects())`() ` Detects when an[SQLiteCursor](https://developer.android.com/reference/android/database/sqlite/SQLiteCursor)or other SQLite object is finalized without having been closed.                                                                                                                                                                                                                                                                                                                           |
| ` `[StrictMode.VmPolicy.Builder](https://developer.android.com/reference/android/os/StrictMode.VmPolicy.Builder) | ` `[detectNonSdkApiUsage](https://developer.android.com/reference/android/os/StrictMode.VmPolicy.Builder#detectNonSdkApiUsage())`() ` Detects reflective usage of APIs that are not part of the public Android SDK.                                                                                                                                                                                                                                                                                                                                                                                                                                    |
| ` `[StrictMode.VmPolicy.Builder](https://developer.android.com/reference/android/os/StrictMode.VmPolicy.Builder) | ` `[detectUnsafeIntentLaunch](https://developer.android.com/reference/android/os/StrictMode.VmPolicy.Builder#detectUnsafeIntentLaunch())`() ` Detects when your app sends an unsafe[Intent](https://developer.android.com/reference/android/content/Intent).                                                                                                                                                                                                                                                                                                                                                                                           |
| ` `[StrictMode.VmPolicy.Builder](https://developer.android.com/reference/android/os/StrictMode.VmPolicy.Builder) | ` `[detectUntaggedSockets](https://developer.android.com/reference/android/os/StrictMode.VmPolicy.Builder#detectUntaggedSockets())`() ` Detects any sockets in the calling app which have not been tagged using[TrafficStats](https://developer.android.com/reference/android/net/TrafficStats).                                                                                                                                                                                                                                                                                                                                                       |
| ` `[StrictMode.VmPolicy.Builder](https://developer.android.com/reference/android/os/StrictMode.VmPolicy.Builder) | ` `[ignoreBlockedBackgroundActivityLaunch](https://developer.android.com/reference/android/os/StrictMode.VmPolicy.Builder#ignoreBlockedBackgroundActivityLaunch())`() ` Stops detecting whether your app is blocked from launching a background activity or a PendingIntent created by your app cannot be launched.                                                                                                                                                                                                                                                                                                                                    |
| ` `[StrictMode.VmPolicy.Builder](https://developer.android.com/reference/android/os/StrictMode.VmPolicy.Builder) | ` `[penaltyDeath](https://developer.android.com/reference/android/os/StrictMode.VmPolicy.Builder#penaltyDeath())`() ` Crashes the whole process on violation.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          |
| ` `[StrictMode.VmPolicy.Builder](https://developer.android.com/reference/android/os/StrictMode.VmPolicy.Builder) | ` `[penaltyDeathOnCleartextNetwork](https://developer.android.com/reference/android/os/StrictMode.VmPolicy.Builder#penaltyDeathOnCleartextNetwork())`() ` Crashes the whole process when cleartext network traffic is detected.                                                                                                                                                                                                                                                                                                                                                                                                                        |
| ` `[StrictMode.VmPolicy.Builder](https://developer.android.com/reference/android/os/StrictMode.VmPolicy.Builder) | ` `[penaltyDeathOnFileUriExposure](https://developer.android.com/reference/android/os/StrictMode.VmPolicy.Builder#penaltyDeathOnFileUriExposure())`() ` Crashes the whole process when a`file://`[Uri](https://developer.android.com/reference/android/net/Uri)is exposed beyond this app.                                                                                                                                                                                                                                                                                                                                                             |
| ` `[StrictMode.VmPolicy.Builder](https://developer.android.com/reference/android/os/StrictMode.VmPolicy.Builder) | ` `[penaltyDropBox](https://developer.android.com/reference/android/os/StrictMode.VmPolicy.Builder#penaltyDropBox())`() ` Enables detected violations log a stacktrace and timing data to the[DropBox](https://developer.android.com/reference/android/os/DropBoxManager)on policy violation.                                                                                                                                                                                                                                                                                                                                                          |
| ` `[StrictMode.VmPolicy.Builder](https://developer.android.com/reference/android/os/StrictMode.VmPolicy.Builder) | ` `[penaltyListener](https://developer.android.com/reference/android/os/StrictMode.VmPolicy.Builder#penaltyListener(java.util.concurrent.Executor,%20android.os.StrictMode.OnVmViolationListener))`(`[Executor](https://developer.android.com/reference/java/util/concurrent/Executor)` executor, `[StrictMode.OnVmViolationListener](https://developer.android.com/reference/android/os/StrictMode.OnVmViolationListener)` listener) ` Calls #[OnVmViolationListener.onVmViolation(Violation)](https://developer.android.com/reference/android/os/StrictMode.OnVmViolationListener#onVmViolation(android.os.strictmode.Violation))on every violation. |
| ` `[StrictMode.VmPolicy.Builder](https://developer.android.com/reference/android/os/StrictMode.VmPolicy.Builder) | ` `[penaltyLog](https://developer.android.com/reference/android/os/StrictMode.VmPolicy.Builder#penaltyLog())`() ` Logs detected violations to the system log.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          |
| ` `[StrictMode.VmPolicy.Builder](https://developer.android.com/reference/android/os/StrictMode.VmPolicy.Builder) | ` `[permitNonSdkApiUsage](https://developer.android.com/reference/android/os/StrictMode.VmPolicy.Builder#permitNonSdkApiUsage())`() ` Permits reflective usage of APIs that are not part of the public Android SDK.                                                                                                                                                                                                                                                                                                                                                                                                                                    |
| ` `[StrictMode.VmPolicy.Builder](https://developer.android.com/reference/android/os/StrictMode.VmPolicy.Builder) | ` `[permitUnsafeIntentLaunch](https://developer.android.com/reference/android/os/StrictMode.VmPolicy.Builder#permitUnsafeIntentLaunch())`() ` Permits your app to launch any[Intent](https://developer.android.com/reference/android/content/Intent)which originated from outside your app.                                                                                                                                                                                                                                                                                                                                                            |
| ` `[StrictMode.VmPolicy.Builder](https://developer.android.com/reference/android/os/StrictMode.VmPolicy.Builder) | ` `[setClassInstanceLimit](https://developer.android.com/reference/android/os/StrictMode.VmPolicy.Builder#setClassInstanceLimit(java.lang.Class,%20int))`(`[Class](https://developer.android.com/reference/java/lang/Class)`<T> klass, int instanceLimit) ` Sets an upper bound on how many instances of a class can be in memory at once.                                                                                                                                                                                                                                                                                                             |

| ### Inherited methods |
|-----------------------|---|
| From class` `[java.lang.Object](https://developer.android.com/reference/java/lang/Object)` ` |--------------------------------------------------------------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| | ` `[Object](https://developer.android.com/reference/java/lang/Object)          | ` `[clone](https://developer.android.com/reference/java/lang/Object#clone())`() ` Creates and returns a copy of this object.                                                                                                                                                      | | ` boolean`                                                                     | ` `[equals](https://developer.android.com/reference/java/lang/Object#equals(java.lang.Object))`(`[Object](https://developer.android.com/reference/java/lang/Object)` obj) ` Indicates whether some other object is "equal to" this one.                                           | | ` void`                                                                        | ` `[finalize](https://developer.android.com/reference/java/lang/Object#finalize())`() ` Called by the garbage collector on an object when garbage collection determines that there are no more references to the object.                                                          | | ` final `[Class](https://developer.android.com/reference/java/lang/Class)`<?>` | ` `[getClass](https://developer.android.com/reference/java/lang/Object#getClass())`() ` Returns the runtime class of this`Object`.                                                                                                                                                | | ` int`                                                                         | ` `[hashCode](https://developer.android.com/reference/java/lang/Object#hashCode())`() ` Returns a hash code value for the object.                                                                                                                                                 | | ` final void`                                                                  | ` `[notify](https://developer.android.com/reference/java/lang/Object#notify())`() ` Wakes up a single thread that is waiting on this object's monitor.                                                                                                                            | | ` final void`                                                                  | ` `[notifyAll](https://developer.android.com/reference/java/lang/Object#notifyAll())`() ` Wakes up all threads that are waiting on this object's monitor.                                                                                                                         | | ` `[String](https://developer.android.com/reference/java/lang/String)          | ` `[toString](https://developer.android.com/reference/java/lang/Object#toString())`() ` Returns a string representation of the object.                                                                                                                                            | | ` final void`                                                                  | ` `[wait](https://developer.android.com/reference/java/lang/Object#wait(long,%20int))`(long timeoutMillis, int nanos) ` Causes the current thread to wait until it is awakened, typically by being*notified* or*interrupted*, or until a certain amount of real time has elapsed. | | ` final void`                                                                  | ` `[wait](https://developer.android.com/reference/java/lang/Object#wait(long))`(long timeoutMillis) ` Causes the current thread to wait until it is awakened, typically by being*notified* or*interrupted*, or until a certain amount of real time has elapsed.                   | | ` final void`                                                                  | ` `[wait](https://developer.android.com/reference/java/lang/Object#wait())`() ` Causes the current thread to wait until it is awakened, typically by being*notified* or*interrupted*.                                                                                             | ||

## Public constructors

### Builder

Added in[API level 9](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public Builder ()
```

<br />

<br />

### Builder

Added in[API level 11](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public Builder (StrictMode.VmPolicy base)
```

Builds upon an existing VmPolicy.

<br />

|              Parameters              ||
|--------|------------------------------|
| `base` | `StrictMode.VmPolicy` <br /> |

## Public methods

### build

Added in[API level 9](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public StrictMode.VmPolicy build ()
```

Constructs the VmPolicy instance.

Note: if no penalties are enabled before calling`build`,[penaltyLog()](https://developer.android.com/reference/android/os/StrictMode.VmPolicy.Builder#penaltyLog())is implicitly set.

<br />

|                                                Returns                                                ||
|-----------------------------------------------------------------------------------------------|--------|
| [StrictMode.VmPolicy](https://developer.android.com/reference/android/os/StrictMode.VmPolicy) | <br /> |

### detectActivityLeaks

Added in[API level 11](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public StrictMode.VmPolicy.Builder detectActivityLeaks ()
```

Detects leaks of[Activity](https://developer.android.com/reference/android/app/Activity)subclasses.

<br />

|                                                                      Returns                                                                      ||
|---------------------------------------------------------------------------------------------------------------|------------------------------------|
| [StrictMode.VmPolicy.Builder](https://developer.android.com/reference/android/os/StrictMode.VmPolicy.Builder) | This value cannot be`null`. <br /> |

### detectAll

Added in[API level 9](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public StrictMode.VmPolicy.Builder detectAll ()
```

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

<br />

|                                                                      Returns                                                                      ||
|---------------------------------------------------------------------------------------------------------------|------------------------------------|
| [StrictMode.VmPolicy.Builder](https://developer.android.com/reference/android/os/StrictMode.VmPolicy.Builder) | This value cannot be`null`. <br /> |

### detectBlockedBackgroundActivityLaunch

Added in[API level 36](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public StrictMode.VmPolicy.Builder detectBlockedBackgroundActivityLaunch ()
```

Detects when your app is blocked from launching a background activity or a PendingIntent created by your app cannot be launched.

Starting an activity requires[specific permissions](https://developer.android.com/guide/components/activities/background-starts)which may depend on the state at runtime and especially in case of[PendingIntent](https://developer.android.com/reference/android/app/PendingIntent)starts on the collaborating app. If the activity start is blocked methods like[Context.startActivity(Intent)](https://developer.android.com/reference/android/content/Context#startActivity(android.content.Intent))or[PendingIntent.send()](https://developer.android.com/reference/android/app/PendingIntent#send())have no way to return that information. Instead you can use this strct mode feature to detect blocked starts.

Note that in some cases blocked starts may be unavoidable, e.g. when the user clicks the home button while the app tries to start a new activity.

<br />

|                                                                      Returns                                                                      ||
|---------------------------------------------------------------------------------------------------------------|------------------------------------|
| [StrictMode.VmPolicy.Builder](https://developer.android.com/reference/android/os/StrictMode.VmPolicy.Builder) | This value cannot be`null`. <br /> |

### detectCleartextNetwork

Added in[API level 23](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public StrictMode.VmPolicy.Builder detectCleartextNetwork ()
```

Detects 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()](https://developer.android.com/reference/android/os/StrictMode.VmPolicy.Builder#penaltyDeath())or[penaltyDeathOnCleartextNetwork()](https://developer.android.com/reference/android/os/StrictMode.VmPolicy.Builder#penaltyDeathOnCleartextNetwork())will block further traffic on that socket to prevent accidental data leakage, in addition to crashing your process.

Using[penaltyDropBox()](https://developer.android.com/reference/android/os/StrictMode.VmPolicy.Builder#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.

<br />

|                                                                      Returns                                                                      ||
|---------------------------------------------------------------------------------------------------------------|------------------------------------|
| [StrictMode.VmPolicy.Builder](https://developer.android.com/reference/android/os/StrictMode.VmPolicy.Builder) | This value cannot be`null`. <br /> |

### detectContentUriWithoutPermission

Added in[API level 26](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public StrictMode.VmPolicy.Builder detectContentUriWithoutPermission ()
```

Detects when the calling application sends a`content://`[Uri](https://developer.android.com/reference/android/net/Uri)to another app without setting[Intent.FLAG_GRANT_READ_URI_PERMISSION](https://developer.android.com/reference/android/content/Intent#FLAG_GRANT_READ_URI_PERMISSION)or[Intent.FLAG_GRANT_WRITE_URI_PERMISSION](https://developer.android.com/reference/android/content/Intent#FLAG_GRANT_WRITE_URI_PERMISSION).

Forgetting to include one or more of these flags when sending an intent is typically an app bug.

<br />

|                                                                      Returns                                                                      ||
|---------------------------------------------------------------------------------------------------------------|------------------------------------|
| [StrictMode.VmPolicy.Builder](https://developer.android.com/reference/android/os/StrictMode.VmPolicy.Builder) | This value cannot be`null`. <br /> |

**See also:**

- [Intent.FLAG_GRANT_READ_URI_PERMISSION](https://developer.android.com/reference/android/content/Intent#FLAG_GRANT_READ_URI_PERMISSION)
- [Intent.FLAG_GRANT_WRITE_URI_PERMISSION](https://developer.android.com/reference/android/content/Intent#FLAG_GRANT_WRITE_URI_PERMISSION)  

### detectCredentialProtectedWhileLocked

Added in[API level 29](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public StrictMode.VmPolicy.Builder detectCredentialProtectedWhileLocked ()
```

Detects access to filesystem paths stored in credential protected storage areas while the user is locked.

When a user is locked, credential protected storage is unavailable, and files stored in these locations appear to not exist, which can result in subtle app bugs if they assume default behaviors or empty states. Instead, apps should store data needed while a user is locked under device protected storage areas.

<br />

|                                                                      Returns                                                                      ||
|---------------------------------------------------------------------------------------------------------------|------------------------------------|
| [StrictMode.VmPolicy.Builder](https://developer.android.com/reference/android/os/StrictMode.VmPolicy.Builder) | This value cannot be`null`. <br /> |

**See also:**

- [Context.createDeviceProtectedStorageContext()](https://developer.android.com/reference/android/content/Context#createDeviceProtectedStorageContext())  

### detectFileUriExposure

Added in[API level 18](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public StrictMode.VmPolicy.Builder detectFileUriExposure ()
```

Detects when the calling application exposes a`file://`[Uri](https://developer.android.com/reference/android/net/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[Manifest.permission.READ_EXTERNAL_STORAGE](https://developer.android.com/reference/android/Manifest.permission#READ_EXTERNAL_STORAGE)runtime permission, or the platform may be sharing the[Uri](https://developer.android.com/reference/android/net/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.

<br />

|                                                                      Returns                                                                      ||
|---------------------------------------------------------------------------------------------------------------|------------------------------------|
| [StrictMode.VmPolicy.Builder](https://developer.android.com/reference/android/os/StrictMode.VmPolicy.Builder) | This value cannot be`null`. <br /> |

**See also:**

- [FileProvider](https://developer.android.com/reference/androidx/core/content/FileProvider.html)
- [Intent.FLAG_GRANT_READ_URI_PERMISSION](https://developer.android.com/reference/android/content/Intent#FLAG_GRANT_READ_URI_PERMISSION)  

### detectImplicitDirectBoot

Added in[API level 29](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public StrictMode.VmPolicy.Builder detectImplicitDirectBoot ()
```

Detects any implicit reliance on Direct Boot automatic filtering of[PackageManager](https://developer.android.com/reference/android/content/pm/PackageManager)values. Violations are only triggered when implicit calls are made while the user is locked.

Apps becoming Direct Boot aware need to carefully inspect each query site and explicitly decide which combination of flags they want to use:

- [PackageManager.MATCH_DIRECT_BOOT_AWARE](https://developer.android.com/reference/android/content/pm/PackageManager#MATCH_DIRECT_BOOT_AWARE)
- [PackageManager.MATCH_DIRECT_BOOT_UNAWARE](https://developer.android.com/reference/android/content/pm/PackageManager#MATCH_DIRECT_BOOT_UNAWARE)
- [PackageManager.MATCH_DIRECT_BOOT_AUTO](https://developer.android.com/reference/android/content/pm/PackageManager#MATCH_DIRECT_BOOT_AUTO)

<br />

<br />

|                                                                      Returns                                                                      ||
|---------------------------------------------------------------------------------------------------------------|------------------------------------|
| [StrictMode.VmPolicy.Builder](https://developer.android.com/reference/android/os/StrictMode.VmPolicy.Builder) | This value cannot be`null`. <br /> |

### detectIncorrectContextUse

Added in[API level 31](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public StrictMode.VmPolicy.Builder detectIncorrectContextUse ()
```

Detects attempts to invoke a method on a[Context](https://developer.android.com/reference/android/content/Context)that is not suited for such operation.

An example of this is trying to obtain an instance of UI service (e.g.[WindowManager](https://developer.android.com/reference/android/view/WindowManager)) from a non-visual[Context](https://developer.android.com/reference/android/content/Context). This is not allowed, since a non-visual[Context](https://developer.android.com/reference/android/content/Context)is not adjusted to any visual area, and therefore can report incorrect metrics or resources.

<br />

|                                                                      Returns                                                                      ||
|---------------------------------------------------------------------------------------------------------------|------------------------------------|
| [StrictMode.VmPolicy.Builder](https://developer.android.com/reference/android/os/StrictMode.VmPolicy.Builder) | This value cannot be`null`. <br /> |

**See also:**

- [Context.getDisplay()](https://developer.android.com/reference/android/content/Context#getDisplay())
- [Context.getSystemService(String)](https://developer.android.com/reference/android/content/Context#getSystemService(java.lang.String))  

### detectLeakedClosableObjects

Added in[API level 11](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public StrictMode.VmPolicy.Builder detectLeakedClosableObjects ()
```

Detects when an[Closeable](https://developer.android.com/reference/java/io/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.

<br />

|                                                                      Returns                                                                      ||
|---------------------------------------------------------------------------------------------------------------|------------------------------------|
| [StrictMode.VmPolicy.Builder](https://developer.android.com/reference/android/os/StrictMode.VmPolicy.Builder) | This value cannot be`null`. <br /> |

### detectLeakedRegistrationObjects

Added in[API level 16](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public StrictMode.VmPolicy.Builder detectLeakedRegistrationObjects ()
```

Detects when a[BroadcastReceiver](https://developer.android.com/reference/android/content/BroadcastReceiver)or[ServiceConnection](https://developer.android.com/reference/android/content/ServiceConnection)is leaked during[Context](https://developer.android.com/reference/android/content/Context)teardown.

<br />

|                                                                      Returns                                                                      ||
|---------------------------------------------------------------------------------------------------------------|------------------------------------|
| [StrictMode.VmPolicy.Builder](https://developer.android.com/reference/android/os/StrictMode.VmPolicy.Builder) | This value cannot be`null`. <br /> |

### detectLeakedSqlLiteObjects

Added in[API level 9](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public StrictMode.VmPolicy.Builder detectLeakedSqlLiteObjects ()
```

Detects when an[SQLiteCursor](https://developer.android.com/reference/android/database/sqlite/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.

<br />

|                                                                      Returns                                                                      ||
|---------------------------------------------------------------------------------------------------------------|------------------------------------|
| [StrictMode.VmPolicy.Builder](https://developer.android.com/reference/android/os/StrictMode.VmPolicy.Builder) | This value cannot be`null`. <br /> |

### detectNonSdkApiUsage

Added in[API level 28](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public StrictMode.VmPolicy.Builder detectNonSdkApiUsage ()
```

Detects reflective usage of APIs that are not part of the public Android SDK.

Note that any non-SDK APIs that this processes accesses before this detection is enabled may not be detected. To ensure that all such API accesses are detected, you should apply this policy as early as possible after process creation.

<br />

|                                                                      Returns                                                                      ||
|---------------------------------------------------------------------------------------------------------------|------------------------------------|
| [StrictMode.VmPolicy.Builder](https://developer.android.com/reference/android/os/StrictMode.VmPolicy.Builder) | This value cannot be`null`. <br /> |

### detectUnsafeIntentLaunch

Added in[API level 31](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public StrictMode.VmPolicy.Builder detectUnsafeIntentLaunch ()
```

Detects when your app sends an unsafe[Intent](https://developer.android.com/reference/android/content/Intent).

Violations may indicate security vulnerabilities in the design of your app, where a malicious app could trick you into granting[Uri](https://developer.android.com/reference/android/net/Uri)permissions or launching unexported components. Here are some typical design patterns that can be used to safely resolve these violations:

- If you are sending an implicit intent to an unexported component, you should make it an explicit intent by using[Intent.setPackage](https://developer.android.com/reference/android/content/Intent#setPackage(java.lang.String)),[Intent.setClassName](https://developer.android.com/reference/android/content/Intent#setClassName(android.content.Context,%20java.lang.String))or[Intent.setComponent](https://developer.android.com/reference/android/content/Intent#setComponent(android.content.ComponentName)).
- If you are unparceling and sending an intent from the intent delivered, The ideal approach is to migrate to using a[PendingIntent](https://developer.android.com/reference/android/app/PendingIntent), which ensures that your launch is performed using the identity of the original creator, completely avoiding the security issues described above.
- If using a[PendingIntent](https://developer.android.com/reference/android/app/PendingIntent)isn't feasible, an alternative approach is to create a brand new[Intent](https://developer.android.com/reference/android/content/Intent)and carefully copy only specific values from the original[Intent](https://developer.android.com/reference/android/content/Intent)after careful validation.

Note that this*may* detect false-positives if your app sends itself an[Intent](https://developer.android.com/reference/android/content/Intent)which is first routed through the OS, such as using[Intent.createChooser](https://developer.android.com/reference/android/content/Intent#createChooser(android.content.Intent,%20java.lang.CharSequence)). In these cases, careful inspection is required to determine if the return point into your app is appropriately protected with a signature permission or marked as unexported. If the return point is not protected, your app is likely vulnerable to malicious apps.

<br />

|                                                                      Returns                                                                      ||
|---------------------------------------------------------------------------------------------------------------|------------------------------------|
| [StrictMode.VmPolicy.Builder](https://developer.android.com/reference/android/os/StrictMode.VmPolicy.Builder) | This value cannot be`null`. <br /> |

**See also:**

- [Context.startActivity(Intent)](https://developer.android.com/reference/android/content/Context#startActivity(android.content.Intent))
- [Context.startService(Intent)](https://developer.android.com/reference/android/content/Context#startService(android.content.Intent))
- [Context.bindService(Intent, ServiceConnection, int)](https://developer.android.com/reference/android/content/Context#bindService(android.content.Intent,%20android.content.ServiceConnection,%20int))
- [Context.sendBroadcast(Intent)](https://developer.android.com/reference/android/content/Context#sendBroadcast(android.content.Intent))
- [Activity.setResult(int, Intent)](https://developer.android.com/reference/android/app/Activity#setResult(int,%20android.content.Intent))  

### detectUntaggedSockets

Added in[API level 26](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public StrictMode.VmPolicy.Builder detectUntaggedSockets ()
```

Detects any sockets in the calling app which have not been tagged using[TrafficStats](https://developer.android.com/reference/android/net/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.

<br />

|                                                                      Returns                                                                      ||
|---------------------------------------------------------------------------------------------------------------|------------------------------------|
| [StrictMode.VmPolicy.Builder](https://developer.android.com/reference/android/os/StrictMode.VmPolicy.Builder) | This value cannot be`null`. <br /> |

**See also:**

- [TrafficStats.setThreadStatsTag(int)](https://developer.android.com/reference/android/net/TrafficStats#setThreadStatsTag(int))
- [TrafficStats.tagSocket(java.net.Socket)](https://developer.android.com/reference/android/net/TrafficStats#tagSocket(java.net.Socket))
- [TrafficStats.tagDatagramSocket(java.net.DatagramSocket)](https://developer.android.com/reference/android/net/TrafficStats#tagDatagramSocket(java.net.DatagramSocket))  

### ignoreBlockedBackgroundActivityLaunch

Added in[API level 36](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public StrictMode.VmPolicy.Builder ignoreBlockedBackgroundActivityLaunch ()
```

Stops detecting whether your app is blocked from launching a background activity or a PendingIntent created by your app cannot be launched.

This disables the effect of[detectBlockedBackgroundActivityLaunch()](https://developer.android.com/reference/android/os/StrictMode.VmPolicy.Builder#detectBlockedBackgroundActivityLaunch()).

<br />

|                                                                      Returns                                                                      ||
|---------------------------------------------------------------------------------------------------------------|------------------------------------|
| [StrictMode.VmPolicy.Builder](https://developer.android.com/reference/android/os/StrictMode.VmPolicy.Builder) | This value cannot be`null`. <br /> |

### penaltyDeath

Added in[API level 9](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public 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.

<br />

|                                                                      Returns                                                                      ||
|---------------------------------------------------------------------------------------------------------------|------------------------------------|
| [StrictMode.VmPolicy.Builder](https://developer.android.com/reference/android/os/StrictMode.VmPolicy.Builder) | This value cannot be`null`. <br /> |

### penaltyDeathOnCleartextNetwork

Added in[API level 23](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public StrictMode.VmPolicy.Builder penaltyDeathOnCleartextNetwork ()
```

Crashes the whole process when cleartext network traffic is detected.

<br />

|                                                                      Returns                                                                      ||
|---------------------------------------------------------------------------------------------------------------|------------------------------------|
| [StrictMode.VmPolicy.Builder](https://developer.android.com/reference/android/os/StrictMode.VmPolicy.Builder) | This value cannot be`null`. <br /> |

**See also:**

- [detectCleartextNetwork()](https://developer.android.com/reference/android/os/StrictMode.VmPolicy.Builder#detectCleartextNetwork())  

### penaltyDeathOnFileUriExposure

Added in[API level 24](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public StrictMode.VmPolicy.Builder penaltyDeathOnFileUriExposure ()
```

Crashes the whole process when a`file://`[Uri](https://developer.android.com/reference/android/net/Uri)is exposed beyond this app.

<br />

|                                                                      Returns                                                                      ||
|---------------------------------------------------------------------------------------------------------------|------------------------------------|
| [StrictMode.VmPolicy.Builder](https://developer.android.com/reference/android/os/StrictMode.VmPolicy.Builder) | This value cannot be`null`. <br /> |

**See also:**

- [detectFileUriExposure()](https://developer.android.com/reference/android/os/StrictMode.VmPolicy.Builder#detectFileUriExposure())  

### penaltyDropBox

Added in[API level 9](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public StrictMode.VmPolicy.Builder penaltyDropBox ()
```

Enables detected violations log a stacktrace and timing data to the[DropBox](https://developer.android.com/reference/android/os/DropBoxManager)on policy violation. Intended mostly for platform integrators doing beta user field data collection.

<br />

|                                                                      Returns                                                                      ||
|---------------------------------------------------------------------------------------------------------------|------------------------------------|
| [StrictMode.VmPolicy.Builder](https://developer.android.com/reference/android/os/StrictMode.VmPolicy.Builder) | This value cannot be`null`. <br /> |

### penaltyListener

Added in[API level 28](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public StrictMode.VmPolicy.Builder penaltyListener (Executor executor, 
                StrictMode.OnVmViolationListener listener)
```

Calls #[OnVmViolationListener.onVmViolation(Violation)](https://developer.android.com/reference/android/os/StrictMode.OnVmViolationListener#onVmViolation(android.os.strictmode.Violation))on every violation.

<br />

|                                     Parameters                                     ||
|------------|------------------------------------------------------------------------|
| `executor` | `Executor`: This value cannot be`null`. <br />                         |
| `listener` | `StrictMode.OnVmViolationListener`: This value cannot be`null`. <br /> |

|                                                                      Returns                                                                      ||
|---------------------------------------------------------------------------------------------------------------|------------------------------------|
| [StrictMode.VmPolicy.Builder](https://developer.android.com/reference/android/os/StrictMode.VmPolicy.Builder) | This value cannot be`null`. <br /> |

### penaltyLog

Added in[API level 9](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public StrictMode.VmPolicy.Builder penaltyLog ()
```

Logs detected violations to the system log.

<br />

|                                                                      Returns                                                                      ||
|---------------------------------------------------------------------------------------------------------------|------------------------------------|
| [StrictMode.VmPolicy.Builder](https://developer.android.com/reference/android/os/StrictMode.VmPolicy.Builder) | This value cannot be`null`. <br /> |

### permitNonSdkApiUsage

Added in[API level 28](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public StrictMode.VmPolicy.Builder permitNonSdkApiUsage ()
```

Permits reflective usage of APIs that are not part of the public Android SDK. Note that this**only** affects`StrictMode`, the underlying runtime may continue to restrict or warn on access to methods that are not part of the public SDK.

<br />

|                                                                      Returns                                                                      ||
|---------------------------------------------------------------------------------------------------------------|------------------------------------|
| [StrictMode.VmPolicy.Builder](https://developer.android.com/reference/android/os/StrictMode.VmPolicy.Builder) | This value cannot be`null`. <br /> |

### permitUnsafeIntentLaunch

Added in[API level 31](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public StrictMode.VmPolicy.Builder permitUnsafeIntentLaunch ()
```

Permits your app to launch any[Intent](https://developer.android.com/reference/android/content/Intent)which originated from outside your app.

Disabling this check is*strongly discouraged* , as violations may indicate security vulnerabilities in the design of your app, where a malicious app could trick you into granting[Uri](https://developer.android.com/reference/android/net/Uri)permissions or launching unexported components.

<br />

|                                                                      Returns                                                                      ||
|---------------------------------------------------------------------------------------------------------------|------------------------------------|
| [StrictMode.VmPolicy.Builder](https://developer.android.com/reference/android/os/StrictMode.VmPolicy.Builder) | This value cannot be`null`. <br /> |

**See also:**

- [detectUnsafeIntentLaunch()](https://developer.android.com/reference/android/os/StrictMode.VmPolicy.Builder#detectUnsafeIntentLaunch())  

### setClassInstanceLimit

Added in[API level 11](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public StrictMode.VmPolicy.Builder setClassInstanceLimit (Class<T> klass, 
                int instanceLimit)
```

Sets an upper bound on how many instances of a class can be in memory at once. Helps to prevent object leaks.

<br />

|           Parameters            ||
|-----------------|----------------|
| `klass`         | `Class` <br /> |
| `instanceLimit` | `int` <br />   |

|                                                                      Returns                                                                      ||
|---------------------------------------------------------------------------------------------------------------|------------------------------------|
| [StrictMode.VmPolicy.Builder](https://developer.android.com/reference/android/os/StrictMode.VmPolicy.Builder) | This value cannot be`null`. <br /> |