I need to know in my script whether or not the device's screen is off. Is there any simple command to obtain such information using ADB?
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
dumpsys power | grep mScreenOn
回答2:
On 5.0 it looks like you have to grep the dumpsys power
output for
Display Power: state=OFF
or
Display Power: state=ON
回答3:
On Moto G5+, Moto X4, and Samsung Note 8 I'm seeing the following to work whereas dumpsys power did not (all devices are Marshmallow or later):
adb shell dumpsys deviceidle | grep mScreenOn
yields,
mScreenOn=false
when the screen is 'locked' whether blank or not, whereas,
adb shell dumpsys window | grep mScreenOn
yeilds,
mScreenOnEarly=false mScreenOnFully=false
only if the screen is not 'breathing' info such as the time.
Use dumpsys deviceidle to know if the screen needs to be unlocked to allow user interaction.