记一次尴尬的应用程序崩溃!事件起因是对一个应用添加了一个简单功能,即实现对人员密码的校验,密码校验走的http请求,请求成功与否需要toast并更新页面UI,例如改改字符什么的简单操作。但问题来了,总是莫名其妙的出现程序崩溃,而且还是native层的InputDispatcher崩溃,折磨了几天找不到原因,最后终于让我想明白了。
先上native层报错提示:
2023-11-28 15:14:06.539 10940-10940/? A/DEBUG: *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
2023-11-28 15:14:06.540 10940-10940/? A/DEBUG: Build fingerprint: 'alps/full_k62v1_64_bsp/k62v1_64_bsp:10/QP1A.190711.020/B31:user/release-keys'
2023-11-28 15:14:06.540 10940-10940/? A/DEBUG: Revision: '0'
2023-11-28 15:14:06.540 10940-10940/? A/DEBUG: ABI: 'arm64'
2023-11-28 15:14:06.542 10940-10940/? A/DEBUG: Timestamp: 2023-11-28 15:14:06+0800
2023-11-28 15:14:06.542 10940-10940/? A/DEBUG: pid: 10805, tid: 10838, name: RenderThread >>> com.sgsg.hdpdaapp <<<
2023-11-28 15:14:06.542 10940-10940/? A/DEBUG: uid: 10223
2023-11-28 15:14:06.542 10940-10940/? A/DEBUG: signal 11 (SIGSEGV), code 1 (SEGV_MAPERR), fault addr 0x643036f1f74b04
2023-11-28 15:14:06.542 10940-10940/? A/DEBUG: x0 0000007216c57b68 x1 0000000064313933 x2 0000000000000001 x3 0000007217175120
2023-11-28 15:14:06.543 10940-10940/? A/DEBUG: x4 000000721ad11e28 x5 0000007216e9e630 x6 0000000000000000 x7 000000726af27fe5
2023-11-28 15:14:06.543 10940-10940/? A/DEBUG: x8 6164303561326638 x9 0000000190c4e4cc x10 0000000033613062 x11 0000000000000000
2023-11-28 15:14:06.543 10940-10940/? A/DEBUG: x12 0000007216c58328 x13 0000007216c58328 x14 0000007217101d80 x15 000000000000000d
2023-11-28 15:14:06.543 10940-10940/? A/DEBUG: x16 0000007307514380 x17 00000073070aece8 x18 000000721a79e000 x19 0000000000000001
2023-11-28 15:14:06.543 10940-10940/? A/DEBUG: x20 0000007216c57b00 x21 0000007217175120 x22 000000721ad14020 x23 0000007277faba80
2023-11-28 15:14:06.543 10940-10940/? A/DEBUG: x24 0000007217175120 x25 000000721ad14020 x26 0000007216c57b00 x27 0000000000000001
2023-11-28 15:14:06.543 10940-10940/? A/DEBUG: x28 0000007216e9e630 x29 000000721ad11aa0
2023-11-28 15:14:06.543 10940-10940/? A/DEBUG: sp 000000721ad11a50 lr 00000073070aa734 pc 00000073070aecf0
2023-11-28 15:14:06.615 10940-10940/? A/DEBUG: backtrace:
2023-11-28 15:14:06.615 10940-10940/? A/DEBUG: #00 pc 0000000000361cf0 /system/lib64/libhwui.so (GrGLProgramDataManager::set1f(GrResourceHandle<GrGLSLProgramDataManager::UniformHandleKind>, float) const+8) (BuildId: 0591cf420be9730a7d8df6bf18e00243)
2023-11-28 15:14:06.615 10940-10940/? A/DEBUG: #01 pc 000000000035d730 /system/lib64/libhwui.so (GrGLProgram::setRenderTargetState(GrRenderTarget const*, GrSurfaceOrigin, GrPrimitiveProcessor const&)+424) (BuildId: 0591cf420be9730a7d8df6bf18e00243)
2023-11-28 15:14:06.616 10940-10940/? A/DEBUG: #02 pc 000000000035d0f8 /system/lib64/libhwui.so (GrGLProgram::updateUniformsAndTextureBindings(GrRenderTarget const*, GrSurfaceOrigin, GrPrimitiveProcessor const&, GrPipeline const&, GrTextureProxy const* const*)+56) (BuildId: 0591cf420be9730a7d8df6bf18e00243)
2023-11-28 15:14:06.616 10940-10940/? A/DEBUG: #03 pc 000000000035c224 /system/lib64/libhwui.so (GrGLGpu::flushGLState(GrRenderTarget*, GrSurfaceOrigin, GrPrimitiveProcessor const&, GrPipeline const&, GrPipeline::FixedDynamicState const*, GrPipeline::DynamicStateArrays const*, int, bool)+340) (BuildId: 0591cf420be9730a7d8df6bf18e00243)
2023-11-28 15:14:06.616 10940-10940/? A/DEBUG: #04 pc 000000000035baa4 /system/lib64/libhwui.so (GrGLGpu::draw(GrRenderTarget*, GrSurfaceOrigin, GrPrimitiveProcessor const&, GrPipeline const&, GrPipeline::FixedDynamicState const*, GrPipeline::DynamicStateArrays const*, GrMesh const*, int)+188) (BuildId: 0591cf420be9730a7d8df6bf18e00243)
2023-11-28 15:14:06.616 10940-10940/? A/DEBUG: #05 pc 000000000035b9d8 /system/lib64/libhwui.so (GrGLGpuRTCommandBuffer::onDraw(GrPrimitiveProcessor const&, GrPipeline const&, GrPipeline::FixedDynamicState const*, GrPipeline::DynamicStateArrays const*, GrMesh const*, int, SkRect const&)+56) (BuildId: 0591cf420be9730a7d8df6bf18e00243)
2023-11-28 15:14:06.616 10940-10940/? A/DEBUG: #06 pc 00000000003348c0 /system/lib64/libhwui.so (GrGpuRTCommandBuffer::draw(GrPrimitiveProcessor const&, GrPipeline const&, GrPipeline::FixedDynamicState const*, GrPipeline::DynamicStateArrays const*, GrMesh const*, int, SkRect const&)+176) (BuildId: 0591cf420be9730a7d8df6bf18e00243)
2023-11-28 15:14:06.616 10940-10940/? A/DEBUG: #07 pc 00000000003342ac /system/lib64/libhwui.so (GrOpFlushState::executeDrawsAndUploadsForMeshDrawOp(GrOp const*, SkRect const&, GrProcessorSet&&, unsigned int, GrUserStencilSettings const*)+340) (BuildId: 0591cf420be9730a7d8df6bf18e00243)
2023-11-28 15:14:06.616 10940-10940/? A/DEBUG: #08 pc 000000000061c030 /system/lib64/libhwui.so (GrOp::execute(GrOpFlushState*, SkRect const&)+80) (BuildId: 0591cf420be9730a7d8df6bf18e00243)
2023-11-28 15:14:06.616 10940-10940/? A/DEBUG: #09 pc 00000000002e1640 /system/lib64/libhwui.so (GrRenderTargetOpList::onExecute(GrOpFlushState*)+352) (BuildId: 0591cf420be9730a7d8df6bf18e00243)
2023-11-28 15:14:06.616 10940-10940/? A/DEBUG: #10 pc 00000000003ab1d8 /system/lib64/libhwui.so (GrDrawingManager::executeOpLists(int, int, GrOpFlushState*, int*)+408) (BuildId: 0591cf420be9730a7d8df6bf18e00243)
2023-11-28 15:14:06.616 10940-10940/? A/DEBUG: #11 pc 00000000003c3b10 /system/lib64/libhwui.so (GrDrawingManager::flush(GrSurfaceProxy*, SkSurface::BackendSurfaceAccess, GrFlushFlags, int, GrBackendSemaphore*, void (*)(void*), void*)+1184) (BuildId: 0591cf420be9730a7d8df6bf18e00243)
2023-11-28 15:14:06.616 10940-10940/? A/DEBUG: #12 pc 00000000003c356c /system/lib64/libhwui.so (GrDrawingManager::prepareSurfaceForExternalIO(GrSurfaceProxy*, SkSurface::BackendSurfaceAccess, GrFlushFlags, int, GrBackendSemaphore*, void (*)(void*), void*)+196) (BuildId: 0591cf420be9730a7d8df6bf18e00243)
2023-11-28 15:14:06.616 10940-10940/? A/DEBUG: #13 pc 00000000003c3360 /system/lib64/libhwui.so (GrRenderTargetContext::prepareForExternalIO(SkSurface::BackendSurfaceAccess, GrFlushFlags, int, GrBackendSemaphore*, void (*)(void*), void*)+120) (BuildId: 0591cf420be9730a7d8df6bf18e00243)
2023-11-28 15:14:06.616 10940-10940/? A/DEBUG: #14 pc 00000000003cf120 /system/lib64/libhwui.so (android::uirenderer::skiapipeline::SkiaPipeline::renderFrame(android::uirenderer::LayerUpdateQueue const&, SkRect const&, std::__1::vector<android::sp<android::uirenderer::RenderNode>, std::__1::allocator<android::sp<android::uirenderer::RenderNode>>> const&, bool, android::uirenderer::Rect const&, sk_sp<SkSurface>, SkMatrix const&)+224) (BuildId: 0591cf420be9730a7d8df6bf18e00243)
2023-11-28 15:14:06.616 10940-10940/? A/DEBUG: #15 pc 000000000027e6e4 /system/lib64/libhwui.so (android::uirenderer::skiapipeline::SkiaOpenGLPipeline::draw(android::uirenderer::renderthread::Frame const&, SkRect const&, SkRect const&, android::uirenderer::LightGeometry const&, android::uirenderer::LayerUpdateQueue*, android::uirenderer::Rect const&, bool, android::uirenderer::LightInfo const&, std::__1::vector<android::sp<android::uirenderer::RenderNode>, std::__1::allocator<android::sp<android::uirenderer::RenderNode>>> const&, android::uirenderer::FrameInfoVisualizer*)+436) (BuildId: 0591cf420be9730a7d8df6bf18e00243)
2023-11-28 15:14:06.616 10940-10940/? A/DEBUG: #16 pc 00000000003c05e4 /system/lib64/libhwui.so (android::uirenderer::renderthread::CanvasContext::draw()+252) (BuildId: 0591cf420be9730a7d8df6bf18e00243)
2023-11-28 15:14:06.616 10940-10940/? A/DEBUG: #17 pc 00000000003bf780 /system/lib64/libhwui.so (_ZNSt3__110__function6__funcIZN7android10uirenderer12renderthread13DrawFrameTask11postAndWaitEvE3$_0NS_9allocatorIS6_EEFvvEEclEv$c303f2d2360db58ed70a2d0ac7ed911b+216) (BuildId: 0591cf420be9730a7d8df6bf18e00243)
2023-11-28 15:14:06.616 10940-10940/? A/DEBUG: #18 pc 00000000003d2374 /system/lib64/libhwui.so (android::uirenderer::WorkQueue::process()+228) (BuildId: 0591cf420be9730a7d8df6bf18e00243)
2023-11-28 15:14:06.617 10940-10940/? A/DEBUG: #19 pc 00000000003d20a0 /system/lib64/libhwui.so (android::uirenderer::renderthread::RenderThread::threadLoop()+80) (BuildId: 0591cf420be9730a7d8df6bf18e00243)
2023-11-28 15:14:06.617 10940-10940/? A/DEBUG: #20 pc 00000000000137a4 /system/lib64/libutils.so (android::Thread::_threadLoop(void*)+284) (BuildId: f013cbada038685234657c61db8227dc)
2023-11-28 15:14:06.617 10940-10940/? A/DEBUG: #21 pc 00000000000e2364 /apex/com.android.runtime/lib64/bionic/libc.so (__pthread_start(void*)+36) (BuildId: 2a5abdc9c768b33656f7aa8d9ce5cf54)
2023-11-28 15:14:06.617 10940-10940/? A/DEBUG: #22 pc 0000000000083d98 /apex/com.android.runtime/lib64/bionic/libc.so (__start_thread+64) (BuildId: 2a5abdc9c768b33656f7aa8d9ce5cf54)
2023-11-28 15:14:07.347 682-682/? E//system/bin/tombstoned: Tombstone written to: /data/tombstones/tombstone_09
2023-11-28 15:14:07.452 1073-1090/? E/GraphicExt: GraphicExtModuleLoader::CreateGraphicExtInstance false
2023-11-28 15:14:07.470 1073-1191/? E/InputDispatcher: channel 'e5fcb8e Toast (server)' ~ Channel is unrecoverably broken and will be disposed!
2023-11-28 15:14:07.470 1073-1191/? E/InputDispatcher: channel '57bf925 com.sgsg.hdpdaapp/com.sgsg.hdpdaapp.activity.PDAHandoverOutActivity (server)' ~ Channel is unrecoverably broken and will be disposed!
2023-11-28 15:14:07.470 1073-1191/? E/InputDispatcher: channel '5e148a9 com.sgsg.hdpdaapp/com.sgsg.hdpdaapp.activity.PDAHandoverVertifyActivity (server)' ~ Channel is unrecoverably broken and will be disposed!
2023-11-28 15:14:07.471 1073-1191/? E/InputDispatcher: channel '8ba0952 com.sgsg.hdpdaapp/com.sgsg.hdpdaapp.activity.Main2Activity (server)' ~ Channel is unrecoverably broken and will be disposed!
其实在日志中就可以看出,是事件的分发机制出了冲突,后续终于我想明白了,toast是系统层的UI操作,而我自身页面的UI操作是我自身的程序进程。如果我如此操作:
App.toast("xxxx",0);
TextView.setText("xxx");
TextView.setBackgroundResource(xxx);
那么这样会随机出现问题的,因为toast时调用的是launch进程的UI绘制,它会去lockCavans屏幕,而这时你又立马去对自己进程的UI进行操作,这时就会出现冲突,它无法去完成其中的某项绘制,从而造成程序的崩溃。解决的方法是对自身的UI绘制代码加上postDealy(500),延迟500毫秒后再做UI绘制。