The MediaProvider module optimizes indexed metadata (audio, video, and images from SD cards and USB devices) and makes that data available to apps through the MediaStore public APIs. To maintain user privacy, the MediaProvider module enforces the scoped storage security model introduced in Android 10, which includes redacting sensitive location metadata. This module is updatable, enabling Android to respond faster to security issues (keeping sensitive user data protected) and add new media formats quicker (providing consistency to both users and developers).
Changes in Android 10
Android 10 introduced several improvements related to identifying and extracting data from media files, specifically:
Determining the file content type using the first part of a file’s MIME type. For example, the OS knows that both
image/x-newly-invented-formatare images, and can thus accurately describe relevant permissions to the end user.
Determining the MIME type using only the file extension (and without using content sniffing to avoid security issues).
Determining the MIME type of an arbitrary file using a combination of upstream Debian Linux and Android mappings.
Returning relevant data from
Changes in Android 11
In Android 11, the MediaProvider module builds on the changes made in Android 10 with the following improvements:
Improvements to indexing. The MediaProvider module now indexes metadata by reconciling available metadata against MediaStore public APIs. Changes include:
QUERY_ARG_MATCH_FAVORITEargument to enable gallery-style apps to quickly filter media based on this column.
Indexing color space metadata.
New 'is_trashed' column and
QUERY_ARG_MATCH_TRASHEDargument to enable gallery-style apps to filter based on this column.
New APIs that enable bulk-modification of multiple items with a single user dialog prompt, including
GENERATION_MODIFIEDcolumns for use in quickly and reliably detecting changes that have occurred since a previous synchronization point.
GROUP BYpublic API for use with additional metadata columns not mentioned above.
ExifInterfaceto extract metadata from PNG and WebP containers.
DateTimeOriginalmetadata in screen captures.
In addition, you can now customize MediaProvider by adding new media formats, marking which storage devices should be indexed, and even replacing the MTP stack. For details, see Customization.
Android 11 migrates all code in
packages/providers/MediaProvider to a new location, with the notable exception
of MTP-related logic. In addition,
frameworks/base/core/java/android/provider/MediaStore.java is now inside the
module boundary at
The MediaProvider module is in APK-in-APEX format.
MediaProvider dependencies are related to customizations (that is, if you customize MediaProvider, you must ensure your implementation meets the dependency associated with your customization).
When using custom or nonstandard media file formats (for example, a format generated by a vendor-specific Camera app), you must register each custom format with
MimeUtilsand the Media Extractor module to enable indexing by MediaProvider.
To ensure MediaProvider indexes a custom set of storage devices (such SD card slots and USB ports) used in a
StorageManagerServiceimplementation, set the
When using a custom (non-AOSP) MTP implementation, ensure the implementation relies solely on public and system APIs to enable the implementation to interact with MediaStore.
You can now add new media formats, influence which storage devices are indexed, and replace the MTP stack.
Custom media formats. For each new custom media format, you must provide a mapping from the unique file extension to a MIME type. We strongly encourage you to follow the IANA registration process.
You can't redefine an extension or MIME type that's already defined in AOSP.
audio/*files, MediaProvider continues consulting
MediaMetadataRetriever. Use the Android 10 Media Extractors to return metadata for custom formats.
image/*files, MediaProvider continues standardizing on
Exiffor metadata. You can extend
android.media.ExifInterfaceto extract and return
Exifmetadata for any custom image formats.
Storage devices indexing flag. MediaProvider indexes all volumes returned by
StorageVolume.getMediaStoreVolumeName()is non-null. You can customize the list of volumes returned to influence what is indexed, but we advise against including transient volumes (such as USB OTG drives).
MTP stack replacement. Android 11 places the MTP stack entirely outside the module boundary and ensures that it works against public APIs.
You can verify the functionality of MediaProvider using the following tests:
To verify the functionality of MediaStore public APIs, use tests in the
CtsProviderTestCasespackage of the Android Compatibility Test Suite (CTS).
To verify the functionality of MediaProvider internals, use tests in
To run both sets of tests together, use the following
atest --test-mapping packages/providers/MediaProvider