diff --git a/frameworks/inputmethod_ability/include/event_target.h b/frameworks/inputmethod_ability/include/event_target.h index e4aa750..afd0c49 100644 --- a/frameworks/inputmethod_ability/include/event_target.h +++ b/frameworks/inputmethod_ability/include/event_target.h @@ -45,9 +45,6 @@ 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 4bf35db..72dea34 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 f769c71..4c6f1b0 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,7 +181,6 @@ 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; } @@ -191,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; @@ -203,15 +202,13 @@ 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); } @@ -222,11 +219,12 @@ 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 1f3b59d..c14fd5f 100644 --- a/frameworks/inputmethod_ability/src/input_method_ability.cpp +++ b/frameworks/inputmethod_ability/src/input_method_ability.cpp @@ -32,7 +32,6 @@ namespace MiscServices { InputMethodAbility::InputMethodAbility() : stop_(false) { writeInputChannel = nullptr; - editorAttribute = nullptr; Initialize(); OnConnect(); } @@ -90,9 +89,8 @@ 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 e148163..1e06f7e 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 c75abde..f562d97 100644 --- a/frameworks/inputmethod_ability/src/input_method_agent_stub.cpp +++ b/frameworks/inputmethod_ability/src/input_method_agent_stub.cpp @@ -24,7 +24,6 @@ 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 113207a..58dc01a 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 a0d5a0f..bf51a66 100644 --- a/frameworks/inputmethod_ability/src/input_method_core_stub.cpp +++ b/frameworks/inputmethod_ability/src/input_method_core_stub.cpp @@ -12,6 +12,8 @@ * 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 fbac59e..a6324ed 100644 --- a/frameworks/inputmethod_controller/include/input_client_proxy.h +++ b/frameworks/inputmethod_controller/include/input_client_proxy.h @@ -22,14 +22,13 @@ 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 ae193a6..08fa114 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 fcd4e59..2bda76e 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 3e5ab88..b5a5433 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 6daa45f..0d4ef4d 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: () => void): void; + function HideKeyboardSelf(callback: 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 e044d1f..00394d2 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 006b039..1c7066c 100644 --- a/services/include/i_platform_api.h +++ b/services/include/i_platform_api.h @@ -56,6 +56,7 @@ 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 2c94b53..e455486 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"); + + virtual void notifyEvent(int eventId, int userId, const std::vector& eventContent) = 0; }; - - DECLARE_INTERFACE_DESCRIPTOR(u"ohos.miscservices.inputmethod.IPlatformCallback"); - - 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 bcaa1df..b1addd9 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 0594a12..589fa65 100644 --- a/services/include/input_method_setting.h +++ b/services/include/input_method_setting.h @@ -32,6 +32,7 @@ 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 c04361e..df9c38e 100644 --- a/services/include/input_method_system_ability_stub.h +++ b/services/include/input_method_system_ability_stub.h @@ -26,8 +26,7 @@ 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; @@ -36,7 +35,6 @@ 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 93e8946..56ca14e 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 84b6340..7f1b3bd 100644 --- a/services/include/peruser_session.h +++ b/services/include/peruser_session.h @@ -122,10 +122,6 @@ 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 @@ -150,6 +146,7 @@ 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 28e1a55..a6daf8b 100644 --- a/services/include/peruser_setting.h +++ b/services/include/peruser_setting.h @@ -58,7 +58,6 @@ 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 b20b514..504f1d6 100644 --- a/services/include/platform_callback_stub.h +++ b/services/include/platform_callback_stub.h @@ -23,16 +23,17 @@ #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 8cb9d01..4e24b67 100644 --- a/services/include/utils.h +++ b/services/include/utils.h @@ -19,21 +19,20 @@ #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 3e1cb6d..e739e81 100644 --- a/services/src/input_attribute.cpp +++ b/services/src/input_attribute.cpp @@ -21,7 +21,6 @@ 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 4fb9204..903b990 100644 --- a/services/src/input_control_channel_stub.cpp +++ b/services/src/input_control_channel_stub.cpp @@ -13,6 +13,8 @@ * 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 b5108c9..88dc892 100644 --- a/services/src/input_method_ability_connection_stub.cpp +++ b/services/src/input_method_ability_connection_stub.cpp @@ -22,7 +22,6 @@ 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 9040150..349f821 100644 --- a/services/src/input_method_property.cpp +++ b/services/src/input_method_property.cpp @@ -22,7 +22,6 @@ 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 71b6ddf..fee4092 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 9532c57..81ceaea 100644 --- a/services/src/input_method_system_ability_stub.cpp +++ b/services/src/input_method_system_ability_stub.cpp @@ -207,6 +207,7 @@ namespace MiscServices { Message *msg = new Message(MSG_ID_RELEASE_INPUT, parcel); MessageHandler::Instance()->SendMessage(msg); + } /*! Start input @@ -270,7 +271,7 @@ namespace MiscServices { */ int32_t InputMethodSystemAbilityStub::getUserId(int32_t uid) { - return uid/USER_ID_CHANGE_VALUE; + return uid/1000000; } } } \ No newline at end of file diff --git a/services/src/keyboard_type.cpp b/services/src/keyboard_type.cpp index 237052b..5956659 100644 --- a/services/src/keyboard_type.cpp +++ b/services/src/keyboard_type.cpp @@ -106,10 +106,11 @@ 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 d69fe04..46ab8de 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 8a220a0..cdcebe4 100644 --- a/services/src/peruser_session.cpp +++ b/services/src/peruser_session.cpp @@ -12,14 +12,16 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -#include "unistd.h" // usleep + +#include +#include "unistd.h" //usleep +#include "peruser_session.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 "peruser_session.h" #include "ability_connect_callback_proxy.h" #include "ability_manager_interface.h" #include "sa_mgr_client.h" @@ -99,7 +101,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 @@ -264,12 +266,10 @@ namespace MiscServices { } if (flag) { int ret = StartInputMethod(i); - if (ret != ErrorCode::NO_ERROR) { - needReshowClient = nullptr; - break; - } if (needReshowClient && GetImeIndex(needReshowClient) == i) { - ShowKeyboard(needReshowClient); + if (ret == ErrorCode::NO_ERROR) { + ShowKeyboard(needReshowClient); + } needReshowClient = nullptr; } } @@ -502,13 +502,11 @@ 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; } @@ -519,8 +517,7 @@ 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; @@ -567,8 +564,7 @@ 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; @@ -696,7 +692,7 @@ namespace MiscServices { StopInputMethod(1 - index); } - if (IncreaseOrResetImeError(false, index) == IME_ERROR_CODE) { + if (IncreaseOrResetImeError(false, index) == 3) { // call to disable the current input method. MessageParcel *parcel = new MessageParcel(); parcel->WriteInt32(userId_); @@ -711,7 +707,7 @@ namespace MiscServices { parcel->WriteInt32(index); parcel->WriteString16(currentIme[index]->mImeId); Message *msg = new Message(MSG_ID_RESTART_IMS, parcel); - usleep(SLEEP_TIME_MORE); // wait that PACKAGE_REMOVED message is received if this ime has been removed + usleep(1600*1000); // wait that PACKAGE_REMOVED message is received if this ime has been removed MessageHandler::Instance()->SendMessage(msg); } IMSA_HILOGI("End...[%{public}d]\n", userId_); @@ -855,7 +851,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; @@ -993,8 +989,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 > COMMON_COUNT_THREE_HUNDRED) { + //time difference is more than 5 minutes, reset time and error num; + if (diffSeconds > 300) { past[imeIndex] = now; errorNum[imeIndex] = 1; } @@ -1040,9 +1036,6 @@ 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 574d921..3f3caa0 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,15 +67,14 @@ namespace MiscServices { } } - /** - * 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. - */ + /*! 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. + */ int PerUserSetting::OnPackageAdded(std::u16string& packageName, bool isSecurityIme) { if (isSecurityIme) { @@ -117,15 +116,13 @@ namespace MiscServices { return ErrorCode::NO_ERROR; } - /** - * 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. - */ + /*! 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. + */ int PerUserSetting::OnPackageRemoved(std::u16string& packageName, bool isSecurityIme) { if (isSecurityIme) { @@ -168,7 +165,8 @@ namespace MiscServices { } Platform::Instance()->SetInputMethodSetting(userId_, imSetting); // wait for some time so that the setting change will not be overrided by the followed transact - usleep(COMMON_COUNT_ONE_HUNDRED_THOUSAND); + int32_t sleepTime = 100000; + usleep(sleepTime); return ErrorCode::NO_ERROR; } diff --git a/services/src/platform_api_proxy.cpp b/services/src/platform_api_proxy.cpp index 5cf2b19..674eaf9 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,6 +167,7 @@ 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 e9c8179..2552630 100644 --- a/unitest/BUILD.gn +++ b/unitest/BUILD.gn @@ -43,6 +43,7 @@ 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" ] @@ -70,6 +71,7 @@ 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" ]