JeffLIrion / python-androidtv

Communicate with an Android TV or Fire TV device via ADB over a network.
MIT License
168 stars 59 forks source link

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

Open glassbase opened 2 years ago

glassbase commented 2 years ago

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 commented 2 years ago

Please change title of issue as necessary

JeffLIrion commented 2 years ago

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 commented 2 years ago

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 {.*}) && { 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 commented 2 years ago

@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 commented 2 years ago

@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 commented 2 years ago

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:

https://github.com/JeffLIrion/python-androidtv/pull/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 commented 2 years ago

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 commented 2 years ago

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

glassbase commented 2 years ago

related issues: https://github.com/ollo69/ha-androidtv-custom/issues/1 https://github.com/deviant-aut/HA-androidtv11/issues/9

we need a custom command for current_app as well

JeffLIrion commented 2 years ago

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: https://github.com/JeffLIrion/python-androidtv/blob/043bbb5bf72717f40fde7ea3d4bb776293c49005/androidtv/constants.py#L61

JeffLIrion commented 2 years ago

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

https://github.com/JeffLIrion/python-androidtv/blob/043bbb5bf72717f40fde7ea3d4bb776293c49005/tests/test_constants.py#L119

glassbase commented 2 years ago

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 commented 2 years ago

For the record, the output should look like: https://github.com/JeffLIrion/python-androidtv/blob/043bbb5bf72717f40fde7ea3d4bb776293c49005/tests/test_basetv_sync.py#L122

glassbase commented 2 years ago

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. https://github.com/JeffLIrion/python-androidtv/blob/043bbb5bf72717f40fde7ea3d4bb776293c49005/androidtv/constants.py#L162