Is there a way to check if Android device screen is locked via adb?

前端 未结 8 1308
迷失自我
迷失自我 2020-12-10 08:04

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?

8条回答
  •  眼角桃花
    2020-12-10 08:25

    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.

提交回复
热议问题