From 6c48c64b9a806b3c20b7e8e5f696e4246ee13e59 Mon Sep 17 00:00:00 2001 From: zhouyongfei Date: Thu, 17 Mar 2022 10:02:23 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E7=A1=AC=E9=94=AE?= =?UTF-8?q?=E7=9B=98=E5=9B=9E=E8=B0=83=E6=8E=A5=E5=8F=A3=E4=B8=BA=E5=AD=90?= =?UTF-8?q?=E7=BA=BF=E7=A8=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: zhouyongfei --- .../src/input_method_core_proxy.cpp | 3 ++ .../src/js_keyboard_delegate_listener.cpp | 38 +++++++++++-------- services/src/input_method_system_ability.cpp | 14 ++++--- services/src/peruser_session.cpp | 1 + 4 files changed, 34 insertions(+), 22 deletions(-) diff --git a/frameworks/inputmethod_ability/src/input_method_core_proxy.cpp b/frameworks/inputmethod_ability/src/input_method_core_proxy.cpp index 3adc7d5..6b16bbf 100644 --- a/frameworks/inputmethod_ability/src/input_method_core_proxy.cpp +++ b/frameworks/inputmethod_ability/src/input_method_core_proxy.cpp @@ -43,6 +43,7 @@ namespace MiscServices { if (inputControlChannel == nullptr) { IMSA_HILOGI("InputMethodCoreProxy::initializeInput inputControlChannel is nullptr"); + return ErrorCode::ERROR_NULL_POINTER; } IMSA_HILOGI("InputMethodCoreProxy::initializeInput displayId = %{public}d", displayId); MessageParcel data, reply; @@ -51,6 +52,7 @@ namespace MiscServices { sptr channelObject = inputControlChannel->AsObject(); if (channelObject == nullptr) { IMSA_HILOGI("InputMethodCoreProxy::initializeInput channelObject is nullptr"); + return ErrorCode::ERROR_NULL_POINTER; } bool wor = data.WriteRemoteObject(channelObject); if (wor) { @@ -137,6 +139,7 @@ namespace MiscServices { } if (inputDataChannel == nullptr) { IMSA_HILOGI("InputMethodCoreProxy::startInput inputDataChannel is nullptr"); + return false; } MessageParcel data; diff --git a/interfaces/kits/js/napi/inputmethodengine/src/js_keyboard_delegate_listener.cpp b/interfaces/kits/js/napi/inputmethodengine/src/js_keyboard_delegate_listener.cpp index 9eadaef..df0bb2e 100644 --- a/interfaces/kits/js/napi/inputmethodengine/src/js_keyboard_delegate_listener.cpp +++ b/interfaces/kits/js/napi/inputmethodengine/src/js_keyboard_delegate_listener.cpp @@ -149,22 +149,28 @@ namespace MiscServices { std::lock_guard lock(mMutex); IMSA_HILOGI("JsKeyboardDelegateListener::OnKeyEvent"); - NativeValue* nativeValue = engine_->CreateObject(); - NativeObject* object = ConvertNativeValueTo(nativeValue); - if (object == nullptr) { - IMSA_HILOGI("Failed to convert rect to jsObject"); - return false; - } - NativeValue* argv[] = {nativeValue}; - std::string methodName; - if (keyStatus == 2) { - methodName = "keyDown"; - } else { - methodName = "keyUp"; - } - object->SetProperty("keyCode", CreateJsValue(*engine_, static_cast(keyCode))); - object->SetProperty("keyAction", CreateJsValue(*engine_, static_cast(keyStatus))); - return CallJsMethodReturnBool(methodName, argv, ArraySize(argv)); + bool result = false; + auto task = [this, keyCode, keyStatus, &result] () { + NativeValue* nativeValue = engine_->CreateObject(); + NativeObject* object = ConvertNativeValueTo(nativeValue); + if (object == nullptr) { + IMSA_HILOGI("Failed to convert rect to jsObject"); + return false; + } + NativeValue* argv[] = {nativeValue}; + std::string methodName; + if (keyStatus == 2) { + methodName = "keyDown"; + } else { + methodName = "keyUp"; + } + object->SetProperty("keyCode", CreateJsValue(*engine_, static_cast(keyCode))); + object->SetProperty("keyAction", CreateJsValue(*engine_, static_cast(keyStatus))); + return CallJsMethodReturnBool(methodName, argv, ArraySize(argv)); + }; + + mainHandler_->PostSyncTask(task); + return result; } void JsKeyboardDelegateListener::OnCursorUpdate(int32_t positionX, int32_t positionY, int height) diff --git a/services/src/input_method_system_ability.cpp b/services/src/input_method_system_ability.cpp index 68338ce..7d35050 100644 --- a/services/src/input_method_system_ability.cpp +++ b/services/src/input_method_system_ability.cpp @@ -209,11 +209,11 @@ namespace MiscServices { if (it == msgHandlers.end()) { IMSA_HILOGE("InputMethodSystemAbility::StartInputService() need start handler"); MessageHandler *handler = new MessageHandler(); - if (session == nullptr) { - IMSA_HILOGE("InputMethodSystemAbility::OnPrepareInput session is nullptr"); + if (session != nullptr) { + IMSA_HILOGE("InputMethodSystemAbility::OnPrepareInput session is not nullptr"); + session->CreateWorkThread(*handler); + msgHandlers.insert(std::pair(MAIN_USER_ID, handler)); } - session->CreateWorkThread(*handler); - msgHandlers.insert(std::pair(MAIN_USER_ID, handler)); } bool isStartSuccess = false; @@ -245,6 +245,7 @@ namespace MiscServices { PerUserSession *session = GetUserSession(MAIN_USER_ID); if (session == nullptr){ IMSA_HILOGE("InputMethodSystemAbility::StopInputService abort session is nullptr"); + return; } session->StopInputService(imeId); @@ -723,8 +724,6 @@ namespace MiscServices { } if (setting == nullptr || setting->GetUserState() != UserState::USER_STATE_UNLOCKED) { IMSA_HILOGE("InputMethodSystemAbility::OnHandleMessage Aborted! userId = %{public}d,", userId); - IMSA_HILOGE("InputMethodSystemAbility::OnHandleMessage Aborted! userState = %{public}d", - setting->GetUserState()); return ErrorCode::ERROR_USER_NOT_UNLOCKED; } @@ -848,6 +847,9 @@ namespace MiscServices { return ErrorCode::ERROR_USER_NOT_UNLOCKED; } PerUserSession *session = GetUserSession(userId); + if (session == nullptr) { + return ErrorCode::ERROR_NULL_POINTER; + } int32_t ret = session->OnSettingChanged(updatedKey, updatedValue); if (ret == ErrorCode::ERROR_SETTING_SAME_VALUE) { IMSA_HILOGI("End...No need to update\n"); diff --git a/services/src/peruser_session.cpp b/services/src/peruser_session.cpp index 5682952..a0275db 100644 --- a/services/src/peruser_session.cpp +++ b/services/src/peruser_session.cpp @@ -1182,6 +1182,7 @@ namespace MiscServices { InputAttribute *attribute = data->ReadParcelable(); if (attribute == nullptr) { IMSA_HILOGI("PerUserSession::OnPrepareInput attribute is nullptr"); + return; } int ret = AddClient(pid, uid, displayId, client, channel, *attribute); From 32e42254ad562a2a0a9f04be0703c233a2be1ea0 Mon Sep 17 00:00:00 2001 From: zhouyongfei Date: Thu, 17 Mar 2022 20:11:13 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E7=A1=AC=E9=94=AE?= =?UTF-8?q?=E7=9B=98=E5=93=8D=E5=BA=94=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 --- .../inputmethodengine/src/js_keyboard_delegate_listener.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/interfaces/kits/js/napi/inputmethodengine/src/js_keyboard_delegate_listener.cpp b/interfaces/kits/js/napi/inputmethodengine/src/js_keyboard_delegate_listener.cpp index df0bb2e..5427c42 100644 --- a/interfaces/kits/js/napi/inputmethodengine/src/js_keyboard_delegate_listener.cpp +++ b/interfaces/kits/js/napi/inputmethodengine/src/js_keyboard_delegate_listener.cpp @@ -149,13 +149,13 @@ namespace MiscServices { std::lock_guard lock(mMutex); IMSA_HILOGI("JsKeyboardDelegateListener::OnKeyEvent"); - bool result = false; + auto result = false; auto task = [this, keyCode, keyStatus, &result] () { NativeValue* nativeValue = engine_->CreateObject(); NativeObject* object = ConvertNativeValueTo(nativeValue); if (object == nullptr) { IMSA_HILOGI("Failed to convert rect to jsObject"); - return false; + return; } NativeValue* argv[] = {nativeValue}; std::string methodName; @@ -166,7 +166,7 @@ namespace MiscServices { } object->SetProperty("keyCode", CreateJsValue(*engine_, static_cast(keyCode))); object->SetProperty("keyAction", CreateJsValue(*engine_, static_cast(keyStatus))); - return CallJsMethodReturnBool(methodName, argv, ArraySize(argv)); + result = CallJsMethodReturnBool(methodName, argv, ArraySize(argv)); }; mainHandler_->PostSyncTask(task);