Merge "Call setupAppDir before EnsureDirExists" am: d4de02ed14 am: f44cf21080 am: f1f587f28a

Original change: https://android-review.googlesource.com/c/platform/system/vold/+/1553602

MUST ONLY BE SUBMITTED BY AUTOMERGER

Change-Id: Ibc67fc45df3a5c9ec8946739531d51462736967f
diff --git a/VolumeManager.cpp b/VolumeManager.cpp
index ac7356c..f97397d 100644
--- a/VolumeManager.cpp
+++ b/VolumeManager.cpp
@@ -813,17 +813,18 @@
     }
 
     for (int i = 0; i < size; i++) {
-        auto status = EnsureDirExists(sources_cstr[i], 0771, AID_MEDIA_RW, AID_MEDIA_RW);
-        if (status != OK) {
-            PLOG(ERROR) << "Failed to create dir: " << sources_cstr[i];
-            return false;
-        }
         // Make sure /storage/emulated/... paths are setup correctly
-        status = setupAppDir(targets_cstr[i], uid, false /* fixupExistingOnly */);
+        // This needs to be done before EnsureDirExists to ensure Android/ is created.
+        auto status = setupAppDir(targets_cstr[i], uid, false /* fixupExistingOnly */);
         if (status != OK) {
             PLOG(ERROR) << "Failed to create dir: " << targets_cstr[i];
             return false;
         }
+        status = EnsureDirExists(sources_cstr[i], 0771, AID_MEDIA_RW, AID_MEDIA_RW);
+        if (status != OK) {
+            PLOG(ERROR) << "Failed to create dir: " << sources_cstr[i];
+            return false;
+        }
     }
 
     char android_data_dir[PATH_MAX];