您正在删除/ data/data及其所有子目录。这是应用程序存储应用程序私有数据的地方,SuperUser肯定会在这里存储授权应用程序的列表。
我相信你已经猜到了什么是异想天开......你正在删除自己的授权。
您需要向superUser添加一个异常。
要添加一个异常,我找不到一个简单的解决方案,因为只有有限的shell命令可用。如果你安装了busybox,它会给你机会使用grep命令来解析输入并排除你想要的行。
另外,程序可以用下面的方法做:
process = Runtime.getRuntime().exec(new String[] {"su", "-c", "ls /data/data"});
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(process.getInputStream()));
String line;
ArrayList<String> files = new ArrayList<String>();
files.add("su");
files.add("-c");
files.add("rm -r");
while ((line = bufferedReader.readLine()) != null){
//test if you want to exclude the file before you add it
files.add("/data/data/" + line);
}
//issue a new command to remove the directories
process = Runtime.getRuntime().exec(files.toArray(new String[0])); //changed this line
希望它帮助。
--EDITED--
代码波纹管有根设备上工作的罚款。最后发出的命令也是ls
,因为我不想删除我的文件,但您可以用其他任何东西替换它(请参阅文件中的注释)。
private void execCmd(){
Process process;
try {
process = Runtime.getRuntime().exec(new String[] {"su", "-c", "ls /data/data"});
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
return;
}
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(process.getInputStream()));
String line;
ArrayList<String> files = new ArrayList<String>();
files.add("su");
files.add("-c");
// files.add("rm -r"); //Uncomment this line and comment the line bellow for real delete
files.add("ls");
try {
while ((line = bufferedReader.readLine()) != null){
//test if you want to exclude the file before you add it
files.add("/data/data/" + line);
}
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
//comment lines bellow to stop logging the command being sent
Log.d(TAG, "Command size: " + files.size());
for(int i=0; i< files.size(); i++)
Log.d(TAG, "Cmd[" + i + "]: " + files.get(i));
try {
process = Runtime.getRuntime().exec(files.toArray(new String[0]));
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} //changed this line
}
问候
答案时是有帮助的我的问题,然后我接受了,但我会是“少”难以接受的答案现在... – CELB