From: xue <2144439972@qq.com> Date: Wed, 18 Mar 2026 09:03:44 +0000 (+0800) Subject: 产测死机问题修复 X-Git-Url: http://git.snicker.com.cn/css/static/gitweb.css?a=commitdiff_plain;h=ff901499f09c8c3599903c4bf7b2787de12fe27a;p=mirrors%2FFD230.git 产测死机问题修复 --- diff --git a/code/sdk/zhihui/UI/producttest/src/testGPS.cpp b/code/sdk/zhihui/UI/producttest/src/testGPS.cpp index 6268510cf..67ed9305b 100644 --- a/code/sdk/zhihui/UI/producttest/src/testGPS.cpp +++ b/code/sdk/zhihui/UI/producttest/src/testGPS.cpp @@ -246,7 +246,12 @@ namespace OHOS void gpsdataTimerCallBackproc() { - GraphicService::GetInstance()->PostGraphicEvent(std::bind(&testGPSView::gpsdataTimerCallBack,testGPSView::GetInstance())); + // 定时器是全局的,可能在界面已销毁后仍然触发一次,这里要做空指针防护 + testGPSView *view = testGPSView::GetInstance(); + if (view == nullptr) { + return; + } + GraphicService::GetInstance()->PostGraphicEvent(std::bind(&testGPSView::gpsdataTimerCallBack, view)); } diff --git a/code/sdk/zhihui/UI/producttest/src/testold.cpp b/code/sdk/zhihui/UI/producttest/src/testold.cpp index 55ee56be7..97d50bb82 100644 --- a/code/sdk/zhihui/UI/producttest/src/testold.cpp +++ b/code/sdk/zhihui/UI/producttest/src/testold.cpp @@ -18,7 +18,8 @@ namespace OHOS static testoldView *g_pSystemAboutTheWatchView{nullptr}; static osTimerId_t g_aging_timer=NULL; - + static volatile bool g_aging_view_valid = false; /* 防止定时器回调在界面销毁后访问已释放控件导致 Load access fault */ + #ifdef SUPPORT_FACTORY_SERVICE static ble_aging_t aging_t; #endif @@ -69,6 +70,7 @@ namespace OHOS { if(testoldScrollView) { + g_aging_view_valid = false; testoldScrollView->RemoveAll(); if (g_aging_timer != NULL) @@ -266,10 +268,14 @@ namespace OHOS { do_custom_fileoperate_service_check_msg(CUSTOM_FILEOPERATE_MSG_TYPE_AGING_DATA_READ, NULL, 0); LOS_Msleep(500); -#ifdef SUPPORT_FACTORY_SERVICE + if (!g_aging_view_valid) { + return; /* 界面已退出或正在清理,避免 use-after-free 导致 Load access fault */ + } factorytest_get_aging_data(&aging_t); -#endif OHOS::testoldView *pview = OHOS::testoldView::GetInstance(); + if (pview == nullptr || !g_aging_view_valid) { + return; + } pview->setdata(); } @@ -594,6 +600,7 @@ namespace OHOS testoldScrollView->SetTouchable(true); testoldScrollView->SetDraggable(true); + g_aging_view_valid = true; /* 界面已就绪,允许定时器回调访问 UI */ g_aging_timer = osTimerNew((osTimerFunc_t)msgupdateTimerCallBack, osTimerPeriodic, NULL, NULL); osStatus_t ret = osTimerStart(g_aging_timer, 1000 * 60 * 10);