Home Assistant Community Add-on: ADB - Android Debug Bridge

Thanks! I use the mini media player as well. And indeed when opening the more info panel I can turn off the Shield. That made me realize that the mini media player does a toggle service call by default, which apparently doesn’t work for the Shield TV.

I have now added toggle_power: false in the mini media player settings and then both turning on and off work fine :smile:

Help, I’m a newbie to Hass.io

Saldy I can’t get the Android TV Component to work.

Here’s what I get in my Hass log.

Tue Feb 12 2019 20:56:27 GMT+1100 (Australian Eastern Daylight Time)
Error while setting up platform androidtv
Traceback (most recent call last):
File “/usr/local/lib/python3.6/site-packages/homeassistant/helpers/entity_platform.py”, line 128, in _async_setup_platform
SLOW_SETUP_MAX_WAIT, loop=hass.loop)
File “/usr/local/lib/python3.6/asyncio/tasks.py”, line 358, in wait_for
return fut.result()
File “/usr/local/lib/python3.6/concurrent/futures/thread.py”, line 56, in run
result = self.fn(*self.args, **self.kwargs)
File “/config/custom_components/media_player/androidtv.py”, line 191, in setup_platform
adb_server_port=config[CONF_ADB_SERVER_PORT])
File “/config/deps/lib/python3.6/site-packages/androidtv/init.py”, line 230, in init
self.properties = self.device_info()
File “/config/deps/lib/python3.6/site-packages/androidtv/init.py”, line 325, in device_info
properties = self._adb_shell(‘getprop’)
File “/config/deps/lib/python3.6/site-packages/androidtv/init.py”, line 479, in _adb_shell_pure_python_adb
return self._adb_device.shell(cmd)
File “/config/deps/lib/python3.6/site-packages/adb_messenger/command/transport/init.py”, line 20, in shell
conn = self.create_connection(timeout=timeout)
File “/config/deps/lib/python3.6/site-packages/adb_messenger/device.py”, line 45, in create_connection
self.transport(conn)
File “/config/deps/lib/python3.6/site-packages/adb_messenger/command/transport/init.py”, line 15, in transport
connection.send(cmd)
File “/config/deps/lib/python3.6/site-packages/adb_messenger/connection.py”, line 77, in send
return self._check_status()
File “/config/deps/lib/python3.6/site-packages/adb_messenger/connection.py”, line 83, in _check_status
raise RuntimeError(“ERROR: {} {}”.format(repr(recv), error))
RuntimeError: ERROR: ‘FAIL’ 00a7device unauthorized.
This adb server’s $ADB_VENDOR_KEYS is not set
Try ‘adb kill-server’ if that seems wrong.
Otherwise check for a confirmation dialog on your device.

i had the same error when settings it up for my shield

this error indicates you have not manually accepted/authorised the connection. when you start up the add-on it will try to connect to your shield with the ip address you input into the add-ons config settings. You then have to accept the prompt that will appear on the shield (save the authorisation with the checkbox too) to authorise the connection.

If the promt dont come up on your Shield, you might not have activated “developer mode” on your Shield, and then activated “network adb”.
This steps is a must.

Thanks mcfrojd and simbesh.

No prompt on Shield and developer mode with Network Adb on.
I’ll restart it and go through the steps again.

C

Sweet! I will do that too then.

Worked it out, I didn’t create the directory for the keys to be stored in.
Instructions are a little miss-leading. I suggest that a line is added in if that’s the case because ATM it refers to that specific instruction as optional.

How are you guys getting the proper intenets for your specific devices? I have a bravia tv and some of the commands listed in this thread work on it, some dont. Specifically, the plex command listed in the thread doesn’t work. How would I go about finding the commands for my device?

Hi guys,

I managed to open Kodi on my NVidia Shield TV by using the

-n org.xbmc.kodi/.Splash

intent. The odd thing is that when I return to the Home screen, I get a message saying “-n Kodi Unknown” that I cannot get rid of. Only closing the Kodi app removes also the message…

Opening other apps (e. g. Youtube) does not cause this message, it’s only Kodi. Has anybody else also encountered this message?

Yes, the same here. :frowning:

I’m having issues with the Plex app not always opening. Sometimes it works, but sometimes it gets into a state where it refuses to start via the intent until I open it via the menus on the Shield itself.

This is the intent I’m currently using that seems to work more reliably:

intent: dummy: -n com.plexapp.android/com.plexapp.plex.activities.SplashActivity

The reason is that the -n package/activity syntax doesn’t get parsed quite like I thought it did originally. Looking at the logcat output, it appears the -n is getting stuck into the data_uri:

