Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Different versions of Android TV / Fire TV - help with adb commands for this project #295

Open
glassbase opened this issue Feb 1, 2022 · 14 comments

Comments

@glassbase
Copy link
Contributor

I am not super familiar with adb commands needed for this project other than what I have quickly read in the current issue of Android TV 9 (vs 10) vs 11.

Would it beneficial for this project for everyone with different devices and OSes to run certain commands to help build out the required commands required to parse out data?

What would those commands be?

Just myself - I have Mi Box 3 with OS 8, Mi Box 3 with OS 9. Shield 2019 with OS 9, Onn with OS 10, random Fire TV devices with OS 5, 6, 7.

Thanks @JeffLIrion for all the hard work on this over the years, been using since it was a beta component.

@glassbase
Copy link
Contributor Author

Please change title of issue as necessary

@JeffLIrion
Copy link
Owner

Would it beneficial for this project for everyone with different devices and OSes to run certain commands to help build out the required commands required to parse out data?

What I really need is for people to submit pull requests. Maybe it will be more clear after someone submits the first one that adds device-specific commands. Although the way that Google-specific commands are handled should serve as a good template.

You can keep this issue open, but what's needed is for people to contribute fixes rather than post information and rely on me to make the code changes.

@StephenGoodall
Copy link
Contributor

Looking at the recent changes, CUSTOM_CURRENT_APP will be an option soon, amongst others, and I'm just guessing but i think for the Nvidia Shield, on Android 11, that value would need to be something like this:
CURRENT_APP=$(grep -m1 -E 'mActivityRecord=|mCurrentFocus' <<< $(dumpsys window windows) | grep -o {.*}) && { CURRENT_APP=${CURRENT_APP%%/*}; CURRENT_APP=${CURRENT_APP##* * }; CURRENT_APP=${CURRENT_APP%\\}; } && echo $CURRENT_APP

(I just stuck all the relevant bits together from the constants file @barmazu posted recently:
https://github.com/barmazu/python-androidtv/blob/10a2606d0d794f02fe74b0aa2f93c372519a58af/androidtv/constants.py )

I quickly tested it from the services tab of homeassistant and it returned this when it was asleep:
com.android.systemui
And this when I had Netflix open:
com.netflix.ninja

Is there an official place we could start recording these custom commands in a table (PR's could then be raised to add new entries) to save people having to figure it out from scratch each time? Would the README file be a bad place for that? Or would it need to be done within the Sphinx docs? I'm not sure what the proper way of recording things like that would be.

Device Android Version Custom Command Name Custom Command
NVIDIA Shield 11 CUSTOM_CURRENT_APP CURRENT_APP=$(grep -m1 -E 'mActivityRecord=|mCurrentFocus' <<< $(dumpsys window windows) | grep -o {.*}) &amp;&amp; { CURRENT_APP=${CURRENT_APP%%/*}; CURRENT_APP=${CURRENT_APP##* * }; CURRENT_APP=${CURRENT_APP%\}; } && echo $CURRENT_APP

Markdown is definitely not a good way to do it 😁

@JeffLIrion
Copy link
Owner

@StephenGoodall this issue is a good place, at least for now.

You commented elsewhere about using the output of getprop ro.build.version.release to determine the correct command for a device. That output is already stored as self.device_properties["sw_version"]. But yes, that is how device-specific commands should be implemented.

@StephenGoodall
Copy link
Contributor

@StephenGoodall this issue is a good place, at least for now.

You commented elsewhere about using the output of getprop ro.build.version.release to determine the correct command for a device. That output is already stored as self.device_properties["sw_version"]. But yes, that is how device-specific commands should be implemented.

Yeah, I thought of using that and then when I started looking into the code I found that you'd already done it that way 😁
I started editing a branch and having 3 versions of some constants but it got a bit trickier once the constants started to refer to other existing ones, eg. The launch_app constant would need to refer to one of 3 current_app values. I may have another look today and see if I can think of a tidy way to handle it.

Otherwise, maybe extending the customizable commands list would be another option if more commands start to need different versions

@StephenGoodall
Copy link
Contributor

StephenGoodall commented Feb 10, 2022

I didn't get much time today but threw a bit of a PR together to show what kind of thing i was looking at yesterday:

#303

It keeps failing the checks, so I've been changing it in parts but it's failing on the "black" step now I think. The line in the makefile refers to androidtv but I'll have to have another look tomorrow (at a guess, some lines are over 120 chars?)

@deviant-aut
Copy link
Contributor

Tried this for Nvidia Shield TV ANdroid 11.

CUSTOM_CURRENT_APP:
CURRENT_APP=$(dumpsys window windows | grep 'Window #1') && CURRENT_APP=${CURRENT_APP%%/*} && CURRENT_APP=${CURRENT_APP##* } && echo $CURRENT_APP

CUSTOM_AUDIO_STATE:
CURRENT_AUDIO_STATE=$(dumpsys audio | sed -r -n '/[0-9]{2}-[0-9]{2}.*player piid:.*state:.*$/h; ${x;p;}') && echo $CURRENT_AUDIO_STATE | grep paused >/dev/null 2>&1 && echo -e '1\c' || { echo $CURRENT_AUDIO_STATE | grep started >/dev/null 2>&1 && echo '2\c' || echo '0\c' ; }

@deviant-aut
Copy link
Contributor

Need some solution for CMD_DEFINE_CURRENT_APP_VARIABLE. It is referenced to often inside constants file.

@glassbase
Copy link
Contributor Author

glassbase commented May 18, 2022

related issues:
ollo69/ha-androidtv-custom#1
deviant-aut/HA-androidtv11#9

we need a custom command for current_app as well

@JeffLIrion
Copy link
Owner

related issues: ollo69/ha-androidtv-custom#1 deviant-aut/HA-androidtv11#9

we need a custom command for current_app as well

This is it:

CUSTOM_CURRENT_APP_MEDIA_SESSION_STATE,

@JeffLIrion
Copy link
Owner

When posting device-specific commands, please include the output of this command:

r"getprop ro.product.manufacturer && getprop ro.product.model && getprop ro.serialno && getprop ro.build.version.release",

@glassbase
Copy link
Contributor Author

glassbase commented May 21, 2022

OK, i will try it. They way I read it, thought that meant get the current app's media_session_state... I did not think it was a combination result of both.

Since I do not have a current working device, what should the result look like?

edit - got it figured out after lots of trial and error
here is my custom_current_app_media_session_state:
CURRENT_APP=$(dumpsys activity a . | grep -E 'mResumedActivity' | cut -d ' ' -f 8 | cut -d '/' -f 1) && echo $CURRENT_APP && dumpsys media_session | grep -A 100 'Sessions Stack' | grep -A 100 $CURRENT_APP | grep -m 1 'state=PlaybackState {'

@JeffLIrion
Copy link
Owner

For the record, the output should look like:

MEDIA_SESSION_STATE_OUTPUT = "com.amazon.tv.launcher\nstate=PlaybackState {state=2, position=0, buffered position=0, speed=0.0, updated=65749, actions=240640, custom actions=[], active item id=-1, error=null}"

@glassbase
Copy link
Contributor Author

glassbase commented May 21, 2022

Thanks... for some reason I thought it needed the text && as a part of the later parsing (because I am not that versed in programming), it worked with that text inbetween, but removed that echo now.

CMD_CURRENT_APP_MEDIA_SESSION_STATE = CMD_CURRENT_APP + " && " + CMD_MEDIA_SESSION_STATE

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants