diff options
author | 2024-09-24 17:09:30 +0000 | |
---|---|---|
committer | 2024-11-04 06:40:53 +0000 | |
commit | c863d5686f0c7edb33cb95d5ae06c307225e77bf (patch) | |
tree | ce5d42bd1a569386d61c4dcbaae1a389855e4594 /apex | |
parent | bea932735f37f95802322fa933a16678ecb8dec9 (diff) |
Mark media as favorite API
Expose new API to allow apps with READ_EXTERNAL_STROAGE/READ_MEDIA_IMAGES/ READ_MEDIA_VIDEOS to update is_favorite column using this new API.
Is_favorite is not a critical column and updates on its gallery apps should be allowed for a better user experience.
Bug: 294364218
Test: android.provider.cts.media.MediaStoreTest#testMarkMediaAsFavorite
Flag: com.android.providers.media.flags.enable_mark_media_as_favorite_api
Change-Id: Ia526cc4f7545268283e69510a1b240eeca18c06c
Diffstat (limited to 'apex')
-rw-r--r-- | apex/framework/api/current.txt | 1 | ||||
-rw-r--r-- | apex/framework/java/android/provider/MediaStore.java | 41 |
2 files changed, 42 insertions, 0 deletions
diff --git a/apex/framework/api/current.txt b/apex/framework/api/current.txt index 0290f7c16..2ccf5367c 100644 --- a/apex/framework/api/current.txt +++ b/apex/framework/api/current.txt @@ -161,6 +161,7 @@ package android.provider { method public static boolean isCurrentCloudMediaProviderAuthority(@NonNull android.content.ContentResolver, @NonNull String); method public static boolean isCurrentSystemGallery(@NonNull android.content.ContentResolver, int, @NonNull String); method public static boolean isSupportedCloudMediaProviderAuthority(@NonNull android.content.ContentResolver, @NonNull String); + method @FlaggedApi("com.android.providers.media.flags.enable_mark_media_as_favorite_api") public static void markIsFavoriteStatus(@NonNull android.content.ContentResolver, @NonNull java.util.Collection<android.net.Uri>, boolean); method public static void notifyCloudMediaChangedEvent(@NonNull android.content.ContentResolver, @NonNull String, @NonNull String) throws java.lang.SecurityException; method @FlaggedApi("com.android.providers.media.flags.media_store_open_file") @Nullable public static android.content.res.AssetFileDescriptor openAssetFileDescriptor(@NonNull android.content.ContentResolver, @NonNull android.net.Uri, @NonNull String, @Nullable android.os.CancellationSignal) throws java.io.FileNotFoundException; method @FlaggedApi("com.android.providers.media.flags.media_store_open_file") @Nullable public static android.os.ParcelFileDescriptor openFileDescriptor(@NonNull android.content.ContentResolver, @NonNull android.net.Uri, @NonNull String, @Nullable android.os.CancellationSignal) throws java.io.FileNotFoundException; diff --git a/apex/framework/java/android/provider/MediaStore.java b/apex/framework/java/android/provider/MediaStore.java index 50c242404..7a262a86d 100644 --- a/apex/framework/java/android/provider/MediaStore.java +++ b/apex/framework/java/android/provider/MediaStore.java @@ -198,6 +198,8 @@ public final class MediaStore { /** {@hide} */ public static final String CREATE_FAVORITE_REQUEST_CALL = "create_favorite_request"; /** {@hide} */ + public static final String MARK_MEDIA_AS_FAVORITE = "mark_media_as_favorite"; + /** {@hide} */ public static final String CREATE_DELETE_REQUEST_CALL = "create_delete_request"; /** {@hide} */ @@ -1578,6 +1580,45 @@ public final class MediaStore { } /** + * Sets the media isFavorite status if the calling app has wider read permission on media + * files for given type. Calling app should have one of READ_EXTERNAL_STORAGE or + * WRITE_EXTERNAL_STORAGE if target sdk <= T. For target sdk > T, it + * should have READ_MEDIA_IMAGES for images, READ_MEDIA_VIDEOS for videos or READ_MEDIA_AUDIO + * for audio files or MANAGE_EXTERNAL_STORAGE permission. + * + * @param resolver used to connect with {@link MediaStore#AUTHORITY} + * @param uris a collection of media items to include in this request. Each item + * must be hosted by {@link MediaStore#AUTHORITY} and must + * reference a specific media item by {@link BaseColumns#_ID} + * sample uri - content://media/external_primary/images/media/24 + * @param areFavorites the {@link MediaColumns#IS_FAVORITE} value to apply. + */ + @FlaggedApi(Flags.FLAG_ENABLE_MARK_MEDIA_AS_FAVORITE_API) + public static void markIsFavoriteStatus(@NonNull ContentResolver resolver, + @NonNull Collection<Uri> uris, boolean areFavorites) { + Objects.requireNonNull(resolver); + Objects.requireNonNull(uris); + + final ContentValues values = new ContentValues(); + if (areFavorites) { + values.put(MediaColumns.IS_FAVORITE, 1); + } else { + values.put(MediaColumns.IS_FAVORITE, 0); + } + final Iterator<Uri> it = uris.iterator(); + final ClipData clipData = ClipData.newRawUri(null, it.next()); + while (it.hasNext()) { + clipData.addItem(new ClipData.Item(it.next())); + } + + final Bundle extras = new Bundle(); + extras.putParcelable(EXTRA_CLIP_DATA, clipData); + extras.putParcelable(EXTRA_CONTENT_VALUES, values); + resolver.call(AUTHORITY, MARK_MEDIA_AS_FAVORITE, null, extras); + } + + + /** * Create a {@link PendingIntent} that will prompt the user to permanently * delete the requested media items. When the user approves this request, * {@link ContentResolver#delete} will be called on these items. |