【问题标题】:Android: Getting "su" to work in a rooted AVD in the same way it works on a real rooted device?Android:让“su”在有根 AVD 中工作,就像在真正有根设备上工作一样?
【发布时间】:2014-11-29 15:49:42
【问题描述】:

我正在为需要进入超级用户模式的根设备编写应用程序。我知道如何以适用于实际 root 设备的方式执行此操作,但是当我在 AVD 中测试它时,“su”命令的行为与它在真实设备上的行为不同。它不允许非 root 用户“su”到 root ... AVD 只允许 root 到 su 到非 root 用户。

有谁知道如何让以下代码片段在 Android 模拟器中工作?

        // ... etc. ...

        Process process = null;

        try {
            // This works on a rooted device and fails within
            // the rooted AVD ...
            process = new ProcessBuilder("/system/xbin/su").start();
        }
        catch (Throwable t) {
            t.printStackTrace();
            return;
        }

        DataOutputStream  writer = new DataOutputStream(process.getOutputStream());
        InputStreamReader stream = new InputStreamReader(process.getInputStream());
        BufferedReader    reader = new BufferedReader(stream);

        try {
            writer.writeBytes("exec /system/bin/mount -o remount,rw /system\n");
            // Just in case the "exec" fails, above ...
            writer.writeBytes("exit 1\n");
            writer.close();
        }
        catch (Throwable t) {
            t.printStackTrace();
            return;
        }
        finally {
            try {
                reader.close();
            }
            catch (Throwable t) {
                // do nothing
            }
            try {
                stream.close();
            }
            catch (Throwable t) {
                // do nothing
            }
        }

        // ... etc. ...

这会失败,因为应用程序没有以 root 身份运行,但在 AVD 中,/system/xbin/su 命令仅在由 root 用户调用时才有效。下面的 adb shell 对话框说明了这一点(我正在连接到正在运行的 AVD)...

% adb shell
root@generic:/ # ### we are now running as root
root@generic:/ # /system/xbin/su u0_a70
root@generic:/ $ ### this worked because "su" is invoked as root
root@generic:/ $ ### we are now running as user u0_a70
root@generic:/ $ /system/xbin/su root
su: uid 10070 not allowed to su
1|root@generic:/ $ ### this didn't work as a non-root user

有谁知道如何让“su”命令在 root AVD 中工作,就像“su”在 root 设备中工作一样?

提前致谢。

PS:这是针对 Android 4.4.x 的

【问题讨论】:

    标签: android root avd su


    【解决方案1】:

    不要使用现有的 Android 模拟器,使用 GenyMotion 并按照本教程进行操作 XDA link

    希望对你有帮助:)

    【讨论】:

    • 非常感谢。我没有听说过 Genymotion。我已经安装了,效果很好!当前版本结果是内置了超级用户,所以我什至不需要链接中的特殊“su”。
    • PS:开箱即用,这个 Genymotion AVD 就像一个普通的根设备一样工作......至少 w/r/t 获得超级用户访问权限。
    • PPS:出于好奇,我尝试了您在来自 Android 的标准 AVD 中提供的链接中的 su。它是在不同的架构下编译的,它不起作用。当试图在那里运行它时,它会产生这个错误:“/system/bin/su: not executable: magic 7F45”。但我不需要它,因为我正在使用 Genymotion。
    • 很高兴我能帮上忙 :)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-04-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多