OSDN Git Service

Add support for su daemon installation and detection in recovery zip.
authorKoushik Dutta <koushd@gmail.com>
Tue, 30 Jul 2013 02:17:36 +0000 (19:17 -0700)
committerKoushik Dutta <koushd@gmail.com>
Tue, 30 Jul 2013 03:05:10 +0000 (20:05 -0700)
Change-Id: I09f2d2be61c9e8c5dec755de05227d41e08e4de8

Android.mk
Superuser/assets/install-recovery.sh
Superuser/assets/update-binary
Superuser/build.xml
Superuser/jni/su/su.c

index 3b0884b..69cbaf4 100644 (file)
@@ -59,6 +59,14 @@ $(SUPERUSER_RC): $(LOCAL_INSTALLED_MODULE) $(LOCAL_PATH)/Android.mk
        @rm -rf $@
        $(hide) cp external/koush/Superuser/init.superuser.rc $@
 
+
+SUPERUSER_MARKER := $(TARGET_OUT_ETC)/.has_su_daemon
+$(SUPERUSER_MARKER): $(LOCAL_MODULE)
+$(SUPERUSER_MARKER): $(LOCAL_INSTALLED_MODULE) $(LOCAL_PATH)/Android.mk
+       @mkdir -p $(dir $@)
+       @rm -rf $@
+       $(hide) touch $@
+
 ALL_MODULES.$(LOCAL_MODULE).INSTALLED := \
-    $(ALL_MODULES.$(LOCAL_MODULE).INSTALLED) $(TARGET_ROOT_OUT)/init.superuser.rc
-endif
\ No newline at end of file
+    $(ALL_MODULES.$(LOCAL_MODULE).INSTALLED) $(TARGET_ROOT_OUT)/init.superuser.rc $(TARGET_OUT_ETC)/.has_su_daemon
+endif
index 0018d8c..96e623c 100755 (executable)
@@ -7,4 +7,4 @@ mount -oro,remount /
 cp /system/xbin/su /superuser
 chmod 6755 /superuser/su
 mount -oro,remount /superuser
-/superuser/su --daemon &
\ No newline at end of file
+/superuser/su --daemon &
index e307989..6acff09 100644 (file)
@@ -6,6 +6,7 @@
 echo -n -e 'ui_print Installing Superuser...\n' > /proc/self/fd/$2
 echo -n -e 'ui_print\n' > /proc/self/fd/$2
 
+# detect binary versions to install
 X86=$(uname -a | grep x86)
 I686=$(uname -a | grep i686)
 I386=$(uname -a | grep i386)
@@ -25,6 +26,7 @@ then
   mkdir -p $PLATFORM
   cp /cache/su $PLATFORM/su
   cp /cache/Superuser.apk .
+  cp /cache/install-recovery.sh .
 fi
 
 
@@ -49,4 +51,24 @@ ln -s /system/xbin/su /system/bin/su
 cp Superuser.apk /system/app
 chmod 644 /system/app/Superuser.apk
 
+# if the system is at least 4.3, and there is no su daemon built in,
+# let's try to install it using install-recovery.sh
+BUILD_RELEASE_VERSION=$(cat /system/build.prop | grep ro\\.build\\.version\\.release)
+IS_43=$(echo $BUILD_RELEASE_VERSION | grep 4\\.3)
+if [ -z "$IS_43" -o "$IS_43" \> "4.3"  -o "$IS_43" == "4.3" ]
+then
+    # check for rom su daemon before clobbering install-recovery.sh
+    if [ ! -f "/system/etc/.has_su_daemon" ]
+    then
+        echo -n -e 'ui_print Installing Superuser daemon...\n' > /proc/self/fd/$2
+        echo -n -e 'ui_print\n' > /proc/self/fd/$2
+        cp install-recovery.sh /system/etc/install-recovery.sh
+        chmod 755 /system/etc/install-recovery.sh
+        # note that an post install su daemon was installed
+        # so recovery doesn't freak out and recommend you disable
+        # the install-recovery.sh execute bit.
+        touch /system/etc/.installed_su_daemon
+    fi
+fi
+
 umount /system
\ No newline at end of file
index 5500c8a..2f7ec33 100644 (file)
@@ -86,6 +86,7 @@
     <target name="-post-build">
         <mkdir dir="bin/recoveryzip/META-INF/com/google/android" />
         <copy file="assets/update-binary" tofile="bin/recoveryzip/META-INF/com/google/android/update-binary"/>
+        <copy file="assets/install-recovery.sh" tofile="bin/recoveryzip/install-recovery.sh"/>
         <copy file="bin/Superuser-release.apk" tofile="bin/recoveryzip/Superuser.apk"/>
 
         <exec executable="zip" failonerror="true" dir="bin/recoveryzip">
index 603a22d..daca273 100644 (file)
@@ -370,7 +370,6 @@ static int socket_send_request(int fd, const struct su_context *ctx) {
 do {                                                \
     size_t __len = htonl(data_len);                 \
     __len = write((fd), &__len, sizeof(__len));     \
-    LOGE("%d", __len);\
     if (__len != sizeof(__len)) {                   \
         PLOGE("write(" #data ")");                  \
         return -1;                                  \