Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 858b311c authored by Jeff Sharkey's avatar Jeff Sharkey
Browse files

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
parent d8dc4bcd
Loading
Loading
Loading
Loading
+14 −5
Original line number Diff line number Diff line
@@ -3166,20 +3166,29 @@ public final class MediaStore {

        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.
     */