Why does exec() start a ADB daemon? [closed]

北城余情 提交于 2019-11-26 21:59:48

问题


I am building an app for some set of rooted phones I have. I was wondering if there is any way that I could uninstall a system app which comes with the phone running some code from my app.

I have tried running commands like adb shell pm clear COM.PACKAGE.NAME from the phone itself by Runtime.getRuntime().exec(), but the output of the command is as follows:

cannot bind 'tcp:5038

* Daemon not running. Starting it now on port 5038*

Why?


回答1:


ADB server starts on your host machine (Unix, Windows) and, by default, binds to port 5037. A client (also your host machine) uses the port to send commands to a target device where the commands are executed in the system environment.

Reference:

  1. Android Debug Bridge on the Android developer site.
  2. ADB(Android Debug Bridge): How it works? by Tetsuyuki Kobayashi

When you run an app, its code is executed in the environment. So when you call Runtime.getRuntime().exec("adb shell command") what you actually do is trying to start another adb server process (on a target device now) which starts on tcp port 5038, since port 5037 is busy.

To sum up: you do not need to pass adb parameter to the exec() method, it's redundant. Instead use

Runtime.getRuntime().exec("command")

Regarding uninstalling system apps programmatically, your app must get su first which is out of the scope of the question. Although, the following links might help you to start:

  1. ANDROID: How to gain root access in an Android application?
  2. execute shell command from android


来源:https://stackoverflow.com/questions/34104119/why-does-exec-start-a-adb-daemon

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!