|
应用判断是否具有root权限,只需要看能否在data分区创建文件,如果能够在data分区创建文件,那么应用具有root权限
public static boolean upgradeRootPermission( ) {
Process process = null;
DataOutputStream os = null;
try {
Log.i("roottest", "try it");
String cmd = "touch /data/roottest.txt";
process = Runtime.getRuntime().exec("su"); //切换到root帐号
os = new DataOutputStream(process.getOutputStream());
os.writeBytes(cmd + "\n");
os.writeBytes("exit\n");
os.flush();
process.waitFor();
} catch (Exception e) {
return false;
} finally {
try {
if (os != null) {
os.close();
}
process.destroy();
} catch (Exception e) {
}
}
return true;
}
|
|