0

I'm implementing a terminal "emulator"/"launcher" in my app. I want to let the user to use all android shell commands. This works great, until I use the "su" command. here is the source code:

Code:

    ProcessBuilder processBuilder = new ProcessBuilder(input);        
    processBuilder.directory(info.currentDirectory);

    Process process;

    try {
        process = processBuilder.start();
    } catch (IOException e) {
        return 1;
    } 

    process.waitFor();

    InputStream i = process.getInputStream();
    InputStream e = process.getErrorStream();

    BufferedReader ir = new BufferedReader(new InputStreamReader(i));
    BufferedReader er = new BufferedReader(new InputStreamReader(e));

    String s = null;
    output = "";
    for(int count = 0; count == 0 || s != null; count++) {
        s = ir.readLine();
        if(s != null) {
            if(count == 0) 
                output = output.concat(mContext.getString(R.string.output_label) + "\n");
            output = output.concat(s + "\n");
        }
    }
    s = null;
    for(int count = 0; count == 0 || s != null; count++) {
        s = er.readLine();
        if(s != null) {
            if(count == 0) 
                output = output.concat(mContext.getString(R.string.error_label) + "\n");
            output = output.concat(s + "\n");
        }
    }
    process.destroy();

Main thread is blocked forever in any case: if I call only process.waitFor, and if I use one of the InputStream objects.

What's the problem? SU permissions are granted normally...

Tsyvarev
  • 60,011
  • 17
  • 110
  • 153
Andre99
  • 61
  • 10
  • After permissions are granted, `su` command does not terminate, it creates/reuses terminal, which is used for root's process. Did you find that terminal? – Tsyvarev Sep 15 '15 at 15:13
  • what do you mean? a terminal instance? – Andre99 Sep 15 '15 at 18:46
  • Yes, it is probably new terminal instance. But I has no guesses where it can be. I am sure only that `su` process is not terminated after permissions are granted. – Tsyvarev Sep 15 '15 at 19:00
  • so what should I do? should I create a thread that only manages su process? but, in this case, am I able to use SU permissions? – Andre99 Sep 15 '15 at 19:02
  • You should call `su` with parameters, so it will execute some your application in the process with root permissions. See, e.g., that answer for related question: http://stackoverflow.com/a/21596583/3440745. – Tsyvarev Sep 15 '15 at 19:15
  • yeah, I should. thank you for your help – Andre99 Sep 15 '15 at 19:20

0 Answers0