【问题标题】:android emulator root access安卓模拟器root权限
【发布时间】:2013-05-18 12:30:23
【问题描述】:

我需要在我的应用程序中执行一个 C 程序,只需将可执行文件添加到 android 项目并构建 .apk。然后我尝试像这样在我的应用程序中执行程序:

    Process result = Runtime.getRuntime().exec("su");
    String cmd = "PROGRAM_NAME";

    DataOutputStream dos = new DataOutputStream(result.getOutputStream());
    DataInputStreamdis = new DataInputStream(result.getInputStream());

    dos.writeBytes(cmd + "\n");
    dos.writeBytes("exit\n");
    dos.flush();

我知道我需要 root 访问权限才能执行此操作,因此我安装了 Superuser.apk 但这不起作用。还有另一种可能的方法吗?顺便说一句,代码没有完全扩展,它应该只看一下程序的执行方式 我正在使用 Android 4.2.1 运行模拟器

编辑: 首先检查root权限

         Process suProcess = Runtime.getRuntime().exec("su");

         DataOutputStream os = new DataOutputStream(suProcess.getOutputStream());
         DataInputStream osRes = new DataInputStream(suProcess.getInputStream());

         if (null != os && null != osRes) {
             os.writeBytes("id\n");
             os.flush();
             String currUid = osRes.readLine();
             boolean exitSu = false;
             if (null == currUid) {
                 Log.d("ROOT", "Can't get root access or denied by user");
            }

【问题讨论】:

  • 在这里查看答案:stackoverflow.com/questions/5095234/…
  • 使用 android 版本 2.2 这就是为什么它适用于他们,我使用的是 4.2.1 Root.apk/Superuser.apk,无论如何都认为它是一样的,不工作!?
  • Superuser.apk 不会 root 设备。尝试第二个答案的说明并尝试将 /system 文件系统重新安装为读/写并推送 su 命令。
  • 顺便说一句,我刚刚启动了我的模拟器。 adb shell 让您以 root 身份进入,因此您可以对图像执行任何操作。 /system/xbin/su 是正确的路径。我认为 Process 不会搜索您的 PATH 环境变量。
  • 我已经尝试了这些说明,但它不起作用,我可以毫无错误地执行它们,但我仍然没有 root 权限(请参阅问题的编辑)

标签: android emulation root


【解决方案1】:

我遇到了和你一样的问题。您可以找到很多答案,例如 here ,但它们太旧了,它们不再工作(在新的 sdk 中)。

我找到了最佳答案 here,它说 Security Tips of Android 不允许任何开发人员拥有 root 访问权限:

 A central design point of the Android security architecture is that no application, by default,
 has permission to perform any operations that would adversely impact other applications, the 
operating system, or the user. This includes reading or writing the user's private data (such as 
contacts or e-mails), reading or writing another application's files, performing network access, 
keeping the device awake, etc.

因此,您在应用层下的唯一访问权限是权限。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-05-06
    • 1970-01-01
    • 1970-01-01
    • 2011-04-06
    • 1970-01-01
    • 2015-03-23
    相关资源
    最近更新 更多