【发布时间】:2011-10-07 20:41:44
【问题描述】:
我创建了一个检查安卓手机是否root的方法。这样做如下
public int checkrootcommand(String string) {
// TODO Auto-generated method stub
Process exec;
try {
exec = Runtime.getRuntime().exec(new String[]{"su","-c"});
final OutputStreamWriter out = new OutputStreamWriter(exec.getOutputStream());
out.write("exit");
out.flush();
Log.i(SUPER_USER_COMMAND, "su command executed successfully");
return 0; // returns zero when the command is executed successfully
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return 1; //returns one when the command execution fails
}
但问题是 checkrootcommand() 方法首先执行它工作正常,但是当再次调用相同的方法时,超级用户会话仍在运行。方法执行后有什么方法可以结束超级用户会话吗??
【问题讨论】:
-
尝试在出口的末尾添加一个 \n。但这不是测试手机是否已root的可靠方法。
-
@antlersoft : 你能建议一个合适的方法吗?
-
code.google.com/p/roottools 也许你对此感兴趣
-
@Badr Hari:感谢您的建议。
-
这不仅不可靠,尝试使用 su 来检查一个没有宣传自己使用 root 权限来做对用户有益的事情的应用程序可能会导致用户将您的应用程序报告为邪恶。即使他们不报告,他们也可能会使用 su 包装器将您的应用程序列入黑名单,同时允许他们希望拥有 root 访问权限的应用程序这样做 - 因此您可能会错误地认为它没有 root 权限,而不仅仅是 root 权限,但以最常见的方式之一设置为 root 访问。