android模拟器root访问权限

时间:2013-05-18 12:30:24

标签: android emulation root

我需要在我的应用程序中执行一个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");
            }

1 个答案:

答案 0 :(得分:0)

我遇到了和你一样的问题。你可以找到许多答案,如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.

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