Move enabling sdcardfs behind a property am: f36bdddc7e am: 09daf93c62

Change-Id: Iaf328bd2731b680a0da9d66555c0ed7ea5b01b7a
diff --git a/Utils.cpp b/Utils.cpp
index b129990..15a5e49 100644
--- a/Utils.cpp
+++ b/Utils.cpp
@@ -132,7 +132,7 @@
 
 // Sets a default ACL on the directory.
 int SetDefaultAcl(const std::string& path, mode_t mode, uid_t uid, gid_t gid) {
-    if (IsFilesystemSupported("sdcardfs")) {
+    if (IsSdcardfsUsed()) {
         // sdcardfs magically takes care of this
         return OK;
     }
@@ -227,7 +227,7 @@
         return ret;
     }
 
-    if (!IsFilesystemSupported("sdcardfs")) {
+    if (!IsSdcardfsUsed()) {
         ret = SetQuotaProjectId(path, projectId);
     }
 
@@ -255,7 +255,7 @@
             return ret;
         }
 
-        if (!IsFilesystemSupported("sdcardfs")) {
+        if (!IsSdcardfsUsed()) {
             ret = SetQuotaProjectId(itEntry.path(), projectId);
             if (ret != 0) {
                 return ret;
@@ -271,6 +271,7 @@
     long projectId;
     size_t pos;
     int ret = 0;
+    bool sdcardfsSupport = IsSdcardfsUsed();
 
     // Make sure the Android/ directories exist and are setup correctly
     ret = PrepareAndroidDirs(root);
@@ -291,17 +292,17 @@
     // Check that the next part matches one of the allowed Android/ dirs
     if (StartsWith(pathFromRoot, kAppDataDir)) {
         appDir = kAppDataDir;
-        if (!IsFilesystemSupported("sdcardfs")) {
+        if (!sdcardfsSupport) {
             gid = AID_EXT_DATA_RW;
         }
     } else if (StartsWith(pathFromRoot, kAppMediaDir)) {
         appDir = kAppMediaDir;
-        if (!IsFilesystemSupported("sdcardfs")) {
+        if (!sdcardfsSupport) {
             gid = AID_MEDIA_RW;
         }
     } else if (StartsWith(pathFromRoot, kAppObbDir)) {
         appDir = kAppObbDir;
-        if (!IsFilesystemSupported("sdcardfs")) {
+        if (!sdcardfsSupport) {
             gid = AID_EXT_OBB_RW;
         }
     } else {
@@ -368,7 +369,7 @@
                 return ret;
             }
 
-            if (!IsFilesystemSupported("sdcardfs")) {
+            if (!sdcardfsSupport) {
                 // Set project ID inheritance, so that future subdirectories inherit the
                 // same project ID
                 ret = SetQuotaInherit(pathToCreate);
@@ -943,6 +944,11 @@
     return supported.find(fsType + "\n") != std::string::npos;
 }
 
+bool IsSdcardfsUsed() {
+    return IsFilesystemSupported("sdcardfs") &&
+           base::GetBoolProperty(kExternalStorageSdcardfs, true);
+}
+
 status_t WipeBlockDevice(const std::string& path) {
     status_t res = -1;
     const char* c_path = path.c_str();
@@ -1426,7 +1432,7 @@
         return -errno;
     }
 
-    if (IsFilesystemSupported("sdcardfs")) {
+    if (IsSdcardfsUsed()) {
         std::string sdcardfs_path(
                 StringPrintf("/mnt/runtime/full/%s", relative_upper_path.c_str()));
 
@@ -1478,7 +1484,7 @@
     std::string androidObbDir = volumeRoot + kAppObbDir;
     std::string androidMediaDir = volumeRoot + kAppMediaDir;
 
-    bool useSdcardFs = IsFilesystemSupported("sdcardfs");
+    bool useSdcardFs = IsSdcardfsUsed();
 
     // mode 0771 + sticky bit for inheriting GIDs
     mode_t mode = S_IRWXU | S_IRWXG | S_IXOTH | S_ISGID;
diff --git a/Utils.h b/Utils.h
index e04dcaa..eac3cf4 100644
--- a/Utils.h
+++ b/Utils.h
@@ -36,6 +36,7 @@
 
 static const char* kPropFuse = "persist.sys.fuse";
 static const char* kVoldAppDataIsolationEnabled = "persist.sys.vold_app_data_isolation_enabled";
+static const char* kExternalStorageSdcardfs = "external_storage.sdcardfs.enabled";
 
 /* SELinux contexts used depending on the block device type */
 extern security_context_t sBlkidContext;
@@ -124,6 +125,7 @@
 uint64_t GetTreeBytes(const std::string& path);
 
 bool IsFilesystemSupported(const std::string& fsType);
+bool IsSdcardfsUsed();
 bool IsFuseDaemon(const pid_t pid);
 
 /* Wipes contents of block device at given path */
diff --git a/VolumeManager.cpp b/VolumeManager.cpp
index f64f5f6..f42f3e7 100644
--- a/VolumeManager.cpp
+++ b/VolumeManager.cpp
@@ -83,6 +83,7 @@
 using android::vold::DeleteDirContentsAndDir;
 using android::vold::EnsureDirExists;
 using android::vold::IsFilesystemSupported;
+using android::vold::IsSdcardfsUsed;
 using android::vold::IsVirtioBlkDevice;
 using android::vold::PrepareAndroidDirs;
 using android::vold::PrepareAppDirFromRoot;
@@ -780,7 +781,7 @@
 
 static std::string getStorageDirSrc(userid_t userId, const std::string& dirName,
         const std::string& packageName) {
-    if (IsFilesystemSupported("sdcardfs")) {
+    if (IsSdcardfsUsed()) {
         return StringPrintf("/mnt/runtime/default/emulated/%d/%s/%s",
                 userId, dirName.c_str(), packageName.c_str());
     } else {
@@ -1049,7 +1050,7 @@
 }
 
 int VolumeManager::fixupAppDir(const std::string& path, int32_t appUid) {
-    if (IsFilesystemSupported("sdcardfs")) {
+    if (IsSdcardfsUsed()) {
         //sdcardfs magically does this for us
         return OK;
     }
diff --git a/model/EmulatedVolume.cpp b/model/EmulatedVolume.cpp
index e7cd36e..bb5aa86 100644
--- a/model/EmulatedVolume.cpp
+++ b/model/EmulatedVolume.cpp
@@ -49,7 +49,7 @@
     mRawPath = rawPath;
     mLabel = "emulated";
     mFuseMounted = false;
-    mUseSdcardFs = IsFilesystemSupported("sdcardfs");
+    mUseSdcardFs = IsSdcardfsUsed();
     mAppDataIsolationEnabled = base::GetBoolProperty(kVoldAppDataIsolationEnabled, false);
 }
 
@@ -60,7 +60,7 @@
     mRawPath = rawPath;
     mLabel = fsUuid;
     mFuseMounted = false;
-    mUseSdcardFs = IsFilesystemSupported("sdcardfs");
+    mUseSdcardFs = IsSdcardfsUsed();
     mAppDataIsolationEnabled = base::GetBoolProperty(kVoldAppDataIsolationEnabled, false);
 }
 
diff --git a/model/PublicVolume.cpp b/model/PublicVolume.cpp
index a0b3227..6195482 100644
--- a/model/PublicVolume.cpp
+++ b/model/PublicVolume.cpp
@@ -51,7 +51,7 @@
     setId(StringPrintf("public:%u,%u", major(device), minor(device)));
     mDevPath = StringPrintf("/dev/block/vold/%s", getId().c_str());
     mFuseMounted = false;
-    mUseSdcardFs = IsFilesystemSupported("sdcardfs");
+    mUseSdcardFs = IsSdcardfsUsed();
 }
 
 PublicVolume::~PublicVolume() {}