Merge "Port to binder based keymaster hal"
diff --git a/Android.mk b/Android.mk
index 5ddeda1..1e20215 100644
--- a/Android.mk
+++ b/Android.mk
@@ -67,6 +67,7 @@
 	libsquashfs_utils \
 	libscrypt_static \
 	libbatteryservice \
+	libavb \
 
 vold_conlyflags := -std=c11
 vold_cflags := -Werror -Wall -Wno-missing-field-initializers -Wno-unused-variable -Wno-unused-parameter
diff --git a/CommandListener.cpp b/CommandListener.cpp
index b548a91..a312af2 100644
--- a/CommandListener.cpp
+++ b/CommandListener.cpp
@@ -703,8 +703,9 @@
             PLOG(ERROR) << "Failed to stat /proc/" << pid;
             return -errno;
         }
-        if (sb.st_uid != uid) {
-            LOG(ERROR) << "Mismatch UID expected=" << uid << ", actual=" << sb.st_uid;
+        if (sb.st_uid != AID_SYSTEM) {
+            LOG(ERROR) << "Only system can mount appfuse. UID expected=" << AID_SYSTEM
+                    << ", actual=" << sb.st_uid;
             return -EPERM;
         }
     }
diff --git a/main.cpp b/main.cpp
index 9cbcf88..68477ac 100644
--- a/main.cpp
+++ b/main.cpp
@@ -39,7 +39,7 @@
 #include <dirent.h>
 #include <fs_mgr.h>
 
-static int process_config(VolumeManager *vm);
+static int process_config(VolumeManager *vm, bool* has_adoptable);
 static void coldboot(const char *path);
 static void parse_args(int argc, char** argv);
 
@@ -106,7 +106,9 @@
         exit(1);
     }
 
-    if (process_config(vm)) {
+    bool has_adoptable;
+
+    if (process_config(vm, &has_adoptable)) {
         PLOG(ERROR) << "Error reading configuration... continuing anyways";
     }
 
@@ -131,6 +133,10 @@
         exit(1);
     }
 
+    // This call should go after listeners are started to avoid
+    // a deadlock between vold and init (see b/34278978 for details)
+    property_set("vold.has_adoptable", has_adoptable ? "1" : "0");
+
     // Eventually we'll become the monitoring thread
     while(1) {
         sleep(1000);
@@ -207,7 +213,7 @@
     }
 }
 
-static int process_config(VolumeManager *vm) {
+static int process_config(VolumeManager *vm, bool* has_adoptable) {
     std::string path(android::vold::DefaultFstabPath());
     fstab = fs_mgr_read_fstab(path.c_str());
     if (!fstab) {
@@ -216,7 +222,7 @@
     }
 
     /* Loop through entries looking for ones that vold manages */
-    bool has_adoptable = false;
+    *has_adoptable = false;
     for (int i = 0; i < fstab->num_entries; i++) {
         if (fs_mgr_is_voldmanaged(&fstab->recs[i])) {
             if (fs_mgr_is_nonremovable(&fstab->recs[i])) {
@@ -230,7 +236,7 @@
 
             if (fs_mgr_is_encryptable(&fstab->recs[i])) {
                 flags |= android::vold::Disk::Flags::kAdoptable;
-                has_adoptable = true;
+                *has_adoptable = true;
             }
             if (fs_mgr_is_noemulatedsd(&fstab->recs[i])
                     || property_get_bool("vold.debug.default_primary", false)) {
@@ -241,6 +247,5 @@
                     new VolumeManager::DiskSource(sysPattern, nickname, flags)));
         }
     }
-    property_set("vold.has_adoptable", has_adoptable ? "1" : "0");
     return 0;
 }