ads

lundi 14 septembre 2015

ProcessBuilder.start() with "su" command blocks thread



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...



Aucun commentaire:

Enregistrer un commentaire