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?
相关问题
- How can I create this custom Bottom Navigation on
- Bottom Navigation View gets Shrink Down
- How to make that the snackbar action button be sho
- Listening to outgoing sms not working android
- How to create Circular view on android wear?
相关文章
- android开发 怎么把图片放入drawable的文件夹下
- android上如何获取/storage/emulated/下的文件列表
- androidStudio有个箭头不认识
- SQLite不能创建表
- Windows - Android SDK manager not listing any plat
- Animate Recycler View grid when number of columns
- Why is the app closing suddenly without showing an
- Android OverlayItem.setMarker(): Change the marker
If its a rooted phone you can check some fields related to lock in settings.db.
settings.db is located at
/data/data/com.android.providers.settings/databases
Since Lollipop
PowerManager.isInteractive()
andTrustManager.isDeviceLocked()
are the proper methods to check if the device's screen is on and unlocked.And their corresponding
service call
commands would be:and
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:
OFF - Screen off
ON_LOCKED - Screen displays locked screen
ON_UNLOCKED - device unlocked
Bryan's solution didn't work for my device (Samsung Galaxy S3 running version 4.4.2).
For my KitKat GS3:
mScreenOn=true
(works regardless of screen lock state).mUserActivityTimeoutOverrideFromWindowManager=-1
(works regardless of screen ON or OFF).If that doesn't work for you, I'd recommend you try the following:
adb shell dumpsys power > dumpsys.power.screen_off.locked.txt
adb shell dumpsys power > dumpsys.power.screen_on.locked.txt
adb shell dumpsys power > dumpsys.power.screen_on.unlocked.txt
adb shell dumpsys power > dumpsys.power.screen_off.unlocked.txt
.txt
files.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 > <textFileNameOfYourChoice>
tl;dr
The combination that I'm finding to be persistent is:
Device is locked AND screen is off:
mAwake=false
ANDmShowingLockscreen=true
Device is locked AND screen is on:
mAwake=true
ANDmShowingLockscreen=true
Device is unlocked AND screen is on:
mAwake=true
ANDmShowingLockscreen=false
This command will output everything relating to power for the device:
You can pipe this to a grep to get the values of
mHoldingWakeLockSuspendBlocker
andmHoldingDisplaySuspendBlocker
:If both are false, the display is off.
If
mHoldingWakeLockSuspendBlocker
is false, andmHoldingDisplaySuspendBlocker
is true, the display is on, but locked.If both are true, the display is on.