vidstige / jadb

ADB Client in pure Java.
Apache License 2.0
640 stars 178 forks source link

ECONNREFUSED on Android #118

Closed H4xX0r1337 closed 5 years ago

H4xX0r1337 commented 5 years ago

I am trying to use an ADB library on an Android app. I tried another lib and it worked, but is not maintained anymore. That's why I want to use this one. I am always getting ECONNREFUSED on Android. I have granted all necessary permissions, but i can't connect to the phone. Neither from a real device nor from the emulator, but it works from the PC. Of course I have wireless USB-Debugging on port 5555. This is my source code and this is the stacktrace (sry for quality). Othrewise I just have a simple activity wth a button and granted the INTERNET permission in the manifest.

vidstige commented 5 years ago

jadb is meant to be running on the host machine, not the phone. It might work, but seems like a strange thing to do. Do you want to connect to an Android from an Android via adb?

H4xX0r1337 commented 5 years ago

@vidstige Yes, I want to connect from an Android phone to the same Android phone. It is a nice way to get elevated privileges. This old library is working. It's a shame that I can't use jadb.

jpage4500 commented 3 years ago

@H4xX0r1337 -- I know this was a long time ago but I'm also interested in making a connection from an Android app to the adb service on the same device.. did you ever figure out a solution?

Both this library and the other one you mentioned return the same error (I tried both port 5555 and 5037)

Exception: failed to connect to localhost/127.0.0.1 (port 5037) from /:: (port 48398): connect failed: ECONNREFUSED (Connection refused)

thanks!

vidstige commented 3 years ago

@jpage4500 @H4xX0r1337 it seems to be very easy to enable this. Check out this answer over at stackoverflow.com.

  1. Root the device
  2. setprop service.adb.tcp.port 5555
    stop adbd
    start adbd

For security reasons, it's intended design that the device needs to be rooted. Hope this helps!

jpage4500 commented 3 years ago

Hi @vidstige - thanks for the quick reply!

The answer I think you're mentioning is putting the device into wireless adb mode, right? I can do that today w/out root. I just have to type adb tcpip 5555 on my laptop with a device connected via USB. From that point on, I can run adb connect IP:5555 to connect to that device wirelessly and run normal adb commands.

What I'm wondering and I think is what the OP is also talking about is an Android app that talks to the adb service on the same device directly - no other adb server running on a laptop in between.

The reason for this is exactly what was stated earlier too.. in my case I have a helper app which can simplify entering text into whatever text field is in the foreground. I can do this via adb using adb input text hello.

However, If I run this from the app itself (ie: Process.exec("input text hello")) I get back an Exception:

SecurityException: Injecting to another application requires INJECT_EVENTS permission

But, I was hoping if my app could send the command through the adb service running on the device it wouldn't face that same limitation.. maybe that's not possible but it seemed worth a shot.