diff --git a/frameworks/native/inputmethod_controller/src/input_method_controller.cpp b/frameworks/native/inputmethod_controller/src/input_method_controller.cpp index 4ba7568266398a56c8009e7f8ed5ede0d4c22b55..868b477a9024f688b820a0cecdd7831f1e345371 100644 --- a/frameworks/native/inputmethod_controller/src/input_method_controller.cpp +++ b/frameworks/native/inputmethod_controller/src/input_method_controller.cpp @@ -53,13 +53,19 @@ std::mutex InputMethodController::instanceLock_; std::mutex InputMethodController::logLock_; int InputMethodController::keyEventCountInPeriod_ = 0; std::chrono::system_clock::time_point InputMethodController::startLogTime_ = system_clock::now(); +std::mutex InputMethodController::printTextChangeMutex_; +int32_t InputMethodController::textChangeCountInPeriod_ = 0; +std::chrono::steady_clock::time_point InputMethodController::textChangeStartLogTime_ = steady_clock::now(); constexpr int32_t LOOP_COUNT = 5; constexpr int32_t LOG_MAX_TIME = 20; +constexpr int32_t LOG_INSERT_MAX_TIME = 20; // 20s +constexpr int32_t LOG_INSERT_MIN_TIME = 5; // 5s constexpr int64_t DELAY_TIME = 100; constexpr int32_t ACE_DEAL_TIME_OUT = 200; constexpr int32_t MAX_PLACEHOLDER_SIZE = 255; // 256 utf16 char constexpr int32_t MAX_ABILITY_NAME_SIZE = 127; // 127 utf16 char static constexpr int32_t MAX_TIMEOUT = 2500; +constexpr int64_t DISPATCH_KEYBOARD_TIME_OUT = 5; // 5ms constexpr size_t MAX_AGENT_NUMBER = 2; const std::string IME_MIRROR_NAME = "proxyIme_IME_MIRROR"; InputMethodController::InputMethodController() @@ -959,6 +965,7 @@ void InputMethodController::PrintKeyEventLog() int32_t InputMethodController::DispatchKeyEvent(std::shared_ptr keyEvent, KeyEventCallback callback) { + int64_t startTime = duration_cast(system_clock::now().time_since_epoch()).count(); PrintKeyEventLog(); KeyEventInfo keyEventInfo = { std::chrono::system_clock::now(), keyEvent }; keyEventQueue_.Push(keyEventInfo); @@ -1000,6 +1007,10 @@ int32_t InputMethodController::DispatchKeyEvent(std::shared_ptr k keyEventRetHandler_.RemoveKeyEventCbInfo(cbId); } keyEventQueue_.Pop(); + int64_t endTime = duration_cast(system_clock::now().time_since_epoch()).count(); + if (endTime - startTime > DISPATCH_KEYBOARD_TIME_OUT) { + IMSA_HILOGW("DispatchKeyEvent timeout: [%{public}" PRId64 ", %{public}" PRId64 "].", startTime, endTime); + } return ret; } @@ -1232,6 +1243,11 @@ void InputMethodController::OnInputStop(bool isStopInactiveClient, sptr(now - textChangeStartLogTime_).count() > LOG_INSERT_MIN_TIME && + std::chrono::duration_cast(now - textChangeStartLogTime_).count() < LOG_INSERT_MAX_TIME) { + IMSA_HILOGW("unbind before insertText PrintTextChangeLogCount: %{public}d !", textChangeCountInPeriod_); + } if (proxy == nullptr) { IMSA_HILOGD("proxy is nullptr."); return; @@ -1396,7 +1412,7 @@ int32_t InputMethodController::InsertText(const std::u16string &text) IMSA_HILOGD("ACE InsertText."); listener->InsertTextV2(text); } - + PrintTextChangeLog(); PrintLogIfAceTimeout(start); return ErrorCode::NO_ERROR; } @@ -1619,6 +1635,20 @@ void InputMethodController::PrintLogIfAceTimeout(int64_t start) } } +void InputMethodController::PrintTextChangeLog() +{ + std::lock_guard lock(printTextChangeMutex_); + auto now = steady_clock::now(); + if (textChangeCountInPeriod_ == 0) { + textChangeStartLogTime_ = now; + } + textChangeCountInPeriod_++; + if (std::chrono::duration_cast(now - textChangeStartLogTime_).count() >= LOG_INSERT_MAX_TIME) { + IMSA_HILOGW("PrintTextChangeLogCount: %{public}d, ACE_InsertText success!", textChangeCountInPeriod_); + textChangeCountInPeriod_ = 0; + } +} + int32_t InputMethodController::ReceivePrivateCommand( const std::unordered_map &privateCommand) { @@ -1692,6 +1722,7 @@ int32_t InputMethodController::SetPreviewTextInner(const std::string &text, cons InputMethodSyncTrace aceTracer("ACE_SetPreviewText"); ret = listener->SetPreviewTextV2(Str8ToStr16(text), range); } + PrintTextChangeLog(); PrintLogIfAceTimeout(start); if (ret != ErrorCode::NO_ERROR) { IMSA_HILOGE("failed to SetPreviewText: %{public}d!", ret); diff --git a/frameworks/native/inputmethod_controller/src/input_method_utils.cpp b/frameworks/native/inputmethod_controller/src/input_method_utils.cpp index 080a217fc7665491f8be91bc5da7b97a7bbe8e7b..fd4a01f401462d1af8c935f6c0624a54c8650901 100644 --- a/frameworks/native/inputmethod_controller/src/input_method_utils.cpp +++ b/frameworks/native/inputmethod_controller/src/input_method_utils.cpp @@ -240,7 +240,7 @@ bool Value::Marshalling(Parcel &out) const return false; } if (valueMap.size() == 0) { - IMSA_HILOGE("valueMap size is zero!"); + IMSA_HILOGD("valueMap size is zero!"); return true; } for (auto& it : valueMap) { diff --git a/interfaces/inner_api/inputmethod_controller/include/input_method_controller.h b/interfaces/inner_api/inputmethod_controller/include/input_method_controller.h index 1ea657d0d5a69e01b25261407c1185b19d9c47bd..a2183f3bf441c2d6e0519a9416b558cdaea96d36 100644 --- a/interfaces/inner_api/inputmethod_controller/include/input_method_controller.h +++ b/interfaces/inner_api/inputmethod_controller/include/input_method_controller.h @@ -1025,6 +1025,7 @@ private: void SetAgent(const sptr &agentObject, const std::string &bundleName); std::shared_ptr GetAgent(); void PrintLogIfAceTimeout(int64_t start); + void PrintTextChangeLog(); void PrintKeyEventLog(); std::shared_ptr GetMsgHandlerCallback(); int32_t IsValidTextConfig(const TextConfig &textConfig); @@ -1079,6 +1080,9 @@ private: static std::mutex logLock_; static int keyEventCountInPeriod_; static std::chrono::system_clock::time_point startLogTime_; + static std::mutex printTextChangeMutex_; + static int32_t textChangeCountInPeriod_; + static std::chrono::steady_clock::time_point textChangeStartLogTime_; std::atomic_bool isEditable_{ false }; std::atomic_bool isBound_{ false }; diff --git a/services/src/input_method_system_ability.cpp b/services/src/input_method_system_ability.cpp index 694bcb94ff63ec9cb25e26a7e9abc3cbd59cc40b..f9c7d33d15f5752e1d4c5d5ef4de51e94d97e8b4 100644 --- a/services/src/input_method_system_ability.cpp +++ b/services/src/input_method_system_ability.cpp @@ -677,9 +677,12 @@ int32_t InputMethodSystemAbility::StartInputInner( { auto userId = GetCallingUserId(); AccessTokenID tokenId = IPCSkeleton::GetCallingTokenID(); - if (!identityChecker_->IsBroker(tokenId) && !identityChecker_->IsFocused(IPCSkeleton::GetCallingPid(), tokenId, - IdentityChecker::INVALID_PID, true, inputClientInfo.config.abilityToken)) { - return ErrorCode::ERROR_CLIENT_NOT_FOCUSED; + if (!identityChecker_->IsFocused(IPCSkeleton::GetCallingPid(), tokenId, IdentityChecker::INVALID_PID, true, + inputClientInfo.config.abilityToken)) { + if (!identityChecker_->IsBroker(tokenId)) { + return ErrorCode::ERROR_CLIENT_NOT_FOCUSED; + } + IMSA_HILOGW("is broker attach!"); } auto session = UserSessionManager::GetInstance().GetUserSession(userId); if (session == nullptr) {