From 6a863905937c4bde4eb1db8ed66a1a2d235dcc85 Mon Sep 17 00:00:00 2001 From: Juha Heinanen Date: Sun, 26 Apr 2026 07:48:23 +0300 Subject: [PATCH] Avoid IME related crash in buggy devices --- .../kotlin/com/tutpro/baresip/BaresipApp.kt | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/app/src/main/kotlin/com/tutpro/baresip/BaresipApp.kt b/app/src/main/kotlin/com/tutpro/baresip/BaresipApp.kt index b5062e2e..29c21b69 100644 --- a/app/src/main/kotlin/com/tutpro/baresip/BaresipApp.kt +++ b/app/src/main/kotlin/com/tutpro/baresip/BaresipApp.kt @@ -1,15 +1,40 @@ package com.tutpro.baresip import android.app.Application +import android.os.DeadObjectException +import android.util.Log class BaresipApp : Application() { override fun onCreate() { super.onCreate() + + val defaultHandler = Thread.getDefaultUncaughtExceptionHandler() + Thread.setDefaultUncaughtExceptionHandler { thread, throwable -> + if (isImeDeadObjectException(throwable)) { + Log.e(TAG, "Caught DeadObjectException from IME: $throwable") + } else { + defaultHandler?.uncaughtException(thread, throwable) + } + } + if (!BaresipService.libraryLoaded) { Log.i(TAG, "Loading baresip library") System.loadLibrary("baresip") BaresipService.libraryLoaded = true } } + + private fun isImeDeadObjectException(throwable: Throwable): Boolean { + var cause: Throwable? = throwable + while (cause != null) { + if (cause is DeadObjectException) { + if (cause.stackTrace.any { it.methodName == "updateCursorAnchorInfo" }) { + return true + } + } + cause = cause.cause + } + return false + } }