virresh / matvt

Virtual Mouse for Android TV that can be controlled via remote itself.
GNU General Public License v3.0
211 stars 35 forks source link

Incorporate ADB lib to work around devices with gesture api disabled #24

Open virresh opened 2 years ago

virresh commented 2 years ago

ADB lib - https://github.com/tananaev/adblib

This would send shell input commands directly to the input jar on devices with wireless adb enabled.

sweenwolf commented 2 years ago

There will be 1 or more seconds delay https://user-images.githubusercontent.com/30427735/141248062-cc183259-510b-4c8a-bb39-66dfdee2204f.mp4

virresh commented 2 years ago

Oh damn, I thought it'd be fast enough on localhost. Thanks for the PoC though.

Seems like the input.jar itself introduces some delay and combined with network it lags a lot.

Some more poking around yields this - https://android.googlesource.com/platform/frameworks/base/+/android-4.4.2_r1/cmds/input/src/com/android/commands/input/Input.java#247

We can use those private methods and call the input API directly to remove any lag at all without root, however, SELinux policies will block us on the INJECT_EVENT permission. I can't think of a way without root to achieve this 😞

ybtag commented 2 years ago

This method only works for me (on the Sonim XP3plus flip phone) after connecting to the phone with USB adb and sending adb tcpip 5555. Until then the adb daemon on the phone only listens on USB, not TCPIP, and MATVT can't connect to it.

The way around it would seem to be with Wireless ADB, but on Android 11 there are two problems with this: The daemon listens on random ports, and the client needs to provide a pairing code in order to connect. The tananaev library doesn't provide this functionality, and in fact seems to be outdated and a dead project.

This is really more of an issue with tananaev'a adblib. Thank you again @virresh for your creative solution to use this library to get around the Android 11 issues.

virresh commented 2 years ago

Oh I see. Randomized ports are definitely painful :(

There might yet be another work-around for that by re-implementing the whole ADB protocol in a java library (I saw some libraries that do this), write a usb emulation driver and then invoke adb tcpip <fixed_port> command via the Java interface.

But all that is kinda tedious to maintain. It has several loop holes and too much dependency which might break easily which is very hard to maintain. Mentioning this possibility here just in case someone is interested in hacking around on this idea further.

ybtag commented 1 year ago

Just noticed a solution to the port problem here. I will try to implement it in my branch

virresh commented 1 year ago

Oh, interesting. Let me know what results you get with the workaround.