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

1

-2

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?

Barnsley answered 5/12, 2015 at 11:8 Comment(0)
T
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
Titi answered 5/12, 2015 at 23:58 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.