-1

I want to use adb to install apps to my Android-based TV from an Android phone rather than a computer.

So I decide to read adb source code, port the adb code and compile it to a library file (libadb.so) and then invoke it by JNI from within an Android app.

When I test this apk on my telephone, the adb server fails with can not bind 'tcp:5037' port.

I thought the failure to open that port might be a conflict with the existing implementation of ADB which might be using it, so I removed that. It didn't work. I tried to change to other ports, such as 4097,or 6066. It still didn't work. I have no further ideas how to solve this problem.

Chris Stratton
  • 39,853
  • 6
  • 84
  • 117
  • Since you seem to be failing to open any TCP sockets at all, the first thing to check would be if your are running within an app which has Internet permission. Android enforces this via a modification to the Linux kernel - only userids in the network group can open AF_INET sockets, and that membership is controlled by the AndroidManifest.xml of the package executing your code. – Chris Stratton Mar 06 '15 at 15:58
  • Personally, I might be tempted to do this using the command-line executable build of ADB for Android itself which has appeared in recent versions (or possibly your own re-build of that if the one on your device isn't suitable) - it may be cleaner to do it that way with an executable than to have all of this linked into a DVM/ART application process via JNI. – Chris Stratton Mar 06 '15 at 16:06
  • It works after adding Internet permission. Thanks a lot.@Chris Stratton – user4641142 Mar 09 '15 at 01:05

1 Answers1

1

Android enforces its Internet Permission via a modification to the Linux Kernel which checks that a process is a member of an associated unix group before allowing it to open sockets in the AF_INET domain.

Such membership is inherited, so native code executed, either as a JNI library or by invoking a distinct executable, will only be able to perform network operations if it is either run as a privileged user automatically having this membership (such as adb's "shell" account, or as root on an engineering build) or run under the identify of an application package having the Internet permission in its manifest.

There may be a number of additional challenges with your goal (and it is unclear why the stock adb client on the device is not workable for you), but the immediate solution to your present problem is to run your customized adb tool from an application with Internet permission.

Chris Stratton
  • 39,853
  • 6
  • 84
  • 117