From b362a46256b910d3870cd594ba0f8fd5604d5e6f Mon Sep 17 00:00:00 2001 From: zhouyongfei Date: Wed, 19 Jan 2022 17:42:48 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E5=90=88=E5=85=A5=E7=A1=AC=E9=94=AE?= =?UTF-8?q?=E7=9B=98=E6=8C=89=E9=94=AE=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: zhouyongfei --- .../include/i_input_method_core.h | 3 +-- .../input_method_system_ability_proxy.h | 1 + .../src/input_method_controller.cpp | 15 ++++++++----- .../src/input_method_system_ability_proxy.cpp | 19 +++++++++++++++++ .../kits/js/napi/js_input_method_engine.cpp | 1 + .../include/i_input_method_system_ability.h | 2 ++ .../input_method_system_ability_stub.h | 4 +++- services/include/peruser_session.h | 1 + services/src/input_method_system_ability.cpp | 1 + .../src/input_method_system_ability_stub.cpp | 21 +++++++++++++++++++ services/src/peruser_session.cpp | 20 ++++++++++++++++++ 11 files changed, 80 insertions(+), 8 deletions(-) diff --git a/frameworks/inputmethod_ability/include/i_input_method_core.h b/frameworks/inputmethod_ability/include/i_input_method_core.h index 4fc9fef19..c5efbeea0 100644 --- a/frameworks/inputmethod_ability/include/i_input_method_core.h +++ b/frameworks/inputmethod_ability/include/i_input_method_core.h @@ -36,10 +36,9 @@ namespace MiscServices { INITIALIZE_INPUT = FIRST_CALL_TRANSACTION, START_INPUT, STOP_INPUT, + DISPATCH_KEY, SHOW_KEYBOARD, HIDE_KEYBOARD, - ON_CURSOR_UPDATE, - ON_SELECT_TEXT_CHANGE, SET_KEYBOARD_TYPE, GET_KEYBOARD_WINDOW_HEIGHT, }; diff --git a/frameworks/inputmethod_controller/include/input_method_system_ability_proxy.h b/frameworks/inputmethod_controller/include/input_method_system_ability_proxy.h index 80fdc6f15..39aa5cc21 100644 --- a/frameworks/inputmethod_controller/include/input_method_system_ability_proxy.h +++ b/frameworks/inputmethod_controller/include/input_method_system_ability_proxy.h @@ -40,6 +40,7 @@ namespace MiscServices { virtual void releaseInput(MessageParcel& data) override; virtual void startInput(MessageParcel& data) override; virtual void stopInput(MessageParcel& data) override; + virtual void DispatchKey(MessageParcel& data) override; virtual int32_t setInputMethodCore(sptr &core) override; int32_t Prepare(int32_t displayId, sptr &client, sptr &channel, diff --git a/frameworks/inputmethod_controller/src/input_method_controller.cpp b/frameworks/inputmethod_controller/src/input_method_controller.cpp index 0e92e0e80..a8fa03e52 100644 --- a/frameworks/inputmethod_controller/src/input_method_controller.cpp +++ b/frameworks/inputmethod_controller/src/input_method_controller.cpp @@ -350,13 +350,18 @@ using namespace MessageID; bool InputMethodController::dispatchKeyEvent(std::shared_ptr keyEvent) { IMSA_HILOGI("InputMethodController::dispatchKeyEvent"); - if (mAgent == nullptr) { - IMSA_HILOGI("InputMethodController::dispatchKeyEvent mAgent is nullptr"); + if (mImms == nullptr) { return false; } - IMSA_HILOGI("InputMethodController::dispatchKeyEvent (%{public}d, %{public}d)", - keyEvent->GetKeyCode(), keyEvent->GetKeyAction()); - mAgent->DispatchKey(keyEvent->GetKeyCode(), keyEvent->GetKeyAction()); + MessageParcel data; + if (!(data.WriteInterfaceToken(mImms->GetDescriptor()) + &&data.WriteRemoteObject(mClient->AsObject().GetRefPtr()) + &&data.WriteInt32(keyEvent->GetKeyCode()) + &&data.WriteInt32(keyEvent->GetKeyAction()))) { + return false; + } + mImms->DispatchKey(data); + return true; } } diff --git a/frameworks/inputmethod_controller/src/input_method_system_ability_proxy.cpp b/frameworks/inputmethod_controller/src/input_method_system_ability_proxy.cpp index 3ae9c12a7..ba47a8a22 100644 --- a/frameworks/inputmethod_controller/src/input_method_system_ability_proxy.cpp +++ b/frameworks/inputmethod_controller/src/input_method_system_ability_proxy.cpp @@ -97,6 +97,25 @@ namespace MiscServices { } } + void InputMethodSystemAbilityProxy::DispatchKey(MessageParcel& data) + { + IMSA_HILOGI("InputMethodSystemAbilityProxy::DispatchKey"); + MessageParcel reply; + MessageOption option; + + auto ret = Remote()->SendRequest(DISPATCH_KEY, data, reply, option); + if (ret != NO_ERROR) { + IMSA_HILOGI("InputMethodSystemAbilityProxy::DispatchKey SendRequest failed"); + return; + } + + ret = reply.ReadInt32(); + if (ret != NO_ERROR) { + IMSA_HILOGI("InputMethodSystemAbilityProxy::DispatchKey reply failed"); + return; + } + } + int32_t InputMethodSystemAbilityProxy::setInputMethodCore(sptr &core) { IMSA_HILOGI("InputMethodSystemAbilityProxy::setInputMethodCore"); diff --git a/interfaces/kits/js/napi/js_input_method_engine.cpp b/interfaces/kits/js/napi/js_input_method_engine.cpp index a1e8121b0..bf7612e69 100644 --- a/interfaces/kits/js/napi/js_input_method_engine.cpp +++ b/interfaces/kits/js/napi/js_input_method_engine.cpp @@ -298,6 +298,7 @@ namespace MiscServices { DECLARE_NAPI_FUNCTION("InsertText", JS_InsertText), DECLARE_NAPI_FUNCTION("DeleteForward", JS_DeleteForward), DECLARE_NAPI_FUNCTION("DeleteBackward", JS_DeleteBackward), + DECLARE_NAPI_FUNCTION("MoveCursor", JS_MoveCursor), DECLARE_NAPI_FUNCTION("HideKeyboardSelf", JS_HideKeyboardSelf), DECLARE_NAPI_FUNCTION("GetTextBeforeCursor", JS_GetTextBeforeCursor), DECLARE_NAPI_FUNCTION("GetTextAfterCursor", JS_GetTextAfterCursor), diff --git a/services/include/i_input_method_system_ability.h b/services/include/i_input_method_system_ability.h index 290e4a1c6..25246ab56 100644 --- a/services/include/i_input_method_system_ability.h +++ b/services/include/i_input_method_system_ability.h @@ -37,6 +37,7 @@ namespace MiscServices { RELEASE_INPUT, START_INPUT, STOP_INPUT, + DISPATCH_KEY, SET_INPUT_METHOD_CORE, GET_DISPLAY_MODE, GET_KEYBOARD_WINDOW_HEIGHT, @@ -52,6 +53,7 @@ namespace MiscServices { virtual void releaseInput(MessageParcel& data) = 0; virtual void startInput(MessageParcel& data) = 0; virtual void stopInput(MessageParcel& data) = 0; + virtual void DispatchKey(MessageParcel& data) = 0; virtual int32_t setInputMethodCore(sptr &core) = 0; virtual int32_t getDisplayMode(int32_t retMode) = 0; diff --git a/services/include/input_method_system_ability_stub.h b/services/include/input_method_system_ability_stub.h index ad4d8192a..ec836b260 100644 --- a/services/include/input_method_system_ability_stub.h +++ b/services/include/input_method_system_ability_stub.h @@ -26,12 +26,14 @@ namespace OHOS { namespace MiscServices { class InputMethodSystemAbilityStub : public IRemoteStub { public: - int32_t OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) override; + int32_t OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, + MessageOption &option) override; virtual void prepareInput(MessageParcel& data) override; virtual void releaseInput(MessageParcel& data) override; virtual void startInput(MessageParcel& data) override; virtual void stopInput(MessageParcel& data) override; + virtual void DispatchKey(MessageParcel& data) override; void setInputMethodCoreFromHap(MessageParcel& data); protected: int32_t getUserId(int32_t uid); diff --git a/services/include/peruser_session.h b/services/include/peruser_session.h index 77fdbb513..ac2ecac85 100644 --- a/services/include/peruser_session.h +++ b/services/include/peruser_session.h @@ -165,6 +165,7 @@ namespace MiscServices { void OnReleaseInput(Message *msg); void OnStartInput(Message *msg); void OnStopInput(Message *msg); + void DispatchKey(Message *msg); void OnClientDied(const wptr& who); void OnImsDied(const wptr& who); void OnHideKeyboardSelf(int flags); diff --git a/services/src/input_method_system_ability.cpp b/services/src/input_method_system_ability.cpp index 246dc9812..a9a9bf7f9 100644 --- a/services/src/input_method_system_ability.cpp +++ b/services/src/input_method_system_ability.cpp @@ -418,6 +418,7 @@ namespace MiscServices { case MSG_ID_SET_DISPLAY_MODE: case MSG_ID_CLIENT_DIED: case MSG_ID_IMS_DIED: + case MSG_ID_DISPATCH_KEY: case MSG_ID_RESTART_IMS: { OnHandleMessage(msg); break; diff --git a/services/src/input_method_system_ability_stub.cpp b/services/src/input_method_system_ability_stub.cpp index 9532c5720..09cfefda3 100644 --- a/services/src/input_method_system_ability_stub.cpp +++ b/services/src/input_method_system_ability_stub.cpp @@ -61,6 +61,12 @@ namespace MiscServices { reply.WriteInt32(NO_ERROR); break; } + case DISPATCH_KEY: { + MessageParcel *msgParcel = (MessageParcel*) &data; + DispatchKey(*msgParcel); + reply.WriteInt32(NO_ERROR); + break; + } case SET_INPUT_METHOD_CORE: { MessageParcel *msgParcel = (MessageParcel*) &data; setInputMethodCoreFromHap(*msgParcel); @@ -245,6 +251,21 @@ namespace MiscServices { MessageHandler::Instance()->SendMessage(msg); } + void InputMethodSystemAbilityStub::DispatchKey(MessageParcel& data) + { + IMSA_HILOGI("InputMethodSystemAbilityStub::DispatchKey"); + int32_t uid = IPCSkeleton::GetCallingUid(); + int32_t userId = getUserId(uid); + MessageParcel *parcel = new MessageParcel(); + parcel->WriteInt32(userId); + parcel->WriteRemoteObject(data.ReadRemoteObject()); + parcel->WriteInt32(data.ReadInt32()); + parcel->WriteInt32(data.ReadInt32()); + + Message *msg = new Message(MSG_ID_DISPATCH_KEY, parcel); + MessageHandler::Instance()->SendMessage(msg); + } + /*! Prepare input \n Send prepareInput command to work thread. The handling of prepareInput is in the work thread of PerUserSession. diff --git a/services/src/peruser_session.cpp b/services/src/peruser_session.cpp index 3be9b5ad5..038e7b3fa 100644 --- a/services/src/peruser_session.cpp +++ b/services/src/peruser_session.cpp @@ -152,6 +152,10 @@ namespace MiscServices { OnStopInput(msg); break; } + case MSG_ID_DISPATCH_KEY: { + DispatchKey(msg); + break; + } case MSG_ID_SET_INPUT_METHOD_CORE: { onSetInputMethodCore(msg); break; @@ -1338,5 +1342,21 @@ namespace MiscServices { IMSA_HILOGI("PerUserSession::OnStopInput End...[%{public}d]\n", userId_); } } + + void PerUserSession::DispatchKey(Message *msg) + { + IMSA_HILOGI("PerUserSession::DispatchKey"); + MessageParcel *data = msg->msgContent_; + + sptr clientObject = data->ReadRemoteObject(); + int32_t keyCode = data->ReadInt32(); + int32_t state = data->ReadInt32(); + + if (localControlChannel[currentIndex]->GetAgentAndChannel(&imsAgent, &imsChannel) == true) { + IMSA_HILOGI("PerUserSession::DispatchKey GetAgentAndChannel"); + sptr agent = new InputMethodAgentProxy(imsAgent->AsObject().GetRefPtr()); + agent->DispatchKey(keyCode,state); + } + } } } -- Gitee From dc1ebfd8796c81b96db84562a3c4aa58e0729882 Mon Sep 17 00:00:00 2001 From: zhouyongfei Date: Wed, 19 Jan 2022 19:22:07 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E9=9D=99=E6=80=81=E5=91=8A=E8=AD=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: zhouyongfei --- services/src/peruser_session.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/services/src/peruser_session.cpp b/services/src/peruser_session.cpp index 038e7b3fa..16301064c 100644 --- a/services/src/peruser_session.cpp +++ b/services/src/peruser_session.cpp @@ -1355,7 +1355,7 @@ namespace MiscServices { if (localControlChannel[currentIndex]->GetAgentAndChannel(&imsAgent, &imsChannel) == true) { IMSA_HILOGI("PerUserSession::DispatchKey GetAgentAndChannel"); sptr agent = new InputMethodAgentProxy(imsAgent->AsObject().GetRefPtr()); - agent->DispatchKey(keyCode,state); + agent->DispatchKey(keyCode, state); } } } -- Gitee