home-assistant / core

:house_with_garden: Open source home automation that puts local control and privacy first.
https://www.home-assistant.io
Apache License 2.0
71.16k stars 29.85k forks source link

Android TV 11 not working with Android TV integration #56567

Closed blakadder closed 2 years ago

blakadder commented 2 years ago

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

androidtv documentation androidtv source (message by IssueLinks)

probot-home-assistant[bot] commented 2 years ago

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

Any update on this issue?

hellcry37 commented 2 years ago

also looking for any update on this

TarcisioMenezes commented 2 years ago

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

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

As far as I can tell there's a fix in the works - https://github.com/JeffLIrion/python-androidtv/issues/271 has more info

s-e-t-h commented 2 years ago

Hope this can be fixed, did an update from google break it?

On Tue, 30 Nov 2021 at 11:18, Peter @.***> wrote:

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

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/home-assistant/core/issues/56567#issuecomment-982539991, or unsubscribe https://github.com/notifications/unsubscribe-auth/APD5BYDRADSIJZYI7J5MZATUOSXJNANCNFSM5ETM54NA . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.

-- Kind Regards,

Seth Kazzim CEO Erebor

Website: erebor.co

http://apps.apple.com/gb/app/erebor/id1476194291 https://play.google.com/store/apps/details?id=co.erebor.app

Mobile: +447432457398

LinkedIn: Personal https://www.linkedin.com/in/sethkazzim & Erebor https://www.linkedin.com/company/erebor-ltd/

Registered Address:

Kemp House,

160 City Road,

London,

United Kingdom,

EC1V 2NX

Erebor Ltd is a company registered in England and Wales with company number: 11964616

D-U-N-S Number: 225028911

ReenigneArcher commented 2 years ago

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

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

ReenigneArcher commented 2 years ago

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

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

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

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

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

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

undulattice commented 2 years ago

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

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

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

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

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

@frenck Duly noted, with apologies.

deviant-aut commented 2 years ago

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

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

rdgerken commented 2 years ago

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

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

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

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

Albinoman887 commented 2 years ago

I can fix it. its pretty easy. dumpsys window | windows was changed to dumpsys window | displays so that needs changing and then wrap that in an ifdef that checks if "getprop ro.product.build.version" equals 11 or higher and if so use the new command

tabnul commented 2 years ago

Who is able to contribute to the code? It seems everyone knows how to fix it except the HA contributors :)

Good work on the custom integration, going to try it before it gets officially fixed !

msm8811 commented 2 years ago

Is there another issue tracking a fix for the problem than this one?

JeffLIrion commented 2 years ago

This will be fixed as soon as someone submits a pull request. https://github.com/JeffLIrion/python-androidtv

Albinoman887 commented 2 years ago

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

s-e-t-h commented 2 years ago

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

Cross-posting here for visibility (https://github.com/JeffLIrion/python-androidtv/issues/271#issuecomment-1017192652)

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

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

gazpachoking commented 2 years ago

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

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

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

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

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

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

Hi there. Switch apps is probably not the right term - I meant the launching of apps. For instance, I have a script that starts Spotify which no longer works. When one attempts to “select source” on the media player component, the relevant app does not launch.

On Sun, 06 Feb 2022 at 20:12, manticore1991 @.***> wrote:

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?

— Reply to this email directly, view it on GitHub https://github.com/home-assistant/core/issues/56567#issuecomment-1030884965, or unsubscribe https://github.com/notifications/unsubscribe-auth/AJBDEVLONPW6OYNNLQUICWLUZ22XJANCNFSM5ETM54NA . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.

You are receiving this because you commented.Message ID: @.***>

manticore1991 commented 2 years ago

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

Hukuma1 commented 2 years ago

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

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

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

This pull request would allow users to fix it for themselves by customizing the ADB commands used: https://github.com/home-assistant/core/pull/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 commented 2 years ago

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

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.