Move enabling sdcardfs behind a property

This allows devices that have sdcardfs enabled in the kernel to not use
it. When external_storage.sdcardfs.enabled=0, sdcardfs will not be
mounted. This is treated as default true to not affect upgrading
devices. It does not use the old ro.sys.sdcardfs as that has been
repurposed over time and no longer can be relied on to turn off
sdcardfs. This is included within emulated_storage.mk

Bug: 155222498
Test: mount|grep "type sdcardfs" should find nothing after boot complete
      if external_storage.sdcardfs.enabled=0
Change-Id: I23d75fb1225aeabbcb1a035ad62fd042b6b3c7b5
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;