I know that PowerManager and/or KeyguardManager can help me check if a device screen is locked/unlocked. Is there a way to check this via adb?
This command will output everything relating to power for the device:
adb shell dumpsys power
You can pipe this to a grep to get the values of mHoldingWakeLockSuspendBlocker
and mHoldingDisplaySuspendBlocker
:
adb shell dumpsys power | grep 'mHolding'
If both are false, the display is off.
If mHoldingWakeLockSuspendBlocker
is false, and mHoldingDisplaySuspendBlocker
is true, the display is on, but locked.
If both are true, the display is on.
Since Lollipop PowerManager.isInteractive()
and TrustManager.isDeviceLocked()
are the proper methods to check if the device's screen is on and unlocked.
And their corresponding service call
commands would be:
adb shell service call power 12
and
adb shell service call trust 7
And this is how it can be checked from Python code without having to find Android version specific service call codes for your device - https://gist.github.com/ktnr74/60ac7bcc2cd17b43f2cb
This works only when device has NFC:
# returns one of: mScreenState=OFF|ON_LOCKED|ON_UNLOCKED
adb shell dumpsys nfc | grep 'mScreenState='
OFF - Screen off
ON_LOCKED - Screen displays locked screen
ON_UNLOCKED - device unlocked
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With