Clean up MIME type mappings.
The existing design was becoming a mess, since it was a mixture of an outdated /etc/mime.types combined with Android-specific overrides that had accumulated over the years. This new design takes the upstream /etc/mime.types as-is, and then layers on any Android-specific overrides. This design follows the industry best-practice of how these files are parsed, such as how https://golang.org/src/mime/type_unix.go is implemented. (That is, when building the mapping in order, the first MIME type takes precedence, and the last extension takes precedence.) I can't find evidence of the potential security issues mentioned in older comments, since this is only building a straightforward mapping between MIME types and extensions; downloads from the web already have full control over both the MIME type and extension via the "Content-Type" and "Content-Disposition" headers. Thus this change technically re-introduces many "application/*" MIME types from upstream. To support a handful of cases where Android feels strongly, this new design supports an extension being suffixed with "!" which indicates it should take precedence over any existing MIME type. The "android.mime.types" file in this CL is enough to keep all previous mappings intact, while also adding a handful of new popular MIME types such as HEIF. Bug: 112162449 Test: cts-tradefed run commandAndExit cts-dev -m CtsLibcoreTestCases -t libcore.libcore.net.MimeUtilsTest Change-Id: I830717428e72ac37c5ecd1f23d915aa878ef3744
Loading
Please sign in to comment