diff options
| author | 2019-02-18 13:23:51 -0700 | |
|---|---|---|
| committer | 2019-02-18 20:38:07 +0000 | |
| commit | f8fa9404054d30091bb0cc6b4a0302416ca11a3c (patch) | |
| tree | a1329150e9ce858afea248a5d21a6dbd30c765cb | |
| parent | 2022cbf43c4607b6bd7c961e05b8d11ed2a076a0 (diff) | |
Map MediaStore items to StorageVolume.
Add missing getStorageVolume() method to provide mapping from Uri
to underlying StorageVolume.
Bug: 124013019
Test: atest cts/tests/tests/provider/src/android/provider/cts/MediaStore*
Change-Id: I91e246d29629eec84956ff113ef976e153fc69f7
| -rw-r--r-- | api/current.txt | 1 | ||||
| -rw-r--r-- | core/java/android/os/storage/StorageManager.java | 24 |
2 files changed, 24 insertions, 1 deletions
diff --git a/api/current.txt b/api/current.txt index 1c60efa62be3..01890c8c1497 100644 --- a/api/current.txt +++ b/api/current.txt @@ -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); diff --git a/core/java/android/os/storage/StorageManager.java b/core/java/android/os/storage/StorageManager.java index 43c906495cb6..15aaa946e602 100644 --- a/core/java/android/os/storage/StorageManager.java +++ b/core/java/android/os/storage/StorageManager.java @@ -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); |