File tree Expand file tree Collapse file tree
controller/app/src/main/java/org/iiab/controller Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1414import android .os .Looper ;
1515import android .util .Log ;
1616
17+ import org .iiab .controller .util .AppExecutors ;
18+
1719import java .io .BufferedReader ;
1820import java .io .File ;
1921import java .io .InputStreamReader ;
2628
2729public class PRootEngine {
2830 private static final String TAG = "IIAB-PRootEngine" ;
29- private Process currentProcess ;
30- private java .io .OutputStream processOutputStream ;
31+ private volatile Process currentProcess ;
32+ private volatile java .io .OutputStream processOutputStream ;
3133
3234 public interface OutputListener {
3335 void onOutputLine (String line );
@@ -369,8 +371,19 @@ public void writeToShell(String command) {
369371 }
370372
371373 public void killProcess () {
372- if (currentProcess != null ) {
373- currentProcess .destroy ();
374- }
374+ final Process p = currentProcess ;
375+ if (p == null ) return ;
376+ p .destroy ();
377+ // Reap the child off the caller's thread so it does not linger as a
378+ // zombie / hold proot mounts. Process.waitFor(timeout) is API 26+ and
379+ // minSdk is 24, so we drain on the shared io() executor instead of
380+ // blocking the caller.
381+ AppExecutors .get ().io ().execute (() -> {
382+ try {
383+ p .waitFor ();
384+ } catch (InterruptedException e ) {
385+ Thread .currentThread ().interrupt ();
386+ }
387+ });
375388 }
376389}
You can’t perform that action at this time.
0 commit comments