修复 AppKiller 引起的死循环崩溃和前端解析兼容性

This commit is contained in:
844143714@qq,com 2026-04-30 01:49:27 +08:00
parent 2e389918f3
commit 62ce781993
2 changed files with 25 additions and 19 deletions

View File

@ -503,22 +503,23 @@
showPttResult("[回调] " + msg); showPttResult("[回调] " + msg);
}; };
// ES6 特性测试函数 // ES6 特性测试函数(通过 eval 避免阻塞旧版 JS 引擎整体解析)
function testES6Features() { function testES6Features() {
try { try {
const arr = [1, 2, 3]; eval("\
const [a, ...rest] = arr; const arr = [1, 2, 3];\
let sum = rest.reduce((acc, val) => acc + val, 0); const [a, ...rest] = arr;\
const myMap = new Map(); let sum = rest.reduce((acc, val) => acc + val, 0);\
myMap.set('key', `Sum is ${sum}`); const myMap = new Map();\
myMap.set('key', `Sum is ${sum}`);\
new Promise((resolve) => { new Promise((resolve) => {\
setTimeout(() => resolve(myMap.get('key')), 100); setTimeout(() => resolve(myMap.get('key')), 100);\
}).then(res => { }).then(res => {\
alert(`ES6 引擎测试成功!\n解构: a=${a}\nPromise/Map 返回: ${res}`); alert(`ES6 引擎测试成功!\\n解构: a=${a}\\nPromise/Map 返回: ${res}`);\
}); });\
");
} catch(e) { } catch(e) {
alert("ES6 测试失败: " + e.message); alert("ES6 测试失败 (当前环境可能不支持): " + e.message);
} }
} }
function addExitText() { function addExitText() {

View File

@ -5,7 +5,12 @@ import timber.log.Timber
object AppKiller { object AppKiller {
private var isKilling = false
fun killApp(context: Context, isCrash: Boolean = false) { fun killApp(context: Context, isCrash: Boolean = false) {
if (isKilling) return
isKilling = true
Timber.tag("AppKiller").i("Starting app cleanup. isCrash: $isCrash") Timber.tag("AppKiller").i("Starting app cleanup. isCrash: $isCrash")
try { try {
@ -30,12 +35,6 @@ object AppKiller {
Timber.tag("AppKiller").e(e, "Printer close failed") Timber.tag("AppKiller").e(e, "Printer close failed")
} }
try {
LogManager.shutdown()
} catch (e: Exception) {
// ignore
}
Timber.tag("AppKiller").i("Cleanup finished. Killing process.") Timber.tag("AppKiller").i("Cleanup finished. Killing process.")
if (!isCrash) { if (!isCrash) {
@ -44,6 +43,12 @@ object AppKiller {
} catch (e: Exception) {} } catch (e: Exception) {}
} }
try {
// LogManager.shutdown() 会关闭其内部的线程池
// 调用后绝对不能再使用 Timber 打印日志,否则会抛出 RejectedExecutionException 导致死循环
LogManager.shutdown()
} catch (e: Exception) {}
android.os.Process.killProcess(android.os.Process.myPid()) android.os.Process.killProcess(android.os.Process.myPid())
} }