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?
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