Merge "camera3: Add opaque raw format."
diff --git a/debuggerd/crasher.c b/debuggerd/crasher.c
index 0033948..5a2bc3c 100644
--- a/debuggerd/crasher.c
+++ b/debuggerd/crasher.c
@@ -57,13 +57,13 @@
 
 static void *noisy(void *x)
 {
-    char c = (unsigned) x;
+    char c = (uintptr_t) x;
     for(;;) {
         usleep(250*1000);
         write(2, &c, 1);
         if(c == 'C') *((unsigned*) 0) = 42;
     }
-    return 0;
+    return NULL;
 }
 
 static int ctest()
@@ -81,7 +81,7 @@
 
 static void* thread_callback(void* raw_arg)
 {
-    return (void*) do_action((const char*) raw_arg);
+    return (void*) (uintptr_t) do_action((const char*) raw_arg);
 }
 
 static int do_action_on_thread(const char* arg)
@@ -90,7 +90,7 @@
     pthread_create(&t, NULL, thread_callback, (void*) arg);
     void* result = NULL;
     pthread_join(t, &result);
-    return (int) result;
+    return (int) (uintptr_t) result;
 }
 
 __attribute__((noinline)) static int crash3(int a) {
diff --git a/fastbootd/commands.c b/fastbootd/commands.c
index 063e1a6..98b7866 100644
--- a/fastbootd/commands.c
+++ b/fastbootd/commands.c
@@ -124,9 +124,9 @@
         goto error;
     }
 
-    kernel_ptr = (void *)((unsigned) ptr + hdr->page_size);
-    ramdisk_ptr = (void *)((unsigned) kernel_ptr + kernel_actual);
-    second_ptr = (void *)((unsigned) ramdisk_ptr + ramdisk_actual);
+    kernel_ptr = (void *)((uintptr_t) ptr + hdr->page_size);
+    ramdisk_ptr = (void *)((uintptr_t) kernel_ptr + kernel_actual);
+    second_ptr = (void *)((uintptr_t) ramdisk_ptr + ramdisk_actual);
 
     D(INFO, "preparing to boot");
     // Prepares boot physical address. Addresses from header are ignored
diff --git a/fastbootd/commands/boot.c b/fastbootd/commands/boot.c
index 8da9a28..922914b 100644
--- a/fastbootd/commands/boot.c
+++ b/fastbootd/commands/boot.c
@@ -89,10 +89,10 @@
  * Kernel address is not set into kernel_phys
  * Ramdisk is set to position relative to kernel
  */
