u can turn it on/off if u do like:
adb shell
@shell: input keyevent 26
@shell: (enter or via hidden command empty line)
@shell: exit
this worked for me on some android versions ;)
(NOTE: this will turn the screen on and off, depends on the actual screen state)
To detect the current state of the screen u can use the following ways:
Android < 5.x.x
adb shell dumpsys input_method
In the output search for mScreenOn=true/false
Android >= 5.x.x
adb shell dumpsys display
In the output search for mScreenState=ON/OFF
In my scripts i use this \s{0,}mScreen(State|On)=(?<STATE>(true|false|on|off))\s{0,}
(Compiled|IgnoreCase|ExplicitCapture) regular expression for both outputs to detect the current state.
EDIT (16.03.2018):
There is also another way to detect the screen state, it works since Android 3.0. The dumpsys window policy
command will give us all we need. - In the output search for mScreenOn(Fully)?=(?<STATE>(true|false))
.
There are also other useful informations like:
mUnrestrictedScreen
(value is like: (0,0) 768x1280
)
mRestrictedScreen
(value is like: (0,0) 768x1184
)
Regards,
k1ll3r8e