修复息屏进入对话Bug,优化对话流程
authorxue <2144439972@qq.com>
Thu, 20 Nov 2025 11:14:47 +0000 (19:14 +0800)
committerxue <2144439972@qq.com>
Thu, 20 Nov 2025 11:14:47 +0000 (19:14 +0800)
code/sdk/application/wearable/ln/nativeapp/nativeui/thunderbird/include/ThunderBirdPresenter.h
code/sdk/application/wearable/ln/nativeapp/nativeui/thunderbird/src/ThunderBirdPresenter.cpp

index 3773b7b..1da019c 100644 (file)
@@ -38,6 +38,7 @@ namespace OHOS
         bool isDialogueing{false};//是否进入对话模式
         bool powerKeyPressed{false};//电源键按下标志位,防止重复触发
         bool screenOnFromOff{false};//从息屏状态亮屏的标志位,防止松开时立即息屏
+        bool pendingDialogueJump{false};//等待音频初始化完成后跳转对话界面的标志位
 
         void SetDialogueing(bool dialogueing);//设置对话模式标志位
 
index 15acf9f..813323b 100644 (file)
@@ -126,13 +126,21 @@ namespace OHOS
         int16_t currentView = ThunderBirdMainView::GetInstance()->GetCurrentView();
         int16_t currentSubView = ThunderBirdMainView::GetInstance()->GetCurrentSubView();
         int screenState = uapi_get_screen_state();
-        int originalScreenState = screenState; // 保存原始屏幕状态,用于HandlePowerKey判断
+        int originalScreenState = screenState; // 保存原始屏幕状态,用于判断是否息屏
         
         // 按键事件日志
         WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "OnKeyAct: keyID=%d, keyState=%d, screenState=%d", keyID, keyState, screenState);
         
