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

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

Merge "Map MediaStore items to StorageVolume."

parents 9a8bcf5f f8fa9404
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -35683,6 +35683,7 @@ package android.os.storage {
    method public String getMountedObbPath(String);
    method @NonNull public android.os.storage.StorageVolume getPrimaryStorageVolume();
    method @Nullable public android.os.storage.StorageVolume getStorageVolume(java.io.File);
    method @NonNull public android.os.storage.StorageVolume getStorageVolume(@NonNull android.net.Uri);
    method @NonNull public java.util.List<android.os.storage.StorageVolume> getStorageVolumes();
    method @NonNull public java.util.UUID getUuidForPath(@NonNull java.io.File) throws java.io.IOException;
    method public boolean isAllocationSupported(@NonNull java.io.FileDescriptor);
+23 −1
Original line number Diff line number Diff line
@@ -38,6 +38,7 @@ import android.content.pm.IPackageMoveObserver;
import android.content.pm.PackageManager;
import android.content.res.ObbInfo;
import android.content.res.ObbScanner;
import android.net.Uri;
import android.os.Binder;
import android.os.Environment;
import android.os.FileUtils;
@@ -55,6 +56,7 @@ import android.os.RemoteException;
import android.os.ServiceManager;
import android.os.ServiceManager.ServiceNotFoundException;
import android.os.SystemProperties;
import android.provider.MediaStore;
import android.provider.Settings;
import android.sysprop.VoldProperties;
import android.system.ErrnoException;
@@ -1096,12 +1098,32 @@ public class StorageManager {
    }

    /**
     * Return the {@link StorageVolume} that contains the given file, or {@code null} if none.
     * Return the {@link StorageVolume} that contains the given file, or
     * {@code null} if none.
     */
    public @Nullable StorageVolume getStorageVolume(File file) {
        return getStorageVolume(getVolumeList(), file);
    }

    /**
     * Return the {@link StorageVolume} that contains the given
     * {@link MediaStore} item.
     */
    public @NonNull StorageVolume getStorageVolume(@NonNull Uri uri) {
        final String volumeName = MediaStore.getVolumeName(uri);
        switch (volumeName) {
            case MediaStore.VOLUME_EXTERNAL:
                return getPrimaryStorageVolume();
            default:
                for (StorageVolume vol : getStorageVolumes()) {
                    if (Objects.equals(vol.getNormalizedUuid(), volumeName)) {
                        return vol;
                    }
                }
        }
        throw new IllegalStateException("Unknown volume for " + uri);
    }

    /** {@hide} */
    public static @Nullable StorageVolume getStorageVolume(File file, int userId) {
        return getStorageVolume(getVolumeList(userId, 0), file);