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

Commit 969cdb3d authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Remove "tags" arg from getDocumentMetadata."

parents d1cc7910 17a9ce33
Loading
Loading
Loading
Loading
+47 −42
Original line number Diff line number Diff line
@@ -187,9 +187,6 @@ public final class DocumentsContract {
    /** {@hide} */
    public static final String METADATA_EXIF = "android:documentExif";

    /** {@hide} */
    public static final String EXTRA_METADATA_TAGS = "android:documentMetadataTags";

    /**
     * Constants related to a document, including {@link Cursor} column names
     * and flags.
@@ -1396,38 +1393,42 @@ public final class DocumentsContract {

    /**
     * Returns metadata associated with the document. The type of metadata returned
     * is specific to the document type. For example image files will largely return EXIF
     * metadata.
     *
     * <p>The returned {@link Bundle} will contain zero or more entries.
     * <p>Each entry represents a specific type of metadata.
     *
     * <p>if tags == null, then a list of default tags will be used.
     *
     * @param documentUri a Document URI
     * @param tags an array of keys to choose which data are added to the Bundle. If the Document
     *             is a JPG or ExifInterface compatible, send keys from {@link ExifInterface}.
     *             If tags are null, a set of default tags will be used. If the tags don't
     *             match with any relevant data, they will not be added to the Bundle.
     * @return a Bundle of Bundles. If metadata exists within the Bundle, there will also
     * be a String under DocumentsContract.METADATA_TYPES that will return a String[] of the
     * types of metadata gathered.
     *
     * <pre><code>
     *     Bundle metadata = DocumentsContract.getDocumentMetadata(resolver, imageDocUri, tags);
     *     int imageLength = metadata.getInt(ExifInterface.TAG_IMAGE_LENGTH);
     * is specific to the document type. For example the data returned for an image
     * file will likely consist primarily or soley of EXIF metadata.
     *
     * <p>The returned {@link Bundle} will contain zero or more entries depending
     * on the type of data supported by the document provider.
     *
     * <ol>
     * <li>A {@link DocumentsContract.METADATA_TYPES} containing a {@code String[]} value.
     *     The string array identifies the type or types of metadata returned. Each
     *     value in the can be used to access a {@link Bundle} of data
     *     containing that type of data.
     * <li>An entry each for each type of returned metadata. Each set of metadata is
     *     itself represented as a bundle and accessible via a string key naming
     *     the type of data.
     * </ol>
     *
     * <p>Example:
     * <p><pre><code>
     *     Bundle metadata = DocumentsContract.getDocumentMetadata(client, imageDocUri, tags);
     *     if (metadata.containsKey(DocumentsContract.METADATA_EXIF)) {
     *         Bundle exif = metadata.getBundle(DocumentsContract.METADATA_EXIF);
     *         int imageLength = exif.getInt(ExifInterface.TAG_IMAGE_LENGTH);
     *     }
     * </code></pre>
     *
     * @param documentUri a Document URI
     * @return a Bundle of Bundles.
     * {@hide}
     */
    public static Bundle getDocumentMetadata(ContentResolver resolver, Uri documentUri,
            @Nullable String[] tags)
    public static Bundle getDocumentMetadata(ContentResolver resolver, Uri documentUri)
            throws FileNotFoundException {
        final ContentProviderClient client = resolver.acquireUnstableContentProviderClient(
                documentUri.getAuthority());

        try {
            return getDocumentMetadata(client, documentUri, tags);
            return getDocumentMetadata(client, documentUri);
        } catch (Exception e) {
            Log.w(TAG, "Failed to get document metadata");
            rethrowIfNecessary(resolver, e);
@@ -1439,35 +1440,39 @@ public final class DocumentsContract {

    /**
     * Returns metadata associated with the document. The type of metadata returned
     * is specific to the document type. For example image files will largely return EXIF
     * metadata.
     *
     * <p>The returned {@link Bundle} will contain zero or more entries.
     * <p>Each entry represents a specific type of metadata.
     *
     * <p>if tags == null, then a list of default tags will be used.
     *
     * @param documentUri a Document URI
     * @param tags an array of keys to choose which data are added to the Bundle. If the Document
     *             is a JPG or ExifInterface compatible, send keys from {@link ExifInterface}.
     *             If tags are null, a set of default tags will be used. If the tags don't
     *             match with any relevant data, they will not be added to the Bundle.
     * @return a Bundle of Bundles. If metadata exists within the Bundle, there will also
     * be a String under DocumentsContract.METADATA_TYPES that will return a String[] of the
     * types of metadata gathered.
     *
     * <pre><code>
     * is specific to the document type. For example the data returned for an image
     * file will likely consist primarily or soley of EXIF metadata.
     *
     * <p>The returned {@link Bundle} will contain zero or more entries depending
     * on the type of data supported by the document provider.
     *
     * <ol>
     * <li>A {@link DocumentsContract.METADATA_TYPES} containing a {@code String[]} value.
     *     The string array identifies the type or types of metadata returned. Each
     *     value in the can be used to access a {@link Bundle} of data
     *     containing that type of data.
     * <li>An entry each for each type of returned metadata. Each set of metadata is
     *     itself represented as a bundle and accessible via a string key naming
     *     the type of data.
     * </ol>
     *
     * <p>Example:
     * <p><pre><code>
     *     Bundle metadata = DocumentsContract.getDocumentMetadata(client, imageDocUri, tags);
     *     int imageLength = metadata.getInt(ExifInterface.TAG_IMAGE_LENGTH);
     *     if (metadata.containsKey(DocumentsContract.METADATA_EXIF)) {
     *         Bundle exif = metadata.getBundle(DocumentsContract.METADATA_EXIF);
     *         int imageLength = exif.getInt(ExifInterface.TAG_IMAGE_LENGTH);
     *     }
     * </code></pre>
     *
     * @param documentUri a Document URI
     * @return a Bundle of Bundles.
     * {@hide}
     */
    public static Bundle getDocumentMetadata(ContentProviderClient client,
            Uri documentUri, @Nullable String[] tags) throws RemoteException {
    public static Bundle getDocumentMetadata(
            ContentProviderClient client, Uri documentUri) throws RemoteException {
        final Bundle in = new Bundle();
        in.putParcelable(EXTRA_URI, documentUri);
        in.putStringArray(EXTRA_METADATA_TAGS, tags);

        final Bundle out = client.call(METHOD_GET_DOCUMENT_METADATA, null, in);

+6 −6
Original line number Diff line number Diff line
@@ -629,7 +629,7 @@ public abstract class DocumentsProvider extends ContentProvider {
    }

    /** {@hide} */
    public @Nullable Bundle getDocumentMetadata(String documentId, @Nullable String[] tags)
    public @Nullable Bundle getDocumentMetadata(String documentId)
            throws FileNotFoundException {
        throw new UnsupportedOperationException("Metadata not supported");
    }
@@ -649,11 +649,12 @@ public abstract class DocumentsProvider extends ContentProvider {
     *
     * @hide
     */
    protected Bundle getDocumentMetadataFromStream(
            InputStream stream, String mimeType, @Nullable String[] tags)
    protected Bundle getDocumentMetadataFromStream(InputStream stream, String mimeType)
            throws IOException {
        Bundle metadata = new Bundle();
        MetadataReader.getMetadata(metadata, stream, mimeType, tags);
        // TODO: Remove the last null arg from MetadataReader. It was the "tags" value,
        // the has been removed from the getDocumentMetadata method.
        MetadataReader.getMetadata(metadata, stream, mimeType, null);
        return metadata;
    }

@@ -1169,8 +1170,7 @@ public abstract class DocumentsProvider extends ContentProvider {

            out.putParcelable(DocumentsContract.EXTRA_RESULT, path);
        } else if (METHOD_GET_DOCUMENT_METADATA.equals(method)) {
            return getDocumentMetadata(
                    documentId, extras.getStringArray(DocumentsContract.EXTRA_METADATA_TAGS));
            return getDocumentMetadata(documentId);
        } else {
            throw new UnsupportedOperationException("Method not supported " + method);
        }
+2 −2
Original line number Diff line number Diff line
@@ -110,7 +110,7 @@ public abstract class FileSystemProvider extends DocumentsProvider {
    }

    @Override
    public @Nullable Bundle getDocumentMetadata(String documentId, @Nullable String[] tags)
    public @Nullable Bundle getDocumentMetadata(String documentId)
            throws FileNotFoundException {
        File file = getFileForDocId(documentId);

@@ -132,7 +132,7 @@ public abstract class FileSystemProvider extends DocumentsProvider {
        FileInputStream stream = new FileInputStream(filePath);

        try {
            return getDocumentMetadataFromStream(stream, getTypeForFile(file), tags);
            return getDocumentMetadataFromStream(stream, getTypeForFile(file));
        } catch (IOException e) {
            Log.e(TAG, "An error occurred retrieving the metadata", e);
        } finally {