-int prepare_boot_linux(unsigned kernel_phys, void *kernel_addr, int kernel_size,
-                       unsigned ramdisk_phys, void *ramdisk_addr, int ramdisk_size,
-                       unsigned second_phys, void *second_addr, int second_size,
-                       unsigned atags_phys, void *atags_addr, int atags_size) {
+int prepare_boot_linux(uintptr_t kernel_phys, void *kernel_addr, int kernel_size,
+                       uintptr_t ramdisk_phys, void *ramdisk_addr, int ramdisk_size,
+                       uintptr_t second_phys, void *second_addr, int second_size,
+                       uintptr_t atags_phys, void *atags_addr, int atags_size) {
     struct kexec_segment segment[4];
     int segment_count = 2;
     unsigned entry = START_ADDRESS + KEXEC_ARM_ZIMAGE_OFFSET;
diff --git a/fastbootd/commands/boot.h b/fastbootd/commands/boot.h
index 901c38a..a5efd01 100644
--- a/fastbootd/commands/boot.h
+++ b/fastbootd/commands/boot.h
@@ -40,8 +40,8 @@
 #define KEXEC_TYPE_DEFAULT 0
 #define KEXEC_TYPE_CRASH   1
 
-int prepare_boot_linux(unsigned, void *, int, unsigned, void *, int,
-                       unsigned, void *, int, unsigned, void *, int);
+int prepare_boot_linux(uintptr_t, void *, int, uintptr_t, void *, int,
+                       uintptr_t, void *, int, uintptr_t, void *, int);
 unsigned *create_atags(unsigned *, int, const struct boot_img_hdr *, int *);
 long kexec_load(unsigned int, unsigned long, struct kexec_segment *, unsigned long);
 char *read_atags(const char *, int *);
diff --git a/fastbootd/protocol.c b/fastbootd/protocol.c
index 0086b4a..3908020 100644
--- a/fastbootd/protocol.c
+++ b/fastbootd/protocol.c
@@ -142,7 +142,7 @@
     char response[64];
     ssize_t ret;
 
-    snprintf(response, 64, "DATA%08x", len);
+    snprintf(response, 64, "DATA%08zx", len);
     ret = protocol_handle_write(phandle, response, strlen(response));
     if (ret < 0)
         return;
diff --git a/include/private/android_filesystem_config.h b/include/private/android_filesystem_config.h
index e3568ae..20bfdbe 100644
--- a/include/private/android_filesystem_config.h
+++ b/include/private/android_filesystem_config.h
@@ -248,6 +248,7 @@
     { 00750, AID_ROOT,      AID_SHELL,     (1 << CAP_SETUID) | (1 << CAP_SETGID), "system/bin/run-as" },
 
     { 00750, AID_ROOT,      AID_ROOT,      0, "system/bin/uncrypt" },
+    { 00750, AID_ROOT,      AID_ROOT,      0, "system/bin/install-recovery.sh" },
     { 00755, AID_ROOT,      AID_SHELL,     0, "system/bin/*" },
     { 00755, AID_ROOT,      AID_ROOT,      0, "system/lib/valgrind/*" },
     { 00755, AID_ROOT,      AID_SHELL,     0, "system/xbin/*" },
diff --git a/liblog/tests/benchmark_main.cpp b/liblog/tests/benchmark_main.cpp
index 02df460..090394c 100644
--- a/liblog/tests/benchmark_main.cpp
+++ b/liblog/tests/benchmark_main.cpp
@@ -16,6 +16,7 @@
 
 #include <benchmark.h>
 
+#include <inttypes.h>
 #include <regex.h>
 #include <stdio.h>
 #include <stdlib.h>
@@ -158,10 +159,10 @@
     sdev = (sqrt((double)nXvariance) / gBenchmarkNum / gBenchmarkNum) + 0.5;
   }
   if (mean > (10000 * sdev)) {
-    printf("%-25s %10llu %10llu%s\n", full_name,
+    printf("%-25s %10" PRIu64 " %10" PRIu64 "%s\n", full_name,
             static_cast<uint64_t>(iterations), mean, throughput);
   } else {
-    printf("%-25s %10llu %10llu(\317\203%llu)%s\n", full_name,
+    printf("%-25s %10" PRIu64 " %10" PRIu64 "(\317\203%" PRIu64 ")%s\n", full_name,
            static_cast<uint64_t>(iterations), mean, sdev, throughput);
   }
   fflush(stdout);
diff --git a/liblog/tests/liblog_test.cpp b/liblog/tests/liblog_test.cpp
index 9ae8f22..d71d97a 100644
--- a/liblog/tests/liblog_test.cpp
+++ b/liblog/tests/liblog_test.cpp
@@ -15,6 +15,7 @@
  */
 
 #include <fcntl.h>
+#include <inttypes.h>
 #include <signal.h>
 #include <gtest/gtest.h>
 #include <log/log.h>
@@ -85,8 +86,8 @@
 
 static void* ConcurrentPrintFn(void *arg) {
     int ret = __android_log_buf_print(LOG_ID_MAIN, ANDROID_LOG_INFO,
-                                  "TEST__android_log_print", "Concurrent %d",
-                                  reinterpret_cast<int>(arg));
+                                  "TEST__android_log_print", "Concurrent %" PRIuPTR,
+                                  reinterpret_cast<uintptr_t>(arg));
     return reinterpret_cast<void*>(ret);
 }
 
@@ -106,8 +107,9 @@
     for (i=0; i < NUM_CONCURRENT; i++) {
         void* result;
         ASSERT_EQ(0, pthread_join(t[i], &result));
-        if ((0 == ret) && (0 != reinterpret_cast<int>(result))) {
-            ret = reinterpret_cast<int>(result);
+        int this_result = reinterpret_cast<uintptr_t>(result);
+        if ((0 == ret) && (0 != this_result)) {
+            ret = this_result;
         }
     }
     ASSERT_LT(0, ret);
diff --git a/libnl_2/Android.mk b/libnl_2/Android.mk
index deac9de..3721fc6 100644
--- a/libnl_2/Android.mk
+++ b/libnl_2/Android.mk
@@ -26,6 +26,7 @@
 # Static Library
 LOCAL_MODULE := libnl_2
 LOCAL_MODULE_TAGS := optional
+LOCAL_32_BIT_ONLY := true
 include $(BUILD_STATIC_LIBRARY)
 
 include $(CLEAR_VARS)
@@ -34,4 +35,5 @@
 LOCAL_SHARED_LIBRARIES:= liblog
 LOCAL_MODULE := libnl_2
 LOCAL_MODULE_TAGS := optional
+LOCAL_32_BIT_ONLY := true
 include $(BUILD_SHARED_LIBRARY)
diff --git a/rootdir/init.rc b/rootdir/init.rc
index dc260e6..51246fb 100644
--- a/rootdir/init.rc
+++ b/rootdir/init.rc
@@ -226,8 +226,12 @@
     restorecon_recursive /data/misc/zoneinfo
     mkdir /data/misc/vpn 0770 system vpn
     mkdir /data/misc/systemkeys 0700 system system
-    # give system access to wpa_supplicant.conf for backup and restore
     mkdir /data/misc/wifi 0770 wifi wifi
+    mkdir /data/misc/wifi/sockets 0770 wifi wifi
+    restorecon_recursive /data/misc/wifi/sockets
+    mkdir /data/misc/wifi/wpa_supplicant 0770 wifi wifi
+    mkdir /data/misc/dhcp 0770 dhcp dhcp
+    # give system access to wpa_supplicant.conf for backup and restore
     chmod 0660 /data/misc/wifi/wpa_supplicant.conf
     mkdir /data/local 0751 root root
     mkdir /data/misc/media 0700 media media
@@ -536,7 +540,7 @@
     class main
     socket installd stream 600 system system
 
-service flash_recovery /system/etc/install-recovery.sh
+service flash_recovery /system/bin/install-recovery.sh
     class main
     oneshot
 
diff --git a/sdcard/sdcard.c b/sdcard/sdcard.c
index 05fbfba..4722708 100644
--- a/sdcard/sdcard.c
+++ b/sdcard/sdcard.c
@@ -200,7 +200,7 @@
 }
 
 static int int_hash(void *key) {
-    return (int) key;
+    return (int) (uintptr_t) key;
 }
 
 static bool int_equals(void *keyA, void *keyB) {
@@ -487,7 +487,7 @@
         break;
     case PERM_ANDROID_DATA:
     case PERM_ANDROID_OBB:
-        appid = (appid_t) hashmapGet(fuse->package_to_appid, node->name);
+        appid = (appid_t) (uintptr_t) hashmapGet(fuse->package_to_appid, node->name);
         if (appid != 0) {
             node->uid = multiuser_get_uid(parent->userid, appid);
         }
@@ -511,7 +511,7 @@
     }
 
     appid_t appid = multiuser_get_app_id(hdr->uid);
-    return hashmapContainsKey(fuse->appid_with_rw, (void*) appid);
+    return hashmapContainsKey(fuse->appid_with_rw, (void*) (uintptr_t) appid);
 }
 
 /* Kernel has already enforced everything we returned through
@@ -1621,12 +1621,12 @@
 
         if (sscanf(buf, "%s %d %*d %*s %*s %s", package_name, &appid, gids) == 3) {
             char* package_name_dup = strdup(package_name);
-            hashmapPut(fuse->package_to_appid, package_name_dup, (void*) appid);
+            hashmapPut(fuse->package_to_appid, package_name_dup, (void*) (uintptr_t) appid);
 
             char* token = strtok(gids, ",");
             while (token != NULL) {
                 if (strtoul(token, NULL, 10) == fuse->write_gid) {
-                    hashmapPut(fuse->appid_with_rw, (void*) appid, (void*) 1);
+                    hashmapPut(fuse->appid_with_rw, (void*) (uintptr_t) appid, (void*) (uintptr_t) 1);
                     break;
                 }
                 token = strtok(NULL, ",");
diff --git a/toolbox/restorecon.c b/toolbox/restorecon.c
index f9f604f..137e9fa 100644
--- a/toolbox/restorecon.c
+++ b/toolbox/restorecon.c
@@ -2,76 +2,41 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <errno.h>
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <fts.h>
 #include <selinux/selinux.h>
-#include <selinux/label.h>
 #include <selinux/android.h>
 
-static struct selabel_handle *sehandle;
 static const char *progname;
-static int nochange;
-static int verbose;
 
 static void usage(void)
 {
-    fprintf(stderr, "usage:  %s [-nrRv] pathname...\n", progname);
+    fprintf(stderr, "usage:  %s [-FnrRv] pathname...\n", progname);
     exit(1);
 }
 
-static int restore(const char *pathname, const struct stat *sb)
-{
-    char *oldcontext, *newcontext;
-
-    if (lgetfilecon(pathname, &oldcontext) < 0) {
-        fprintf(stderr, "Could not get context of %s:  %s\n",
-                pathname, strerror(errno));
-        return -1;
-    }
-    if (selabel_lookup(sehandle, &newcontext, pathname, sb->st_mode) < 0) {
-        fprintf(stderr, "Could not lookup context for %s:  %s\n", pathname,
-                strerror(errno));
-        return -1;
-    }
-    if (strcmp(newcontext, "<<none>>") &&
-        strcmp(oldcontext, newcontext)) {
-        if (verbose)
-            printf("Relabeling %s from %s to %s.\n", pathname, oldcontext, newcontext);
-        if (!nochange) {
-            if (lsetfilecon(pathname, newcontext) < 0) {
-                fprintf(stderr, "Could not label %s with %s:  %s\n",
-                        pathname, newcontext, strerror(errno));
-                return -1;
-            }
-        }
-    }
-    freecon(oldcontext);
-    freecon(newcontext);
-    return 0;
-}
-
 int restorecon_main(int argc, char **argv)
 {
-    int ch, recurse = 0, ftsflags = FTS_PHYSICAL;
-    int i = 0;
+    int ch, i, rc;
+    unsigned int flags = 0;
 
     progname = argv[0];
 
     do {
-        ch = getopt(argc, argv, "nrRv");
+        ch = getopt(argc, argv, "FnrRv");
         if (ch == EOF)
             break;
         switch (ch) {
+        case 'F':
+            flags |= SELINUX_ANDROID_RESTORECON_FORCE;
+            break;
         case 'n':
-            nochange = 1;
+            flags |= SELINUX_ANDROID_RESTORECON_NOCHANGE;
             break;
         case 'r':
         case 'R':
-            recurse = 1;
+            flags |= SELINUX_ANDROID_RESTORECON_RECURSE;
             break;
         case 'v':
-            verbose = 1;
+            flags |= SELINUX_ANDROID_RESTORECON_VERBOSE;
             break;
         default:
             usage();
@@ -83,53 +48,11 @@
     if (!argc)
         usage();
 
-    sehandle = selinux_android_file_context_handle();
-
-    if (!sehandle) {
-        fprintf(stderr, "Could not load file_contexts:  %s\n",
-                strerror(errno));
-        return -1;
-    }
-
-    if (recurse) {
-        FTS *fts;
-        FTSENT *ftsent;
-        fts = fts_open(argv, ftsflags, NULL);
-        if (!fts) {
-            fprintf(stderr, "Could not traverse filesystems (first was %s):  %s\n",
-                    argv[0], strerror(errno));
-            return -1;
-        }
-        while ((ftsent = fts_read(fts))) {
-            switch (ftsent->fts_info) {
-            case FTS_DP:
-                break;
-            case FTS_DNR:
-            case FTS_ERR:
-            case FTS_NS:
-                fprintf(stderr, "Could not access %s:  %s\n", ftsent->fts_path,
-                        strerror(errno));
-                fts_set(fts, ftsent, FTS_SKIP);
-                break;
-            default:
-                if (restore(ftsent->fts_path, ftsent->fts_statp) < 0)
-                    fts_set(fts, ftsent, FTS_SKIP);
-                break;
-            }
-        }
-    } else {
-        int i, rc;
-        struct stat sb;
-
-        for (i = 0; i < argc; i++) {
-            rc = lstat(argv[i], &sb);
-            if (rc < 0) {
-                fprintf(stderr, "Could not stat %s:  %s\n", argv[i],
-                        strerror(errno));
-                continue;
-            }
-            restore(argv[i], &sb);
-        }
+    for (i = 0; i < argc; i++) {
+        rc = selinux_android_restorecon_flags(argv[i], flags);
+        if (rc < 0)
+            fprintf(stderr, "Could not restorecon %s:  %s\n", argv[i],
+                    strerror(errno));
     }
 
     return 0;