diff --git a/frameworks/inputmethod_ability/include/event_target.h b/frameworks/inputmethod_ability/include/event_target.h index afd0c49248d0e9a3902cc980759bcfb03d83a338..e4aa7509a3f686d77fa98fd9864075f8a98018e8 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: + static const int LISTENER_TYPTE_MAX_LENGTH = 64; }; } } diff --git a/frameworks/inputmethod_ability/include/input_method_core_stub.h b/frameworks/inputmethod_ability/include/input_method_core_stub.h index 72dea34e58f8d89172d9989e937789ff439cf8d2..4bf35db6d41ed6fe10bfb595b6d220122f3a6386 100644 --- a/frameworks/inputmethod_ability/include/input_method_core_stub.h +++ b/frameworks/inputmethod_ability/include/input_method_core_stub.h @@ -16,13 +16,13 @@ #ifndef FM_IMMS_PROJECT_INPUTCONTROLCHANNEL_SK_H #define FM_IMMS_PROJECT_INPUTCONTROLCHANNEL_SK_H +#include +#include +#include #include "iremote_broker.h" #include "iremote_stub.h" #include "i_input_method_agent.h" #include "input_channel.h" -#include -#include -#include #include "message_parcel.h" #include "input_attribute.h" #include "i_input_data_channel.h" diff --git a/frameworks/inputmethod_ability/src/event_target.cpp b/frameworks/inputmethod_ability/src/event_target.cpp index 4c6f1b032f04058bf1d970829101b6c5b40eb1f8..f769c719c1827675fc71f09d5586c5d515c60d45 100644 --- a/frameworks/inputmethod_ability/src/event_target.cpp +++ b/frameworks/inputmethod_ability/src/event_target.cpp @@ -19,10 +19,10 @@ #include "utils/log.h" #include "input_method_ability.h" -#define LISTENER_TYPTE_MAX_LENGTH 64 namespace OHOS { namespace MiscServices { struct EventListener { + static const int LISTENER_TYPTE_MAX_LENGTH = 64; char type[LISTENER_TYPTE_MAX_LENGTH] = { 0 }; bool isOnce = false; napi_ref handlerRef = nullptr; @@ -181,6 +181,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 +191,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 +203,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 +222,11 @@ 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 c14fd5ff083bae4e7634b44ef7aab4f755bcc780..1f3b59d71c64968fe4fcea079ca61137d0b6dbf3 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 1e06f7e0fee51d11551dde38f4d2beb030e6038d..e148163178c5366b96c6d4986feb64f542fd9f8d 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_agent_stub.cpp b/frameworks/inputmethod_ability/src/input_method_agent_stub.cpp index f562d973ce734018c7fd50635748afb59dfc547b..c75abde85ace431bcd3ce6dfc90a82e7447d58f3 100644 --- a/frameworks/inputmethod_ability/src/input_method_agent_stub.cpp +++ b/frameworks/inputmethod_ability/src/input_method_agent_stub.cpp @@ -24,6 +24,7 @@ namespace MiscServices { InputMethodAgentStub::InputMethodAgentStub() { + msgHandler_ = nullptr; } InputMethodAgentStub::~InputMethodAgentStub() diff --git a/frameworks/inputmethod_ability/src/input_method_core_proxy.cpp b/frameworks/inputmethod_ability/src/input_method_core_proxy.cpp index 58dc01ac53609eddf0cd0a056c23aff6ae7d0ff6..113207af51e57db66940e3dd098a42ef14eaa27c 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 bf51a666e6a3bd35c8a8ef1d3cc4f73c35fe788c..a0d5a0f667312db50b87b1191cc055277551b3e7 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 a6324edf847d0dc46371f6c09ec09f289d4da39a..fbac59e8dc17d77b3c34b7c5e25b5541cd36222f 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/include/input_client_stub.h b/frameworks/inputmethod_controller/include/input_client_stub.h index 08fa114acb709b7edbf296f65c9d92821eceeaca..ae193a68eb292bef9c0b7d6892b0de2043ab177b 100644 --- a/frameworks/inputmethod_controller/include/input_client_stub.h +++ b/frameworks/inputmethod_controller/include/input_client_stub.h @@ -33,7 +33,7 @@ namespace MiscServices { void SetHandler(MessageHandler *handler); int32_t onInputReady(int32_t retValue, const sptr& agent, - const InputChannel *channel) override; + const InputChannel *channel) override; int32_t onInputReleased(int32_t retValue) override; int32_t setDisplayMode(int32_t mode) override; private: diff --git a/frameworks/inputmethod_controller/include/input_method_system_ability_proxy.h b/frameworks/inputmethod_controller/include/input_method_system_ability_proxy.h index 2bda76ed189c2aee8ff77d5478fc31457c605748..fcd4e596055e1017cdbaaeb658182344c0055de9 100644 --- a/frameworks/inputmethod_controller/include/input_method_system_ability_proxy.h +++ b/frameworks/inputmethod_controller/include/input_method_system_ability_proxy.h @@ -29,7 +29,7 @@ namespace OHOS { namespace MiscServices { -class InputMethodSystemAbilityProxy : public IRemoteProxy { + class InputMethodSystemAbilityProxy : public IRemoteProxy { public: explicit InputMethodSystemAbilityProxy(const sptr &object); ~InputMethodSystemAbilityProxy() = default; diff --git a/frameworks/inputmethod_controller/src/input_method_controller.cpp b/frameworks/inputmethod_controller/src/input_method_controller.cpp index b5a5433072c3624c7ba99dad8f663a79a63e4dc3..3e5ab885c3a71d4afd49717cadc4742c5b93ac92 100644 --- a/frameworks/inputmethod_controller/src/input_method_controller.cpp +++ b/frameworks/inputmethod_controller/src/input_method_controller.cpp @@ -64,7 +64,7 @@ using namespace MessageID; mInputDataChannel = new InputDataChannelStub(); mInputDataChannel->SetHandler(msgHandler); - workThreadHandler = std::thread([this]{WorkThread();}); + workThreadHandler = std::thread([this] {WorkThread();}); mAttribute.SetInputPattern(InputAttribute::PATTERN_TEXT); textListener = nullptr; diff --git a/interfaces/kits/js/declaration/api/@ohos.inputmethodengine.d.ts b/interfaces/kits/js/declaration/api/@ohos.inputmethodengine.d.ts index 0d4ef4db27534035b7d01523ced36fcd86f93fd9..6daa45ffff5190bae8a535969cda466ba0dca673 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/interfaces/kits/js/napi/js_input_method_engine.cpp b/interfaces/kits/js/napi/js_input_method_engine.cpp index 00394d2202f156cbb73bcea6f889954346330fc6..e044d1fca0cb6da99c240fd4f5241f92f384eb50 100644 --- a/interfaces/kits/js/napi/js_input_method_engine.cpp +++ b/interfaces/kits/js/napi/js_input_method_engine.cpp @@ -213,8 +213,8 @@ namespace MiscServices { */ extern "C" __attribute__((constructor)) void RegisterModule() { - IMSA_HILOGI("RegisterModule() is called!"); - napi_module_register(&inputMethodEngineModule); + IMSA_HILOGI("RegisterModule() is called!"); + napi_module_register(&inputMethodEngineModule); } } } \ No newline at end of file diff --git a/services/include/i_platform_api.h b/services/include/i_platform_api.h index 1c7066c50728cc989927cc8586e9fe1e486f3373..006b03955c38361bd34cc0fd07b9fde1f349fa12 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/i_platform_callback.h b/services/include/i_platform_callback.h index e45548666deb386776a535fa0dd2c2668cebc00d..2c94b538b45870c9f19a5e84ce7014f3894d4f24 100644 --- a/services/include/i_platform_callback.h +++ b/services/include/i_platform_callback.h @@ -23,17 +23,17 @@ #include "global.h" namespace OHOS { - namespace MiscServices { - class IPlatformCallback : public IRemoteBroker { - public: - enum { - NOTIFY_EVENT = OHOS::FIRST_CALL_TRANSACTION, - }; +namespace MiscServices { + class IPlatformCallback : public IRemoteBroker { + public: + enum { + NOTIFY_EVENT = OHOS::FIRST_CALL_TRANSACTION, + }; - DECLARE_INTERFACE_DESCRIPTOR(u"ohos.miscservices.inputmethod.IPlatformCallback"); + DECLARE_INTERFACE_DESCRIPTOR(u"ohos.miscservices.inputmethod.IPlatformCallback"); - virtual void notifyEvent(int eventId, int userId, const std::vector& eventContent) = 0; - }; - } + virtual void notifyEvent(int eventId, int userId, const std::vector& eventContent) = 0; + }; +} } #endif // FM_IMMS_PROJECT_IPLATFORMCALLBACK_H diff --git a/services/include/input_control_channel_stub.h b/services/include/input_control_channel_stub.h index b1addd9fa6aed916a2a41ee1d6db8d9d11f8d876..bcaa1dfdffb5b639980abdcb3be62a8ac029acd5 100644 --- a/services/include/input_control_channel_stub.h +++ b/services/include/input_control_channel_stub.h @@ -16,12 +16,12 @@ #ifndef FM_IMMS_PROJECT_INPUTCONTROLCHANNELSTUB_H #define FM_IMMS_PROJECT_INPUTCONTROLCHANNELSTUB_H +#include +#include #include "iremote_broker.h" #include "iremote_stub.h" #include "i_input_method_agent.h" #include "input_channel.h" -#include -#include #include "message_parcel.h" #include "i_input_control_channel.h" diff --git a/services/include/input_method_setting.h b/services/include/input_method_setting.h index 589fa65612d79a6ea7c50421fb8520005104ecac..0594a12457345a99fabb98ece8fe7187e58c45e0 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 df9c38edb17b54a3647c57a2dcd7cebe2200ff94..c04361ecc78e5f48746f2acec031f3d3b1045506 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; @@ -35,6 +36,7 @@ namespace MiscServices { void setInputMethodCoreFromHap(MessageParcel& data); protected: int32_t getUserId(int32_t uid); + int USER_ID_CHANGE_VALUE = 1000000; }; } } diff --git a/services/include/message_handler.h b/services/include/message_handler.h index 56ca14e60de8f3993c91aa2d35bb15256fdc43d6..93e894692aae4440e53c2bf267b5ba4e9ddb2f07 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, @@ -76,7 +76,7 @@ namespace MessageID { }; } -class MessageHandler { + class MessageHandler { public: MessageHandler(); ~MessageHandler(); diff --git a/services/include/peruser_session.h b/services/include/peruser_session.h index 7f1b3bd1248466569330a1a6ddd1588b0ab67608..84b63402c2fa4a4485ae670ae5d4283050920b5c 100644 --- a/services/include/peruser_session.h +++ b/services/include/peruser_session.h @@ -122,6 +122,10 @@ namespace MiscServices { int currentIndex; std::map, ClientInfo*> mapClients; int MIN_IME = 2; + 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 @@ -146,7 +150,6 @@ namespace MiscServices { std::mutex mtx; // mutex to lock the operations among multi work threads sptr connCallback; sptr inputMethodAbility_; - int SLEEP_TIME = 300000; PerUserSession(const PerUserSession&); PerUserSession& operator =(const PerUserSession&); diff --git a/services/include/peruser_setting.h b/services/include/peruser_setting.h index a6daf8ba24ab6a89bd80e2859fbfa92c535d5bff..28e1a5575d2da7cb32dac883b456c5a60caa1715 100644 --- a/services/include/peruser_setting.h +++ b/services/include/peruser_setting.h @@ -58,6 +58,7 @@ namespace MiscServices { std::vector inputMethodProperties; // a vector to save all IME installed for this user std::u16string currentImeId; // the id of the default input method engine. InputMethodSetting inputMethodSetting; // the object to manage the setting data for this user + int COMMON_COUNT_ONE_HUNDRED_THOUSAND = 100000; PerUserSetting(const PerUserSetting&); PerUserSetting& operator =(const PerUserSetting&); diff --git a/services/include/platform_callback_stub.h b/services/include/platform_callback_stub.h index 504f1d6a57b90021b1293048d0d8842154c00422..b20b5142a8c4922e89d5bcde7a3386f2cfe2da6f 100644 --- a/services/include/platform_callback_stub.h +++ b/services/include/platform_callback_stub.h @@ -23,17 +23,16 @@ #include "i_platform_callback.h" namespace OHOS { - namespace MiscServices { - class PlatformCallbackStub : public IRemoteStub { - public: - PlatformCallbackStub(); - ~PlatformCallbackStub(); +namespace MiscServices { + class PlatformCallbackStub : public IRemoteStub { + public: + PlatformCallbackStub(); + ~PlatformCallbackStub(); - virtual int OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, - MessageOption &option) override; - virtual void notifyEvent(int eventId, int userId, const std::vector& eventContent) override; - }; - - } + virtual int OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, + MessageOption &option) override; + virtual void notifyEvent(int eventId, int userId, const std::vector& eventContent) override; + }; +} } #endif // FM_IMMS_PROJECT_PLATFORMCALLBACK_SK_H diff --git a/services/include/utils.h b/services/include/utils.h index 4e24b67405131d8e85e867854b7d8cc06db29123..8cb9d01db7eb914378e86681803366078c6c68ba 100644 --- a/services/include/utils.h +++ b/services/include/utils.h @@ -19,20 +19,21 @@ #define FM_IMMS_PROJECT_UTILS_H #include -#include #include #include namespace OHOS { namespace MiscServices { class Utils { - public: - 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) { - return std::wstring_convert, char16_t>{}.from_bytes(str); - } + public: + 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) + { + return std::wstring_convert, char16_t> {}.from_bytes(str); + } }; } } diff --git a/services/src/input_attribute.cpp b/services/src/input_attribute.cpp index e739e8111975fadf0d88dbadcd3d7daf91398bc6..3e1cb6dc48e2d788b4da4ad745f870d71e759eca 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_control_channel_stub.cpp b/services/src/input_control_channel_stub.cpp index 903b9903539ba8c1e1dd7d6642111e36d38e251e..4fb9204c968947dcb03b63fedfbbcc15493f92d8 100644 --- a/services/src/input_control_channel_stub.cpp +++ b/services/src/input_control_channel_stub.cpp @@ -13,8 +13,6 @@ * limitations under the License. */ -#include -#include #include "message_handler.h" #include "input_control_channel_stub.h" #include "i_input_control_channel.h" diff --git a/services/src/input_method_ability_connection_stub.cpp b/services/src/input_method_ability_connection_stub.cpp index 88dc89281680f0181a43a9df2ac702b2004bdebf..b5108c998a1b8366aa0b9cfcac065c0a3fc95cad 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 349f82162d0db423bde76110686453fda8725c44..904015035277279108b200756ecf90b2a30dfad3 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 fee4092d114362d55de9b9ee6280f25fc1781903..71b6ddf2d102c0dd84078b19204face0eeda13dc 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; @@ -582,7 +582,7 @@ namespace MiscServices { std::map::iterator it = msgHandlers.find(userId); if (it != msgHandlers.end()) { MessageHandler *handler = it->second; - Message *destMsg = new Message(MSG_ID_USER_LOCK , nullptr); + Message *destMsg = new Message(MSG_ID_USER_LOCK, nullptr); if (destMsg != nullptr) { handler->SendMessage(destMsg); PerUserSession *userSession = GetUserSession(userId); diff --git a/services/src/input_method_system_ability_stub.cpp b/services/src/input_method_system_ability_stub.cpp index 81ceaea94d3b45fd862f2e5c45402452389c72d8..9532c5720d26e31a8371040b050213d995501181 100644 --- a/services/src/input_method_system_ability_stub.cpp +++ b/services/src/input_method_system_ability_stub.cpp @@ -207,7 +207,6 @@ namespace MiscServices { Message *msg = new Message(MSG_ID_RELEASE_INPUT, parcel); MessageHandler::Instance()->SendMessage(msg); - } /*! Start input @@ -271,7 +270,7 @@ namespace MiscServices { */ int32_t InputMethodSystemAbilityStub::getUserId(int32_t uid) { - return uid/1000000; + return uid/USER_ID_CHANGE_VALUE; } } } \ No newline at end of file diff --git a/services/src/keyboard_type.cpp b/services/src/keyboard_type.cpp index 59566591b363886266a242871652d7b7b2b9d2cf..237052bf11bb84c728c03d4fa0943c9ea8d1d676 100644 --- a/services/src/keyboard_type.cpp +++ b/services/src/keyboard_type.cpp @@ -106,11 +106,10 @@ namespace MiscServices { { mId = typeId; if (typeId != ID_NONE) { - mHashCode = typeId; + mHashCode = typeId; } else { - mHashCode = ID_NONE; + mHashCode = ID_NONE; } - } void KeyboardType::setLabelId(int32_t labelId) diff --git a/services/src/message_handler.cpp b/services/src/message_handler.cpp index 46ab8deff00465178e8e435f49189ee687af17ed..d69fe04ea422b72747422535f762acf3dd55f886 100644 --- a/services/src/message_handler.cpp +++ b/services/src/message_handler.cpp @@ -46,7 +46,7 @@ namespace MiscServices { std::unique_lock lock(mMutex); mQueue.push(msg); } - mCV.notify_one(); + mCV.notify_one(); } /*! Get a message @@ -56,7 +56,7 @@ namespace MiscServices { Message *MessageHandler::GetMessage() { std::unique_lock lock(mMutex); - mCV.wait(lock, [this]{ + mCV.wait(lock, [this] { return !this->mQueue.empty(); }); diff --git a/services/src/peruser_session.cpp b/services/src/peruser_session.cpp index cdcebe40886b87894c501a2bacb53934db6975ef..8a220a0392ecaf0b93f055fe8e9aa19d14d4be40 100644 --- a/services/src/peruser_session.cpp +++ b/services/src/peruser_session.cpp @@ -12,16 +12,14 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - -#include -#include "unistd.h" //usleep -#include "peruser_session.h" +#include "unistd.h" // usleep #include "platform.h" #include "parcel.h" #include "message_parcel.h" #include "utils.h" #include "want.h" #include "input_method_ability_connection_stub.h" +#include "peruser_session.h" #include "ability_connect_callback_proxy.h" #include "ability_manager_interface.h" #include "sa_mgr_client.h" @@ -101,7 +99,7 @@ namespace MiscServices { void PerUserSession::CreateWorkThread(MessageHandler& handler) { msgHandler = &handler; - workThreadHandler = std::thread([this]{WorkThread();}); + workThreadHandler = std::thread([this] {WorkThread();}); } /*! Wait till work thread exits @@ -266,10 +264,12 @@ namespace MiscServices { } if (flag) { int ret = StartInputMethod(i); + if (ret != ErrorCode::NO_ERROR) { + needReshowClient = nullptr; + break; + } if (needReshowClient && GetImeIndex(needReshowClient) == i) { - if (ret == ErrorCode::NO_ERROR) { - ShowKeyboard(needReshowClient); - } + ShowKeyboard(needReshowClient); needReshowClient = nullptr; } } @@ -502,11 +502,13 @@ namespace MiscServices { ret = imsCore[index]->showKeyboard(1); if (!ret) { - IMSA_HILOGE("PerUserSession::ShowKeyboard Aborted! showKeyboard has error : %{public}s", ErrorCode::ToString(ret)); + IMSA_HILOGE("PerUserSession::ShowKeyboard Aborted! showKeyboard has error : %{public}s", + ErrorCode::ToString(ret)); int ret_client = clientInfo->client->onInputReady(1, nullptr, nullptr); if (ret_client != ErrorCode::NO_ERROR) { - IMSA_HILOGE("PerUserSession::ShowKeyboard onInputReady has error : %{public}s", ErrorCode::ToString(ret_client)); + IMSA_HILOGE("PerUserSession::ShowKeyboard onInputReady has error : %{public}s", + ErrorCode::ToString(ret_client)); } return ErrorCode::ERROR_KBD_SHOW_FAILED; } @@ -517,7 +519,8 @@ namespace MiscServices { int result = clientInfo->client->onInputReady(0, imsAgent, imsChannel); if (result != ErrorCode::NO_ERROR) { - IMSA_HILOGE("PerUserSession::ShowKeyboard Aborted! onInputReady return : %{public}s", ErrorCode::ToString(ret)); + IMSA_HILOGE("PerUserSession::ShowKeyboard Aborted! onInputReady return : %{public}s", + ErrorCode::ToString(ret)); return result; } currentClient = inputClient; @@ -564,7 +567,8 @@ namespace MiscServices { int ret_client_stop = clientInfo->client->onInputReady(1, nullptr, nullptr); if (ret_client_stop != ErrorCode::NO_ERROR) { - IMSA_HILOGE("PerUserSession::HideKeyboard onInputReady return : %{public}s", ErrorCode::ToString(ret_client_stop)); + IMSA_HILOGE("PerUserSession::HideKeyboard onInputReady return : %{public}s", + ErrorCode::ToString(ret_client_stop)); } currentClient = nullptr; imsAgent = nullptr; @@ -692,7 +696,7 @@ namespace MiscServices { StopInputMethod(1 - index); } - if (IncreaseOrResetImeError(false, index) == 3) { + if (IncreaseOrResetImeError(false, index) == IME_ERROR_CODE) { // call to disable the current input method. MessageParcel *parcel = new MessageParcel(); parcel->WriteInt32(userId_); @@ -707,7 +711,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_); @@ -851,7 +855,7 @@ namespace MiscServices { return; } int size = 0; - if (index == SECURITY_IME || currentIme[DEFAULT_IME] == currentIme[SECURITY_IME] ) { + if (index == SECURITY_IME || currentIme[DEFAULT_IME] == currentIme[SECURITY_IME]) { size = currentIme[index]->mTypes.size(); } else { std::u16string imeId = currentIme[index]->mImeId; @@ -989,8 +993,8 @@ 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; - if (diffSeconds > 300) { + // time difference is more than 5 minutes, reset time and error num; + if (diffSeconds > COMMON_COUNT_THREE_HUNDRED) { past[imeIndex] = now; errorNum[imeIndex] = 1; } @@ -1036,6 +1040,9 @@ namespace MiscServices { */ void PerUserSession::ResetCurrentKeyboardType(int imeIndex) { + if (imeIndex < 0 || imeIndex > 1) { + return; + } currentKbdIndex[imeIndex] = 0; int hashCode = 0; if (imeIndex == DEFAULT_IME) { diff --git a/services/src/peruser_setting.cpp b/services/src/peruser_setting.cpp index 3f3caa0466a4d6b1297fcac20da97e4d8aea2e82..574d92108ee7f7876937850f06beca9f70c6b054 100644 --- a/services/src/peruser_setting.cpp +++ b/services/src/peruser_setting.cpp @@ -12,8 +12,8 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - -#include "unistd.h" //usleep + +#include "unistd.h" // usleep #include "peruser_setting.h" #include "platform.h" #include "utils.h" @@ -67,14 +67,15 @@ namespace MiscServices { } } - /*! Add an input method engine. - \n It's called when a package is installed in the system. - \param packageName the package name of installed package. - \param[out] isSecurityIme check if the added ime is a security ime. - \return ErrorCode::NO_ERROR The installed package is an IME package, and is added in the input method management system - \return ErrorCode::ERROR_NOT_IME_PACKAGE The installed package is not an IME package. - \return ErrorCode::ERROR_IME_PACKAGE_DUPLICATED The installed package is duplicated. - */ + /** + * Add an input method engine.It's called when a package is installed in the system. + * @param packageName the package name of installed package. + * @param isSecurityIme check if the added ime is a security ime. + * @return ErrorCode::NO_ERROR The installed package is an IME package, + * and is added in the input method management system + * ErrorCode::ERROR_NOT_IME_PACKAGE The installed package is not an IME package. + * ErrorCode::ERROR_IME_PACKAGE_DUPLICATED The installed package is duplicated. + */ int PerUserSetting::OnPackageAdded(std::u16string& packageName, bool isSecurityIme) { if (isSecurityIme) { @@ -116,13 +117,15 @@ namespace MiscServices { return ErrorCode::NO_ERROR; } - /*! Remove an input method engine. - \n It's called when a package is removed from the system. - \param packageName the package name of installed package. - \param[out] isSecurityIme check if the removed ime is a security ime. - \return ErrorCode::NO_ERROR The removed package is an IME package, and is removed from the input method management system - \return ErrorCode::ERROR_NOT_IME_PACKAGE The removed package is not an IME package. - */ + /** + * Remove an input method engine. + * It's called when a package is removed from the system. + * @param packageName the package name of installed package. + * @param isSecurityIme check if the removed ime is a security ime. + * @return ErrorCode::NO_ERROR The removed package is an IME package, + * and is removed from the input method management system + * ErrorCode::ERROR_NOT_IME_PACKAGE The removed package is not an IME package. + */ int PerUserSetting::OnPackageRemoved(std::u16string& packageName, bool isSecurityIme) { if (isSecurityIme) { @@ -165,8 +168,7 @@ namespace MiscServices { } Platform::Instance()->SetInputMethodSetting(userId_, imSetting); // wait for some time so that the setting change will not be overrided by the followed transact - int32_t sleepTime = 100000; - usleep(sleepTime); + usleep(COMMON_COUNT_ONE_HUNDRED_THOUSAND); return ErrorCode::NO_ERROR; } diff --git a/services/src/platform_api_proxy.cpp b/services/src/platform_api_proxy.cpp index 674eaf95b652639f4663ab93b4cc3de106dff618..5cf2b198eb12ff8c6a898562a408b89a32f1bf12 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; } @@ -167,7 +167,6 @@ namespace MiscServices { return ErrorCode::NO_ERROR; } - virtual int32_t getInputMethodProperty(int userId, const std::u16string& packageName, InputMethodProperty *inputMethodProperty) { diff --git a/unitest/BUILD.gn b/unitest/BUILD.gn index 25526308897ee138a2cfc06c1daa56c52330727e..e9c817928847a2102ac44ab5097691d51817b650 100644 --- a/unitest/BUILD.gn +++ b/unitest/BUILD.gn @@ -43,7 +43,6 @@ ohos_unittest("InputMethodControllerTest") { "//foundation/distributedschedule/samgr/interfaces/innerkits/samgr_proxy:samgr_proxy", "//third_party/googletest:gtest_main", "//utils/native/base:utils", - "//utils/native/base:utils", ] external_deps = [ "hiviewdfx_hilog_native:libhilog" ] @@ -71,7 +70,6 @@ ohos_unittest("InputMethodAbilityTest") { "//foundation/distributedschedule/samgr/interfaces/innerkits/samgr_proxy:samgr_proxy", "//third_party/googletest:gtest_main", "//utils/native/base:utils", - "//utils/native/base:utils", ] external_deps = [ "hiviewdfx_hilog_native:libhilog" ]