Resolve symlinks when listing scan paths.
Some paths like /product might be symlinks to /system/product.
Bug: 124070462, 124074176, 124074218, 124074430
Test: atest CtsMediaTestCases
Change-Id: Ic0aa388f385d13a124ae170686dea18e716016e0
diff --git a/core/java/android/provider/MediaStore.java b/core/java/android/provider/MediaStore.java
index 2a04dfc..0b38420 100644
--- a/core/java/android/provider/MediaStore.java
+++ b/core/java/android/provider/MediaStore.java
@@ -3166,20 +3166,29 @@
final ArrayList<File> res = new ArrayList<>();
if (VOLUME_INTERNAL.equals(volumeName)) {
- res.add(new File(Environment.getRootDirectory(), "media"));
- res.add(new File(Environment.getOemDirectory(), "media"));
- res.add(new File(Environment.getProductDirectory(), "media"));
+ addCanoncialFile(res, new File(Environment.getRootDirectory(), "media"));
+ addCanoncialFile(res, new File(Environment.getOemDirectory(), "media"));
+ addCanoncialFile(res, new File(Environment.getProductDirectory(), "media"));
} else {
- res.add(getVolumePath(volumeName));
+ addCanoncialFile(res, getVolumePath(volumeName));
final UserManager um = AppGlobals.getInitialApplication()
.getSystemService(UserManager.class);
if (VOLUME_EXTERNAL.equals(volumeName) && um.isDemoUser()) {
- res.add(Environment.getDataPreloadsMediaDirectory());
+ addCanoncialFile(res, Environment.getDataPreloadsMediaDirectory());
}
}
return res;
}
+ private static void addCanoncialFile(List<File> list, File file) {
+ try {
+ list.add(file.getCanonicalFile());
+ } catch (IOException e) {
+ Log.w(TAG, "Failed to resolve " + file + ": " + e);
+ list.add(file);
+ }
+ }
+
/**
* Uri for querying the state of the media scanner.
*/