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

Commit 50e73370 authored by Zim's avatar Zim
Browse files

Fix canonicalizing /sdcard

We now transform the realpath of /sdcard with FUSE mounts from
/mnt/user/<userid>/emulated/<userid> to
realpath of /storage/emulated/<userid> which is what is expected
without FUSE when matching with VolumeInfo#path.

Test: atest
android.os.storage.cts.StorageManagerTest#testGetExternalUuidForPath
Bug: 135341433

Change-Id: I8ffe8ac7109329d360fe18ce3e6ed227672b77bc
parent f8ac43ed
Loading
Loading
Loading
Loading
+8 −1
Original line number Diff line number Diff line
@@ -829,7 +829,14 @@ public class StorageManager {
     */
    public @NonNull UUID getUuidForPath(@NonNull File path) throws IOException {
        Preconditions.checkNotNull(path);
        final String pathString = path.getCanonicalPath();
        String pathString = path.getCanonicalPath();
        if (path.getPath().startsWith("/sdcard")) {
            // On FUSE enabled devices, realpath(2) /sdcard is /mnt/user/<userid>/emulated/<userid>
            // as opposed to /storage/emulated/<userid>.
            // And vol.path below expects to match with a path starting with /storage
            pathString = pathString.replaceFirst("^/mnt/user/[0-9]+/", "/storage/");
        }

        if (FileUtils.contains(Environment.getDataDirectory().getAbsolutePath(), pathString)) {
            return UUID_DEFAULT;
        }