From 7466ee37e912f25c3db4ffff8342ee5a81b79ce3 Mon Sep 17 00:00:00 2001 From: zhouyongfei Date: Mon, 14 Feb 2022 17:07:40 +0800 Subject: [PATCH] =?UTF-8?q?=E8=A7=A3=E5=86=B3=E6=B2=A1=E6=9C=89=E7=BB=91?= =?UTF-8?q?=E5=AE=9A=E8=BE=93=E5=85=A5=E6=B3=95=E6=97=B6=EF=BC=8C=E8=BF=98?= =?UTF-8?q?=E6=B6=88=E8=B4=B9=E7=89=A9=E7=90=86=E6=8C=89=E9=94=AE=E7=9A=84?= =?UTF-8?q?=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 d3f38fa..22bdda3 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 3c8dfad..88dce9d 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 32be7ca..91923f1 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 9c22c43..b314264 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 6fff114..03ead7f 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 fde9c99..2155aa3 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 6ee0002..f871770 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 dfc9ad6..aacb8c8 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); }