14

Below is excerpted from http://developer.android.com/reference/android/app/KeyguardManager.html

public boolean isDeviceLocked ()

Returns whether the device is currently locked and requires a PIN, pattern or password to unlock. Returns true if unlocking the device currently requires a PIN, pattern or password.

public boolean isKeyguardSecure ()

Return whether the keyguard requires a password to unlock. Returns true if keyguard is secure.

What's the difference between isDeviceLocked and isKeyguardSecure?

xmllmx
  • 39,765
  • 26
  • 162
  • 323
  • 3
    Well, if you have a password, both methods return `true`. If you have a PIN or pattern, just `isDeviceLocked` returns `true` and if you have no lock, both return `false`. I guess `isKeyguardSecure` has its function because PIN and pattern can be bypassed more easily. – ByteHamster May 04 '15 at 15:17
  • 1
    Why compare `isDeviceLocked()` with `isKeyguardSecure()`? The pendant to `isDeviceLocked()` is `isKeyguardLocked()`, the *keyguard api being older and also taking SIM Pin into account. – Patrick Oct 04 '17 at 16:16

1 Answers1

18

public boolean isDeviceLocked ()

This method takes the current UI state of the Lockscreen into account.

So if a secure Screen Lock has been setup, it will contrary to isKeyguardSecure() return false if:

  • The user has unlocked the Lockscreen and is using the device
  • The Smart Lock feature (Settings -> Security -> Smart Lock) allows the device to be unlocked without further authentication

public boolean isKeyguardSecure ()

This method does NOT take the current UI state of the Lockscreen into account.

So if a secure Screen Lock has been setup, it will always return true, regardless of if the Lockscreen has been unlocked by the user or if Smart Lock allows unlock without further authentication.

I was not able to reproduce the behavior reported by ByteHamster btw.

Martin Nordholts
  • 10,338
  • 2
  • 39
  • 43
  • 7
    Would be more interesting to compare KeyguardManager.isDeviceLocked() with KeyguardManager.isKeyguardLocked(). I haven't found answer yet – demaksee Jul 30 '18 at 15:57