Modern Apps git

← Modern-Apps.git

photos: keep face/CLIP recognition inert when the JNI link fails

Commit
36d47e1876f3b2b5fa937f5d0832c07c6cac7485
Author
Vayun Mathur <[email protected]>
When
2026-11-07 08:14 UTC (29 days ago)
Parents
80652f5
FaceDetector/FaceEmbedder and ClipHandle bring-up can throw
LinkageError (missing JNI symbol or framework method) when
libmodelrunner.so loads incomplete; FaceRecognizer.ensureInit only
caught IllegalStateException/IOException and ClipEmbedder documented
never-throws bring-up, so both crashed instead of reporting
unavailable. Catch LinkageError at both call sites.

(cherry picked from commit da1051e223e7718dcff82890231ae6727134c771)

Diff

photos/src/main/java/com/vayunmathur/photos/util/ClipEmbedder.kt
diff --git a/photos/src/main/java/com/vayunmathur/photos/util/ClipEmbedder.kt b/photos/src/main/java/com/vayunmathur/photos/util/ClipEmbedder.ktindex ddbaaed3e6..aa55bf2269 100644--- a/photos/src/main/java/com/vayunmathur/photos/util/ClipEmbedder.kt+++ b/photos/src/main/java/com/vayunmathur/photos/util/ClipEmbedder.kt@@ -117,7 +117,17 @@ object ClipEmbedder {             }             // Construction never throws: an absent, compressed or malformed asset, a missing             // `libmodelrunner.so` and a device without fp16 compute all come back unavailable.-            val handle = ClipHandle.inAssets(app.assets)+            // A linkage failure inside the native bring-up is an Error, so guard+            // it here to keep that guarantee on incomplete host/device libraries.+            val handle = try {+                ClipHandle.inAssets(app.assets)+            } catch (_: LinkageError) {+                Log.error(TAG, "TinyCLIP native library incomplete")+                return false+            } catch (_: RuntimeException) {+                Log.error(TAG, "TinyCLIP bring-up failed")+                return false+            }             if (!handle.isAvailable) {                 Log.error(TAG, "cannot bring up $handle")                 handle.close()
photos/src/main/java/com/vayunmathur/photos/util/FaceRecognizer.kt
diff --git a/photos/src/main/java/com/vayunmathur/photos/util/FaceRecognizer.kt b/photos/src/main/java/com/vayunmathur/photos/util/FaceRecognizer.ktindex 481b4521e1..43e57cd244 100644--- a/photos/src/main/java/com/vayunmathur/photos/util/FaceRecognizer.kt+++ b/photos/src/main/java/com/vayunmathur/photos/util/FaceRecognizer.kt@@ -123,6 +123,16 @@ object FaceRecognizer {             embedder = null             initFailed = true             false+        } catch (e: LinkageError) {+            // A loaded-but-incomplete libmodelrunner.so (missing JNI symbol) is+            // an Error, not an Exception: without this the "models unavailable"+            // degradation crashes instead of reporting unavailable.+            Log.error(TAG, "Face models unavailable", e)+            closeQuietly()+            detector = null+            embedder = null+            initFailed = true+            false         }     }