From 9d8f560ff9d63814cf8b134757bbf9068f321376 Mon Sep 17 00:00:00 2001 From: cy7717 Date: Wed, 9 Jul 2025 22:47:10 +0800 Subject: [PATCH] mod for etext dit agent abnormal Signed-off-by: cy7717 --- .../include/input_data_channel_proxy_wrap.h | 4 +- .../src/input_data_channel_proxy_wrap.cpp | 68 ++++++++++------- .../src/input_method_ability.cpp | 9 ++- .../IInputDataChannel.idl | 27 ++++--- .../include/input_data_channel_service_impl.h | 29 ++++---- .../src/input_data_channel_service_impl.cpp | 73 +++++++++---------- .../src/input_method_controller.cpp | 9 ++- .../include/input_method_controller.h | 6 +- .../cpp_test/src/ima_text_edit_test.cpp | 6 +- .../src/input_method_ability_test.cpp | 8 +- .../src/input_method_controller_test.cpp | 15 ++++ 11 files changed, 142 insertions(+), 112 deletions(-) diff --git a/frameworks/native/inputmethod_ability/include/input_data_channel_proxy_wrap.h b/frameworks/native/inputmethod_ability/include/input_data_channel_proxy_wrap.h index dbdf79f71..8c1794bbc 100644 --- a/frameworks/native/inputmethod_ability/include/input_data_channel_proxy_wrap.h +++ b/frameworks/native/inputmethod_ability/include/input_data_channel_proxy_wrap.h @@ -51,7 +51,8 @@ struct ResponseHandler { }; class InputDataChannelProxyWrap { public: - explicit InputDataChannelProxyWrap(const std::shared_ptr &channel); + InputDataChannelProxyWrap( + const std::shared_ptr &channel, const sptr &agentObject); ~InputDataChannelProxyWrap(); int32_t InsertText(const std::string &text, const AsyncIpcCallBack &callback = nullptr); @@ -88,6 +89,7 @@ private: std::map> rspHandlers_; std::mutex channelMutex_; std::shared_ptr channel_ = nullptr; + sptr agentObject_ = nullptr; }; } // namespace MiscServices } // namespace OHOS diff --git a/frameworks/native/inputmethod_ability/src/input_data_channel_proxy_wrap.cpp b/frameworks/native/inputmethod_ability/src/input_data_channel_proxy_wrap.cpp index 2f479012a..a5366fc14 100644 --- a/frameworks/native/inputmethod_ability/src/input_data_channel_proxy_wrap.cpp +++ b/frameworks/native/inputmethod_ability/src/input_data_channel_proxy_wrap.cpp @@ -25,13 +25,15 @@ namespace OHOS { namespace MiscServices { constexpr std::size_t MESSAGE_UNANSWERED_MAX_NUMBER = 1000; -InputDataChannelProxyWrap::InputDataChannelProxyWrap(const std::shared_ptr &channel) +InputDataChannelProxyWrap::InputDataChannelProxyWrap( + const std::shared_ptr &channel, const sptr &agentObject) { auto now = std::chrono::steady_clock::now(); auto duration = now.time_since_epoch(); msgId_ = static_cast(std::chrono::duration_cast(duration).count()); msgId_ = msgId_ ? msgId_ : ++msgId_; channel_ = channel; + agentObject_ = agentObject; } InputDataChannelProxyWrap::~InputDataChannelProxyWrap() @@ -40,24 +42,27 @@ InputDataChannelProxyWrap::~InputDataChannelProxyWrap() int32_t InputDataChannelProxyWrap::InsertText(const std::string &text, const AsyncIpcCallBack &callback) { - auto work = [text](uint64_t msgId, const std::shared_ptr &channel) -> int32_t { - return channel->InsertText(text, msgId); + auto work = [agentObject = agentObject_, text]( + uint64_t msgId, const std::shared_ptr &channel) -> int32_t { + return channel->InsertText(text, msgId, agentObject); }; return Request(callback, work, callback == nullptr); } int32_t InputDataChannelProxyWrap::DeleteForward(int32_t length, const AsyncIpcCallBack &callback) { - auto work = [length](uint64_t msgId, const std::shared_ptr &channel) -> int32_t { - return channel->DeleteForward(length, msgId); + auto work = [agentObject = agentObject_, length]( + uint64_t msgId, const std::shared_ptr &channel) -> int32_t { + return channel->DeleteForward(length, msgId, agentObject); }; return Request(callback, work, callback == nullptr); } int32_t InputDataChannelProxyWrap::DeleteBackward(int32_t length, const AsyncIpcCallBack &callback) { - auto work = [length](uint64_t msgId, const std::shared_ptr &channel) -> int32_t { - return channel->DeleteBackward(length, msgId); + auto work = [agentObject = agentObject_, length]( + uint64_t msgId, const std::shared_ptr &channel) -> int32_t { + return channel->DeleteBackward(length, msgId, agentObject); }; return Request(callback, work, callback == nullptr); } @@ -65,8 +70,9 @@ int32_t InputDataChannelProxyWrap::DeleteBackward(int32_t length, const AsyncIpc int32_t InputDataChannelProxyWrap::GetTextBeforeCursor( int32_t number, std::string &text, const AsyncIpcCallBack &callback) { - auto work = [number](uint64_t msgId, const std::shared_ptr &channel) -> int32_t { - return channel->GetTextBeforeCursor(number, msgId); + auto work = [agentObject = agentObject_, number]( + uint64_t msgId, const std::shared_ptr &channel) -> int32_t { + return channel->GetTextBeforeCursor(number, msgId, agentObject); }; SyncOutput output = nullptr; if (callback == nullptr) { @@ -78,8 +84,9 @@ int32_t InputDataChannelProxyWrap::GetTextBeforeCursor( int32_t InputDataChannelProxyWrap::GetTextAfterCursor( int32_t number, std::string &text, const AsyncIpcCallBack &callback) { - auto work = [number, text](uint64_t msgId, const std::shared_ptr &channel) -> int32_t { - return channel->GetTextAfterCursor(number, msgId); + auto work = [agentObject = agentObject_, number, text]( + uint64_t msgId, const std::shared_ptr &channel) -> int32_t { + return channel->GetTextAfterCursor(number, msgId, agentObject); }; SyncOutput output = nullptr; if (callback == nullptr) { @@ -90,24 +97,27 @@ int32_t InputDataChannelProxyWrap::GetTextAfterCursor( int32_t InputDataChannelProxyWrap::SendFunctionKey(int32_t funcKey, const AsyncIpcCallBack &callback) { - auto work = [funcKey](uint64_t msgId, const std::shared_ptr &channel) -> int32_t { - return channel->SendFunctionKey(funcKey, msgId); + auto work = [agentObject = agentObject_, funcKey]( + uint64_t msgId, const std::shared_ptr &channel) -> int32_t { + return channel->SendFunctionKey(funcKey, msgId, agentObject); }; return Request(callback, work, callback == nullptr); } int32_t InputDataChannelProxyWrap::MoveCursor(int32_t keyCode, const AsyncIpcCallBack &callback) { - auto work = [keyCode](uint64_t msgId, const std::shared_ptr &channel) -> int32_t { - return channel->MoveCursor(keyCode, msgId); + auto work = [agentObject = agentObject_, keyCode]( + uint64_t msgId, const std::shared_ptr &channel) -> int32_t { + return channel->MoveCursor(keyCode, msgId, agentObject); }; return Request(callback, work, callback == nullptr); } int32_t InputDataChannelProxyWrap::SelectByRange(int32_t start, int32_t end, const AsyncIpcCallBack &callback) { - auto work = [start, end](uint64_t msgId, const std::shared_ptr &channel) -> int32_t { - return channel->SelectByRange(start, end, msgId); + auto work = [agentObject = agentObject_, start, end]( + uint64_t msgId, const std::shared_ptr &channel) -> int32_t { + return channel->SelectByRange(start, end, msgId, agentObject); }; return Request(callback, work, callback == nullptr); } @@ -115,25 +125,27 @@ int32_t InputDataChannelProxyWrap::SelectByRange(int32_t start, int32_t end, con int32_t InputDataChannelProxyWrap::SelectByMovement( int32_t direction, int32_t cursorMoveSkip, const AsyncIpcCallBack &callback) { - auto work = [direction, cursorMoveSkip]( + auto work = [agentObject = agentObject_, direction, cursorMoveSkip]( uint64_t msgId, const std::shared_ptr &channel) -> int32_t { - return channel->SelectByMovement(direction, cursorMoveSkip, msgId); + return channel->SelectByMovement(direction, cursorMoveSkip, msgId, agentObject); }; return Request(callback, work, callback == nullptr); } int32_t InputDataChannelProxyWrap::HandleExtendAction(int32_t action, const AsyncIpcCallBack &callback) { - auto work = [action](uint64_t msgId, const std::shared_ptr &channel) -> int32_t { - return channel->HandleExtendAction(action, msgId); + auto work = [agentObject = agentObject_, action]( + uint64_t msgId, const std::shared_ptr &channel) -> int32_t { + return channel->HandleExtendAction(action, msgId, agentObject); }; return Request(callback, work, callback == nullptr); } int32_t InputDataChannelProxyWrap::GetTextIndexAtCursor(int32_t &index, const AsyncIpcCallBack &callback) { - auto work = [](uint64_t msgId, const std::shared_ptr &channel) -> int32_t { - return channel->GetTextIndexAtCursor(msgId); + auto work = [agentObject = agentObject_]( + uint64_t msgId, const std::shared_ptr &channel) -> int32_t { + return channel->GetTextIndexAtCursor(msgId, agentObject); }; SyncOutput output = nullptr; if (callback == nullptr) { @@ -145,16 +157,18 @@ int32_t InputDataChannelProxyWrap::GetTextIndexAtCursor(int32_t &index, const As int32_t InputDataChannelProxyWrap::SetPreviewText( const std::string &text, const RangeInner &range, const AsyncIpcCallBack &callback) { - auto work = [text, range](uint64_t msgId, const std::shared_ptr &channel) -> int32_t { - return channel->SetPreviewText(text, range, msgId); + auto work = [agentObject = agentObject_, text, range]( + uint64_t msgId, const std::shared_ptr &channel) -> int32_t { + return channel->SetPreviewText(text, range, msgId, agentObject); }; return Request(callback, work, callback == nullptr); } int32_t InputDataChannelProxyWrap::FinishTextPreview(const AsyncIpcCallBack &callback) { - auto work = [](uint64_t msgId, const std::shared_ptr &channel) -> int32_t { - return channel->FinishTextPreview(msgId); + auto work = [agentObject = agentObject_]( + uint64_t msgId, const std::shared_ptr &channel) -> int32_t { + return channel->FinishTextPreview(msgId, agentObject); }; return Request(callback, work, callback == nullptr); } diff --git a/frameworks/native/inputmethod_ability/src/input_method_ability.cpp b/frameworks/native/inputmethod_ability/src/input_method_ability.cpp index a4656c99d..d039712bd 100644 --- a/frameworks/native/inputmethod_ability/src/input_method_ability.cpp +++ b/frameworks/native/inputmethod_ability/src/input_method_ability.cpp @@ -864,14 +864,15 @@ void InputMethodAbility::SetInputDataChannel(const sptr &object) IMSA_HILOGE("failed to create channel proxy!"); return; } - auto channelWrap = std::make_shared(channelProxy); + sptr agentObject = nullptr; + if (agentStub_ != nullptr) { + agentObject = agentStub_->AsObject(); + } + auto channelWrap = std::make_shared(channelProxy, agentObject); if (channelWrap == nullptr) { IMSA_HILOGE("failed to create channel wrap!"); return; } - if (agentStub_ != nullptr) { - channelProxy->SetSpareAgent(agentStub_->AsObject()); - } if (dataChannelProxyWrap_ != nullptr) { dataChannelProxyWrap_->ClearRspHandlers(); } diff --git a/frameworks/native/inputmethod_controller/IInputDataChannel.idl b/frameworks/native/inputmethod_controller/IInputDataChannel.idl index be653439b..011eebb14 100644 --- a/frameworks/native/inputmethod_controller/IInputDataChannel.idl +++ b/frameworks/native/inputmethod_controller/IInputDataChannel.idl @@ -22,26 +22,25 @@ sequenceable input_method_utils..OHOS.MiscServices.RangeInner; sequenceable input_method_utils..OHOS.MiscServices.ArrayBuffer; sequenceable OHOS.IRemoteObject; interface OHOS.MiscServices.IInputDataChannel { - [ipccode 0, oneway] void InsertText([in] String text, [in] unsigned long msgId); - [oneway] void DeleteForward([in] int length, [in] unsigned long msgId); - [oneway] void DeleteBackward([in] int length, [in] unsigned long msgId); - [oneway] void GetTextBeforeCursor([in] int number, [in] unsigned long msgId); - [oneway] void GetTextAfterCursor([in] int number, [in] unsigned long msgId); + [ipccode 0, oneway] void InsertText([in] String text, [in] unsigned long msgId, [in] IRemoteObject agent); + [oneway] void DeleteForward([in] int length, [in] unsigned long msgId, [in] IRemoteObject agent); + [oneway] void DeleteBackward([in] int length, [in] unsigned long msgId, [in] IRemoteObject agent); + [oneway] void GetTextBeforeCursor([in] int number, [in] unsigned long msgId, [in] IRemoteObject agent); + [oneway] void GetTextAfterCursor([in] int number, [in] unsigned long msgId, [in] IRemoteObject agent); void GetTextConfig([out] struct TextTotalConfigInner textConfiginner); [oneway] void SendKeyboardStatus([in] int status); - [oneway] void SendFunctionKey([in] int funcKey, [in] unsigned long msgId); - [oneway] void MoveCursor([in] int keyCode, [in] unsigned long msgId); + [oneway] void SendFunctionKey([in] int funcKey, [in] unsigned long msgId, [in] IRemoteObject agent); + [oneway] void MoveCursor([in] int keyCode, [in] unsigned long msgId, [in] IRemoteObject agent); void GetEnterKeyType([out] int keyType); void GetInputPattern([out] int inputPattern); - [oneway] void SelectByRange([in] int start, [in] int end, [in] unsigned long msgId); - [oneway] void SelectByMovement([in] int direction, [in] int cursorMoveSkip, [in] unsigned long msgId); - [oneway] void HandleExtendAction([in] int action, [in] unsigned long msgId); - [oneway] void GetTextIndexAtCursor([in] unsigned long msgId); + [oneway] void SelectByRange([in] int start, [in] int end, [in] unsigned long msgId, [in] IRemoteObject agent); + [oneway] void SelectByMovement([in] int direction, [in] int cursorMoveSkip, [in] unsigned long msgId, [in] IRemoteObject agent); + [oneway] void HandleExtendAction([in] int action, [in] unsigned long msgId, [in] IRemoteObject agent); + [oneway] void GetTextIndexAtCursor([in] unsigned long msgId, [in] IRemoteObject agent); [oneway] void NotifyPanelStatusInfo([in] PanelStatusInfoInner info); [oneway] void NotifyKeyboardHeight([in] unsigned int height); void SendPrivateCommand([in] Value value); - [oneway] void SetPreviewText([in] String text, [in] RangeInner rangeInner, [in] unsigned long msgId); - [oneway] void FinishTextPreview([in] unsigned long msgId); + [oneway] void SetPreviewText([in] String text, [in] RangeInner rangeInner, [in] unsigned long msgId, [in] IRemoteObject agent); + [oneway] void FinishTextPreview([in] unsigned long msgId, [in] IRemoteObject agent); void SendMessage([in] ArrayBuffer arraybuffer); - [oneway] void SetSpareAgent([in] IRemoteObject agent); } diff --git a/frameworks/native/inputmethod_controller/include/input_data_channel_service_impl.h b/frameworks/native/inputmethod_controller/include/input_data_channel_service_impl.h index 785e993be..4b0124877 100644 --- a/frameworks/native/inputmethod_controller/include/input_data_channel_service_impl.h +++ b/frameworks/native/inputmethod_controller/include/input_data_channel_service_impl.h @@ -31,28 +31,29 @@ public: InputDataChannelServiceImpl(); ~InputDataChannelServiceImpl(); - ErrCode InsertText(const std::string &text, uint64_t msgId) override; - ErrCode DeleteForward(int32_t length, uint64_t msgId) override; - ErrCode DeleteBackward(int32_t length, uint64_t msgId) override; - ErrCode GetTextBeforeCursor(int32_t number, uint64_t msgId) override; - ErrCode GetTextAfterCursor(int32_t number, uint64_t msgId) override; + ErrCode InsertText(const std::string &text, uint64_t msgId, const sptr &agent) override; + ErrCode DeleteForward(int32_t length, uint64_t msgId, const sptr &agent) override; + ErrCode DeleteBackward(int32_t length, uint64_t msgId, const sptr &agent) override; + ErrCode GetTextBeforeCursor(int32_t number, uint64_t msgId, const sptr &agent) override; + ErrCode GetTextAfterCursor(int32_t number, uint64_t msgId, const sptr &agent) override; ErrCode GetTextConfig(TextTotalConfigInner &textConfigInner) override; ErrCode SendKeyboardStatus(int32_t status) override; - ErrCode SendFunctionKey(int32_t funcKey, uint64_t msgId) override; - ErrCode MoveCursor(int32_t keyCode, uint64_t msgId) override; + ErrCode SendFunctionKey(int32_t funcKey, uint64_t msgId, const sptr &agent) override; + ErrCode MoveCursor(int32_t keyCode, uint64_t msgId, const sptr &agent) override; ErrCode GetEnterKeyType(int32_t &keyType) override; ErrCode GetInputPattern(int32_t &inputPattern) override; - ErrCode SelectByRange(int32_t start, int32_t end, uint64_t msgId) override; - ErrCode SelectByMovement(int32_t direction, int32_t cursorMoveSkip, uint64_t msgId) override; - ErrCode HandleExtendAction(int32_t action, uint64_t msgId) override; - ErrCode GetTextIndexAtCursor(uint64_t msgId) override; + ErrCode SelectByRange(int32_t start, int32_t end, uint64_t msgId, const sptr &agent) override; + ErrCode SelectByMovement( + int32_t direction, int32_t cursorMoveSkip, uint64_t msgId, const sptr &agent) override; + ErrCode HandleExtendAction(int32_t action, uint64_t msgId, const sptr &agent) override; + ErrCode GetTextIndexAtCursor(uint64_t msgId, const sptr &agent) override; ErrCode NotifyPanelStatusInfo(const PanelStatusInfoInner &info) override; ErrCode NotifyKeyboardHeight(uint32_t height) override; ErrCode SendPrivateCommand(const Value &value) override; - ErrCode SetPreviewText(const std::string &text, const RangeInner &rangeInner, uint64_t msgId) override; - ErrCode FinishTextPreview(uint64_t msgId) override; + ErrCode SetPreviewText(const std::string &text, const RangeInner &rangeInner, uint64_t msgId, + const sptr &agent) override; + ErrCode FinishTextPreview(uint64_t msgId, const sptr &agent) override; ErrCode SendMessage(const ArrayBuffer &arraybuffer) override; - ErrCode SetSpareAgent(const sptr &agent) override; }; } // namespace MiscServices } // namespace OHOS diff --git a/frameworks/native/inputmethod_controller/src/input_data_channel_service_impl.cpp b/frameworks/native/inputmethod_controller/src/input_data_channel_service_impl.cpp index 81376ca63..7a0d4e2ca 100644 --- a/frameworks/native/inputmethod_controller/src/input_data_channel_service_impl.cpp +++ b/frameworks/native/inputmethod_controller/src/input_data_channel_service_impl.cpp @@ -29,8 +29,10 @@ InputDataChannelServiceImpl::InputDataChannelServiceImpl() {} InputDataChannelServiceImpl::~InputDataChannelServiceImpl() {} -ErrCode InputDataChannelServiceImpl::InsertText(const std::string &text, uint64_t msgId) +ErrCode InputDataChannelServiceImpl::InsertText( + const std::string &text, uint64_t msgId, const sptr &agent) { + IMSA_HILOGD("start."); auto instance = InputMethodController::GetInstance(); if (instance == nullptr) { IMSA_HILOGE("failed to get InputMethodController instance!"); @@ -38,11 +40,12 @@ ErrCode InputDataChannelServiceImpl::InsertText(const std::string &text, uint64_ } int32_t ret = instance->InsertText(Str8ToStr16(text)); ResponseData data = std::monostate{}; - instance->ResponseDataChannel(msgId, ret, data); + instance->ResponseDataChannel(agent, msgId, ret, data); + IMSA_HILOGD("end."); return ret; } -ErrCode InputDataChannelServiceImpl::DeleteForward(int32_t length, uint64_t msgId) +ErrCode InputDataChannelServiceImpl::DeleteForward(int32_t length, uint64_t msgId, const sptr &agent) { auto instance = InputMethodController::GetInstance(); if (instance == nullptr) { @@ -51,11 +54,11 @@ ErrCode InputDataChannelServiceImpl::DeleteForward(int32_t length, uint64_t msgI } int32_t ret = instance->DeleteForward(length); ResponseData data = std::monostate{}; - instance->ResponseDataChannel(msgId, ret, data); + instance->ResponseDataChannel(agent, msgId, ret, data); return ret; } -ErrCode InputDataChannelServiceImpl::DeleteBackward(int32_t length, uint64_t msgId) +ErrCode InputDataChannelServiceImpl::DeleteBackward(int32_t length, uint64_t msgId, const sptr &agent) { auto instance = InputMethodController::GetInstance(); if (instance == nullptr) { @@ -64,11 +67,12 @@ ErrCode InputDataChannelServiceImpl::DeleteBackward(int32_t length, uint64_t msg } int32_t ret = instance->DeleteBackward(length); ResponseData data = std::monostate{}; - instance->ResponseDataChannel(msgId, ret, data); + instance->ResponseDataChannel(agent, msgId, ret, data); return ret; } -ErrCode InputDataChannelServiceImpl::GetTextBeforeCursor(int32_t number, uint64_t msgId) +ErrCode InputDataChannelServiceImpl::GetTextBeforeCursor( + int32_t number, uint64_t msgId, const sptr &agent) { auto instance = InputMethodController::GetInstance(); if (instance == nullptr) { @@ -78,11 +82,12 @@ ErrCode InputDataChannelServiceImpl::GetTextBeforeCursor(int32_t number, uint64_ std::u16string text; int32_t ret = instance->GetLeft(number, text); ResponseData data = Str16ToStr8(text); - instance->ResponseDataChannel(msgId, ret, data); + instance->ResponseDataChannel(agent, msgId, ret, data); return ret; } -ErrCode InputDataChannelServiceImpl::GetTextAfterCursor(int32_t number, uint64_t msgId) +ErrCode InputDataChannelServiceImpl::GetTextAfterCursor( + int32_t number, uint64_t msgId, const sptr &agent) { auto instance = InputMethodController::GetInstance(); if (instance == nullptr) { @@ -90,13 +95,13 @@ ErrCode InputDataChannelServiceImpl::GetTextAfterCursor(int32_t number, uint64_t return ErrorCode::ERROR_EX_NULL_POINTER; } std::u16string text; - auto ret = instance->GetRight(number, text); + auto ret = instance->GetRight(number, text); ResponseData data = Str16ToStr8(text); - instance->ResponseDataChannel(msgId, ret, data); + instance->ResponseDataChannel(agent, msgId, ret, data); return ret; } -ErrCode InputDataChannelServiceImpl::GetTextIndexAtCursor(uint64_t msgId) +ErrCode InputDataChannelServiceImpl::GetTextIndexAtCursor(uint64_t msgId, const sptr &agent) { int32_t index = 0; auto instance = InputMethodController::GetInstance(); @@ -106,7 +111,7 @@ ErrCode InputDataChannelServiceImpl::GetTextIndexAtCursor(uint64_t msgId) } auto ret = instance->GetTextIndexAtCursor(index); ResponseData data = index; - instance->ResponseDataChannel(msgId, ret, data); + instance->ResponseDataChannel(agent, msgId, ret, data); return ret; } @@ -155,7 +160,7 @@ ErrCode InputDataChannelServiceImpl::SendKeyboardStatus(int32_t status) return ERR_OK; } -ErrCode InputDataChannelServiceImpl::SendFunctionKey(int32_t funcKey, uint64_t msgId) +ErrCode InputDataChannelServiceImpl::SendFunctionKey(int32_t funcKey, uint64_t msgId, const sptr &agent) { auto instance = InputMethodController::GetInstance(); if (instance == nullptr) { @@ -164,11 +169,11 @@ ErrCode InputDataChannelServiceImpl::SendFunctionKey(int32_t funcKey, uint64_t m } auto ret = instance->SendFunctionKey(funcKey); ResponseData data = std::monostate{}; - instance->ResponseDataChannel(msgId, ret, data); + instance->ResponseDataChannel(agent, msgId, ret, data); return ret; } -ErrCode InputDataChannelServiceImpl::MoveCursor(int32_t keyCode, uint64_t msgId) +ErrCode InputDataChannelServiceImpl::MoveCursor(int32_t keyCode, uint64_t msgId, const sptr &agent) { auto instance = InputMethodController::GetInstance(); if (instance == nullptr) { @@ -177,11 +182,12 @@ ErrCode InputDataChannelServiceImpl::MoveCursor(int32_t keyCode, uint64_t msgId) } auto ret = instance->MoveCursor(static_cast(keyCode)); ResponseData data = std::monostate{}; - instance->ResponseDataChannel(msgId, ret, data); + instance->ResponseDataChannel(agent, msgId, ret, data); return ret; } -ErrCode InputDataChannelServiceImpl::SelectByRange(int32_t start, int32_t end, uint64_t msgId) +ErrCode InputDataChannelServiceImpl::SelectByRange( + int32_t start, int32_t end, uint64_t msgId, const sptr &agent) { auto instance = InputMethodController::GetInstance(); if (instance == nullptr) { @@ -191,11 +197,12 @@ ErrCode InputDataChannelServiceImpl::SelectByRange(int32_t start, int32_t end, u instance->SelectByRange(start, end); ResponseData data = std::monostate{}; - instance->ResponseDataChannel(msgId, ERR_OK, data); + instance->ResponseDataChannel(agent, msgId, ERR_OK, data); return ERR_OK; } -ErrCode InputDataChannelServiceImpl::SelectByMovement(int32_t direction, int32_t cursorMoveSkip, uint64_t msgId) +ErrCode InputDataChannelServiceImpl::SelectByMovement( + int32_t direction, int32_t cursorMoveSkip, uint64_t msgId, const sptr &agent) { auto instance = InputMethodController::GetInstance(); if (instance == nullptr) { @@ -204,11 +211,12 @@ ErrCode InputDataChannelServiceImpl::SelectByMovement(int32_t direction, int32_t } instance->SelectByMovement(direction, cursorMoveSkip); ResponseData data = std::monostate{}; - instance->ResponseDataChannel(msgId, ERR_OK, data); + instance->ResponseDataChannel(agent, msgId, ERR_OK, data); return ERR_OK; } -ErrCode InputDataChannelServiceImpl::HandleExtendAction(int32_t action, uint64_t msgId) +ErrCode InputDataChannelServiceImpl::HandleExtendAction( + int32_t action, uint64_t msgId, const sptr &agent) { auto instance = InputMethodController::GetInstance(); if (instance == nullptr) { @@ -217,7 +225,7 @@ ErrCode InputDataChannelServiceImpl::HandleExtendAction(int32_t action, uint64_t } auto ret = instance->HandleExtendAction(action); ResponseData data = std::monostate{}; - instance->ResponseDataChannel(msgId, ret, data); + instance->ResponseDataChannel(agent, msgId, ret, data); return ret; } @@ -257,7 +265,7 @@ ErrCode InputDataChannelServiceImpl::SendPrivateCommand(const Value &value) } ErrCode InputDataChannelServiceImpl::SetPreviewText( - const std::string &text, const RangeInner &rangeInner, uint64_t msgId) + const std::string &text, const RangeInner &rangeInner, uint64_t msgId, const sptr &agent) { Range range = InputMethodTools::GetInstance().InnerToRange(rangeInner); auto instance = InputMethodController::GetInstance(); @@ -267,11 +275,11 @@ ErrCode InputDataChannelServiceImpl::SetPreviewText( } auto ret = instance->SetPreviewText(text, range); ResponseData data = std::monostate{}; - instance->ResponseDataChannel(msgId, ret, data); + instance->ResponseDataChannel(agent, msgId, ret, data); return ret; } -ErrCode InputDataChannelServiceImpl::FinishTextPreview(uint64_t msgId) +ErrCode InputDataChannelServiceImpl::FinishTextPreview(uint64_t msgId, const sptr &agent) { auto instance = InputMethodController::GetInstance(); if (instance == nullptr) { @@ -280,7 +288,7 @@ ErrCode InputDataChannelServiceImpl::FinishTextPreview(uint64_t msgId) } auto ret = instance->FinishTextPreview(); ResponseData data = std::monostate{}; - instance->ResponseDataChannel(msgId, ret, data); + instance->ResponseDataChannel(agent, msgId, ret, data); return ret; } @@ -293,16 +301,5 @@ ErrCode InputDataChannelServiceImpl::SendMessage(const ArrayBuffer &arraybuffer) } return instance->RecvMessage(arraybuffer); } - -ErrCode InputDataChannelServiceImpl::SetSpareAgent(const sptr &agent) -{ - auto instance = InputMethodController::GetInstance(); - if (instance == nullptr) { - IMSA_HILOGE("failed to get InputMethodController instance!"); - return ErrorCode::ERROR_EX_NULL_POINTER; - } - instance->SetAgent(agent); - return ERR_OK; -} } // namespace MiscServices } // namespace OHOS \ No newline at end of file diff --git a/frameworks/native/inputmethod_controller/src/input_method_controller.cpp b/frameworks/native/inputmethod_controller/src/input_method_controller.cpp index fafa924f8..e129c4d6a 100644 --- a/frameworks/native/inputmethod_controller/src/input_method_controller.cpp +++ b/frameworks/native/inputmethod_controller/src/input_method_controller.cpp @@ -1828,13 +1828,14 @@ void InputMethodController::GetWindowScaleCoordinate(int32_t& x, int32_t& y, uin handler(x, y, windowId); } -int32_t InputMethodController::ResponseDataChannel(uint64_t msgId, int32_t code, const ResponseData &data) +int32_t InputMethodController::ResponseDataChannel( + const sptr &agentObject, uint64_t msgId, int32_t code, const ResponseData &data) { - auto agent = GetAgent(); - if (agent == nullptr) { - IMSA_HILOGD("agent is nullptr!"); + if (agentObject == nullptr) { + IMSA_HILOGE("agentObject is nullptr!"); return ErrorCode::ERROR_IME_NOT_STARTED; } + auto agent = std::make_shared(agentObject); ResponseDataInner inner; inner.rspData = data; return agent->ResponseDataChannel(msgId, code, inner); 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 c09b21433..5db9a18f1 100644 --- a/interfaces/inner_api/inputmethod_controller/include/input_method_controller.h +++ b/interfaces/inner_api/inputmethod_controller/include/input_method_controller.h @@ -992,8 +992,6 @@ public: */ IMF_API int32_t RegisterWindowScaleCallbackHandler(WindowScaleCallback&& callback); - void SetAgent(const sptr &agentObject); - private: InputMethodController(); ~InputMethodController(); @@ -1019,6 +1017,7 @@ private: void SetTextListener(sptr listener); bool IsEditable(); bool IsBound(); + void SetAgent(const sptr &agentObject); std::shared_ptr GetAgent(); void PrintLogIfAceTimeout(int64_t start); void PrintKeyEventLog(); @@ -1031,7 +1030,8 @@ private: int32_t ShowSoftKeyboardInner(ClientType type); void ReportClientShow(int32_t eventCode, int32_t errCode, ClientType type); void GetWindowScaleCoordinate(int32_t& x, int32_t& y, uint32_t windowId); - int32_t ResponseDataChannel(uint64_t msgId, int32_t code, const ResponseData &data); + int32_t ResponseDataChannel( + const sptr &agentObject, uint64_t msgId, int32_t code, const ResponseData &data); void CalibrateImmersiveParam(InputAttribute &inputAttribute); friend class InputDataChannelServiceImpl; diff --git a/test/unittest/cpp_test/src/ima_text_edit_test.cpp b/test/unittest/cpp_test/src/ima_text_edit_test.cpp index 59efbd4b0..8dc8eca6a 100644 --- a/test/unittest/cpp_test/src/ima_text_edit_test.cpp +++ b/test/unittest/cpp_test/src/ima_text_edit_test.cpp @@ -438,7 +438,7 @@ HWTEST_F(ImaTextEditTest, ImaTextEditTest_ClearRspHandlers, TestSize.Level0) { IMSA_HILOGI("ImeProxyTest::ImaTextEditTest_ClearRspHandlers"); auto channelProxy = std::make_shared(nullptr); - auto channelWrap = std::make_shared(channelProxy); + auto channelWrap = std::make_shared(channelProxy, nullptr); auto delayTask = [&channelWrap]() { usleep(100000); channelWrap->ClearRspHandlers(); @@ -464,7 +464,7 @@ HWTEST_F(ImaTextEditTest, ImaTextEditTest_DeleteRspHandler, TestSize.Level0) constexpr std::size_t UNANSWERED_MAX_NUMBER = 1000; IMSA_HILOGI("ImeProxyTest::ImaTextEditTest_DeleteRspHandler"); auto channelProxy = std::make_shared(nullptr); - auto channelWrap = std::make_shared(channelProxy); + auto channelWrap = std::make_shared(channelProxy, nullptr); std::shared_ptr firstHandler = nullptr; std::shared_ptr lastHandler = nullptr; @@ -487,7 +487,7 @@ HWTEST_F(ImaTextEditTest, ImaTextEditTest_HandleResponse, TestSize.Level0) { IMSA_HILOGI("ImeProxyTest::ImaTextEditTest_HandleResponse"); auto channelProxy = std::make_shared(nullptr); - auto channelWrap = std::make_shared(channelProxy); + auto channelWrap = std::make_shared(channelProxy, nullptr); std::shared_ptr handler = nullptr; handler = channelWrap->AddRspHandler(CommonRsp, false); diff --git a/test/unittest/cpp_test/src/input_method_ability_test.cpp b/test/unittest/cpp_test/src/input_method_ability_test.cpp index cd15f0fce..7e7789c20 100644 --- a/test/unittest/cpp_test/src/input_method_ability_test.cpp +++ b/test/unittest/cpp_test/src/input_method_ability_test.cpp @@ -2012,8 +2012,8 @@ HWTEST_F(InputMethodAbilityTest, testHandleUnconsumedKey_008, TestSize.Level0) sptr channelObject = new InputDataChannelServiceImpl(); auto channelProxy = std::make_shared(channelObject->AsObject()); - InputMethodAbility::GetInstance().dataChannelProxyWrap_ - = std::make_shared(channelProxy); + InputMethodAbility::GetInstance().dataChannelProxyWrap_ = + std::make_shared(channelProxy, nullptr); InputMethodAbility::GetInstance().inputAttribute_.needAutoInputNumkey = true; auto keyEvent = KeyEventUtil::CreateKeyEvent(MMI::KeyEvent::KEYCODE_NUMPAD_0, MMI::KeyEvent::KEY_ACTION_DOWN); @@ -2032,8 +2032,8 @@ HWTEST_F(InputMethodAbilityTest, testHandleUnconsumedKey_009, TestSize.Level0) IMSA_HILOGI("InputMethodAbilityTest testHandleUnconsumedKey_009 START"); sptr channelObject = new InputDataChannelServiceImpl(); auto channelProxy = std::make_shared(channelObject->AsObject()); - InputMethodAbility::GetInstance().dataChannelProxyWrap_ - = std::make_shared(channelProxy); + InputMethodAbility::GetInstance().dataChannelProxyWrap_ = + std::make_shared(channelProxy, nullptr); InputMethodAbility::GetInstance().inputAttribute_.needAutoInputNumkey = true; auto keyEvent = KeyEventUtil::CreateKeyEvent(MMI::KeyEvent::KEYCODE_A, MMI::KeyEvent::KEY_ACTION_DOWN); diff --git a/test/unittest/cpp_test/src/input_method_controller_test.cpp b/test/unittest/cpp_test/src/input_method_controller_test.cpp index be683ab8d..2a867a20f 100644 --- a/test/unittest/cpp_test/src/input_method_controller_test.cpp +++ b/test/unittest/cpp_test/src/input_method_controller_test.cpp @@ -2111,5 +2111,20 @@ HWTEST_F(InputMethodControllerTest, TestNotifyOnInputStopFinished001, TestSize.L EXPECT_EQ(ret, ErrorCode::NO_ERROR); UserSessionManager::GetInstance().userSessions_.clear(); } + +/** + * @tc.name: TestResponseDataChannel + * @tc.desc: Test ResponseDataChannel + * @tc.type: FUNC + */ +HWTEST_F(InputMethodControllerTest, TestResponseDataChannel, TestSize.Level0) +{ + IMSA_HILOGI("TestResponseDataChannel START"); + uint64_t msgId = 10; + int32_t code = 5; + ResponseData data = std::monostate{}; + auto ret = inputMethodController_->ResponseDataChannel(nullptr, msgId, code, data); + EXPECT_NE(ret, ErrorCode::NO_ERROR); +} } // namespace MiscServices } // namespace OHOS -- Gitee