1

Tried to check device Screen ON or OFF using mScreenOn=true or mPowerState=SCREEN_BRIGHT_BIT. But the following commands are NOT working in latest android versions. It is returning nothing

Following commands working fine in Android - 4.3 Jelly Bean

  1. using input_method dumpsys

    adb shell dumpsys input_method | grep mScreenOn

  2. using power dumpsys

    adb shell dumpsys power | grep mScreenOn or

    adb shell dumpsys power | grep mPowerState

is there any other way to verify the screen OFF or ON state using adb shell command on latest android versions (Lollipop, Nougat, Oreo, Pie,..etc)

Lava Sangeetham
  • 2,943
  • 4
  • 38
  • 54

3 Answers3

5

Recently I had same problem and found out below solution.

mInteractive value would be "true" in dumpsys input_method for display ON and "false" for display OFF.

Ex usage in shell script:

screen_info=`adb shell dumpsys input_method | grep mInteractive=true`
if [[ $screen_info == *"mInteractive"* ]]
then
    echo "Screen is ON"
     #Do something
else
    echo "Screen is OFF"
    #Do something
fi
Sambath
  • 66
  • 4
3

Android 5.0.1 – Lollipop the behavior changed, they removed logging mScreenOn

Tried many times and found out after comparing the dumpsys input_method files

adb shell dumpsys input_method | grep -i mActive
Lava Sangeetham
  • 2,943
  • 4
  • 38
  • 54
3

has answer for android - Obtain screen status using ADB - Stack Overflow, and copy to here:

  • 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