Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 8f70cac0 authored by Jeff Sharkey's avatar Jeff Sharkey Committed by Android (Google) Code Review
Browse files

Merge changes from topics "trashz", "bucketz"

* changes:
  Public APIs for "trashing" media.
  Define secondary media item bucketing.
parents afbd1c4c 5cc407f7
Loading
Loading
Loading
Loading
+8 −0
Original line number Diff line number Diff line
@@ -37864,7 +37864,11 @@ package android.provider {
    method public static java.lang.String getVolumeName(android.net.Uri);
    method public static android.provider.MediaStore.PendingSession openPending(android.content.Context, android.net.Uri);
    method public static android.net.Uri setIncludePending(android.net.Uri);
    method public static android.net.Uri setIncludeTrashed(android.net.Uri);
    method public static android.net.Uri setRequireOriginal(android.net.Uri);
    method public static void trash(android.content.Context, android.net.Uri);
    method public static void trash(android.content.Context, android.net.Uri, long);
    method public static void untrash(android.content.Context, android.net.Uri);
    field public static final java.lang.String ACTION_IMAGE_CAPTURE = "android.media.action.IMAGE_CAPTURE";
    field public static final java.lang.String ACTION_IMAGE_CAPTURE_SECURE = "android.media.action.IMAGE_CAPTURE_SECURE";
    field public static final java.lang.String ACTION_REVIEW = "android.provider.action.REVIEW";
@@ -38087,6 +38091,7 @@ package android.provider {
    field public static final deprecated java.lang.String MINI_THUMB_MAGIC = "mini_thumb_magic";
    field public static final java.lang.String ORIENTATION = "orientation";
    field public static final deprecated java.lang.String PICASA_ID = "picasa_id";
    field public static final java.lang.String SECONDARY_BUCKET_ID = "secondary_bucket_id";
  }
  public static final class MediaStore.Images.Media implements android.provider.MediaStore.Images.ImageColumns {
@@ -38131,11 +38136,13 @@ package android.provider {
  public static abstract interface MediaStore.MediaColumns implements android.provider.BaseColumns {
    field public static final deprecated java.lang.String DATA = "_data";
    field public static final java.lang.String DATE_ADDED = "date_added";
    field public static final java.lang.String DATE_EXPIRES = "date_expires";
    field public static final java.lang.String DATE_MODIFIED = "date_modified";
    field public static final java.lang.String DISPLAY_NAME = "_display_name";
    field public static final java.lang.String HASH = "_hash";
    field public static final java.lang.String HEIGHT = "height";
    field public static final java.lang.String IS_PENDING = "is_pending";
    field public static final java.lang.String IS_TRASHED = "is_trashed";
    field public static final java.lang.String MIME_TYPE = "mime_type";
    field public static final java.lang.String OWNER_PACKAGE_NAME = "owner_package_name";
    field public static final java.lang.String SIZE = "_size";
@@ -38211,6 +38218,7 @@ package android.provider {
    field public static final deprecated java.lang.String LONGITUDE = "longitude";
    field public static final deprecated java.lang.String MINI_THUMB_MAGIC = "mini_thumb_magic";
    field public static final java.lang.String RESOLUTION = "resolution";
    field public static final java.lang.String SECONDARY_BUCKET_ID = "secondary_bucket_id";
    field public static final java.lang.String TAGS = "tags";
  }
+151 −13
Original line number Diff line number Diff line
@@ -17,6 +17,7 @@
package android.provider;

import android.annotation.BytesLong;
import android.annotation.DurationMillisLong;
import android.annotation.IntRange;
import android.annotation.NonNull;
import android.annotation.Nullable;
@@ -55,6 +56,7 @@ import android.os.storage.StorageVolume;
import android.os.storage.VolumeInfo;
import android.service.media.CameraPrewarmService;
import android.text.TextUtils;
import android.text.format.DateUtils;
import android.util.ArrayMap;
import android.util.ArraySet;
import android.util.Log;
@@ -131,6 +133,8 @@ public final class MediaStore {
    /** {@hide} */
    public static final String PARAM_INCLUDE_PENDING = "includePending";
    /** {@hide} */
    public static final String PARAM_INCLUDE_TRASHED = "includeTrashed";
    /** {@hide} */
    public static final String PARAM_PROGRESS = "progress";
    /** {@hide} */
    public static final String PARAM_REQUIRE_ORIGINAL = "requireOriginal";
@@ -485,11 +489,28 @@ public final class MediaStore {
     * By default no pending items are returned.
     *
     * @see MediaColumns#IS_PENDING
     * @see MediaStore#setIncludePending(Uri)
     * @see MediaStore#createPending(Context, PendingParams)
     */
    public static @NonNull Uri setIncludePending(@NonNull Uri uri) {
        return uri.buildUpon().appendQueryParameter(PARAM_INCLUDE_PENDING, "1").build();
    }

    /**
     * Update the given {@link Uri} to also include any trashed media items from
     * calls such as
     * {@link ContentResolver#query(Uri, String[], Bundle, CancellationSignal)}.
     * By default no trashed items are returned.
     *
     * @see MediaColumns#IS_TRASHED
     * @see MediaStore#setIncludeTrashed(Uri)
     * @see MediaStore#trash(Context, Uri)
     * @see MediaStore#untrash(Context, Uri)
     */
    public static @NonNull Uri setIncludeTrashed(@NonNull Uri uri) {
        return uri.buildUpon().appendQueryParameter(PARAM_INCLUDE_TRASHED, "1").build();
    }

    /**
     * Update the given {@link Uri} to indicate that the caller requires the
     * original file contents when calling
@@ -516,6 +537,9 @@ public final class MediaStore {
     *
     * @return token which can be passed to {@link #openPending(Context, Uri)}
     *         to work with this pending item.
     * @see MediaColumns#IS_PENDING
     * @see MediaStore#setIncludePending(Uri)
     * @see MediaStore#createPending(Context, PendingParams)
     */
    public static @NonNull Uri createPending(@NonNull Context context,
            @NonNull PendingParams params) {
@@ -572,6 +596,8 @@ public final class MediaStore {
            this.insertValues.put(MediaColumns.DATE_ADDED, now);
            this.insertValues.put(MediaColumns.DATE_MODIFIED, now);
            this.insertValues.put(MediaColumns.IS_PENDING, 1);
            this.insertValues.put(MediaColumns.DATE_EXPIRES,
                    (System.currentTimeMillis() + DateUtils.DAY_IN_MILLIS) / 1000);
        }

        /**
@@ -696,6 +722,7 @@ public final class MediaStore {
        public @NonNull Uri publish() {
            final ContentValues values = new ContentValues();
            values.put(MediaColumns.IS_PENDING, 0);
            values.putNull(MediaColumns.DATE_EXPIRES);
            mContext.getContentResolver().update(mUri, values, null, null);
            return mUri;
        }
@@ -716,6 +743,67 @@ public final class MediaStore {
        }
    }

    /**
     * Mark the given item as being "trashed", meaning it should be deleted at
     * some point in the future. This is a more gentle operation than simply
     * calling {@link ContentResolver#delete(Uri, String, String[])}, which
     * would take effect immediately.
     * <p>
     * This method preserves trashed items for at least 48 hours before erasing
     * them, giving the user a chance to untrash the item.
     *
     * @see MediaColumns#IS_TRASHED
     * @see MediaStore#setIncludeTrashed(Uri)
     * @see MediaStore#trash(Context, Uri)
     * @see MediaStore#untrash(Context, Uri)
     */
    public static void trash(@NonNull Context context, @NonNull Uri uri) {
        trash(context, uri, 48 * DateUtils.HOUR_IN_MILLIS);
    }

    /**
     * Mark the given item as being "trashed", meaning it should be deleted at
     * some point in the future. This is a more gentle operation than simply
     * calling {@link ContentResolver#delete(Uri, String, String[])}, which
     * would take effect immediately.
     * <p>
     * This method preserves trashed items for at least the given timeout before
     * erasing them, giving the user a chance to untrash the item.
     *
     * @see MediaColumns#IS_TRASHED
     * @see MediaStore#setIncludeTrashed(Uri)
     * @see MediaStore#trash(Context, Uri)
     * @see MediaStore#untrash(Context, Uri)
     */
    public static void trash(@NonNull Context context, @NonNull Uri uri,
            @DurationMillisLong long timeoutMillis) {
        if (timeoutMillis < 0) {
            throw new IllegalArgumentException();
        }

        final ContentValues values = new ContentValues();
        values.put(MediaColumns.IS_TRASHED, 1);
        values.put(MediaColumns.DATE_EXPIRES,
                (System.currentTimeMillis() + timeoutMillis) / 1000);
        context.getContentResolver().update(uri, values, null, null);
    }

    /**
     * Mark the given item as being "untrashed", meaning it should no longer be
     * deleted as previously requested through {@link #trash(Context, Uri)}.
     *
     * @see MediaColumns#IS_TRASHED
     * @see MediaStore#setIncludeTrashed(Uri)
     * @see MediaStore#trash(Context, Uri)
     * @see MediaStore#untrash(Context, Uri)
     */
    public static void untrash(@NonNull Context context, @NonNull Uri uri) {
        final ContentValues values = new ContentValues();
        values.put(MediaColumns.IS_TRASHED, 0);
        values.putNull(MediaColumns.DATE_EXPIRES);
        context.getContentResolver().update(uri, values, null, null);
    }

    /**
     * Common fields for most MediaProvider tables
     */
@@ -821,11 +909,33 @@ public final class MediaStore {
         * <p>
         * Type: BOOLEAN
         *
         * @see MediaColumns#IS_PENDING
         * @see MediaStore#setIncludePending(Uri)
         * @see MediaStore#createPending(Context, PendingParams)
         * @see MediaStore#PARAM_INCLUDE_PENDING
         */
        public static final String IS_PENDING = "is_pending";

        /**
         * Flag indicating if a media item is trashed.
         * <p>
         * Type: BOOLEAN
         *
         * @see MediaColumns#IS_TRASHED
         * @see MediaStore#setIncludeTrashed(Uri)
         * @see MediaStore#trash(Context, Uri)
         * @see MediaStore#untrash(Context, Uri)
         */
        public static final String IS_TRASHED = "is_trashed";

        /**
         * The time the file should be considered expired. Units are seconds
         * since 1970. Typically only meaningful in the context of
         * {@link #IS_PENDING} or {@link #IS_TRASHED}.
         * <p>
         * Type: INTEGER
         */
        public static final String DATE_EXPIRES = "date_expires";

        /**
         * The width of the image/video in pixels.
         */
@@ -1251,18 +1361,32 @@ public final class MediaStore {
            public static final String MINI_THUMB_MAGIC = "mini_thumb_magic";

            /**
             * The bucket id of the image. This is a read-only property that
             * is automatically computed from the DATA column.
             * <P>Type: TEXT</P>
             * The primary bucket ID of this media item. This can be useful to
             * present the user a first-level clustering of related media items.
             * This is a read-only column that is automatically computed.
             * <p>
             * Type: INTEGER
             */
            public static final String BUCKET_ID = "bucket_id";

            /**
             * The bucket display name of the image. This is a read-only property that
             * is automatically computed from the DATA column.
             * <P>Type: TEXT</P>
             * The primary bucket display name of this media item. This can be
             * useful to present the user a first-level clustering of related
             * media items. This is a read-only column that is automatically
             * computed.
             * <p>
             * Type: TEXT
             */
            public static final String BUCKET_DISPLAY_NAME = "bucket_display_name";

            /**
             * The secondary bucket ID of this media item. This can be useful to
             * present the user a second-level clustering of related media
             * items. This is a read-only column that is automatically computed.
             * <p>
             * Type: INTEGER
             */
            public static final String SECONDARY_BUCKET_ID = "secondary_bucket_id";
        }

        public static final class Media implements ImageColumns {
@@ -2500,19 +2624,33 @@ public final class MediaStore {
            public static final String MINI_THUMB_MAGIC = "mini_thumb_magic";

            /**
             * The bucket id of the video. This is a read-only property that
             * is automatically computed from the DATA column.
             * <P>Type: TEXT</P>
             * The primary bucket ID of this media item. This can be useful to
             * present the user a first-level clustering of related media items.
             * This is a read-only column that is automatically computed.
             * <p>
             * Type: INTEGER
             */
            public static final String BUCKET_ID = "bucket_id";

            /**
             * The bucket display name of the video. This is a read-only property that
             * is automatically computed from the DATA column.
             * <P>Type: TEXT</P>
             * The primary bucket display name of this media item. This can be
             * useful to present the user a first-level clustering of related
             * media items. This is a read-only column that is automatically
             * computed.
             * <p>
             * Type: TEXT
             */
            public static final String BUCKET_DISPLAY_NAME = "bucket_display_name";

            /**
             * The secondary bucket ID of this media item. This can be useful to
             * present the user a second-level clustering of related media
             * items. This is a read-only column that is automatically computed.
             * <p>
             * Type: INTEGER
             */
            public static final String SECONDARY_BUCKET_ID = "secondary_bucket_id";

            /**
             * The bookmark for the video. Time in ms. Represents the location in the video that the
             * video should start playing at the next time it is opened. If the value is null or