From e21ec4ba9caab49d1ae1db84d29cfdde0045ac81 Mon Sep 17 00:00:00 2001 From: xue <2144439972@qq.com> Date: Thu, 20 Nov 2025 19:14:47 +0800 Subject: [PATCH] =?utf8?q?=E4=BF=AE=E5=A4=8D=E6=81=AF=E5=B1=8F=E8=BF=9B?= =?utf8?q?=E5=85=A5=E5=AF=B9=E8=AF=9DBug=EF=BC=8C=E4=BC=98=E5=8C=96?= =?utf8?q?=E5=AF=B9=E8=AF=9D=E6=B5=81=E7=A8=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- .../include/ThunderBirdPresenter.h | 1 + .../thunderbird/src/ThunderBirdPresenter.cpp | 67 ++++++++++++++++--- 2 files changed, 57 insertions(+), 11 deletions(-) diff --git a/code/sdk/application/wearable/ln/nativeapp/nativeui/thunderbird/include/ThunderBirdPresenter.h b/code/sdk/application/wearable/ln/nativeapp/nativeui/thunderbird/include/ThunderBirdPresenter.h index 3773b7be4..1da019c25 100644 --- a/code/sdk/application/wearable/ln/nativeapp/nativeui/thunderbird/include/ThunderBirdPresenter.h +++ b/code/sdk/application/wearable/ln/nativeapp/nativeui/thunderbird/include/ThunderBirdPresenter.h @@ -38,6 +38,7 @@ namespace OHOS bool isDialogueing{false};//是否进入对话模式 bool powerKeyPressed{false};//电源键按下标志位,防止重复触发 bool screenOnFromOff{false};//从息屏状态亮屏的标志位,防止松开时立即息屏 + bool pendingDialogueJump{false};//等待音频初始化完成后跳转对话界面的标志位 void SetDialogueing(bool dialogueing);//设置对话模式标志位 diff --git a/code/sdk/application/wearable/ln/nativeapp/nativeui/thunderbird/src/ThunderBirdPresenter.cpp b/code/sdk/application/wearable/ln/nativeapp/nativeui/thunderbird/src/ThunderBirdPresenter.cpp index 15acf9f29..813323b06 100644 --- a/code/sdk/application/wearable/ln/nativeapp/nativeui/thunderbird/src/ThunderBirdPresenter.cpp +++ b/code/sdk/application/wearable/ln/nativeapp/nativeui/thunderbird/src/ThunderBirdPresenter.cpp @@ -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(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(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(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(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); // 打开屏幕常亮 // 进入对话模式时记录当前表情 -- 2.17.1