解决4GAI中断对话会死机问题,@薛文强测试次数超过100次,未出现。 1999/1 1999/head 2000/target/1
authorluozheng <1732036298@qq.com>
Tue, 22 Jul 2025 10:04:18 +0000 (18:04 +0800)
committerluozheng <1732036298@qq.com>
Tue, 22 Jul 2025 10:04:18 +0000 (18:04 +0800)
code/sdk/application/wearable/fd230app/nativeui/aivoice/include/AiVoicePresenter.h
code/sdk/application/wearable/fd230app/nativeui/aivoice/src/AiVoicePresenter.cpp

index 257255b..2967eb5 100644 (file)
@@ -14,6 +14,7 @@
 #include "components/ui_time_picker.h"
 #include "components/ui_slider.h"
 #include "ModelListenerSample.h"
+#include <mutex>
 namespace OHOS
 {
     class AiVoiceView;
@@ -74,6 +75,8 @@ namespace OHOS
 
         int preHeight{0};
         bool isScroll{false};
+
+        std::mutex m_mutex;  // 添加互斥锁
     };
 }
 
index 2d30825..fdaeaec 100644 (file)
@@ -27,7 +27,7 @@
 #include "aivoice/include/AiVoiceSelectView.h"
 
 #include "cat1_ws.h"
-
+#include <mutex>
 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<std::mutex> 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;
         }