diff --git a/core/java/android/provider/MediaStore.java b/core/java/android/provider/MediaStore.java index aa774a6f0e865..23937d6c85a6e 100644 --- a/core/java/android/provider/MediaStore.java +++ b/core/java/android/provider/MediaStore.java @@ -3304,6 +3304,14 @@ public final class MediaStore { @TestApi public static @NonNull File getVolumePath(@NonNull String volumeName) throws FileNotFoundException { + final StorageManager sm = AppGlobals.getInitialApplication() + .getSystemService(StorageManager.class); + return getVolumePath(sm.getVolumes(), volumeName); + } + + /** {@hide} */ + public static @NonNull File getVolumePath(@NonNull List volumes, + @NonNull String volumeName) throws FileNotFoundException { if (TextUtils.isEmpty(volumeName)) { throw new IllegalArgumentException(); } @@ -3312,19 +3320,18 @@ public final class MediaStore { case VOLUME_INTERNAL: case VOLUME_EXTERNAL: throw new FileNotFoundException(volumeName + " has no associated path"); - case VOLUME_EXTERNAL_PRIMARY: - return Environment.getExternalStorageDirectory(); } - final StorageManager sm = AppGlobals.getInitialApplication() - .getSystemService(StorageManager.class); - for (VolumeInfo vi : sm.getVolumes()) { - if (Objects.equals(vi.getNormalizedFsUuid(), volumeName)) { - final File path = vi.getPathForUser(UserHandle.myUserId()); + final boolean wantPrimary = VOLUME_EXTERNAL_PRIMARY.equals(volumeName); + for (VolumeInfo volume : volumes) { + final boolean matchPrimary = wantPrimary + && volume.isPrimary(); + final boolean matchSecondary = !wantPrimary + && Objects.equals(volume.getNormalizedFsUuid(), volumeName); + if (matchPrimary || matchSecondary) { + final File path = volume.getPathForUser(UserHandle.myUserId()); if (path != null) { return path; - } else { - throw new FileNotFoundException("Failed to find path for " + vi); } } } diff --git a/core/res/AndroidManifest.xml b/core/res/AndroidManifest.xml index b634bb2a6e9ee..142e2a4e7a5d9 100644 --- a/core/res/AndroidManifest.xml +++ b/core/res/AndroidManifest.xml @@ -4434,7 +4434,7 @@ + android:protectionLevel="signature|privileged" /> - diff --git a/packages/SystemUI/AndroidManifest.xml b/packages/SystemUI/AndroidManifest.xml index 4b4912cb1e8a5..7db8969e2e042 100644 --- a/packages/SystemUI/AndroidManifest.xml +++ b/packages/SystemUI/AndroidManifest.xml @@ -222,9 +222,6 @@ - - -