diff options
Diffstat (limited to 'apex')
-rw-r--r-- | apex/framework/java/android/provider/MediaStore.java | 46 |
1 files changed, 45 insertions, 1 deletions
diff --git a/apex/framework/java/android/provider/MediaStore.java b/apex/framework/java/android/provider/MediaStore.java index 3c25ef22b..b528bf649 100644 --- a/apex/framework/java/android/provider/MediaStore.java +++ b/apex/framework/java/android/provider/MediaStore.java @@ -32,6 +32,7 @@ import android.annotation.WorkerThread; import android.app.Activity; import android.app.AppOpsManager; import android.app.PendingIntent; +import android.app.compat.CompatChanges; import android.compat.annotation.UnsupportedAppUsage; import android.content.ClipData; import android.content.ContentProvider; @@ -61,6 +62,7 @@ import android.os.Bundle; import android.os.CancellationSignal; import android.os.Environment; import android.os.OperationCanceledException; +import android.os.Parcel; import android.os.ParcelFileDescriptor; import android.os.Parcelable; import android.os.RemoteException; @@ -663,6 +665,11 @@ public final class MediaStore { public static final String INTENT_ACTION_VIDEO_CAMERA = "android.media.action.VIDEO_CAMERA"; /** + * This is a copy of the flag that exists in MediaProvider. + */ + static final long EXCLUDE_UNRELIABLE_STORAGE_VOLUMES = 391360514L; + + /** * Standard Intent action that can be sent to have the camera application * capture an image and return it. * <p> @@ -1559,6 +1566,11 @@ public final class MediaStore { * once obtained you can directly {@link ContentResolver#update} columns * like {@link MediaColumns#IS_FAVORITE}, {@link MediaColumns#IS_TRASHED}, * or {@link ContentResolver#delete}. + * <p> + * Note: if your app targets {@link android.os.Build.VERSION_CODES#BAKLAVA} + * and above, you can send a maximum of 2000 uris in each request. + * Attempting to send more than 2000 uris will result in a + * {@link java.lang.IllegalArgumentException}. * * @param resolver Used to connect with {@link MediaStore#AUTHORITY}. * Typically this value is {@link Context#getContentResolver()}, @@ -1591,6 +1603,11 @@ public final class MediaStore { * determine if you already hold write access before requesting access, use * {@link Context#checkUriPermission(Uri, int, int, int)} with * {@link Intent#FLAG_GRANT_WRITE_URI_PERMISSION}. + * <p> + * Note: if your app targets {@link android.os.Build.VERSION_CODES#BAKLAVA} + * and above, you can send a maximum of 2000 uris in each request. + * Attempting to send more than 2000 uris will result in a + * {@link java.lang.IllegalArgumentException}. * * @param resolver Used to connect with {@link MediaStore#AUTHORITY}. * Typically this value is {@link Context#getContentResolver()}, @@ -1632,6 +1649,11 @@ public final class MediaStore { * determine if you already hold write access before requesting access, use * {@link Context#checkUriPermission(Uri, int, int, int)} with * {@link Intent#FLAG_GRANT_WRITE_URI_PERMISSION}. + * <p> + * Note: if your app targets {@link android.os.Build.VERSION_CODES#BAKLAVA} + * and above, you can send a maximum of 2000 uris in each request. + * Attempting to send more than 2000 uris will result in a + * {@link java.lang.IllegalArgumentException}. * * @param resolver Used to connect with {@link MediaStore#AUTHORITY}. * Typically this value is {@link Context#getContentResolver()}, @@ -1712,6 +1734,11 @@ public final class MediaStore { * determine if you already hold write access before requesting access, use * {@link Context#checkUriPermission(Uri, int, int, int)} with * {@link Intent#FLAG_GRANT_WRITE_URI_PERMISSION}. + * <p> + * Note: if your app targets {@link android.os.Build.VERSION_CODES#BAKLAVA} + * and above, you can send a maximum of 2000 uris in each request. + * Attempting to send more than 2000 uris will result in a + * {@link java.lang.IllegalArgumentException}. * * @param resolver Used to connect with {@link MediaStore#AUTHORITY}. * Typically this value is {@link Context#getContentResolver()}, @@ -4714,7 +4741,15 @@ public final class MediaStore { case Environment.MEDIA_MOUNTED_READ_ONLY: { final String volumeName = sv.getMediaStoreVolumeName(); if (volumeName != null) { - res.add(volumeName); + File directory = sv.getDirectory(); + if (shouldExcludeUnReliableStorageVolumes(context) + && directory != null + && directory.getAbsolutePath() != null + && directory.getAbsolutePath().startsWith("/mnt/")) { + Log.d(TAG, "skipping unreliable volume : " + volumeName); + } else { + res.add(volumeName); + } } break; } @@ -4724,6 +4759,15 @@ public final class MediaStore { } /** + * Checks if the EXCLUDE_UNRELIABLE_STORAGE_VOLUMES appcompat flag is enabled. + */ + private static boolean shouldExcludeUnReliableStorageVolumes(Context context) { + return Flags.excludeUnreliableVolumes() + && CompatChanges.isChangeEnabled( + EXCLUDE_UNRELIABLE_STORAGE_VOLUMES, context.getApplicationInfo().uid); + } + + /** * Works exactly the same as * {@link ContentResolver#openFileDescriptor(Uri, String, CancellationSignal)}, but only works * for {@link Uri} whose scheme is {@link ContentResolver#SCHEME_CONTENT} and its authority is |