summaryrefslogtreecommitdiff
path: root/apex
diff options
context:
space:
mode:
author Darshil Shah <darshilshah@google.com> 2024-11-04 12:46:49 +0000
committer Android (Google) Code Review <android-gerrit@google.com> 2024-11-04 12:46:49 +0000
commite6b3ede721e94b10eac38f20212acc547f950f09 (patch)
treec6703990008f2a9ae436c59dc9d94c2123f8e88f /apex
parentbf2f512c45300fe1061e595c6da56d1e01a5b71b (diff)
parentc863d5686f0c7edb33cb95d5ae06c307225e77bf (diff)
Merge "Mark media as favorite API" into main
Diffstat (limited to 'apex')
-rw-r--r--apex/framework/api/current.txt1
-rw-r--r--apex/framework/java/android/provider/MediaStore.java41
2 files changed, 42 insertions, 0 deletions
diff --git a/apex/framework/api/current.txt b/apex/framework/api/current.txt
index 8bc2086a2..930f05347 100644
--- a/apex/framework/api/current.txt
+++ b/apex/framework/api/current.txt
@@ -177,6 +177,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 222716d21..0a5d79a10 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} */
@@ -1632,6 +1634,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.