DeviceLockManager
public
final
class
DeviceLockManager
extends Object
java.lang.Object | |
↳ | 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 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 | |
---|---|
int |
DEVICE_LOCK_ROLE_FINANCING
Constant representing a financed device role, returned by |
String |
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
|
clearDeviceRestrictions(Executor executor, OutcomeReceiver<Void, Exception> callback)
Clear device restrictions. |
void
|
getDeviceId(Executor executor, OutcomeReceiver<DeviceId, Exception> callback)
Gets the device id. |
void
|
getKioskApps(Executor executor, OutcomeReceiver<Map<Integer, String>, Exception> callback)
Get the kiosk app roles and packages. |
void
|
isDeviceLocked(Executor executor, OutcomeReceiver<Boolean, Exception> callback)
Checks if the device is locked or not. |
void
|
lockDevice(Executor executor, OutcomeReceiver<Void, Exception> callback)
Locks the device. |
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. |
void
|
unlockDevice(Executor executor, OutcomeReceiver<Void, Exception> callback)
Unlocks the device. |
Inherited methods | |
---|---|
Constants
DEVICE_LOCK_ROLE_FINANCING
public static final int DEVICE_LOCK_ROLE_FINANCING
Constant representing a financed device role, returned by getKioskApps(Executor, OutcomeReceiver)
.
Constant Value: 0 (0x00000000)
EXTRA_DEVICE_LOCK_VERSION
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.
Constant Value: "android.devicelock.extra.DEVICE_LOCK_VERSION"
Public methods
clearDeviceRestrictions
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 lockDevice(Executor, OutcomeReceiver)
) if payments are missed and unlock (using unlockDevice(Executor, OutcomeReceiver)
))
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
(
UserManager.DISALLOW_DEBUGGING_FEATURES
) - Disable installing from unknown sources
(
UserManager.DISALLOW_INSTALL_UNKNOWN_SOURCES
, when configured in the backend) - Disable outgoing calls
(
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 clearDeviceRestrictions(Executor, OutcomeReceiver)
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:
SecurityException
if the caller is missing theERROR(/android.android.Manifest.permission.MANAGE_DEVICE_LOCK_STATE)
permission.IllegalStateException
if the device has already been cleared or if policies could not be enforced for the clear state.TimeoutException
if the response from the underlying binder call is not received within the specified duration (10 seconds).
Requires
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 : this returns either success or an exception.
This value cannot be null . |
Throws | |
---|---|
RuntimeException |
if there are binder communications errors |
getDeviceId
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:
SecurityException
if the caller is missing theERROR(/android.android.Manifest.permission.MANAGE_DEVICE_LOCK_STATE)
permission.IllegalStateException
if no registered Device ID is found.TimeoutException
if the response from the underlying binder call is not received within the specified duration (10 seconds).
Requires
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 : this returns either the DeviceId or an exception.
This value cannot be null . |
Throws | |
---|---|
RuntimeException |
if there are binder communications errors |
getKioskApps
public void getKioskApps (Executor executor, OutcomeReceiver<Map<Integer, String>, Exception> callback)
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 : 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
.DEVICE_LOCK_ROLE_FINANCING . The String represents the package
name of the kiosk app for that role.
This value cannot be null . |
Throws | |
---|---|
RuntimeException |
if there are binder communications errors |
isDeviceLocked
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:
SecurityException
if the caller is missing theERROR(/android.android.Manifest.permission.MANAGE_DEVICE_LOCK_STATE)
permission.IllegalStateException
if called before setting the locked state of the device throughlockDevice(Executor, OutcomeReceiver)
orunlockDevice(Executor, OutcomeReceiver)
.TimeoutException
if the response from the underlying binder call is not received within the specified duration (10 seconds).
Requires
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 : this returns either the lock status or an exception.
This value cannot be null . |
Throws | |
---|---|
RuntimeException |
if there are binder communications errors |
lockDevice
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:
SecurityException
if the caller is missing theERROR(/android.android.Manifest.permission.MANAGE_DEVICE_LOCK_STATE)
permission.IllegalStateException
if the device has already been cleared or if policies could not be enforced for the lock state.TimeoutException
if the response from the underlying binder call is not received within the specified duration (10 seconds).
Requires
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 : this returns either success or an exception.
This value cannot be null . |
Throws | |
---|---|
RuntimeException |
if there are binder communications errors |
notifyKioskSetupFinished
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
lockDevice(Executor, OutcomeReceiver)
or unlockDevice(Executor, OutcomeReceiver)
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:
SecurityException
if the caller is missing theERROR(/android.android.Manifest.permission.MANAGE_DEVICE_LOCK_STATE)
permission.IllegalStateException
if the device has already been cleared or if policies could not be enforced for the lock or unlock state.TimeoutException
if the response from the underlying binder call is not received within the specified duration (10 seconds).
Requires
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 : this returns either success or an exception.
This value cannot be null . |
Throws | |
---|---|
RuntimeException |
if there are binder communications errors |
unlockDevice
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:
SecurityException
if the caller is missing theERROR(/android.android.Manifest.permission.MANAGE_DEVICE_LOCK_STATE)
permission.IllegalStateException
if the device has already been cleared or if policies could not be enforced for the unlock state.TimeoutException
If the response from the underlying binder call is not received within the specified duration (10 seconds).
Requires
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 : this returns either success or an exception.
This value cannot be null . |
Throws | |
---|---|
RuntimeException |
if there are binder communications errors |