Modern Apps git

← Modern-Apps.git

library-avatar: keep the fd handoff test off Robolectric's detachFd

Commit
f2cafcef6d4a97652c2c378188bec0e6957192be
Author
Vayun Mathur <[email protected]>
When
2026-11-07 19:59 UTC (28 days ago)
Parents
0811e32
handOff detaches the fd into native ran fine on device but the
unit test died with NoSuchMethodError inside Robolectric:
its ParcelFileDescriptor.detachFd() calls the libcore-internal
FileDescriptor.getOwnerId$(), which does not exist on the host
JDK (run 8f356294).

handOff is split so the detach step is injectable, defaulting to
the real ParcelFileDescriptor::detachFd; the test passes the raw
fd instead. On-device ownership semantics are unchanged - the
production caller still detaches exactly as before.

Verified locally on devvm24805:
:library:avatar:testDebugUnitTest for YuuAvatarAssetsTest green
(was failing with the same NoSuchMethodError before).

Diff

library/avatar/src/main/java/com/vayunmathur/library/avatar/YuuAvatarAssets.kt
diff --git a/library/avatar/src/main/java/com/vayunmathur/library/avatar/YuuAvatarAssets.kt b/library/avatar/src/main/java/com/vayunmathur/library/avatar/YuuAvatarAssets.ktindex e5ba398ecc..3e4b88ced2 100644--- a/library/avatar/src/main/java/com/vayunmathur/library/avatar/YuuAvatarAssets.kt+++ b/library/avatar/src/main/java/com/vayunmathur/library/avatar/YuuAvatarAssets.kt@@ -36,8 +36,21 @@ object YuuAvatarAssets {      * Detaches [afd]'s fd into native. Split from [adoptBundledMesh] so the      * fd ownership transfer can be exercised without a bundled mesh asset.      */-    internal fun handOff(afd: AssetFileDescriptor) {-        val fd = afd.parcelFileDescriptor.detachFd()+    internal fun handOff(afd: AssetFileDescriptor) =+        handOff(afd, ParcelFileDescriptor::detachFd)++    /**+     * [handOff] with the detach step injectable. Robolectric's+     * ParcelFileDescriptor.detachFd() calls a libcore-internal+     * FileDescriptor method that does not exist on the host JDK, so the+     * unit test supplies the raw fd instead; on-device the real detach+     * above is used and ownership semantics are unchanged.+     */+    internal fun handOff(+        afd: AssetFileDescriptor,+        detachFd: (ParcelFileDescriptor) -> Int,+    ) {+        val fd = detachFd(afd.parcelFileDescriptor)         var handed = false         try {             YuuAvatarNative.setBundledMeshFd(fd, afd.startOffset, afd.length)
library/avatar/src/test/java/com/vayunmathur/library/avatar/YuuAvatarAssetsTest.kt
diff --git a/library/avatar/src/test/java/com/vayunmathur/library/avatar/YuuAvatarAssetsTest.kt b/library/avatar/src/test/java/com/vayunmathur/library/avatar/YuuAvatarAssetsTest.ktindex 24aae00353..35af8f627e 100644--- a/library/avatar/src/test/java/com/vayunmathur/library/avatar/YuuAvatarAssetsTest.kt+++ b/library/avatar/src/test/java/com/vayunmathur/library/avatar/YuuAvatarAssetsTest.kt@@ -35,7 +35,11 @@ class YuuAvatarAssetsTest {             val afd = android.content.res.AssetFileDescriptor(pfd, 0, file.length())             // Ownership moves to native; this must not throw even though the             // bytes are not a real mesh (parsing happens on surface creation).-            YuuAvatarAssets.handOff(afd)+            // The fd is passed raw rather than detached: Robolectric's+            // detachFd() needs a libcore-internal FileDescriptor method the+            // host JDK lacks (NoSuchMethodError), which says nothing about+            // the on-device detach path.+            YuuAvatarAssets.handOff(afd) { it.fd }         } finally {             file.delete()         }