Added in API level 34

DeviceLockManager


class DeviceLockManager
kotlin.Any
   ↳ android.devicelock.DeviceLockManager

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 android.content.Context#getSystemService(java.lang.String) with Context#DEVICE_LOCK_SERVICE to create a DeviceLockManager.


Requires the PackageManager#FEATURE_DEVICE_LOCK feature which can be detected using PackageManager.hasSystemFeature(String).

Summary

Constants
static Int

Constant representing a financed device role, returned by getKioskApps.

Public methods
Unit

Get the device id.

Unit

Get the kiosk app roles and packages.

Unit

Check if the device is locked or not.

Unit
lockDevice(executor: Executor, callback: OutcomeReceiver<Void!, Exception!>)

Lock the device.

Unit
unlockDevice(executor: Executor, callback: OutcomeReceiver<Void!, Exception!>)

Unlock the device.

Constants

DEVICE_LOCK_ROLE_FINANCING

Added in API level 34
static val DEVICE_LOCK_ROLE_FINANCING: Int

Constant representing a financed device role, returned by getKioskApps.

Value: 0

Public methods

getDeviceId

Added in API level 34
fun getDeviceId(
    executor: Executor,
    callback: OutcomeReceiver<DeviceId!, Exception!>
): Unit

Get the device id.
Requires android.Manifest.permission#MANAGE_DEVICE_LOCK_STATE

Parameters
executor Executor: the Executor on which to invoke the callback. This value cannot be null. Callback and listener events are dispatched through this Executor, providing an easy way to control which thread is used. To dispatch events through the main thread of your application, you can use Context.getMainExecutor(). Otherwise, provide an Executor that dispatches to an appropriate thread.
callback OutcomeReceiver<DeviceId!, Exception!>: this returns either the DeviceId or an exception. This value cannot be null.

getKioskApps

Added in API level 34
fun getKioskApps(
    executor: Executor,
    callback: OutcomeReceiver<MutableMap<Int!, String!>!, Exception!>
): Unit

Get the kiosk app roles and packages.

Parameters
executor Executor: the Executor on which to invoke the callback. This value cannot be null. Callback and listener events are dispatched through this Executor, providing an easy way to control which thread is used. To dispatch events through the main thread of your application, you can use Context.getMainExecutor(). Otherwise, provide an Executor that dispatches to an appropriate thread.
callback OutcomeReceiver<MutableMap<Int!, String!>!, Exception!>: this returns either a 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 {@value #DEVICE_LOCK_ROLE_FINANCING}. The String represents tha package name of the kiosk app for that role. This value cannot be null.

isDeviceLocked

Added in API level 34
fun isDeviceLocked(
    executor: Executor,
    callback: OutcomeReceiver<Boolean!, Exception!>
): Unit

Check if the device is locked or not.
Requires android.Manifest.permission#MANAGE_DEVICE_LOCK_STATE

Parameters
executor Executor: the Executor on which to invoke the callback. This value cannot be null. Callback and listener events are dispatched through this Executor, providing an easy way to control which thread is used. To dispatch events through the main thread of your application, you can use Context.getMainExecutor(). Otherwise, provide an Executor that dispatches to an appropriate thread.
callback OutcomeReceiver<Boolean!, Exception!>: this returns either the lock status or an exception. This value cannot be null.

lockDevice

Added in API level 34
fun lockDevice(
    executor: Executor,
    callback: OutcomeReceiver<Void!, Exception!>
): Unit

Lock the device.
Requires android.Manifest.permission#MANAGE_DEVICE_LOCK_STATE

Parameters
executor Executor: the Executor on which to invoke the callback. This value cannot be null. Callback and listener events are dispatched through this Executor, providing an easy way to control which thread is used. To dispatch events through the main thread of your application, you can use Context.getMainExecutor(). Otherwise, provide an Executor that dispatches to an appropriate thread.
callback OutcomeReceiver<Void!, Exception!>: this returns either success or an exception. This value cannot be null.

unlockDevice

Added in API level 34
fun unlockDevice(
    executor: Executor,
    callback: OutcomeReceiver<Void!, Exception!>
): Unit

Unlock the device.
Requires android.Manifest.permission#MANAGE_DEVICE_LOCK_STATE

Parameters
executor Executor: the Executor on which to invoke the callback. This value cannot be null. Callback and listener events are dispatched through this Executor, providing an easy way to control which thread is used. To dispatch events through the main thread of your application, you can use Context.getMainExecutor(). Otherwise, provide an Executor that dispatches to an appropriate thread.
callback OutcomeReceiver<Void!, Exception!>: this returns either success or an exception. This value cannot be null.