diff --git a/api/current.txt b/api/current.txt index 429674c46438a..bb7b45df59c4b 100644 --- a/api/current.txt +++ b/api/current.txt @@ -29584,6 +29584,7 @@ package android.os.storage { public class StorageManager { method public java.lang.String getMountedObbPath(java.lang.String); method public android.os.storage.StorageVolume getPrimaryStorageVolume(); + method public android.os.storage.StorageVolume getStorageVolume(java.io.File); method public java.util.List getStorageVolumes(); method public boolean isEncrypted(java.io.File); method public boolean isObbMounted(java.lang.String); diff --git a/api/system-current.txt b/api/system-current.txt index befff23a14041..c8f6ba7724e4c 100644 --- a/api/system-current.txt +++ b/api/system-current.txt @@ -31890,6 +31890,7 @@ package android.os.storage { public class StorageManager { method public java.lang.String getMountedObbPath(java.lang.String); method public android.os.storage.StorageVolume getPrimaryStorageVolume(); + method public android.os.storage.StorageVolume getStorageVolume(java.io.File); method public java.util.List getStorageVolumes(); method public boolean isEncrypted(java.io.File); method public boolean isObbMounted(java.lang.String); diff --git a/api/test-current.txt b/api/test-current.txt index d39e0b76a0083..19d43f260091d 100644 --- a/api/test-current.txt +++ b/api/test-current.txt @@ -29653,6 +29653,7 @@ package android.os.storage { public class StorageManager { method public java.lang.String getMountedObbPath(java.lang.String); method public android.os.storage.StorageVolume getPrimaryStorageVolume(); + method public android.os.storage.StorageVolume getStorageVolume(java.io.File); method public java.util.List getStorageVolumes(); method public boolean isEncrypted(java.io.File); method public boolean isObbMounted(java.lang.String); diff --git a/core/java/android/os/storage/StorageManager.java b/core/java/android/os/storage/StorageManager.java index ece12280bb803..da215c61641a2 100644 --- a/core/java/android/os/storage/StorageManager.java +++ b/core/java/android/os/storage/StorageManager.java @@ -824,7 +824,9 @@ public class StorageManager { } } - /** {@hide} */ + /** + * Return the {@link StorageVolume} that contains the given file, or {@code null} if none. + */ public @Nullable StorageVolume getStorageVolume(File file) { return getStorageVolume(getVolumeList(), file); } @@ -836,9 +838,13 @@ public class StorageManager { /** {@hide} */ private static @Nullable StorageVolume getStorageVolume(StorageVolume[] volumes, File file) { + if (file == null) { + return null; + } try { file = file.getCanonicalFile(); } catch (IOException ignored) { + Slog.d(TAG, "Could not get canonical path for " + file); return null; } for (StorageVolume volume : volumes) {