Modern Apps git

← Modern-Apps.git

share: map advertised AirDrop UTIs to MIME types

Commit
5f3ebc60c8d4024a7ed189c3247bd777a2c2ef80
Author
Vayun Mathur <[email protected]>
When
2026-11-08 02:15 UTC (28 days ago)
Parents
05b6fca
Files received over AirDrop arrived as application/octet-stream when
their extension mapped to a UTI that mimeByUti did not know: zip
(com.pkware.zip-archive), epub (com.apple.epub.document), mkv, tar,
ics, md, csv, mpeg/mpg, dmg, pkpass and usd/usdz all fell through to
the generic type, so notifications and open intents could not tell a
book or an archive from opaque bytes.

Add the missing entries (keeping the Apple-canonical UTIs already
there, e.g. org.idpf.epub-container, alongside the ones Mosey
advertises). UTIs with no standard MIME (url, webloc, plist,
camera-raw, iWork, ipa) deliberately stay unmapped rather than risk
misrouting a file to the wrong app.

Verified with :share:testDevUnitTest (new UtiMimeTest round-trips
every advertised UTI through mimeTypeOf).

Diff

share/src/main/java/com/vayunmathur/share/domain/airdrop/Uti.kt
diff --git a/share/src/main/java/com/vayunmathur/share/domain/airdrop/Uti.kt b/share/src/main/java/com/vayunmathur/share/domain/airdrop/Uti.ktindex 12a28824fa..63ba553138 100644--- a/share/src/main/java/com/vayunmathur/share/domain/airdrop/Uti.kt+++ b/share/src/main/java/com/vayunmathur/share/domain/airdrop/Uti.kt@@ -75,9 +75,21 @@ object Uti {      private val mimeByUti: Map<String, String> = mapOf(         "com.adobe.pdf" to "application/pdf",+        "com.apple.epub.document" to "application/epub+zip",         "org.idpf.epub-container" to "application/epub+zip",+        "com.pkware.zip-archive" to "application/zip",         "public.zip-archive" to "application/zip",         "org.gnu.gzip-archive" to "application/gzip",+        "public.tar-archive" to "application/x-tar",+        "public.calendar-event" to "text/calendar",+        "net.daringfireball.markdown" to "text/markdown",+        "public.comma-separated-values-text" to "text/csv",+        "com.apple.pkpass" to "application/vnd.apple.pkpass",+        "com.apple.diskimage" to "application/x-apple-diskimage",+        "public.matroska-video" to "video/x-matroska",+        "public.mpeg" to "video/mpeg",+        "com.pixar.usd" to "model/vnd.pixar.usd",+        "com.pixar.usdz" to "model/vnd.usdz+zip",         NOTES_DOCUMENT to "text/plain",         "com.apple.rtfd" to "text/rtf",         "public.html" to "text/html",
share/src/test/java/com/vayunmathur/share/domain/airdrop/UtiMimeTest.kt
diff --git a/share/src/test/java/com/vayunmathur/share/domain/airdrop/UtiMimeTest.kt b/share/src/test/java/com/vayunmathur/share/domain/airdrop/UtiMimeTest.ktnew file mode 100644index 0000000000..90e973fe16--- /dev/null+++ b/share/src/test/java/com/vayunmathur/share/domain/airdrop/UtiMimeTest.kt@@ -0,0 +1,39 @@+package com.vayunmathur.share.domain.airdrop++import org.junit.Assert.assertEquals+import org.junit.Assert.assertNull+import org.junit.Test++/**+ * Every UTI [Uti.forFileName] advertises in an Ask must resolve through [Uti.mimeTypeOf]:+ * otherwise the receiver files it as `application/octet-stream`.+ */+class UtiMimeTest {++    @Test+    fun `advertised archive and document UTIs resolve to MIME types`() {+        assertEquals("application/zip", Uti.mimeTypeOf(Uti.forFileName("a.zip").uti))+        assertEquals("application/epub+zip", Uti.mimeTypeOf(Uti.forFileName("b.epub").uti))+        assertEquals("application/x-tar", Uti.mimeTypeOf(Uti.forFileName("c.tar").uti))+        assertEquals("text/markdown", Uti.mimeTypeOf(Uti.forFileName("d.md").uti))+        assertEquals("text/csv", Uti.mimeTypeOf(Uti.forFileName("e.csv").uti))+        assertEquals("text/calendar", Uti.mimeTypeOf(Uti.forFileName("f.ics").uti))+        assertEquals("application/vnd.apple.pkpass", Uti.mimeTypeOf(Uti.forFileName("g.pkpass").uti))+        assertEquals("application/x-apple-diskimage", Uti.mimeTypeOf(Uti.forFileName("h.dmg").uti))+    }++    @Test+    fun `advertised media UTIs resolve to MIME types`() {+        assertEquals("video/x-matroska", Uti.mimeTypeOf(Uti.forFileName("a.mkv").uti))+        assertEquals("video/mpeg", Uti.mimeTypeOf(Uti.forFileName("b.mpeg").uti))+        assertEquals("video/mpeg", Uti.mimeTypeOf(Uti.forFileName("c.mpg").uti))+        assertEquals("model/vnd.pixar.usd", Uti.mimeTypeOf(Uti.forFileName("d.usd").uti))+        assertEquals("model/vnd.usdz+zip", Uti.mimeTypeOf(Uti.forFileName("e.usdz").uti))+    }++    @Test+    fun `unknown UTI still resolves to null for the generic fallback`() {+        assertNull(Uti.mimeTypeOf("com.example.never-seen"))+        assertNull(Uti.mimeTypeOf("public.data"))+    }+}