games-chess: treat Maia linkage failure as AI unavailable
- Commit
7479566533859f2fe03e26b80075d1b1602d34e7- Author
- Vayun Mathur <[email protected]>
- When
- 2026-11-07 11:44 UTC (29 days ago)
- Parents
a49b8c7
MaiaEngine.ensure() called MaiaHandle.inAssets unguarded. On runtimes where the native bridge cannot link (Robolectric's ParcelFileDescriptor lacks getOwnerId, i.e. NoSuchMethodError - a LinkageError, not an Exception), the error escaped viewModelScope and crashed any host of ChessViewModel, including MainActivity under Robolectric. That is precisely the documented 'no libmodelrunner.so for this ABI' case, so ensure() now maps LinkageError to unavailable (null), exactly like a failed Vulkan probe. No behavior change where the model loads. Unblocks the MainActivity Robolectric launch test in the pass-3 screen commit. (cherry picked from commit 5b1a6b125d8e3b9ad40f52acd74e02c7b8f8498f)
Diff
games/chess/src/main/java/com/vayunmathur/games/chess/util/MaiaEngine.kt
diff --git a/games/chess/src/main/java/com/vayunmathur/games/chess/util/MaiaEngine.kt b/games/chess/src/main/java/com/vayunmathur/games/chess/util/MaiaEngine.ktindex 791bd7ee0a..f12f6ac6d2 100644--- a/games/chess/src/main/java/com/vayunmathur/games/chess/util/MaiaEngine.kt+++ b/games/chess/src/main/java/com/vayunmathur/games/chess/util/MaiaEngine.kt@@ -155,7 +155,14 @@ class MaiaEngine(private val context: Context) { model?.let { return it } if (closed || attempts >= MAX_ATTEMPTS) return null attempts++- val handle = MaiaHandle.inAssets(context.assets)+ // A missing/unloadable native runtime surfaces as a LinkageError (e.g.+ // NoSuchMethodError from ParcelFileDescriptor on runtimes without the+ // API), which is exactly the "AI unavailable on this device" case.+ val handle = try {+ MaiaHandle.inAssets(context.assets)+ } catch (_: LinkageError) {+ return null+ } if (!handle.isAvailable) { handle.close() return null