DevicePolicyManager.LockNow Method

Definition

Overloads

LockNow()

Make the device lock immediately, as if the lock screen timeout has expired at the point of this call.

LockNow(DevicePolicyManagerFlags)

Make the device lock immediately, as if the lock screen timeout has expired at the point of this call.

LockNow()

Make the device lock immediately, as if the lock screen timeout has expired at the point of this call.

[Android.Runtime.Register("lockNow", "()V", "GetLockNowHandler")]
[Android.Runtime.RequiresPermission("android.permission.MANAGE_DEVICE_POLICY_LOCK")]
public virtual void LockNow ();
[<Android.Runtime.Register("lockNow", "()V", "GetLockNowHandler")>]
[<Android.Runtime.RequiresPermission("android.permission.MANAGE_DEVICE_POLICY_LOCK")>]
abstract member LockNow : unit -> unit
override this.LockNow : unit -> unit
Attributes

Remarks

Make the device lock immediately, as if the lock screen timeout has expired at the point of this call.

This method secures the device in response to an urgent situation, such as a lost or stolen device. After this method is called, the device must be unlocked using strong authentication (PIN, pattern, or password). This API is intended for use only by device admins.

From version android.os.Build.VERSION_CODES#R onwards, the caller must either have the LOCK_DEVICE permission or the device must have the device admin feature; if neither is true, then the method will return without completing any action. Before version android.os.Build.VERSION_CODES#R, the device needed the device admin feature, regardless of the caller's permissions.

The calling device admin must have requested DeviceAdminInfo#USES_POLICY_FORCE_LOCK to be able to call this method; if it has not, a security exception will be thrown.

If there's no lock type set, this method forces the device to go to sleep but doesn't lock the device. Device admins who find the device in this state can lock an otherwise-insecure device by first calling #resetPassword to set the password and then lock the device.

This method can be called on the DevicePolicyManager instance returned by #getParentProfileInstance(ComponentName) in order to lock the parent profile.

NOTE: on android.content.pm.PackageManager#FEATURE_AUTOMOTIVE automotive builds, this method doesn't turn off the screen as it would be a driving safety distraction.

Equivalent to calling #lockNow(int) with no flags.

Java documentation for android.app.admin.DevicePolicyManager.lockNow().

Portions of this page are modifications based on work created and shared by the Android Open Source Project and used according to terms described in the Creative Commons 2.5 Attribution License.

Applies to

LockNow(DevicePolicyManagerFlags)

Make the device lock immediately, as if the lock screen timeout has expired at the point of this call.

[Android.Runtime.Register("lockNow", "(I)V", "GetLockNow_IHandler", ApiSince=26)]
[Android.Runtime.RequiresPermission("android.permission.MANAGE_DEVICE_POLICY_LOCK")]
public virtual void LockNow (Android.App.Admin.DevicePolicyManagerFlags flags);
[<Android.Runtime.Register("lockNow", "(I)V", "GetLockNow_IHandler", ApiSince=26)>]
[<Android.Runtime.RequiresPermission("android.permission.MANAGE_DEVICE_POLICY_LOCK")>]
abstract member LockNow : Android.App.Admin.DevicePolicyManagerFlags -> unit
override this.LockNow : Android.App.Admin.DevicePolicyManagerFlags -> unit

Parameters

flags
DevicePolicyManagerFlags

May be 0 or #FLAG_EVICT_CREDENTIAL_ENCRYPTION_KEY.

Attributes

Remarks

Make the device lock immediately, as if the lock screen timeout has expired at the point of this call.

This method secures the device in response to an urgent situation, such as a lost or stolen device. After this method is called, the device must be unlocked using strong authentication (PIN, pattern, or password). This API is for use only by device admins and holders of the android.Manifest.permission#MANAGE_DEVICE_POLICY_LOCK permission.

From version android.os.Build.VERSION_CODES#R onwards, the caller must either have the LOCK_DEVICE permission or the device must have the device admin feature; if neither is true, then the method will return without completing any action. Before version android.os.Build.VERSION_CODES#R, the device needed the device admin feature, regardless of the caller's permissions.

A calling device admin must have requested DeviceAdminInfo#USES_POLICY_FORCE_LOCK to be able to call this method; if it has not, a security exception will be thrown.

If there's no lock type set, this method forces the device to go to sleep but doesn't lock the device. Device admins who find the device in this state can lock an otherwise-insecure device by first calling #resetPassword to set the password and then lock the device.

This method can be called on the DevicePolicyManager instance returned by #getParentProfileInstance(ComponentName) in order to lock the parent profile as well as the managed profile.

NOTE: In order to lock the parent profile and evict the encryption key of the managed profile, #lockNow() must be called twice: First, #lockNow() should be called on the DevicePolicyManager instance returned by #getParentProfileInstance(ComponentName), then #lockNow(int) should be called on the DevicePolicyManager instance associated with the managed profile, with the #FLAG_EVICT_CREDENTIAL_ENCRYPTION_KEY flag. Calling the method twice in this order ensures that all users are locked and does not stop the device admin on the managed profile from issuing a second call to lock its own profile.

NOTE: on android.content.pm.PackageManager#FEATURE_AUTOMOTIVE automotive builds, this method doesn't turn off the screen as it would be a driving safety distraction.

Java documentation for android.app.admin.DevicePolicyManager.lockNow(int).

Portions of this page are modifications based on work created and shared by the Android Open Source Project and used according to terms described in the Creative Commons 2.5 Attribution License.

Applies to