Avoid IME related crash in buggy devices
This commit is contained in:
@@ -1,15 +1,40 @@
|
|||||||
package com.tutpro.baresip
|
package com.tutpro.baresip
|
||||||
|
|
||||||
import android.app.Application
|
import android.app.Application
|
||||||
|
import android.os.DeadObjectException
|
||||||
|
import android.util.Log
|
||||||
|
|
||||||
class BaresipApp : Application() {
|
class BaresipApp : Application() {
|
||||||
|
|
||||||
override fun onCreate() {
|
override fun onCreate() {
|
||||||
super.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) {
|
if (!BaresipService.libraryLoaded) {
|
||||||
Log.i(TAG, "Loading baresip library")
|
Log.i(TAG, "Loading baresip library")
|
||||||
System.loadLibrary("baresip")
|
System.loadLibrary("baresip")
|
||||||
BaresipService.libraryLoaded = true
|
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
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user