Unfortunately 'run-parts' is gone with CM13, added code to replace it. The
authorAlexander Koenig <alex@lisas.de>
Mon, 7 Dec 2015 20:48:31 +0000 (21:48 +0100)
committerAlexander Koenig <alex@lisas.de>
Mon, 7 Dec 2015 20:48:31 +0000 (21:48 +0100)
scripts will have to detach or terminate properly or the App will hang.

app/src/main/java/de/lisas/alex/runuserinit/RunActivity.java

index a20d2424aa36c38a8599c598462e32593adb167d..408d1f2ba718c2cd2918ea076b4cd6f16fdf0c3a 100644 (file)
@@ -29,7 +29,9 @@ import android.view.Menu;
 import android.view.MenuItem;
 import android.view.View;
 
+import java.io.BufferedReader;
 import java.io.IOException;
+import java.io.InputStreamReader;
 
 public class RunActivity extends Activity {
 
@@ -48,8 +50,19 @@ public class RunActivity extends Activity {
 
     static void runAsRoot() {
         try {
-            Process process = Runtime.getRuntime().exec(new String[] { "su", "-c", "run-parts /data/local/userinit.d/" });
-            process.waitFor();
+            // Replace run-parts as it's gone with CM13
+            Process lsProcess = Runtime.getRuntime().exec(new String[] { "su", "-c", "ls /data/local/userinit.d/" });
+            BufferedReader reader = new BufferedReader(new InputStreamReader(lsProcess.getInputStream()));
+
+            String initScript;
+            while ((initScript = reader.readLine()) != null) {
+                // You better take care that these scripts daemonize whatever they run
+                Process process = Runtime.getRuntime().exec(new String[] { "su", "-c", "/data/local/userinit.d/" + initScript });
+                process.waitFor();
+            }
+
+            lsProcess.waitFor();
+
         } catch (IOException e) {
             e.printStackTrace();
         } catch (InterruptedException e) {