Issue
I want to connect to adb shell from my app. To achieve it I need adbd transport to listen on a tcp port.
Using a real device is not a solution, I want to test my app specifically with android emulator.
I create and run the emulator:
avdmanager create avd -n phone -d pixel_xl -k "system-images;android-30;google_apis_playstore;x86_64"
emulator @phone
I run adb tcpip 5555
. Though the command runs successfully adbd transport is not exposed.
adb shell logcat | grep adbd
01-15 15:40:23.786 2013 2013 I adbd : Setup mdns on port= 5555
01-15 15:40:23.787 2013 2032 I adbd : Waiting for persist.adb.tls_server.enable=1
01-15 15:40:23.787 2013 2013 I adbd : adbd listening on tcp:5555
01-15 15:40:23.788 2013 2013 I adbd : adbd listening on vsock:5555
01-15 15:40:23.798 2013 2040 I adbd : host-14: read thread spawning
01-15 15:40:23.799 2013 2013 I adbd : host-14: already offline
01-15 15:40:23.799 2013 2013 I adbd : Calling send_auth_request...
01-15 15:40:23.806 2013 2041 I adbd : host-14: write thread spawning
01-15 15:40:23.808 2013 2013 I adbd : adbd_auth: loading keys from /data/misc/adb/adb_keys
01-15 15:40:23.809 2013 2013 I adbd : adb client authorized
01-15 15:40:23.818 2013 2033 I adbd : adbd_auth: received a new framework connection
01-15 15:40:23.819 2013 2033 I adbd : adbd_auth: received new framework fd 18 (current = -1)
01-15 15:40:23.819 2013 2033 I adbd : adbd_auth: marking framework writable
01-15 15:40:24.793 2013 2034 I adbd : adbd mDNS service _adb._tcp registered: 1
01-15 15:43:09.598 2013 6477 I adbd : adbd restarting in TCP mode (port = 5555)
01-15 15:43:09.635 6478 6479 I adbd : Waiting for persist.adb.tls_server.enable=1
01-15 15:43:09.635 6478 6478 I adbd : Setup mdns on port= 5555
01-15 15:43:09.635 6478 6478 I adbd : adbd listening on tcp:5555
01-15 15:43:09.635 6478 6478 I adbd : adbd listening on vsock:5555
01-15 15:43:09.635 6478 6481 I adbd : adbd mDNS service _adb._tcp registered: 1
01-15 15:43:10.856 6478 6485 I adbd : host-12: read thread spawning
01-15 15:43:10.856 6478 6486 I adbd : host-12: write thread spawning
01-15 15:43:10.857 6478 6478 I adbd : host-12: already offline
01-15 15:43:10.857 6478 6478 I adbd : Calling send_auth_request...
01-15 15:43:10.859 6478 6478 I adbd : adbd_auth: loading keys from /data/misc/adb/adb_keys
01-15 15:43:10.860 6478 6478 I adbd : adb client authorized
01-15 15:43:11.607 6478 6480 I adbd : adbd_auth: received a new framework connection
01-15 15:43:11.607 6478 6480 I adbd : adbd_auth: received new framework fd 18 (current = -1)
01-15 15:43:11.607 6478 6480 I adbd : adbd_auth: marking framework writable
adb shell netstat -tulpn
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program Name
tcp 0 0 10.0.2.16:54912 172.217.16.42:443 ESTABLISHED -
tcp 0 0 10.0.2.16:60088 172.217.20.202:443 ESTABLISHED -
tcp6 0 0 ::ffff:10.0.2.16:43504 ::ffff:142.250.75.3:443 ESTABLISHED -
tcp6 0 0 ::ffff:10.0.2.16:43502 ::ffff:142.250.75.3:443 ESTABLISHED -
tcp6 0 0 ::ffff:10.0.2.16:44476 ::ffff:64.233.164.:5228 ESTABLISHED -
tcp6 0 0 ::ffff:10.0.2.16:59130 ::ffff:142.250.203.:443 ESTABLISHED -
tcp6 0 0 ::ffff:10.0.2.16:50832 ::ffff:172.217.16.1:443 ESTABLISHED -
tcp6 0 0 ::ffff:10.0.2.16:50836 ::ffff:172.217.16.1:443 ESTABLISHED -
tcp6 0 0 ::ffff:10.0.2.16:35828 ::ffff:216.58.215.1:443 ESTABLISHED -
tcp6 0 0 ::ffff:10.0.2.16:48984 ::ffff:216.58.215.7:443 ESTABLISHED -
tcp6 0 0 ::ffff:10.0.2.16:49628 ::ffff:172.217.16.4:443 ESTABLISHED -
tcp6 0 0 ::ffff:10.0.2.16:60070 ::ffff:172.217.20.2:443 ESTABLISHED -
tcp6 0 0 ::ffff:10.0.2.16:43942 ::ffff:216.58.215.6:443 ESTABLISHED -
tcp6 0 0 ::ffff:10.0.2.16:57422 ::ffff:142.250.203.:443 ESTABLISHED -
tcp6 0 0 ::ffff:10.0.2.16:54880 ::ffff:172.217.16.4:443 ESTABLISHED -
tcp6 0 0 ::ffff:10.0.2.16:54876 ::ffff:172.217.16.4:443 ESTABLISHED -
tcp6 0 0 ::ffff:10.0.2.16:43506 ::ffff:142.250.75.3:443 ESTABLISHED -
tcp6 0 0 ::ffff:10.0.2.16:60054 ::ffff:172.217.20.2:443 ESTABLISHED -
tcp6 0 0 ::ffff:10.0.2.16:60072 ::ffff:172.217.20.2:443 ESTABLISHED -
udp 4608 0 10.0.2.16:68 10.0.2.2:67 ESTABLISHED -
udp 0 0 0.0.0.0:5353 0.0.0.0:* -
udp 0 0 0.0.0.0:5353 0.0.0.0:* -
udp 0 0 0.0.0.0:50490 0.0.0.0:* -
udp6 0 0 :::35263 :::* -
udp6 0 0 :::5228 :::* -
udp6 0 0 :::5353 :::* -
udp6 0 0 :::5353 :::* -
udp6 0 0 :::5353 :::* -
adb shell nc localhost 5555
nc: connect: Connection refused
I also tried using different system image with no success:
avdmanager create avd -n tv -d tv_720p -k "system-images;android-28;android-tv;x86"
How do I make it possible to connect to emulator adb shell using tcp transport?
Solution
There is no supported way to do this. When in emulator(ro.kernel.qemu=1
) adb uses QEMUD pipes instead of regular sockets.
EDIT
I made it work. I replaced
func = use_qemu_goldfish() ? qemu_socket_thread : server_socket_thread;
with
std::thread(qemu_socket_thread, port).detach();
std::thread(server_socket_thread, port).detach();
For some reason adb doesn't work if you run only server_socket_thread
.
Answered By - Marcin Król
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.