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

Android TV 11 not working with Android TV integration #56567

Closed
blakadder opened this issue Sep 23, 2021 · 59 comments · Fixed by #68720
Closed

Android TV 11 not working with Android TV integration #56567

blakadder opened this issue Sep 23, 2021 · 59 comments · Fixed by #68720

Comments

@blakadder
Copy link

The problem

I have a TCL TV with Android TV 11 installed running on latest release HA (2021.9.7) and I the only states HA receives are Off,Idle and Standby with adb response: null in Developer - States tab.

Currently implemented adb commands in the integration cannot parse states or running apps due to changes in reporting from Android TV 11.

What is version of Home Assistant Core has the issue?

2021.9.7

What was the last working version of Home Assistant Core?

No response

What type of installation are you running?

Home Assistant Container

Integration causing the issue

androidtv

Link to integration documentation on our website

https://www.home-assistant.io/integrations/androidtv/

Example YAML snippet

No response

Anything in the logs that might be useful for us?

No response

Additional information

Issue in integration github: JeffLIrion/python-androidtv#271
Community forum discussion: https://community.home-assistant.io/t/new-chromecast-w-android-tv-integration-only-showing-as-off-or-idle/234424/43

@probot-home-assistant
Copy link

androidtv documentation
androidtv source
(message by IssueLinks)

@probot-home-assistant
Copy link

Hey there @JeffLIrion, mind taking a look at this issue as it has been labeled with an integration (androidtv) you are listed as a code owner for? Thanks!
(message by CodeOwnersMention)

@s-e-t-h
Copy link

s-e-t-h commented Oct 15, 2021

Any update on this issue?

@hellcry37

This comment was marked as abuse.

@TarcisioMenezes
Copy link

Any update here?
This integration is really important , specially after the release of Google TV dongle and TV brands like TCL and Sony with Google TV on them.

@tjsansone
Copy link

Same here. (Re: Just seeking an update)

I'm happy to lend a hand - it sounds like the source of the issue is identified (?). What's left to be done?

I can take a look / potentially address; just hoping to avoid sifting through comments and code, since the current details are rather sparse.. Much appreciated.

Cheers

@pmannk
Copy link

pmannk commented Nov 30, 2021

As far as I can tell there's a fix in the works - JeffLIrion/python-androidtv#271 has more info

@s-e-t-h
Copy link

s-e-t-h commented Nov 30, 2021 via email

@ReenigneArcher
Copy link

Android 11 uses random ADB port each time. Below is a section of python script that connects to an Android 11 client over adb. It uses a port scanner to try connecting (the code is not that clean, but maybe it can help someone here solve the issue in HA). Might be a problem for HA as the scan is slow depending on the number of threads you use. If you specify a lot of threads then you eat up ram. My code could certainly be optimized better.

https://github.com/RetroArcher/RetroArcher.bundle/blob/1b2b84678a55894aa1b08ded629679f327bb598f/Contents/Code/retroarcher/retroarcher.py#L441

@karwosts
Copy link
Contributor

FYI ShieldTV is rolling out Android 11 updates today, going to impact a lot more people soon.

@ReenigneArcher
Copy link

FYI ShieldTV is rolling out Android 11 updates today, going to impact a lot more people soon.

I just updated. The port remains as 5555. Props to Nvidia for reverting this!

@fredamn76
Copy link

fredamn76 commented Jan 12, 2022

After updating my Nvidia Shield to Android TV 11 the integration regarding playstate fails.

However the integration can interact with adb on Nvidia Shield with Android TV 11.

@tungmeister
Copy link

Hopefully there will be a fix soon, I was already aware of this issue though so lucky haven't let my shield update.

@deviant-aut
Copy link

deviant-aut commented Jan 12, 2022

just updated my shield tv, wasn't aware of this issue before...
broke my automation

was able to use this fix:
https://github.com/JeffLIrion/python-androidtv/issues/271#issuecomment-1011126402

@undulattice
Copy link

just updated my shield tv, wasn't aware of this issue before... broke my automation

