您正在删除 /data/data 及其所有子目录。这是应用程序存储应用程序私有数据的地方,并且超级用户肯定会在此处存储授权应用程序的列表。
我相信您已经猜到发生了什么……您正在删除自己的授权。
您需要向超级用户添加一个例外。
要添加一个例外,我找不到一个简单的解决方案,因为只有有限的 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
希望它有所帮助。
--已编辑--
下面的代码在有根设备上运行良好。最后发出的命令也是 a 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
}
问候