Using ADB locally on device (loopback) shows no devices

JayShortway picture JayShortway · Nov 6, 2014 · Viewed 8.5k times · Source

I am trying to use ADB on an Android device itself, so without any host computer. This was working perfectly a couple of days ago, but it suddenly stopped working. As far as I know nothing changed since then (e.g. no apps (un)installed). I could use adb backup -f /sdcard/backup.ab <package-name> in a terminal emulator and it would start to backup that package. When I try that now, it returns adb: unable to connect for backup. Investigating using adb devices returns an empty list. I never bothered to check the devices previously, I just went straight to my adb command, because everything was working.

This was on an HTC Desire running Android 4.4.2, ADB version 1.0.31. Using ADB from my PC with this phone is working perfectly, but this is not what I want.

What I have tried

  • I have tried to perform the same actions on different devices (Asus PadFone 2 on 4.4.2, Samsung Galaxy Note GT-N7000 on 4.4.2, Sony Xperia S on 4.1.2.) but adb devices returns an empty list on all of them. I am starting to wonder why this has worked on my HTC Desire in the first place.
  • Searching Google and Stack Overflow, but most (if not all) results refer to a driver problem or any other problem involving a host computer.
  • adb kill-server + adb start-server about a hundred times, as well as stop adbd + start adbd.
  • Turning 'USB Debugging' off and on in the Settings, as well as revoking access to previously authorized computers. (However, in the working situation, I never got any RSA key verification prompt.)
  • adb -a devices -> empty list.
  • adb usb -> error: device not found.
  • Trying to restart adb(d) in TCP mode is unsuccessful (even though this was not necessary in the working situation). adb tcpip 5555 returns error: device not found.
  • getprop returns no entry named service.adb.tcp.port and setprop service.adb.tcp.port 5555 silently fails. (Checking afterwards using getprop service.adb.tcp.port returns nothing. Doesn't this need root?)
  • adb connect localhost returns unable to connect to localhost:5555.
  • When the daemon starts, it starts on port 5038 (when using ADB from my PC it starts on 5037). adb connect localhost:5038 returns connected to localhost:5038. However adb devices still returns an empty list, and adb backup returns adb: unable to connect for backup. Furthermore adb shell returns error: device not found and adb get-state returns unknown. So no success here either.
  • Finding my local ip using getprop dhcp.wlan0.ipaddress (returns 192.168.1.xx) and then adb connect 192.168.1.xx returns unable to connect to :5555. adb connect 192.168.1.xx:5038 -> unable to connect to :5038. Using ADBHOST=192.168.1.xx adb start-server has no effect on these outcomes.
  • One of the few search results that was actually somewhat relevant is this thread on the AOSP Issue Tracker. Yet, it describes a problem where, after using setprop service.adb.tcp.port 5555, adb devices at least shows a device, however offline (namely localhost:5555 offline). Somewhat near the end of the thread a solution is reached, which involves changing the $HOME directory so as to change where the RSA keys are saved, e.g. HOME=/sdcard. It is then necessary to append the public key to /data/misc/adb/adb_keys using cat /sdcard/.android/adbkey.pub >> /data/misc/adb/adb_keys. However, I presume this needs root? Also, all of this was not necessary in the working situation so I doubt the solution to my problem is to be found in this direction. This article, derived from the thread at AOSP's Issue Tracker, does not speak of appending the public key. However, the approach mentioned is unsuccessful.
  • netstat returns (among others):

    • Proto: tcp
    • Recv-Q: 0
    • Send-Q: 0
    • Local Address: 127.0.0.1:5038
    • Foreign Address: 0.0.0.0:*
    • State: LISTEN
  • ps shows an /sbin/adbd process as well as an adb process:

    • USER: shell PID: 92 PPID: 1 VSIZE: 3624 RSS: 264 WCHAN: ffffffff PC: 00000000 S NAME: /sbin/adbd
    • USER: u0_a57 PID: 9754 PPID: 1 VSIZE: 3016 RSS: 988 WCHAN: ffffffff PC: 4014f768 S NAME: adb
    • (Commands executed from the terminal are executed as USER: u0_a57.)

I guess that's pretty much it.

I am looking for a solution where no root is needed, as it was not needed when I had it working before. I hope my situation and question is clear. Please let me know if my question needs improving, as this is my first time posting on Stack Overflow. Hopefully someone can help me with this. Thanks in advance!

Answer

Tyler Richardson picture Tyler Richardson · Dec 13, 2016

I believe your device might have rebooted. To initially get your phone into tcp, you must have ran adb tcpip 5555 from a computer. But that doesn't last forever. If your phone gets rebooted, then you will have to run adb tcpip 5555 from a computer again.

I am not sure what you meant when you said:

Trying to restart adb(d) in TCP mode is unsuccessful (even though this was not necessary in the working situation). adb tcpip 5555 returns error: device not found.

Did you run that from a computer? If it was from a computer then I'm not sure what the problem is there. But if it was from the phone, then it can't find the device to change to tcp.

To fix this, adb tcpip 5555 from a computer should work.