question

jasonbanks avatar image
jasonbanks asked jasonbanks answered

Lockscreen.lock() failing

We need to trigger device locking at certain points in our application, but the call to the Lockscreen.lock() is failing to lock the screen, and returning result of false. Is there any way to determine why the lock request is failing? We are running fullscreen immersive in customer mode, but didn't think any of that should prevent a lock request.

Code is very straight forward...

Lockscreen lockscreen = new Lockscreen(getBaseContext().getApplicationContext());
lockscreen.lock();
lockscreen
10 |2000

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

tanaybh avatar image
tanaybh answered

Programmatically, there’s no way to get further information on why a lock call might’ve failed. However, there’s also not many reasons for it to fail. If you didn’t see a stack trace in the logs with more detailed info when you made the call, then it most likely failed due to there not being an active employee (and thus the device is already considered locked). You should check whether there’s an active employee before calling lock(), which can be done using EmployeeConnector’s getEmployee() method (with no params); if it returns null, there’s no active employee and thus the device is already considered locked.

10 |2000

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

jasonbanks avatar image
jasonbanks answered

The issue turned out to be a combination of CustomerMode being active, as well as activity running full-screen immersive. Simply disabled CustomerMode and cleared decorview flags. Locking working perfectly now.

10 |2000

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Welcome to the
Clover Developer Community