From ee7232a16cfae025a59e32ed73e21c9446ae5116 Mon Sep 17 00:00:00 2001 From: zhouyongfei Date: Thu, 16 Dec 2021 20:00:42 +0800 Subject: [PATCH 1/4] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E5=91=8A=E8=AD=A6?= =?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 --- .../inputmethod_ability/include/event_target.h | 3 +++ .../inputmethod_ability/src/event_target.cpp | 16 +++++++--------- .../src/input_method_ability.cpp | 4 +++- .../src/input_method_agent_proxy.cpp | 2 +- .../src/input_method_core_proxy.cpp | 2 +- .../src/input_method_core_stub.cpp | 2 -- .../include/input_client_proxy.h | 5 +++-- .../src/input_method_controller.cpp | 2 +- .../declaration/api/@ohos.inputmethodengine.d.ts | 2 +- services/include/i_platform_api.h | 1 - services/include/input_method_setting.h | 1 - .../include/input_method_system_ability_stub.h | 3 ++- services/include/message_handler.h | 2 +- services/include/peruser_session.h | 1 + services/include/utils.h | 7 ++++--- services/src/input_attribute.cpp | 1 + .../src/input_method_ability_connection_stub.cpp | 1 + services/src/input_method_property.cpp | 1 + services/src/input_method_system_ability.cpp | 6 +++--- services/src/keyboard_type.cpp | 1 - services/src/peruser_session.cpp | 7 +++---- services/src/peruser_setting.cpp | 1 - services/src/platform_api_proxy.cpp | 2 +- 23 files changed, 38 insertions(+), 35 deletions(-) diff --git a/frameworks/inputmethod_ability/include/event_target.h b/frameworks/inputmethod_ability/include/event_target.h index afd0c4924..80ae0c878 100644 --- a/frameworks/inputmethod_ability/include/event_target.h +++ b/frameworks/inputmethod_ability/include/event_target.h @@ -45,6 +45,9 @@ namespace MiscServices { napi_ref thisVarRef_; EventListener *first_; EventListener *last_; + + private: + int LISTENER_TYPTE_MAX_LENGTH = 64; }; } } diff --git a/frameworks/inputmethod_ability/src/event_target.cpp b/frameworks/inputmethod_ability/src/event_target.cpp index 4c6f1b032..877a1482f 100644 --- a/frameworks/inputmethod_ability/src/event_target.cpp +++ b/frameworks/inputmethod_ability/src/event_target.cpp @@ -19,7 +19,6 @@ #include "utils/log.h" #include "input_method_ability.h" -#define LISTENER_TYPTE_MAX_LENGTH 64 namespace OHOS { namespace MiscServices { struct EventListener { @@ -181,6 +180,7 @@ namespace MiscServices { uv_work_t *work = new (std::nothrow) uv_work_t; if (work == nullptr) { IMSA_HILOGI("EventTarget::Emit No memory work == nullptr"); + delete work; return; } @@ -190,7 +190,7 @@ namespace MiscServices { work->data = (void *)eventTargetCB; int ret = uv_queue_work(loop, work, [](uv_work_t *work) {}, [](uv_work_t *work, int status) { - //Js Thread + // Js Thread if (work == nullptr) { IMSA_HILOGI("EventTarget::Emit work == nullptr"); return; @@ -202,13 +202,15 @@ namespace MiscServices { napi_value thisVar = nullptr; napi_get_reference_value(eventTargetCB->env, eventTargetCB->thisVarRef, &thisVar); - for (EventListener *eventListener = eventTargetCB->first; eventListener != nullptr; eventListener = eventListener->next) { + for (EventListener *eventListener = eventTargetCB->first; eventListener != nullptr; + eventListener = eventListener->next) { if (strcmp(eventListener->type, eventTargetCB->type) == 0) { napi_value jsEvent = eventTargetCB->event ? eventTargetCB->event->ToJsObject() : nullptr; napi_value handler = nullptr; napi_value result = nullptr; napi_get_reference_value(eventTargetCB->env, eventListener->handlerRef, &handler); - napi_call_function(eventTargetCB->env, thisVar, handler, jsEvent ? 1 : 0, jsEvent ? &jsEvent : nullptr, &result); + napi_call_function(eventTargetCB->env, thisVar, handler, + jsEvent ? 1 : 0, jsEvent ? &jsEvent : nullptr, &result); if (eventListener->isOnce) { eventTargetCB->eventTarget->Off(eventTargetCB->type, handler); } @@ -219,12 +221,8 @@ namespace MiscServices { if (eventTargetCB) { delete eventTargetCB; } - delete work; }); - if (ret != 0) { - IMSA_HILOGI("EventTarget::Emit failed to execute libuv work queue"); - delete work; - } + delete work; } } } \ No newline at end of file diff --git a/frameworks/inputmethod_ability/src/input_method_ability.cpp b/frameworks/inputmethod_ability/src/input_method_ability.cpp index c14fd5ff0..1f3b59d71 100644 --- a/frameworks/inputmethod_ability/src/input_method_ability.cpp +++ b/frameworks/inputmethod_ability/src/input_method_ability.cpp @@ -32,6 +32,7 @@ namespace MiscServices { InputMethodAbility::InputMethodAbility() : stop_(false) { writeInputChannel = nullptr; + editorAttribute = nullptr; Initialize(); OnConnect(); } @@ -89,8 +90,9 @@ namespace MiscServices { sptr stub2 = stub; if (mImms != nullptr) { mImms->setInputMethodCore(stub2); + } else { + IMSA_HILOGI("InputMethodAbility::OnConnect() mImms is nullptr"); } - IMSA_HILOGI("InputMethodAbility::OnConnect() mImms is nullptr"); return nullptr; } diff --git a/frameworks/inputmethod_ability/src/input_method_agent_proxy.cpp b/frameworks/inputmethod_ability/src/input_method_agent_proxy.cpp index 1e06f7e0f..e14816317 100644 --- a/frameworks/inputmethod_ability/src/input_method_agent_proxy.cpp +++ b/frameworks/inputmethod_ability/src/input_method_agent_proxy.cpp @@ -19,7 +19,7 @@ namespace OHOS { namespace MiscServices { using namespace ErrorCode; InputMethodAgentProxy::InputMethodAgentProxy(const sptr &object) - : IRemoteProxy(object) + : IRemoteProxy(object) { } diff --git a/frameworks/inputmethod_ability/src/input_method_core_proxy.cpp b/frameworks/inputmethod_ability/src/input_method_core_proxy.cpp index 58dc01ac5..113207af5 100644 --- a/frameworks/inputmethod_ability/src/input_method_core_proxy.cpp +++ b/frameworks/inputmethod_ability/src/input_method_core_proxy.cpp @@ -21,7 +21,7 @@ namespace OHOS { namespace MiscServices { InputMethodCoreProxy::InputMethodCoreProxy(const OHOS::sptr &impl) - : IRemoteProxy(impl) + : IRemoteProxy(impl) { } diff --git a/frameworks/inputmethod_ability/src/input_method_core_stub.cpp b/frameworks/inputmethod_ability/src/input_method_core_stub.cpp index bf51a666e..a0d5a0f66 100644 --- a/frameworks/inputmethod_ability/src/input_method_core_stub.cpp +++ b/frameworks/inputmethod_ability/src/input_method_core_stub.cpp @@ -12,8 +12,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -#include -#include #include "message_handler.h" #include "i_input_data_channel.h" #include "input_method_core_stub.h" diff --git a/frameworks/inputmethod_controller/include/input_client_proxy.h b/frameworks/inputmethod_controller/include/input_client_proxy.h index a6324edf8..fbac59e8d 100644 --- a/frameworks/inputmethod_controller/include/input_client_proxy.h +++ b/frameworks/inputmethod_controller/include/input_client_proxy.h @@ -22,13 +22,14 @@ namespace OHOS { namespace MiscServices { -class InputClientProxy : public IRemoteProxy { + class InputClientProxy : public IRemoteProxy { public: explicit InputClientProxy(const sptr &object); ~InputClientProxy() = default; DISALLOW_COPY_AND_MOVE(InputClientProxy); - int32_t onInputReady(int32_t retValue, const sptr& agent, const InputChannel *channel) override; + int32_t onInputReady(int32_t retValue, const sptr& agent, + const InputChannel *channel) override; int32_t onInputReleased(int32_t retValue) override; int32_t setDisplayMode(int32_t mode) override; diff --git a/frameworks/inputmethod_controller/src/input_method_controller.cpp b/frameworks/inputmethod_controller/src/input_method_controller.cpp index 25aeae2f5..b4c05e7dc 100644 --- a/frameworks/inputmethod_controller/src/input_method_controller.cpp +++ b/frameworks/inputmethod_controller/src/input_method_controller.cpp @@ -159,7 +159,7 @@ using namespace MessageID; void InputMethodController::Attach(sptr &listener) { PrepareInput(0, mClient, mInputDataChannel, mAttribute); - textListener=listener; + textListener = listener; } void InputMethodController::ShowTextInput() diff --git a/interfaces/kits/js/declaration/api/@ohos.inputmethodengine.d.ts b/interfaces/kits/js/declaration/api/@ohos.inputmethodengine.d.ts index 0d4ef4db2..6daa45fff 100644 --- a/interfaces/kits/js/declaration/api/@ohos.inputmethodengine.d.ts +++ b/interfaces/kits/js/declaration/api/@ohos.inputmethodengine.d.ts @@ -34,7 +34,7 @@ declare namespace inputMethodEngine { function DeleteBackward(length: number, callback: () => void): void; function DeleteBackward(length: number): Promise; - function HideKeyboardSelf(callback: callback: () => void): void; + function HideKeyboardSelf(callback: () => void): void; function HideKeyboardSelf(): Promise; } diff --git a/services/include/i_platform_api.h b/services/include/i_platform_api.h index 1c7066c50..006b03955 100644 --- a/services/include/i_platform_api.h +++ b/services/include/i_platform_api.h @@ -56,7 +56,6 @@ namespace OHOS { InputMethodProperty *inputMethodProperty) = 0; virtual int32_t getInputMethodSetting(int userId, InputMethodSetting *inputMethodSetting) = 0; virtual int32_t setInputMethodSetting(int userId, const InputMethodSetting& inputMethodSetting) = 0; - }; } } diff --git a/services/include/input_method_setting.h b/services/include/input_method_setting.h index 589fa6561..0594a1245 100644 --- a/services/include/input_method_setting.h +++ b/services/include/input_method_setting.h @@ -32,7 +32,6 @@ namespace MiscServices { const static std::u16string CURRENT_SYS_KEYBOARD_TYPE_TAG; // default keyboard type for security IME const static std::u16string SYSTEM_LOCALE_TAG; // locale list supported in the system - InputMethodSetting(); ~InputMethodSetting(); InputMethodSetting(const InputMethodSetting& inputMethodSetting); diff --git a/services/include/input_method_system_ability_stub.h b/services/include/input_method_system_ability_stub.h index ad4d8192a..c04361ecc 100644 --- a/services/include/input_method_system_ability_stub.h +++ b/services/include/input_method_system_ability_stub.h @@ -26,7 +26,8 @@ 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; diff --git a/services/include/message_handler.h b/services/include/message_handler.h index b370193c5..93e894692 100644 --- a/services/include/message_handler.h +++ b/services/include/message_handler.h @@ -58,7 +58,7 @@ namespace MessageID { MSG_ID_SHELL_COMMAND, // shell command MSG_ID_EXIT_SERVICE, // exit service - //the request from IMSA to IMC + // the request from IMSA to IMC MSG_ID_INSERT_CHAR, MSG_ID_DELETE_BACKWARD, MSG_ID_CLOSE, diff --git a/services/include/peruser_session.h b/services/include/peruser_session.h index 77fdbb513..84b63402c 100644 --- a/services/include/peruser_session.h +++ b/services/include/peruser_session.h @@ -125,6 +125,7 @@ namespace MiscServices { int IME_ERROR_CODE = 3; int COMMON_COUNT_THREE_HUNDRED = 300; int SLEEP_TIME = 300000; + int SLEEP_TIME_MORE = 1600000; InputMethodProperty *currentIme[MAX_IME]; // 0 - the default ime. 1 - security ime diff --git a/services/include/utils.h b/services/include/utils.h index 8312017f0..8cb9d01db 100644 --- a/services/include/utils.h +++ b/services/include/utils.h @@ -19,7 +19,6 @@ #define FM_IMMS_PROJECT_UTILS_H #include -#include #include #include @@ -27,10 +26,12 @@ namespace OHOS { namespace MiscServices { class Utils { public: - static std::string to_utf8(std::u16string str16) { + static std::string to_utf8(std::u16string str16) + { return std::wstring_convert, char16_t> {}.to_bytes(str16); } - static std::u16string to_utf16(std::string str) { + static std::u16string to_utf16(std::string str) + { return std::wstring_convert, char16_t> {}.from_bytes(str); } }; diff --git a/services/src/input_attribute.cpp b/services/src/input_attribute.cpp index e739e8111..3e1cb6dc4 100644 --- a/services/src/input_attribute.cpp +++ b/services/src/input_attribute.cpp @@ -21,6 +21,7 @@ namespace MiscServices { */ InputAttribute::InputAttribute() : enterKeyType(0), inputOption(0) { + inputPattern = PATTERN_TEXT; } /*! Constructor diff --git a/services/src/input_method_ability_connection_stub.cpp b/services/src/input_method_ability_connection_stub.cpp index 88dc89281..b5108c998 100644 --- a/services/src/input_method_ability_connection_stub.cpp +++ b/services/src/input_method_ability_connection_stub.cpp @@ -22,6 +22,7 @@ namespace MiscServices { InputMethodAbilityConnectionStub::InputMethodAbilityConnectionStub(const int index) { mIndex = index; + messageHandler = nullptr; } InputMethodAbilityConnectionStub::~InputMethodAbilityConnectionStub() diff --git a/services/src/input_method_property.cpp b/services/src/input_method_property.cpp index 349f82162..904015035 100644 --- a/services/src/input_method_property.cpp +++ b/services/src/input_method_property.cpp @@ -22,6 +22,7 @@ namespace MiscServices { */ InputMethodProperty::InputMethodProperty() { + mDefaultImeId = 0; } /*! Destructor diff --git a/services/src/input_method_system_ability.cpp b/services/src/input_method_system_ability.cpp index 246dc9812..71b6ddf2d 100644 --- a/services/src/input_method_system_ability.cpp +++ b/services/src/input_method_system_ability.cpp @@ -58,7 +58,7 @@ namespace MiscServices { } std::map::const_iterator it; - for (it = userSessions.cbegin(); it != userSessions.cend();) { + for (it = userSessions.cbegin(); it != userSessions.cend(); ) { PerUserSession *session = it->second; it = userSessions.erase(it); delete session; @@ -66,7 +66,7 @@ namespace MiscServices { } userSessions.clear(); std::map::const_iterator it1; - for (it1 = userSettings.cbegin(); it1 != userSettings.cend();) { + for (it1 = userSettings.cbegin(); it1 != userSettings.cend(); ) { PerUserSetting *setting = it1->second; it1 = userSettings.erase(it1); delete setting; @@ -74,7 +74,7 @@ namespace MiscServices { } userSettings.clear(); std::map::const_iterator it2; - for (it2 = msgHandlers.cbegin(); it2 != msgHandlers.cend();) { + for (it2 = msgHandlers.cbegin(); it2 != msgHandlers.cend(); ) { MessageHandler *handler = it2->second; it2 = msgHandlers.erase(it2); delete handler; diff --git a/services/src/keyboard_type.cpp b/services/src/keyboard_type.cpp index c92fe7740..237052bf1 100644 --- a/services/src/keyboard_type.cpp +++ b/services/src/keyboard_type.cpp @@ -110,7 +110,6 @@ namespace MiscServices { } else { mHashCode = ID_NONE; } - } void KeyboardType::setLabelId(int32_t labelId) diff --git a/services/src/peruser_session.cpp b/services/src/peruser_session.cpp index 3be9b5ad5..a6e9d348f 100644 --- a/services/src/peruser_session.cpp +++ b/services/src/peruser_session.cpp @@ -13,14 +13,12 @@ * limitations under the License. */ -#include "unistd.h" #include "platform.h" #include "parcel.h" #include "message_parcel.h" #include "utils.h" #include "want.h" #include "input_method_ability_connection_stub.h" -#include #include "peruser_session.h" #include "ability_connect_callback_proxy.h" #include "ability_manager_interface.h" @@ -45,6 +43,7 @@ namespace MiscServices { { userId_ = userId; msgId_ = msgId; + imsChannel = nullptr; } RemoteObjectDeathRecipient::~RemoteObjectDeathRecipient() @@ -713,7 +712,7 @@ namespace MiscServices { parcel->WriteInt32(index); parcel->WriteString16(currentIme[index]->mImeId); Message *msg = new Message(MSG_ID_RESTART_IMS, parcel); - usleep(1600*1000); // wait that PACKAGE_REMOVED message is received if this ime has been removed + usleep(SLEEP_TIME_MORE); // wait that PACKAGE_REMOVED message is received if this ime has been removed MessageHandler::Instance()->SendMessage(msg); } IMSA_HILOGI("End...[%{public}d]\n", userId_); @@ -995,7 +994,7 @@ namespace MiscServices { time_t now = time(0); double diffSeconds = difftime(now, past[imeIndex]); - //time difference is more than 5 minutes, reset time and error num; + // time difference is more than 5 minutes, reset time and error num; if (diffSeconds > COMMON_COUNT_THREE_HUNDRED) { past[imeIndex] = now; errorNum[imeIndex] = 1; diff --git a/services/src/peruser_setting.cpp b/services/src/peruser_setting.cpp index 5dcdf453e..ee60d2ca9 100644 --- a/services/src/peruser_setting.cpp +++ b/services/src/peruser_setting.cpp @@ -13,7 +13,6 @@ * limitations under the License. */ -#include "unistd.h" #include "peruser_setting.h" #include "platform.h" #include "utils.h" diff --git a/services/src/platform_api_proxy.cpp b/services/src/platform_api_proxy.cpp index 4906fadf7..5cf2b198e 100644 --- a/services/src/platform_api_proxy.cpp +++ b/services/src/platform_api_proxy.cpp @@ -76,7 +76,7 @@ namespace MiscServices { return nullptr; } int code = reply.ReadException(); - if (code != 0) {// code = 0, means no exception. + if (code != 0) { // code = 0, means no exception. LOG_DEBUG("exception code : %d\n", code); return nullptr; } -- Gitee From 904e168bb634e11a6626a4d0665f1d279c833ebe Mon Sep 17 00:00:00 2001 From: zhouyongfei Date: Thu, 16 Dec 2021 21:05:01 +0800 Subject: [PATCH 2/4] refresh Signed-off-by: zhouyongfei --- frameworks/inputmethod_ability/include/event_target.h | 2 +- frameworks/inputmethod_ability/src/event_target.cpp | 3 +++ services/src/peruser_session.cpp | 2 +- 3 files changed, 5 insertions(+), 2 deletions(-) diff --git a/frameworks/inputmethod_ability/include/event_target.h b/frameworks/inputmethod_ability/include/event_target.h index 80ae0c878..e4aa7509a 100644 --- a/frameworks/inputmethod_ability/include/event_target.h +++ b/frameworks/inputmethod_ability/include/event_target.h @@ -47,7 +47,7 @@ namespace MiscServices { EventListener *last_; private: - int LISTENER_TYPTE_MAX_LENGTH = 64; + static const int LISTENER_TYPTE_MAX_LENGTH = 64; }; } } diff --git a/frameworks/inputmethod_ability/src/event_target.cpp b/frameworks/inputmethod_ability/src/event_target.cpp index 877a1482f..bd50e0239 100644 --- a/frameworks/inputmethod_ability/src/event_target.cpp +++ b/frameworks/inputmethod_ability/src/event_target.cpp @@ -222,6 +222,9 @@ namespace MiscServices { delete eventTargetCB; } }); + if (ret != 0) { + IMSA_HILOGI("EventTarget::Emit failed to execute libuv work queue"); + } delete work; } } diff --git a/services/src/peruser_session.cpp b/services/src/peruser_session.cpp index a6e9d348f..e8253c302 100644 --- a/services/src/peruser_session.cpp +++ b/services/src/peruser_session.cpp @@ -12,7 +12,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - +#include "unistd.h" // usleep #include "platform.h" #include "parcel.h" #include "message_parcel.h" -- Gitee From 0b7ebd436c5f9abe7bce9603148b090cc1f01d44 Mon Sep 17 00:00:00 2001 From: zhouyongfei Date: Thu, 16 Dec 2021 21:42:36 +0800 Subject: [PATCH 3/4] refresh Signed-off-by: zhouyongfei --- frameworks/inputmethod_ability/src/event_target.cpp | 1 + services/src/peruser_session.cpp | 1 - services/src/peruser_setting.cpp | 3 ++- 3 files changed, 3 insertions(+), 2 deletions(-) diff --git a/frameworks/inputmethod_ability/src/event_target.cpp b/frameworks/inputmethod_ability/src/event_target.cpp index bd50e0239..fc83bccf8 100644 --- a/frameworks/inputmethod_ability/src/event_target.cpp +++ b/frameworks/inputmethod_ability/src/event_target.cpp @@ -22,6 +22,7 @@ namespace OHOS { namespace MiscServices { struct EventListener { + int LISTENER_TYPTE_MAX_LENGTH = 64; char type[LISTENER_TYPTE_MAX_LENGTH] = { 0 }; bool isOnce = false; napi_ref handlerRef = nullptr; diff --git a/services/src/peruser_session.cpp b/services/src/peruser_session.cpp index e8253c302..f0393676c 100644 --- a/services/src/peruser_session.cpp +++ b/services/src/peruser_session.cpp @@ -43,7 +43,6 @@ namespace MiscServices { { userId_ = userId; msgId_ = msgId; - imsChannel = nullptr; } RemoteObjectDeathRecipient::~RemoteObjectDeathRecipient() diff --git a/services/src/peruser_setting.cpp b/services/src/peruser_setting.cpp index ee60d2ca9..574d92108 100644 --- a/services/src/peruser_setting.cpp +++ b/services/src/peruser_setting.cpp @@ -12,7 +12,8 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - + +#include "unistd.h" // usleep #include "peruser_setting.h" #include "platform.h" #include "utils.h" -- Gitee From 475713f53ef9ee82c236dc37c368b61f31e9d59f Mon Sep 17 00:00:00 2001 From: zhouyongfei Date: Fri, 17 Dec 2021 09:55:54 +0800 Subject: [PATCH 4/4] refresh Signed-off-by: zhouyongfei --- frameworks/inputmethod_ability/src/event_target.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frameworks/inputmethod_ability/src/event_target.cpp b/frameworks/inputmethod_ability/src/event_target.cpp index fc83bccf8..f769c719c 100644 --- a/frameworks/inputmethod_ability/src/event_target.cpp +++ b/frameworks/inputmethod_ability/src/event_target.cpp @@ -22,7 +22,7 @@ namespace OHOS { namespace MiscServices { struct EventListener { - int LISTENER_TYPTE_MAX_LENGTH = 64; + static const int LISTENER_TYPTE_MAX_LENGTH = 64; char type[LISTENER_TYPTE_MAX_LENGTH] = { 0 }; bool isOnce = false; napi_ref handlerRef = nullptr; -- Gitee