DO NOT MERGE. Block adoptable storage when using FBE. am: 84be704af4
am: 1fbe38f424

Change-Id: I7331a05a5d40d8cf1d946971e86097e716580094
diff --git a/Android.mk b/Android.mk
index cabf9b3..4cd3dd0 100644
--- a/Android.mk
+++ b/Android.mk
@@ -51,6 +51,7 @@
 	liblogwrap \
 	libext4_utils \
 	libf2fs_sparseblock \
+	libcrypto_utils \
 	libcrypto \
 	libselinux \
 	libutils \
@@ -66,7 +67,6 @@
 	libfec_rs \
 	libsquashfs_utils \
 	libscrypt_static \
-	libmincrypt \
 	libbatteryservice \
 
 vold_conlyflags := -std=c11
diff --git a/Disk.cpp b/Disk.cpp
index 1e1a63e..6562d96 100644
--- a/Disk.cpp
+++ b/Disk.cpp
@@ -136,7 +136,7 @@
 }
 
 void Disk::listVolumes(VolumeBase::Type type, std::list<std::string>& list) {
-    for (auto vol : mVolumes) {
+    for (const auto& vol : mVolumes) {
         if (vol->getType() == type) {
             list.push_back(vol->getId());
         }
@@ -209,7 +209,7 @@
 }
 
 void Disk::destroyAllVolumes() {
-    for (auto vol : mVolumes) {
+    for (const auto& vol : mVolumes) {
         vol->destroy();
     }
     mVolumes.clear();
@@ -305,7 +305,7 @@
 
     Table table = Table::kUnknown;
     bool foundParts = false;
-    for (auto line : output) {
+    for (const auto& line : output) {
         char* cline = (char*) line.c_str();
         char* token = strtok(cline, kSgdiskToken);
         if (token == nullptr) continue;
@@ -370,7 +370,7 @@
 }
 
 status_t Disk::unmountAll() {
-    for (auto vol : mVolumes) {
+    for (const auto& vol : mVolumes) {
         vol->unmount();
     }
     return OK;
diff --git a/EmulatedVolume.h b/EmulatedVolume.h
index 09686c1..9b0c049 100644
--- a/EmulatedVolume.h
+++ b/EmulatedVolume.h
@@ -37,7 +37,7 @@
  */
 class EmulatedVolume : public VolumeBase {
 public:
-    EmulatedVolume(const std::string& rawPath);
+    explicit EmulatedVolume(const std::string& rawPath);
     EmulatedVolume(const std::string& rawPath, dev_t device, const std::string& fsUuid);
     virtual ~EmulatedVolume();
 
diff --git a/MoveTask.cpp b/MoveTask.cpp
index a0522d2..0a60c4e 100644
--- a/MoveTask.cpp
+++ b/MoveTask.cpp
@@ -27,7 +27,7 @@
 #include <dirent.h>
 #include <sys/wait.h>
 
-#define CONSTRAIN(amount, low, high) (amount < low ? low : (amount > high ? high : amount))
+#define CONSTRAIN(amount, low, high) ((amount) < (low) ? (low) : ((amount) > (high) ? (high) : (amount)))
 
 using android::base::StringPrintf;
 
diff --git a/NetlinkHandler.h b/NetlinkHandler.h
index 00a31c8..56eb23c 100644
--- a/NetlinkHandler.h
+++ b/NetlinkHandler.h
@@ -22,7 +22,7 @@
 class NetlinkHandler: public NetlinkListener {
 
 public:
-    NetlinkHandler(int listenerSocket);
+    explicit NetlinkHandler(int listenerSocket);
     virtual ~NetlinkHandler();
 
     int start(void);
diff --git a/TrimTask.cpp b/TrimTask.cpp
index d7bfda7..6c141f2 100644
--- a/TrimTask.cpp
+++ b/TrimTask.cpp
@@ -53,7 +53,7 @@
     VolumeManager* vm = VolumeManager::Instance();
     std::list<std::string> privateIds;
     vm->listVolumes(VolumeBase::Type::kPrivate, privateIds);
-    for (auto id : privateIds) {
+    for (const auto& id : privateIds) {
         auto vol = vm->findVolume(id);
         if (vol != nullptr && vol->getState() == VolumeBase::State::kMounted) {
             mPaths.push_back(vol->getPath());
@@ -114,7 +114,7 @@
 void TrimTask::run() {
     acquire_wake_lock(PARTIAL_WAKE_LOCK, kWakeLock);
 
-    for (auto path : mPaths) {
+    for (const auto& path : mPaths) {
         LOG(DEBUG) << "Starting trim of " << path;
 
         int fd = open(path.c_str(), O_RDONLY | O_DIRECTORY | O_CLOEXEC | O_NOFOLLOW);
diff --git a/TrimTask.h b/TrimTask.h
index 57be802..2ade7b5 100644
--- a/TrimTask.h
+++ b/TrimTask.h
@@ -27,7 +27,7 @@
 
 class TrimTask {
 public:
-    TrimTask(int flags);
+    explicit TrimTask(int flags);
     virtual ~TrimTask();
 
     enum Flags {
diff --git a/Utils.cpp b/Utils.cpp
index 014055b..17e9ffd 100644
--- a/Utils.cpp
+++ b/Utils.cpp
@@ -208,10 +208,10 @@
     }
 
     char value[128];
-    for (auto line : output) {
+    for (const auto& line : output) {
         // Extract values from blkid output, if defined
         const char* cline = line.c_str();
-        char* start = strstr(cline, "TYPE=");
+        const char* start = strstr(cline, "TYPE=");
         if (start != nullptr && sscanf(start + 5, "\"%127[^\"]\"", value) == 1) {
             fsType = value;
         }
diff --git a/VoldCommand.h b/VoldCommand.h
index 5ddc666..e435159 100644
--- a/VoldCommand.h
+++ b/VoldCommand.h
@@ -21,7 +21,7 @@
 
 class VoldCommand : public FrameworkCommand {
 public:
-    VoldCommand(const char *cmd);
+    explicit VoldCommand(const char *cmd);
     virtual ~VoldCommand() {}
 };
 
diff --git a/VolumeBase.cpp b/VolumeBase.cpp
index ea4d372..627feba 100644
--- a/VolumeBase.cpp
+++ b/VolumeBase.cpp
@@ -219,7 +219,7 @@
     }
 
     setState(State::kEjecting);
-    for (auto vol : mVolumes) {
+    for (const auto& vol : mVolumes) {
         if (vol->destroy()) {
             LOG(WARNING) << getId() << " failed to destroy " << vol->getId()
                     << " stacked above";
diff --git a/VolumeManager.cpp b/VolumeManager.cpp
index 5cc60a1..2085ca8 100644
--- a/VolumeManager.cpp
+++ b/VolumeManager.cpp
@@ -63,8 +63,8 @@
 
 #define MASS_STORAGE_FILE_PATH  "/sys/class/android_usb/android0/f_mass_storage/lun/file"
 
-#define ROUND_UP_POWER_OF_2(number, po2) (((!!(number & ((1U << po2) - 1))) << po2)\
-                                         + (number & (~((1U << po2) - 1))))
+#define ROUND_UP_POWER_OF_2(number, po2) (((!!((number) & ((1U << (po2)) - 1))) << (po2))\
+                                         + ((number) & (~((1U << (po2)) - 1))))
 
 using android::base::StringPrintf;
 
@@ -296,7 +296,7 @@
 
     switch (evt->getAction()) {
     case NetlinkEvent::Action::kAdd: {
-        for (auto source : mDiskSources) {
+        for (const auto& source : mDiskSources) {
             if (source->matches(eventPath)) {
                 // For now, assume that MMC and virtio-blk (the latter is
                 // emulator-specific; see Disk.cpp for details) devices are SD,
@@ -322,7 +322,7 @@
     }
     case NetlinkEvent::Action::kChange: {
         LOG(DEBUG) << "Disk at " << major << ":" << minor << " changed";
-        for (auto disk : mDisks) {
+        for (const auto& disk : mDisks) {
             if (disk->getDevice() == device) {
                 disk->readMetadata();
                 disk->readPartitions();
@@ -366,7 +366,7 @@
     if (mInternalEmulated->getId() == id) {
         return mInternalEmulated;
     }
-    for (auto disk : mDisks) {
+    for (const auto& disk : mDisks) {
         auto vol = disk->findVolume(id);
         if (vol != nullptr) {
             return vol;
@@ -378,7 +378,7 @@
 void VolumeManager::listVolumes(android::vold::VolumeBase::Type type,
         std::list<std::string>& list) {
     list.clear();
-    for (auto disk : mDisks) {
+    for (const auto& disk : mDisks) {
         disk->listVolumes(type, list);
     }
 }
@@ -497,7 +497,7 @@
     }
     endmntent(fp);
 
-    for (auto path : toUnmount) {
+    for (const auto& path : toUnmount) {
         if (umount2(path.c_str(), MNT_DETACH)) {
             ALOGW("Failed to unmount %s: %s", path.c_str(), strerror(errno));
         }
@@ -623,7 +623,7 @@
     // newly connected framework hears all events.
     mInternalEmulated->destroy();
     mInternalEmulated->create();
-    for (auto disk : mDisks) {
+    for (const auto& disk : mDisks) {
         disk->destroy();
         disk->create();
     }
@@ -634,7 +634,7 @@
 
 int VolumeManager::shutdown() {
     mInternalEmulated->destroy();
-    for (auto disk : mDisks) {
+    for (const auto& disk : mDisks) {
         disk->destroy();
     }
     mDisks.clear();
@@ -648,7 +648,7 @@
     if (mInternalEmulated != nullptr) {
         mInternalEmulated->unmount();
     }
-    for (auto disk : mDisks) {
+    for (const auto& disk : mDisks) {
         disk->unmountAll();
     }
 
@@ -672,7 +672,7 @@
     }
     endmntent(fp);
 
-    for (auto path : toUnmount) {
+    for (const auto& path : toUnmount) {
         SLOGW("Tearing down stale mount %s", path.c_str());
         android::vold::ForceUnmount(path);
     }
diff --git a/VolumeManager.h b/VolumeManager.h
index 39fc8f9..dd9f09d 100644
--- a/VolumeManager.h
+++ b/VolumeManager.h
@@ -217,7 +217,7 @@
 
 extern "C" {
 #endif /* __cplusplus */
-#define UNMOUNT_NOT_MOUNTED_ERR -2
+#define UNMOUNT_NOT_MOUNTED_ERR (-2)
     int vold_unmountAll(void);
 #ifdef __cplusplus
 }
diff --git a/cryptfs.h b/cryptfs.h
index 11d9bb7..bf158de 100644
--- a/cryptfs.h
+++ b/cryptfs.h
@@ -191,32 +191,32 @@
 /* Return values for cryptfs_crypto_complete */
 #define CRYPTO_COMPLETE_NOT_ENCRYPTED  1
 #define CRYPTO_COMPLETE_ENCRYPTED      0
-#define CRYPTO_COMPLETE_BAD_METADATA  -1
-#define CRYPTO_COMPLETE_PARTIAL       -2
-#define CRYPTO_COMPLETE_INCONSISTENT  -3
-#define CRYPTO_COMPLETE_CORRUPT       -4
+#define CRYPTO_COMPLETE_BAD_METADATA  (-1)
+#define CRYPTO_COMPLETE_PARTIAL       (-2)
+#define CRYPTO_COMPLETE_INCONSISTENT  (-3)
+#define CRYPTO_COMPLETE_CORRUPT       (-4)
 
 /* Return values for cryptfs_enable_inplace*() */
 #define ENABLE_INPLACE_OK 0
-#define ENABLE_INPLACE_ERR_OTHER -1
-#define ENABLE_INPLACE_ERR_DEV -2  /* crypto_blkdev issue */
+#define ENABLE_INPLACE_ERR_OTHER (-1)
+#define ENABLE_INPLACE_ERR_DEV (-2)  /* crypto_blkdev issue */
 
 /* Return values for cryptfs_getfield */
 #define CRYPTO_GETFIELD_OK                   0
-#define CRYPTO_GETFIELD_ERROR_NO_FIELD      -1
-#define CRYPTO_GETFIELD_ERROR_OTHER         -2
-#define CRYPTO_GETFIELD_ERROR_BUF_TOO_SMALL -3
+#define CRYPTO_GETFIELD_ERROR_NO_FIELD      (-1)
+#define CRYPTO_GETFIELD_ERROR_OTHER         (-2)
+#define CRYPTO_GETFIELD_ERROR_BUF_TOO_SMALL (-3)
 
 /* Return values for cryptfs_setfield */
 #define CRYPTO_SETFIELD_OK                    0
-#define CRYPTO_SETFIELD_ERROR_OTHER          -1
-#define CRYPTO_SETFIELD_ERROR_FIELD_TOO_LONG -2
-#define CRYPTO_SETFIELD_ERROR_VALUE_TOO_LONG -3
+#define CRYPTO_SETFIELD_ERROR_OTHER          (-1)
+#define CRYPTO_SETFIELD_ERROR_FIELD_TOO_LONG (-2)
+#define CRYPTO_SETFIELD_ERROR_VALUE_TOO_LONG (-3)
 
 /* Return values for persist_del_key */
 #define PERSIST_DEL_KEY_OK                 0
-#define PERSIST_DEL_KEY_ERROR_OTHER       -1
-#define PERSIST_DEL_KEY_ERROR_NO_FIELD    -2
+#define PERSIST_DEL_KEY_ERROR_OTHER       (-1)
+#define PERSIST_DEL_KEY_ERROR_NO_FIELD    (-2)
 
 #ifdef __cplusplus
 extern "C" {