ActivityManager: START u0 {act=android.intent.action.VIEW dat=-n flg=0x10000000 cmp=com.plexapp.android/com.plexapp.plex.activities.SplashActivity}

Plex actually tries to use that and will fail for certain things. For whatever reason, anything containing a : seems to work. However, plex: is special and will cause it to attempt to load content, which will present an error message if it can’t find it. I was able to get it to launch shows and movies directly using:

plex://<server_id>/movie//library/metadata/<movie_id>

You can get the server_id and movie_id by viewing the item in the plex web app and looking at the URL. The path for shows is a tiny bit different, but you can figure it out from the same URL.

Replacing everything in the URL with hyphens also seems to work to launch the app:

plex://-/-//-

Really though, I think this would be more useful if we could just write the entire ADB command or shell command or at least am start command from scratch. Because I think what is really needed here is

am start -a android.intent.action.MAIN -c android.intent.category.LEANBACK_LAUNCHER -n com.plexapp.android/com.plexapp.plex.activities.SplashActivity

That matches the intent that gets used when launching the app from launcher and should work more reliably for starting any app.

At the very least, removing the -d from the am start command should help because trying to pass a data_uri that the app can’t handle seems to be causing issues and even passing a blank data_uri doesn’t fix it.

Edit: And finally, here is my hack around the issue:

intent: ; am start -a android.intent.action.MAIN -c android.intent.category.LEANBACK_LAUNCHER -n com.plexapp.android/com.plexapp.plex.activities.SplashActivity

The semicolon will simply end the first am start command (which will fail because it’s missing data) and then run the second command. That will let you run any arbitrary ADB shell command. I made some helper scripts to do all of this:

script:
  'androidtv_shell':
    alias: Android TV Shell
    sequence:
    - service: media_player.androidtv_intent
      data_template:
        entity_id: "{{ entity_id }}"
        intent: "; {{ command }}"
  'androidtv_app':
    alias: Android TV App
    sequence:
    - service: script.androidtv_shell
      data_template:
        entity_id: "{{ entity_id }}"
        command: "am start -a android.intent.action.MAIN -c android.intent.category.LEANBACK_LAUNCHER -n {{component}}"
  'plex':
    alias: Plex
    sequence:
    - service: script.androidtv_app
      data:
        entity_id: media_player.shield_tv
        component: com.plexapp.android/com.plexapp.plex.activities.SplashActivity
1 Like

You could register a new service, such as media_player.androidtv_adb_cmd. You could use the media_player.firetv_adb_cmd in my Fire TV custom component as a starting point. It checks if the command cmd is in a dictionary called KEYS and, if so, sends the key command adb shell input keyevent <KEYS[cmd]>. If not, it sends the command adb shell <cmd>. The main lines of interest in the code start here and here.

I actually tried that initially but I got an error that the AndroidTV object has no method adb_shell. I’m not sure why because I can see where it gets set and it’s obviously being used by the other services. I didn’t look into it too much though.

Edit: Figured it out. It was renamed in 0.0.6. For 0.0.5, it’s _adb_shell. I went ahead and updated to the custom component based on 0.0.7 and implemented it there. Works great. Thanks!

PR for anyone who wants it and my updated scripts:

script:
  'androidtv_app':
    alias: Android TV App
    sequence:
    - service: media_player.androidtv_command
      data_template:
        entity_id: "{{ entity_id }}"
        command: "am start -a android.intent.action.MAIN -c android.intent.category.LEANBACK_LAUNCHER -n {{component}}"
  'plex':
    alias: Plex
    sequence:
    - service: script.androidtv_app
      data:
        entity_id: media_player.shield_tv
        component: com.plexapp.android/com.plexapp.plex.activities.SplashActivity

I dont use Hass.io but i’m interest to understand how you have been able to launch a specific movie in Plex from the ADB intent.
Could you elaborate ?

Edit:
I figure it out by myself :

{"entity_id": "media_player.shield", "intent": "plex://<server_id>/movie//library/metadata/<movie_id>" }

1 Like

I have now my code on github for my lovelace “multi remote”
Where the “Shield” part uses this wounderful addon.

Anyone else who cannot get KEYCODE_ENTER to work?

Yes, mine does not work either.

Working fine here. Here’s an example that works for me:

{"entity_id" :"media_player.nvidia_shield", "key": "KEYCODE_ENTER"}

Make sure you aren’t using KEYCODE_DPAD_ENTER since the enter key drops the DPAD part.

1 Like