From 79c88ab3719f185a59d4323275ba964c57e78ed7 Mon Sep 17 00:00:00 2001 From: ma-shaoyin Date: Tue, 12 Jul 2022 15:55:59 +0800 Subject: [PATCH] Signed-off-by: ma-shaoyin Changes to be committed: --- .../src/input_method_controller.cpp | 31 ++++++++++--------- 1 file changed, 17 insertions(+), 14 deletions(-) diff --git a/frameworks/inputmethod_controller/src/input_method_controller.cpp b/frameworks/inputmethod_controller/src/input_method_controller.cpp index e8f0241..02f525a 100644 --- a/frameworks/inputmethod_controller/src/input_method_controller.cpp +++ b/frameworks/inputmethod_controller/src/input_method_controller.cpp @@ -341,8 +341,9 @@ using namespace MessageID; void InputMethodController::OnCursorUpdate(CursorInfo cursorInfo) { - if (!mAgent) { - IMSA_HILOGI("InputMethodController::OnCursorUpdate mAgent is nullptr"); + sptr agent = mAgent; + if (agent == nullptr) { + IMSA_HILOGI("InputMethodController::OnCursorUpdate agent is nullptr"); return; } @@ -351,7 +352,7 @@ using namespace MessageID; return; } cursorInfo_ = cursorInfo; - mAgent->OnCursorUpdate(cursorInfo.left, cursorInfo.top, cursorInfo.height); + agent->OnCursorUpdate(cursorInfo.left, cursorInfo.top, cursorInfo.height); } void InputMethodController::OnSelectionChange(std::u16string text, int start, int end) @@ -365,11 +366,12 @@ using namespace MessageID; mSelectOldEnd = mSelectNewEnd; mSelectNewBegin = start; mSelectNewEnd = end; - if (!mAgent) { - IMSA_HILOGI("InputMethodController::OnSelectionChange mAgent is nullptr"); + sptr agent = mAgent; + if (agent == nullptr) { + IMSA_HILOGI("InputMethodController::OnSelectionChange agent is nullptr"); return; } - mAgent->OnSelectionChange(mTextString, mSelectOldBegin, mSelectOldEnd, mSelectNewBegin, mSelectNewEnd); + agent->OnSelectionChange(mTextString, mSelectOldBegin, mSelectOldEnd, mSelectNewBegin, mSelectNewEnd); } void InputMethodController::OnConfigurationChange(Configuration info) @@ -404,18 +406,19 @@ using namespace MessageID; bool InputMethodController::dispatchKeyEvent(std::shared_ptr keyEvent) { IMSA_HILOGI("InputMethodController::dispatchKeyEvent"); - if (!mAgent) { - IMSA_HILOGI("InputMethodController::dispatchKeyEvent mAgent is nullptr"); + sptr agent = mAgent; + if (agent == nullptr) { + IMSA_HILOGI("InputMethodController::dispatchKeyEvent agent is nullptr"); return false; } MessageParcel data; - if (!(data.WriteInterfaceToken(mAgent->GetDescriptor()) + if (!(data.WriteInterfaceToken(agent->GetDescriptor()) && data.WriteInt32(keyEvent->GetKeyCode()) && data.WriteInt32(keyEvent->GetKeyAction()))) { return false; } - return mAgent->DispatchKeyEvent(data); + return agent->DispatchKeyEvent(data); } int32_t InputMethodController::GetEnterKeyType() @@ -432,13 +435,13 @@ using namespace MessageID; void InputMethodController::SetCallingWindow(uint32_t windowId) { + sptr agent = mAgent; IMSA_HILOGI("InputMethodController::SetCallingWindow windowId = %{public}d", windowId); - if (!mAgent) { - IMSA_HILOGI("InputMethodController::SetCallingWindow mAgent is nullptr"); + if (agent == nullptr) { + IMSA_HILOGI("InputMethodController::SetCallingWindow agent is nullptr"); return; } - mAgent->SetCallingWindow(windowId); - return; + agent->SetCallingWindow(windowId); } int32_t InputMethodController::SwitchInputMethod(InputMethodProperty *target)