diff options
author | 2018-08-27 18:03:33 -0600 | |
---|---|---|
committer | 2018-08-28 13:02:35 -0600 | |
commit | 91e3cd4c6c1b00f606966a3af2abc0ef6f331bb0 (patch) | |
tree | e904980a97f58618b277256dde37f2d3e824657e /packages/MtpDocumentsProvider | |
parent | bfbdd1c0b912e3c2df027e4030931e1e2c070270 (diff) |
More robust MTP-to-MIME-type mappings.
Recently in I830717428e72ac37c5ecd1f23d915aa878ef3744, we greatly
improved the underlying file-extension-to-MIME-type mappings defined
in libcore and used across the OS.
Instead of maintaining divergent mappings here in MediaFile, this
change delegates all file extension logic down to libcore, and
standardizes all MediaScanner internals on using MIME types. To
register new file types in the future:
1. Add the MIME-to-extension registration in libcore.
2. Add the MIME-to-MTP mapping here in MediaFile.
This change also ensures that unknown MIME types are surfaced
across MTP, using constants like FORMAT_UNDEFINED_AUDIO for audio/*
until an explicit format is defined.
We now surface WMA/WMV file formats, even if the device can't
natively play them back, since we still want to offer the ability
for users to copy them around, and the user may have a third-party
app capable of playing them.
Keeps @UnsupportedAppUsage intact for now.
Bug: 111268862, 112162449
Test: atest frameworks/base/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/unit/MediaFileTest.java
Test: atest cts/tests/tests/provider/src/android/provider/cts/MediaStore*
Change-Id: I2f6a5411bc215f776f00e0f9a4b7d825b10b377d
Diffstat (limited to 'packages/MtpDocumentsProvider')
-rw-r--r-- | packages/MtpDocumentsProvider/src/com/android/mtp/MtpDatabase.java | 20 |
1 files changed, 1 insertions, 19 deletions
diff --git a/packages/MtpDocumentsProvider/src/com/android/mtp/MtpDatabase.java b/packages/MtpDocumentsProvider/src/com/android/mtp/MtpDatabase.java index f243b51d6769..59c205aebe18 100644 --- a/packages/MtpDocumentsProvider/src/com/android/mtp/MtpDatabase.java +++ b/packages/MtpDocumentsProvider/src/com/android/mtp/MtpDatabase.java @@ -851,25 +851,7 @@ class MtpDatabase { return DocumentsContract.Document.MIME_TYPE_DIR; } - final String formatCodeMimeType = MediaFile.getMimeTypeForFormatCode(info.getFormat()); - final String mediaFileMimeType = MediaFile.getMimeTypeForFile(info.getName()); - - // Format code can be mapped with multiple mime types, e.g. FORMAT_MPEG is mapped with - // audio/mp4 and video/mp4. - // As file extension contains more information than format code, returns mime type obtained - // from file extension if it is consistent with format code. - if (mediaFileMimeType != null && - MediaFile.getFormatCode("", mediaFileMimeType) == info.getFormat()) { - return mediaFileMimeType; - } - if (formatCodeMimeType != null) { - return formatCodeMimeType; - } - if (mediaFileMimeType != null) { - return mediaFileMimeType; - } - // We don't know the file type. - return "application/octet-stream"; + return MediaFile.getMimeType(info.getName(), info.getFormat()); } private static int getRootFlags(int[] operationsSupported) { |