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

Commit fd71805e authored by Jeff Sharkey's avatar Jeff Sharkey Committed by Android (Google) Code Review
Browse files

Merge "Support getStorageVolume() for synthetic volumes." into rvc-dev

parents 4d96602d 88818fe7
Loading
Loading
Loading
Loading
+14 −1
Original line number Diff line number Diff line
@@ -56,6 +56,7 @@ import android.content.pm.IPackageMoveObserver;
import android.content.pm.PackageManager;
import android.content.res.ObbInfo;
import android.content.res.ObbScanner;
import android.database.Cursor;
import android.net.Uri;
import android.os.Binder;
import android.os.Environment;
@@ -1201,7 +1202,19 @@ public class StorageManager {
     * {@link MediaStore} item.
     */
    public @NonNull StorageVolume getStorageVolume(@NonNull Uri uri) {
        final String volumeName = MediaStore.getVolumeName(uri);
        String volumeName = MediaStore.getVolumeName(uri);

        // When Uri is pointing at a synthetic volume, we're willing to query to
        // resolve the actual volume name
        if (Objects.equals(volumeName, MediaStore.VOLUME_EXTERNAL)) {
            try (Cursor c = mContext.getContentResolver().query(uri,
                    new String[] { MediaStore.MediaColumns.VOLUME_NAME }, null, null)) {
                if (c.moveToFirst()) {
                    volumeName = c.getString(0);
                }
            }
        }

        switch (volumeName) {
            case MediaStore.VOLUME_EXTERNAL_PRIMARY:
                return getPrimaryStorageVolume();