简体   繁体   English

具有getevent的扎根android手机上的权限被拒绝

[英]Permission denied on rooted android phone with getevent

I have very simple code as follows: 我有非常简单的代码,如下所示:

@Override
public void onClick(View v) 
{
  Log.i("MyApp", "Started");
  try
  {
    Process processStart = Runtime.getRuntime().exec("su");
  } 
  catch (IOException e1)
  {
    e1.printStackTrace();
  }
  String myStringArray[]= {"getevent","/dev/input/event0"};
  String line;
  try 
  {
    Process process = Runtime.getRuntime().exec(myStringArray);
    InputStreamReader inputstreamreader = new InputStreamReader(process.getInputStream());
    BufferedReader bufferedReader = new BufferedReader(inputstreamreader);
    bufferedReader.read();
    while ((line = bufferedReader.readLine()) != null) 
    {
      Log.i("MyApp", line);
    }
    InputStreamReader errstreamreader = new InputStreamReader(process.getErrorStream());
    BufferedReader errReader = new BufferedReader(errstreamreader);
    errReader.read();
    while ((line = errReader.readLine()) != null) 
    {
      Log.i("MyApp", line);
    }
  } catch(java.io.IOException e){
  }
  Log.i("MyApp", "Finished");
}
});

but I get this error: 但是我得到这个错误:

could not open /dev/input/event0, permission denied

I get asked to grant root permission on the phone but before that it have error on logcat. 我被要求在电话上授予root权限,但是在此之前,logcat出现错误。

I have also tried with processStart.waitFor(); 我也尝试过使用processStart.waitFor();

But it hangs the application there and does not move forward at all. 但是它将应用程序挂在那里,根本不前进。 I have tried looking the reason everywhere but could not get this to work. 我试过到处寻找原因,但无法解决这个问题。

I also tried with ProcessBuilder but when I use that the getevent returns nothing at all... 我也尝试过使用ProcessBuilder,但是当我使用该方法时,getevent根本不返回任何内容。

I think you have misunderstood the usage of 'su'. 我认为您误解了“ su”的用法。

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

The above code will create a new process and execute the 'su' command, which will only make the child process to become 'root'. 上面的代码将创建一个新进程并执行'su'命令,这只会使子进程成为'root'。

Your calling process is still a normal process so that you cannot do 'getevent'. 您的调用过程仍然是正常过程,因此您无法执行“ getevent”。 Instead you should run this super command in your 'rooted child process' like: 相反,您应该在“ rooted child process”中运行此超级命令,如下所示:

mProcess = new ProcessBuilder()
                        .command("/system/xbin/su")
                        .redirectErrorStream(true).start();

OutputStream out = mProcess.getOutputStream();

String cmd = "getevent /dev/input/event0 \n";
Log.d(TAG, "Native command = " + cmd);
out.write(cmd.getBytes());

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM