From 9d8a83529c5871504818414e93d17c6998badff4 Mon Sep 17 00:00:00 2001 From: ma-shaoyin Date: Sun, 14 Apr 2024 16:51:59 +0800 Subject: [PATCH] Signed-off-by: ma-shaoyin Changes to be committed: --- services/include/input_method_system_ability.h | 2 +- services/src/input_method_system_ability.cpp | 14 ++++++++++---- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/services/include/input_method_system_ability.h b/services/include/input_method_system_ability.h index 91e7a994..dff8381b 100644 --- a/services/include/input_method_system_ability.h +++ b/services/include/input_method_system_ability.h @@ -158,7 +158,7 @@ private: std::atomic imeStarting_ = false; std::mutex switchImeMutex_; std::atomic switchImeCount_ = 0; - uint32_t targetSwitchCount_ = 0; + std::atomic targetSwitchCount_ = 0; }; } // namespace MiscServices } // namespace OHOS diff --git a/services/src/input_method_system_ability.cpp b/services/src/input_method_system_ability.cpp index 3468f99f..8aa72ca4 100644 --- a/services/src/input_method_system_ability.cpp +++ b/services/src/input_method_system_ability.cpp @@ -927,9 +927,14 @@ int32_t InputMethodSystemAbility::SwitchByCombinationKey(uint32_t state) if (CombinationKey::IsMatch(CombinationKeyFunction::SWITCH_IME, state)) { IMSA_HILOGI("switch ime"); { + if (switchImeCount_.load() != 0) { + IMSA_HILOGI("already has switch ime task."); + ++targetSwitchCount_; + return ErrorCode::NO_ERROR; + } std::lock_guard lock(switchImeMutex_); // 0 means current swich ime task count. - if (!switchQueue_.IsEmpty() || switchImeCount_.load() != 0) { + if (switchImeCount_.load() != 0) { IMSA_HILOGI("already has switch ime task."); ++targetSwitchCount_; return ErrorCode::NO_ERROR; @@ -942,7 +947,6 @@ int32_t InputMethodSystemAbility::SwitchByCombinationKey(uint32_t state) std::lock_guard lock(switchImeMutex_); SwitchType(); --switchImeCount_; - targetSwitchCount_ = 0; }; // 0 means delay time is 0. serviceHandler_->PostTask(switchTask, "SwitchImeTask", 0, AppExecFwk::EventQueue::Priority::IMMEDIATE); @@ -1006,8 +1010,10 @@ int32_t InputMethodSystemAbility::SwitchLanguage() int32_t InputMethodSystemAbility::SwitchType() { SwitchInfo switchInfo = { std::chrono::system_clock::now(), "", "" }; - int32_t ret = ImeInfoInquirer::GetInstance().GetSwitchInfoBySwitchCount( - switchInfo, userId_, enableImeOn_, targetSwitchCount_); + auto cacheCount = targetSwitchCount_.load(); + targetSwitchCount_.store(0); + int32_t ret = + ImeInfoInquirer::GetInstance().GetSwitchInfoBySwitchCount(switchInfo, userId_, enableImeOn_, cacheCount); if (ret != ErrorCode::NO_ERROR) { IMSA_HILOGE("Get next SwitchInfo failed, stop switching ime."); return ret;