From 33461886cb7335fdb9e673e0477244f37e84db0a Mon Sep 17 00:00:00 2001 From: zhouyongfei Date: Mon, 14 Feb 2022 17:07:40 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E8=A7=A3=E5=86=B3=E6=B2=A1=E6=9C=89?= =?UTF-8?q?=E7=BB=91=E5=AE=9A=E8=BE=93=E5=85=A5=E6=B3=95=E6=97=B6=EF=BC=8C?= =?UTF-8?q?=E8=BF=98=E6=B6=88=E8=B4=B9=E7=89=A9=E7=90=86=E6=8C=89=E9=94=AE?= =?UTF-8?q?=E7=9A=84=E9=97=AE=E9=A2=98?= 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 | 2 ++ .../include/input_method_ability.h | 1 + .../include/input_method_core_proxy.h | 2 +- .../include/input_method_core_stub.h | 1 + .../src/input_method_ability.cpp | 9 +++++++++ .../src/input_method_core_proxy.cpp | 19 +++++++++++++++++++ .../src/input_method_core_stub.cpp | 17 +++++++++++++++++ services/src/peruser_session.cpp | 2 ++ 8 files changed, 52 insertions(+), 1 deletion(-) diff --git a/frameworks/inputmethod_ability/include/i_input_method_core.h b/frameworks/inputmethod_ability/include/i_input_method_core.h index d3f38fa14..22bdda396 100644 --- a/frameworks/inputmethod_ability/include/i_input_method_core.h +++ b/frameworks/inputmethod_ability/include/i_input_method_core.h @@ -34,6 +34,7 @@ namespace MiscServices { public: enum { INITIALIZE_INPUT = FIRST_CALL_TRANSACTION, + SET_CLIENT_STATE, START_INPUT, STOP_INPUT, SHOW_KEYBOARD, @@ -56,6 +57,7 @@ namespace MiscServices { virtual int32_t setKeyboardType(const KeyboardType& type) = 0; virtual int32_t getKeyboardWindowHeight(int32_t retHeight) = 0; virtual int32_t InitInputControlChannel(sptr &inputControlChannel) = 0; + virtual void SetClientState(bool state) = 0; }; } } diff --git a/frameworks/inputmethod_ability/include/input_method_ability.h b/frameworks/inputmethod_ability/include/input_method_ability.h index 3c8dfaddc..88dce9dc6 100644 --- a/frameworks/inputmethod_ability/include/input_method_ability.h +++ b/frameworks/inputmethod_ability/include/input_method_ability.h @@ -64,6 +64,7 @@ namespace MiscServices { bool stop_; int32_t KEYBOARD_HIDE = 1; int32_t KEYBOARD_SHOW = 2; + bool isBindClient = false; // communicating with IMSA sptr inputControlChannel; diff --git a/frameworks/inputmethod_ability/include/input_method_core_proxy.h b/frameworks/inputmethod_ability/include/input_method_core_proxy.h index 32be7cada..91923f1be 100644 --- a/frameworks/inputmethod_ability/include/input_method_core_proxy.h +++ b/frameworks/inputmethod_ability/include/input_method_core_proxy.h @@ -45,7 +45,7 @@ namespace MiscServices { virtual int32_t setKeyboardType(const KeyboardType& type) override; virtual int32_t getKeyboardWindowHeight(int32_t retHeight) override; virtual int32_t InitInputControlChannel(sptr &inputControlChannel) override; - + virtual void SetClientState(bool state) override; private: static inline BrokerDelegator delegator_; }; diff --git a/frameworks/inputmethod_ability/include/input_method_core_stub.h b/frameworks/inputmethod_ability/include/input_method_core_stub.h index 9c22c43dd..b31426435 100644 --- a/frameworks/inputmethod_ability/include/input_method_core_stub.h +++ b/frameworks/inputmethod_ability/include/input_method_core_stub.h @@ -54,6 +54,7 @@ namespace MiscServices { virtual int32_t setKeyboardType(const KeyboardType& type) override; virtual int32_t getKeyboardWindowHeight(int32_t retHeight) override; virtual int32_t InitInputControlChannel(sptr &inputControlChannel) override; + virtual void SetClientState(bool state) override; void SetMessageHandler(MessageHandler *msgHandler); private: diff --git a/frameworks/inputmethod_ability/src/input_method_ability.cpp b/frameworks/inputmethod_ability/src/input_method_ability.cpp index 6fff11462..03ead7f7f 100644 --- a/frameworks/inputmethod_ability/src/input_method_ability.cpp +++ b/frameworks/inputmethod_ability/src/input_method_ability.cpp @@ -138,6 +138,11 @@ namespace MiscServices { OnInitInputControlChannel(msg); break; } + case MSG_ID_SET_CLIENT_STATE: { + MessageParcel *data = msg->msgContent_; + isBindClient = data->ReadBool(); + break; + } case MSG_ID_START_INPUT: { OnStartInput(msg); break; @@ -252,6 +257,10 @@ namespace MiscServices { { IMSA_HILOGI("InputMethodAbility::DispatchKeyEvent"); IMSA_HILOGI("InputMethodAbility::DispatchKeyEvent: key = %{public}d, status = %{public}d", keyCode, keyStatus); + if (!isBindClient) { + IMSA_HILOGI("InputMethodAbility::DispatchKeyEvent abort. no client"); + return false; + } return imeListener_->OnKeyEvent(keyCode, keyStatus); } diff --git a/frameworks/inputmethod_ability/src/input_method_core_proxy.cpp b/frameworks/inputmethod_ability/src/input_method_core_proxy.cpp index fde9c990c..2155aa3f0 100644 --- a/frameworks/inputmethod_ability/src/input_method_core_proxy.cpp +++ b/frameworks/inputmethod_ability/src/input_method_core_proxy.cpp @@ -90,6 +90,25 @@ namespace MiscServices { return code; } + void InputMethodCoreProxy::SetClientState(bool state) + { + IMSA_HILOGI("InputMethodCoreProxy::SetClientState"); + MessageParcel data; + if (!(data.WriteInterfaceToken(GetDescriptor()) + && data.WriteBool(state))) { + IMSA_HILOGI("InputMethodCoreProxy::SetClientState write error"); + return; + } + MessageParcel reply; + MessageOption option { + MessageOption::TF_SYNC + }; + + int32_t status = Remote()->SendRequest(SET_CLIENT_STATE, data, reply, option); + if (status != ErrorCode::NO_ERROR) { + IMSA_HILOGI("InputMethodCoreProxy::SetClientState status = %{public}d", status); + } + } bool InputMethodCoreProxy::startInput(const sptr &inputDataChannel, const InputAttribute& editorAttribute, bool supportPhysicalKbd) { diff --git a/frameworks/inputmethod_ability/src/input_method_core_stub.cpp b/frameworks/inputmethod_ability/src/input_method_core_stub.cpp index 6ee000231..f8717704d 100644 --- a/frameworks/inputmethod_ability/src/input_method_core_stub.cpp +++ b/frameworks/inputmethod_ability/src/input_method_core_stub.cpp @@ -94,6 +94,11 @@ namespace MiscServices { reply.WriteNoException(); break; } + case SET_CLIENT_STATE: { + bool state = data.ReadBool(); + SetClientState(state); + break; + } case STOP_INPUT: { stopInput(); reply.WriteNoException(); @@ -201,6 +206,18 @@ namespace MiscServices { return ErrorCode::NO_ERROR; } + void InputMethodCoreStub::SetClientState(bool state) + { + IMSA_HILOGI("InputMethodCoreStub::SetClientState"); + if (msgHandler_ == nullptr) { + return; + } + MessageParcel *data = new MessageParcel(); + + Message *msg = new Message(MessageID::MSG_ID_SET_CLIENT_STATE, data); + msgHandler_->SendMessage(msg); + } + bool InputMethodCoreStub::showKeyboard(const sptr& inputDataChannel) { IMSA_HILOGI("InputMethodCoreStub::showKeyboard"); diff --git a/services/src/peruser_session.cpp b/services/src/peruser_session.cpp index dfc9ad695..aacb8c8fe 100644 --- a/services/src/peruser_session.cpp +++ b/services/src/peruser_session.cpp @@ -1218,6 +1218,7 @@ namespace MiscServices { sptr client = new InputClientProxy(clientObject); sptr interface = client; int remainClientNum = 0; + imsCore[0]->SetClientState(false); HideKeyboard(client); int ret = RemoveClient(client, remainClientNum); if (ret != ErrorCode::NO_ERROR) { @@ -1237,6 +1238,7 @@ namespace MiscServices { MessageParcel *data = msg->msgContent_; sptr clientObject = data->ReadRemoteObject(); sptr client = new InputClientProxy(clientObject); + imsCore[0]->SetClientState(true); ShowKeyboard(client); } -- Gitee From e1db7b496d208e6a0f31af9f23b243a44bc91127 Mon Sep 17 00:00:00 2001 From: zhouyongfei Date: Mon, 14 Feb 2022 19:18:12 +0800 Subject: [PATCH 2/2] fix bugs Signed-off-by: zhouyongfei --- services/include/message_handler.h | 1 + 1 file changed, 1 insertion(+) diff --git a/services/include/message_handler.h b/services/include/message_handler.h index d5a41ce1f..3a12967ce 100644 --- a/services/include/message_handler.h +++ b/services/include/message_handler.h @@ -70,6 +70,7 @@ namespace MessageID { MSG_ID_MOVE_CURSOR, // the request from IMSA to IMA + MSG_ID_SET_CLIENT_STATE, MSG_ID_SHOW_KEYBOARD, MSG_ID_INITIALIZE_INPUT, MSG_ID_HIDE_KEYBOARD, -- Gitee