goldfish: fix selinux denials from qemu-props

This cl fixes qemu-props to work around the limitation brought
upon by PRODUCT_COMPATIBLE_PROPERTY_OVERRIDE := true, since many
system properties (such as bootcomplete) cannot be read/set anmore

Some properties are there for historical reason and they are kept
unchanged.

BUG: 109872686
this cl only impact emulator images

Change-Id: I8b5e43dbcf840966cb6d90ccaeae5ec50adbb5af
diff --git a/init.ranchu.rc b/init.ranchu.rc
index e654dc6..2193c58 100644
--- a/init.ranchu.rc
+++ b/init.ranchu.rc
@@ -27,6 +27,8 @@
 
     setprop wifi.interface wlan0
 
+    start goldfish-logcat
+
 
 service ranchu-setup /vendor/bin/init.ranchu-core.sh
     class core
@@ -34,12 +36,15 @@
     group root
     oneshot
 
-on property:qemu.timezone=*
-    setprop persist.sys.timezone ${qemu.timezone}
+on property:vendor.qemu.timezone=*
+    setprop persist.sys.timezone ${vendor.qemu.timezone}
 
 on property:vendor.qemu.android.bootanim=0
     setprop debug.sf.nobootanimation 1
 
+on property:dev.bootcomplete=1
+    setprop vendor.qemu.dev.bootcomplete 1
+
 service ranchu-net /vendor/bin/init.ranchu-net.sh
     class late_start
     user root
@@ -83,9 +88,6 @@
     group root
     oneshot
 
-on property:qemu.logcat=start
-    start goldfish-logcat
-
 # -Q is a special logcat option that forces the
 # program to check wether it runs on the emulator
 # if it does, it redirects its output to the device
diff --git a/qemu-props/qemu-props.c b/qemu-props/qemu-props.c
index e54c2d5..e1b8ae7 100644
--- a/qemu-props/qemu-props.c
+++ b/qemu-props/qemu-props.c
@@ -27,7 +27,7 @@
 #define DEBUG  1
 
 #if DEBUG
-#  include <cutils/log.h>
+#  include <log/log.h>
 #  define  DD(...)    ALOGI(__VA_ARGS__)
 #else
 #  define  DD(...)    ((void)0)
@@ -88,6 +88,7 @@
         DD("receiving..");
         char* q;
         char  temp[BUFF_SIZE];
+        char  vendortemp[BUFF_SIZE];
         int   len = qemud_channel_recv(qemud_fd, temp, sizeof temp - 1);
 
         /* lone NUL-byte signals end of properties */
@@ -106,9 +107,25 @@
         }
         *q++ = '\0';
 
-        if (property_set(temp, q) < 0) {
-            DD("could not set property '%s' to '%s'", temp, q);
+        char* final_prop_name = NULL;
+        if (strcmp(temp, "qemu.sf.lcd.density") == 0 ) {
+            final_prop_name = temp;
+        } else if (strcmp(temp, "qemu.hw.mainkeys") == 0 ) {
+            final_prop_name = temp;
+        } else if (strcmp(temp, "qemu.cmdline") == 0 ) {
+            final_prop_name = temp;
+        } else if (strcmp(temp, "dalvik.vm.heapsize") == 0 ) {
+            continue; /* cannot set it here */
+        } else if (strcmp(temp, "ro.opengles.version") == 0 ) {
+            continue; /* cannot set it here */
         } else {
+            snprintf(vendortemp, sizeof(vendortemp), "vendor.%s", temp);
+            final_prop_name = vendortemp;
+        }
+        if (property_set(temp, q) < 0) {
+            ALOGW("could not set property '%s' to '%s'", final_prop_name, q);
+        } else {
+            ALOGI("successfully set property '%s' to '%s'", final_prop_name, q);
             count += 1;
         }
     }
@@ -116,20 +133,15 @@
     char temp[BUFF_SIZE];
     for (;;) {
         usleep(5000000); /* 5 seconds */
-        property_get("sys.boot_completed", temp, "");
+        property_get("vendor.qemu.dev.bootcomplete", temp, "");
         int is_boot_completed = (strncmp(temp, "1", 1) == 0) ? 1 : 0;
         if (is_boot_completed) {
+            ALOGI("tell the host boot completed");
             notifyHostBootComplete();
             break;
         }
     }
 
-    /* HACK start adbd periodically every minute, if adbd is already running, this is a no-op */
-    for(;;) {
-        usleep(60000000); /* 1 minute */
-        property_set("qemu.adbd", "start");
-    }
-
     /* finally, close the channel and exit */
     if (s_QemuMiscPipe >= 0) {
         close(s_QemuMiscPipe);
@@ -153,7 +165,7 @@
     WriteFully(s_QemuMiscPipe, &pipe_command_length, sizeof(pipe_command_length));
     WriteFully(s_QemuMiscPipe, set, pipe_command_length);
     ReadFully(s_QemuMiscPipe, &pipe_command_length, sizeof(pipe_command_length));
-    if (pipe_command_length > sizeof(set) || pipe_command_length <= 0)
+    if (pipe_command_length > (int)(sizeof(set)) || pipe_command_length <= 0)
         return;
     ReadFully(s_QemuMiscPipe, set, pipe_command_length);
 }