修复 AppKiller 引起的死循环崩溃和前端解析兼容性
This commit is contained in:
parent
2e389918f3
commit
62ce781993
|
|
@ -503,22 +503,23 @@
|
|||
showPttResult("[回调] " + msg);
|
||||
};
|
||||
|
||||
// ES6 特性测试函数
|
||||
// ES6 特性测试函数(通过 eval 避免阻塞旧版 JS 引擎整体解析)
|
||||
function testES6Features() {
|
||||
try {
|
||||
const arr = [1, 2, 3];
|
||||
const [a, ...rest] = arr;
|
||||
let sum = rest.reduce((acc, val) => acc + val, 0);
|
||||
const myMap = new Map();
|
||||
myMap.set('key', `Sum is ${sum}`);
|
||||
|
||||
new Promise((resolve) => {
|
||||
setTimeout(() => resolve(myMap.get('key')), 100);
|
||||
}).then(res => {
|
||||
alert(`ES6 引擎测试成功!\n解构: a=${a}\nPromise/Map 返回: ${res}`);
|
||||
});
|
||||
eval("\
|
||||
const arr = [1, 2, 3];\
|
||||
const [a, ...rest] = arr;\
|
||||
let sum = rest.reduce((acc, val) => acc + val, 0);\
|
||||
const myMap = new Map();\
|
||||
myMap.set('key', `Sum is ${sum}`);\
|
||||
new Promise((resolve) => {\
|
||||
setTimeout(() => resolve(myMap.get('key')), 100);\
|
||||
}).then(res => {\
|
||||
alert(`ES6 引擎测试成功!\\n解构: a=${a}\\nPromise/Map 返回: ${res}`);\
|
||||
});\
|
||||
");
|
||||
} catch(e) {
|
||||
alert("ES6 测试失败: " + e.message);
|
||||
alert("ES6 测试失败 (当前环境可能不支持): " + e.message);
|
||||
}
|
||||
}
|
||||
function addExitText() {
|
||||
|
|
|
|||
|
|
@ -5,7 +5,12 @@ import timber.log.Timber
|
|||
|
||||
object AppKiller {
|
||||
|
||||
private var isKilling = false
|
||||
|
||||
fun killApp(context: Context, isCrash: Boolean = false) {
|
||||
if (isKilling) return
|
||||
isKilling = true
|
||||
|
||||
Timber.tag("AppKiller").i("Starting app cleanup. isCrash: $isCrash")
|
||||
|
||||
try {
|
||||
|
|
@ -30,12 +35,6 @@ object AppKiller {
|
|||
Timber.tag("AppKiller").e(e, "Printer close failed")
|
||||
}
|
||||
|
||||
try {
|
||||
LogManager.shutdown()
|
||||
} catch (e: Exception) {
|
||||
// ignore
|
||||
}
|
||||
|
||||
Timber.tag("AppKiller").i("Cleanup finished. Killing process.")
|
||||
|
||||
if (!isCrash) {
|
||||
|
|
@ -44,6 +43,12 @@ object AppKiller {
|
|||
} catch (e: Exception) {}
|
||||
}
|
||||
|
||||
try {
|
||||
// LogManager.shutdown() 会关闭其内部的线程池
|
||||
// 调用后绝对不能再使用 Timber 打印日志,否则会抛出 RejectedExecutionException 导致死循环
|
||||
LogManager.shutdown()
|
||||
} catch (e: Exception) {}
|
||||
|
||||
android.os.Process.killProcess(android.os.Process.myPid())
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue