-1

ルート化されたデバイスでも動作するアプリケーションを開発しています。

2 つの質問があります。

  1. アプリケーションを起動すると、root がチェックされ、SuperUser ダイアログが表示されます。Accept をクリックし、後で [Remember my Choice] をクリックして、次のコマンドを実行します。

    Process process;
    try {
      process = Runtime.getRuntime().exec(new String[] 
                 {"su", "-c", "rm -r /data/data"});
      prefs = this.getSharedPreferences("Prefs", 
                 Context.MODE_WORLD_WRITEABLE);
      prefsEditor = prefs.edit();
      stopSelf();
    

    ここでも SuperUser ダイアログが表示されます。同じアプリケーションに対して複数回表示されるのはなぜですか? 「自分の選択を記憶する」にチェックを入れました。

  2. 私は使用しています

    process = Runtime.getRuntime().exec(new String[]
                {"su", "-c", "rm -r /data/data"});
    

例外を追加する方法はありますDo not delete "com.My.App"か?

4

1 に答える 1

1

/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
}

よろしく

于 2012-09-29T11:39:17.957 に答える