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

前端 未结 8 1303
迷失自我
迷失自我 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:20

    One adb command I'm using is:

    adb shell dumpsys window

    This returns a few system variables that are useful such as mAwake, mShowingLockscreen, mScreenOnEarly, mScreenOnFully.

    To figure out which correspond to a locked/unlocked screen, I used adb shell dumpsys window >

    tl;dr

    The combination that I'm finding to be persistent is:

    Device is locked AND screen is off: mAwake=false AND mShowingLockscreen=true

    Device is locked AND screen is on: mAwake=true AND mShowingLockscreen=true

    Device is unlocked AND screen is on: mAwake=true AND mShowingLockscreen=false

提交回复
热议问题