From: luozheng <1732036298@qq.com> Date: Tue, 22 Jul 2025 10:04:18 +0000 (+0800) Subject: 解决4GAI中断对话会死机问题,@薛文强测试次数超过100次,未出现。 X-Git-Url: http://git.snicker.com.cn/css/static/gitweb.css?a=commitdiff_plain;h=refs%2Fchanges%2F2000%2Ftarget%2F1;p=mirrors%2FFD230.git 解决4GAI中断对话会死机问题,@薛文强测试次数超过100次,未出现。 --- diff --git a/code/sdk/application/wearable/fd230app/nativeui/aivoice/include/AiVoicePresenter.h b/code/sdk/application/wearable/fd230app/nativeui/aivoice/include/AiVoicePresenter.h index 257255bd2..2967eb596 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/aivoice/include/AiVoicePresenter.h +++ b/code/sdk/application/wearable/fd230app/nativeui/aivoice/include/AiVoicePresenter.h @@ -14,6 +14,7 @@ #include "components/ui_time_picker.h" #include "components/ui_slider.h" #include "ModelListenerSample.h" +#include namespace OHOS { class AiVoiceView; @@ -74,6 +75,8 @@ namespace OHOS int preHeight{0}; bool isScroll{false}; + + std::mutex m_mutex; // 添加互斥锁 }; } diff --git a/code/sdk/application/wearable/fd230app/nativeui/aivoice/src/AiVoicePresenter.cpp b/code/sdk/application/wearable/fd230app/nativeui/aivoice/src/AiVoicePresenter.cpp index 2d30825d0..fdaeaecce 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/aivoice/src/AiVoicePresenter.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/aivoice/src/AiVoicePresenter.cpp @@ -27,7 +27,7 @@ #include "aivoice/include/AiVoiceSelectView.h" #include "cat1_ws.h" - +#include namespace OHOS { #ifdef __cplusplus @@ -146,7 +146,8 @@ namespace OHOS if (model->GetSelect4gorbt() == AI_SELECT_4G) { preHeight = 0; - ChangeViewAndLogicOperator(model->GetCurView(), AIVOICE_RETURN_RESULT_TEXT_VIEWID); + if (model->GetCurView() == AIVOICE_LISTENING_VIEWID || model->GetCurView() == AIVOICE_THINKING_VIEWID) + ChangeViewAndLogicOperator(model->GetCurView(), AIVOICE_RETURN_RESULT_TEXT_VIEWID); } else if (model->GetSelect4gorbt() == AI_SELECT_BT) { @@ -285,6 +286,10 @@ namespace OHOS bool AiVoicePresenter::ChangeViewAndLogicOperator(int16_t hideView, int16_t showView) { WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AiVoicePresenter::ChangeViewOperator"); + + // 加锁,作用域结束时自动释放锁 + std::lock_guard lock(m_mutex); + bool isSameView = (hideView == showView); if (isSameView) { @@ -591,6 +596,14 @@ namespace OHOS auto it = viewIdMap.find(viewId); if (it != viewIdMap.end()) { + if (it->first != ALERT_APPBLUETOOTH_AND_4GNETWORK_ENSURE_BUTTON_VIEW_ID) + { + if (model->GetSelect4gorbt() == AI_SELECT_4G) + { + dinit_ai_task(); + LOS_Msleep(50); + } + } ChangeViewAndLogicOperator(it->second.first, it->second.second); return true; }