mirror of
https://github.com/AngelAuraMC/Amethyst-Android.git
synced 2026-04-18 00:27:04 -04:00
fix: Fix mimetype issues with stock android not matching .mrpack
We want to be able to grey out files that are not .zip or .mrpack so people can have an easier chance of seeing their modpacks. To do this, we match the `application/x-modrinth-modpack+zip` and `application/zip` mimetypes as prescribed in the Modrinth documentation https://support.modrinth.com/en/articles/8802351-modrinth-modpack-format-mrpack. Stock android does not have `application/x-modrinth-modpack+zip`. OEM vendors seem to include this in their ROMs, possibly from just using https://gitlab.freedesktop.org/xdg/shared-mime-info as part of where they source their additional mimetypes from. There's a tendency for Android 12 and below to not have the `application/x-modrinth-modpack+zip` mimetype, likely due to the addition of it being relatively recent, so we have to account for that by also adding `application/octet-stream`. We cannot only have `application/octet-stream` or else it fails to match .mrpack in systems that have `application/x-modrinth-modpack+zip`. Sadly there seems to be no reliable way to check whether or the the ROM has the `application/x-modrinth-modpack+zip` mimetype so we just match it along with `application/octet-stream` to cover our bases.
This commit is contained in:
@@ -36,10 +36,24 @@ public class OpenDocumentWithExtension extends ActivityResultContract<Object, Ur
|
||||
int count = 0;
|
||||
for (String extension: extensions) {
|
||||
String extensionMimetype = MimeTypeMap.getSingleton().getMimeTypeFromExtension(extension);
|
||||
// This somehow works despite finding no code showing where modrinth was defined.
|
||||
// Guessing that just DocumentsUI supports this, if someone files a bug report saying
|
||||
// they can't select mrpacks with DocumentsUI, remove this and just don't filter at all.
|
||||
if (Objects.equals(extension, "mrpack")) extensionMimetype = "application/x-modrinth-modpack+zip";
|
||||
if (Objects.equals(extension, "mrpack")) {
|
||||
// Special handling here because depending on whether the ROM has
|
||||
// `x-modrinth-modpack+zip` in their mimetypes or not because if it does,
|
||||
// `octet-stream` will no longer match mrpack files.
|
||||
|
||||
// Checking this with MimeTypeMap.hasExtension() and .hasMimeType() always returns
|
||||
// false so we do both instead.
|
||||
|
||||
// `octet-stream` highlights a lot of unrelated files but it's the best
|
||||
// we can do. Mimetypes are built into the ROM after all.
|
||||
// See https://android.googlesource.com/platform/external/mime-support/+/refs/heads/main
|
||||
// or https://android.googlesource.com/platform/frameworks/base/+/refs/heads/main/mime/java-res/android.mime.types
|
||||
extensionsMimeType.add("application/octet-stream");
|
||||
extensionsMimeType.add("application/x-modrinth-modpack+zip");
|
||||
count++;
|
||||
continue;
|
||||
}
|
||||
|
||||
if(extensionMimetype == null) continue; // If null is passed, it matches all files
|
||||
extensionsMimeType.add(extensionMimetype);
|
||||
count++;
|
||||
|
||||
Reference in New Issue
Block a user