android shell检查是否锁屏_有没有办法检查Android设备屏幕是否通过adb锁定?

bd96500e110b49cbb3cd949968f18be7.png

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.


版权声明:本文为weixin_32758097原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。