/data/data とそのすべてのサブディレクトリを削除しています。これは、アプリケーションがアプリのプライベート データを保存する場所であり、SuperUser が許可されたアプリケーションのリストをここに保存していることは確かです。
何が起こっているかはすでにお分かりだと思います...あなたは自分の権限を削除しています。
スーパーユーザーに例外を追加する必要があります。
例外を追加するには、限られたシェル コマンドしか使用できないため、簡単な解決策を見つけることができませんでした。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
それが役に立ったことを願っています。
--編集済み--
以下のコードは、ルート化されたデバイスで正常に動作しています。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
}
よろしく