-        // 刷新息屏计时:任意按键按下时重置屏幕熄灭倒计时
-        if (keyState == InputDevice::STATE_PRESS) {
+        // 息屏后,只有电源键操作有效,其他操作都直接忽略
+        bool isPowerKey = (keyID == static_cast<uint16_t>(ZliteKeyCode::ZLITE_KEY_POWER));
+        if (originalScreenState != 0 && !isPowerKey) {
+            // 息屏状态且不是电源键,直接忽略
+            WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "OnKeyAct: screen is off and key is not power key, ignore keyID=%d", keyID);
+            return true;
+        }
+        
+        // 刷新息屏计时:任意按键按下时重置屏幕熄灭倒计时(只有电源键或已亮屏时才刷新)
+        if (keyState == InputDevice::STATE_PRESS && (isPowerKey || originalScreenState == 0)) {
             uapi_set_screen_on_api();
             // 修复:在调用uapi_set_screen_on_api()后重新获取屏幕状态,确保使用最新的状态
             screenState = uapi_get_screen_state();
@@ -147,7 +155,7 @@ namespace OHOS
                 return HandlePowerKey(keyState, currentView, currentSubView, originalScreenState);
                 
             case static_cast<uint16_t>(ZliteKeyCode::ZLITE_KEY_FUNC):
-                // 非电源键需要亮屏才能处理
+                // 非电源键需要亮屏才能处理(已在上面检查过,这里确保亮屏)
                 if (screenState != 0) {
                     WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "HandleFuncKey: screen is off, ignore");
                     return true;
@@ -156,7 +164,7 @@ namespace OHOS
                 return HandleFuncKey(keyState, currentView, currentSubView, screenState);
                 
             case static_cast<uint16_t>(ZliteKeyCode::ZLITE_KEY_VENDOR_UP):
-                // 非电源键需要亮屏才能处理
+                // 非电源键需要亮屏才能处理(已在上面检查过,这里确保亮屏)
                 if (screenState != 0) {
                     WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "HandleVendorUpKey: screen is off, ignore");
                     return true;
@@ -165,7 +173,7 @@ namespace OHOS
                 return HandleVendorUpKey(keyState, currentView, currentSubView, screenState);
                 
             case static_cast<uint16_t>(ZliteKeyCode::ZLITE_KEY_VENDOR_DOWN):
-                // 非电源键需要亮屏才能处理
+                // 非电源键需要亮屏才能处理(已在上面检查过,这里确保亮屏)
                 if (screenState != 0) {
                     WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "HandleVendorDownKey: screen is off, ignore");
                     return true;
@@ -184,7 +192,25 @@ namespace OHOS
 #ifdef CUSTOM_UTILS
        if(custom_get_factory_test_flag())
         return;
-#endif       
+#endif
+        // 检查是否需要等待音频初始化完成后跳转界面
+        if (pendingDialogueJump && ln_ws_is_audio_initialized()) {
+            pendingDialogueJump = false;
+            WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "音频初始化完成,执行延迟的界面跳转");
+            
+            int16_t currentView = ThunderBirdMainView::GetInstance()->GetCurrentView();
+            ThunderBirdMainView::GetInstance()->ChangeView(currentView, THUNDERBIRD_DIALOGUEVIEW, ThunderBirdDialogueView::THUNDERBIRD_DIALOGUEVIEW_LISTENING);
+            
+            if(currentView == THUNDERBIRD_GUIDEVIEW)
+            {
+                ThunderBirdDialogueView::GetInstance()->Isband(false);
+            }
+            else
+            {
+                ThunderBirdDialogueView::GetInstance()->Isband(true);
+            }
+        }
+       
         //如果在二维码界面 判断是否绑定
         if(ThunderBirdMainView::GetInstance() != nullptr)
        { 
@@ -773,6 +799,13 @@ namespace OHOS
 
     static void HandleFuncKeyLongPressCallBack(void)
     {
+        // 息屏后,长按FUNC键也应该被忽略
+        int screenState = uapi_get_screen_state();
+        if (screenState != 0) {
+            WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "HandleFuncKeyLongPressCallBack: screen is off, ignore");
+            return;
+        }
+        
         if (ThunderBirdPresenter::GetInstance()) {
             ThunderBirdPresenter::GetInstance()->HandleFuncKeyLongPress();
         }
@@ -815,15 +848,27 @@ namespace OHOS
                     }
                 }
                 
-                ThunderBirdMainView::GetInstance()->ChangeView(currentView, THUNDERBIRD_DIALOGUEVIEW, ThunderBirdDialogueView::THUNDERBIRD_DIALOGUEVIEW_LISTENING);
-                if(currentView == THUNDERBIRD_GUIDEVIEW)
+                // 检查音频是否已初始化,如果未初始化则设置标志位等待定时器检查
+                if(ln_ws_is_audio_initialized())
                 {
-                    ThunderBirdDialogueView::GetInstance()->Isband(false);
+                    // 音频已初始化,直接跳转界面
+                    ThunderBirdMainView::GetInstance()->ChangeView(currentView, THUNDERBIRD_DIALOGUEVIEW, ThunderBirdDialogueView::THUNDERBIRD_DIALOGUEVIEW_LISTENING);
+                    if(currentView == THUNDERBIRD_GUIDEVIEW)
+                    {
+                        ThunderBirdDialogueView::GetInstance()->Isband(false);
+                    }
+                    else
+                    {
+                        ThunderBirdDialogueView::GetInstance()->Isband(true);
+                    }
                 }
                 else
                 {
-                    ThunderBirdDialogueView::GetInstance()->Isband(true);
+                    // 音频未初始化,设置标志位,等待定时器检查
+                    pendingDialogueJump = true;
+                    WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "音频未初始化,设置pendingDialogueJump=true,等待定时器检查");
                 }
+                
                 isDialogueing = true;
                 ScreenAlwaysOnCtr(OPEN_SCREEN_ALWAYS_ON); // 打开屏幕常亮
                 // 进入对话模式时记录当前表情