Nerwyn / android-tv-card

Universal Customizable TV Remote Card, with HA actions, super configurable touchpad, slider, haptics, and keyboard
Apache License 2.0
183 stars 9 forks source link

Slow Seamless Keyboard Input #82

Closed Chewie610 closed 2 months ago

Chewie610 commented 2 months ago

Is your feature request related to a problem? Please describe. The seamless keyboard entry through adb is very laggy compared to the likes of the textbox entry or the Google Home remote. Text entered takes 1-2 seconds to show up, then pauses for another 1-2 seconds to show the next letter.

Describe the solution you'd like Can the scan interval for seamless keyboard be set higher to respond faster?

Describe alternatives you've considered Can we intercept and see if the Google Home app's implementation is using adb to send keyboard inputs? Granted, the textbox entry proves that adb is not the issue for the delay.

Additional context The textbox implementation is able to send text through adb very fast. When using seamless keyboard, all "text" is processed very slow. However, the delete/backspace key seems to be registered very fast.

Nerwyn commented 2 months ago

Seamless ADB keyboard input is slow because the way Home Assistant allows you to send ADB shell commands is slow. Bulk ADB keyboard input feels fast because it's only sending one shell command with all the text rather than one shell command per character. If it was possible for Home Assistant to open and maintain a shell connection to Android TV, then it may speed things up. I should look into this and will leave this card open until I can confirm that Home Assistant doesn't allow us to open a shell and send multiple async commands to it.

I previously asked about sending keyboard commands through the remote API like the Google Home/TV apps do on the community forum , but according to the developer of the Home Assistant remote API integration and it's underlying library tronikos it had not been reversed engineered yet so that's a dead end until it is.

Non-character keys are fast because they're sent through the remote API, which is much faster than adb shell.

Nerwyn commented 2 months ago

Home Assistant's ADB implementation uses adb-shell, which doesn't seem to allow for the opening of a shell session to send multiple commands to so that's a dead end.

They do support using an alternative ADB server but the Home Assistant adb server add-on has been deprecated. I did manage to install adb via the terminal and use that but there was no difference in performance.

I also tried implementing some alternate keyboard input methods that buffered text and sent it on an interval but that wasn't any faster and resulted in more staggered text input.

Unless keyboard input via the remote API gets reverse engineered, there is nothing that can be done about ADK keyboards poor performance.

Chewie610 commented 2 months ago

Ah, so since it's adb-shell, I guess it's not connected permanently in a shell session? Only when it sends a command does it connect?

One other feature request I had was to see if it's possible to open the phone's keyboard dialog automatically when you request text for the textbox method. When using a browser on my PC, the text field is automatically entered so I can begin typing right away. However, when on my phone (Android), I need to click on the text field before the keyboard shows up and I can start typing.

Nerwyn commented 2 months ago

Yeah, it's a new shell session for each command. Very inefficient but I don't think there's a way around it.

It isn't possible. In order to bring up the on screen keyboard a text input has to be brought into focus. The browser prompt is blocking and no other calls can be made while it's open, and even if I could make other calls the browser prompt isn't an HTML element that can be interacted with.