在主线程中的断点处停止几秒钟后 ANR 崩溃(AOSP - RK3288 框)
ANR crash after a few seconds when stopping at breakpoint in main thread (AOSP - RK3288 box)
我有一个 RK3288 盒子,我正在为其开发应用程序。
我遇到了一个让我很头疼的问题。我无法调试任何东西。
每次我附加调试器时,当我遇到主线程上的断点时,我的应用程序会在几秒钟后崩溃。
以下是发生这种情况时的 logcat:
05-02 20:52:39.734 459-534/system_process I/InputDispatcher: Application is not responding: Window{3026b626 u0 com.kushtrim.playground/com.kushtrim.playground.MainActivity}. It has been 5001.8ms since event, 5001.6ms since wait started. Reason: Waiting to send non-key event because the touched window has not finished processing certain input events that were delivered to it over 500.0ms ago. Wait queue length: 17. Wait queue head age: 5505.1ms.
05-02 20:52:39.794 459-534/system_process I/WindowManagerService: Input event dispatching timed out sending to com.kushtrim.playground/com.kushtrim.playground.MainActivity. Reason: Waiting to send non-key event because the touched window has not finished processing certain input events that were delivered to it over 500.0ms ago. Wait queue length: 17. Wait queue head age: 5505.1ms.
05-02 20:52:39.811 459-482/system_process I/Process: Sending signal. PID: 8790 SIG: 3
05-02 20:52:39.812 8790-8799/com.kushtrim.playground I/art: Thread[5,tid=8799,WaitingInMainSignalCatcherLoop,Thread*=0xb7294b58,peer=0x12c000a0,"Signal Catcher"]: reacting to signal 3
05-02 20:52:39.970 459-482/system_process I/Process: Sending signal. PID: 459 SIG: 3
05-02 20:52:39.970 459-468/system_process I/art: Thread[5,tid=468,WaitingInMainSignalCatcherLoop,Thread*=0xb7113410,peer=0x12c020a0,"Signal Catcher"]: reacting to signal 3
05-02 20:52:39.970 8790-8799/com.kushtrim.playground I/art: Wrote stack traces to '/data/anr/traces.txt'
05-02 20:52:40.123 459-478/system_process E/SensorsHal: poll() failed (Interrupted system call)
05-02 20:52:40.824 459-981/system_process E/WifiHAL: Error polling socket
05-02 20:52:40.900 6611-6661/com.solaborate.hello D/Webrtc_calls: SocketIoStatus conected: true , socketId: 9U55YZnsB0EeSDcHACui
05-02 20:52:41.018 459-482/system_process I/Process: Sending signal. PID: 852 SIG: 3
05-02 20:52:41.019 852-864/com.android.phone I/art: Thread[5,tid=864,WaitingInMainSignalCatcherLoop,Thread*=0xb7113410,peer=0x12c000a0,"Signal Catcher"]: reacting to signal 3
05-02 20:52:41.023 459-1442/system_process W/ActivityManagerService: Missing app error report, app = com.kushtrim.playground crashing = false notResponding = true
05-02 20:52:41.028 459-468/system_process I/art: Wrote stack traces to '/data/anr/traces.txt'
05-02 20:52:41.028 459-482/system_process I/Process: Sending signal. PID: 811 SIG: 3
05-02 20:52:41.029 811-820/com.android.inputmethod.latin I/art: Thread[5,tid=820,WaitingInMainSignalCatcherLoop,Thread*=0xb7112928,peer=0x12c000a0,"Signal Catcher"]: reacting to signal 3
05-02 20:52:41.152 811-820/com.android.inputmethod.latin I/art: Wrote stack traces to '/data/anr/traces.txt'
05-02 20:52:41.152 459-482/system_process I/Process: Sending signal. PID: 628 SIG: 3
05-02 20:52:41.152 628-636/com.android.systemui I/art: Thread[5,tid=636,WaitingInMainSignalCatcherLoop,Thread*=0xb7112928,peer=0x12c000a0,"Signal Catcher"]: reacting to signal 3
05-02 20:52:41.209 852-864/com.android.phone I/art: Wrote stack traces to '/data/anr/traces.txt'
05-02 20:52:41.209 459-482/system_process I/Process: Sending signal. PID: 712 SIG: 3
05-02 20:52:41.209 712-719/com.cghs.stresstest I/art: Thread[5,tid=719,WaitingInMainSignalCatcherLoop,Thread*=0xb7112a18,peer=0x12c000a0,"Signal Catcher"]: reacting to signal 3
05-02 20:52:41.286 712-719/com.cghs.stresstest I/art: Wrote stack traces to '/data/anr/traces.txt'
05-02 20:52:41.286 459-482/system_process I/Process: Sending signal. PID: 591 SIG: 3
05-02 20:52:41.286 591-600/android.process.media I/art: Thread[5,tid=600,WaitingInMainSignalCatcherLoop,Thread*=0xb7112928,peer=0x12c000a0,"Signal Catcher"]: reacting to signal 3
05-02 20:52:41.313 628-636/com.android.systemui I/art: Wrote stack traces to '/data/anr/traces.txt'
05-02 20:52:41.396 591-600/android.process.media I/art: Wrote stack traces to '/data/anr/traces.txt'
05-02 20:52:41.554 459-913/system_process W/ActivityManagerService: Missing app error report, app = com.kushtrim.playground crashing = false notResponding = true
05-02 20:52:42.094 459-944/system_process W/ActivityManagerService: Missing app error report, app = com.kushtrim.playground crashing = false notResponding = true
05-02 20:52:43.304 459-1982/system_process W/ActivityManagerService: Missing app error report, app = com.kushtrim.playground crashing = false notResponding = true
05-02 20:52:43.869 459-482/system_process I/art: Explicit concurrent mark sweep GC freed 58037(3MB) AllocSpace objects, 10(257KB) LOS objects, 33% free, 19MB/28MB, paused 811us total 53.345ms
05-02 20:52:43.883 459-482/system_process W/ProcessCpuTracker: Skipping unknown process pid 9185
05-02 20:52:44.189 459-4388/system_process W/ActivityManagerService: Missing app error report, app = com.kushtrim.playground crashing = false notResponding = true
05-02 20:52:44.418 459-482/system_process I/Process: Sending signal. PID: 1155 SIG: 3
05-02 20:52:44.418 1155-1164/com.waxrain.airplaydmr I/art: Thread[5,tid=1164,WaitingInMainSignalCatcherLoop,Thread*=0xb7112928,peer=0x32c070a0,"Signal Catcher"]: reacting to signal 3
05-02 20:52:44.540 1155-1164/com.waxrain.airplaydmr I/art: Wrote stack traces to '/data/anr/traces.txt'
05-02 20:52:44.549 459-482/system_process E/ActivityManagerService: ANR in com.kushtrim.playground (com.kushtrim.playground/.MainActivity)
PID: 8790
Reason: Input dispatching timed out (Waiting to send non-key event because the touched window has not finished processing certain input events that were delivered to it over 500.0ms ago. Wait queue length: 17. Wait queue head age: 5505.1ms.)
Load: 1.48 / 1.36 / 1.86
CPU usage from 567ms to -4733ms ago:
31% 459/system_server: 14% user + 17% kernel / faults: 6486 minor 5 major
0% 164/debuggerd: 0% user + 0% kernel / faults: 3474 minor 5 major
8.6% 161/surfaceflinger: 5.6% user + 3% kernel / faults: 629 minor
0% 852/com.android.phone: 0% user + 0% kernel / faults: 2463 minor
2.8% 8790/com.kushtrim.playground: 1.1% user + 1.7% kernel / faults: 1497 minor
0.6% 628/com.android.systemui: 0.3% user + 0.2% kernel / faults: 1800 minor 2 major
0% 811/com.android.inputmethod.latin: 0% user + 0% kernel / faults: 2089 minor
2.2% 1155/com.waxrain.airplaydmr: 1.5% user + 0.7% kernel / faults: 1754 minor
2% 174/adbd: 0.1% user + 1.8% kernel / faults: 564 minor
0% 591/android.process.media: 0% user + 0% kernel / faults: 2149 minor 1 major
0% 712/com.cghs.stresstest: 0% user + 0% kernel / faults: 1984 minor
0.9% 69/cfinteractive: 0% user + 0.9% kernel
0.5% 153/dhd_dpc: 0% user + 0.5% kernel
0.5% 155/logd: 0.3% user + 0.1% kernel
0.3% 68/rk-fb: 0% user + 0.3% kernel
0.3% 152/dhd_watchdog_th: 0% user + 0.3% kernel
0.1% 8/rcu_preempt: 0% user + 0.1% kernel
0.1% 14/ksoftirqd/1: 0% user + 0.1% kernel
0.1% 19/ksoftirqd/2: 0% user + 0.1% kernel
0.1% 24/ksoftirqd/3: 0% user + 0.1% kernel
0.1% 67/fb-vsync: 0% user + 0.1% kernel
0.1% 110/mmcqd/0: 0% user + 0.1% kernel
0.1% 122/irq/198-mma8452: 0% user + 0.1% kernel
0.1% 507/mediaserver: 0% user + 0.1% kernel / faults: 12 minor
0% 1174/com.android.settings: 0% user + 0% kernel / faults: 22 minor
0.1% 1252/wdog2: 0% user + 0.1% kernel
0.1% 1486/com.skype.raider: 0.1% user + 0% kernel / faults: 6 minor
0.1% 2355/com.tencent.mm:push: 0% user + 0.1% kernel / faults: 331 minor
0.1% 4835/wpa_supplicant: 0% user + 0.1% kernel
0.1% 6611/com.solaborate.hello: 0.1% user + 0% kernel / faults: 12 minor
0% 7891/kworker/2:2: 0% user + 0% kernel
0.1% 7974/kworker/0:1: 0% user + 0.1% kernel
0.1% 8875/logcat: 0.1% user + 0% kernel
+0% 9168/kworker/u8:4: 0% user + 0% kernel
19% TOTAL: 8.1% user + 11% kernel + 0.3% iowait + 0% softirq
CPU usage from 4062ms to 4577ms later:
7.6% 459/system_server: 3.8% user + 3.8% kernel / faults: 27 minor
3.8% 482/ActivityManager: 1.9% user + 1.9% kernel
1.9% 487/android.display: 1.9% user + 0% kernel
5.7% 161/surfaceflinger: 1.9% user + 3.8% kernel / faults: 14 minor
1.9% 161/surfaceflinger: 1.9% user + 0% kernel
1.9% 314/DispSync: 0% user + 1.9% kernel
1.9% 433/surfaceflinger: 0% user + 1.9% kernel
1.9% 552/Binder_4: 1.9% user + 0% kernel
1.3% 14/ksoftirqd/1: 0% user + 1.3% kernel
1.3% 19/ksoftirqd/2: 0% user + 1.3% kernel
1.4% 153/dhd_dpc: 0% user + 1.4% kernel
1.4% 174/adbd: 0% user + 1.4% kernel / faults: 60 minor
1.4% 174/adbd: 1.4% user + 0% kernel
1.5% 1155/com.waxrain.airplaydmr: 1.5% user + 0% kernel
6.4% TOTAL: 2.4% user + 3.9% kernel
现在,我自己做了一些研究,发现在正常情况下 ANR is triggered when there is no response to a touch event for more than 5s,这似乎就是这里发生的事情。
虽然这对于应用程序的正常运行来说是可以的,但如果我在按钮上放置断点 OnClickListener 就不会发生这种情况,但在我的情况下会发生。
我在任何其他 phone 上都没有发生这种情况,只是在这个板上。
我该怎么做才能解决这个问题,并最终和平调试?
我应该提到我也有 OS 代码(AOSP + 内核),并且我自己有 compiled/installed,所以我可以修改 OS 如果需要的话。
以下是 ANR 跟踪记录(如果有帮助的话):https://pastebin.com/C3dh9rzK
编辑:
这似乎不是应用程序的问题,而是 OS 中的问题。
我能够在一个全新的项目中重现崩溃,我只是在其中添加了一个按钮和一个 OnClickListener。然后我在侦听器中放置了一个断点,附加了调试器并单击了按钮。咔嚓一声。
ANR 可以通过在主线程上有新事件进入时保持主线程来触发。此事件可能是一个输入,也可能像 BroadcastReceiver
捡起 Intent
.
一样简单
这一点很重要,因为您的应用程序可能在您尝试调试的同时在主线程中执行另一项任务。
直接来自 ANRs 上的文档:
This means anything your application is doing in the UI thread that
takes a long time to complete can trigger the ANR dialog because your
application is not giving itself a chance to handle the input event or
intent broadcasts.
您可以在主线程上追踪其他代码 运行 或者您可以尝试下面更大胆的解决方案。
既然你提到你可以修改 AOSP 而这只是为了调试你可以尝试一个史诗般的 hack 让你调试。
ANR超时时间定义在/frameworks/base/libs/ui
路径下的文件InputDispatcher.cpp
中。
const nsecs_t DEFAULT_INPUT_DISPATCHING_TIMEOUT = 5000 * 1000000LL;
没有什么能阻止您更改该值,以便您可以安心调试!
我会尝试类似以下的操作 - 我没有您的有问题的设备,所以我无法自行测试。
在ActivityManagerService.java中(显示ANR对话框的部分):
http://androidxref.com/4.4.4_r1/xref/frameworks/base/services/java/com/android/server/am/ActivityManagerService.java#1124
添加条件:
if (proc != null && proc.debugging) {
return;
}
我不知道您正在构建哪个 Android 版本,因此当然可能与链接文件略有不同。
嗯,我做了一些检查。我注意到使用连接了调试器的 Nexus 5x 并在 onClick 方法中放置一个断点不会启动 ANR。
如果我分离调试器,ANR 将按预期启动。
所以,这就是为什么我猜 SO 正在考虑附加的调试器并忽略(或避免启动)ANR 对话框。
我猜你使用的 SO 与智能手机中使用的略有不同(可能是旧版本?),但这里有一些注意事项。
当主线程被长 运行 任务或任何其他原因阻塞时,会显示 ANR。调试器产生 ANR 是有道理的,因为调试器停止了线程。
检查主线程阻塞的线程不能是主线程。
为了避免 ANR,有必要与检查主线程是否被阻塞的组件进行通信,以表明我们处于调试模式。可能使用另一个版本的 SO 可以为您解决这个问题。
或者阻塞系统中的所有线程运行。
@CJBS 的回答可能对你有用:
android Studio 中的断点可以配置为挂起所有 运行 线程。这应该足以避免 ANR。
有史以来最奇怪的事情,我不敢相信我以前怎么没发现这一点。如果我 运行 来自 Android Studio 的应用程序使用 "Debug app" 按钮 运行s应用程序并附加调试器,它不会因 ANR 而崩溃。如果我 运行 应用程序正常,然后 然后附加调试器 ,就会发生上述问题。
我想我总是做第二个。
知道它在第一个实例中起作用,我开始尝试让它在第二个实例中起作用。
调用此代码(或在开发人员选项中将应用设置为调试)修复了问题:
adb shell am set-debug-app --persistent com.kushtrim.playground
我不确定为什么在这个板上,如果你想附加调试器,必须设置调试应用程序,但在我的 Pixel XL 中不需要。无论如何,问题已解决。
我有一个 RK3288 盒子,我正在为其开发应用程序。
我遇到了一个让我很头疼的问题。我无法调试任何东西。
每次我附加调试器时,当我遇到主线程上的断点时,我的应用程序会在几秒钟后崩溃。
以下是发生这种情况时的 logcat:
05-02 20:52:39.734 459-534/system_process I/InputDispatcher: Application is not responding: Window{3026b626 u0 com.kushtrim.playground/com.kushtrim.playground.MainActivity}. It has been 5001.8ms since event, 5001.6ms since wait started. Reason: Waiting to send non-key event because the touched window has not finished processing certain input events that were delivered to it over 500.0ms ago. Wait queue length: 17. Wait queue head age: 5505.1ms.
05-02 20:52:39.794 459-534/system_process I/WindowManagerService: Input event dispatching timed out sending to com.kushtrim.playground/com.kushtrim.playground.MainActivity. Reason: Waiting to send non-key event because the touched window has not finished processing certain input events that were delivered to it over 500.0ms ago. Wait queue length: 17. Wait queue head age: 5505.1ms.
05-02 20:52:39.811 459-482/system_process I/Process: Sending signal. PID: 8790 SIG: 3
05-02 20:52:39.812 8790-8799/com.kushtrim.playground I/art: Thread[5,tid=8799,WaitingInMainSignalCatcherLoop,Thread*=0xb7294b58,peer=0x12c000a0,"Signal Catcher"]: reacting to signal 3
05-02 20:52:39.970 459-482/system_process I/Process: Sending signal. PID: 459 SIG: 3
05-02 20:52:39.970 459-468/system_process I/art: Thread[5,tid=468,WaitingInMainSignalCatcherLoop,Thread*=0xb7113410,peer=0x12c020a0,"Signal Catcher"]: reacting to signal 3
05-02 20:52:39.970 8790-8799/com.kushtrim.playground I/art: Wrote stack traces to '/data/anr/traces.txt'
05-02 20:52:40.123 459-478/system_process E/SensorsHal: poll() failed (Interrupted system call)
05-02 20:52:40.824 459-981/system_process E/WifiHAL: Error polling socket
05-02 20:52:40.900 6611-6661/com.solaborate.hello D/Webrtc_calls: SocketIoStatus conected: true , socketId: 9U55YZnsB0EeSDcHACui
05-02 20:52:41.018 459-482/system_process I/Process: Sending signal. PID: 852 SIG: 3
05-02 20:52:41.019 852-864/com.android.phone I/art: Thread[5,tid=864,WaitingInMainSignalCatcherLoop,Thread*=0xb7113410,peer=0x12c000a0,"Signal Catcher"]: reacting to signal 3
05-02 20:52:41.023 459-1442/system_process W/ActivityManagerService: Missing app error report, app = com.kushtrim.playground crashing = false notResponding = true
05-02 20:52:41.028 459-468/system_process I/art: Wrote stack traces to '/data/anr/traces.txt'
05-02 20:52:41.028 459-482/system_process I/Process: Sending signal. PID: 811 SIG: 3
05-02 20:52:41.029 811-820/com.android.inputmethod.latin I/art: Thread[5,tid=820,WaitingInMainSignalCatcherLoop,Thread*=0xb7112928,peer=0x12c000a0,"Signal Catcher"]: reacting to signal 3
05-02 20:52:41.152 811-820/com.android.inputmethod.latin I/art: Wrote stack traces to '/data/anr/traces.txt'
05-02 20:52:41.152 459-482/system_process I/Process: Sending signal. PID: 628 SIG: 3
05-02 20:52:41.152 628-636/com.android.systemui I/art: Thread[5,tid=636,WaitingInMainSignalCatcherLoop,Thread*=0xb7112928,peer=0x12c000a0,"Signal Catcher"]: reacting to signal 3
05-02 20:52:41.209 852-864/com.android.phone I/art: Wrote stack traces to '/data/anr/traces.txt'
05-02 20:52:41.209 459-482/system_process I/Process: Sending signal. PID: 712 SIG: 3
05-02 20:52:41.209 712-719/com.cghs.stresstest I/art: Thread[5,tid=719,WaitingInMainSignalCatcherLoop,Thread*=0xb7112a18,peer=0x12c000a0,"Signal Catcher"]: reacting to signal 3
05-02 20:52:41.286 712-719/com.cghs.stresstest I/art: Wrote stack traces to '/data/anr/traces.txt'
05-02 20:52:41.286 459-482/system_process I/Process: Sending signal. PID: 591 SIG: 3
05-02 20:52:41.286 591-600/android.process.media I/art: Thread[5,tid=600,WaitingInMainSignalCatcherLoop,Thread*=0xb7112928,peer=0x12c000a0,"Signal Catcher"]: reacting to signal 3
05-02 20:52:41.313 628-636/com.android.systemui I/art: Wrote stack traces to '/data/anr/traces.txt'
05-02 20:52:41.396 591-600/android.process.media I/art: Wrote stack traces to '/data/anr/traces.txt'
05-02 20:52:41.554 459-913/system_process W/ActivityManagerService: Missing app error report, app = com.kushtrim.playground crashing = false notResponding = true
05-02 20:52:42.094 459-944/system_process W/ActivityManagerService: Missing app error report, app = com.kushtrim.playground crashing = false notResponding = true
05-02 20:52:43.304 459-1982/system_process W/ActivityManagerService: Missing app error report, app = com.kushtrim.playground crashing = false notResponding = true
05-02 20:52:43.869 459-482/system_process I/art: Explicit concurrent mark sweep GC freed 58037(3MB) AllocSpace objects, 10(257KB) LOS objects, 33% free, 19MB/28MB, paused 811us total 53.345ms
05-02 20:52:43.883 459-482/system_process W/ProcessCpuTracker: Skipping unknown process pid 9185
05-02 20:52:44.189 459-4388/system_process W/ActivityManagerService: Missing app error report, app = com.kushtrim.playground crashing = false notResponding = true
05-02 20:52:44.418 459-482/system_process I/Process: Sending signal. PID: 1155 SIG: 3
05-02 20:52:44.418 1155-1164/com.waxrain.airplaydmr I/art: Thread[5,tid=1164,WaitingInMainSignalCatcherLoop,Thread*=0xb7112928,peer=0x32c070a0,"Signal Catcher"]: reacting to signal 3
05-02 20:52:44.540 1155-1164/com.waxrain.airplaydmr I/art: Wrote stack traces to '/data/anr/traces.txt'
05-02 20:52:44.549 459-482/system_process E/ActivityManagerService: ANR in com.kushtrim.playground (com.kushtrim.playground/.MainActivity)
PID: 8790
Reason: Input dispatching timed out (Waiting to send non-key event because the touched window has not finished processing certain input events that were delivered to it over 500.0ms ago. Wait queue length: 17. Wait queue head age: 5505.1ms.)
Load: 1.48 / 1.36 / 1.86
CPU usage from 567ms to -4733ms ago:
31% 459/system_server: 14% user + 17% kernel / faults: 6486 minor 5 major
0% 164/debuggerd: 0% user + 0% kernel / faults: 3474 minor 5 major
8.6% 161/surfaceflinger: 5.6% user + 3% kernel / faults: 629 minor
0% 852/com.android.phone: 0% user + 0% kernel / faults: 2463 minor
2.8% 8790/com.kushtrim.playground: 1.1% user + 1.7% kernel / faults: 1497 minor
0.6% 628/com.android.systemui: 0.3% user + 0.2% kernel / faults: 1800 minor 2 major
0% 811/com.android.inputmethod.latin: 0% user + 0% kernel / faults: 2089 minor
2.2% 1155/com.waxrain.airplaydmr: 1.5% user + 0.7% kernel / faults: 1754 minor
2% 174/adbd: 0.1% user + 1.8% kernel / faults: 564 minor
0% 591/android.process.media: 0% user + 0% kernel / faults: 2149 minor 1 major
0% 712/com.cghs.stresstest: 0% user + 0% kernel / faults: 1984 minor
0.9% 69/cfinteractive: 0% user + 0.9% kernel
0.5% 153/dhd_dpc: 0% user + 0.5% kernel
0.5% 155/logd: 0.3% user + 0.1% kernel
0.3% 68/rk-fb: 0% user + 0.3% kernel
0.3% 152/dhd_watchdog_th: 0% user + 0.3% kernel
0.1% 8/rcu_preempt: 0% user + 0.1% kernel
0.1% 14/ksoftirqd/1: 0% user + 0.1% kernel
0.1% 19/ksoftirqd/2: 0% user + 0.1% kernel
0.1% 24/ksoftirqd/3: 0% user + 0.1% kernel
0.1% 67/fb-vsync: 0% user + 0.1% kernel
0.1% 110/mmcqd/0: 0% user + 0.1% kernel
0.1% 122/irq/198-mma8452: 0% user + 0.1% kernel
0.1% 507/mediaserver: 0% user + 0.1% kernel / faults: 12 minor
0% 1174/com.android.settings: 0% user + 0% kernel / faults: 22 minor
0.1% 1252/wdog2: 0% user + 0.1% kernel
0.1% 1486/com.skype.raider: 0.1% user + 0% kernel / faults: 6 minor
0.1% 2355/com.tencent.mm:push: 0% user + 0.1% kernel / faults: 331 minor
0.1% 4835/wpa_supplicant: 0% user + 0.1% kernel
0.1% 6611/com.solaborate.hello: 0.1% user + 0% kernel / faults: 12 minor
0% 7891/kworker/2:2: 0% user + 0% kernel
0.1% 7974/kworker/0:1: 0% user + 0.1% kernel
0.1% 8875/logcat: 0.1% user + 0% kernel
+0% 9168/kworker/u8:4: 0% user + 0% kernel
19% TOTAL: 8.1% user + 11% kernel + 0.3% iowait + 0% softirq
CPU usage from 4062ms to 4577ms later:
7.6% 459/system_server: 3.8% user + 3.8% kernel / faults: 27 minor
3.8% 482/ActivityManager: 1.9% user + 1.9% kernel
1.9% 487/android.display: 1.9% user + 0% kernel
5.7% 161/surfaceflinger: 1.9% user + 3.8% kernel / faults: 14 minor
1.9% 161/surfaceflinger: 1.9% user + 0% kernel
1.9% 314/DispSync: 0% user + 1.9% kernel
1.9% 433/surfaceflinger: 0% user + 1.9% kernel
1.9% 552/Binder_4: 1.9% user + 0% kernel
1.3% 14/ksoftirqd/1: 0% user + 1.3% kernel
1.3% 19/ksoftirqd/2: 0% user + 1.3% kernel
1.4% 153/dhd_dpc: 0% user + 1.4% kernel
1.4% 174/adbd: 0% user + 1.4% kernel / faults: 60 minor
1.4% 174/adbd: 1.4% user + 0% kernel
1.5% 1155/com.waxrain.airplaydmr: 1.5% user + 0% kernel
6.4% TOTAL: 2.4% user + 3.9% kernel
现在,我自己做了一些研究,发现在正常情况下 ANR is triggered when there is no response to a touch event for more than 5s,这似乎就是这里发生的事情。
虽然这对于应用程序的正常运行来说是可以的,但如果我在按钮上放置断点 OnClickListener 就不会发生这种情况,但在我的情况下会发生。
我在任何其他 phone 上都没有发生这种情况,只是在这个板上。
我该怎么做才能解决这个问题,并最终和平调试?
我应该提到我也有 OS 代码(AOSP + 内核),并且我自己有 compiled/installed,所以我可以修改 OS 如果需要的话。
以下是 ANR 跟踪记录(如果有帮助的话):https://pastebin.com/C3dh9rzK
编辑:
这似乎不是应用程序的问题,而是 OS 中的问题。
我能够在一个全新的项目中重现崩溃,我只是在其中添加了一个按钮和一个 OnClickListener。然后我在侦听器中放置了一个断点,附加了调试器并单击了按钮。咔嚓一声。
ANR 可以通过在主线程上有新事件进入时保持主线程来触发。此事件可能是一个输入,也可能像 BroadcastReceiver
捡起 Intent
.
这一点很重要,因为您的应用程序可能在您尝试调试的同时在主线程中执行另一项任务。
直接来自 ANRs 上的文档:
This means anything your application is doing in the UI thread that takes a long time to complete can trigger the ANR dialog because your application is not giving itself a chance to handle the input event or intent broadcasts.
您可以在主线程上追踪其他代码 运行 或者您可以尝试下面更大胆的解决方案。
既然你提到你可以修改 AOSP 而这只是为了调试你可以尝试一个史诗般的 hack 让你调试。
ANR超时时间定义在/frameworks/base/libs/ui
路径下的文件InputDispatcher.cpp
中。
const nsecs_t DEFAULT_INPUT_DISPATCHING_TIMEOUT = 5000 * 1000000LL;
没有什么能阻止您更改该值,以便您可以安心调试!
我会尝试类似以下的操作 - 我没有您的有问题的设备,所以我无法自行测试。
在ActivityManagerService.java中(显示ANR对话框的部分): http://androidxref.com/4.4.4_r1/xref/frameworks/base/services/java/com/android/server/am/ActivityManagerService.java#1124
添加条件:
if (proc != null && proc.debugging) {
return;
}
我不知道您正在构建哪个 Android 版本,因此当然可能与链接文件略有不同。
嗯,我做了一些检查。我注意到使用连接了调试器的 Nexus 5x 并在 onClick 方法中放置一个断点不会启动 ANR。
如果我分离调试器,ANR 将按预期启动。
所以,这就是为什么我猜 SO 正在考虑附加的调试器并忽略(或避免启动)ANR 对话框。
我猜你使用的 SO 与智能手机中使用的略有不同(可能是旧版本?),但这里有一些注意事项。
当主线程被长 运行 任务或任何其他原因阻塞时,会显示 ANR。调试器产生 ANR 是有道理的,因为调试器停止了线程。
检查主线程阻塞的线程不能是主线程。
为了避免 ANR,有必要与检查主线程是否被阻塞的组件进行通信,以表明我们处于调试模式。可能使用另一个版本的 SO 可以为您解决这个问题。
或者阻塞系统中的所有线程运行。
@CJBS 的回答可能对你有用:
android Studio 中的断点可以配置为挂起所有 运行 线程。这应该足以避免 ANR。
有史以来最奇怪的事情,我不敢相信我以前怎么没发现这一点。如果我 运行 来自 Android Studio 的应用程序使用 "Debug app" 按钮 运行s应用程序并附加调试器,它不会因 ANR 而崩溃。如果我 运行 应用程序正常,然后 然后附加调试器 ,就会发生上述问题。 我想我总是做第二个。
知道它在第一个实例中起作用,我开始尝试让它在第二个实例中起作用。
调用此代码(或在开发人员选项中将应用设置为调试)修复了问题:
adb shell am set-debug-app --persistent com.kushtrim.playground
我不确定为什么在这个板上,如果你想附加调试器,必须设置调试应用程序,但在我的 Pixel XL 中不需要。无论如何,问题已解决。