was able to use this fix: https://github.com/JeffLIrion/python-androidtv/issues/271#issuecomment-1011126402

Can confirm that this works. :-)

@fredamn76
Copy link

How do we update the file on Home Assistant? I use Home Assistant OS

@undulattice
Copy link

How do we update the file on Home Assistant? I use Home Assistant OS

You have to SSH into underlying OS, and replace it from there. It's a little hairy if you're not comfortable with command line.

https://developers.home-assistant.io/docs/operating-system/debugging/

@tungmeister
Copy link

@undulattice Before I update to 11 and apply this fix can you confirm that it's pulling all app status information through as it did on the previous build, specifically the media duration and position for apps such as plex, etc?

@undulattice
Copy link

@undulattice Before I update to 11 and apply this fix can you confirm that it's pulling all app status information through as it did on the previous build, specifically the media duration and position for apps such as plex, etc?

I always found the AndroidTV implementation of duration, position, etc. a bit flakey. Always used the cast integration for it, which continues to work perfectly.
I get progress bar while playing media in Plex, and can skip back and forward to whatever position. Works fine. :-)

@tungmeister
Copy link

Yeah, I do use the cast one and the separate plex one but just wanted to confirm everything is as it was on the previous version before upgrading as I have an esphome AVR display that has a progress bar on it I didn't want to lose that functionality.

@frenck
Copy link
Member

frenck commented Jan 13, 2022

How do we update the file on Home Assistant? I use Home Assistant OS

You have to SSH into underlying OS, and replace it from there. It's a little hairy if you're not comfortable with command line.

developers.home-assistant.io/docs/operating-system/debugging

This is a hack and not a supported method. We strongly discourage such practices and I would appreciate it if this was not advised or discussed in official resources/channels. Keep in mind, not everyone knows what they are doing there.

The correct way to handle this is to fix the actual integration or run it as a custom integration (which can be modified at will).

@undulattice
Copy link

@frenck
Duly noted, with apologies.

@deviant-aut
Copy link

As I am not able to contribute to a proper solution in HA, I created this custom_component as temporary solution
https://github.com/deviant-aut/HA-androidtv11

@undulattice
Copy link

Thanks @deviant-aut. Works great so far. :-)

@rdgerken
Copy link

I copied this custom component in, but I'm not seeing it do anything. Should it just work with my existing yaml configuration for my nvidia shields, or do I need to reconfigure them through discovery to make this work? Thanks!

@deviant-aut
Copy link

I copied this custom component in, but I'm not seeing it do anything. Should it just work with my existing yaml configuration for my nvidia shields, or do I need to reconfigure them through discovery to make this work? Thanks!

If you put all files into the correct folder it should just work with yoir existing configuration.
If you are still having problems I suggest to create an issue in the github project auf the custom component.
Here is the place for core components related issues.

@undulattice
Copy link

@rdgerken Leave everything as it is. Rename the custom component directory to androidtv, and restart HA.
Should pick up everything and even creates an entry on the integrations page. 🙂

@TarcisioMenezes
Copy link

TarcisioMenezes commented Jan 16, 2022

Does anybody know if the fix is coming soon to the official AndroidTV integration? It's been a while...

@s-e-t-h
Copy link

s-e-t-h commented Jan 19, 2022

I guess I'll do it ;) I use opemhab for android tv stuff but should be the same basic stuff

We're all cheering you on! :)

Could someone explain what we'd need to learn to help with such issues in the future?
Python?

@JeffLIrion
Copy link
Contributor

Cross-posting here for visibility (JeffLIrion/python-androidtv#271 (comment))

I did a lot of work to spport device-specific commands. Now all that's needed is for someone to submit a pull request.

https://github.com/JeffLIrion/python-androidtv/blob/1577e22f0137007327595340f94d0428c63791cd/androidtv/basetv/basetv.py#L94-L173

@justinbyoung
Copy link

Do we know if @JeffLIrion 's code has been pulled into the 2022.2 release?

@gazpachoking
Copy link

I believe @JeffLIrion's update was just to allow specific commands per device. I don't believe anyone has actually written the code to choose the right commands for all the devices that need to be supported yet.

@timbba80
Copy link

timbba80 commented Feb 3, 2022

This issue has been a known issue for over 4 months now, and while reading this conversation, the fix is already provided by few individuals as a workaround. But still the main repository, used by HA is not updated nor fixed.

What's taking so long time with getting this fixed? I understand and appreciate the fact that people are doing these things for free, but in case the owners, who can fix this, do not have the time/interest, maybe someone else should be promoted as individual having rights to update the repo?

@JeffLIrion
Copy link
Contributor

the fix is already provided by few individuals as a workaround.

The key word is workaround. A pull request with proper unit test coverage that does not break compatibility for pre-Android 11 devices has not been submitted. And anything short of that is not a fix.

maybe someone else should be promoted as individual having rights to update the repo?

There's no need to "promote" someone to be able to update the repo. Literally anyone can submit a pull request.

@timbba80
Copy link

timbba80 commented Feb 3, 2022

the fix is already provided by few individuals as a workaround.

The key word is workaround. A pull request with proper unit test coverage that does not break compatibility for pre-Android 11 devices has not been submitted. And anything short of that is not a fix.

Thanks for the reply!

Any reason why meanwhile two separate versions, one for pre 11 and one for 11 could not be created? I admit, I am no expert on this area which why the question might be really stupid from technical point of view..

The workaround by using custom component setup is not reliable (works for a while, then status going to idle and staying as such) , and the other listed workarounds are neither an option for me (as the folder where the updated file should be copied to does not exist). And the lack of HA not being able to identify if shield is playing, idle, paused etc.. does make all linked automations useless.

I'm thinking of reverting back to 9 with my shield, but if we will have this fixed in next few week's, I'll rather wait. But right now the fact of one of the core integrations not working as should, and unawareness of ETA is leading to people being unaware of what' s going on, if anything + not knowing if they should wait for week/month/half year/year.

@ipodmusicman
Copy link

Hi folks, could this be part of the reason why after the 2022.2.2 upgrade I cannot switch apps on my Nvidia Shield running Experience 9? I was able to launch apps in 2022.12.10. I don't want to log an issue if this is all related to the Android TV 11 advisory which the Shield is currently running.

@manticore1991
Copy link

Hi folks, could this be part of the reason why after the 2022.2.2 upgrade I cannot switch apps on my Nvidia Shield running Experience 9? I was able to launch apps in 2022.12.10. I don't want to log an issue if this is all related to the Android TV 11 advisory which the Shield is currently running.

What do you mean "switch apps"? What exactly are you trying to do?

@ipodmusicman
Copy link

ipodmusicman commented Feb 6, 2022 via email

@manticore1991
Copy link

Ahhh, I see! Could very well be another problem related to Android TV 11.

@Hukuma1
Copy link

Hukuma1 commented Feb 6, 2022

Would be nice if we could at least take the approach of having 2 versions while a proper fix (read: not workaround) is implemented? I upgraded to Android 11 on the Shield strictly by accident; wasn't aware of this issue and unable to roll back. Everything else has been working great on it, minus this integration.

@timbba80
Copy link

timbba80 commented Feb 6, 2022

Would be nice if we could at least take the approach of having 2 versions while a proper fix (read: not workaround) is implemented? I upgraded to Android 11 on the Shield strictly by accident; wasn't aware of this issue and unable to roll back. Everything else has been working great on it, minus this integration.

Fully agree, there's no insight of when a full blown solution (compatible with pre-11 and 11) would be avail. Thus a workaround with two versions would be a decent solution.

@jobhh
Copy link

jobhh commented Feb 6, 2022

There are basically two issues that prevent this integration from being properly fixed on Android 11+ devices connected over Wi-Fi.

  1. Android 10+ has MAC address randomization enabled by default for Wi-Fi connections. If you do not disable this, your Android device will receive a new ip adres every time it connects to the Wi-Fi with a new MAC adres. The only way around this is for the user to manually disable MAC randomization for a given Wi-Fi network. See https://source.android.com/devices/tech/connect/WiFi-mac-randomization and https://developer.android.com/about/versions/10/privacy/changes#randomized-mac-addresses
  2. Android 11+ has ADB port randomization (which I personally don't see the added benefit of). The default ADB port used to be 5555, but it is now randomized each time for wireless debugging. The only way around this is for Home Assistant to scan for open ports at the ip adres of the Android device.

In short: For Wi-Fi connected Android devices there seems to be no solution without port scanning, which is frowned upon from a security perspective, and it would only work if the ip address is known/static, which is only the case when the user disabled MAC randomization for the active Wi-Fi network.

The only reliable fix: Use a wired network

@JeffLIrion
Copy link
Contributor

This pull request would allow users to fix it for themselves by customizing the ADB commands used: #65397

You'd just need to figure out the right ADB commands.

Regarding the "2 versions" suggestion, again, anyone can step up and work on this...

@kylehase
Copy link

kylehase commented Feb 9, 2022

In short: There seems to be no solution without port scanning, which is frowned upon from a security perspective, and it would only work if the ip address is known/static

This is atypical, and substantially more effort, but could a solution be to introduce a client-side app to track and report back IP address and ADB port changes?

@ReenigneArcher
Copy link

Note: If device is wired, the port remains 5555 (at least on Shield).

Also, yea my port scanning method is not the greatest, kind of slow too. Works for my use case, but I already know the ip address. If ip address is unknown, it's a terrible method.

@jobhh
Copy link

jobhh commented Feb 9, 2022

This is atypical, and substantially more effort, but could a solution be to introduce a client-side app to track and report back IP address and ADB port changes?

An Android app can keep track of the IP address, but the user can disable MAC randomization for a given Wi-Fi network and then the IP address won't change anyway, so that's not the main issue.

An Android app can check if ADB over USB is enabled by reading this value, https://developer.android.com/reference/android/provider/Settings.Global#ADB_ENABLED:
Settings.Global.getString(context.contentResolver, "adb_enabled")

It is not documented, but this can also be done for wireless debugging:
Settings.Global.getString(context.contentResolver, "adb_wifi_enabled")

However, then we'd only know whether ADB over Wi-Fi is enabled or not. I don't think there is a readily available programmatical method to determine which port is active. That information is not available in the device properties or the global/system/secure settings and I don't think Google made it available through documented Android APIs. Sooooo, as far as I know there is currently no workaorund other than port scanning to find the ADB port when the Android device is connected via Wi-Fi.

The easiest solution is still to connect the Android device via a wired network :)

@roofuskit
Copy link

roofuskit commented Feb 15, 2022

the fix is already provided by few individuals as a workaround.

The key word is workaround. A pull request with proper unit test coverage that does not break compatibility for pre-Android 11 devices has not been submitted. And anything short of that is not a fix.

maybe someone else should be promoted as individual having rights to update the repo?

There's no need to "promote" someone to be able to update the repo. Literally anyone can submit a pull request.

So all you have to do is select which command set to use via a drop down during setup? A dropdown with "AndroidTV 10 or earlier" and "AndroidTV 11+" sounds like an easy solution.

@Inrego
Copy link

Inrego commented Feb 17, 2022

Couldn't a workaround be an app installed on Android TV, which takes care of the stuff we previously relied on adb for? Reporting state, launching apps etc.

@rytilahti
Copy link
Member

rytilahti commented Feb 18, 2022

Having an app that provides the wanted information on the device could be a more optimal solution (instead of using something that's designed for other purposes) depending on what sort of access a regular app has on the device. This would not be a workaround but another approach to interact with android tv devices.

However, this would require someone to develop and maintain the app. If some of you want to volunteer and work on that approach, it makes sense to first contact the developers of the official companion app to get their opinion if it could be extended to cover at least the common use cases. But all of this is somewhat offtopic for the issue at hand, and should be discussed elsewhere.

(this is just my 0.05e as onlooker, I tried to create a simple media status tracker app on android at some point and found quickly out that tracking the media state isn't as simple as I thought as not all apps were using the mediasession apis back then)

@tabnul
Copy link

tabnul commented Feb 18, 2022

Having an app that provides the wanted information on the device could be a more optimal solution (instead of using something that's designed for other purposes) depending on what sort of access a regular app has on the device. This would not be a workaround but another approach to interact with android tv devices.

However, this would require someone to develop and maintain the app. If some of you want to volunteer and work on that approach, it makes sense to first contact the developers of the official companion app to get their opinion if it could be extended to cover at least the common use cases. But all of this is somewhat offtopic for the issue at hand, and should be discussed elsewhere.

(this is just my 0.05e as onlooker, I tried to create a simple media status tracker app on android at some point and found quickly out that tracking the media state isn't as simple as I thought as not all apps were using the mediasession apis back then)

Something like unified remote, which doesnt have an android server yet; https://www.unifiedremote.com/download/other

@gac9415
Copy link

gac9415 commented Feb 24, 2022

Not sure if this is the right spot to post this, so please forgive me if not. I went through with ANDROIDTV.LEARN_SENDEVENT
to get event commands but when trying to call them I get permission denied in my ADB_response log. I've got Android 11 so my first thought is this might be related? Anybody have any insight?

@gobigdave
Copy link

This is atypical, and substantially more effort, but could a solution be to introduce a client-side app to track and report back IP address and ADB port changes?

An Android app can keep track of the IP address, but the user can disable MAC randomization for a given Wi-Fi network and then the IP address won't change anyway, so that's not the main issue.

An Android app can check if ADB over USB is enabled by reading this value, https://developer.android.com/reference/android/provider/Settings.Global#ADB_ENABLED:

Settings.Global.getString(context.contentResolver, "adb_enabled")

It is not documented, but this can also be done for wireless debugging:

Settings.Global.getString(context.contentResolver, "adb_wifi_enabled")

However, then we'd only know whether ADB over Wi-Fi is enabled or not. I don't think there is a readily available programmatical method to determine which port is active. That information is not available in the device properties or the global/system/secure settings and I don't think Google made it available through documented Android APIs. Sooooo, as far as I know there is currently no workaorund other than port scanning to find the ADB port when the Android device is connected via Wi-Fi.

The easiest solution is still to connect the Android device via a wired network :)

I'm connected to a wired network, and the integration still doesn't work. I can turn it on and off. I can see a preview of what is playing, but status is always idle. I'm guessing there is more to it that wired vs WiFi.

@alexyao2015
Copy link
Contributor

alexyao2015 commented Mar 23, 2022

Android 10+ has MAC address randomization enabled by default for Wi-Fi connections. If you do not disable this, your Android device will receive a new ip adres every time it connects to the Wi-Fi with a new MAC adres.

This is not the case with Android 11 and is only potentially an issue with some Android 12 devices. https://source.android.com/devices/tech/connect/wifi-mac-randomization-behavior#persistent

It seems like the other issue has to do with port scanning for the adb port on wireless (I would presume such a solution would likely not be accepted into HA core). The workaround for this in core would probably have to require using a wired connection or maybe the official companion app could provide home assistant with the adb port (it appears that the port is stored in the property service.adb.tls.port, however that is restricted to root only).

I'm trying to figure out the state of affairs with this issue. I currently see there is a pull request at #65397 which appears to fix some issues with the commands being incorrect. Additionally, I see there is this custom component that was created several months back, which I presume also has fixed some issues? Does anyone here have any concrete understanding of what is broken/what needs to be fixed/what has already been fixed?

@tungmeister
Copy link

tungmeister commented Mar 23, 2022

@alexyao2015 The custom component based on barmazu's fork pretty much 100% fixes the issues with Android 11 on the Nvidia Shield. What's requied I believe are these alterations to be transposed into the device-specific commands - more details here

@github-actions github-actions bot locked and limited conversation to collaborators Apr 26, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.