Added in [API level 34](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels) Summary: [Constants](https://developer.android.com/reference/android/devicelock/DeviceLockManager#constants) \| [Methods](https://developer.android.com/reference/android/devicelock/DeviceLockManager#pubmethods) \| [Inherited Methods](https://developer.android.com/reference/android/devicelock/DeviceLockManager#inhmethods)

# DeviceLockManager

*** ** * ** ***

` public final class DeviceLockManager `   
` extends https://developer.android.com/reference/java/lang/Object ` ` `

|---|---|
| [java.lang.Object](https://developer.android.com/reference/java/lang/Object) ||
| ↳ | android.devicelock.DeviceLockManager |

<br />

*** ** * ** ***

Manager used to interact with the system device lock service. The device lock feature is used by special applications ('kiosk apps', downloaded and installed by the device lock solution) to lock and unlock a device. A typical use case is a financed device, where the financing entity has the capability to lock the device in case of a missed payment. When a device is locked, only a limited set of interactions with the device is allowed (for example, placing emergency calls).

Use `https://developer.android.com/reference/android/content/Context#getSystemService(java.lang.String)` with `https://developer.android.com/reference/android/content/Context#DEVICE_LOCK_SERVICE` to create a `https://developer.android.com/reference/android/devicelock/DeviceLockManager`.
.   
Requires the `https://developer.android.com/reference/android/content/pm/PackageManager#FEATURE_DEVICE_LOCK` feature which can be detected using `https://developer.android.com/reference/android/content/pm/PackageManager#hasSystemFeature(java.lang.String)`.

<br />

## Summary

| ### Constants ||
|---|---|
| `int` | `https://developer.android.com/reference/android/devicelock/DeviceLockManager#DEVICE_LOCK_ROLE_FINANCING` Constant representing a financed device role, returned by `https://developer.android.com/reference/android/devicelock/DeviceLockManager#getKioskApps(java.util.concurrent.Executor,%20android.os.OutcomeReceiver<java.util.Map<java.lang.Integer,java.lang.String>,java.lang.Exception>)`. |
| `https://developer.android.com/reference/java/lang/String` | `https://developer.android.com/reference/android/devicelock/DeviceLockManager#EXTRA_DEVICE_LOCK_VERSION` Extra passed to the kiosk setup activity containing the version of the Device Lock solution that started the activity. |

| ### Public methods ||
|---|---|
| ` void` | ` https://developer.android.com/reference/android/devicelock/DeviceLockManager#clearDeviceRestrictions(java.util.concurrent.Executor,%20android.os.OutcomeReceiver<java.lang.Void,java.lang.Exception>)(https://developer.android.com/reference/java/util/concurrent/Executor executor, https://developer.android.com/reference/android/os/OutcomeReceiver<https://developer.android.com/reference/java/lang/Void, https://developer.android.com/reference/java/lang/Exception> callback) ` Clear device restrictions. |
| ` void` | ` https://developer.android.com/reference/android/devicelock/DeviceLockManager#getDeviceId(java.util.concurrent.Executor,%20android.os.OutcomeReceiver<android.devicelock.DeviceId,java.lang.Exception>)(https://developer.android.com/reference/java/util/concurrent/Executor executor, https://developer.android.com/reference/android/os/OutcomeReceiver<https://developer.android.com/reference/android/devicelock/DeviceId, https://developer.android.com/reference/java/lang/Exception> callback) ` Gets the device id. |
| ` void` | ` https://developer.android.com/reference/android/devicelock/DeviceLockManager#getKioskApps(java.util.concurrent.Executor,%20android.os.OutcomeReceiver<java.util.Map<java.lang.Integer,java.lang.String>,java.lang.Exception>)(https://developer.android.com/reference/java/util/concurrent/Executor executor, https://developer.android.com/reference/android/os/OutcomeReceiver<https://developer.android.com/reference/java/util/Map<https://developer.android.com/reference/java/lang/Integer, https://developer.android.com/reference/java/lang/String>, https://developer.android.com/reference/java/lang/Exception> callback) ` Get the kiosk app roles and packages. |
| ` void` | ` https://developer.android.com/reference/android/devicelock/DeviceLockManager#isDeviceLocked(java.util.concurrent.Executor,%20android.os.OutcomeReceiver<java.lang.Boolean,java.lang.Exception>)(https://developer.android.com/reference/java/util/concurrent/Executor executor, https://developer.android.com/reference/android/os/OutcomeReceiver<https://developer.android.com/reference/java/lang/Boolean, https://developer.android.com/reference/java/lang/Exception> callback) ` Checks if the device is locked or not. |
| ` void` | ` https://developer.android.com/reference/android/devicelock/DeviceLockManager#lockDevice(java.util.concurrent.Executor,%20android.os.OutcomeReceiver<java.lang.Void,java.lang.Exception>)(https://developer.android.com/reference/java/util/concurrent/Executor executor, https://developer.android.com/reference/android/os/OutcomeReceiver<https://developer.android.com/reference/java/lang/Void, https://developer.android.com/reference/java/lang/Exception> callback) ` Locks the device. |
| ` void` | ` https://developer.android.com/reference/android/devicelock/DeviceLockManager#notifyKioskSetupFinished(java.util.concurrent.Executor,%20android.os.OutcomeReceiver<java.lang.Void,java.lang.Exception>)(https://developer.android.com/reference/java/util/concurrent/Executor executor, https://developer.android.com/reference/android/os/OutcomeReceiver<https://developer.android.com/reference/java/lang/Void, https://developer.android.com/reference/java/lang/Exception> callback) ` Notifies DLC that kiosk set-up has finished and we no longer need to lock to the set-up activity. |
| ` void` | ` https://developer.android.com/reference/android/devicelock/DeviceLockManager#unlockDevice(java.util.concurrent.Executor,%20android.os.OutcomeReceiver<java.lang.Void,java.lang.Exception>)(https://developer.android.com/reference/java/util/concurrent/Executor executor, https://developer.android.com/reference/android/os/OutcomeReceiver<https://developer.android.com/reference/java/lang/Void, https://developer.android.com/reference/java/lang/Exception> callback) ` Unlocks the device. |

### Inherited methods

From class ` https://developer.android.com/reference/java/lang/Object ` ` https://developer.android.com/reference/java/lang/Object` ` https://developer.android.com/reference/java/lang/Object#clone()() `

Creates and returns a copy of this object.
` boolean` ` https://developer.android.com/reference/java/lang/Object#equals(java.lang.Object)(https://developer.android.com/reference/java/lang/Object obj) `

Indicates whether some other object is "equal to" this one.
` void` ` 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 https://developer.android.com/reference/java/lang/Class<?>` ` https://developer.android.com/reference/java/lang/Object#getClass()() `

Returns the runtime class of this `Object`.
` int` ` https://developer.android.com/reference/java/lang/Object#hashCode()() `

Returns a hash code value for the object.
` final void` ` https://developer.android.com/reference/java/lang/Object#notify()() `

Wakes up a single thread that is waiting on this object's monitor.
` final void` ` https://developer.android.com/reference/java/lang/Object#notifyAll()() `

Wakes up all threads that are waiting on this object's monitor.
` https://developer.android.com/reference/java/lang/String` ` https://developer.android.com/reference/java/lang/Object#toString()() `

Returns a string representation of the object.
` final void` ` 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` ` 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` ` 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*.

## Constants

### DEVICE_LOCK_ROLE_FINANCING

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

```
public static final int DEVICE_LOCK_ROLE_FINANCING
```

Constant representing a financed device role, returned by `https://developer.android.com/reference/android/devicelock/DeviceLockManager#getKioskApps(java.util.concurrent.Executor,%20android.os.OutcomeReceiver<java.util.Map<java.lang.Integer,java.lang.String>,java.lang.Exception>)`.

<br />

Constant Value: 0 (0x00000000)

### EXTRA_DEVICE_LOCK_VERSION

Added in [version 36.1](https://developer.android.com/topic/libraries/support-library/revisions)

```
public static final String EXTRA_DEVICE_LOCK_VERSION
```

Extra passed to the kiosk setup activity containing the version of the Device Lock solution that started the activity. The kiosk setup activity can retrieve the version by calling getIntent().getIntExtra(DeviceLockManager.EXTRA_DEVICE_LOCK_VERSION, 1) This is meant to be used by kiosk apps sharing the same setup activity between the legacy Device Owner(DO) based DeviceLock solution (version 1) and successive versions.

<br />

Constant Value: "android.devicelock.extra.DEVICE_LOCK_VERSION"

## Public methods

### clearDeviceRestrictions

Added in [version 36.1](https://developer.android.com/topic/libraries/support-library/revisions)

```
public void clearDeviceRestrictions (Executor executor, 
                OutcomeReceiver<Void, Exception> callback)
```

Clear device restrictions.

After a device determines that it's part of a program (e.g. financing) by checking in with the device lock backend, it will go though a provisioning flow and install a kiosk app.

At this point, the device is "restricted" and the creditor kiosk app is able to lock the device. For example, a creditor kiosk app in a financing use case may lock the device (using `https://developer.android.com/reference/android/devicelock/DeviceLockManager#lockDevice(java.util.concurrent.Executor,%20android.os.OutcomeReceiver<java.lang.Void,java.lang.Exception>)`) if payments are missed and unlock (using `https://developer.android.com/reference/android/devicelock/DeviceLockManager#unlockDevice(java.util.concurrent.Executor,%20android.os.OutcomeReceiver<java.lang.Void,java.lang.Exception>)`)) once they are resumed.

The Device Lock solution will also put in place some additional restrictions when a device is enrolled in the program, namely:

- Disable debugging features (`https://developer.android.com/reference/android/os/UserManager#DISALLOW_DEBUGGING_FEATURES`)
- Disable installing from unknown sources (`https://developer.android.com/reference/android/os/UserManager#DISALLOW_INSTALL_UNKNOWN_SOURCES`, when configured in the backend)
- Disable outgoing calls (`https://developer.android.com/reference/android/os/UserManager#DISALLOW_OUTGOING_CALLS`, when configured in the backend and the device is locked)

Once the program is completed (e.g. the device has been fully paid off), the kiosk app can use the `https://developer.android.com/reference/android/devicelock/DeviceLockManager#clearDeviceRestrictions(java.util.concurrent.Executor,%20android.os.OutcomeReceiver<java.lang.Void,java.lang.Exception>)` API to lift the above restrictions.

At this point, the kiosk app has relinquished its ability to lock the device.

Exceptions that can be returned through the ParcelableException on the callback's `onError` method:

- `https://developer.android.com/reference/java/lang/SecurityException` if the caller is missing the `https://developer.android.com/` permission.
- `https://developer.android.com/reference/java/lang/IllegalStateException` if the device has already been cleared or if policies could not be enforced for the clear state.
- `https://developer.android.com/reference/java/util/concurrent/TimeoutException` if the response from the underlying binder call is not received within the specified duration (10 seconds).

.   
Requires `https://developer.android.com/reference/android/Manifest.permission#MANAGE_DEVICE_LOCK_STATE`

<br />

<br />

| Parameters ||
|---|---|
| `executor` | `Executor`: the `https://developer.android.com/reference/java/util/concurrent/Executor` on which to invoke the callback. This value cannot be `null`. Callback and listener events are dispatched through this `https://developer.android.com/reference/java/util/concurrent/Executor`, providing an easy way to control which thread is used. To dispatch events through the main thread of your application, you can use `https://developer.android.com/reference/android/content/Context#getMainExecutor()`. Otherwise, provide an `https://developer.android.com/reference/java/util/concurrent/Executor` that dispatches to an appropriate thread. <br /> |
| `callback` | `OutcomeReceiver`: this returns either success or an exception. This value cannot be `null`. <br /> |

| Throws ||
|---|---|
| `https://developer.android.com/reference/java/lang/RuntimeException` | if there are binder communications errors |

### getDeviceId

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

```
public void getDeviceId (Executor executor, 
                OutcomeReceiver<DeviceId, Exception> callback)
```

Gets the device id.

Exceptions that can be returned through the ParcelableException on the callback's `onError` method:

- `https://developer.android.com/reference/java/lang/SecurityException` if the caller is missing the `https://developer.android.com/` permission.
- `https://developer.android.com/reference/java/lang/IllegalStateException` if no registered Device ID is found.
- `https://developer.android.com/reference/java/util/concurrent/TimeoutException` if the response from the underlying binder call is not received within the specified duration (10 seconds).

.   
Requires `https://developer.android.com/reference/android/Manifest.permission#MANAGE_DEVICE_LOCK_STATE`

<br />

<br />

| Parameters ||
|---|---|
| `executor` | `Executor`: the `https://developer.android.com/reference/java/util/concurrent/Executor` on which to invoke the callback. This value cannot be `null`. Callback and listener events are dispatched through this `https://developer.android.com/reference/java/util/concurrent/Executor`, providing an easy way to control which thread is used. To dispatch events through the main thread of your application, you can use `https://developer.android.com/reference/android/content/Context#getMainExecutor()`. Otherwise, provide an `https://developer.android.com/reference/java/util/concurrent/Executor` that dispatches to an appropriate thread. <br /> |
| `callback` | `OutcomeReceiver`: this returns either the `https://developer.android.com/reference/android/devicelock/DeviceId` or an exception. This value cannot be `null`. <br /> |

| Throws ||
|---|---|
| `https://developer.android.com/reference/java/lang/RuntimeException` | if there are binder communications errors |

### getKioskApps

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

```
public void getKioskApps (Executor executor, 
                OutcomeReceiver<Map<Integer, String>, Exception> callback)
```

Get the kiosk app roles and packages.

<br />

| Parameters ||
|---|---|
| `executor` | `Executor`: the `https://developer.android.com/reference/java/util/concurrent/Executor` on which to invoke the callback. This value cannot be `null`. Callback and listener events are dispatched through this `https://developer.android.com/reference/java/util/concurrent/Executor`, providing an easy way to control which thread is used. To dispatch events through the main thread of your application, you can use `https://developer.android.com/reference/android/content/Context#getMainExecutor()`. Otherwise, provide an `https://developer.android.com/reference/java/util/concurrent/Executor` that dispatches to an appropriate thread. <br /> |
| `callback` | `OutcomeReceiver`: this returns either a `https://developer.android.com/reference/java/util/Map` of device roles/package names, or an exception. The Integer in the map represent the device lock role (at this moment, the only supported role is `https://developer.android.com/reference/android/devicelock/DeviceLockManager#DEVICE_LOCK_ROLE_FINANCING`. The String represents the package name of the kiosk app for that role. This value cannot be `null`. <br /> |

| Throws ||
|---|---|
| `https://developer.android.com/reference/java/lang/RuntimeException` | if there are binder communications errors |

### isDeviceLocked

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

```
public void isDeviceLocked (Executor executor, 
                OutcomeReceiver<Boolean, Exception> callback)
```

Checks if the device is locked or not.

Exceptions that can be returned through the ParcelableException on the callback's `onError` method:

- `https://developer.android.com/reference/java/lang/SecurityException` if the caller is missing the `https://developer.android.com/` permission.
- `https://developer.android.com/reference/java/lang/IllegalStateException` if called before setting the locked state of the device through `https://developer.android.com/reference/android/devicelock/DeviceLockManager#lockDevice(java.util.concurrent.Executor,%20android.os.OutcomeReceiver<java.lang.Void,java.lang.Exception>)` or `https://developer.android.com/reference/android/devicelock/DeviceLockManager#unlockDevice(java.util.concurrent.Executor,%20android.os.OutcomeReceiver<java.lang.Void,java.lang.Exception>)`.
- `https://developer.android.com/reference/java/util/concurrent/TimeoutException` if the response from the underlying binder call is not received within the specified duration (10 seconds).

.   
Requires `https://developer.android.com/reference/android/Manifest.permission#MANAGE_DEVICE_LOCK_STATE`

<br />

<br />

| Parameters ||
|---|---|
| `executor` | `Executor`: the `https://developer.android.com/reference/java/util/concurrent/Executor` on which to invoke the callback. This value cannot be `null`. Callback and listener events are dispatched through this `https://developer.android.com/reference/java/util/concurrent/Executor`, providing an easy way to control which thread is used. To dispatch events through the main thread of your application, you can use `https://developer.android.com/reference/android/content/Context#getMainExecutor()`. Otherwise, provide an `https://developer.android.com/reference/java/util/concurrent/Executor` that dispatches to an appropriate thread. <br /> |
| `callback` | `OutcomeReceiver`: this returns either the lock status or an exception. This value cannot be `null`. <br /> |

| Throws ||
|---|---|
| `https://developer.android.com/reference/java/lang/RuntimeException` | if there are binder communications errors |

### lockDevice

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

```
public void lockDevice (Executor executor, 
                OutcomeReceiver<Void, Exception> callback)
```

Locks the device.

Exceptions that can be returned through the ParcelableException on the callback's `onError` method:

- `https://developer.android.com/reference/java/lang/SecurityException` if the caller is missing the `https://developer.android.com/` permission.
- `https://developer.android.com/reference/java/lang/IllegalStateException` if the device has already been cleared or if policies could not be enforced for the lock state.
- `https://developer.android.com/reference/java/util/concurrent/TimeoutException` if the response from the underlying binder call is not received within the specified duration (10 seconds).

.   
Requires `https://developer.android.com/reference/android/Manifest.permission#MANAGE_DEVICE_LOCK_STATE`

<br />

<br />

| Parameters ||
|---|---|
| `executor` | `Executor`: the `https://developer.android.com/reference/java/util/concurrent/Executor` on which to invoke the callback. This value cannot be `null`. Callback and listener events are dispatched through this `https://developer.android.com/reference/java/util/concurrent/Executor`, providing an easy way to control which thread is used. To dispatch events through the main thread of your application, you can use `https://developer.android.com/reference/android/content/Context#getMainExecutor()`. Otherwise, provide an `https://developer.android.com/reference/java/util/concurrent/Executor` that dispatches to an appropriate thread. <br /> |
| `callback` | `OutcomeReceiver`: this returns either success or an exception. This value cannot be `null`. <br /> |

| Throws ||
|---|---|
| `https://developer.android.com/reference/java/lang/RuntimeException` | if there are binder communications errors |

### notifyKioskSetupFinished

Added in [version 36.1](https://developer.android.com/topic/libraries/support-library/revisions)

```
public void notifyKioskSetupFinished (Executor executor, 
                OutcomeReceiver<Void, Exception> callback)
```

Notifies DLC that kiosk set-up has finished and we no longer need to lock to the set-up activity. This will close the set-up activity as specified through a callback and then respect the current device lock state. If the device has never been locked or unlocked by the kiosk, it will unlock the device. Invoking `https://developer.android.com/reference/android/devicelock/DeviceLockManager#lockDevice(java.util.concurrent.Executor,%20android.os.OutcomeReceiver<java.lang.Void,java.lang.Exception>)` or `https://developer.android.com/reference/android/devicelock/DeviceLockManager#unlockDevice(java.util.concurrent.Executor,%20android.os.OutcomeReceiver<java.lang.Void,java.lang.Exception>)` will also result in the device provision state moving from kiosk_provisioned to provision_success.

Exceptions that can be returned through the ParcelableException on the callback's `onError` method:

- `https://developer.android.com/reference/java/lang/SecurityException` if the caller is missing the `https://developer.android.com/` permission.
- `https://developer.android.com/reference/java/lang/IllegalStateException` if the device has already been cleared or if policies could not be enforced for the lock or unlock state.
- `https://developer.android.com/reference/java/util/concurrent/TimeoutException` if the response from the underlying binder call is not received within the specified duration (10 seconds).

.   
Requires `https://developer.android.com/reference/android/Manifest.permission#MANAGE_DEVICE_LOCK_STATE`

<br />

<br />

| Parameters ||
|---|---|
| `executor` | `Executor`: the `https://developer.android.com/reference/java/util/concurrent/Executor` on which to invoke the callback. This value cannot be `null`. Callback and listener events are dispatched through this `https://developer.android.com/reference/java/util/concurrent/Executor`, providing an easy way to control which thread is used. To dispatch events through the main thread of your application, you can use `https://developer.android.com/reference/android/content/Context#getMainExecutor()`. Otherwise, provide an `https://developer.android.com/reference/java/util/concurrent/Executor` that dispatches to an appropriate thread. <br /> |
| `callback` | `OutcomeReceiver`: this returns either success or an exception. This value cannot be `null`. <br /> |

| Throws ||
|---|---|
| `https://developer.android.com/reference/java/lang/RuntimeException` | if there are binder communications errors |

### unlockDevice

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

```
public void unlockDevice (Executor executor, 
                OutcomeReceiver<Void, Exception> callback)
```

Unlocks the device.

Exceptions that can be returned through the ParcelableException on the callback's `onError` method:

- `https://developer.android.com/reference/java/lang/SecurityException` if the caller is missing the `https://developer.android.com/` permission.
- `https://developer.android.com/reference/java/lang/IllegalStateException` if the device has already been cleared or if policies could not be enforced for the unlock state.
- `https://developer.android.com/reference/java/util/concurrent/TimeoutException` If the response from the underlying binder call is not received within the specified duration (10 seconds).

.   
Requires `https://developer.android.com/reference/android/Manifest.permission#MANAGE_DEVICE_LOCK_STATE`

<br />

<br />

| Parameters ||
|---|---|
| `executor` | `Executor`: the `https://developer.android.com/reference/java/util/concurrent/Executor` on which to invoke the callback. This value cannot be `null`. Callback and listener events are dispatched through this `https://developer.android.com/reference/java/util/concurrent/Executor`, providing an easy way to control which thread is used. To dispatch events through the main thread of your application, you can use `https://developer.android.com/reference/android/content/Context#getMainExecutor()`. Otherwise, provide an `https://developer.android.com/reference/java/util/concurrent/Executor` that dispatches to an appropriate thread. <br /> |
| `callback` | `OutcomeReceiver`: this returns either success or an exception. This value cannot be `null`. <br /> |

| Throws ||
|---|---|
| `https://developer.android.com/reference/java/lang/RuntimeException` | if there are binder communications errors |