为什么exec()启动ADB守护程序? [英] Why does exec() start a ADB daemon?

查看:205
本文介绍了为什么exec()启动ADB守护程序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在为我拥有的一些植根电话构建应用程序。我想知道是否可以通过电话从我的应用程序中运行一些代码的系统应用程序卸载。

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.

我尝试通过电话运行 adb shell pm clear COM.PACKAGE.NAME 这样的命令c $ c> Runtime.getRuntime()。exec(),但是命令的输出如下:

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*

为什么?

推荐答案

ADB 服务器在主机( Unix Windows ),默认情况下绑定到端口 5037 。客户端(也是您的主机)使用端口将命令发送到在系统环境中执行命令的目标设备。

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.

参考 >:


  1. Android调试桥 Android 开发人员网站上。

  2. ADB(Android调试桥):如何工作?通过小林哲之

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

一个应用程序,其代码在环境中执行。因此,当您调用 Runtime.getRuntime()。exec( adb shell命令)时,实际上是在尝试启动另一个 adb 服务器进程(现在在目标设备上),开始于 tcp 端口 5038 ,因为端口 5037 很忙。

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.

总结一下:您不需要通过 adb exec()方法的c $ c>参数,它是多余的。而是使用

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

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

关于以编程方式卸载系统应用程序,您的应用程序必须首先获得 su ,这超出了题。虽然,以下链接可能会帮助您开始:

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执行shell命令

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

这篇关于为什么exec()启动ADB守护程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