OSDN Git Service

Fix recovery install via app.
authorKoushik Dutta <koushd@gmail.com>
Mon, 5 Aug 2013 22:35:59 +0000 (15:35 -0700)
committerKoushik Dutta <koushd@gmail.com>
Mon, 5 Aug 2013 22:35:59 +0000 (15:35 -0700)
Fix adb shell not being able to access /data.
Use thin font on values-16, only on Superuser-light theme.
Better logging.

Change-Id: I9d7dd0d9b0a006f1703926f65f8a5ea3f0e29bd2

Superuser/jni/su/daemon.c
Superuser/jni/su/su.c
Superuser/jni/su/su.h
Superuser/res/values-v16/styles.xml [new file with mode: 0644]
Superuser/src/com/koushikdutta/superuser/MainActivity.java
Superuser/src/com/koushikdutta/superuser/util/SuHelper.java

index 2208cd3..ca34e56 100644 (file)
@@ -178,6 +178,9 @@ static int daemon_accept(int fd) {
     chown(outfile, daemon_from_uid, 0);
     chown(infile, daemon_from_uid, 0);
     chown(errfile, daemon_from_uid, 0);
+    chmod(outfile, 0660);
+    chmod(infile, 0660);
+    chmod(errfile, 0660);
 
     // ack
     write_int(fd, 1);
@@ -200,17 +203,17 @@ static int daemon_accept(int fd) {
 
     int outfd = open(outfile, O_WRONLY);
     if (outfd <= 0) {
-        PLOGE("outfd");
+        PLOGE("outfd daemon %s", outfile);
         goto done;
     }
     int errfd = open(errfile, O_WRONLY);
     if (errfd <= 0) {
-        PLOGE("errfd");
+        PLOGE("errfd daemon %s", errfile);
         goto done;
     }
     int infd = open(infile, O_RDONLY);
     if (infd <= 0) {
-        PLOGE("infd");
+        PLOGE("infd daemon %s", infile);
         goto done;
     }
 
@@ -402,17 +405,17 @@ int connect_daemon(int argc, char *argv[]) {
 
     int outfd = open(outfile, O_RDONLY);
     if (outfd <= 0) {
-        PLOGE("outfd");
+        PLOGE("outfd %s ", outfile);
         exit(-1);
     }
     int errfd = open(errfile, O_RDONLY);
     if (errfd <= 0) {
-        PLOGE("errfd");
+        PLOGE("errfd %s", errfile);
         exit(-1);
     }
     int infd = open(infile, O_WRONLY);
     if (infd <= 0) {
-        PLOGE("infd");
+        PLOGE("infd %s", infile);
         exit(-1);
     }
 
index 9a4a7aa..6cbe724 100644 (file)
@@ -610,13 +610,24 @@ int access_disabled(const struct su_initiator *from) {
     return 0;
 }
 
+static int is_api_18() {
+  char sdk_ver[PROPERTY_VALUE_MAX];
+  char *data = read_file("/system/build.prop");
+  get_property(data, sdk_ver, "ro.build.version.sdk", "0");
+  int ver = atoi(sdk_ver);
+  free(data);
+  return ver >= 18;
+}
+
 int main(int argc, char *argv[]) {
     // start up in daemon mode if prompted
     if (argc == 2 && strcmp(argv[1], "--daemon") == 0) {
         return run_daemon();
     }
 
-    if (geteuid() != AID_ROOT && getuid() != AID_ROOT) {
+    // attempt to use the daemon client if not root,
+    // or this is api 18 and adb shell (/data is not readable even as root)
+    if ((geteuid() != AID_ROOT && getuid() != AID_ROOT) || (is_api_18() && getuid() == AID_SHELL)) {
         // attempt to connect to daemon...
         LOGD("starting daemon client %d %d", getuid(), geteuid());
         return connect_daemon(argc, argv);
index 3dd6688..4bbe406 100644 (file)
@@ -82,7 +82,7 @@
 #define str(a) #a
 
 #ifndef VERSION_CODE
-#define VERSION_CODE 10
+#define VERSION_CODE 12
 #endif
 #define VERSION xstr(VERSION_CODE) " " REQUESTOR
 
diff --git a/Superuser/res/values-v16/styles.xml b/Superuser/res/values-v16/styles.xml
new file mode 100644 (file)
index 0000000..4005216
--- /dev/null
@@ -0,0 +1,15 @@
+<resources xmlns:android="http://schemas.android.com/apk/res/android">
+
+    <style name="AndroidTheme" parent="@android:style/Theme.Holo.Light.DarkActionBar">
+        <item name="android:textViewStyle">@style/RobotoTextViewStyle</item>
+        <item name="android:buttonStyle">@style/RobotoButtonStyle</item>
+    </style>
+
+    <style name="RobotoTextViewStyle" parent="android:Widget.TextView">
+        <item name="android:fontFamily">sans-serif-light</item>
+    </style>
+
+    <style name="RobotoButtonStyle" parent="android:Widget.Holo.Button">
+        <item name="android:fontFamily">sans-serif-light</item>
+    </style>
+</resources>
index cc7319b..c6b8114 100644 (file)
@@ -107,9 +107,6 @@ public class MainActivity extends BetterListActivity {
                     File zip = getFileStreamPath("superuser.zip");
                     ZipOutputStream zout = new ZipOutputStream(new FileOutputStream(zip));
                     doEntry(zout, "assets/update-binary", "META-INF/com/google/android/update-binary");
-                    zout.close();
-
-                    zout = new ZipOutputStream(new FileOutputStream(zip));
                     doEntry(zout, "assets/install-recovery.sh", "install-recovery.sh");
                     zout.close();
 
index 5654575..3234ce8 100644 (file)
@@ -4,7 +4,7 @@ import android.content.Context;
 import android.util.Log;
 
 public class SuHelper {
-    public static String CURRENT_VERSION = "10";
+    public static String CURRENT_VERSION = "12";
     public static void checkSu(Context context) throws Exception {
         Process p = Runtime.getRuntime().exec("su -v");
         String result = Settings.readToEnd(p.getInputStream());