Add self/primary symlink on /mnt/pass_through
We bind mount /mnt/user/<userid> onto /storage for normal apps and
/mnt/pass_through/<userid> for special apps like the FUSE daemon or
the old android.process.media hosting the DownloadManager. This bind
mount allows app have /storage/self/primary which is what /sdcard
symlinks to.
Before this change, we were not creating the self/primary symlink on
/mnt/pass_through/<userid> so trying to access /sdcard from the
DownloadManager would fail.
Bug: 135341433
Test: atest android.app.cts.DownloadManagerTest#testAddCompletedDownload_invalidPaths
Change-Id: I660139be3d850e6e9ea4705f86ef2b5872ddca16
diff --git a/Utils.cpp b/Utils.cpp
index 46272f6..a798b27 100644
--- a/Utils.cpp
+++ b/Utils.cpp
@@ -1056,8 +1056,16 @@
return -1;
}
linkpath += "/primary";
-
Symlink(fuse_path + "/" + std::to_string(user_id), linkpath);
+
+ std::string pass_through_linkpath(StringPrintf("/mnt/pass_through/%d/self", user_id));
+ result = PrepareDir(pass_through_linkpath, 0755, AID_ROOT, AID_ROOT);
+ if (result != android::OK) {
+ PLOG(ERROR) << "Failed to prepare directory " << pass_through_linkpath;
+ return -1;
+ }
+ pass_through_linkpath += "/primary";
+ Symlink(pass_through_path + "/" + std::to_string(user_id), pass_through_linkpath);
}
// Open fuse fd.