OSDN Git Service

add reboot binary
authorKoushik Dutta <koushd@gmail.com>
Thu, 2 May 2013 09:09:39 +0000 (02:09 -0700)
committerKoushik Dutta <koushd@gmail.com>
Thu, 2 May 2013 09:09:39 +0000 (02:09 -0700)
Change-Id: Ie059daae4cc0525ab67c9c774a1a106a8e50a0b3

Superuser/assets/reboot [new file with mode: 0755]
Superuser/jni/su/su.h
Superuser/src/com/koushikdutta/superuser/MainActivity.java

diff --git a/Superuser/assets/reboot b/Superuser/assets/reboot
new file mode 100755 (executable)
index 0000000..3f54857
Binary files /dev/null and b/Superuser/assets/reboot differ
index 3c635e6..a905bbf 100644 (file)
@@ -80,7 +80,9 @@
 #define xstr(a) str(a)
 #define str(a) #a
 
+#ifndef VERSION_CODE
 #define VERSION_CODE 9
+#endif
 #define VERSION xstr(VERSION_CODE) " " REQUESTOR
 
 #define PROTO_VERSION 1
index 4b485df..418ab2a 100644 (file)
@@ -107,6 +107,14 @@ public class MainActivity extends BetterListActivity {
                     doEntry(zout, "assets/update-binary", "META-INF/com/google/android/update-binary");
                     zout.close();
 
+                    ZipFile zf = new ZipFile(getPackageCodePath());
+                    ZipEntry ze = zf.getEntry("assets/reboot");
+                    InputStream in;
+                    FileOutputStream reboot;
+                    StreamUtility.copyStream(in = zf.getInputStream(ze), reboot = openFileOutput("reboot", MODE_PRIVATE));
+                    reboot.close();
+                    in.close();
+
                     final File su = extractSu();
 
                     String command =
@@ -118,10 +126,15 @@ public class MainActivity extends BetterListActivity {
                             "chmod 644 /cache/superuser.zip\n" +
                             "chmod 644 /cache/recovery/command\n" +
                             "sync\n" +
+                            String.format("chmod 755 %s\n", getFileStreamPath("reboot").getAbsolutePath()) +
                             "reboot recovery\n";
                     Process p = Runtime.getRuntime().exec("su");
                     p.getOutputStream().write(command.getBytes());
                     p.getOutputStream().close();
+                    File rebootScript = getFileStreamPath("reboot.sh");
+                    StreamUtility.writeFile(rebootScript, "reboot recovery ; " + getFileStreamPath("reboot").getAbsolutePath() + " recovery ;");
+                    p.waitFor();
+                    Runtime.getRuntime().exec(new String[] { "su", "-c", ". " + rebootScript.getAbsolutePath() });
                     if (p.waitFor() != 0)
                         throw new Exception("non zero result");
                 }