10

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?

tomrozb
  • 25,773
  • 31
  • 101
  • 122

5 Answers5

14

dumpsys power | grep mScreenOn

Alex P.
  • 30,437
  • 17
  • 118
  • 169
  • 1
    Is this specific to some range of devices or Android specific? It works, but better is to grep for mScreenOn= (mScreenOn returns more than one entry in my case). – tomrozb Oct 26 '13 at 21:49
  • 1
    This command works on 4.2+ devices, use `dumpsys input_method | grep mScreenOn` for devices with a lower version. For more info see my answer to this post: http://stackoverflow.com/a/21419347/1345115 – Carlo B. Jan 29 '14 at 00:05
  • 1
    Just a note, dumpsys is a shell command, not an adb command. The cut and paste answer would be adb shell dumpsys power | grep mScreenOn – Bobbi Bennett Nov 14 '15 at 14:09
  • Doesn't work with me (Android 6). This only shows if the graphical data is on or off. If I connect with adb to the phone and turn the screen off, this still shows as the screen being on. – brunoais Jul 08 '20 at 19:55
12

On 5.0 it looks like you have to grep the dumpsys power output for

Display Power: state=OFF

or

Display Power: state=ON
aschmied
  • 908
  • 2
  • 10
  • 26
2

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.

2

This worked for me:

adb shell dumpsys display | grep mScreenState

Output:

mScreenState=OFF
Bryndox
  • 21
  • 2
1
  • My Phone: XiaoMi 9
    • Android: 10

use adb to check screen status ON/OFF ?

method 1: use mHoldingDisplaySuspendBlocker

  • Command: adb shell dumpsys power | grep mHoldingDisplaySuspendBlocker
  • Output:
    • mHoldingDisplaySuspendBlocker=false -> Screen OFF
    • mHoldingDisplaySuspendBlocker=true -> Screen ON

method 2: use mWakefulness

  • Command: adb shell dumpsys power | grep mWakefulness=
  • Output:
    • mWakefulness=Dozing -> Screen OFF
    • mWakefulness=Awake -> Screen ON

method 3: use nfc (if android has NFC module)

  • Command: adb shell dumpsys nfc | grep mScreenState=
  • Output:
    • mScreenState=OFF_LOCKED -> Screen OFF (and Locked)
    • mScreenState=ON_XXX -> Screen ON
      • mScreenState=ON_LOCKED -> Screen ON (and Locked)
      • mScreenState=ON_UNLOCKED -> Screen ON (and Unlocked)

method 4: use service call

  • Command: adb shell service call power 12
  • Output:
    • Result: Parcel(00000000 00000000 '........') -> 0 means Screen OFF
    • Result: Parcel(00000000 00000001 '........') -> 1 means Screen ON
crifan
  • 12,947
  • 1
  • 71
  • 56