It appears that nVidia Shield Android TV comes with Android 5.1.1 and a Marshmallow update is available since December only. I'm assuming that Android 5.1.1 is the version installed in your device.
Query system services
Enable adb in wireless mode on device. Follow the official guide or this answer of Izzy for instructions, if needed.
You can find the status of Android - sleep or awake - from the dump of various system services.
Service: Power
adb shell dumpsys power
Search the strings mWakefulness
and/or Display Power: state
. Both of them would give you the status you need.
Example:
adb shell 'dumpsys power | grep -e "mWakefulness=" -e "Display Power"'
gives me
mWakefulness=Asleep
Display Power: state=OFF
Service: Window
adb shell dumpsys window
Search the strings mAwake=true
and/or mScreenOnEarly=true
and/or mScreenOnFully=true
Example:
adb shell 'dumpsys window | grep -e "mAwake=" -e "mScreenOnEarly" -e "mScreenOnFully"'
gives me
mAwake=true
mScreenOnEarly=true mScreenOnFully=true
Service: Display
adb shell dumpsys display
Search the strings mState=OFF
and/or mScreenState=OFF
.
Example:
adb shell 'dumpsys display | grep -e "mState=" -e "mScreenState"'
gives me
mState=OFF
mScreenState=OFF
Use Automation
If none of the system services mentioned in previous method worked for you, setup an automation app, such as Tasker or MacroDroid or Automate.
We would now use automation to write the status of Android into a file, such as Sleeping for sleep mode and Awake when it is awake.
- Profile: Event → Display → Display Off
- Task: (Actions) : File → Write File → select a text file to write into, type Sleeping and uncheck Add Newline
- Profile: Event → Display → Display On
- Task: (Actions) : File → Write File → select a text file to write into, type Awake and uncheck Add Newline
Android sadly doesn't come with echo
or printf
utility, If the device is rooted then you can install busybox and be at peace. If not, download busybox binary, set executable permissions and push it into /data/local/tmp
using adb push
. Another way for a non-rooted device is to keep three files, one for state, one with the text Sleeping and and the last one with the text Awake. Whenever the screen turns off/on, copy the second/third file into first one.
MacriDroid also requires a plugin, such as Secure Settings to execute commands.
For a non-rooted Android, echo
should be replaced with ./data/local/tmp/busybox echo
. Otherwise, do a copy operation using the command cp SOURCE DESTINATION
.
Your flow should more or less look like this image
(Click image to enlarge)
Your need to create two flows, one for sleep and other for awake. The second block in the flow is named Broadcast receive and can be found under Apps. The third block is named File write text and can be found under File & Storage.
You can now check the content of that file using adb in wireless mode or using SSH (requires an SSH server on Android; run the server on all interfaces and do not bind it to a single interface.)
There is another possibility, such as making your automation app upload the file to a local or remote server so that you can query that server instead of Android to know status.