diff --git a/frameworks/inputmethod_ability/include/input_method_ability.h b/frameworks/inputmethod_ability/include/input_method_ability.h index 00674e9..01bfd53 100644 --- a/frameworks/inputmethod_ability/include/input_method_ability.h +++ b/frameworks/inputmethod_ability/include/input_method_ability.h @@ -53,6 +53,7 @@ namespace MiscServices { int32_t displyId = 0; sptr startInputToken; InputChannel *writeInputChannel; + bool stop_; // communicating with IMSA sptr inputControlChannel; diff --git a/frameworks/inputmethod_ability/src/input_method_ability.cpp b/frameworks/inputmethod_ability/src/input_method_ability.cpp index 4749eaf..9e2c15c 100644 --- a/frameworks/inputmethod_ability/src/input_method_ability.cpp +++ b/frameworks/inputmethod_ability/src/input_method_ability.cpp @@ -29,7 +29,7 @@ namespace MiscServices { sptr InputMethodAbility::instance_; std::mutex InputMethodAbility::instanceLock_; - InputMethodAbility::InputMethodAbility() + InputMethodAbility::InputMethodAbility() : stop_(false) { Initialize(); OnConnect(); @@ -41,6 +41,7 @@ namespace MiscServices { delete msgHandler; msgHandler = nullptr; } + stop_ = true; } sptr InputMethodAbility::GetInstance() @@ -109,7 +110,7 @@ namespace MiscServices { void InputMethodAbility::WorkThread() { - while (1) { + while (!stop_) { Message *msg = msgHandler->GetMessage(); switch (msg->msgId_) { case MSG_ID_INITIALIZE_INPUT: { diff --git a/frameworks/inputmethod_ability/src/input_method_core_stub.cpp b/frameworks/inputmethod_ability/src/input_method_core_stub.cpp index d1d0862..bf51a66 100644 --- a/frameworks/inputmethod_ability/src/input_method_core_stub.cpp +++ b/frameworks/inputmethod_ability/src/input_method_core_stub.cpp @@ -33,6 +33,7 @@ namespace MiscServices { InputMethodCoreStub::InputMethodCoreStub(int userId) { userId_ = userId; + msgHandler_ = nullptr; } InputMethodCoreStub::~InputMethodCoreStub() diff --git a/frameworks/inputmethod_controller/include/input_method_controller.h b/frameworks/inputmethod_controller/include/input_method_controller.h index 31a4e05..84f9902 100644 --- a/frameworks/inputmethod_controller/include/input_method_controller.h +++ b/frameworks/inputmethod_controller/include/input_method_controller.h @@ -77,6 +77,7 @@ namespace MiscServices { static sptr instance_; std::thread workThreadHandler; MessageHandler *msgHandler; + bool stop_; }; } } diff --git a/frameworks/inputmethod_controller/src/input_method_controller.cpp b/frameworks/inputmethod_controller/src/input_method_controller.cpp index 4e45b62..23c6948 100644 --- a/frameworks/inputmethod_controller/src/input_method_controller.cpp +++ b/frameworks/inputmethod_controller/src/input_method_controller.cpp @@ -24,7 +24,7 @@ using namespace MessageID; sptr InputMethodController::instance_; std::mutex InputMethodController::instanceLock_; - InputMethodController::InputMethodController() + InputMethodController::InputMethodController() : stop_(false) { IMSA_HILOGI("InputMethodController structure"); Initialize(); @@ -35,6 +35,7 @@ using namespace MessageID; if (msgHandler != nullptr) { delete msgHandler; msgHandler = nullptr; + stop_ = false; } } @@ -97,7 +98,7 @@ using namespace MessageID; void InputMethodController::WorkThread() { - while (1) { + while (!stop_) { Message *msg = msgHandler->GetMessage(); switch (msg->msgId_) { case MSG_ID_INSERT_CHAR: { 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 96161a9..3ae9c12 100644 --- a/frameworks/inputmethod_controller/src/input_method_system_ability_proxy.cpp +++ b/frameworks/inputmethod_controller/src/input_method_system_ability_proxy.cpp @@ -303,7 +303,7 @@ namespace MiscServices { KeyboardType *keyType = reply.ReadParcelable(); if (keyType == nullptr) { - return ERROR_STATUS_BAD_INDEX; + return ERROR_NULL_POINTER; } *retType = *keyType; delete keyType; diff --git a/interfaces/kits/js/napi/js_input_method_engine.cpp b/interfaces/kits/js/napi/js_input_method_engine.cpp index 2941f56..00394d2 100644 --- a/interfaces/kits/js/napi/js_input_method_engine.cpp +++ b/interfaces/kits/js/napi/js_input_method_engine.cpp @@ -171,7 +171,6 @@ namespace MiscServices { eventTarget->Off(type); } - delete type; delete type; type = nullptr; napi_value result = nullptr; diff --git a/services/src/input_method_system_ability.cpp b/services/src/input_method_system_ability.cpp index 487bfd0..fee4092 100644 --- a/services/src/input_method_system_ability.cpp +++ b/services/src/input_method_system_ability.cpp @@ -583,11 +583,16 @@ namespace MiscServices { if (it != msgHandlers.end()) { MessageHandler *handler = it->second; Message *destMsg = new Message(MSG_ID_USER_LOCK , nullptr); - handler->SendMessage(destMsg); - GetUserSession(userId)->JoinWorkThread(); - msgHandlers.erase(it); - delete handler; - handler = nullptr; + if (destMsg != nullptr) { + handler->SendMessage(destMsg); + PerUserSession *userSession = GetUserSession(userId); + if (userSession != nullptr) { + userSession->JoinWorkThread(); + } + msgHandlers.erase(it); + delete handler; + handler = nullptr; + } } setting->OnUserLocked(); IMSA_HILOGI("End...[%d]\n", userId); @@ -705,6 +710,10 @@ namespace MiscServices { { IMSA_HILOGI("Start...\n"); MessageParcel *data = msg->msgContent_; + if (data == nullptr) { + IMSA_HILOGI("InputMethodSystemAbility::OnPackageRemoved data is nullptr"); + return ErrorCode::ERROR_NULL_POINTER; + } int32_t userId = data->ReadInt32(); int32_t size = data->ReadInt32(); @@ -719,6 +728,10 @@ namespace MiscServices { return ErrorCode::ERROR_USER_NOT_UNLOCKED; } PerUserSession *session = GetUserSession(userId); + if (session == nullptr) { + IMSA_HILOGI("InputMethodSystemAbility::OnPackageRemoved session is nullptr"); + return ErrorCode::ERROR_NULL_POINTER; + } session->OnPackageRemoved(packageName); bool securityImeFlag = false; int32_t ret = setting->OnPackageRemoved(packageName, securityImeFlag); diff --git a/services/src/peruser_session.cpp b/services/src/peruser_session.cpp index fb80334..d4d1f8f 100644 --- a/services/src/peruser_session.cpp +++ b/services/src/peruser_session.cpp @@ -977,8 +977,8 @@ namespace MiscServices { */ int PerUserSession::IncreaseOrResetImeError(bool resetFlag, int imeIndex) { - static int errorNum[MIN_IME] = {0, 0}; - static time_t past[MIN_IME] = {time(0), time(0)}; + static int errorNum[2] = {0, 0}; + static time_t past[2] = {time(0), time(0)}; if (resetFlag == true) { errorNum[imeIndex] = 0; past[imeIndex] = 0;