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

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

MUST ONLY BE SUBMITTED BY AUTOMERGER

Change-Id: I53ebb973e11e87f4404d13089848b8115bbbee05
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];