diff --git a/README.md b/README.md index 9e01cbfaab10405f46413e01c6111295aadf6f27..1f57d1434dd33bcb46d1b68d821059d239814097 100644 --- a/README.md +++ b/README.md @@ -1,22 +1,50 @@ # miscservices_inputmethod -#### 介绍 -输入法框架 +####Introduction +Input Method Framework, is used to connect the application and input method. the application can input text through the input method -#### 安装教程 +####Warehouse path -1. 随版本烧录即可带上 +/base/miscservices/inputmethod -#### 使用说明 +####Introduction to framework code -1. 在编辑属性的控件中进行点击操作,即可通过输入法框架调起默认输入法应用 -2. 通过输入法应用可以进行打字,并上屏输入字符到应用客户端 +The input method framework currently has four modules, as follows: -#### 参与贡献 +1. Application client -1. Fork 本仓库 -2. 新建 Feat_master 分支 -3. 提交代码 -4. 新建 Pull Request +Path: /base/miscservices/inputmethod/frameworks/inputmethod_controller +Function: realize the service delivery of application and input method framework, including the binding between application and input method service, application display and hiding request for input method, etc + +2. Input method client + +Path: /base/miscservices/inputmethod/frameworks/inputmethod_ability + +Function: the intermediate bridge between input method framework service and input method delivery, including monitoring the current status of input method, etc + +3. Input method service + +Path: /base/miscservices/inputmethod/services + +Function: as the core of the input method framework, the main processing logic of the input method is completed here + +4. Input method JS interface + +Path: /base/miscservices/inputmethod/interfaces/kits/JS + +Function: the temporarily exposed JS interface is mainly reserved for calling input methods + +####Main functions supported by the framework + +1. Click in the edit attribute control to invoke the default input method application through the input method framework + +2. Typing can be carried out through the input method application, and characters can be input to the application client on the screen + +####Participation contribution + +1. Fork warehouse +2. Submission code +3. Create a new pull request +4. Commit is complete diff --git a/README_zh.md b/README_zh.md new file mode 100644 index 0000000000000000000000000000000000000000..0406b4d9453f8ba0810a4b36235f90b2d4cc23be --- /dev/null +++ b/README_zh.md @@ -0,0 +1,48 @@ +# miscservices_inputmethod + +#### 介绍 +输入法框架,主要作用是拉通应用和输入法,保证应用可以通过输入法进行文本输入 + +#### 仓路径 +/base/miscservices/inputmethod + +#### 框架代码介绍 +输入法框架目前有四大模块,具体如下: + +1. 应用客户端 + +路径:/base/miscservices/inputmethod/frameworks/inputmethod_controller + +作用:实现应用和输入法框架服务交付,包括应用与输入法服务的绑定、应用对输入法的显示和隐藏请求等等 + +2. 输入法客户端 + +路径:/base/miscservices/inputmethod/frameworks/inputmethod_ability + +作用:实现输入法框架服务与输入法交付的中间桥梁,包括监听输入法当前的状态等等 + +3. 输入法服务 + +路径:/base/miscservices/inputmethod/services + +作用:作为输入法框架的核心,输入法的主要处理逻辑都是在这里完成 + +4. 输入法Js接口 + +路径:/base/miscservices/inputmethod/interfaces/kits/js + +作用:暂时对外暴露的js接口,主要是留给输入法进行调用使用的 + +#### 框架主要支持功能 + +1.在编辑属性的控件中进行点击操作,即可通过输入法框架调起默认输入法应用 + +2.通过输入法应用可以进行打字,并上屏输入字符到应用客户端 + +#### 参与贡献 + +1. Fork 本仓库 +2. 提交代码 +3. 新建 Pull Request +4. commit完成即可 + diff --git a/frameworks/inputmethod_ability/include/event_target.h b/frameworks/inputmethod_ability/include/event_target.h index 5ff610cb8bc81b3fa0eb3a9141828e295e880592..bce87b7c8c33851c7386c8a06b47a85891bee2fb 100644 --- a/frameworks/inputmethod_ability/include/event_target.h +++ b/frameworks/inputmethod_ability/include/event_target.h @@ -13,8 +13,8 @@ * limitations under the License. */ -#ifndef FOUNDATION_ACE_NAPI_TEST_NATIVE_MODULE_NETSERVER_EVENT_TARGET_H -#define FOUNDATION_ACE_NAPI_TEST_NATIVE_MODULE_NETSERVER_EVENT_TARGET_H +#ifndef INPUT_METHOD_NAPI_EVENT_TARGET_H +#define INPUT_METHOD_NAPI_EVENT_TARGET_H #include "napi/native_api.h" #include "global.h" @@ -23,7 +23,6 @@ namespace OHOS { namespace MiscServices { struct EventListener; - class Event { public: virtual napi_value ToJsObject() = 0; @@ -48,4 +47,4 @@ protected: }; } } -#endif /* FOUNDATION_ACE_NAPI_TEST_NATIVE_MODULE_NETSERVER_EVENT_TARGET_H */ \ No newline at end of file +#endif // INPUT_METHOD_NAPI_EVENT_TARGET_H \ No newline at end of file diff --git a/frameworks/inputmethod_ability/include/input_method_ability.h b/frameworks/inputmethod_ability/include/input_method_ability.h index e43403290bc27c4a00f6cb2d3791028efe7c7fe0..fbb770f1729ccdca33192e068a44e44b949f83e3 100644 --- a/frameworks/inputmethod_ability/include/input_method_ability.h +++ b/frameworks/inputmethod_ability/include/input_method_ability.h @@ -66,7 +66,6 @@ namespace MiscServices { sptr mImms; sptr GetImsaProxy(); - void Initialize(); void WorkThread(); void CreateInputMethodAgent(bool supportPhysicalKbd); diff --git a/frameworks/inputmethod_ability/include/input_method_core_proxy.h b/frameworks/inputmethod_ability/include/input_method_core_proxy.h index 63db0e0f871044ea7739b554f83d8164e84fcb97..0b09b716c6d1d06404858384dfed3b8663b34df9 100644 --- a/frameworks/inputmethod_ability/include/input_method_core_proxy.h +++ b/frameworks/inputmethod_ability/include/input_method_core_proxy.h @@ -43,7 +43,7 @@ namespace MiscServices { virtual bool showKeyboard(int32_t flags) override; virtual bool hideKeyboard(int32_t flags) override; virtual int32_t setKeyboardType(const KeyboardType& type) override; - virtual int32_t getKeyboardWindowHeight(int32_t * retHeight) override; + virtual int32_t getKeyboardWindowHeight(int32_t *retHeight) override; private: static inline BrokerDelegator delegator_; diff --git a/frameworks/inputmethod_ability/include/input_method_core_stub.h b/frameworks/inputmethod_ability/include/input_method_core_stub.h index acb47cd8668cc39669dc2839c0d7efbcb55f8fae..bd2c229ec75b3e5f70fa816bc65f196342f5d260 100644 --- a/frameworks/inputmethod_ability/include/input_method_core_stub.h +++ b/frameworks/inputmethod_ability/include/input_method_core_stub.h @@ -52,7 +52,7 @@ namespace MiscServices { virtual bool showKeyboard(int32_t flags) override; virtual bool hideKeyboard(int32_t flags)override; virtual int32_t setKeyboardType(const KeyboardType& type) override; - virtual int32_t getKeyboardWindowHeight(int32_t * retHeight) override; + virtual int32_t getKeyboardWindowHeight(int32_t *retHeight) override; void SetMessageHandler(MessageHandler* msgHandler); private: diff --git a/frameworks/inputmethod_ability/src/input_method_ability.cpp b/frameworks/inputmethod_ability/src/input_method_ability.cpp index 6c144ca3c10086eba3c67221110c6fb6317bf99a..6b918451d3879dd75944f1205a5c522d59503206 100644 --- a/frameworks/inputmethod_ability/src/input_method_ability.cpp +++ b/frameworks/inputmethod_ability/src/input_method_ability.cpp @@ -12,9 +12,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - - - #include "input_method_ability.h" #include "input_method_core_proxy.h" #include "input_method_core_stub.h" diff --git a/frameworks/inputmethod_ability/src/input_method_agent_proxy.cpp b/frameworks/inputmethod_ability/src/input_method_agent_proxy.cpp index 5155eff8a82c54f9231604cd7d0cef67bff20de0..02dd7c490d7a776943ad152b34aed6e542ce9a9d 100644 --- a/frameworks/inputmethod_ability/src/input_method_agent_proxy.cpp +++ b/frameworks/inputmethod_ability/src/input_method_agent_proxy.cpp @@ -18,7 +18,8 @@ namespace OHOS { namespace MiscServices { using namespace ErrorCode; - InputMethodAgentProxy::InputMethodAgentProxy(const sptr &object) : IRemoteProxy(object) { + InputMethodAgentProxy::InputMethodAgentProxy(const sptr &object) + : IRemoteProxy(object) { } int32_t InputMethodAgentProxy::DispatchKey(int32_t key, int32_t status) { diff --git a/frameworks/inputmethod_ability/src/input_method_agent_stub.cpp b/frameworks/inputmethod_ability/src/input_method_agent_stub.cpp index 980e94755b0936f717abf3bc8a631103e9a85a3e..c2504abb98baa39514aa14faa4a8db2668519ca9 100644 --- a/frameworks/inputmethod_ability/src/input_method_agent_stub.cpp +++ b/frameworks/inputmethod_ability/src/input_method_agent_stub.cpp @@ -28,7 +28,8 @@ namespace MiscServices { InputMethodAgentStub::~InputMethodAgentStub() { } - int32_t InputMethodAgentStub::OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) { + int32_t InputMethodAgentStub::OnRemoteRequest(uint32_t code, MessageParcel &data, + MessageParcel &reply, MessageOption &option) { IMSA_HILOGI("InputMethodAgentStub::OnRemoteRequest code = %{public}d", code); auto descriptorToken = data.ReadInterfaceToken(); if (descriptorToken != GetDescriptor()) { diff --git a/frameworks/inputmethod_ability/src/input_method_core_proxy.cpp b/frameworks/inputmethod_ability/src/input_method_core_proxy.cpp index b6cf309b4b2025f136f1fc5852198431934f54b8..7d19a54156898842814d123fed50e6ddaea4a1ff 100644 --- a/frameworks/inputmethod_ability/src/input_method_core_proxy.cpp +++ b/frameworks/inputmethod_ability/src/input_method_core_proxy.cpp @@ -20,12 +20,14 @@ namespace OHOS { namespace MiscServices { - InputMethodCoreProxy::InputMethodCoreProxy(const OHOS::sptr &impl) : IRemoteProxy(impl) { + InputMethodCoreProxy::InputMethodCoreProxy(const OHOS::sptr &impl) + : IRemoteProxy(impl) { } InputMethodCoreProxy::~InputMethodCoreProxy() = default; - int32_t InputMethodCoreProxy::initializeInput(sptr &startInputToken, int32_t displayId, sptr &inputControlChannel) { + int32_t InputMethodCoreProxy::initializeInput(sptr &startInputToken, int32_t displayId, + sptr &inputControlChannel) { IMSA_HILOGI("InputMethodCoreProxy::initializeInput"); if (startInputToken == nullptr) { IMSA_HILOGI("InputMethodCoreProxy::initializeInput startInputToken is nullptr"); @@ -58,7 +60,8 @@ namespace MiscServices { return code; } - bool InputMethodCoreProxy::startInput(const sptr &inputDataChannel, const InputAttribute& editorAttribute, bool supportPhysicalKbd) { + bool InputMethodCoreProxy::startInput(const sptr &inputDataChannel, + const InputAttribute& editorAttribute, bool supportPhysicalKbd) { IMSA_HILOGI("InputMethodCoreProxy::startInput"); if (inputDataChannel == nullptr) { IMSA_HILOGI("InputMethodCoreProxy::startInput inputDataChannel is nullptr"); @@ -160,7 +163,7 @@ namespace MiscServices { return code; } - int32_t InputMethodCoreProxy::getKeyboardWindowHeight(int32_t * retHeight) { + int32_t InputMethodCoreProxy::getKeyboardWindowHeight(int32_t* retHeight) { IMSA_HILOGI("InputMethodCoreProxy::getKeyboardWindowHeight"); MessageParcel data, reply; data.WriteInterfaceToken(GetDescriptor()); diff --git a/frameworks/inputmethod_ability/src/input_method_core_stub.cpp b/frameworks/inputmethod_ability/src/input_method_core_stub.cpp index 07c39faeaa200a567e92fcac8362eb364ffc14a5..a7ecadab83e8218d49c66cbe3034e3cdc9d18442 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" @@ -39,7 +37,8 @@ namespace MiscServices { InputMethodCoreStub::~InputMethodCoreStub() { } - int32_t InputMethodCoreStub::OnRemoteRequest(uint32_t code, MessageParcel & data, MessageParcel & reply, MessageOption & option) { + int32_t InputMethodCoreStub::OnRemoteRequest(uint32_t code, MessageParcel& data, MessageParcel& reply, + MessageOption& option) { IMSA_HILOGI("InputMethodCoreStub::OnRemoteRequest"); auto descriptorToken = data.ReadInterfaceToken(); if (descriptorToken != GetDescriptor()) { @@ -112,7 +111,8 @@ namespace MiscServices { return NO_ERROR; } - int32_t InputMethodCoreStub::initializeInput(sptr& startInputToken, int32_t displayId, sptr& inputControlChannel) { + int32_t InputMethodCoreStub::initializeInput(sptr& startInputToken, int32_t displayId, + sptr& inputControlChannel) { IMSA_HILOGI("InputMethodCoreStub::initializeInput"); if (msgHandler_==nullptr) { return ErrorCode::ERROR_NULL_POINTER; @@ -133,7 +133,8 @@ namespace MiscServices { return ErrorCode::NO_ERROR; } - bool InputMethodCoreStub::startInput(const sptr& inputDataChannel, const InputAttribute& editorAttribute, bool supportPhysicalKbd) { + bool InputMethodCoreStub::startInput(const sptr& inputDataChannel, + const InputAttribute& editorAttribute, bool supportPhysicalKbd) { IMSA_HILOGI("InputMethodCoreStub::startInput"); if (msgHandler_ == nullptr) { return ErrorCode::ERROR_NULL_POINTER; @@ -202,7 +203,7 @@ namespace MiscServices { return ErrorCode::NO_ERROR; } - int32_t InputMethodCoreStub::getKeyboardWindowHeight(int32_t * retHeight) { + int32_t InputMethodCoreStub::getKeyboardWindowHeight(int32_t* retHeight) { IMSA_HILOGI("InputMethodCoreStub::getKeyboardWindowHeight"); if (msgHandler_==nullptr) { return ErrorCode::ERROR_NULL_POINTER; diff --git a/frameworks/inputmethod_controller/include/i_input_client.h b/frameworks/inputmethod_controller/include/i_input_client.h index 09438928ce83dab01593244f0bb1fff4147b4780..a55a5dcaa4408d6949c523efcabdbfde4d6ea757 100644 --- a/frameworks/inputmethod_controller/include/i_input_client.h +++ b/frameworks/inputmethod_controller/include/i_input_client.h @@ -27,21 +27,21 @@ */ namespace OHOS { namespace MiscServices { - class IInputClient : public IRemoteBroker { - public: - enum { - ON_INPUT_READY = 0, - ON_INPUT_RELEASED , - SET_DISPLAY_MODE , - }; + class IInputClient : public IRemoteBroker { + public: + enum { + ON_INPUT_READY = 0, + ON_INPUT_RELEASED, + SET_DISPLAY_MODE, + }; - DECLARE_INTERFACE_DESCRIPTOR(u"ohos.miscservices.inputmethod.InputClient"); + DECLARE_INTERFACE_DESCRIPTOR(u"ohos.miscservices.inputmethod.InputClient"); - virtual int32_t onInputReady(int32_t retValue, const sptr& agent, const InputChannel* channel) = 0; - virtual int32_t onInputReleased(int32_t retValue) = 0; - virtual int32_t setDisplayMode(int32_t mode) = 0; - }; + virtual int32_t onInputReady(int32_t retValue, const sptr& agent, + const InputChannel* channel) = 0; + virtual int32_t onInputReleased(int32_t retValue) = 0; + virtual int32_t setDisplayMode(int32_t mode) = 0; + }; } } - -#endif // FM_IMMS_PROJECT_IINPUTCLIENT_H +#endif // FM_IMMS_PROJECT_IINPUTCLIENT_H \ No newline at end of file diff --git a/frameworks/inputmethod_controller/include/i_input_data_channel.h b/frameworks/inputmethod_controller/include/i_input_data_channel.h index fc4270e2b3f999d7506599fbb54d507f3ae3ce7d..39e0a4fc734d2637fa9480dbf7d7cc89d1c7702f 100644 --- a/frameworks/inputmethod_controller/include/i_input_data_channel.h +++ b/frameworks/inputmethod_controller/include/i_input_data_channel.h @@ -25,7 +25,7 @@ */ namespace OHOS { namespace MiscServices { - class IInputDataChannel: public IRemoteBroker { + class IInputDataChannel : public IRemoteBroker { public: enum { INSERT_TEXT = 0, diff --git a/frameworks/inputmethod_controller/include/input_client_proxy.h b/frameworks/inputmethod_controller/include/input_client_proxy.h index 8d0fb6cc9fee160c269407071bc13288b6695bcd..c535f2f5fd85312e97bd14430c6042be6a359607 100644 --- a/frameworks/inputmethod_controller/include/input_client_proxy.h +++ b/frameworks/inputmethod_controller/include/input_client_proxy.h @@ -22,9 +22,7 @@ namespace OHOS { namespace MiscServices { - -class InputClientProxy : public IRemoteProxy -{ +class InputClientProxy : public IRemoteProxy { public: explicit InputClientProxy(const sptr &object); ~InputClientProxy() = default; diff --git a/frameworks/inputmethod_controller/include/input_data_channel_proxy.h b/frameworks/inputmethod_controller/include/input_data_channel_proxy.h index db55eb4a2d48d3298f5308d22a7f9e597218a7be..23c695129331650a00e8a3d95be22d948e9167f6 100644 --- a/frameworks/inputmethod_controller/include/input_data_channel_proxy.h +++ b/frameworks/inputmethod_controller/include/input_data_channel_proxy.h @@ -13,8 +13,6 @@ * limitations under the License. */ - - #ifndef FM_IMC_PROJECT_INPUTDATACHANNELPROXY_H #define FM_IMC_PROJECT_INPUTDATACHANNELPROXY_H @@ -23,21 +21,19 @@ namespace OHOS { namespace MiscServices { - -class InputDataChannelProxy : public IRemoteProxy -{ -public: - explicit InputDataChannelProxy(const sptr &object); - ~InputDataChannelProxy() = default; - DISALLOW_COPY_AND_MOVE(InputDataChannelProxy); - - bool InsertText(const std::u16string& text) override; - bool DeleteBackward(int32_t length) override; - void Close() override; - -private: - static inline BrokerDelegator delegator_; -}; + class InputDataChannelProxy : public IRemoteProxy { + public: + explicit InputDataChannelProxy(const sptr &object); + ~InputDataChannelProxy() = default; + DISALLOW_COPY_AND_MOVE(InputDataChannelProxy); + + bool InsertText(const std::u16string& text) override; + bool DeleteBackward(int32_t length) override; + void Close() override; + + private: + static inline BrokerDelegator delegator_; + }; } } #endif \ No newline at end of file diff --git a/frameworks/inputmethod_controller/include/input_method_controller.h b/frameworks/inputmethod_controller/include/input_method_controller.h index 474c7de45d44f0f87059738f55b419ef67f046e9..37a589cefdd50404ab123ed18af6567c3d183f7b 100644 --- a/frameworks/inputmethod_controller/include/input_method_controller.h +++ b/frameworks/inputmethod_controller/include/input_method_controller.h @@ -17,7 +17,6 @@ #ifndef FM_IMC_PROJECT_INPUTMETHODCONTROLLER_H #define FM_IMC_PROJECT_INPUTMETHODCONTROLLER_H -//#include "refbase.h" #include #include #include "input_data_channel_stub.h" @@ -30,7 +29,6 @@ namespace OHOS { namespace MiscServices { - class OnTextChangedListener : public virtual RefBase { public: virtual void InsertText(const std::u16string& text) = 0; @@ -60,7 +58,8 @@ namespace MiscServices { bool Initialize(); sptr GetImsaProxy(); - void PrepareInput(int32_t displayId,sptr &client,sptr &channel,InputAttribute &attribute); + void PrepareInput(int32_t displayId, sptr &client, sptr &channel, + InputAttribute &attribute); void StartInput(sptr &client); void StopInput(sptr &client); void ReleaseInput(sptr &client); @@ -71,7 +70,7 @@ namespace MiscServices { sptr mImms; sptr deathRecipient_; sptr mAgent; - sptr textListener; + OnTextChangedListener* textListener; InputAttribute mAttribute; static std::mutex instanceLock_; 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 447b78a5a4af4b2caf2f2c58759e565cb47952c4..973ab694f2095f6b541571afb622962472fcddf5 100644 --- a/frameworks/inputmethod_controller/include/input_method_system_ability_proxy.h +++ b/frameworks/inputmethod_controller/include/input_method_system_ability_proxy.h @@ -13,7 +13,6 @@ * limitations under the License. */ - #ifndef FM_IMC_PROJECT_INPUTMETHODSYSTEMABILITYPROXY_H #define FM_IMC_PROJECT_INPUTMETHODSYSTEMABILITYPROXY_H @@ -30,35 +29,34 @@ namespace OHOS { namespace MiscServices { - -class InputMethodSystemAbilityProxy : public IRemoteProxy -{ -public: - explicit InputMethodSystemAbilityProxy(const sptr &object); - ~InputMethodSystemAbilityProxy() = default; - DISALLOW_COPY_AND_MOVE(InputMethodSystemAbilityProxy); - - virtual void prepareInput(MessageParcel& data) override; - virtual void releaseInput(MessageParcel& data) override; - virtual void startInput(MessageParcel& data) override; - virtual void stopInput(MessageParcel& data) override; - virtual int32_t setInputMethodCore(sptr &core) override; - - int32_t Prepare(int32_t displayId, sptr &client, sptr &channel, InputAttribute &attribute); - int32_t Release(sptr &client); - int32_t Start(sptr &client); - int32_t Stop(sptr &client); - - virtual int32_t getDisplayMode(int32_t *retMode) override; - virtual int32_t getKeyboardWindowHeight(int32_t *retHeight) override; - virtual int32_t getCurrentKeyboardType(KeyboardType* retType) override; - virtual int32_t listInputMethodEnabled(std::vector *properties) override; - virtual int32_t listInputMethod(std::vector *properties) override; - virtual int32_t listKeyboardType(const std::u16string& imeId, std::vector *types) override; - -private: - static inline BrokerDelegator delegator_; -}; +class InputMethodSystemAbilityProxy : public IRemoteProxy { + public: + explicit InputMethodSystemAbilityProxy(const sptr &object); + ~InputMethodSystemAbilityProxy() = default; + DISALLOW_COPY_AND_MOVE(InputMethodSystemAbilityProxy); + + virtual void prepareInput(MessageParcel& data) override; + virtual void releaseInput(MessageParcel& data) override; + virtual void startInput(MessageParcel& data) override; + virtual void stopInput(MessageParcel& data) override; + virtual int32_t setInputMethodCore(sptr &core) override; + + int32_t Prepare(int32_t displayId, sptr &client, sptr &channel, + InputAttribute &attribute); + int32_t Release(sptr &client); + int32_t Start(sptr &client); + int32_t Stop(sptr &client); + + virtual int32_t getDisplayMode(int32_t *retMode) override; + virtual int32_t getKeyboardWindowHeight(int32_t *retHeight) override; + virtual int32_t getCurrentKeyboardType(KeyboardType* retType) override; + virtual int32_t listInputMethodEnabled(std::vector *properties) override; + virtual int32_t listInputMethod(std::vector *properties) override; + virtual int32_t listKeyboardType(const std::u16string& imeId, std::vector *types) override; + + private: + static inline BrokerDelegator delegator_; + }; } } #endif \ No newline at end of file diff --git a/frameworks/inputmethod_controller/src/input_client_proxy.cpp b/frameworks/inputmethod_controller/src/input_client_proxy.cpp index 25e66b239b4a875ca860b6956a3f7b8694e5a930..a34d424a7e0f6d9aae55d3f2ed5f82a79ceab69c 100644 --- a/frameworks/inputmethod_controller/src/input_client_proxy.cpp +++ b/frameworks/inputmethod_controller/src/input_client_proxy.cpp @@ -18,12 +18,11 @@ namespace OHOS { namespace MiscServices { using namespace ErrorCode; - InputClientProxy::InputClientProxy(const sptr &object) : IRemoteProxy(object) - { + InputClientProxy::InputClientProxy(const sptr &object) : IRemoteProxy(object) { } - int32_t InputClientProxy::onInputReady(int32_t retValue, const sptr& agent, const InputChannel* channel) - { + int32_t InputClientProxy::onInputReady(int32_t retValue, const sptr& agent, + const InputChannel* channel) { IMSA_HILOGI("InputClientProxy::onInputReady"); MessageParcel data, reply; MessageOption option; diff --git a/frameworks/inputmethod_controller/src/input_client_stub.cpp b/frameworks/inputmethod_controller/src/input_client_stub.cpp index 4d7de3dfb591966914f5c047d3d3ed2944b5257b..19deaa184d5bc847801030f60dff05a1e4bebe6d 100644 --- a/frameworks/inputmethod_controller/src/input_client_stub.cpp +++ b/frameworks/inputmethod_controller/src/input_client_stub.cpp @@ -18,88 +18,86 @@ namespace OHOS { namespace MiscServices { + InputClientStub::InputClientStub() + { -InputClientStub::InputClientStub() -{ + } -} + InputClientStub::~InputClientStub() + { -InputClientStub::~InputClientStub() -{ + } -} + int32_t InputClientStub::OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, + MessageOption &option) + { + IMSA_HILOGI("InputClientStub::OnRemoteRequest. code = %{public}u", code); + auto descriptorToken = data.ReadInterfaceToken(); + if (descriptorToken != GetDescriptor()) { + return ErrorCode::ERROR_STATUS_UNKNOWN_TRANSACTION; + } + switch (code) { + case ON_INPUT_READY: { + if (msgHandler == nullptr) { + break; + } + MessageParcel* parcel = new MessageParcel(); + parcel->WriteInt32(data.ReadInt32()); + if (data.ReadInt32() > 0) { + parcel->WriteRemoteObject(data.ReadRemoteObject()); + } + if (data.ReadInt32() > 0) { + parcel->WriteParcelable(data.ReadParcelable()); + } -int32_t InputClientStub::OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, - MessageOption &option) -{ - IMSA_HILOGI("InputClientStub::OnRemoteRequest. code = %{public}u", code); - auto descriptorToken = data.ReadInterfaceToken(); - if (descriptorToken != GetDescriptor()) { - return ErrorCode::ERROR_STATUS_UNKNOWN_TRANSACTION; - } - switch (code) { - case ON_INPUT_READY: { - if (msgHandler == nullptr) { + Message* msg = new Message(MessageID::MSG_ID_ON_INPUT_READY, parcel); + msgHandler->SendMessage(msg); break; } - MessageParcel* parcel = new MessageParcel(); - parcel->WriteInt32(data.ReadInt32()); - if (data.ReadInt32() > 0) { - parcel->WriteRemoteObject(data.ReadRemoteObject()); - } - if (data.ReadInt32() > 0) { - parcel->WriteParcelable(data.ReadParcelable()); - } - - Message* msg = new Message(MessageID::MSG_ID_ON_INPUT_READY, parcel); - msgHandler->SendMessage(msg); - break; - } - case ON_INPUT_RELEASED: { - if (msgHandler == nullptr) { + case ON_INPUT_RELEASED: { + if (msgHandler == nullptr) { + break; + } + MessageParcel* parcel = new MessageParcel(); + parcel->WriteInt32(data.ReadInt32()); + Message* msg = new Message(MessageID::MSG_ID_EXIT_SERVICE, parcel); + msgHandler->SendMessage(msg); break; } - MessageParcel* parcel = new MessageParcel(); - parcel->WriteInt32(data.ReadInt32()); - Message* msg = new Message(MessageID::MSG_ID_EXIT_SERVICE, parcel); - msgHandler->SendMessage(msg); - break; - } - case SET_DISPLAY_MODE: { - if (msgHandler == nullptr) { + case SET_DISPLAY_MODE: { + if (msgHandler == nullptr) { + break; + } + MessageParcel* parcel = new MessageParcel(); + parcel->WriteInt32(data.ReadInt32()); + Message* msg = new Message(MessageID::MSG_ID_SET_DISPLAY_MODE, parcel); + msgHandler->SendMessage(msg); break; } - MessageParcel* parcel = new MessageParcel(); - parcel->WriteInt32(data.ReadInt32()); - Message* msg = new Message(MessageID::MSG_ID_SET_DISPLAY_MODE, parcel); - msgHandler->SendMessage(msg); - break; + default: + return IPCObjectStub::OnRemoteRequest(code, data, reply, option); } - default: - return IPCObjectStub::OnRemoteRequest(code, data, reply, option); + return NO_ERROR; } - return NO_ERROR; -} - -int32_t InputClientStub::onInputReady(int32_t retValue, const sptr& agent, const InputChannel* channel) -{ - return ErrorCode::NO_ERROR; -} -int32_t InputClientStub::onInputReleased(int32_t retValue) -{ - return ErrorCode::NO_ERROR; -} + int32_t InputClientStub::onInputReady(int32_t retValue, const sptr& agent, + const InputChannel* channel) { + return ErrorCode::NO_ERROR; + } -int32_t InputClientStub::setDisplayMode(int32_t mode) -{ - return ErrorCode::NO_ERROR; -} + int32_t InputClientStub::onInputReleased(int32_t retValue) + { + return ErrorCode::NO_ERROR; + } -void InputClientStub::SetHandler(MessageHandler* handler) -{ - msgHandler = handler; -} + int32_t InputClientStub::setDisplayMode(int32_t mode) + { + return ErrorCode::NO_ERROR; + } + void InputClientStub::SetHandler(MessageHandler* handler) + { + msgHandler = handler; + } } } \ No newline at end of file diff --git a/frameworks/inputmethod_controller/src/input_data_channel_proxy.cpp b/frameworks/inputmethod_controller/src/input_data_channel_proxy.cpp index 71ceb3e28a2bce653cacfd4763b4c4ce4fa9d3c4..f3dda7bea331470dea631233787b95a267e8d59c 100644 --- a/frameworks/inputmethod_controller/src/input_data_channel_proxy.cpp +++ b/frameworks/inputmethod_controller/src/input_data_channel_proxy.cpp @@ -19,55 +19,53 @@ namespace OHOS { namespace MiscServices { + InputDataChannelProxy::InputDataChannelProxy(const sptr &object) + : IRemoteProxy(object) { + } -InputDataChannelProxy::InputDataChannelProxy(const sptr &object) : IRemoteProxy(object) -{ - -} - -bool InputDataChannelProxy::InsertText(const std::u16string& text) -{ - IMSA_HILOGI("InputDataChannelProxy::InsertText"); - MessageParcel data, reply; - MessageOption option; - data.WriteInterfaceToken(GetDescriptor()); - data.WriteString16(text); + bool InputDataChannelProxy::InsertText(const std::u16string& text) + { + IMSA_HILOGI("InputDataChannelProxy::InsertText"); + MessageParcel data, reply; + MessageOption option; + data.WriteInterfaceToken(GetDescriptor()); + data.WriteString16(text); - auto ret = Remote()->SendRequest(INSERT_TEXT, data, reply, option); - if (ret != NO_ERROR) { - return false; + auto ret = Remote()->SendRequest(INSERT_TEXT, data, reply, option); + if (ret != NO_ERROR) { + return false; + } + auto result = reply.ReadBool(); + return result; } - auto result = reply.ReadBool(); - return result; -} -bool InputDataChannelProxy::DeleteBackward(int32_t length) -{ - IMSA_HILOGI("InputDataChannelProxy::DeleteBackward"); - MessageParcel data, reply; - MessageOption option; - data.WriteInterfaceToken(GetDescriptor()); - data.WriteInt32(length); + bool InputDataChannelProxy::DeleteBackward(int32_t length) + { + IMSA_HILOGI("InputDataChannelProxy::DeleteBackward"); + MessageParcel data, reply; + MessageOption option; + data.WriteInterfaceToken(GetDescriptor()); + data.WriteInt32(length); - auto ret = Remote()->SendRequest(DELETE_BACKWARD, data, reply, option); - if (ret != NO_ERROR) { - return false; + auto ret = Remote()->SendRequest(DELETE_BACKWARD, data, reply, option); + if (ret != NO_ERROR) { + return false; + } + auto result = reply.ReadBool(); + return result; } - auto result = reply.ReadBool(); - return result; -} -void InputDataChannelProxy::Close() -{ - IMSA_HILOGI("InputDataChannelProxy::Close"); - MessageParcel data, reply; - MessageOption option; - data.WriteInterfaceToken(GetDescriptor()); + void InputDataChannelProxy::Close() + { + IMSA_HILOGI("InputDataChannelProxy::Close"); + MessageParcel data, reply; + MessageOption option; + data.WriteInterfaceToken(GetDescriptor()); - auto ret = Remote()->SendRequest(CLOSE, data, reply, option); - if (ret != NO_ERROR) { - + auto ret = Remote()->SendRequest(CLOSE, data, reply, option); + if (ret != NO_ERROR) { + + } } } -} } \ No newline at end of file diff --git a/frameworks/inputmethod_controller/src/input_data_channel_stub.cpp b/frameworks/inputmethod_controller/src/input_data_channel_stub.cpp index 517c7fced99363c4f82e6e84d4d7d1248da4ae76..9f482a0e3ff49d3ff79293f837027710087abfbc 100644 --- a/frameworks/inputmethod_controller/src/input_data_channel_stub.cpp +++ b/frameworks/inputmethod_controller/src/input_data_channel_stub.cpp @@ -17,82 +17,82 @@ namespace OHOS { namespace MiscServices { -InputDataChannelStub::InputDataChannelStub() : msgHandler(nullptr) -{ + InputDataChannelStub::InputDataChannelStub() : msgHandler(nullptr) + { -} - -InputDataChannelStub::~InputDataChannelStub() -{ - if (msgHandler != nullptr) { - delete msgHandler; } -} -int32_t InputDataChannelStub::OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, - MessageOption &option) -{ - IMSA_HILOGI("InputDataChannelStub::OnRemoteRequest code = %{public}d", code); - auto descriptorToken = data.ReadInterfaceToken(); - if (descriptorToken != GetDescriptor()) { - return ErrorCode::ERROR_STATUS_UNKNOWN_TRANSACTION; - } - switch (code) { - case INSERT_TEXT: { - auto text = data.ReadString16(); - InsertText(text); - break; + InputDataChannelStub::~InputDataChannelStub() + { + if (msgHandler != nullptr) { + delete msgHandler; } - case DELETE_BACKWARD: { - auto length = data.ReadInt32(); - DeleteBackward(length); - break; + } + + int32_t InputDataChannelStub::OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, + MessageOption &option) + { + IMSA_HILOGI("InputDataChannelStub::OnRemoteRequest code = %{public}d", code); + auto descriptorToken = data.ReadInterfaceToken(); + if (descriptorToken != GetDescriptor()) { + return ErrorCode::ERROR_STATUS_UNKNOWN_TRANSACTION; } - case CLOSE: { - Close(); - break; + switch (code) { + case INSERT_TEXT: { + auto text = data.ReadString16(); + InsertText(text); + break; + } + case DELETE_BACKWARD: { + auto length = data.ReadInt32(); + DeleteBackward(length); + break; + } + case CLOSE: { + Close(); + break; + } + default: + return IPCObjectStub::OnRemoteRequest(code, data, reply, option); } - default: - return IPCObjectStub::OnRemoteRequest(code, data, reply, option); + return NO_ERROR; } - return NO_ERROR; -} -bool InputDataChannelStub::InsertText(const std::u16string& text) -{ - IMSA_HILOGI("InputDataChannelStub::InsertText"); - if (msgHandler != nullptr) { - MessageParcel* parcel = new MessageParcel; - parcel->WriteString16(text); - Message* msg = new Message(MessageID::MSG_ID_INSERT_CHAR, parcel); - msgHandler->SendMessage(msg); - IMSA_HILOGI("InputDataChannelStub::InsertText return true"); - return true; + bool InputDataChannelStub::InsertText(const std::u16string& text) + { + IMSA_HILOGI("InputDataChannelStub::InsertText"); + if (msgHandler != nullptr) { + MessageParcel* parcel = new MessageParcel; + parcel->WriteString16(text); + Message* msg = new Message(MessageID::MSG_ID_INSERT_CHAR, parcel); + msgHandler->SendMessage(msg); + IMSA_HILOGI("InputDataChannelStub::InsertText return true"); + return true; + } + return false; } - return false; -} -bool InputDataChannelStub::DeleteBackward(int32_t length) -{ - IMSA_HILOGI("InputDataChannelStub::DeleteBackward"); - if (msgHandler != nullptr) { - MessageParcel* parcel = new MessageParcel; - parcel->WriteInt32(length); - Message* msg = new Message(MessageID::MSG_ID_DELETE_BACKWARD, parcel); - msgHandler->SendMessage(msg); - return true; + bool InputDataChannelStub::DeleteBackward(int32_t length) + { + IMSA_HILOGI("InputDataChannelStub::DeleteBackward"); + if (msgHandler != nullptr) { + MessageParcel* parcel = new MessageParcel; + parcel->WriteInt32(length); + Message* msg = new Message(MessageID::MSG_ID_DELETE_BACKWARD, parcel); + msgHandler->SendMessage(msg); + return true; + } + return false; } - return false; -} -void InputDataChannelStub::Close() -{ + void InputDataChannelStub::Close() + { -} + } -void InputDataChannelStub::SetHandler(MessageHandler* handler) -{ - msgHandler = handler; -} + void InputDataChannelStub::SetHandler(MessageHandler* handler) + { + msgHandler = handler; + } } } \ No newline at end of file diff --git a/frameworks/inputmethod_controller/src/input_method_controller.cpp b/frameworks/inputmethod_controller/src/input_method_controller.cpp index 153bcd6e0f0ba92d1c7fac80a71fdf37a36f6334..11f01ad639586972fe6d3e56eea1b88964eecf1a 100644 --- a/frameworks/inputmethod_controller/src/input_method_controller.cpp +++ b/frameworks/inputmethod_controller/src/input_method_controller.cpp @@ -139,6 +139,7 @@ using namespace MessageID; case MSG_ID_EXIT_SERVICE:{ MessageParcel* data = msg->msgContent_; int32_t ret = data->ReadInt32(); + textListener = nullptr; IMSA_HILOGI("MSG_ID_EXIT_SERVICE : %{public}d", ret); break; } @@ -173,7 +174,8 @@ using namespace MessageID; ReleaseInput(mClient); } - void InputMethodController::PrepareInput(int32_t displayId,sptr &client,sptr &channel,InputAttribute &attribute) + void InputMethodController::PrepareInput(int32_t displayId, sptr &client, + sptr &channel, InputAttribute &attribute) { IMSA_HILOGI("InputMethodController::PrepareInput"); if(mImms == nullptr){ 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 5c631daf7c3f031b3fadb9e3cc6cae3ac1e70590..046f1fc38fce2ee60396c32d45e374ca18a3124c 100644 --- a/frameworks/inputmethod_controller/src/input_method_system_ability_proxy.cpp +++ b/frameworks/inputmethod_controller/src/input_method_system_ability_proxy.cpp @@ -17,394 +17,395 @@ namespace OHOS { namespace MiscServices { -using namespace ErrorCode; + using namespace ErrorCode; + InputMethodSystemAbilityProxy::InputMethodSystemAbilityProxy(const sptr &object) + : IRemoteProxy(object) + { -InputMethodSystemAbilityProxy::InputMethodSystemAbilityProxy(const sptr &object) - : IRemoteProxy(object) -{ + } -} + void InputMethodSystemAbilityProxy::prepareInput(MessageParcel& data) + { + MessageParcel reply; + MessageOption option; -void InputMethodSystemAbilityProxy::prepareInput(MessageParcel& data) -{ - MessageParcel reply; - MessageOption option; + auto ret = Remote()->SendRequest(PREPARE_INPUT, data, reply, option); + if (ret != NO_ERROR) { + IMSA_HILOGI("InputMethodSystemAbilityProxy::prepareInput SendRequest failed"); + return; + } - auto ret = Remote()->SendRequest(PREPARE_INPUT, data, reply, option); - if (ret != NO_ERROR) { - IMSA_HILOGI("InputMethodSystemAbilityProxy::prepareInput SendRequest failed"); - return; + ret = reply.ReadInt32(); + if (ret != NO_ERROR) { + IMSA_HILOGI("InputMethodSystemAbilityProxy::prepareInput reply failed"); + return; + } } - ret = reply.ReadInt32(); - if (ret != NO_ERROR) { - IMSA_HILOGI("InputMethodSystemAbilityProxy::prepareInput reply failed"); - return; - } -} + void InputMethodSystemAbilityProxy::releaseInput(MessageParcel& data) + { + MessageParcel reply; + MessageOption option; -void InputMethodSystemAbilityProxy::releaseInput(MessageParcel& data) -{ - MessageParcel reply; - MessageOption option; + auto ret = Remote()->SendRequest(RELEASE_INPUT, data, reply, option); + if (ret != NO_ERROR) { + IMSA_HILOGI("InputMethodSystemAbilityProxy::releaseInput SendRequest failed"); + return; + } - auto ret = Remote()->SendRequest(RELEASE_INPUT, data, reply, option); - if (ret != NO_ERROR) { - IMSA_HILOGI("InputMethodSystemAbilityProxy::releaseInput SendRequest failed"); - return; + ret = reply.ReadInt32(); + if (ret != NO_ERROR) { + IMSA_HILOGI("InputMethodSystemAbilityProxy::releaseInput reply failed"); + return; + } } - ret = reply.ReadInt32(); - if (ret != NO_ERROR) { - IMSA_HILOGI("InputMethodSystemAbilityProxy::releaseInput reply failed"); - return; - } -} + void InputMethodSystemAbilityProxy::startInput(MessageParcel& data) + { + IMSA_HILOGI("InputMethodSystemAbilityProxy::startInput"); + MessageParcel reply; + MessageOption option; -void InputMethodSystemAbilityProxy::startInput(MessageParcel& data) -{ - IMSA_HILOGI("InputMethodSystemAbilityProxy::startInput"); - MessageParcel reply; - MessageOption option; + auto ret = Remote()->SendRequest(START_INPUT,data,reply,option); + if (ret != NO_ERROR) { + IMSA_HILOGI("InputMethodSystemAbilityProxy::startInput SendRequest failed"); + return; + } - auto ret = Remote()->SendRequest(START_INPUT,data,reply,option); - if (ret != NO_ERROR) { - IMSA_HILOGI("InputMethodSystemAbilityProxy::startInput SendRequest failed"); - return; + ret = reply.ReadInt32(); + if (ret != NO_ERROR) { + IMSA_HILOGI("InputMethodSystemAbilityProxy::startInput reply failed"); + return; + } } - ret = reply.ReadInt32(); - if (ret != NO_ERROR) { - IMSA_HILOGI("InputMethodSystemAbilityProxy::startInput reply failed"); - return; - } -} + void InputMethodSystemAbilityProxy::stopInput(MessageParcel& data) + { + IMSA_HILOGI("InputMethodSystemAbilityProxy::stopInput"); + MessageParcel reply; + MessageOption option; -void InputMethodSystemAbilityProxy::stopInput(MessageParcel& data) -{ - IMSA_HILOGI("InputMethodSystemAbilityProxy::stopInput"); - MessageParcel reply; - MessageOption option; + auto ret = Remote()->SendRequest(STOP_INPUT,data,reply,option); + if (ret != NO_ERROR) { + IMSA_HILOGI("InputMethodSystemAbilityProxy::stopInput SendRequest failed"); + return; + } - auto ret = Remote()->SendRequest(STOP_INPUT,data,reply,option); - if (ret != NO_ERROR) { - IMSA_HILOGI("InputMethodSystemAbilityProxy::stopInput SendRequest failed"); - return; + ret = reply.ReadInt32(); + if (ret != NO_ERROR) { + IMSA_HILOGI("InputMethodSystemAbilityProxy::stopInput reply failed"); + return; + } } - ret = reply.ReadInt32(); - if (ret != NO_ERROR) { - IMSA_HILOGI("InputMethodSystemAbilityProxy::stopInput reply failed"); - return; - } -} + int32_t InputMethodSystemAbilityProxy::setInputMethodCore(sptr &core) + { + IMSA_HILOGI("InputMethodSystemAbilityProxy::setInputMethodCore"); + + if (core == nullptr) { + IMSA_HILOGI("InputMethodSystemAbilityProxy::setInputMethodCore inputDataChannel is nullptr"); + } + auto remote = Remote(); + if (remote == nullptr) + return -1; + MessageParcel data; + if (!(data.WriteInterfaceToken(GetDescriptor()) + && data.WriteRemoteObject(core->AsObject()))) + return -1; + MessageParcel reply; + MessageOption option { MessageOption::TF_SYNC }; + + int32_t status = Remote()->SendRequest(SET_INPUT_METHOD_CORE, data, reply, option); + + return status; + } - int32_t InputMethodSystemAbilityProxy::setInputMethodCore(sptr &core) + int32_t InputMethodSystemAbilityProxy::Prepare(int32_t displayId, sptr &client, + sptr &channel, InputAttribute &attribute) { - IMSA_HILOGI("InputMethodSystemAbilityProxy::setInputMethodCore"); - - if (core == nullptr) { - IMSA_HILOGI("InputMethodSystemAbilityProxy::setInputMethodCore inputDataChannel is nullptr"); - } - auto remote = Remote(); - if (remote == nullptr) - return -1; - MessageParcel data; - if (!(data.WriteInterfaceToken(GetDescriptor()) - && data.WriteRemoteObject(core->AsObject()))) - return -1; - MessageParcel reply; - MessageOption option { MessageOption::TF_SYNC }; + MessageParcel data, reply; + MessageOption option; + if (!data.WriteInterfaceToken(GetDescriptor())) { + return ERROR_EX_PARCELABLE; + } - int32_t status = Remote()->SendRequest(SET_INPUT_METHOD_CORE, data, reply, option); + if (!(data.WriteInt32(displayId) + && data.WriteRemoteObject(client->AsObject()) + && data.WriteRemoteObject(channel->AsObject()) + && data.WriteParcelable(&attribute))) { + return ERROR_EX_PARCELABLE; + } - return status; - } + auto ret = Remote()->SendRequest(PREPARE_INPUT, data, reply, option); + if (ret != NO_ERROR) { + return ERROR_STATUS_FAILED_TRANSACTION; + } -int32_t InputMethodSystemAbilityProxy::Prepare(int32_t displayId, sptr &client, sptr &channel, InputAttribute &attribute) -{ - MessageParcel data, reply; - MessageOption option; - if (!data.WriteInterfaceToken(GetDescriptor())) { - return ERROR_EX_PARCELABLE; + ret = reply.ReadInt32(); + if (ret != NO_ERROR) { + return ret; + } + + return NO_ERROR; } - if (!(data.WriteInt32(displayId) - && data.WriteRemoteObject(client->AsObject()) - && data.WriteRemoteObject(channel->AsObject()) - && data.WriteParcelable(&attribute))) { - return ERROR_EX_PARCELABLE; - } + int32_t InputMethodSystemAbilityProxy::Release(sptr &client) + { + IMSA_HILOGI("InputMethodSystemAbilityProxy::Release"); + MessageParcel data, reply; + MessageOption option; + if (!data.WriteInterfaceToken(GetDescriptor())) { + return ERROR_EX_PARCELABLE; + } - auto ret = Remote()->SendRequest(PREPARE_INPUT, data, reply, option); - if (ret != NO_ERROR) { - return ERROR_STATUS_FAILED_TRANSACTION; - } + if (!data.WriteRemoteObject(client->AsObject().GetRefPtr())) { + return ERROR_EX_PARCELABLE; + } - ret = reply.ReadInt32(); - if (ret != NO_ERROR) { - return ret; - } + auto ret = Remote()->SendRequest(RELEASE_INPUT, data, reply, option); + if (ret != NO_ERROR) { + return ERROR_STATUS_FAILED_TRANSACTION; + } - return NO_ERROR; -} + ret = reply.ReadInt32(); + if (ret != NO_ERROR) { + return ret; + } -int32_t InputMethodSystemAbilityProxy::Release(sptr &client) -{ - IMSA_HILOGI("InputMethodSystemAbilityProxy::Release"); - MessageParcel data, reply; - MessageOption option; - if (!data.WriteInterfaceToken(GetDescriptor())) { - return ERROR_EX_PARCELABLE; + return NO_ERROR; } - if (!data.WriteRemoteObject(client->AsObject().GetRefPtr())) { - return ERROR_EX_PARCELABLE; - } + int32_t InputMethodSystemAbilityProxy::Start(sptr &client) + { + MessageParcel data, reply; + MessageOption option; + if (!data.WriteInterfaceToken(GetDescriptor())) { + return ERROR_EX_PARCELABLE; + } - auto ret = Remote()->SendRequest(RELEASE_INPUT, data, reply, option); - if (ret != NO_ERROR) { - return ERROR_STATUS_FAILED_TRANSACTION; - } + if (!data.WriteRemoteObject(client->AsObject().GetRefPtr())) { + return ERROR_EX_PARCELABLE; + } - ret = reply.ReadInt32(); - if (ret != NO_ERROR) { - return ret; - } + auto ret = Remote()->SendRequest(START_INPUT, data, reply, option); + if (ret != NO_ERROR) { + return ERROR_STATUS_FAILED_TRANSACTION; + } - return NO_ERROR; -} + ret = reply.ReadInt32(); + if (ret != NO_ERROR) { + return ret; + } -int32_t InputMethodSystemAbilityProxy::Start(sptr &client) -{ - MessageParcel data, reply; - MessageOption option; - if (!data.WriteInterfaceToken(GetDescriptor())) { - return ERROR_EX_PARCELABLE; + return NO_ERROR; } - if (!data.WriteRemoteObject(client->AsObject().GetRefPtr())) { - return ERROR_EX_PARCELABLE; - } - - auto ret = Remote()->SendRequest(START_INPUT, data, reply, option); - if (ret != NO_ERROR) { - return ERROR_STATUS_FAILED_TRANSACTION; - } + int32_t InputMethodSystemAbilityProxy::Stop(sptr &client) + { + MessageParcel data, reply; + MessageOption option; + if (!data.WriteInterfaceToken(GetDescriptor())) { + return ERROR_EX_PARCELABLE; + } - ret = reply.ReadInt32(); - if (ret != NO_ERROR) { - return ret; - } + if (!data.WriteRemoteObject(client->AsObject().GetRefPtr())) { + return ERROR_EX_PARCELABLE; + } - return NO_ERROR; -} + auto ret = Remote()->SendRequest(STOP_INPUT, data, reply, option); + if (ret != NO_ERROR) { + return ERROR_STATUS_FAILED_TRANSACTION; + } -int32_t InputMethodSystemAbilityProxy::Stop(sptr &client) -{ - MessageParcel data, reply; - MessageOption option; - if (!data.WriteInterfaceToken(GetDescriptor())) { - return ERROR_EX_PARCELABLE; - } + ret = reply.ReadInt32(); + if (ret != NO_ERROR) { + return ret; + } - if (!data.WriteRemoteObject(client->AsObject().GetRefPtr())) { - return ERROR_EX_PARCELABLE; - } - - auto ret = Remote()->SendRequest(STOP_INPUT, data, reply, option); - if (ret != NO_ERROR) { - return ERROR_STATUS_FAILED_TRANSACTION; + return NO_ERROR; } - ret = reply.ReadInt32(); - if (ret != NO_ERROR) { - return ret; - } + int32_t InputMethodSystemAbilityProxy::getDisplayMode(int32_t *retMode) + { + MessageParcel data, reply; + MessageOption option; - return NO_ERROR; -} + if (!data.WriteInterfaceToken(GetDescriptor())) { + return ERROR_EX_PARCELABLE; + } -int32_t InputMethodSystemAbilityProxy::getDisplayMode(int32_t *retMode) -{ - MessageParcel data, reply; - MessageOption option; + auto ret = Remote()->SendRequest(GET_DISPLAY_MODE, data, reply, option); + if (ret != NO_ERROR) { + return ERROR_STATUS_FAILED_TRANSACTION; + } - if (!data.WriteInterfaceToken(GetDescriptor())) { - return ERROR_EX_PARCELABLE; - } - - auto ret = Remote()->SendRequest(GET_DISPLAY_MODE, data, reply, option); - if (ret != NO_ERROR) { - return ERROR_STATUS_FAILED_TRANSACTION; - } - - ret = reply.ReadInt32(); - if (ret != NO_ERROR) { - return ret; - } + ret = reply.ReadInt32(); + if (ret != NO_ERROR) { + return ret; + } - if (!reply.ReadInt32(*retMode)) { - return ERROR_STATUS_BAD_VALUE; + if (!reply.ReadInt32(*retMode)) { + return ERROR_STATUS_BAD_VALUE; + } + return NO_ERROR; } - return NO_ERROR; -} -int32_t InputMethodSystemAbilityProxy::getKeyboardWindowHeight(int32_t *retHeight) -{ - if (retHeight == nullptr) { - return ERROR_NULL_POINTER; - } + int32_t InputMethodSystemAbilityProxy::getKeyboardWindowHeight(int32_t *retHeight) + { + if (retHeight == nullptr) { + return ERROR_NULL_POINTER; + } - MessageParcel data, reply; - MessageOption option; + MessageParcel data, reply; + MessageOption option; - if (!data.WriteInterfaceToken(GetDescriptor())) { - return ERROR_EX_PARCELABLE; - } - - auto ret = Remote()->SendRequest(GET_KEYBOARD_WINDOW_HEIGHT, data, reply, option); - if (ret != NO_ERROR) { - return ERROR_STATUS_FAILED_TRANSACTION; - } - - ret = reply.ReadInt32(); - if (ret != NO_ERROR) { - return ret; - } + if (!data.WriteInterfaceToken(GetDescriptor())) { + return ERROR_EX_PARCELABLE; + } - if (!reply.ReadInt32(*retHeight)) { - return ERROR_STATUS_BAD_VALUE; - } - return NO_ERROR; -} + auto ret = Remote()->SendRequest(GET_KEYBOARD_WINDOW_HEIGHT, data, reply, option); + if (ret != NO_ERROR) { + return ERROR_STATUS_FAILED_TRANSACTION; + } + + ret = reply.ReadInt32(); + if (ret != NO_ERROR) { + return ret; + } -int32_t InputMethodSystemAbilityProxy::getCurrentKeyboardType(KeyboardType* retType) -{ - if (retType == nullptr) { - return ERROR_NULL_POINTER; + if (!reply.ReadInt32(*retHeight)) { + return ERROR_STATUS_BAD_VALUE; + } + return NO_ERROR; } - MessageParcel data, reply; - MessageOption option; + int32_t InputMethodSystemAbilityProxy::getCurrentKeyboardType(KeyboardType* retType) + { + if (retType == nullptr) { + return ERROR_NULL_POINTER; + } - if (!data.WriteInterfaceToken(GetDescriptor())) { - return ERROR_EX_PARCELABLE; - } - - auto ret = Remote()->SendRequest(GET_CURRENT_KEYBOARD_TYPE, data, reply, option); - if (ret != NO_ERROR) { - return ERROR_STATUS_FAILED_TRANSACTION; - } - - ret = reply.ReadInt32(); - if (ret != NO_ERROR) { - return ret; - } + MessageParcel data, reply; + MessageOption option; - KeyboardType* keyType = reply.ReadParcelable(); - *retType = *keyType; - delete keyType; - return NO_ERROR; -} + if (!data.WriteInterfaceToken(GetDescriptor())) { + return ERROR_EX_PARCELABLE; + } -int32_t InputMethodSystemAbilityProxy::listInputMethodEnabled(std::vector *properties) -{ - if (properties == nullptr) { - return ERROR_NULL_POINTER; - } + auto ret = Remote()->SendRequest(GET_CURRENT_KEYBOARD_TYPE, data, reply, option); + if (ret != NO_ERROR) { + return ERROR_STATUS_FAILED_TRANSACTION; + } - MessageParcel data, reply; - MessageOption option; + ret = reply.ReadInt32(); + if (ret != NO_ERROR) { + return ret; + } - if (!data.WriteInterfaceToken(GetDescriptor())) { - return ERROR_EX_PARCELABLE; + KeyboardType* keyType = reply.ReadParcelable(); + *retType = *keyType; + delete keyType; + return NO_ERROR; } - auto ret = Remote()->SendRequest(LIST_INPUT_METHOD_ENABLED, data, reply, option); - if (ret != NO_ERROR) { - return ERROR_STATUS_FAILED_TRANSACTION; - } + int32_t InputMethodSystemAbilityProxy::listInputMethodEnabled(std::vector *properties) + { + if (properties == nullptr) { + return ERROR_NULL_POINTER; + } - ret = reply.ReadInt32(); - if (ret != NO_ERROR) { - return ret; - } + MessageParcel data, reply; + MessageOption option; - auto size = reply.ReadInt32(); - while (size > 0) { - InputMethodProperty* imp = reply.ReadParcelable(); - properties->push_back(imp); - size--; - } - - return NO_ERROR; -} + if (!data.WriteInterfaceToken(GetDescriptor())) { + return ERROR_EX_PARCELABLE; + } -int32_t InputMethodSystemAbilityProxy::listInputMethod(std::vector *properties) -{ - if (properties == nullptr) { - return ERROR_NULL_POINTER; - } + auto ret = Remote()->SendRequest(LIST_INPUT_METHOD_ENABLED, data, reply, option); + if (ret != NO_ERROR) { + return ERROR_STATUS_FAILED_TRANSACTION; + } - MessageParcel data, reply; - MessageOption option; + ret = reply.ReadInt32(); + if (ret != NO_ERROR) { + return ret; + } - if (!data.WriteInterfaceToken(GetDescriptor())) { - return ERROR_EX_PARCELABLE; - } + auto size = reply.ReadInt32(); + while (size > 0) { + InputMethodProperty* imp = reply.ReadParcelable(); + properties->push_back(imp); + size--; + } - auto ret = Remote()->SendRequest(LIST_INPUT_METHOD, data, reply, option); - if (ret != NO_ERROR) { - return ERROR_STATUS_FAILED_TRANSACTION; + return NO_ERROR; } - ret = reply.ReadInt32(); - if (ret != NO_ERROR) { - return ret; - } + int32_t InputMethodSystemAbilityProxy::listInputMethod(std::vector *properties) + { + if (properties == nullptr) { + return ERROR_NULL_POINTER; + } - auto size = reply.ReadInt32(); + MessageParcel data, reply; + MessageOption option; - while (size > 0) { - InputMethodProperty* imp = reply.ReadParcelable(); - properties->push_back(imp); - size--; - } - - return NO_ERROR; -} + if (!data.WriteInterfaceToken(GetDescriptor())) { + return ERROR_EX_PARCELABLE; + } -int32_t InputMethodSystemAbilityProxy::listKeyboardType(const std::u16string& imeId, std::vector *types) -{ - if (types == nullptr) { - return ERROR_NULL_POINTER; - } + auto ret = Remote()->SendRequest(LIST_INPUT_METHOD, data, reply, option); + if (ret != NO_ERROR) { + return ERROR_STATUS_FAILED_TRANSACTION; + } - MessageParcel data, reply; - MessageOption option; + ret = reply.ReadInt32(); + if (ret != NO_ERROR) { + return ret; + } - if (!(data.WriteInterfaceToken(GetDescriptor()) && data.WriteString16(imeId))) { - return ERROR_EX_PARCELABLE; - } + auto size = reply.ReadInt32(); - auto ret = Remote()->SendRequest(LIST_KEYBOARD_TYPE, data, reply, option); - if (ret != NO_ERROR) { - return ERROR_STATUS_FAILED_TRANSACTION; - } + while (size > 0) { + InputMethodProperty* imp = reply.ReadParcelable(); + properties->push_back(imp); + size--; + } - ret = reply.ReadInt32(); - if (ret != NO_ERROR) { - return ret; + return NO_ERROR; } - auto size = reply.ReadInt32(); - while (size > 0) { - KeyboardType* kt = reply.ReadParcelable(); - types->push_back(kt); - size--; + int32_t InputMethodSystemAbilityProxy::listKeyboardType(const std::u16string& imeId, + std::vector *types) + { + if (types == nullptr) { + return ERROR_NULL_POINTER; + } + + MessageParcel data, reply; + MessageOption option; + + if (!(data.WriteInterfaceToken(GetDescriptor()) && data.WriteString16(imeId))) { + return ERROR_EX_PARCELABLE; + } + + auto ret = Remote()->SendRequest(LIST_KEYBOARD_TYPE, data, reply, option); + if (ret != NO_ERROR) { + return ERROR_STATUS_FAILED_TRANSACTION; + } + + ret = reply.ReadInt32(); + if (ret != NO_ERROR) { + return ret; + } + + auto size = reply.ReadInt32(); + while (size > 0) { + KeyboardType* kt = reply.ReadParcelable(); + types->push_back(kt); + size--; + } + return NO_ERROR; } - return NO_ERROR; -} } } \ No newline at end of file diff --git a/interfaces/kits/js/napi/js_input_method_ability.cpp b/interfaces/kits/js/napi/js_input_method_ability.cpp index 05b325dc1018301ae25e8a1fc9118646bf848c2d..ac52fe42327151e6b0cc7222443c7ca32bbe06f4 100644 --- a/interfaces/kits/js/napi/js_input_method_ability.cpp +++ b/interfaces/kits/js/napi/js_input_method_ability.cpp @@ -191,7 +191,7 @@ napi_value InputMethodAbilityInit(napi_env env, napi_value exports) DECLARE_NAPI_FUNCTION("off", JS_Off), }; napi_define_class(env, className, sizeof(className),JS_Constructor, nullptr, - sizeof(desc) / sizeof(desc[0]), desc, &constructor); + sizeof(desc) / sizeof(desc[0]), desc, &constructor); napi_set_named_property(env, exports, "InputMethodAbility", constructor); return exports; } diff --git a/services/include/global.h b/services/include/global.h index 90db0c0cc37ae71bc3413eac5f001c21b1026534..155d52afd481df75a9db3fd403be32b428d1fc8a 100644 --- a/services/include/global.h +++ b/services/include/global.h @@ -34,17 +34,17 @@ using BRemoteObject = IPCObjectStub; #define INPUTMETHOD_DEBUG 0 #define LOG_INFO(fmt, args...) \ - LogTimeStamp();printf("I %s:%d %s - " fmt, basename(__FILE__), __LINE__, __FUNCTION__, ##args) + LogTimeStamp(); printf("I %s:%d %s - " fmt, basename(__FILE__), __LINE__, __FUNCTION__, ##args) #define LOG_ERROR(fmt, args...) \ - LogTimeStamp();printf("E %s:%d %s - " fmt, basename(__FILE__), __LINE__, __FUNCTION__, ##args) + LogTimeStamp(); printf("E %s:%d %s - " fmt, basename(__FILE__), __LINE__, __FUNCTION__, ##args) #define LOG_WARNING(fmt, args...) \ - LogTimeStamp();printf("W %s:%d %s - " fmt, basename(__FILE__), __LINE__, __FUNCTION__, ##args) + LogTimeStamp(); printf("W %s:%d %s - " fmt, basename(__FILE__), __LINE__, __FUNCTION__, ##args) #if DEBUG #define LOG_DEBUG(fmt, args...) \ - LogTimeStamp();printf("D %s:%d %s - " fmt, basename(__FILE__), __LINE__, __FUNCTION__, ##args) + LogTimeStamp(); printf("D %s:%d %s - " fmt, basename(__FILE__), __LINE__, __FUNCTION__, ##args) #else #define LOG_DEBUG(fmt, args...) #endif @@ -52,100 +52,99 @@ using BRemoteObject = IPCObjectStub; void LogTimeStamp(); namespace CommonEvent { - //! the events handled in input method management system + // the events handled in input method management system enum { - COMMON_EVENT_USER_STARTED = 10001, /*!< a user is started. */ - COMMON_EVENT_USER_STOPPED = 10002, /*!< a user is stopped. */ - COMMON_EVENT_USER_UNLOCKED = 10003, /*!< a user is unlocked. */ - COMMON_EVENT_USER_LOCKED = 10004, /*!< a user is locked. */ - COMMON_EVENT_SETTING_CHANGED = 10005, /*!< input method setting data is changed. */ - COMMON_EVENT_PACKAGE_ADDED = 10006, /*!< a package is installed. */ - COMMON_EVENT_PACKAGE_REMOVED = 10007, /*!< a package is removed */ + COMMON_EVENT_USER_STARTED = 10001, // a user is started. + COMMON_EVENT_USER_STOPPED = 10002, // a user is stopped. + COMMON_EVENT_USER_UNLOCKED = 10003, // a user is unlocked. + COMMON_EVENT_USER_LOCKED = 10004, // a user is locked. + COMMON_EVENT_SETTING_CHANGED = 10005, // input method setting data is changed. + COMMON_EVENT_PACKAGE_ADDED = 10006, // a package is installed. + COMMON_EVENT_PACKAGE_REMOVED = 10007, // a package is removed }; }; -//! User State +// User State namespace UserState { - /*! The states of a user in the system. */ + /*! The states of a user in the system. enum { USER_STATE_NOT_AVAILABLE = -1, - USER_STATE_STARTED = 0, /*!< a user is started. */ - USER_STATE_UNLOCKED, /*!< a user is unlocked. */ + USER_STATE_STARTED = 0, // a user is started. + USER_STATE_UNLOCKED, // a user is unlocked. }; }; -//! Error Code +// Error Code namespace ErrorCode { - /*! Error Code definition in the input method management system */ + /*! Error Code definition in the input method management system enum { - ERROR_STATUS_UNKNOWN_ERROR = (-2147483647 - 1), //!< unknown error - ERROR_STATUS_NO_MEMORY = -ENOMEM, //!< no memory - ERROR_STATUS_INVALID_OPERATION = -ENOSYS, //!< invalid operation - ERROR_STATUS_BAD_VALUE = -EINVAL, //!< bad value - ERROR_STATUS_BAD_TYPE = ERROR_STATUS_UNKNOWN_ERROR+1, //!< bad type - ERROR_STATUS_NAME_NOT_FOUND = -ENOENT, //!< name not found - ERROR_STATUS_PERMISSION_DENIED = -EPERM, //!< permission denied - ERROR_STATUS_NO_INIT = -ENODEV, //!< no init - ERROR_STATUS_ALREADY_EXISTS = -EEXIST, //!< already exist - ERROR_STATUS_DEAD_OBJECT = -EPIPE, //!< dead object - ERROR_STATUS_FAILED_TRANSACTION = ERROR_STATUS_UNKNOWN_ERROR+2, //!< failed transaction - ERROR_STATUS_BAD_INDEX = -EOVERFLOW, //!< bad index - ERROR_STATUS_NOT_ENOUGH_DATA = -ENODATA, //!< not enough data - ERROR_STATUS_WOULD_BLOCK = -EWOULDBLOCK, //!< would block - ERROR_STATUS_TIMED_OUT = -ETIMEDOUT, //!< time out - ERROR_STATUS_UNKNOWN_TRANSACTION = -EBADMSG, //!< unknown transaction - ERROR_STATUS_FDS_NOT_ALLOWED = ERROR_STATUS_UNKNOWN_ERROR+7, //!< fds not allowed - ERROR_STATUS_UNEXPECTED_NULL = ERROR_STATUS_UNKNOWN_ERROR+8, //!< unexpected null, + ERROR_STATUS_UNKNOWN_ERROR = (-2147483647 - 1), // unknown error + ERROR_STATUS_NO_MEMORY = -ENOMEM, // no memory + ERROR_STATUS_INVALID_OPERATION = -ENOSYS, // invalid operation + ERROR_STATUS_BAD_VALUE = -EINVAL, // bad value + ERROR_STATUS_BAD_TYPE = ERROR_STATUS_UNKNOWN_ERROR + 1, // bad type + ERROR_STATUS_NAME_NOT_FOUND = -ENOENT, // name not found + ERROR_STATUS_PERMISSION_DENIED = -EPERM, // permission denied + ERROR_STATUS_NO_INIT = -ENODEV, // no init + ERROR_STATUS_ALREADY_EXISTS = -EEXIST, // already exist + ERROR_STATUS_DEAD_OBJECT = -EPIPE, // dead object + ERROR_STATUS_FAILED_TRANSACTION = ERROR_STATUS_UNKNOWN_ERROR + 2, // failed transaction + ERROR_STATUS_BAD_INDEX = -EOVERFLOW, // bad index + ERROR_STATUS_NOT_ENOUGH_DATA = -ENODATA, // not enough data + ERROR_STATUS_WOULD_BLOCK = -EWOULDBLOCK, // would block + ERROR_STATUS_TIMED_OUT = -ETIMEDOUT, // time out + ERROR_STATUS_UNKNOWN_TRANSACTION = -EBADMSG, // unknown transaction + ERROR_STATUS_FDS_NOT_ALLOWED = ERROR_STATUS_UNKNOWN_ERROR + 7, // fds not allowed + ERROR_STATUS_UNEXPECTED_NULL = ERROR_STATUS_UNKNOWN_ERROR + 8, // unexpected null, // binder exception error code from Status.h - ERROR_EX_ILLEGAL_ARGUMENT = -3, //!< illegal argument exception - ERROR_EX_NULL_POINTER = -4, //!< null pointer exception - ERROR_EX_ILLEGAL_STATE = -5, //!< illegal state exception - ERROR_EX_NETWORK_MAIN_THREAD = -6, //!< network main thread exception - ERROR_EX_UNSUPPORTED_OPERATION = -7, //!< unsupported operation exception - ERROR_EX_SERVICE_SPECIFIC = -8, //!< service specific exception - ERROR_EX_PARCELABLE = -9, //!< parcelable exception + ERROR_EX_ILLEGAL_ARGUMENT = -3, // illegal argument exception + ERROR_EX_NULL_POINTER = -4, // null pointer exception + ERROR_EX_ILLEGAL_STATE = -5, // illegal state exception + ERROR_EX_NETWORK_MAIN_THREAD = -6, // network main thread exception + ERROR_EX_UNSUPPORTED_OPERATION = -7, // unsupported operation exception + ERROR_EX_SERVICE_SPECIFIC = -8, // service specific exception + ERROR_EX_PARCELABLE = -9, // parcelable exception // no error - NO_ERROR = 0, //!< no error + NO_ERROR = 0, // no error // system service error - ERROR_NULL_POINTER, //!< null pointer - ERROR_BAD_PARAMETERS, //!< bad parameters - ERROR_SERVICE_START_FAILED, //!< failed to start service - ERROR_USER_NOT_STARTED, //!< user is not started - ERROR_USER_ALREADY_STARTED, //!< user has already started - ERROR_USER_NOT_UNLOCKED, //!< user is not unlocked - ERROR_USER_ALREADY_UNLOCKED, //!< user has already unlocked - ERROR_USER_NOT_LOCKED, //!< user is not locked - - ERROR_IME_NOT_AVAILABLE, //!< input method engine is not available - ERROR_SECURITY_IME_NOT_AVAILABLE, //!< security input method engine is not available - ERROR_TOKEN_CREATE_FAILED, //!< failed to create window token - ERROR_TOKEN_DESTROY_FAILED, //!< failed to destroy window token - ERROR_IME_BIND_FAILED, //!< failed to bind IME service - ERROR_IME_UNBIND_FAILED, //!< failed to unbind IME service - ERROR_IME_START_FAILED, //!< failed to start IME service - ERROR_IME_STOP_FAILED, //!< failed to stop IME service - ERROR_KBD_SHOW_FAILED, //!< failed to show keyboard - ERROR_KBD_HIDE_FAILED, //!< failed to hide keyboard - ERROR_IME_NOT_STARTED, //!< input method service is not started - ERROR_KBD_IS_OCCUPIED, //!< keyboard is showing by other client - ERROR_KBD_IS_NOT_SHOWING, //!< keyboard is not showing - ERROR_IME_ALREADY_STARTED, //!< input method service has already started - ERROR_NOT_IME_PACKAGE, //!< not an IME package - ERROR_IME_PACKAGE_DUPLICATED, //!< duplicated IME package - ERROR_SETTING_SAME_VALUE, //!< same setting value - ERROR_NO_NEXT_IME, //!< no next ime is available - ERROR_CLIENTWINDOW_NOT_FOCUSED, //!< the input client window is not focused - ERROR_CLIENT_NOT_WINDOW, //!< the input client is not from a valid window + ERROR_NULL_POINTER, // null pointer + ERROR_BAD_PARAMETERS, // bad parameters + ERROR_SERVICE_START_FAILED, // failed to start service + ERROR_USER_NOT_STARTED, // user is not started + ERROR_USER_ALREADY_STARTED, // user has already started + ERROR_USER_NOT_UNLOCKED, // user is not unlocked + ERROR_USER_ALREADY_UNLOCKED, // user has already unlocked + ERROR_USER_NOT_LOCKED, // user is not locked + + ERROR_IME_NOT_AVAILABLE, // input method engine is not available + ERROR_SECURITY_IME_NOT_AVAILABLE, // security input method engine is not available + ERROR_TOKEN_CREATE_FAILED, // failed to create window token + ERROR_TOKEN_DESTROY_FAILED, // failed to destroy window token + ERROR_IME_BIND_FAILED, // failed to bind IME service + ERROR_IME_UNBIND_FAILED, // failed to unbind IME service + ERROR_IME_START_FAILED, // failed to start IME service + ERROR_IME_STOP_FAILED, // failed to stop IME service + ERROR_KBD_SHOW_FAILED, // failed to show keyboard + ERROR_KBD_HIDE_FAILED, // failed to hide keyboard + ERROR_IME_NOT_STARTED, // input method service is not started + ERROR_KBD_IS_OCCUPIED, // keyboard is showing by other client + ERROR_KBD_IS_NOT_SHOWING, // keyboard is not showing + ERROR_IME_ALREADY_STARTED, // input method service has already started + ERROR_NOT_IME_PACKAGE, // not an IME package + ERROR_IME_PACKAGE_DUPLICATED, // duplicated IME package + ERROR_SETTING_SAME_VALUE, // same setting value + ERROR_NO_NEXT_IME, // no next ime is available + ERROR_CLIENTWINDOW_NOT_FOCUSED, // the input client window is not focused + ERROR_CLIENT_NOT_WINDOW, // the input client is not from a valid window // error from ime - ERROR_REMOTE_IME_DIED, //!< remote input method service died abnormally - ERROR_RESTART_IME_FAILED, //!< failed to restart input method service + ERROR_REMOTE_IME_DIED, // remote input method service died abnormally + ERROR_RESTART_IME_FAILED, // failed to restart input method service // error from client - ERROR_REMOTE_CLIENT_DIED, //!< remote client died abnormally - ERROR_CLIENT_DUPLICATED, //!< duplicated client - ERROR_CLIENT_NOT_FOUND, //!< client is not found - + ERROR_REMOTE_CLIENT_DIED, // remote client died abnormally + ERROR_CLIENT_DUPLICATED, // duplicated client + ERROR_CLIENT_NOT_FOUND, // client is not found }; const char* ToString(int errorCode); }; @@ -166,7 +165,6 @@ static constexpr HiviewDFX::HiLogLabel g_SMALL_SERVICES_LABEL = { "line: %d, function: %s," fmt, __LINE__, __FUNCTION__, ##__VA_ARGS__) #define IMSA_HILOGW(fmt, ...) (void)OHOS::HiviewDFX::HiLog::Warn(OHOS::MiscServices::g_SMALL_SERVICES_LABEL, \ "line: %d, function: %s," fmt, __LINE__, __FUNCTION__, ##__VA_ARGS__) - } } #endif // FM_IMMS_PROJECT_GLOBAL_H diff --git a/services/include/i_input_control_channel.h b/services/include/i_input_control_channel.h index 39f89b9d2d1c23d24912fc0e37b6a9bae89fa866..e317b55ea831d8a6d112e8b032947e3233fb3a04 100644 --- a/services/include/i_input_control_channel.h +++ b/services/include/i_input_control_channel.h @@ -43,5 +43,4 @@ namespace OHOS { }; } } - #endif // FM_IMMS_PROJECT_IINPUTCONTROLCHANNEL_H diff --git a/services/include/i_input_method_proxy.h b/services/include/i_input_method_proxy.h index f5122608c1ba533a9ffc61e3f466e1a1725a27c1..35f1573ef49400b292a462cdb5772c77a331b61f 100644 --- a/services/include/i_input_method_proxy.h +++ b/services/include/i_input_method_proxy.h @@ -34,5 +34,4 @@ namespace OHOS { }; } } - #endif // FM_IMMS_PROJECT_IINPUTMETHODAGENT_H diff --git a/services/include/i_input_method_system_ability.h b/services/include/i_input_method_system_ability.h index a4c366557239bf31d454f9aee59ef470a27b14b3..df36ff292d525e1f01e5c6574359076cbd5e2e91 100644 --- a/services/include/i_input_method_system_ability.h +++ b/services/include/i_input_method_system_ability.h @@ -30,38 +30,37 @@ namespace OHOS { namespace MiscServices { -class IInputMethodSystemAbility : public IRemoteBroker { -public: - enum { - PREPARE_INPUT = 0, - RELEASE_INPUT, - START_INPUT, - STOP_INPUT, - SET_INPUT_METHOD_CORE, - GET_DISPLAY_MODE, - GET_KEYBOARD_WINDOW_HEIGHT, - GET_CURRENT_KEYBOARD_TYPE, - LIST_INPUT_METHOD_ENABLED, - LIST_INPUT_METHOD, - LIST_KEYBOARD_TYPE, - }; + class IInputMethodSystemAbility : public IRemoteBroker { + public: + enum { + PREPARE_INPUT = 0, + RELEASE_INPUT, + START_INPUT, + STOP_INPUT, + SET_INPUT_METHOD_CORE, + GET_DISPLAY_MODE, + GET_KEYBOARD_WINDOW_HEIGHT, + GET_CURRENT_KEYBOARD_TYPE, + LIST_INPUT_METHOD_ENABLED, + LIST_INPUT_METHOD, + LIST_KEYBOARD_TYPE, + }; - DECLARE_INTERFACE_DESCRIPTOR(u"ohos.miscservices.inputmethod.IInputMethodSystemAbility"); + DECLARE_INTERFACE_DESCRIPTOR(u"ohos.miscservices.inputmethod.IInputMethodSystemAbility"); - virtual void prepareInput(MessageParcel& data) = 0; - virtual void releaseInput(MessageParcel& data) = 0; - virtual void startInput(MessageParcel& data) = 0; - virtual void stopInput(MessageParcel& data) = 0; - virtual int32_t setInputMethodCore(sptr &core)=0; + virtual void prepareInput(MessageParcel& data) = 0; + virtual void releaseInput(MessageParcel& data) = 0; + virtual void startInput(MessageParcel& data) = 0; + virtual void stopInput(MessageParcel& data) = 0; + virtual int32_t setInputMethodCore(sptr &core)=0; - virtual int32_t getDisplayMode(int32_t *retMode) = 0; - virtual int32_t getKeyboardWindowHeight(int32_t *retHeight) = 0; - virtual int32_t getCurrentKeyboardType(KeyboardType* retType) = 0; - virtual int32_t listInputMethodEnabled(std::vector *properties) = 0; - virtual int32_t listInputMethod(std::vector *properties) = 0; - virtual int32_t listKeyboardType(const std::u16string& imeId, std::vector *types) = 0; -}; + virtual int32_t getDisplayMode(int32_t *retMode) = 0; + virtual int32_t getKeyboardWindowHeight(int32_t *retHeight) = 0; + virtual int32_t getCurrentKeyboardType(KeyboardType* retType) = 0; + virtual int32_t listInputMethodEnabled(std::vector *properties) = 0; + virtual int32_t listInputMethod(std::vector *properties) = 0; + virtual int32_t listKeyboardType(const std::u16string& imeId, std::vector *types) = 0; + }; } } - #endif // FM_IMMS_PROJECT_IINPUTMETHODSYSTEMABILITY_H diff --git a/services/include/i_platform_api.h b/services/include/i_platform_api.h index 4daf851426fbc8185ed533f4f0d694effa63216e..1c7066c50728cc989927cc8586e9fe1e486f3373 100644 --- a/services/include/i_platform_api.h +++ b/services/include/i_platform_api.h @@ -51,7 +51,7 @@ namespace OHOS { virtual int32_t unbindInputMethodService(int userId, const std::u16string& packageName) = 0; virtual sptr createWindowToken(int userId, int displayId, const std::u16string& packageName) = 0; virtual int32_t destroyWindowToken(int userId, const std::u16string& packageName) = 0; - virtual int32_t listInputMethod(int userId, std::vector *inputMethodProperties) = 0; + virtual int32_t listInputMethod(int userId, std::vector *properties) = 0; virtual int32_t getInputMethodProperty(int userId, const std::u16string& packageName, InputMethodProperty *inputMethodProperty) = 0; virtual int32_t getInputMethodSetting(int userId, InputMethodSetting *inputMethodSetting) = 0; diff --git a/services/include/input_attribute.h b/services/include/input_attribute.h index a15513fa97acbdee32d9fe3134938628c474a322..266e35f900bd37ac6e27ab4e0565488e49defc26 100644 --- a/services/include/input_attribute.h +++ b/services/include/input_attribute.h @@ -19,23 +19,23 @@ namespace OHOS { namespace MiscServices { -class InputAttribute : public Parcelable { -public: - InputAttribute(); - InputAttribute(const InputAttribute& attribute); - InputAttribute& operator=(const InputAttribute& attribute); - ~InputAttribute(); - virtual bool Marshalling(Parcel &parcel) const override; - static InputAttribute *Unmarshalling(Parcel &parcel); - void SetInputPattern(int32_t pattern); - bool GetSecurityFlag(); - static const int32_t PATTERN_TEXT = 0x00000001; - static const int32_t PATTERN_PASSWORD = 0x00000007; -private: - int32_t inputPattern; - int32_t enterKeyType; - int32_t inputOption; -}; + class InputAttribute : public Parcelable { + public: + InputAttribute(); + InputAttribute(const InputAttribute& attribute); + InputAttribute& operator=(const InputAttribute& attribute); + ~InputAttribute(); + virtual bool Marshalling(Parcel &parcel) const override; + static InputAttribute *Unmarshalling(Parcel &parcel); + void SetInputPattern(int32_t pattern); + bool GetSecurityFlag(); + static const int32_t PATTERN_TEXT = 0x00000001; + static const int32_t PATTERN_PASSWORD = 0x00000007; + private: + int32_t inputPattern; + int32_t enterKeyType; + int32_t inputOption; + }; } } diff --git a/services/include/input_channel.h b/services/include/input_channel.h index 670b1ceff2ca6649c138020250230697e4a080b6..98ab7f719ef96bc7930a4f634263648a5899a9df 100644 --- a/services/include/input_channel.h +++ b/services/include/input_channel.h @@ -22,7 +22,7 @@ namespace OHOS { namespace MiscServices { - class InputChannel : public Parcelable{ + class InputChannel : public Parcelable { public: InputChannel(); ~InputChannel(); @@ -33,7 +33,7 @@ namespace MiscServices { MessageParcel inputChannelParcel; InputChannel(const InputChannel& channel); InputChannel& operator=(const InputChannel& channel); - }; + }; } } #endif // INPUTMETHODSYSTEMSERVICE_INPUTCHANNEL_H diff --git a/services/include/input_control_channel_proxy.h b/services/include/input_control_channel_proxy.h index f08b4d0e0a9cc8dcc14acb3e2bec59c750ae1dc4..2a3b215aee44b149bf3e056f55e115b6810394ed 100644 --- a/services/include/input_control_channel_proxy.h +++ b/services/include/input_control_channel_proxy.h @@ -41,6 +41,4 @@ namespace MiscServices { }; } } -#endif // FM_IMMS_PROJECT_INPUTCONTROLCHANNELPROXY_H - - +#endif // FM_IMMS_PROJECT_INPUTCONTROLCHANNELPROXY_H \ No newline at end of file diff --git a/services/include/input_control_channel_stub.h b/services/include/input_control_channel_stub.h index af616457a35ef4aa921c34bd88bd30958bad9cc4..9b04295408ad39af0a66f514dfaa8b7a6fee685a 100644 --- a/services/include/input_control_channel_stub.h +++ b/services/include/input_control_channel_stub.h @@ -53,7 +53,7 @@ namespace OHOS { std::condition_variable cv; bool agentReadyFlag = false; bool keyboardReadyFlag = false; - }; + }; } } #endif // FM_IMMS_PROJECT_INPUTCONTROLCHANNEL_SK_H diff --git a/services/include/input_method_ability_connection_stub.h b/services/include/input_method_ability_connection_stub.h index f6739ce600b9980e7e8797f3baea1ec4b3f4008c..87fa112665f85de805a9a3f841cd335b2bb2f8d2 100644 --- a/services/include/input_method_ability_connection_stub.h +++ b/services/include/input_method_ability_connection_stub.h @@ -32,11 +32,11 @@ namespace OHOS { InputMethodAbilityConnectionStub(const int index); ~InputMethodAbilityConnectionStub(); - void OnAbilityConnectDone(const AppExecFwk::ElementName &element, const sptr &remoteObject, int resultCode) override; + void OnAbilityConnectDone(const AppExecFwk::ElementName &element, + const sptr &remoteObject, int resultCode) override; void OnAbilityDisconnectDone(const AppExecFwk::ElementName &element, int resultCode) override; void SetHandler(MessageHandler* handler); - private: MessageHandler* messageHandler; int mIndex; diff --git a/services/include/input_method_property.h b/services/include/input_method_property.h index da09a69630803fe95ac0cdbab639a2e41cd80f5d..522a88a498d6110201d22f652546b4fb020038d8 100644 --- a/services/include/input_method_property.h +++ b/services/include/input_method_property.h @@ -22,23 +22,23 @@ namespace OHOS { namespace MiscServices { -class InputMethodProperty : public Parcelable { -public: - std::u16string mImeId; - std::u16string mPackageName; - std::u16string mAbilityName; - std::u16string mConfigurationPage; - bool isSystemIme; - int32_t mDefaultImeId; - std::vector mTypes; + class InputMethodProperty : public Parcelable { + public: + std::u16string mImeId; + std::u16string mPackageName; + std::u16string mAbilityName; + std::u16string mConfigurationPage; + bool isSystemIme; + int32_t mDefaultImeId; + std::vector mTypes; - InputMethodProperty(); - ~InputMethodProperty(); - InputMethodProperty(const InputMethodProperty& property); - InputMethodProperty& operator=(const InputMethodProperty& property); - virtual bool Marshalling(Parcel &parcel) const override; - static InputMethodProperty *Unmarshalling(Parcel &parcel); -}; + InputMethodProperty(); + ~InputMethodProperty(); + InputMethodProperty(const InputMethodProperty& property); + InputMethodProperty& operator=(const InputMethodProperty& property); + virtual bool Marshalling(Parcel &parcel) const override; + static InputMethodProperty *Unmarshalling(Parcel &parcel); + }; } } #endif // FM_IMMS_PROJECT_INPUTMETHODPROPERTY_H diff --git a/services/include/input_method_setting.h b/services/include/input_method_setting.h index 143fe8b9fe2ee193efad903a3148b4f8139c04da..66c256934ec4cdf4aef65ec4f78907e61f9b20f3 100644 --- a/services/include/input_method_setting.h +++ b/services/include/input_method_setting.h @@ -26,13 +26,11 @@ namespace MiscServices { class InputMethodSetting : public Parcelable { public: - const static std::u16string CURRENT_INPUT_METHOD_TAG; //!< the item name of 'default IME' in the system setting - const static std::u16string ENABLED_INPUT_METHODS_TAG; //!< the item name of 'enabled IME list' in the system setting - const static std::u16string CURRENT_KEYBOARD_TYPE_TAG; //!< the item name of 'default keyboard type' in the system setting - const static std::u16string CURRENT_SYS_KEYBOARD_TYPE_TAG; - //!< the item name of 'default keyboard type for security IME in the system setting - - const static std::u16string SYSTEM_LOCALE_TAG; //!< the item name of locale list supported in the system + const static std::u16string CURRENT_INPUT_METHOD_TAG; // default IME + const static std::u16string ENABLED_INPUT_METHODS_TAG; // enabled IME list + const static std::u16string CURRENT_KEYBOARD_TYPE_TAG; // default keyboard type + 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(); diff --git a/services/include/input_method_system_ability.h b/services/include/input_method_system_ability.h index 85080b89114c2fb3c2fe0d3a6bc2bfed3e30cbf6..09fb192ff2ec2172194357b82e2373bf4da55a37 100644 --- a/services/include/input_method_system_ability.h +++ b/services/include/input_method_system_ability.h @@ -43,7 +43,8 @@ namespace MiscServices { int32_t GetUserState(int32_t userId); - 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 int32_t getDisplayMode(int32_t *retMode) override; virtual int32_t getKeyboardWindowHeight(int32_t *retHeight) override; virtual int32_t getCurrentKeyboardType(KeyboardType* retType) override; diff --git a/services/include/input_method_system_ability_stub.h b/services/include/input_method_system_ability_stub.h index 3b193e40d6a67173be55edacdbe3f9972e835a5a..df9c38edb17b54a3647c57a2dcd7cebe2200ff94 100644 --- a/services/include/input_method_system_ability_stub.h +++ b/services/include/input_method_system_ability_stub.h @@ -24,18 +24,18 @@ namespace OHOS { namespace MiscServices { -class InputMethodSystemAbilityStub : public IRemoteStub { -public: - int32_t OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) override; + class InputMethodSystemAbilityStub : public IRemoteStub { + public: + 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; - virtual void startInput(MessageParcel& data) override; - virtual void stopInput(MessageParcel& data) override; - void setInputMethodCoreFromHap(MessageParcel& data); -protected: - int32_t getUserId(int32_t uid); -}; + virtual void prepareInput(MessageParcel& data) override; + virtual void releaseInput(MessageParcel& data) override; + virtual void startInput(MessageParcel& data) override; + virtual void stopInput(MessageParcel& data) override; + void setInputMethodCoreFromHap(MessageParcel& data); + protected: + int32_t getUserId(int32_t uid); + }; } } diff --git a/services/include/keyboard_type.h b/services/include/keyboard_type.h index da68164ebc134166e8345658cfcd9efe67957271..d3f0fdeb90ead41d44f1ced96effbfb65f299fce 100644 --- a/services/include/keyboard_type.h +++ b/services/include/keyboard_type.h @@ -22,42 +22,42 @@ namespace OHOS { namespace MiscServices { -class KeyboardType : public Parcelable { -public: - KeyboardType(); - KeyboardType(const KeyboardType& type); - ~KeyboardType(); - KeyboardType& operator=(const KeyboardType& type); - virtual bool Marshalling(Parcel &parcel) const override; - static KeyboardType *Unmarshalling(Parcel &parcel); - void setId(int32_t typeId); - void setLabelId(int32_t labelId); - void setIconId(int32_t iconId); - void setAsciiCapability(bool isAsciiCapable); - void setLanguage(std::u16string language); - void setInputSource(std::u16string inputSource); - void setCustomizedValue(std::u16string keyBoardTypeCustomizedValue); - int32_t getId() const; - int32_t getLabelId() const; - int32_t getIconId() const; - int32_t getHashCode() const; - std::u16string getLanguage() const; - std::u16string getInputSource() const; - std::u16string getCustomizedValue() const; - bool supportsAscii(); + class KeyboardType : public Parcelable { + public: + KeyboardType(); + KeyboardType(const KeyboardType& type); + ~KeyboardType(); + KeyboardType& operator=(const KeyboardType& type); + virtual bool Marshalling(Parcel &parcel) const override; + static KeyboardType *Unmarshalling(Parcel &parcel); + void setId(int32_t typeId); + void setLabelId(int32_t labelId); + void setIconId(int32_t iconId); + void setAsciiCapability(bool isAsciiCapable); + void setLanguage(std::u16string language); + void setInputSource(std::u16string inputSource); + void setCustomizedValue(std::u16string customizedValue); + int32_t getId() const; + int32_t getLabelId() const; + int32_t getIconId() const; + int32_t getHashCode() const; + std::u16string getLanguage() const; + std::u16string getInputSource() const; + std::u16string getCustomizedValue() const; + bool supportsAscii(); -private: - int32_t mId; - int32_t mHashCode; - int32_t mLabelId; - int32_t mIconId; - bool mIsAsciiCapable; - std::u16string mLanguage; - std::u16string mInputSource; - std::u16string mCustomizedValue; + private: + int32_t mId; + int32_t mHashCode; + int32_t mLabelId; + int32_t mIconId; + bool mIsAsciiCapable; + std::u16string mLanguage; + std::u16string mInputSource; + std::u16string mCustomizedValue; - const int32_t ID_NONE = 0; -}; + const int32_t ID_NONE = 0; + }; } } #endif // FM_IMMS_PROJECT_KEYBOARDTYPE_H diff --git a/services/include/message.h b/services/include/message.h index 2f5581a2a5117ca01ac43d500e639a71ccfa36ef..5116e9dd53a53b88dec8482302f69e35e8c9b5c2 100644 --- a/services/include/message.h +++ b/services/include/message.h @@ -21,18 +21,18 @@ #include "message_parcel.h" namespace OHOS { namespace MiscServices { -class Message { -public: - int32_t msgId_; //!< message id - MessageParcel *msgContent_ = nullptr; //!< message content - Message(int32_t msgId, MessageParcel* msgContent); - explicit Message(const Message& msg); - Message& operator= (const Message& msg); - ~Message(); -private: - Message(const Message&&); - Message& operator= (const Message&&); -}; + class Message { + public: + int32_t msgId_; // message id + MessageParcel *msgContent_ = nullptr; // message content + Message(int32_t msgId, MessageParcel* msgContent); + explicit Message(const Message& msg); + Message& operator= (const Message& msg); + ~Message(); + private: + Message(const Message&&); + Message& operator= (const Message&&); + }; } } diff --git a/services/include/message_handler.h b/services/include/message_handler.h index 88fa4c315e6a4be2cebb7b4d4bffd092dbee062d..b47d1562ca2eedd7f1c5ce29033e2d5084586dd2 100644 --- a/services/include/message_handler.h +++ b/services/include/message_handler.h @@ -29,34 +29,34 @@ namespace MiscServices { namespace MessageID { enum { // for system broadcast - MSG_ID_SYSTEM_START = 0, //!< system started - MSG_ID_SYSTEM_STOP, //!< system stopped - MSG_ID_USER_START, //!< a user started - MSG_ID_USER_STOP, //!< a user stopped - MSG_ID_USER_UNLOCK, //!< a user unlocked - MSG_ID_USER_LOCK, //!< a user locked - MSG_ID_PACKAGE_ADDED, //!< a package is installed - MSG_ID_PACKAGE_REMOVED, //!< a package is removed - MSG_ID_SETTING_CHANGED, //!< input method setting is changed + MSG_ID_SYSTEM_START = 0, // system started + MSG_ID_SYSTEM_STOP, // system stopped + MSG_ID_USER_START, // a user started + MSG_ID_USER_STOP, // a user stopped + MSG_ID_USER_UNLOCK, // a user unlocked + MSG_ID_USER_LOCK, // a user locked + MSG_ID_PACKAGE_ADDED, // a package is installed + MSG_ID_PACKAGE_REMOVED, // a package is removed + MSG_ID_SETTING_CHANGED, // input method setting is changed // the request from client - MSG_ID_PREPARE_INPUT, //!< prepare input - MSG_ID_START_INPUT, //!< start input - MSG_ID_STOP_INPUT, //!< stop input - MSG_ID_RELEASE_INPUT, //!< release input + MSG_ID_PREPARE_INPUT, // prepare input + MSG_ID_START_INPUT, // start input + MSG_ID_STOP_INPUT, // stop input + MSG_ID_RELEASE_INPUT, // release input MSG_ID_SET_INPUT_METHOD_CORE, // the request to handle the condition that the remote object died - MSG_ID_CLIENT_DIED, //!< input client died - MSG_ID_IMS_DIED, //!< input method service died - MSG_ID_DISABLE_IMS, //!< disable input method service - MSG_ID_RESTART_IMS, //!< restart input method service - MSG_ID_HIDE_KEYBOARD_SELF, //!< hide the current keyboard - MSG_ID_ADVANCE_TO_NEXT, //!< switch to next - MSG_ID_SET_DISPLAY_MODE, //!< set display mode + MSG_ID_CLIENT_DIED, // input client died + MSG_ID_IMS_DIED, // input method service died + MSG_ID_DISABLE_IMS, // disable input method service + MSG_ID_RESTART_IMS, // restart input method service + MSG_ID_HIDE_KEYBOARD_SELF, // hide the current keyboard + MSG_ID_ADVANCE_TO_NEXT, // switch to next + MSG_ID_SET_DISPLAY_MODE, // set display mode - MSG_ID_SHELL_COMMAND, //!< shell command - MSG_ID_EXIT_SERVICE, //!< exit service + MSG_ID_SHELL_COMMAND, // shell command + MSG_ID_EXIT_SERVICE, // exit service //the request from IMSA to IMC MSG_ID_INSERT_CHAR, @@ -65,36 +65,35 @@ namespace MessageID { MSG_ID_ON_INPUT_READY, // the request from IMSA to IMA - MSG_ID_SHOW_KEYBOARD, // - MSG_ID_INITIALIZE_INPUT, // - MSG_ID_HIDE_KEYBOARD, // + MSG_ID_SHOW_KEYBOARD, + MSG_ID_INITIALIZE_INPUT, + MSG_ID_HIDE_KEYBOARD, MSG_ID_SET_KEYBOARD_TYPE, MSG_ID_GET_KEYBOARD_WINDOW_HEIGHT, - + // the request from IMC to IMA - MSG_ID_DISPATCH_KEY,//!< dispatch key from PhysicalKbd + MSG_ID_DISPATCH_KEY, // dispatch key from PhysicalKbd }; } class MessageHandler { -public: - MessageHandler(); - ~MessageHandler(); - void SendMessage(Message* msg); - Message* GetMessage(); - static MessageHandler* Instance(); + public: + MessageHandler(); + ~MessageHandler(); + void SendMessage(Message* msg); + Message* GetMessage(); + static MessageHandler* Instance(); -private: - std::mutex mMutex; //!< a mutex to guard message queue - std::condition_variable mCV; //!< condition variable to work with mMutex - std::queue mQueue ;//!< Message queue, guarded by mMutex; + private: + std::mutex mMutex; // a mutex to guard message queue + std::condition_variable mCV; // condition variable to work with mMutex + std::queue mQueue ; // Message queue, guarded by mMutex; - MessageHandler(const MessageHandler&); - MessageHandler& operator= (const MessageHandler&); - MessageHandler(const MessageHandler&&); - MessageHandler& operator= (const MessageHandler&&); -}; + MessageHandler(const MessageHandler&); + MessageHandler& operator= (const MessageHandler&); + MessageHandler(const MessageHandler&&); + MessageHandler& operator= (const MessageHandler&&); + }; } } - #endif // FM_IMMS_PROJECT_MESSAGEHANDLER_H diff --git a/services/include/peruser_session.h b/services/include/peruser_session.h index e8e3f0be6b2bebe6d1c958778c67639b18b808d6..69b27ff5a80e56ceac769e74b481de1f6d871adf 100644 --- a/services/include/peruser_session.h +++ b/services/include/peruser_session.h @@ -41,156 +41,149 @@ #include "input_method_ability.h" namespace OHOS { - namespace MiscServices { - - - class RemoteObjectDeathRecipient : public IRemoteObject::DeathRecipient { - public: - RemoteObjectDeathRecipient(int userId, int msgId); - ~RemoteObjectDeathRecipient(); - void OnRemoteDied(const wptr& who) override; - private : - int userId_; //!< the id of the user to whom the object is linking - int msgId_; //!< the message id can be MessageID::MSG_ID_CLIENT_DIED and MessageID::MSG_ID_IMS_DIED - }; - - /*! \class ClientInfo - \brief The class defines the details of an input client. - */ - class ClientInfo { - public: - int pid; //!< the process id of the process in which the input client is running - int uid; //!< the uid of the process in which the input client is running - int userId; //!< the user if of the user under which the input client is running - int displayId; //!< the display id on which the input client is showing - sptr client; //!< the remote object handler for the service to callback to the input client - sptr channel; //!< the remote object handler for input method service callback to input client - InputAttribute attribute; //!< the input attribute of the input client - - ClientInfo(int pid, int uid, int userId, int displayId, const sptr& client, - const sptr& channel, const InputAttribute& attribute) - { - this->pid = pid; - this->uid = uid; - this->userId = userId; - this->displayId = displayId; - this->client = client; - this->channel = channel; - this->attribute = attribute; - }; - - ~ClientInfo() - { - this->client = nullptr; - this->channel = nullptr; - }; - }; - - /*! \class PerUserSession - \brief The class provides session management in input method management service - - This class manages the sessions between input clients and input method engines for each unlocked user. - */ - class PerUserSession { - enum { - DEFAULT_IME = 0, //!< index for default input method service - SECURITY_IME = 1, //!< index for security input method service - MAX_IME = 2, //!< the maximum count of ims started for a user - }; - - public: - explicit PerUserSession(int userId); - ~PerUserSession(); - - void SetCurrentIme(InputMethodProperty* ime); - void SetSecurityIme(InputMethodProperty* ime); - void SetInputMethodSetting(InputMethodSetting* setting); - void ResetIme(InputMethodProperty* defaultIme, InputMethodProperty* securityIme); - void OnPackageRemoved(const std::u16string& packageName); - - int GetDisplayMode(); - int GetKeyboardWindowHeight(int *retHeight); - KeyboardType* GetCurrentKeyboardType(); - - int OnSettingChanged(const std::u16string& key, const std::u16string& value); - void Dump(int fd); - void CreateWorkThread(MessageHandler& handler); - void JoinWorkThread(); - void SetInputMethodAbility(sptr &inputMethodAbility); - static void BindInputAbility(); - private: - int userId_; //!< the id of the user to whom the object is linking - int userState; //!< the state of the user to whom the object is linking - int displayId; //!< the id of the display screen on which the user is - int currentIndex; - std::map, ClientInfo*> mapClients; //!< a map to manage the input clients connected to the service - /*!< \n key is the remote IInputClient handler - \n value is an object of an ClientInfo */ - - InputMethodProperty* currentIme[MAX_IME]; //!< 0 - the default ime. 1 - security ime - /*!< \n The pointers are referred to the objects in the PerUserSetting */ - - InputControlChannelStub* localControlChannel[MAX_IME]; //!< inputControlChannel object used by the local process - sptr inputControlChannel[MAX_IME]; //!< channels between the service and input method service - sptr imsCore[MAX_IME]; //!< the remote handlers of input method service - sptr inputMethodToken[MAX_IME]; //!< the window token of keyboard - int currentKbdIndex[MAX_IME]; //!< current keyboard index - int lastImeIndex; //!< The last ime which showed keyboard - InputMethodSetting* inputMethodSetting; //!< The pointer referred to the object in PerUserSetting - int currentDisplayMode; //!< the display mode of the current keyboard - - sptr imsAgent; - InputChannel* imsChannel; //!< the write channel created by input method service - sptr currentClient; //!< the current input client - sptr needReshowClient; //!< the input client for which keyboard need to re-show - - sptr clientDeathRecipient; //!< remote object death monitor for input client - sptr imsDeathRecipient; //!< remote object death monitor for input method service - MessageHandler* msgHandler = nullptr; //!< message handler working with Work Thread - std::thread workThreadHandler; //!< work thread handler - std::mutex mtx; //!< mutex to lock the operations among multi work threads - sptr connCallback; - sptr inputMethodAbility_; - - PerUserSession(const PerUserSession&); - PerUserSession& operator= (const PerUserSession&); - PerUserSession(const PerUserSession&&); - PerUserSession& operator= (const PerUserSession&&); - int IncreaseOrResetImeError(bool resetFlag, int imeIndex); - KeyboardType* GetKeyboardType(int imeIndex, int typeIndex); - void ResetCurrentKeyboardType(int imeIndex); - int OnCurrentKeyboardTypeChanged(int index, const std::u16string& value); - void DumpClientInfo(int fd, const ClientInfo& clientInfo); - void DumpCurrentSession(int fd); - void CopyInputMethodService(int imeIndex); - ClientInfo* GetClientInfo(const sptr& inputClient); - void WorkThread(); - void OnPrepareInput(Message* msg); - void OnReleaseInput(Message* msg); - void OnStartInput(Message* msg); - void OnStopInput(Message* msg); - void OnClientDied(const wptr& who); - void OnImsDied(const wptr& who); - void OnHideKeyboardSelf(int flags); - void OnAdvanceToNext(); - void OnSetDisplayMode(int mode); - void OnRestartIms(int index, const std::u16string& imeId); - void OnUserLocked(); - int AddClient(int pid, int uid, int displayId, const sptr& inputClient, - const sptr& channel, - const InputAttribute& attribute); - int RemoveClient(const sptr& inputClient, int *retClientNum); - int StartInputMethod(int index); - int StopInputMethod(int index); - int ShowKeyboard(const sptr& inputClient); - int HideKeyboard(const sptr& inputClient); - void SetDisplayId(int displayId); - int GetImeIndex(const sptr& inputClient); - static sptr GetAbilityManagerService(); - void onSetInputMethodCore(Message* msg); - - }; - } +namespace MiscServices { + class RemoteObjectDeathRecipient : public IRemoteObject::DeathRecipient { + public: + RemoteObjectDeathRecipient(int userId, int msgId); + ~RemoteObjectDeathRecipient(); + void OnRemoteDied(const wptr& who) override; + private: + int userId_; // the id of the user to whom the object is linking + int msgId_; // the message id can be MessageID::MSG_ID_CLIENT_DIED and MessageID::MSG_ID_IMS_DIED + }; + + /*! \class ClientInfo + \brief The class defines the details of an input client. + */ + class ClientInfo { + public: + int pid; // the process id of the process in which the input client is running + int uid; // the uid of the process in which the input client is running + int userId; // the user if of the user under which the input client is running + int displayId; // the display id on which the input client is showing + sptr client; // the remote object handler for the service to callback to the input client + sptr channel; // the remote object handler for IMSA callback to input client + InputAttribute attribute; // the input attribute of the input client + + ClientInfo(int pid, int uid, int userId, int displayId, const sptr& client, + const sptr& channel, const InputAttribute& attribute) + { + this->pid = pid; + this->uid = uid; + this->userId = userId; + this->displayId = displayId; + this->client = client; + this->channel = channel; + this->attribute = attribute; + }; + + ~ClientInfo() + { + this->client = nullptr; + this->channel = nullptr; + }; + }; + + /*! \class PerUserSession + \brief The class provides session management in input method management service + + This class manages the sessions between input clients and input method engines for each unlocked user. + */ + class PerUserSession { + enum { + DEFAULT_IME = 0, // index for default input method service + SECURITY_IME = 1, // index for security input method service + MAX_IME = 2, // the maximum count of ims started for a user + }; + + public: + explicit PerUserSession(int userId); + ~PerUserSession(); + + void SetCurrentIme(InputMethodProperty* ime); + void SetSecurityIme(InputMethodProperty* ime); + void SetInputMethodSetting(InputMethodSetting* setting); + void ResetIme(InputMethodProperty* defaultIme, InputMethodProperty* securityIme); + void OnPackageRemoved(const std::u16string& packageName); + + int GetDisplayMode(); + int GetKeyboardWindowHeight(int *retHeight); + KeyboardType* GetCurrentKeyboardType(); + + int OnSettingChanged(const std::u16string& key, const std::u16string& value); + void Dump(int fd); + void CreateWorkThread(MessageHandler& handler); + void JoinWorkThread(); + void SetInputMethodAbility(sptr &inputMethodAbility); + static void BindInputAbility(); + private: + int userId_; // the id of the user to whom the object is linking + int userState; // the state of the user to whom the object is linking + int displayId; // the id of the display screen on which the user is + int currentIndex; + std::map, ClientInfo*> mapClients; + + InputMethodProperty* currentIme[MAX_IME]; // 0 - the default ime. 1 - security ime + + InputControlChannelStub* localControlChannel[MAX_IME]; + sptr inputControlChannel[MAX_IME]; + sptr imsCore[MAX_IME]; // the remote handlers of input method service + sptr inputMethodToken[MAX_IME]; // the window token of keyboard + int currentKbdIndex[MAX_IME]; // current keyboard index + int lastImeIndex; // The last ime which showed keyboard + InputMethodSetting* inputMethodSetting; // The pointer referred to the object in PerUserSetting + int currentDisplayMode; // the display mode of the current keyboard + + sptr imsAgent; + InputChannel* imsChannel; // the write channel created by input method service + sptr currentClient; // the current input client + sptr needReshowClient; // the input client for which keyboard need to re-show + + sptr clientDeathRecipient; // remote object death monitor for input client + sptr imsDeathRecipient; + MessageHandler* msgHandler = nullptr; // message handler working with Work Thread + std::thread workThreadHandler; // work thread handler + std::mutex mtx; // mutex to lock the operations among multi work threads + sptr connCallback; + sptr inputMethodAbility_; + + PerUserSession(const PerUserSession&); + PerUserSession& operator= (const PerUserSession&); + PerUserSession(const PerUserSession&&); + PerUserSession& operator= (const PerUserSession&&); + int IncreaseOrResetImeError(bool resetFlag, int imeIndex); + KeyboardType* GetKeyboardType(int imeIndex, int typeIndex); + void ResetCurrentKeyboardType(int imeIndex); + int OnCurrentKeyboardTypeChanged(int index, const std::u16string& value); + void DumpClientInfo(int fd, const ClientInfo& clientInfo); + void DumpCurrentSession(int fd); + void CopyInputMethodService(int imeIndex); + ClientInfo* GetClientInfo(const sptr& inputClient); + void WorkThread(); + void OnPrepareInput(Message* msg); + void OnReleaseInput(Message* msg); + void OnStartInput(Message* msg); + void OnStopInput(Message* msg); + void OnClientDied(const wptr& who); + void OnImsDied(const wptr& who); + void OnHideKeyboardSelf(int flags); + void OnAdvanceToNext(); + void OnSetDisplayMode(int mode); + void OnRestartIms(int index, const std::u16string& imeId); + void OnUserLocked(); + int AddClient(int pid, int uid, int displayId, const sptr& inputClient, + const sptr& channel, + const InputAttribute& attribute); + int RemoveClient(const sptr& inputClient, int *retClientNum); + int StartInputMethod(int index); + int StopInputMethod(int index); + int ShowKeyboard(const sptr& inputClient); + int HideKeyboard(const sptr& inputClient); + void SetDisplayId(int displayId); + int GetImeIndex(const sptr& inputClient); + static sptr GetAbilityManagerService(); + void onSetInputMethodCore(Message* msg); + }; +} } - #endif // FM_IMMS_PROJECT_PERUSERSESSION_H diff --git a/services/include/peruser_setting.h b/services/include/peruser_setting.h index 37e4cb86144744a9823773be58f995c54349747f..65ccda848d16ce694ef5459ced2eaaf40a63383a 100644 --- a/services/include/peruser_setting.h +++ b/services/include/peruser_setting.h @@ -25,49 +25,49 @@ namespace OHOS { namespace MiscServices { -class PerUserSetting { -public: - explicit PerUserSetting(int32_t userId); + class PerUserSetting { + public: + explicit PerUserSetting(int32_t userId); - ~PerUserSetting(); + ~PerUserSetting(); - void Initialize(); - int32_t GetUserState(); - InputMethodProperty* GetCurrentInputMethod(); - InputMethodProperty* GetSecurityInputMethod(); - InputMethodProperty* GetNextInputMethod(); - InputMethodSetting* GetInputMethodSetting(); - InputMethodProperty* GetInputMethodProperty(const std::u16string& imeId); + void Initialize(); + int32_t GetUserState(); + InputMethodProperty* GetCurrentInputMethod(); + InputMethodProperty* GetSecurityInputMethod(); + InputMethodProperty* GetNextInputMethod(); + InputMethodSetting* GetInputMethodSetting(); + InputMethodProperty* GetInputMethodProperty(const std::u16string& imeId); - int32_t OnPackageAdded(std::u16string& packageName, bool* isSecurityIme = nullptr); - int32_t OnPackageRemoved(std::u16string& packageName, bool* isSecurityIme = nullptr); - int32_t OnSettingChanged(const std::u16string& key, const std::u16string& value); - void OnAdvanceToNext(); - void OnUserLocked(); - void Dump(int32_t fd); + int32_t OnPackageAdded(std::u16string& packageName, bool* isSecurityIme = nullptr); + int32_t OnPackageRemoved(std::u16string& packageName, bool* isSecurityIme = nullptr); + int32_t OnSettingChanged(const std::u16string& key, const std::u16string& value); + void OnAdvanceToNext(); + void OnUserLocked(); + void Dump(int32_t fd); - int32_t ListInputMethodEnabled(std::vector *properties); - int32_t ListInputMethod(std::vector *properties); - int32_t ListKeyboardType(const std::u16string& imeId, std::vector *types); + int32_t ListInputMethodEnabled(std::vector *properties); + int32_t ListInputMethod(std::vector *properties); + int32_t ListKeyboardType(const std::u16string& imeId, std::vector *types); - static bool CheckIfSecurityIme(const InputMethodProperty& property); + static bool CheckIfSecurityIme(const InputMethodProperty& property); -private: - int32_t userId_; //!< the id of the user to whom the object is linking - int32_t userState; //!< the state of the user to whom the object is linking - 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 + private: + int32_t userId_; // the id of the user to whom the object is linking + int32_t userState; // the state of the user to whom the object is linking + 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 - PerUserSetting(const PerUserSetting&); - PerUserSetting& operator= (const PerUserSetting&); - PerUserSetting(const PerUserSetting&&); - PerUserSetting& operator= (const PerUserSetting&&); - void InitInputMethodSetting(); - void ResetCurrentInputMethod(); - std::u16string GetKeyboardTypeLanguage(const InputMethodProperty* property, int32_t hashCode); - std::u16string GetImeId(const std::u16string& packageName); -}; + PerUserSetting(const PerUserSetting&); + PerUserSetting& operator= (const PerUserSetting&); + PerUserSetting(const PerUserSetting&&); + PerUserSetting& operator= (const PerUserSetting&&); + void InitInputMethodSetting(); + void ResetCurrentInputMethod(); + std::u16string GetKeyboardTypeLanguage(const InputMethodProperty* property, int32_t hashCode); + std::u16string GetImeId(const std::u16string& packageName); + }; } } #endif // FM_IMMS_PROJECT_PERUSERSETTING_H diff --git a/services/include/platform.h b/services/include/platform.h index 0ea58d186fc789511ad1a6487584cf9317ca620d..2799fb86ce4066945e75dfb7e7d0d0e974b3c539 100644 --- a/services/include/platform.h +++ b/services/include/platform.h @@ -28,18 +28,18 @@ namespace OHOS { namespace MiscServices { - - class Platform { public: static Platform* Instance(); void SetPlatform(const sptr& platformApi); - sptr BindInputMethodService(int userId, const std::u16string& packageName, const std::u16string& intention); + sptr BindInputMethodService(int userId, const std::u16string& packageName, + const std::u16string& intention); int UnbindInputMethodService(int userId, const std::u16string& packageName); sptr CreateWindowToken(int userId, int displayId, const std::u16string& packageName); int DestroyWindowToken(int userId, const std::u16string& packageName); - int ListInputMethod(int userId, std::vector* inputMethodProperties); - int GetInputMethodProperty(int userId, const std::u16string& packageName, InputMethodProperty* inputMethodProperty); + int ListInputMethod(int userId, std::vector* properties); + int GetInputMethodProperty(int userId, const std::u16string& packageName, + InputMethodProperty* inputMethodProperty); int GetInputMethodSetting(int userId, InputMethodSetting* inputMethodSetting); int SetInputMethodSetting(int userId, const InputMethodSetting& inputMethodSetting); bool CheckPhysicalKeyboard(); diff --git a/services/include/platform_callback_stub.h b/services/include/platform_callback_stub.h index 5a9b33ff89237db1ef62bc7410dd7202af406b1d..504f1d6a57b90021b1293048d0d8842154c00422 100644 --- a/services/include/platform_callback_stub.h +++ b/services/include/platform_callback_stub.h @@ -24,13 +24,13 @@ namespace OHOS { namespace MiscServices { - class PlatformCallbackStub : public IRemoteStub { public: PlatformCallbackStub(); ~PlatformCallbackStub(); - virtual int OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) 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; }; diff --git a/services/include/utils.h b/services/include/utils.h index 33365d65dd2f62df213ac0d441a5750713de0020..4e24b67405131d8e85e867854b7d8cc06db29123 100644 --- a/services/include/utils.h +++ b/services/include/utils.h @@ -25,15 +25,15 @@ namespace OHOS { namespace MiscServices { -class Utils { - public: - static std::string to_utf8( std::u16string str16 ) { - return std::wstring_convert< std::codecvt_utf8_utf16, char16_t >{}.to_bytes(str16); - } - static std::u16string to_utf16( std::string str ) { - return std::wstring_convert< std::codecvt_utf8_utf16, char16_t >{}.from_bytes(str); - } -}; + 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); + } + }; } } diff --git a/services/src/global.cpp b/services/src/global.cpp index 06440da07bcc05d9a9a6a6ef4284ed4a90fdadb3..fa5ba8c7876fc44f2c4c1fbbf4fb9a6fe91480b8 100644 --- a/services/src/global.cpp +++ b/services/src/global.cpp @@ -18,206 +18,204 @@ namespace OHOS { namespace MiscServices { - -void LogTimeStamp() -{ - struct timeval tv; - gettimeofday(&tv, nullptr); - struct tm nowTime; - localtime_r(&tv.tv_sec, &nowTime); - printf("%02d-%02d %02d:%02d:%02d.%03d\t", nowTime.tm_mon, nowTime.tm_mday, - nowTime.tm_hour, nowTime.tm_min, nowTime.tm_sec, (int)tv.tv_usec/1000); -} - -namespace ErrorCode { - const char* ToString(int errorCode) + void LogTimeStamp() { - switch (errorCode) { - case NO_ERROR: { - return "no error"; - } - case ERROR_NULL_POINTER: { - return "null pointer"; - } - case ERROR_BAD_PARAMETERS: { - return "bad parameters"; - } - case ERROR_SERVICE_START_FAILED: { - return "failed to start service"; - } - case ERROR_USER_NOT_STARTED: { - return "user has not started"; - } - case ERROR_USER_ALREADY_STARTED: { - return "user has already started"; - } - case ERROR_USER_NOT_UNLOCKED: { - return "user has not unlocked"; - } - case ERROR_USER_ALREADY_UNLOCKED: { - return "user has already unlocked"; - } - case ERROR_USER_NOT_LOCKED: { - return "user has not locked"; - } - case ERROR_IME_NOT_AVAILABLE: { - return "input method engine is not available"; - } - case ERROR_SECURITY_IME_NOT_AVAILABLE: { - return "security input method engine is not available"; - } - case ERROR_TOKEN_CREATE_FAILED: { - return "failed to create token"; - } - case ERROR_TOKEN_DESTROY_FAILED: { - return "failed to destroy token"; - } - case ERROR_IME_BIND_FAILED: { - return "failed to bind service"; - } - case ERROR_IME_UNBIND_FAILED: { - return "failed to unbind service"; - } - case ERROR_IME_START_FAILED: { - return "failed to start input"; - } - case ERROR_IME_STOP_FAILED: { - return "failed to stop input"; - } - case ERROR_KBD_SHOW_FAILED: { - return "failed to show keyboard"; - } - case ERROR_KBD_HIDE_FAILED: { - return "failed to hide keyboard"; - } - case ERROR_IME_NOT_STARTED: { - return "input method service has not started"; - } - case ERROR_KBD_IS_OCCUPIED: { - return "keyboard is showing by another client"; - } - case ERROR_KBD_IS_NOT_SHOWING: { - return "keyboard is not showing"; - } - case ERROR_IME_ALREADY_STARTED: { - return "input method service has already started"; - } - case ERROR_NOT_IME_PACKAGE: { - return "not an input method engine package"; - } - case ERROR_IME_PACKAGE_DUPLICATED: { - return "duplicated input method engine package"; - } - case ERROR_SETTING_SAME_VALUE: { - return "same setting value"; - } - case ERROR_NO_NEXT_IME: { - return "next input method engine is not available"; - } - case ERROR_CLIENTWINDOW_NOT_FOCUSED: { - return "input client window is not focused"; - } - case ERROR_CLIENT_NOT_WINDOW: { - return "input client is not from a valid window"; - } - case ERROR_REMOTE_IME_DIED: { - return "input method service died"; - } - case ERROR_RESTART_IME_FAILED: { - return "failed to restart input method service"; - } - case ERROR_REMOTE_CLIENT_DIED: { - return "input client died"; - } - case ERROR_CLIENT_DUPLICATED: { - return "duplicated client"; - } - case ERROR_CLIENT_NOT_FOUND: { - return "client is not found"; - } - case ERROR_STATUS_UNKNOWN_ERROR: { - return "unknown error"; - } - case ERROR_STATUS_NO_MEMORY: { - return "no memory"; - } - case ERROR_STATUS_INVALID_OPERATION: { - return "invalid operation"; - } - case ERROR_STATUS_BAD_VALUE: { - return "bad value"; - } - case ERROR_STATUS_BAD_TYPE: { - return "bad type"; - } - case ERROR_STATUS_NAME_NOT_FOUND: { - return "name not found"; - } - case ERROR_STATUS_PERMISSION_DENIED: { - return "permission denied"; - } - case ERROR_STATUS_NO_INIT: { - return "no init"; - } - case ERROR_STATUS_ALREADY_EXISTS: { - return "already exists"; - } - case ERROR_STATUS_DEAD_OBJECT: { - return "dead object"; - } - case ERROR_STATUS_FAILED_TRANSACTION: { - return "failed transaction"; - } - case ERROR_STATUS_BAD_INDEX: { - return "bad index"; - } - case ERROR_STATUS_NOT_ENOUGH_DATA: { - return "not enough data"; - } - case ERROR_STATUS_WOULD_BLOCK: { - return "would block"; - } - case ERROR_STATUS_TIMED_OUT: { - return "time out"; - } - case ERROR_STATUS_UNKNOWN_TRANSACTION: { - return "unknown transaction"; - } - case ERROR_STATUS_FDS_NOT_ALLOWED: { - return "fds not allowed"; - } - case ERROR_STATUS_UNEXPECTED_NULL: { - return "unexpected null"; - } - case ERROR_EX_ILLEGAL_ARGUMENT: { - return "illegal argument exception"; - } - case ERROR_EX_NULL_POINTER: { - return "null pointer exception"; - } - case ERROR_EX_ILLEGAL_STATE: { - return "illegal state exception"; - } - case ERROR_EX_NETWORK_MAIN_THREAD: { - return "network main thread exception"; - } - case ERROR_EX_UNSUPPORTED_OPERATION: { - return "unsupported operation exception"; - } - case ERROR_EX_SERVICE_SPECIFIC: { - return "service specific exception"; - } - case ERROR_EX_PARCELABLE: { - return "parcelable exception"; - } - default: { - return "error is out of definition"; - } - } - return "error is out of definition"; - }; -} + struct timeval tv; + gettimeofday(&tv, nullptr); + struct tm nowTime; + localtime_r(&tv.tv_sec, &nowTime); + printf("%02d-%02d %02d:%02d:%02d.%03d\t", nowTime.tm_mon, nowTime.tm_mday, + nowTime.tm_hour, nowTime.tm_min, nowTime.tm_sec, (int)tv.tv_usec/1000); + } + namespace ErrorCode { + const char* ToString(int errorCode) + { + switch (errorCode) { + case NO_ERROR: { + return "no error"; + } + case ERROR_NULL_POINTER: { + return "null pointer"; + } + case ERROR_BAD_PARAMETERS: { + return "bad parameters"; + } + case ERROR_SERVICE_START_FAILED: { + return "failed to start service"; + } + case ERROR_USER_NOT_STARTED: { + return "user has not started"; + } + case ERROR_USER_ALREADY_STARTED: { + return "user has already started"; + } + case ERROR_USER_NOT_UNLOCKED: { + return "user has not unlocked"; + } + case ERROR_USER_ALREADY_UNLOCKED: { + return "user has already unlocked"; + } + case ERROR_USER_NOT_LOCKED: { + return "user has not locked"; + } + case ERROR_IME_NOT_AVAILABLE: { + return "input method engine is not available"; + } + case ERROR_SECURITY_IME_NOT_AVAILABLE: { + return "security input method engine is not available"; + } + case ERROR_TOKEN_CREATE_FAILED: { + return "failed to create token"; + } + case ERROR_TOKEN_DESTROY_FAILED: { + return "failed to destroy token"; + } + case ERROR_IME_BIND_FAILED: { + return "failed to bind service"; + } + case ERROR_IME_UNBIND_FAILED: { + return "failed to unbind service"; + } + case ERROR_IME_START_FAILED: { + return "failed to start input"; + } + case ERROR_IME_STOP_FAILED: { + return "failed to stop input"; + } + case ERROR_KBD_SHOW_FAILED: { + return "failed to show keyboard"; + } + case ERROR_KBD_HIDE_FAILED: { + return "failed to hide keyboard"; + } + case ERROR_IME_NOT_STARTED: { + return "input method service has not started"; + } + case ERROR_KBD_IS_OCCUPIED: { + return "keyboard is showing by another client"; + } + case ERROR_KBD_IS_NOT_SHOWING: { + return "keyboard is not showing"; + } + case ERROR_IME_ALREADY_STARTED: { + return "input method service has already started"; + } + case ERROR_NOT_IME_PACKAGE: { + return "not an input method engine package"; + } + case ERROR_IME_PACKAGE_DUPLICATED: { + return "duplicated input method engine package"; + } + case ERROR_SETTING_SAME_VALUE: { + return "same setting value"; + } + case ERROR_NO_NEXT_IME: { + return "next input method engine is not available"; + } + case ERROR_CLIENTWINDOW_NOT_FOCUSED: { + return "input client window is not focused"; + } + case ERROR_CLIENT_NOT_WINDOW: { + return "input client is not from a valid window"; + } + case ERROR_REMOTE_IME_DIED: { + return "input method service died"; + } + case ERROR_RESTART_IME_FAILED: { + return "failed to restart input method service"; + } + case ERROR_REMOTE_CLIENT_DIED: { + return "input client died"; + } + case ERROR_CLIENT_DUPLICATED: { + return "duplicated client"; + } + case ERROR_CLIENT_NOT_FOUND: { + return "client is not found"; + } + case ERROR_STATUS_UNKNOWN_ERROR: { + return "unknown error"; + } + case ERROR_STATUS_NO_MEMORY: { + return "no memory"; + } + case ERROR_STATUS_INVALID_OPERATION: { + return "invalid operation"; + } + case ERROR_STATUS_BAD_VALUE: { + return "bad value"; + } + case ERROR_STATUS_BAD_TYPE: { + return "bad type"; + } + case ERROR_STATUS_NAME_NOT_FOUND: { + return "name not found"; + } + case ERROR_STATUS_PERMISSION_DENIED: { + return "permission denied"; + } + case ERROR_STATUS_NO_INIT: { + return "no init"; + } + case ERROR_STATUS_ALREADY_EXISTS: { + return "already exists"; + } + case ERROR_STATUS_DEAD_OBJECT: { + return "dead object"; + } + case ERROR_STATUS_FAILED_TRANSACTION: { + return "failed transaction"; + } + case ERROR_STATUS_BAD_INDEX: { + return "bad index"; + } + case ERROR_STATUS_NOT_ENOUGH_DATA: { + return "not enough data"; + } + case ERROR_STATUS_WOULD_BLOCK: { + return "would block"; + } + case ERROR_STATUS_TIMED_OUT: { + return "time out"; + } + case ERROR_STATUS_UNKNOWN_TRANSACTION: { + return "unknown transaction"; + } + case ERROR_STATUS_FDS_NOT_ALLOWED: { + return "fds not allowed"; + } + case ERROR_STATUS_UNEXPECTED_NULL: { + return "unexpected null"; + } + case ERROR_EX_ILLEGAL_ARGUMENT: { + return "illegal argument exception"; + } + case ERROR_EX_NULL_POINTER: { + return "null pointer exception"; + } + case ERROR_EX_ILLEGAL_STATE: { + return "illegal state exception"; + } + case ERROR_EX_NETWORK_MAIN_THREAD: { + return "network main thread exception"; + } + case ERROR_EX_UNSUPPORTED_OPERATION: { + return "unsupported operation exception"; + } + case ERROR_EX_SERVICE_SPECIFIC: { + return "service specific exception"; + } + case ERROR_EX_PARCELABLE: { + return "parcelable exception"; + } + default: { + return "error is out of definition"; + } + } + return "error is out of definition"; + }; + } } } diff --git a/services/src/input_attribute.cpp b/services/src/input_attribute.cpp index 9bba4f6b0110f47da7bb439d9a5043fee1c27a71..aee33ade0f5c48a30d3366ab3b07217034f9fbe2 100644 --- a/services/src/input_attribute.cpp +++ b/services/src/input_attribute.cpp @@ -17,89 +17,89 @@ namespace OHOS { namespace MiscServices { -/*! Constructor -*/ -InputAttribute::InputAttribute() : enterKeyType(0), inputOption(0) -{ -} + /*! Constructor + */ + InputAttribute::InputAttribute() : enterKeyType(0), inputOption(0) + { + } -/*! Constructor - \param attribute the source attribute copied to this instance -*/ -InputAttribute::InputAttribute(const InputAttribute& attribute) -{ - inputPattern = attribute.inputPattern; - enterKeyType = attribute.enterKeyType; - inputOption = attribute.inputOption; -} + /*! Constructor + \param attribute the source attribute copied to this instance + */ + InputAttribute::InputAttribute(const InputAttribute& attribute) + { + inputPattern = attribute.inputPattern; + enterKeyType = attribute.enterKeyType; + inputOption = attribute.inputOption; + } -/*! Destructor -*/ -InputAttribute::~InputAttribute() -{ -} + /*! Destructor + */ + InputAttribute::~InputAttribute() + { + } -/*! operator= - \param attribute the source attribute copied to this instance - \return return this -*/ -InputAttribute& InputAttribute::operator=(const InputAttribute& attribute) -{ - if (this == &attribute) { + /*! operator= + \param attribute the source attribute copied to this instance + \return return this + */ + InputAttribute& InputAttribute::operator=(const InputAttribute& attribute) + { + if (this == &attribute) { + return *this; + } + inputPattern = attribute.inputPattern; + enterKeyType = attribute.enterKeyType; + inputOption = attribute.inputOption; return *this; } - inputPattern = attribute.inputPattern; - enterKeyType = attribute.enterKeyType; - inputOption = attribute.inputOption; - return *this; -} -/*! Write InputAttribute to parcel - \param[out] parcel write the data of InputAttribute to this parcel returned to caller - \return ErrorCode::NO_ERROR - \return ErrorCode::ERROR_NULL_POINTER parcel is null -*/ -bool InputAttribute::Marshalling(OHOS::Parcel &parcel) const { - if (!(parcel.WriteInt32(inputPattern) - && parcel.WriteInt32(enterKeyType) - && parcel.WriteInt32(inputOption))) - return false; - return true; -} + /*! Write InputAttribute to parcel + \param[out] parcel write the data of InputAttribute to this parcel returned to caller + \return ErrorCode::NO_ERROR + \return ErrorCode::ERROR_NULL_POINTER parcel is null + */ + bool InputAttribute::Marshalling(OHOS::Parcel &parcel) const { + if (!(parcel.WriteInt32(inputPattern) + && parcel.WriteInt32(enterKeyType) + && parcel.WriteInt32(inputOption))) + return false; + return true; + } -/*! Read InputAttribute from parcel - \param parcel read the data of InputAttribute from this parcel - \return ErrorCode::NO_ERROR - \return ErrorCode::ERROR_NULL_POINTER parcel is null -*/ -InputAttribute* InputAttribute::Unmarshalling(OHOS::Parcel &parcel) { - auto info = new InputAttribute(); - info->inputPattern = parcel.ReadInt32(); - info->enterKeyType = parcel.ReadInt32(); - info->inputOption = parcel.ReadInt32(); - return info; -} + /*! Read InputAttribute from parcel + \param parcel read the data of InputAttribute from this parcel + \return ErrorCode::NO_ERROR + \return ErrorCode::ERROR_NULL_POINTER parcel is null + */ + InputAttribute* InputAttribute::Unmarshalling(OHOS::Parcel &parcel) { + auto info = new InputAttribute(); + info->inputPattern = parcel.ReadInt32(); + info->enterKeyType = parcel.ReadInt32(); + info->inputOption = parcel.ReadInt32(); + return info; + } -/*! Get the security flag - \return true - It's password EditView. The input method management service should start system - security input method engine for this view. - \return false - It's an normal view. -*/ -bool InputAttribute::GetSecurityFlag() -{ - if (inputPattern == PATTERN_PASSWORD) { - return true; + /*! Get the security flag + \return true - It's password EditView. The input method management service should start system + security input method engine for this view. + \return false - It's an normal view. + */ + bool InputAttribute::GetSecurityFlag() + { + if (inputPattern == PATTERN_PASSWORD) { + return true; + } + return false; } - return false; -} -/*! Set input pattern. - \n It's added for Unit test of PerUserSession - \param pattern PATTERN_PASSWORD or 0. -*/ -void InputAttribute::SetInputPattern(int32_t pattern) -{ - inputPattern = pattern; -} + /*! Set input pattern. + \n It's added for Unit test of PerUserSession + \param pattern PATTERN_PASSWORD or 0. + */ + void InputAttribute::SetInputPattern(int32_t pattern) + { + inputPattern = pattern; + } } } diff --git a/services/src/input_channel.cpp b/services/src/input_channel.cpp index 60eb4032695736519f9ecd9a702843a7d5bcc6a2..88823c8102db2cc2c2c6ca3d05b662aba80d916d 100644 --- a/services/src/input_channel.cpp +++ b/services/src/input_channel.cpp @@ -19,42 +19,42 @@ namespace OHOS { namespace MiscServices { -/*! Constructor -*/ -InputChannel::InputChannel() -{ -} + /*! Constructor + */ + InputChannel::InputChannel() + { + } -/*! Destructor -*/ -InputChannel::~InputChannel() -{ -} + /*! Destructor + */ + InputChannel::~InputChannel() + { + } -/*! Write InputChannel to parcel - \param[out] parcel the data of InputChannel is written to this parcel returned to caller - \return ErrorCode::NO_ERROR - \return ErrorCode::ERROR_NULL_POINTER parcel is null -*/ -bool InputChannel::Marshalling(Parcel &parcel) const { - parcel.ParseFrom(inputChannelParcel.GetData(), inputChannelParcel.GetDataSize()); - return NO_ERROR; -} + /*! Write InputChannel to parcel + \param[out] parcel the data of InputChannel is written to this parcel returned to caller + \return ErrorCode::NO_ERROR + \return ErrorCode::ERROR_NULL_POINTER parcel is null + */ + bool InputChannel::Marshalling(Parcel &parcel) const { + parcel.ParseFrom(inputChannelParcel.GetData(), inputChannelParcel.GetDataSize()); + return NO_ERROR; + } -/*! Get InputChannel from parcel - \param parcel get the data of InputChannel from this parcel - \return ErrorCode::NO_ERROR - \return ErrorCode::ERROR_NULL_POINTER parcel is null -*/ -InputChannel* InputChannel::Unmarshalling(Parcel &parcel) { - auto inputChannel = new InputChannel(); - inputChannel->inputChannelParcel.RewindRead(0); - inputChannel->inputChannelParcel.ParseFrom(parcel.GetData(), parcel.GetDataSize()); - inputChannel->inputChannelParcel.RewindRead(0); + /*! Get InputChannel from parcel + \param parcel get the data of InputChannel from this parcel + \return ErrorCode::NO_ERROR + \return ErrorCode::ERROR_NULL_POINTER parcel is null + */ + InputChannel* InputChannel::Unmarshalling(Parcel &parcel) { + auto inputChannel = new InputChannel(); + inputChannel->inputChannelParcel.RewindRead(0); + inputChannel->inputChannelParcel.ParseFrom(parcel.GetData(), parcel.GetDataSize()); + inputChannel->inputChannelParcel.RewindRead(0); - inputChannel->name = inputChannel->inputChannelParcel.ReadString16(); - inputChannel->inputChannelParcel.RewindRead(0); - return inputChannel; -} + inputChannel->name = inputChannel->inputChannelParcel.ReadString16(); + inputChannel->inputChannelParcel.RewindRead(0); + return inputChannel; + } } } diff --git a/services/src/input_control_channel_proxy.cpp b/services/src/input_control_channel_proxy.cpp index a5f0181c997d01d3aef0df934871aae0e3a8332c..22c8396055551705610e74f6a4b7577dbe23ed73 100644 --- a/services/src/input_control_channel_proxy.cpp +++ b/services/src/input_control_channel_proxy.cpp @@ -24,7 +24,6 @@ #include "i_input_method_agent.h" #include "input_control_channel_proxy.h" - /*! \class InputControlChannelProxy \brief The proxy implementation of IInputControlChannel @@ -32,7 +31,8 @@ */ namespace OHOS { namespace MiscServices { - InputControlChannelProxy::InputControlChannelProxy(const sptr &impl) : IRemoteProxy(impl) { + InputControlChannelProxy::InputControlChannelProxy(const sptr &impl) + : IRemoteProxy(impl) { } InputControlChannelProxy::~InputControlChannelProxy() diff --git a/services/src/input_control_channel_stub.cpp b/services/src/input_control_channel_stub.cpp index e86661b1a518069cc41afa161048243d372aba8f..0c943558eaf2c8302f23f2540bd54216d71a475b 100644 --- a/services/src/input_control_channel_stub.cpp +++ b/services/src/input_control_channel_stub.cpp @@ -45,7 +45,8 @@ namespace OHOS { \param flags the flags of handling transaction \return int32_t */ - int32_t InputControlChannelStub::OnRemoteRequest(uint32_t code, MessageParcel& data, MessageParcel& reply, MessageOption& option) + int32_t InputControlChannelStub::OnRemoteRequest(uint32_t code, MessageParcel& data, + MessageParcel& reply, MessageOption& option) { IMSA_HILOGI("InputControlChannelStub::OnRemoteRequest code = %{public}u", code); auto descriptorToken = data.ReadInterfaceToken(); diff --git a/services/src/input_method_ability_connection_stub.cpp b/services/src/input_method_ability_connection_stub.cpp index 97f65fa6276ca719911013dc9f5b869e9aabb4b4..4bc709f98bfc5316aac70547146d8baf602975b0 100644 --- a/services/src/input_method_ability_connection_stub.cpp +++ b/services/src/input_method_ability_connection_stub.cpp @@ -17,7 +17,6 @@ #include "message_parcel.h" #include "message.h" - namespace OHOS { namespace MiscServices { InputMethodAbilityConnectionStub::InputMethodAbilityConnectionStub(const int index){ @@ -28,7 +27,8 @@ namespace OHOS { } - void InputMethodAbilityConnectionStub::OnAbilityConnectDone(const AppExecFwk::ElementName &element, const sptr &remoteObject, int resultCode){ + void InputMethodAbilityConnectionStub::OnAbilityConnectDone(const AppExecFwk::ElementName &element, + const sptr &remoteObject, int resultCode){ IMSA_HILOGE("ConnectAbility: OnAbilityConnectDone."); if(messageHandler != nullptr){ MessageParcel* data = new MessageParcel(); @@ -40,7 +40,8 @@ namespace OHOS { } } - void InputMethodAbilityConnectionStub::OnAbilityDisconnectDone(const AppExecFwk::ElementName &element, int resultCode) { + void InputMethodAbilityConnectionStub::OnAbilityDisconnectDone(const AppExecFwk::ElementName &element, + int resultCode) { IMSA_HILOGE("ConnectAbility: OnAbilityDisconnectDone."); if(messageHandler != nullptr){ MessageParcel* data = new MessageParcel(); diff --git a/services/src/input_method_agent_proxy.cpp b/services/src/input_method_agent_proxy.cpp index 7a2de408c1c42215bbc2bae50ca4b2df3a727646..80a35550f55660eefd2d5a7042f1d966ca9f98e2 100644 --- a/services/src/input_method_agent_proxy.cpp +++ b/services/src/input_method_agent_proxy.cpp @@ -42,9 +42,7 @@ namespace OHOS { (void)status; return NO_ERROR; } - }; - } } diff --git a/services/src/input_method_property.cpp b/services/src/input_method_property.cpp index 78ff9e79a8edfe5a621ffc6cfd38951ef63022e6..1c8bbb843ad002cc64cb860bf5a0d4d4d43f95c8 100644 --- a/services/src/input_method_property.cpp +++ b/services/src/input_method_property.cpp @@ -17,114 +17,110 @@ namespace OHOS { namespace MiscServices { -using namespace std; -/*! Constructor -*/ -InputMethodProperty::InputMethodProperty() -{ -} + using namespace std; + /*! Constructor + */ + InputMethodProperty::InputMethodProperty() + { + } -/*! Destructor -*/ -InputMethodProperty::~InputMethodProperty() -{ - for(int32_t i=0; i<(int32_t)mTypes.size(); i++) { - delete mTypes[i]; + /*! Destructor + */ + InputMethodProperty::~InputMethodProperty() + { + for(int32_t i=0; i<(int32_t)mTypes.size(); i++) { + delete mTypes[i]; + } + mTypes.clear(); } - mTypes.clear(); -} -/*! Constructor -\param property the source property will be copied to this instance. -*/ -InputMethodProperty::InputMethodProperty(const InputMethodProperty& property) -{ - mImeId = property.mImeId; - mPackageName = property.mPackageName; - mAbilityName = property.mAbilityName; - mConfigurationPage = property.mConfigurationPage; - isSystemIme = property.isSystemIme; - mDefaultImeId = property.mDefaultImeId; + /*! Constructor + \param property the source property will be copied to this instance. + */ + InputMethodProperty::InputMethodProperty(const InputMethodProperty& property) + { + mImeId = property.mImeId; + mPackageName = property.mPackageName; + mAbilityName = property.mAbilityName; + mConfigurationPage = property.mConfigurationPage; + isSystemIme = property.isSystemIme; + mDefaultImeId = property.mDefaultImeId; - for(int i = 0; i < (int)mTypes.size(); i++) { - KeyboardType* type = new KeyboardType(*property.mTypes[i]); - mTypes.push_back(type); + for(int i = 0; i < (int)mTypes.size(); i++) { + KeyboardType* type = new KeyboardType(*property.mTypes[i]); + mTypes.push_back(type); + } } -} -/*! operator= -\param property the source property will be copied to this instance. -\return return this -*/ -InputMethodProperty& InputMethodProperty::operator=(const InputMethodProperty& property) -{ - if (this == &property) { - return *this; - } - mImeId = property.mImeId; - mPackageName = property.mPackageName; - mAbilityName = property.mAbilityName; - mConfigurationPage = property.mConfigurationPage; - isSystemIme = property.isSystemIme; - mDefaultImeId = property.mDefaultImeId; + /*! operator= + \param property the source property will be copied to this instance. + \return return this + */ + InputMethodProperty& InputMethodProperty::operator=(const InputMethodProperty& property) + { + if (this == &property) { + return *this; + } + mImeId = property.mImeId; + mPackageName = property.mPackageName; + mAbilityName = property.mAbilityName; + mConfigurationPage = property.mConfigurationPage; + isSystemIme = property.isSystemIme; + mDefaultImeId = property.mDefaultImeId; - for(int i = 0; i < (int)mTypes.size(); i++) { - KeyboardType* type = new KeyboardType(*property.mTypes[i]); - mTypes.push_back(type); + for(int i = 0; i < (int)mTypes.size(); i++) { + KeyboardType* type = new KeyboardType(*property.mTypes[i]); + mTypes.push_back(type); + } + return *this; } - return *this; -} -/*! Write InputMethodProperty to parcel -\param[out] parcel the information is written to this parcel returned to caller -\return ErrorCode::NO_ERROR -\return ErrorCode::ERROR_NULL_POINTER parcel is null -*/ -bool InputMethodProperty::Marshalling(Parcel &parcel) const -{ - if (!(parcel.WriteString16(mImeId) - &&parcel.WriteString16(mPackageName) - &&parcel.WriteString16(mAbilityName) - &&parcel.WriteString16(mConfigurationPage) - &&parcel.WriteBool(isSystemIme) - &&parcel.WriteInt32(mDefaultImeId))) - return false; - int32_t size = (int32_t)mTypes.size(); - parcel.WriteInt32(size); - if (size == 0) + /*! Write InputMethodProperty to parcel + \param[out] parcel the information is written to this parcel returned to caller + \return ErrorCode::NO_ERROR + \return ErrorCode::ERROR_NULL_POINTER parcel is null + */ + bool InputMethodProperty::Marshalling(Parcel &parcel) const + { + if (!(parcel.WriteString16(mImeId) + &&parcel.WriteString16(mPackageName) + &&parcel.WriteString16(mAbilityName) + &&parcel.WriteString16(mConfigurationPage) + &&parcel.WriteBool(isSystemIme) + &&parcel.WriteInt32(mDefaultImeId))) + return false; + int32_t size = (int32_t)mTypes.size(); + parcel.WriteInt32(size); + if (size == 0) + return true; + for(int i=0; imImeId = parcel.ReadString16(); - info->mPackageName = parcel.ReadString16(); - info->mAbilityName = parcel.ReadString16(); - info->mConfigurationPage = parcel.ReadString16(); - info->isSystemIme = parcel.ReadBool(); - info->mDefaultImeId = parcel.ReadInt32(); + /*! Get InputMethodProperty from parcel + \param parcel read InputMethodProperty from this parcel + \return ErrorCode::NO_ERROR + \return ErrorCode::ERROR_NULL_POINTER parcel is null + */ + InputMethodProperty* InputMethodProperty::Unmarshalling(Parcel &parcel) + { + auto info = new InputMethodProperty(); + info->mImeId = parcel.ReadString16(); + info->mPackageName = parcel.ReadString16(); + info->mAbilityName = parcel.ReadString16(); + info->mConfigurationPage = parcel.ReadString16(); + info->isSystemIme = parcel.ReadBool(); + info->mDefaultImeId = parcel.ReadInt32(); - int32_t size = parcel.ReadInt32(); - if (size == 0) + int32_t size = parcel.ReadInt32(); + if (size == 0) + return info; + for (int i =0; i < size; i++) { + info->mTypes.push_back(parcel.ReadParcelable()); + } return info; - for (int i =0; i < size; i++) { - info->mTypes.push_back(parcel.ReadParcelable()); } - return info; -} } -} - - - - +} \ No newline at end of file diff --git a/services/src/input_method_system_ability.cpp b/services/src/input_method_system_ability.cpp index e9b974999b4c0118fb78220481c5de62f083f9b1..6125c198071e7832295e341befee2d206562ca70 100644 --- a/services/src/input_method_system_ability.cpp +++ b/services/src/input_method_system_ability.cpp @@ -13,7 +13,6 @@ * limitations under the License. */ - #include "input_method_system_ability.h" #include "message_handler.h" #include "system_ability.h" @@ -24,840 +23,836 @@ namespace OHOS { namespace MiscServices { -using namespace MessageID; - -REGISTER_SYSTEM_ABILITY_BY_ID(InputMethodSystemAbility, INPUT_METHOD_SYSTEM_ABILITY_ID, true); -const std::int32_t INIT_INTERVAL = 10000L; -std::mutex InputMethodSystemAbility::instanceLock_; -sptr InputMethodSystemAbility::instance_; - -std::shared_ptr InputMethodSystemAbility::serviceHandler_; - -/*! Constructor -*/ -InputMethodSystemAbility::InputMethodSystemAbility(int32_t systemAbilityId, bool runOnCreate) -: SystemAbility(systemAbilityId, runOnCreate), state_(ServiceRunningState::STATE_NOT_START) -{ - -} - - -/*! Constructor -*/ -InputMethodSystemAbility::InputMethodSystemAbility() : state_(ServiceRunningState::STATE_NOT_START) -{ -} - -/*! Destructor -*/ -InputMethodSystemAbility::~InputMethodSystemAbility() -{ - if (workThreadHandler.joinable()) { - workThreadHandler.join(); - } + using namespace MessageID; + REGISTER_SYSTEM_ABILITY_BY_ID(InputMethodSystemAbility, INPUT_METHOD_SYSTEM_ABILITY_ID, true); + const std::int32_t INIT_INTERVAL = 10000L; + std::mutex InputMethodSystemAbility::instanceLock_; + sptr InputMethodSystemAbility::instance_; + + std::shared_ptr InputMethodSystemAbility::serviceHandler_; + + /** + * constructor + * @param systemAbilityId + * @param runOnCreate + */ + InputMethodSystemAbility::InputMethodSystemAbility(int32_t systemAbilityId, bool runOnCreate) + : SystemAbility(systemAbilityId, runOnCreate), state_(ServiceRunningState::STATE_NOT_START) + { + } + + /** + * constructor + */ + InputMethodSystemAbility::InputMethodSystemAbility() : state_(ServiceRunningState::STATE_NOT_START) + { + } + + /** + * Destructor + */ + InputMethodSystemAbility::~InputMethodSystemAbility() + { + if (workThreadHandler.joinable()) { + workThreadHandler.join(); + } - std::map::const_iterator it; - for(it=userSessions.cbegin(); it!=userSessions.cend();) { - PerUserSession *session = it->second; - it = userSessions.erase(it); - delete session; - } - userSessions.clear(); - std::map::const_iterator it1; - for(it1=userSettings.cbegin(); it1!=userSettings.cend();) { - PerUserSetting *setting = it1->second; - it1 = userSettings.erase(it1); - delete setting; - } - userSettings.clear(); - std::map::const_iterator it2; - for(it2=msgHandlers.cbegin(); it2!=msgHandlers.cend();) { - MessageHandler *handler = it2->second; - it2 = msgHandlers.erase(it2); - delete handler; + std::map::const_iterator it; + for(it=userSessions.cbegin(); it!=userSessions.cend();) { + PerUserSession *session = it->second; + it = userSessions.erase(it); + delete session; + } + userSessions.clear(); + std::map::const_iterator it1; + for(it1=userSettings.cbegin(); it1!=userSettings.cend();) { + PerUserSetting *setting = it1->second; + it1 = userSettings.erase(it1); + delete setting; + } + userSettings.clear(); + std::map::const_iterator it2; + for(it2=msgHandlers.cbegin(); it2!=msgHandlers.cend();) { + MessageHandler *handler = it2->second; + it2 = msgHandlers.erase(it2); + delete handler; + } + msgHandlers.clear(); } - msgHandlers.clear(); -} -sptr InputMethodSystemAbility::GetInstance() -{ - if (instance_ == nullptr) { - std::lock_guard autoLock(instanceLock_); + sptr InputMethodSystemAbility::GetInstance() + { if (instance_ == nullptr) { - instance_ = new InputMethodSystemAbility; + std::lock_guard autoLock(instanceLock_); + if (instance_ == nullptr) { + instance_ = new InputMethodSystemAbility; + } } + return instance_; } - return instance_; -} -void InputMethodSystemAbility::OnStart() -{ - IMSA_HILOGI("Enter OnStart."); - if (state_ == ServiceRunningState::STATE_RUNNING) { - IMSA_HILOGI("ImsaService is already running."); + void InputMethodSystemAbility::OnStart() + { + IMSA_HILOGI("Enter OnStart."); + if (state_ == ServiceRunningState::STATE_RUNNING) { + IMSA_HILOGI("ImsaService is already running."); + return; + } + Initialize(); + InitServiceHandler(); + if (Init() != ErrorCode::NO_ERROR) { + auto callback = [=]() { Init(); }; + serviceHandler_->PostTask(callback, INIT_INTERVAL); + IMSA_HILOGE("Init failed. Try again 10s later"); + return; + } + + IMSA_HILOGI("Start ImsaService ErrorCode::NO_ERROR."); return; } - Initialize(); - InitServiceHandler(); - if (Init() != ErrorCode::NO_ERROR) { - auto callback = [=]() { Init(); }; - serviceHandler_->PostTask(callback, INIT_INTERVAL); - IMSA_HILOGE("Init failed. Try again 10s later"); - return; + + int32_t InputMethodSystemAbility::Init() + { + bool ret = Publish(InputMethodSystemAbility::GetInstance()); + if (!ret) { + IMSA_HILOGE("Publish failed."); + return -1; + } + IMSA_HILOGI("Publish ErrorCode::NO_ERROR."); + state_ = ServiceRunningState::STATE_RUNNING; + return ErrorCode::NO_ERROR; } - IMSA_HILOGI("Start ImsaService ErrorCode::NO_ERROR."); - return; -} + void InputMethodSystemAbility::OnStop() + { + IMSA_HILOGI("OnStop started."); + if (state_ != ServiceRunningState::STATE_RUNNING) { + return; + } + serviceHandler_ = nullptr; -int32_t InputMethodSystemAbility::Init() -{ - bool ret = Publish(InputMethodSystemAbility::GetInstance()); - if (!ret) { - IMSA_HILOGE("Publish failed."); - return -1; + state_ = ServiceRunningState::STATE_NOT_START; + IMSA_HILOGI("OnStop end."); } - IMSA_HILOGI("Publish ErrorCode::NO_ERROR."); - state_ = ServiceRunningState::STATE_RUNNING; - return ErrorCode::NO_ERROR; -} -void InputMethodSystemAbility::OnStop() -{ - IMSA_HILOGI("OnStop started."); - if (state_ != ServiceRunningState::STATE_RUNNING) { - return; + void InputMethodSystemAbility::InitServiceHandler() + { + IMSA_HILOGI("InitServiceHandler started."); + if (serviceHandler_ != nullptr) { + IMSA_HILOGI("InitServiceHandler already init."); + return; + } + std::shared_ptr runner = AppExecFwk::EventRunner::Create("InputMethodSystemAbility"); + serviceHandler_ = std::make_shared(runner); + + IMSA_HILOGI("InitServiceHandler succeeded."); + } + + /*! Initialization of Input method management service + \n It's called after the service starts, before any transaction. + */ + void InputMethodSystemAbility::Initialize() + { + IMSA_HILOGI("InputMethodSystemAbility::Initialize"); + // init work thread to handle the messages + workThreadHandler = std::thread([this] { + WorkThread(); + }); + PerUserSetting* setting=new PerUserSetting(0); + PerUserSession* session=new PerUserSession(0); + userSettings.insert(std::pair(0,setting)); + userSessions.insert(std::pair(0,session)); + + setting->Initialize(); + } + + /*! Get the state of user + \n This API is added for unit test. + \param userID the id of given user + \return user state can be one of the values of UserState + */ + int32_t InputMethodSystemAbility::GetUserState(int32_t userId) + { + PerUserSetting *setting = GetUserSetting(userId); + if (setting == nullptr) { + return UserState::USER_STATE_NOT_AVAILABLE; + } + return setting->GetUserState(); + } + + /*! Handle the transaction from the remote binder + \n Run in binder thread + \param code transaction code number + \param data the params from remote binder + \param[out] reply the result of the transaction replied to the remote binder + \param flags the flags of handling transaction + \return int32_t + */ + int32_t InputMethodSystemAbility::OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, + MessageOption &option) + { + return InputMethodSystemAbilityStub::OnRemoteRequest(code, data, reply, option); + } + + /*! Get the display mode of keyboard + \n Run in binder thread + \param[out] retMode the display mode returned to the caller + \return ErrorCode::NO_ERROR no error + \return ErrorCode::ERROR_USER_NOT_UNLOCKED user not unlocked + */ + int32_t InputMethodSystemAbility::getDisplayMode(int32_t *retMode) + { + int32_t uid = IPCSkeleton::GetCallingUid(); + int32_t userId = getUserId(uid); + PerUserSetting* setting = GetUserSetting(userId); + if (setting == nullptr || setting->GetUserState() != UserState::USER_STATE_UNLOCKED) { + IMSA_HILOGE("%s %d\n", ErrorCode::ToString(ErrorCode::ERROR_USER_NOT_UNLOCKED), userId); + return ErrorCode::ERROR_USER_NOT_UNLOCKED; + } + *retMode = GetUserSession(userId)->GetDisplayMode(); + return ErrorCode::NO_ERROR; } - serviceHandler_ = nullptr; - state_ = ServiceRunningState::STATE_NOT_START; - IMSA_HILOGI("OnStop end."); -} + /*! Get the window height of the current keyboard + \n Run in binder thread + \param[out] retHeight the window height returned to the caller + \return ErrorCode::NO_ERROR no error + \return ErrorCode::ERROR_USER_NOT_UNLOCKED user not unlocked + */ + int32_t InputMethodSystemAbility::getKeyboardWindowHeight(int32_t *retHeight) + { + int32_t uid = IPCSkeleton::GetCallingUid(); + int32_t userId = getUserId(uid); + PerUserSetting* setting = GetUserSetting(userId); + if (setting == nullptr || setting->GetUserState() != UserState::USER_STATE_UNLOCKED) { + IMSA_HILOGE("%s %d\n", ErrorCode::ToString(ErrorCode::ERROR_USER_NOT_UNLOCKED), userId); + return ErrorCode::ERROR_USER_NOT_UNLOCKED; + } -void InputMethodSystemAbility::InitServiceHandler() -{ - IMSA_HILOGI("InitServiceHandler started."); - if (serviceHandler_ != nullptr) { - IMSA_HILOGI("InitServiceHandler already init."); - return; + int32_t ret = GetUserSession(userId)->GetKeyboardWindowHeight(retHeight); + if (ret != ErrorCode::NO_ERROR) { + IMSA_HILOGE("Failed to get keyboard window height. ErrorCode=%d\n", ret); + } + return ret; } - std::shared_ptr runner = AppExecFwk::EventRunner::Create("InputMethodSystemAbility"); - serviceHandler_ = std::make_shared(runner); - - IMSA_HILOGI("InitServiceHandler succeeded."); -} - -/*! Initialization of Input method management service -\n It's called after the service starts, before any transaction. -*/ -void InputMethodSystemAbility::Initialize() -{ - IMSA_HILOGI("InputMethodSystemAbility::Initialize"); - // init work thread to handle the messages - workThreadHandler = std::thread([this] { - WorkThread(); - }); - PerUserSetting* setting=new PerUserSetting(0); - PerUserSession* session=new PerUserSession(0); - userSettings.insert(std::pair(0,setting)); - userSessions.insert(std::pair(0,session)); - - setting->Initialize(); -} - -/*! Get the state of user -\n This API is added for unit test. -\param userID the id of given user -\return user state can be one of the values of UserState -*/ -int32_t InputMethodSystemAbility::GetUserState(int32_t userId) -{ - PerUserSetting *setting = GetUserSetting(userId); - if (setting == nullptr) { - return UserState::USER_STATE_NOT_AVAILABLE; - } - return setting->GetUserState(); -} - -/*! Handle the transaction from the remote binder -\n Run in binder thread -\param code transaction code number -\param data the params from remote binder -\param[out] reply the result of the transaction replied to the remote binder -\param flags the flags of handling transaction -\return int32_t -*/ -int32_t InputMethodSystemAbility::OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, - MessageOption &option) -{ - return InputMethodSystemAbilityStub::OnRemoteRequest(code, data, reply, option); -} - -/*! Get the display mode of keyboard -\n Run in binder thread -\param[out] retMode the display mode returned to the caller -\return ErrorCode::NO_ERROR no error -\return ErrorCode::ERROR_USER_NOT_UNLOCKED user not unlocked -*/ -int32_t InputMethodSystemAbility::getDisplayMode(int32_t *retMode) -{ - int32_t uid = IPCSkeleton::GetCallingUid(); - int32_t userId = getUserId(uid); - PerUserSetting* setting = GetUserSetting(userId); - if (setting == nullptr || setting->GetUserState() != UserState::USER_STATE_UNLOCKED) { - IMSA_HILOGE("%s %d\n", ErrorCode::ToString(ErrorCode::ERROR_USER_NOT_UNLOCKED), userId); - return ErrorCode::ERROR_USER_NOT_UNLOCKED; - } - *retMode = GetUserSession(userId)->GetDisplayMode(); - return ErrorCode::NO_ERROR; -} - -/*! Get the window height of the current keyboard -\n Run in binder thread -\param[out] retHeight the window height returned to the caller -\return ErrorCode::NO_ERROR no error -\return ErrorCode::ERROR_USER_NOT_UNLOCKED user not unlocked -*/ -int32_t InputMethodSystemAbility::getKeyboardWindowHeight(int32_t *retHeight) -{ - int32_t uid = IPCSkeleton::GetCallingUid(); - int32_t userId = getUserId(uid); - PerUserSetting* setting = GetUserSetting(userId); - if (setting == nullptr || setting->GetUserState() != UserState::USER_STATE_UNLOCKED) { - IMSA_HILOGE("%s %d\n", ErrorCode::ToString(ErrorCode::ERROR_USER_NOT_UNLOCKED), userId); - return ErrorCode::ERROR_USER_NOT_UNLOCKED; - } - - int32_t ret = GetUserSession(userId)->GetKeyboardWindowHeight(retHeight); - if (ret != ErrorCode::NO_ERROR) { - IMSA_HILOGE("Failed to get keyboard window height. ErrorCode=%d\n", ret); - } - return ret; -} -/*! Get the current keyboard type -\n Run in binder thread -\param[out] retType the current keyboard type returned to the caller -\return ErrorCode::NO_ERROR no error -\return ErrorCode::ERROR_USER_NOT_UNLOCKED user not unlocked -\return ErrorCode::ERROR_NULL_POINTER current keyboard type is null -*/ -int32_t InputMethodSystemAbility::getCurrentKeyboardType(KeyboardType* retType) -{ - int32_t uid = IPCSkeleton::GetCallingUid(); - int32_t userId = getUserId(uid); - PerUserSetting* setting = GetUserSetting(userId); - if (setting == nullptr || setting->GetUserState() != UserState::USER_STATE_UNLOCKED) { - IMSA_HILOGE("%s %d\n", ErrorCode::ToString(ErrorCode::ERROR_USER_NOT_UNLOCKED), userId); - return ErrorCode::ERROR_USER_NOT_UNLOCKED; - } - - KeyboardType* type = GetUserSession(userId)->GetCurrentKeyboardType(); - if (type == nullptr) { - return ErrorCode::ERROR_NULL_POINTER; - } - *retType = *type; - return ErrorCode::NO_ERROR; -} + /*! Get the current keyboard type + \n Run in binder thread + \param[out] retType the current keyboard type returned to the caller + \return ErrorCode::NO_ERROR no error + \return ErrorCode::ERROR_USER_NOT_UNLOCKED user not unlocked + \return ErrorCode::ERROR_NULL_POINTER current keyboard type is null + */ + int32_t InputMethodSystemAbility::getCurrentKeyboardType(KeyboardType* retType) + { + int32_t uid = IPCSkeleton::GetCallingUid(); + int32_t userId = getUserId(uid); + PerUserSetting* setting = GetUserSetting(userId); + if (setting == nullptr || setting->GetUserState() != UserState::USER_STATE_UNLOCKED) { + IMSA_HILOGE("%s %d\n", ErrorCode::ToString(ErrorCode::ERROR_USER_NOT_UNLOCKED), userId); + return ErrorCode::ERROR_USER_NOT_UNLOCKED; + } -/*! Get the enabled input method engine list -\n Run in binder thread -\param[out] properties input method engine list returned to the caller -\return ErrorCode::NO_ERROR no error -\return ErrorCode::ERROR_USER_NOT_UNLOCKED user not unlocked -*/ -int32_t InputMethodSystemAbility::listInputMethodEnabled(std::vector *properties) -{ - int32_t uid = IPCSkeleton::GetCallingUid(); - int32_t userId = getUserId(uid); - PerUserSetting* setting = GetUserSetting(userId); - if (setting == nullptr || setting->GetUserState() != UserState::USER_STATE_UNLOCKED) { - IMSA_HILOGE("%s %d\n", ErrorCode::ToString(ErrorCode::ERROR_USER_NOT_UNLOCKED), userId); - return ErrorCode::ERROR_USER_NOT_UNLOCKED; - } - setting->ListInputMethodEnabled(properties); - - std::vector::iterator it; - for(it=properties->begin(); it!=properties->end();) { - if (*it && (*it)->isSystemIme) { - it = properties->erase(it); - } else { - ++it; + KeyboardType* type = GetUserSession(userId)->GetCurrentKeyboardType(); + if (type == nullptr) { + return ErrorCode::ERROR_NULL_POINTER; } + *retType = *type; + return ErrorCode::NO_ERROR; } - return ErrorCode::NO_ERROR; -} -/*! Get all of the input method engine list installed in the system -\n Run in binder thread -\param[out] properties input method engine list returned to the caller -\return ErrorCode::NO_ERROR no error -\return ErrorCode::ERROR_USER_NOT_UNLOCKED user not unlocked -*/ -int32_t InputMethodSystemAbility::listInputMethod(std::vector *properties) -{ - int32_t uid = IPCSkeleton::GetCallingUid(); - int32_t userId = getUserId(uid); - PerUserSetting* setting = GetUserSetting(userId); - if (setting == nullptr || setting->GetUserState() != UserState::USER_STATE_UNLOCKED) { - IMSA_HILOGE("%s %d\n", ErrorCode::ToString(ErrorCode::ERROR_USER_NOT_UNLOCKED), userId); - return ErrorCode::ERROR_USER_NOT_UNLOCKED; - } - setting->ListInputMethod(properties); - std::vector::iterator it; - for(it=properties->begin(); it!=properties->end();) { - if (*it && (*it)->isSystemIme) { - it = properties->erase(it); - } else { - ++it; + /*! Get the enabled input method engine list + \n Run in binder thread + \param[out] properties input method engine list returned to the caller + \return ErrorCode::NO_ERROR no error + \return ErrorCode::ERROR_USER_NOT_UNLOCKED user not unlocked + */ + int32_t InputMethodSystemAbility::listInputMethodEnabled(std::vector *properties) { + int32_t uid = IPCSkeleton::GetCallingUid(); + int32_t userId = getUserId(uid); + PerUserSetting* setting = GetUserSetting(userId); + if (setting == nullptr || setting->GetUserState() != UserState::USER_STATE_UNLOCKED) { + IMSA_HILOGE("%s %d\n", ErrorCode::ToString(ErrorCode::ERROR_USER_NOT_UNLOCKED), userId); + return ErrorCode::ERROR_USER_NOT_UNLOCKED; + } + setting->ListInputMethodEnabled(properties); + + std::vector::iterator it; + for(it=properties->begin(); it!=properties->end();) { + if (*it && (*it)->isSystemIme) { + it = properties->erase(it); + } else { + ++it; + } } + return ErrorCode::NO_ERROR; } - return ErrorCode::NO_ERROR; -} -/*! Get the keyboard type list for the given input method engine -\n Run in binder thread -\param imeId the id of the given input method engine -\param[out] types keyboard type list returned to the caller -\return ErrorCode::NO_ERROR no error -\return ErrorCode::ERROR_USER_NOT_UNLOCKED user not unlocked -*/ -int32_t InputMethodSystemAbility::listKeyboardType(const std::u16string& imeId, std::vector *types) -{ - int32_t uid = IPCSkeleton::GetCallingUid(); - int32_t userId = getUserId(uid); - PerUserSetting* setting = GetUserSetting(userId); - if (setting == nullptr || setting->GetUserState() != UserState::USER_STATE_UNLOCKED) { - IMSA_HILOGE("%s %d\n", ErrorCode::ToString(ErrorCode::ERROR_USER_NOT_UNLOCKED), userId); - return ErrorCode::ERROR_USER_NOT_UNLOCKED; - } - return setting->ListKeyboardType(imeId, types); -} - -/*! Print service information for the input method management service. -\n Run in binder thread -\n The information includes : -\li The user information in the service -\li The input method engine information -\li The input method setting data -\li The session information in the service. -\param fd the raw file descriptor that the dump is being sent to -\param args the parameters for dump command. This parameter is ignored here. -\return ErrorCode::NO_ERROR -*/ -int32_t InputMethodSystemAbility::dump(int32_t fd, const std::vector& args) -{ - (void) args; - dprintf(fd, "\nInputMethodSystemAbility State:\n"); - std::map::const_iterator it; - int32_t index = 0; - dprintf(fd, "* User count = %d\n", userSettings.size()); - for(it=userSettings.cbegin(); it!=userSettings.cend(); ++it) { - PerUserSetting* setting = it->second; - int32_t userId = it->first; - int32_t userState = setting->GetUserState(); - if (userState == UserState::USER_STATE_STARTED) { - dprintf(fd, "[%d] User information: UserId = %d, UserState = USER_STATE_STARTED\n", index++, userId); - } else if (userState == UserState::USER_STATE_UNLOCKED) { - dprintf(fd, "[%d] User information: UserId = %d, UserState = USER_STATE_UNLOCKED\n", index++, userId); - setting->Dump(fd); - PerUserSession* session = GetUserSession(userId); - session->Dump(fd); + /*! Get all of the input method engine list installed in the system + \n Run in binder thread + \param[out] properties input method engine list returned to the caller + \return ErrorCode::NO_ERROR no error + \return ErrorCode::ERROR_USER_NOT_UNLOCKED user not unlocked + */ + int32_t InputMethodSystemAbility::listInputMethod(std::vector *properties) + { + int32_t uid = IPCSkeleton::GetCallingUid(); + int32_t userId = getUserId(uid); + PerUserSetting* setting = GetUserSetting(userId); + if (setting == nullptr || setting->GetUserState() != UserState::USER_STATE_UNLOCKED) { + IMSA_HILOGE("%s %d\n", ErrorCode::ToString(ErrorCode::ERROR_USER_NOT_UNLOCKED), userId); + return ErrorCode::ERROR_USER_NOT_UNLOCKED; } - dprintf(fd, "\n"); + setting->ListInputMethod(properties); + std::vector::iterator it; + for(it=properties->begin(); it!=properties->end();) { + if (*it && (*it)->isSystemIme) { + it = properties->erase(it); + } else { + ++it; + } + } + return ErrorCode::NO_ERROR; } - dprintf(fd, "\n"); - return ErrorCode::NO_ERROR; -} - -/*! Get the instance of PerUserSetting for the given user -\param userId the user id of the given user -\return a pointer of the instance if the user is found -\return null if the user is not found -*/ -PerUserSetting* InputMethodSystemAbility::GetUserSetting(int32_t userId) -{ - std::map::iterator it = userSettings.find(userId); - if (it == userSettings.end()) { - return nullptr; - } - return it->second; -} + /*! Get the keyboard type list for the given input method engine + \n Run in binder thread + \param imeId the id of the given input method engine + \param[out] types keyboard type list returned to the caller + \return ErrorCode::NO_ERROR no error + \return ErrorCode::ERROR_USER_NOT_UNLOCKED user not unlocked + */ + int32_t InputMethodSystemAbility::listKeyboardType(const std::u16string& imeId, std::vector *types) + { + int32_t uid = IPCSkeleton::GetCallingUid(); + int32_t userId = getUserId(uid); + PerUserSetting* setting = GetUserSetting(userId); + if (setting == nullptr || setting->GetUserState() != UserState::USER_STATE_UNLOCKED) { + IMSA_HILOGE("%s %d\n", ErrorCode::ToString(ErrorCode::ERROR_USER_NOT_UNLOCKED), userId); + return ErrorCode::ERROR_USER_NOT_UNLOCKED; + } + return setting->ListKeyboardType(imeId, types); + } + + /* Print service information for the input method management service. + * Run in binder thread + * The information includes : + * The user information in the service + * The input method engine information + * The input method setting data + * The session information in the service. + * param fd the raw file descriptor that the dump is being sent to + * param args the parameters for dump command. This parameter is ignored here. + */ + int32_t InputMethodSystemAbility::dump(int32_t fd, const std::vector& args) + { + (void) args; + dprintf(fd, "\nInputMethodSystemAbility State:\n"); + std::map::const_iterator it; + int32_t index = 0; + dprintf(fd, "* User count = %d\n", userSettings.size()); + for(it=userSettings.cbegin(); it!=userSettings.cend(); ++it) { + PerUserSetting* setting = it->second; + int32_t userId = it->first; + int32_t userState = setting->GetUserState(); + if (userState == UserState::USER_STATE_STARTED) { + dprintf(fd, "[%d] User information: UserId = %d, UserState = USER_STATE_STARTED\n", index++, userId); + } else if (userState == UserState::USER_STATE_UNLOCKED) { + dprintf(fd, "[%d] User information: UserId = %d, UserState = USER_STATE_UNLOCKED\n", index++, userId); + setting->Dump(fd); + PerUserSession* session = GetUserSession(userId); + session->Dump(fd); + } + dprintf(fd, "\n"); + } + dprintf(fd, "\n"); -/*! Get the instance of PerUserSession for the given user -\param userId the user id of the given user -\return a pointer of the instance if the user is found -\return null if the user is not found -*/ -PerUserSession* InputMethodSystemAbility::GetUserSession(int32_t userId) -{ - std::map::iterator it = userSessions.find(userId); - if (it == userSessions.end()) { - return nullptr; - } - return it->second; -} + return ErrorCode::NO_ERROR; + } -/*! Work Thread of input method management service -\n Remote commands which may change the state or data in the service will be handled sequentially in this thread. -*/ -void InputMethodSystemAbility::WorkThread() -{ - while(1){ - Message* msg = MessageHandler::Instance()->GetMessage(); - switch(msg->msgId_) { - case MSG_ID_USER_START : { - OnUserStarted(msg); - break; - } - case MSG_ID_USER_STOP: { - OnUserStopped(msg); - break; - } - case MSG_ID_USER_UNLOCK: { - OnUserUnlocked(msg); - break; - } - case MSG_ID_USER_LOCK : { - OnUserLocked(msg); - break; - } - case MSG_ID_PACKAGE_ADDED: { - OnPackageAdded(msg); - break; - } - case MSG_ID_PACKAGE_REMOVED: { - OnPackageRemoved(msg); - break; - } - case MSG_ID_SETTING_CHANGED: { - OnSettingChanged(msg); - break; - } - case MSG_ID_PREPARE_INPUT: { - OnPrepareInput(msg); - break; - } - case MSG_ID_RELEASE_INPUT: - case MSG_ID_START_INPUT: - case MSG_ID_STOP_INPUT: - case MSG_ID_SET_INPUT_METHOD_CORE: - case MSG_ID_HIDE_KEYBOARD_SELF: - case MSG_ID_SET_DISPLAY_MODE: - case MSG_ID_CLIENT_DIED: - case MSG_ID_IMS_DIED: - case MSG_ID_RESTART_IMS: { - OnHandleMessage(msg); - break; - } - case MSG_ID_DISABLE_IMS: { - OnDisableIms(msg); - break; - } - case MSG_ID_ADVANCE_TO_NEXT: { - OnAdvanceToNext(msg); - break; - } - case MSG_ID_EXIT_SERVICE: { - std::map::const_iterator it; - for(it=msgHandlers.cbegin(); it!=msgHandlers.cend();) { - MessageHandler *handler = it->second; - Message* destMsg = new Message(MSG_ID_EXIT_SERVICE, nullptr); - handler->SendMessage(destMsg); - GetUserSession(it->first)->JoinWorkThread(); - it = msgHandlers.erase(it); - delete handler; + /*! Get the instance of PerUserSetting for the given user + \param userId the user id of the given user + \return a pointer of the instance if the user is found + \return null if the user is not found + */ + PerUserSetting* InputMethodSystemAbility::GetUserSetting(int32_t userId) + { + std::map::iterator it = userSettings.find(userId); + if (it == userSettings.end()) { + return nullptr; + } + return it->second; + } + + /*! Get the instance of PerUserSession for the given user + \param userId the user id of the given user + \return a pointer of the instance if the user is found + \return null if the user is not found + */ + PerUserSession* InputMethodSystemAbility::GetUserSession(int32_t userId) + { + std::map::iterator it = userSessions.find(userId); + if (it == userSessions.end()) { + return nullptr; + } + return it->second; + } + + /*! Work Thread of input method management service + \n Remote commands which may change the state or data in the service will be handled sequentially in this thread. + */ + void InputMethodSystemAbility::WorkThread() + { + while(1){ + Message* msg = MessageHandler::Instance()->GetMessage(); + switch(msg->msgId_) { + case MSG_ID_USER_START : { + OnUserStarted(msg); + break; + } + case MSG_ID_USER_STOP: { + OnUserStopped(msg); + break; + } + case MSG_ID_USER_UNLOCK: { + OnUserUnlocked(msg); + break; + } + case MSG_ID_USER_LOCK : { + OnUserLocked(msg); + break; + } + case MSG_ID_PACKAGE_ADDED: { + OnPackageAdded(msg); + break; + } + case MSG_ID_PACKAGE_REMOVED: { + OnPackageRemoved(msg); + break; + } + case MSG_ID_SETTING_CHANGED: { + OnSettingChanged(msg); + break; + } + case MSG_ID_PREPARE_INPUT: { + OnPrepareInput(msg); + break; + } + case MSG_ID_RELEASE_INPUT: + case MSG_ID_START_INPUT: + case MSG_ID_STOP_INPUT: + case MSG_ID_SET_INPUT_METHOD_CORE: + case MSG_ID_HIDE_KEYBOARD_SELF: + case MSG_ID_SET_DISPLAY_MODE: + case MSG_ID_CLIENT_DIED: + case MSG_ID_IMS_DIED: + case MSG_ID_RESTART_IMS: { + OnHandleMessage(msg); + break; + } + case MSG_ID_DISABLE_IMS: { + OnDisableIms(msg); + break; + } + case MSG_ID_ADVANCE_TO_NEXT: { + OnAdvanceToNext(msg); + break; + } + case MSG_ID_EXIT_SERVICE: { + std::map::const_iterator it; + for(it=msgHandlers.cbegin(); it!=msgHandlers.cend();) { + MessageHandler *handler = it->second; + Message* destMsg = new Message(MSG_ID_EXIT_SERVICE, nullptr); + handler->SendMessage(destMsg); + GetUserSession(it->first)->JoinWorkThread(); + it = msgHandlers.erase(it); + delete handler; + } + delete msg; + return; + } + default: { + break; } - delete msg; - return; - } - default: { - break; } } -// delete msg; } -} -/*! Called when a user is started. (EVENT_USER_STARTED is received) -\n Run in work thread of input method management service -\param msg the parameters are saved in msg->msgContent_ -\return ErrorCode -*/ -int32_t InputMethodSystemAbility::OnUserStarted(const Message* msg) -{ - IMSA_HILOGI("Start...\n"); - if (msg->msgContent_ == nullptr) { - IMSA_HILOGE("Aborted! %s\n", ErrorCode::ToString(ErrorCode::ERROR_BAD_PARAMETERS)); - return ErrorCode::ERROR_BAD_PARAMETERS; - } - int32_t userId = msg->msgContent_->ReadInt32(); - PerUserSetting* setting = GetUserSetting(userId); - if (setting != nullptr) { - IMSA_HILOGE("Aborted! %s %d\n", ErrorCode::ToString(ErrorCode::ERROR_USER_ALREADY_STARTED), userId); - return ErrorCode::ERROR_USER_ALREADY_STARTED; - } - - setting = new PerUserSetting(userId); - PerUserSession* session = new PerUserSession(userId); - - userSettings.insert(std::pair(userId, setting)); - userSessions.insert(std::pair(userId, session)); - IMSA_HILOGI("End...[%d]\n", userId); - return ErrorCode::NO_ERROR; -} + /*! Called when a user is started. (EVENT_USER_STARTED is received) + \n Run in work thread of input method management service + \param msg the parameters are saved in msg->msgContent_ + \return ErrorCode + */ + int32_t InputMethodSystemAbility::OnUserStarted(const Message* msg) + { + IMSA_HILOGI("Start...\n"); + if (msg->msgContent_ == nullptr) { + IMSA_HILOGE("Aborted! %s\n", ErrorCode::ToString(ErrorCode::ERROR_BAD_PARAMETERS)); + return ErrorCode::ERROR_BAD_PARAMETERS; + } + int32_t userId = msg->msgContent_->ReadInt32(); + PerUserSetting* setting = GetUserSetting(userId); + if (setting != nullptr) { + IMSA_HILOGE("Aborted! %s %d\n", ErrorCode::ToString(ErrorCode::ERROR_USER_ALREADY_STARTED), userId); + return ErrorCode::ERROR_USER_ALREADY_STARTED; + } -/*! Called when a user is stopped. (EVENT_USER_STOPPED is received) -\n Run in work thread of input method management service -\param msg the parameters are saved in msg->msgContent_ -\return ErrorCode -*/ -int32_t InputMethodSystemAbility::OnUserStopped(const Message* msg) -{ - IMSA_HILOGI("Start...\n"); - if (msg->msgContent_ == nullptr) { - IMSA_HILOGE("Aborted! %s\n", ErrorCode::ToString(ErrorCode::ERROR_BAD_PARAMETERS)); - return ErrorCode::ERROR_BAD_PARAMETERS; - } - int32_t userId = msg->msgContent_->ReadInt32(); - PerUserSetting* setting = GetUserSetting(userId); - PerUserSession* session = GetUserSession(userId); - if (setting == nullptr || session == nullptr) { - IMSA_HILOGE("Aborted! %s %d\n", ErrorCode::ToString(ErrorCode::ERROR_USER_NOT_STARTED), userId); - return ErrorCode::ERROR_USER_NOT_STARTED; - } - if (setting->GetUserState() == UserState::USER_STATE_UNLOCKED) { - IMSA_HILOGE("Aborted! %s %d\n", ErrorCode::ToString(ErrorCode::ERROR_USER_NOT_LOCKED), userId); - return ErrorCode::ERROR_USER_NOT_LOCKED; - } - std::map::iterator itSession = userSessions.find(userId); - userSessions.erase(itSession); - delete session; - - std::map::iterator itSetting = userSettings.find(userId); - userSettings.erase(itSetting); - delete setting; - IMSA_HILOGI("End...[%d]\n", userId); - return ErrorCode::NO_ERROR; -} + setting = new PerUserSetting(userId); + PerUserSession* session = new PerUserSession(userId); -int32_t InputMethodSystemAbility::setInputMethodCore(sptr &core){ - return ErrorCode::NO_ERROR; -} + userSettings.insert(std::pair(userId, setting)); + userSessions.insert(std::pair(userId, session)); + IMSA_HILOGI("End...[%d]\n", userId); + return ErrorCode::NO_ERROR; + } -/*! Called when a user is unlocked. (EVENT_USER_UNLOCKED is received) -\n Run in work thread of input method management service -\param msg the parameters are saved in msg->msgContent_ -\return ErrorCode -*/ -int32_t InputMethodSystemAbility::OnUserUnlocked(const Message* msg) -{ - IMSA_HILOGI("Start...\n"); - if (msg->msgContent_ == nullptr) { - IMSA_HILOGE("Aborted! %s\n", ErrorCode::ToString(ErrorCode::ERROR_BAD_PARAMETERS)); - return ErrorCode::ERROR_BAD_PARAMETERS; - } - int32_t userId = msg->msgContent_->ReadInt32(); - PerUserSetting* setting = GetUserSetting(userId); - PerUserSession* session = GetUserSession(userId); - if (setting == nullptr || session == nullptr) { - IMSA_HILOGE("Aborted! %s %d\n", ErrorCode::ToString(ErrorCode::ERROR_USER_NOT_STARTED), userId); - return ErrorCode::ERROR_USER_NOT_STARTED; - } - if (setting->GetUserState() == UserState::USER_STATE_UNLOCKED) { - IMSA_HILOGE("Aborted! %s %d\n", ErrorCode::ToString(ErrorCode::ERROR_USER_ALREADY_UNLOCKED), userId); - return ErrorCode::ERROR_USER_ALREADY_UNLOCKED; - } - - setting->Initialize(); - - InputMethodProperty* ime = setting->GetSecurityInputMethod(); - session->SetSecurityIme(ime); - ime = setting->GetCurrentInputMethod(); - session->SetCurrentIme(ime); - session->SetInputMethodSetting(setting->GetInputMethodSetting()); - IMSA_HILOGI("End...[%d]\n", userId); - return ErrorCode::NO_ERROR; -} + /*! Called when a user is stopped. (EVENT_USER_STOPPED is received) + \n Run in work thread of input method management service + \param msg the parameters are saved in msg->msgContent_ + \return ErrorCode + */ + int32_t InputMethodSystemAbility::OnUserStopped(const Message* msg) + { + IMSA_HILOGI("Start...\n"); + if (msg->msgContent_ == nullptr) { + IMSA_HILOGE("Aborted! %s\n", ErrorCode::ToString(ErrorCode::ERROR_BAD_PARAMETERS)); + return ErrorCode::ERROR_BAD_PARAMETERS; + } + int32_t userId = msg->msgContent_->ReadInt32(); + PerUserSetting* setting = GetUserSetting(userId); + PerUserSession* session = GetUserSession(userId); + if (setting == nullptr || session == nullptr) { + IMSA_HILOGE("Aborted! %s %d\n", ErrorCode::ToString(ErrorCode::ERROR_USER_NOT_STARTED), userId); + return ErrorCode::ERROR_USER_NOT_STARTED; + } + if (setting->GetUserState() == UserState::USER_STATE_UNLOCKED) { + IMSA_HILOGE("Aborted! %s %d\n", ErrorCode::ToString(ErrorCode::ERROR_USER_NOT_LOCKED), userId); + return ErrorCode::ERROR_USER_NOT_LOCKED; + } + std::map::iterator itSession = userSessions.find(userId); + userSessions.erase(itSession); + delete session; -/*! Called when a user is locked. (EVENT_USER_LOCKED is received) -\n Run in work thread of input method management service -\param msg the parameters are saved in msg->msgContent_ -\return ErrorCode -*/ -int32_t InputMethodSystemAbility::OnUserLocked(const Message* msg) -{ - IMSA_HILOGI("Start...\n"); - if (msg->msgContent_ == nullptr) { - IMSA_HILOGE("Aborted! %s\n", ErrorCode::ToString(ErrorCode::ERROR_BAD_PARAMETERS)); - return ErrorCode::ERROR_BAD_PARAMETERS; - } - int32_t userId = msg->msgContent_->ReadInt32(); - PerUserSetting* setting = GetUserSetting(userId); - if (setting == nullptr || setting->GetUserState() != UserState::USER_STATE_UNLOCKED) { - IMSA_HILOGE("Aborted! %s %d\n", ErrorCode::ToString(ErrorCode::ERROR_USER_NOT_UNLOCKED), userId); - return ErrorCode::ERROR_USER_NOT_UNLOCKED; - } - std::map::iterator it = msgHandlers.find(userId); - 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; - } - setting->OnUserLocked(); - IMSA_HILOGI("End...[%d]\n", userId); - return ErrorCode::NO_ERROR; -} + std::map::iterator itSetting = userSettings.find(userId); + userSettings.erase(itSetting); + delete setting; + IMSA_HILOGI("End...[%d]\n", userId); + return ErrorCode::NO_ERROR; + } + + int32_t InputMethodSystemAbility::setInputMethodCore(sptr &core){ + return ErrorCode::NO_ERROR; + } -/*! Prepare input. Called by an input client. -\n Run in work thread of input method management service -\param msg the parameters from remote client are saved in msg->msgContent_ -\return ErrorCode::NO_ERROR -\return ErrorCode::ERROR_USER_NOT_UNLOCKED user not unlocked -*/ -int32_t InputMethodSystemAbility::OnPrepareInput(Message* msg) -{ - IMSA_HILOGI("InputMethodSystemAbility::OnPrepareInput"); - MessageParcel* data = msg->msgContent_; - int32_t userId = data->ReadInt32(); - - PerUserSetting* setting = GetUserSetting(userId); - if (setting == nullptr || setting->GetUserState() != UserState::USER_STATE_UNLOCKED) { - IMSA_HILOGE("InputMethodSystemAbility::OnPrepareInput GetUserSetting Aborted! %{public}s %{public}d\n", ErrorCode::ToString(ErrorCode::ERROR_USER_NOT_UNLOCKED), userId); - return ErrorCode::ERROR_USER_NOT_UNLOCKED; - } - - std::map::const_iterator it = msgHandlers.find(userId); - if(it==msgHandlers.end()) { + /*! Called when a user is unlocked. (EVENT_USER_UNLOCKED is received) + \n Run in work thread of input method management service + \param msg the parameters are saved in msg->msgContent_ + \return ErrorCode + */ + int32_t InputMethodSystemAbility::OnUserUnlocked(const Message* msg) + { + IMSA_HILOGI("Start...\n"); + if (msg->msgContent_ == nullptr) { + IMSA_HILOGE("Aborted! %s\n", ErrorCode::ToString(ErrorCode::ERROR_BAD_PARAMETERS)); + return ErrorCode::ERROR_BAD_PARAMETERS; + } + int32_t userId = msg->msgContent_->ReadInt32(); + PerUserSetting* setting = GetUserSetting(userId); PerUserSession* session = GetUserSession(userId); - MessageHandler* handler = new MessageHandler(); - session->CreateWorkThread(*handler); - msgHandlers.insert(std::pair(userId, handler)); - it = msgHandlers.find(userId); + if (setting == nullptr || session == nullptr) { + IMSA_HILOGE("Aborted! %s %d\n", ErrorCode::ToString(ErrorCode::ERROR_USER_NOT_STARTED), userId); + return ErrorCode::ERROR_USER_NOT_STARTED; + } + if (setting->GetUserState() == UserState::USER_STATE_UNLOCKED) { + IMSA_HILOGE("Aborted! %s %d\n", ErrorCode::ToString(ErrorCode::ERROR_USER_ALREADY_UNLOCKED), userId); + return ErrorCode::ERROR_USER_ALREADY_UNLOCKED; + } + + setting->Initialize(); + + InputMethodProperty* ime = setting->GetSecurityInputMethod(); + session->SetSecurityIme(ime); + ime = setting->GetCurrentInputMethod(); + session->SetCurrentIme(ime); + session->SetInputMethodSetting(setting->GetInputMethodSetting()); + IMSA_HILOGI("End...[%d]\n", userId); + return ErrorCode::NO_ERROR; } - if (it!=msgHandlers.end()) { - MessageHandler* handler = it->second; - handler->SendMessage(msg); + /*! Called when a user is locked. (EVENT_USER_LOCKED is received) + \n Run in work thread of input method management service + \param msg the parameters are saved in msg->msgContent_ + \return ErrorCode + */ + int32_t InputMethodSystemAbility::OnUserLocked(const Message* msg) + { + IMSA_HILOGI("Start...\n"); + if (msg->msgContent_ == nullptr) { + IMSA_HILOGE("Aborted! %s\n", ErrorCode::ToString(ErrorCode::ERROR_BAD_PARAMETERS)); + return ErrorCode::ERROR_BAD_PARAMETERS; + } + int32_t userId = msg->msgContent_->ReadInt32(); + PerUserSetting* setting = GetUserSetting(userId); + if (setting == nullptr || setting->GetUserState() != UserState::USER_STATE_UNLOCKED) { + IMSA_HILOGE("Aborted! %s %d\n", ErrorCode::ToString(ErrorCode::ERROR_USER_NOT_UNLOCKED), userId); + return ErrorCode::ERROR_USER_NOT_UNLOCKED; + } + std::map::iterator it = msgHandlers.find(userId); + 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; + } + setting->OnUserLocked(); + IMSA_HILOGI("End...[%d]\n", userId); + return ErrorCode::NO_ERROR; } - return 0; -} -/*! Handle message -\param msgId the id of message to run -\msg the parameters are saved in msg->msgContent_ -\return ErrorCode::NO_ERROR -\return ErrorCode::ERROR_USER_NOT_UNLOCKED user not unlocked -*/ -int32_t InputMethodSystemAbility::OnHandleMessage(Message* msg) -{ - MessageParcel* data = msg->msgContent_; - int32_t userId = data->ReadInt32(); - PerUserSetting* setting = GetUserSetting(userId); - if (setting == nullptr || setting->GetUserState() != UserState::USER_STATE_UNLOCKED) { - IMSA_HILOGE("Aborted! %s %d\n", ErrorCode::ToString(ErrorCode::ERROR_USER_NOT_UNLOCKED), userId); - return ErrorCode::ERROR_USER_NOT_UNLOCKED; - } - - std::map::const_iterator it = msgHandlers.find(userId); - if (it!=msgHandlers.end()) { - MessageHandler* handler = it->second; -// Message* destMsg = new Message(*msg); - handler->SendMessage(msg); - } - return ErrorCode::NO_ERROR; -} + /*! Prepare input. Called by an input client. + \n Run in work thread of input method management service + \param msg the parameters from remote client are saved in msg->msgContent_ + \return ErrorCode::NO_ERROR + \return ErrorCode::ERROR_USER_NOT_UNLOCKED user not unlocked + */ + int32_t InputMethodSystemAbility::OnPrepareInput(Message* msg) + { + IMSA_HILOGI("InputMethodSystemAbility::OnPrepareInput"); + MessageParcel* data = msg->msgContent_; + int32_t userId = data->ReadInt32(); + + PerUserSetting* setting = GetUserSetting(userId); + if (setting == nullptr || setting->GetUserState() != UserState::USER_STATE_UNLOCKED) { + IMSA_HILOGE("InputMethodSystemAbility::OnPrepareInput errorCode = ErrorCode::ERROR_USER_NOT_UNLOCKED"); + return ErrorCode::ERROR_USER_NOT_UNLOCKED; + } -/*! Called when a package is installed. -\n Run in work thread of input method management service -\param msg the parameters are saved in msg->msgContent_ -\return ErrorCode::NO_ERROR -\return ErrorCode::ERROR_USER_NOT_UNLOCKED user not unlocked -\return ErrorCode::ERROR_BAD_PARAMETERS bad parameter -*/ -int32_t InputMethodSystemAbility::OnPackageAdded(const Message* msg) -{ - IMSA_HILOGI("Start...\n"); - MessageParcel* data = msg->msgContent_; - int32_t userId = data->ReadInt32(); - int32_t size = data->ReadInt32(); - - if (size <= 0) { - IMSA_HILOGE("Aborted! %s\n", ErrorCode::ToString(ErrorCode::ERROR_BAD_PARAMETERS)); - return ErrorCode::ERROR_BAD_PARAMETERS; - } - std::u16string packageName = data->ReadString16(); - PerUserSetting* setting = GetUserSetting(userId); - if (setting == nullptr || setting->GetUserState() != UserState::USER_STATE_UNLOCKED) { - IMSA_HILOGE("Aborted! %s %d\n", ErrorCode::ToString(ErrorCode::ERROR_USER_NOT_UNLOCKED), userId); - return ErrorCode::ERROR_USER_NOT_UNLOCKED; - } - bool securityImeFlag = false; - int32_t ret = setting->OnPackageAdded(packageName, &securityImeFlag); - if (ret != ErrorCode::NO_ERROR) { - IMSA_HILOGI("End...\n"); - return ret; - } - if (securityImeFlag == true) { - InputMethodProperty* securityIme = setting->GetSecurityInputMethod(); - InputMethodProperty* defaultIme = setting->GetCurrentInputMethod(); - GetUserSession(userId)->ResetIme(defaultIme, securityIme); + std::map::const_iterator it = msgHandlers.find(userId); + if(it==msgHandlers.end()) { + PerUserSession* session = GetUserSession(userId); + MessageHandler* handler = new MessageHandler(); + session->CreateWorkThread(*handler); + msgHandlers.insert(std::pair(userId, handler)); + it = msgHandlers.find(userId); + } + + if (it!=msgHandlers.end()) { + MessageHandler* handler = it->second; + handler->SendMessage(msg); + } + return 0; + } + + /*! Handle message + \param msgId the id of message to run + \msg the parameters are saved in msg->msgContent_ + \return ErrorCode::NO_ERROR + \return ErrorCode::ERROR_USER_NOT_UNLOCKED user not unlocked + */ + int32_t InputMethodSystemAbility::OnHandleMessage(Message* msg) + { + MessageParcel* data = msg->msgContent_; + int32_t userId = data->ReadInt32(); + PerUserSetting* setting = GetUserSetting(userId); + if (setting == nullptr || setting->GetUserState() != UserState::USER_STATE_UNLOCKED) { + IMSA_HILOGE("Aborted! %s %d\n", ErrorCode::ToString(ErrorCode::ERROR_USER_NOT_UNLOCKED), userId); + return ErrorCode::ERROR_USER_NOT_UNLOCKED; + } + + std::map::const_iterator it = msgHandlers.find(userId); + if (it!=msgHandlers.end()) { + MessageHandler* handler = it->second; + handler->SendMessage(msg); + } + return ErrorCode::NO_ERROR; } - IMSA_HILOGI("End...\n"); - return 0; -} -/*! Called when a package is removed. -\n Run in work thread of input method management service -\param msg the parameters are saved in msg->msgContent_ -\return ErrorCode::NO_ERROR -\return ErrorCode::ERROR_USER_NOT_UNLOCKED user not unlocked -\return ErrorCode::ERROR_BAD_PARAMETERS bad parameter -*/ -int32_t InputMethodSystemAbility::OnPackageRemoved(const Message* msg) -{ - IMSA_HILOGI("Start...\n"); - MessageParcel* data = msg->msgContent_; - int32_t userId = data->ReadInt32(); - int32_t size = data->ReadInt32(); - - if (size <= 0) { - IMSA_HILOGE("Aborted! %s\n", ErrorCode::ToString(ErrorCode::ERROR_BAD_PARAMETERS)); - return ErrorCode::ERROR_BAD_PARAMETERS; - } - std::u16string packageName = data->ReadString16(); - PerUserSetting* setting = GetUserSetting(userId); - if (setting == nullptr || setting->GetUserState() != UserState::USER_STATE_UNLOCKED) { - IMSA_HILOGE("Aborted! %s %d\n", ErrorCode::ToString(ErrorCode::ERROR_USER_NOT_UNLOCKED), userId); - return ErrorCode::ERROR_USER_NOT_UNLOCKED; - } - PerUserSession* session = GetUserSession(userId); - session->OnPackageRemoved(packageName); - bool securityImeFlag = false; - int32_t ret = setting->OnPackageRemoved(packageName, &securityImeFlag); - if (ret != ErrorCode::NO_ERROR) { + /*! Called when a package is installed. + \n Run in work thread of input method management service + \param msg the parameters are saved in msg->msgContent_ + \return ErrorCode::NO_ERROR + \return ErrorCode::ERROR_USER_NOT_UNLOCKED user not unlocked + \return ErrorCode::ERROR_BAD_PARAMETERS bad parameter + */ + int32_t InputMethodSystemAbility::OnPackageAdded(const Message* msg) + { + IMSA_HILOGI("Start...\n"); + MessageParcel* data = msg->msgContent_; + int32_t userId = data->ReadInt32(); + int32_t size = data->ReadInt32(); + + if (size <= 0) { + IMSA_HILOGE("Aborted! %s\n", ErrorCode::ToString(ErrorCode::ERROR_BAD_PARAMETERS)); + return ErrorCode::ERROR_BAD_PARAMETERS; + } + std::u16string packageName = data->ReadString16(); + PerUserSetting* setting = GetUserSetting(userId); + if (setting == nullptr || setting->GetUserState() != UserState::USER_STATE_UNLOCKED) { + IMSA_HILOGE("Aborted! %s %d\n", ErrorCode::ToString(ErrorCode::ERROR_USER_NOT_UNLOCKED), userId); + return ErrorCode::ERROR_USER_NOT_UNLOCKED; + } + bool securityImeFlag = false; + int32_t ret = setting->OnPackageAdded(packageName, &securityImeFlag); + if (ret != ErrorCode::NO_ERROR) { + IMSA_HILOGI("End...\n"); + return ret; + } + if (securityImeFlag == true) { + InputMethodProperty* securityIme = setting->GetSecurityInputMethod(); + InputMethodProperty* defaultIme = setting->GetCurrentInputMethod(); + GetUserSession(userId)->ResetIme(defaultIme, securityIme); + } IMSA_HILOGI("End...\n"); - return ret; - } - if (securityImeFlag == true) { + return 0; + } + + /*! Called when a package is removed. + \n Run in work thread of input method management service + \param msg the parameters are saved in msg->msgContent_ + \return ErrorCode::NO_ERROR + \return ErrorCode::ERROR_USER_NOT_UNLOCKED user not unlocked + \return ErrorCode::ERROR_BAD_PARAMETERS bad parameter + */ + int32_t InputMethodSystemAbility::OnPackageRemoved(const Message* msg) + { + IMSA_HILOGI("Start...\n"); + MessageParcel* data = msg->msgContent_; + int32_t userId = data->ReadInt32(); + int32_t size = data->ReadInt32(); + + if (size <= 0) { + IMSA_HILOGE("Aborted! %s\n", ErrorCode::ToString(ErrorCode::ERROR_BAD_PARAMETERS)); + return ErrorCode::ERROR_BAD_PARAMETERS; + } + std::u16string packageName = data->ReadString16(); + PerUserSetting* setting = GetUserSetting(userId); + if (setting == nullptr || setting->GetUserState() != UserState::USER_STATE_UNLOCKED) { + IMSA_HILOGE("Aborted! %s %d\n", ErrorCode::ToString(ErrorCode::ERROR_USER_NOT_UNLOCKED), userId); + return ErrorCode::ERROR_USER_NOT_UNLOCKED; + } + PerUserSession* session = GetUserSession(userId); + session->OnPackageRemoved(packageName); + bool securityImeFlag = false; + int32_t ret = setting->OnPackageRemoved(packageName, &securityImeFlag); + if (ret != ErrorCode::NO_ERROR) { + IMSA_HILOGI("End...\n"); + return ret; + } + if (securityImeFlag == true) { + InputMethodProperty* securityIme = setting->GetSecurityInputMethod(); + InputMethodProperty* defaultIme = setting->GetCurrentInputMethod(); + GetUserSession(userId)->ResetIme(defaultIme, securityIme); + } + return 0; + } + + /*! Called when input method setting data is changed. + \n Run in work thread of input method management service + \param msg the parameters from remote binder are saved in msg->msgContent_ + \return ErrorCode::NO_ERROR + \return ErrorCode::ERROR_USER_NOT_UNLOCKED user not unlocked + \return ErrorCode::ERROR_BAD_PARAMETERS bad parameter + */ + int32_t InputMethodSystemAbility::OnSettingChanged(const Message* msg) + { + IMSA_HILOGI("Start...\n"); + MessageParcel* data = msg->msgContent_; + int32_t userId = data->ReadInt32(); + int32_t size = data->ReadInt32(); + if (size < 2) { + IMSA_HILOGE("Aborted! %s\n", ErrorCode::ToString(ErrorCode::ERROR_BAD_PARAMETERS)); + return ErrorCode::ERROR_BAD_PARAMETERS; + } + std::u16string updatedKey = data->ReadString16(); + std::u16string updatedValue = data->ReadString16(); + PerUserSetting* setting = GetUserSetting(userId); + if (setting == nullptr || setting->GetUserState() != UserState::USER_STATE_UNLOCKED) { + IMSA_HILOGE("Aborted! %s %d\n", ErrorCode::ToString(ErrorCode::ERROR_USER_NOT_UNLOCKED), userId); + return ErrorCode::ERROR_USER_NOT_UNLOCKED; + } + PerUserSession* session = GetUserSession(userId); + int32_t ret = session->OnSettingChanged(updatedKey, updatedValue); + if (ret == ErrorCode::ERROR_SETTING_SAME_VALUE) { + IMSA_HILOGI("End...No need to update\n"); + return ret; + } + + // PerUserSetting does not need handle keyboard type change notification + if (updatedKey == InputMethodSetting::CURRENT_KEYBOARD_TYPE_TAG || + updatedKey == InputMethodSetting::CURRENT_SYS_KEYBOARD_TYPE_TAG) { + IMSA_HILOGI("End...\n"); + return ErrorCode::NO_ERROR; + } + + ret = setting->OnSettingChanged(updatedKey, updatedValue); + if (ret != 0) { + IMSA_HILOGI("End...No need to update\n"); + return ret; + } + InputMethodProperty* securityIme = setting->GetSecurityInputMethod(); InputMethodProperty* defaultIme = setting->GetCurrentInputMethod(); - GetUserSession(userId)->ResetIme(defaultIme, securityIme); + session->ResetIme(defaultIme, securityIme); + IMSA_HILOGI("End...\n"); + return ErrorCode::NO_ERROR; } - return 0; -} -/*! Called when input method setting data is changed. -\n Run in work thread of input method management service -\param msg the parameters from remote binder are saved in msg->msgContent_ -\return ErrorCode::NO_ERROR -\return ErrorCode::ERROR_USER_NOT_UNLOCKED user not unlocked -\return ErrorCode::ERROR_BAD_PARAMETERS bad parameter -*/ -int32_t InputMethodSystemAbility::OnSettingChanged(const Message* msg) -{ - IMSA_HILOGI("Start...\n"); - MessageParcel* data = msg->msgContent_; - int32_t userId = data->ReadInt32(); - int32_t size = data->ReadInt32(); - if (size < 2) { - IMSA_HILOGE("Aborted! %s\n", ErrorCode::ToString(ErrorCode::ERROR_BAD_PARAMETERS)); - return ErrorCode::ERROR_BAD_PARAMETERS; - } - std::u16string updatedKey = data->ReadString16(); - std::u16string updatedValue = data->ReadString16(); - PerUserSetting* setting = GetUserSetting(userId); - if (setting == nullptr || setting->GetUserState() != UserState::USER_STATE_UNLOCKED) { - IMSA_HILOGE("Aborted! %s %d\n", ErrorCode::ToString(ErrorCode::ERROR_USER_NOT_UNLOCKED), userId); - return ErrorCode::ERROR_USER_NOT_UNLOCKED; - } - PerUserSession* session = GetUserSession(userId); - int32_t ret = session->OnSettingChanged(updatedKey, updatedValue); - if (ret == ErrorCode::ERROR_SETTING_SAME_VALUE) { - IMSA_HILOGI("End...No need to update\n"); - return ret; - } + /*! Disable input method service. Called from PerUserSession module + \n Run in work thread of input method management service + \param msg the parameters are saved in msg->msgContent_ + \return ErrorCode::NO_ERROR + \return ErrorCode::ERROR_USER_NOT_UNLOCKED user not unlocked + */ + int32_t InputMethodSystemAbility::OnDisableIms(const Message* msg) + { + IMSA_HILOGI("Start...\n"); + MessageParcel* data = msg->msgContent_; + int32_t userId = data->ReadInt32(); + std::u16string imeId = data->ReadString16(); + PerUserSetting* setting = GetUserSetting(userId); + if (setting == nullptr || setting->GetUserState() != UserState::USER_STATE_UNLOCKED) { + IMSA_HILOGE("Aborted! %s %d\n", ErrorCode::ToString(ErrorCode::ERROR_USER_NOT_UNLOCKED), userId); + return ErrorCode::ERROR_USER_NOT_UNLOCKED; + } - // PerUserSetting does not need handle keyboard type change notification - if (updatedKey == InputMethodSetting::CURRENT_KEYBOARD_TYPE_TAG || - updatedKey == InputMethodSetting::CURRENT_SYS_KEYBOARD_TYPE_TAG) { + InputMethodSetting tmpSetting; + std::u16string key = InputMethodSetting::ENABLED_INPUT_METHODS_TAG; + tmpSetting.SetValue(key, setting->GetInputMethodSetting()->GetValue(key)); + tmpSetting.RemoveEnabledInputMethod(imeId); IMSA_HILOGI("End...\n"); return ErrorCode::NO_ERROR; } - ret = setting->OnSettingChanged(updatedKey, updatedValue); - if (ret != 0) { - IMSA_HILOGI("End...No need to update\n"); - return ret; - } - - InputMethodProperty* securityIme = setting->GetSecurityInputMethod(); - InputMethodProperty* defaultIme = setting->GetCurrentInputMethod(); - session->ResetIme(defaultIme, securityIme); - IMSA_HILOGI("End...\n"); - return ErrorCode::NO_ERROR; -} - -/*! Disable input method service. Called from PerUserSession module -\n Run in work thread of input method management service -\param msg the parameters are saved in msg->msgContent_ -\return ErrorCode::NO_ERROR -\return ErrorCode::ERROR_USER_NOT_UNLOCKED user not unlocked -*/ -int32_t InputMethodSystemAbility::OnDisableIms(const Message* msg) -{ - IMSA_HILOGI("Start...\n"); - MessageParcel* data = msg->msgContent_; - int32_t userId = data->ReadInt32(); - std::u16string imeId = data->ReadString16(); - PerUserSetting* setting = GetUserSetting(userId); - if (setting == nullptr || setting->GetUserState() != UserState::USER_STATE_UNLOCKED) { - IMSA_HILOGE("Aborted! %s %d\n", ErrorCode::ToString(ErrorCode::ERROR_USER_NOT_UNLOCKED), userId); - return ErrorCode::ERROR_USER_NOT_UNLOCKED; - } - - InputMethodSetting tmpSetting; - std::u16string key = InputMethodSetting::ENABLED_INPUT_METHODS_TAG; - tmpSetting.SetValue(key, setting->GetInputMethodSetting()->GetValue(key)); - tmpSetting.RemoveEnabledInputMethod(imeId); - //Platform::Instance()->SetInputMethodSetting(userId, tmpSetting); - IMSA_HILOGI("End...\n"); - return ErrorCode::NO_ERROR; -} - -/*! Switch to next ime or next keyboard type. It's called by input method service -\n Run in work thread of input method management service or the work thread of PerUserSession -\param msg the parameters from remote binder are saved in msg->msgContent_ -\return ErrorCode::NO_ERROR -\return ErrorCode::ERROR_USER_NOT_UNLOCKED user not unlocked -*/ -int32_t InputMethodSystemAbility::OnAdvanceToNext(const Message* msg) -{ - IMSA_HILOGI("Start...\n"); - MessageParcel* data = msg->msgContent_; - int32_t userId = data->ReadInt32(); - bool isCurrentIme = data->ReadBool(); - PerUserSetting* setting = GetUserSetting(userId); - if (setting == nullptr || setting->GetUserState() != UserState::USER_STATE_UNLOCKED) { - IMSA_HILOGE("Aborted! %s %d\n", ErrorCode::ToString(ErrorCode::ERROR_USER_NOT_UNLOCKED), userId); - return ErrorCode::ERROR_USER_NOT_UNLOCKED; - } - if (isCurrentIme) { - std::map::const_iterator it = msgHandlers.find(userId); - if (it!=msgHandlers.end()) { - Message* destMsg = new Message(msg->msgId_, nullptr); - it->second->SendMessage(destMsg); + /*! Switch to next ime or next keyboard type. It's called by input method service + \n Run in work thread of input method management service or the work thread of PerUserSession + \param msg the parameters from remote binder are saved in msg->msgContent_ + \return ErrorCode::NO_ERROR + \return ErrorCode::ERROR_USER_NOT_UNLOCKED user not unlocked + */ + int32_t InputMethodSystemAbility::OnAdvanceToNext(const Message* msg) + { + IMSA_HILOGI("Start...\n"); + MessageParcel* data = msg->msgContent_; + int32_t userId = data->ReadInt32(); + bool isCurrentIme = data->ReadBool(); + PerUserSetting* setting = GetUserSetting(userId); + if (setting == nullptr || setting->GetUserState() != UserState::USER_STATE_UNLOCKED) { + IMSA_HILOGE("Aborted! %s %d\n", ErrorCode::ToString(ErrorCode::ERROR_USER_NOT_UNLOCKED), userId); + return ErrorCode::ERROR_USER_NOT_UNLOCKED; + } + if (isCurrentIme) { + std::map::const_iterator it = msgHandlers.find(userId); + if (it!=msgHandlers.end()) { + Message* destMsg = new Message(msg->msgId_, nullptr); + it->second->SendMessage(destMsg); + } + } else { + setting->OnAdvanceToNext(); } - } else { - setting->OnAdvanceToNext(); + IMSA_HILOGI("End...\n"); + return ErrorCode::NO_ERROR; } - IMSA_HILOGI("End...\n"); - return ErrorCode::NO_ERROR; } -} -} - +} \ No newline at end of file diff --git a/services/src/input_method_system_ability_stub.cpp b/services/src/input_method_system_ability_stub.cpp index df8687d32156f361d8f05c39faea20d42d40676d..e812b61326a70ec52c2159d8ff6f6fa897da5f2b 100644 --- a/services/src/input_method_system_ability_stub.cpp +++ b/services/src/input_method_system_ability_stub.cpp @@ -19,101 +19,118 @@ namespace OHOS { namespace MiscServices { - -using namespace MessageID; -/*! Handle the transaction from the remote binder -\n Run in binder thread -\param code transaction code number -\param data the parameters from remote binder -\param[out] reply the result of the transaction replied to the remote binder -\param flags the flags of handling transaction -\return int32_t -*/ -int32_t InputMethodSystemAbilityStub::OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, - MessageOption &option) -{ - IMSA_HILOGI("InputMethodSystemAbilityStub::OnRemoteRequest code = %{public}u", code); - auto descriptorToken = data.ReadInterfaceToken(); - if (descriptorToken != GetDescriptor()) { - return ErrorCode::ERROR_STATUS_UNKNOWN_TRANSACTION; - } - - switch(code) { - case PREPARE_INPUT: { - prepareInput(data); - reply.WriteInt32(NO_ERROR); - break; - } - case RELEASE_INPUT: { - MessageParcel* msgParcel = (MessageParcel*) &data; - releaseInput(*msgParcel); - reply.WriteInt32(NO_ERROR); - break; - } - case START_INPUT: { - MessageParcel* msgParcel = (MessageParcel*) &data; - startInput(*msgParcel); - reply.WriteInt32(NO_ERROR); - break; - } - case STOP_INPUT: { - MessageParcel* msgParcel = (MessageParcel*) &data; - stopInput(*msgParcel); - reply.WriteInt32(NO_ERROR); - break; - } - case SET_INPUT_METHOD_CORE:{ - MessageParcel* msgParcel = (MessageParcel*) &data; - setInputMethodCoreFromHap(*msgParcel); - reply.WriteInt32(NO_ERROR); - break; + using namespace MessageID; + /*! Handle the transaction from the remote binder + \n Run in binder thread + \param code transaction code number + \param data the parameters from remote binder + \param[out] reply the result of the transaction replied to the remote binder + \param flags the flags of handling transaction + \return int32_t + */ + int32_t InputMethodSystemAbilityStub::OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, + MessageOption &option) + { + IMSA_HILOGI("InputMethodSystemAbilityStub::OnRemoteRequest code = %{public}u", code); + auto descriptorToken = data.ReadInterfaceToken(); + if (descriptorToken != GetDescriptor()) { + return ErrorCode::ERROR_STATUS_UNKNOWN_TRANSACTION; } - case GET_DISPLAY_MODE: { - int32_t mode = 0; - int32_t status = getDisplayMode(&mode); - if (status == ErrorCode::NO_ERROR) { + + switch(code) { + case PREPARE_INPUT: { + prepareInput(data); reply.WriteInt32(NO_ERROR); - reply.WriteInt32(mode); - } else { - reply.WriteInt32(ErrorCode::ERROR_EX_ILLEGAL_STATE); - reply.WriteInt32(-1); + break; } - break; - } - case GET_KEYBOARD_WINDOW_HEIGHT: { - int32_t height = 0; - int32_t status = getKeyboardWindowHeight(&height); - if (status == ErrorCode::NO_ERROR) { + case RELEASE_INPUT: { + MessageParcel* msgParcel = (MessageParcel*) &data; + releaseInput(*msgParcel); reply.WriteInt32(NO_ERROR); - reply.WriteInt32(height); - } else { - reply.WriteInt32(ErrorCode::ERROR_EX_ILLEGAL_STATE); - reply.WriteInt32(-1); + break; } - break; - } - case GET_CURRENT_KEYBOARD_TYPE: { - KeyboardType type; - int32_t status = getCurrentKeyboardType(&type); - if (status == ErrorCode::NO_ERROR) { + case START_INPUT: { + MessageParcel* msgParcel = (MessageParcel*) &data; + startInput(*msgParcel); reply.WriteInt32(NO_ERROR); - reply.WriteParcelable(&type); - } else if (status == ErrorCode::ERROR_NULL_POINTER) { + break; + } + case STOP_INPUT: { + MessageParcel* msgParcel = (MessageParcel*) &data; + stopInput(*msgParcel); reply.WriteInt32(NO_ERROR); - reply.WriteInt32(0); - } else { - reply.WriteInt32(ErrorCode::ERROR_EX_ILLEGAL_STATE); - reply.WriteInt32(-1); + break; } - break; - } - case LIST_INPUT_METHOD_ENABLED: { - std::vector properties; - int32_t ret = listInputMethodEnabled(&properties); - if (ret != ErrorCode::NO_ERROR) { - reply.WriteInt32(ErrorCode::ERROR_EX_ILLEGAL_STATE); // write exception code - reply.WriteInt32(-1); - } else { + case SET_INPUT_METHOD_CORE:{ + MessageParcel* msgParcel = (MessageParcel*) &data; + setInputMethodCoreFromHap(*msgParcel); + reply.WriteInt32(NO_ERROR); + break; + } + case GET_DISPLAY_MODE: { + int32_t mode = 0; + int32_t status = getDisplayMode(&mode); + if (status == ErrorCode::NO_ERROR) { + reply.WriteInt32(NO_ERROR); + reply.WriteInt32(mode); + } else { + reply.WriteInt32(ErrorCode::ERROR_EX_ILLEGAL_STATE); + reply.WriteInt32(-1); + } + break; + } + case GET_KEYBOARD_WINDOW_HEIGHT: { + int32_t height = 0; + int32_t status = getKeyboardWindowHeight(&height); + if (status == ErrorCode::NO_ERROR) { + reply.WriteInt32(NO_ERROR); + reply.WriteInt32(height); + } else { + reply.WriteInt32(ErrorCode::ERROR_EX_ILLEGAL_STATE); + reply.WriteInt32(-1); + } + break; + } + case GET_CURRENT_KEYBOARD_TYPE: { + KeyboardType type; + int32_t status = getCurrentKeyboardType(&type); + if (status == ErrorCode::NO_ERROR) { + reply.WriteInt32(NO_ERROR); + reply.WriteParcelable(&type); + } else if (status == ErrorCode::ERROR_NULL_POINTER) { + reply.WriteInt32(NO_ERROR); + reply.WriteInt32(0); + } else { + reply.WriteInt32(ErrorCode::ERROR_EX_ILLEGAL_STATE); + reply.WriteInt32(-1); + } + break; + } + case LIST_INPUT_METHOD_ENABLED: { + std::vector properties; + int32_t ret = listInputMethodEnabled(&properties); + if (ret != ErrorCode::NO_ERROR) { + reply.WriteInt32(ErrorCode::ERROR_EX_ILLEGAL_STATE); // write exception code + reply.WriteInt32(-1); + } else { + reply.WriteInt32(NO_ERROR); + int32_t size = properties.size(); + reply.WriteInt32(size); + for(int32_t i=0; i properties; + int32_t ret = listInputMethod(&properties); + if (ret != ErrorCode::NO_ERROR) { + reply.WriteInt32(ErrorCode::ERROR_EX_ILLEGAL_STATE); // write exception code + reply.WriteInt32(-1); + return ret; + } reply.WriteInt32(NO_ERROR); int32_t size = properties.size(); reply.WriteInt32(size); @@ -121,159 +138,140 @@ int32_t InputMethodSystemAbilityStub::OnRemoteRequest(uint32_t code, MessageParc reply.WriteParcelable(properties[i]); } properties.clear(); + break; } - break; - } - case LIST_INPUT_METHOD: { - std::vector properties; - int32_t ret = listInputMethod(&properties); - if (ret != ErrorCode::NO_ERROR) { - reply.WriteInt32(ErrorCode::ERROR_EX_ILLEGAL_STATE); // write exception code - reply.WriteInt32(-1); - return ret; - } - reply.WriteInt32(NO_ERROR); - int32_t size = properties.size(); - reply.WriteInt32(size); - for(int32_t i=0; i kbdTypes; - int32_t ret = listKeyboardType(imeId, &kbdTypes); - if (ret != ErrorCode::NO_ERROR) { - reply.WriteInt32(ErrorCode::ERROR_EX_ILLEGAL_STATE); - reply.WriteInt32(-1); - return ret; + case LIST_KEYBOARD_TYPE: { + std::u16string imeId = data.ReadString16(); + std::vector kbdTypes; + int32_t ret = listKeyboardType(imeId, &kbdTypes); + if (ret != ErrorCode::NO_ERROR) { + reply.WriteInt32(ErrorCode::ERROR_EX_ILLEGAL_STATE); + reply.WriteInt32(-1); + return ret; + } + reply.WriteInt32(NO_ERROR); + int32_t size = kbdTypes.size(); + reply.WriteInt32(size); + for(int32_t i=0; iWriteInt32(userId); - parcel->WriteInt32(pid); - parcel->WriteInt32(uid); - parcel->WriteInt32(data.ReadInt32()); - parcel->WriteRemoteObject(data.ReadRemoteObject()); - parcel->WriteRemoteObject(data.ReadRemoteObject()); - parcel->WriteParcelable(data.ReadParcelable()); - - Message* msg = new Message(MSG_ID_PREPARE_INPUT, parcel); - MessageHandler::Instance()->SendMessage(msg); -} - -/*! Release input -\n Send releaseInput command to work thread. - The handling of releaseInput is in the work thread of PerUserSession. -\see PerUserSession::OnReleaseInput -\param data the parcel in which the parameters are saved -*/ -void InputMethodSystemAbilityStub::releaseInput(MessageParcel& data) -{ - IMSA_HILOGE("InputMethodSystemAbilityStub::releaseInput"); - int32_t uid = IPCSkeleton::GetCallingUid(); - int32_t userId = getUserId(uid); - MessageParcel* parcel = new MessageParcel(); - parcel->WriteInt32(userId); - parcel->WriteRemoteObject(data.ReadRemoteObject()); + /*! Prepare input + \n Send prepareInput command to work thread. + The handling of prepareInput is in the work thread of PerUserSession. + \see PerUserSession::OnPrepareInput + \param data the parcel in which the parameters are saved + */ + void InputMethodSystemAbilityStub::prepareInput(MessageParcel& data) + { + IMSA_HILOGI("InputMethodSystemAbilityStub::prepareInput"); + int32_t pid = IPCSkeleton::GetCallingPid(); + int32_t uid = IPCSkeleton::GetCallingUid(); + int32_t userId = getUserId(uid); + MessageParcel* parcel = new MessageParcel(); + parcel->WriteInt32(userId); + parcel->WriteInt32(pid); + parcel->WriteInt32(uid); + parcel->WriteInt32(data.ReadInt32()); + parcel->WriteRemoteObject(data.ReadRemoteObject()); + parcel->WriteRemoteObject(data.ReadRemoteObject()); + parcel->WriteParcelable(data.ReadParcelable()); - Message* msg = new Message(MSG_ID_RELEASE_INPUT, parcel); - MessageHandler::Instance()->SendMessage(msg); + Message* msg = new Message(MSG_ID_PREPARE_INPUT, parcel); + MessageHandler::Instance()->SendMessage(msg); + } -} + /*! Release input + \n Send releaseInput command to work thread. + The handling of releaseInput is in the work thread of PerUserSession. + \see PerUserSession::OnReleaseInput + \param data the parcel in which the parameters are saved + */ + void InputMethodSystemAbilityStub::releaseInput(MessageParcel& data) + { + IMSA_HILOGE("InputMethodSystemAbilityStub::releaseInput"); + int32_t uid = IPCSkeleton::GetCallingUid(); + int32_t userId = getUserId(uid); + MessageParcel* parcel = new MessageParcel(); + parcel->WriteInt32(userId); + parcel->WriteRemoteObject(data.ReadRemoteObject()); -/*! Start input -\n Send startInput command to work thread. - The handling of startInput is in the work thread of PerUserSession. -\see PerUserSession::OnStartInput -\param data the parcel in which the parameters are saved -*/ -void InputMethodSystemAbilityStub::startInput(MessageParcel& data) -{ - int32_t uid = IPCSkeleton::GetCallingUid(); - int32_t userId = getUserId(uid); - MessageParcel* parcel = new MessageParcel(); - parcel->WriteInt32(userId); - parcel->WriteRemoteObject(data.ReadRemoteObject()); + Message* msg = new Message(MSG_ID_RELEASE_INPUT, parcel); + MessageHandler::Instance()->SendMessage(msg); - Message* msg = new Message(MSG_ID_START_INPUT, parcel); - MessageHandler::Instance()->SendMessage(msg); -} + } -/*! Stop input -\n Send stopInput command to work thread. - The handling of stopInput is in the work thread of PerUserSession. -\see PerUserSession::OnStopInput -\param data the parcel in which the parameters are saved -*/ -void InputMethodSystemAbilityStub::stopInput(MessageParcel& data) -{ - int32_t uid = IPCSkeleton::GetCallingUid(); - int32_t userId = getUserId(uid); - MessageParcel* parcel = new MessageParcel(); - parcel->WriteInt32(userId); - parcel->WriteRemoteObject(data.ReadRemoteObject()); + /*! Start input + \n Send startInput command to work thread. + The handling of startInput is in the work thread of PerUserSession. + \see PerUserSession::OnStartInput + \param data the parcel in which the parameters are saved + */ + void InputMethodSystemAbilityStub::startInput(MessageParcel& data) + { + int32_t uid = IPCSkeleton::GetCallingUid(); + int32_t userId = getUserId(uid); + MessageParcel* parcel = new MessageParcel(); + parcel->WriteInt32(userId); + parcel->WriteRemoteObject(data.ReadRemoteObject()); - Message* msg = new Message(MSG_ID_STOP_INPUT, parcel); - MessageHandler::Instance()->SendMessage(msg); -} + Message* msg = new Message(MSG_ID_START_INPUT, parcel); + MessageHandler::Instance()->SendMessage(msg); + } - /*! Prepare input -\n Send prepareInput command to work thread. - The handling of prepareInput is in the work thread of PerUserSession. -\see PerUserSession::OnPrepareInput -\param data the parcel in which the parameters are saved -*/ - void InputMethodSystemAbilityStub::setInputMethodCoreFromHap(MessageParcel& data) + /*! Stop input + \n Send stopInput command to work thread. + The handling of stopInput is in the work thread of PerUserSession. + \see PerUserSession::OnStopInput + \param data the parcel in which the parameters are saved + */ + void InputMethodSystemAbilityStub::stopInput(MessageParcel& data) { - IMSA_HILOGI("InputMethodSystemAbilityStub::setInputMethodCoreFromHap"); int32_t uid = IPCSkeleton::GetCallingUid(); int32_t userId = getUserId(uid); MessageParcel* parcel = new MessageParcel(); parcel->WriteInt32(userId); parcel->WriteRemoteObject(data.ReadRemoteObject()); - Message* msg = new Message(MSG_ID_SET_INPUT_METHOD_CORE, parcel); + Message* msg = new Message(MSG_ID_STOP_INPUT, parcel); MessageHandler::Instance()->SendMessage(msg); } -/*! Get user id from uid -\param uid the uid from which the remote call is -\return return user id of the remote caller -*/ -int32_t InputMethodSystemAbilityStub::getUserId(int32_t uid) -{ - return uid/1000000; -} -} + /*! Prepare input + \n Send prepareInput command to work thread. + The handling of prepareInput is in the work thread of PerUserSession. + \see PerUserSession::OnPrepareInput + \param data the parcel in which the parameters are saved + */ + void InputMethodSystemAbilityStub::setInputMethodCoreFromHap(MessageParcel& data) + { + IMSA_HILOGI("InputMethodSystemAbilityStub::setInputMethodCoreFromHap"); + int32_t uid = IPCSkeleton::GetCallingUid(); + int32_t userId = getUserId(uid); + MessageParcel* parcel = new MessageParcel(); + parcel->WriteInt32(userId); + parcel->WriteRemoteObject(data.ReadRemoteObject()); + + Message* msg = new Message(MSG_ID_SET_INPUT_METHOD_CORE, parcel); + MessageHandler::Instance()->SendMessage(msg); + } + + /*! Get user id from uid + \param uid the uid from which the remote call is + \return return user id of the remote caller + */ + int32_t InputMethodSystemAbilityStub::getUserId(int32_t uid) + { + return uid/1000000; + } } +} \ No newline at end of file diff --git a/services/src/keyboard_type.cpp b/services/src/keyboard_type.cpp index 269cd75bb7edefb6e71dc4cdd22d7bb8c4529ac3..a3839c68c156448d99c18219b386cb0f3c03a8ea 100644 --- a/services/src/keyboard_type.cpp +++ b/services/src/keyboard_type.cpp @@ -17,171 +17,171 @@ namespace OHOS { namespace MiscServices { -using namespace std; -/*! Constructor -*/ -KeyboardType::KeyboardType() -{ -} + using namespace std; + /*! Constructor + */ + KeyboardType::KeyboardType() + { + } -/*! Constructor from another instance - \param type the source instance -*/ -KeyboardType::KeyboardType(const KeyboardType& type) -{ - mId = type.mId; - mHashCode = type.mHashCode; - mLabelId = type.mLabelId; - mIconId = type.mIconId; - mIsAsciiCapable = type.mIsAsciiCapable; - mLanguage = type.mLanguage; - mInputSource = type.mInputSource; - mCustomizedValue = type.mCustomizedValue; -} + /*! Constructor from another instance + \param type the source instance + */ + KeyboardType::KeyboardType(const KeyboardType& type) + { + mId = type.mId; + mHashCode = type.mHashCode; + mLabelId = type.mLabelId; + mIconId = type.mIconId; + mIsAsciiCapable = type.mIsAsciiCapable; + mLanguage = type.mLanguage; + mInputSource = type.mInputSource; + mCustomizedValue = type.mCustomizedValue; + } -/*! Destructor -*/ -KeyboardType::~KeyboardType() -{ -} + /*! Destructor + */ + KeyboardType::~KeyboardType() + { + } + + /*! Get value from another instance + \param type source instance + \return return this + */ + KeyboardType& KeyboardType::operator=(const KeyboardType& type) + { + if (this == &type) { + return *this; + } + + mId = type.mId; + mHashCode = type.mHashCode; + mLabelId = type.mLabelId; + mIconId = type.mIconId; + mIsAsciiCapable = type.mIsAsciiCapable; + mLanguage = type.mLanguage; + mInputSource = type.mInputSource; + mCustomizedValue = type.mCustomizedValue; -/*! Get value from another instance - \param type source instance - \return return this -*/ -KeyboardType& KeyboardType::operator=(const KeyboardType& type) -{ - if (this == &type) { return *this; } - mId = type.mId; - mHashCode = type.mHashCode; - mLabelId = type.mLabelId; - mIconId = type.mIconId; - mIsAsciiCapable = type.mIsAsciiCapable; - mLanguage = type.mLanguage; - mInputSource = type.mInputSource; - mCustomizedValue = type.mCustomizedValue; - - return *this; -} + /*! Write the details of object to parcel + */ + bool KeyboardType::Marshalling(Parcel &parcel) const + { + if (!(parcel.WriteInt32(mId) + && parcel.WriteInt32(mHashCode) + && parcel.WriteInt32(mLabelId) + && parcel.WriteInt32(mIconId) + && parcel.WriteBool(mIsAsciiCapable) + && parcel.WriteString16(mLanguage) + && parcel.WriteString16(mInputSource) + && parcel.WriteString16(mCustomizedValue))) + return false; + return true; + } -/*! Write the details of object to parcel -*/ -bool KeyboardType::Marshalling(Parcel &parcel) const -{ - if (!(parcel.WriteInt32(mId) - && parcel.WriteInt32(mHashCode) - && parcel.WriteInt32(mLabelId) - && parcel.WriteInt32(mIconId) - && parcel.WriteBool(mIsAsciiCapable) - && parcel.WriteString16(mLanguage) - && parcel.WriteString16(mInputSource) - && parcel.WriteString16(mCustomizedValue))) - return false; - return true; -} + /*! Read the details of object from parcel + \param parcel read the details of object from this parcel + \return ErrorCode::NO_ERROR + \return ErrorCode::ERROR_NULL_POINTER parcel is null + */ + KeyboardType* KeyboardType::Unmarshalling(Parcel &parcel) + { + auto info = new KeyboardType(); + info->mId = parcel.ReadInt32(); + info->mHashCode = parcel.ReadInt32(); + info->mLabelId = parcel.ReadInt32(); + info->mIconId = parcel.ReadInt32(); + info->mIsAsciiCapable = parcel.ReadBool(); + info->mLanguage = parcel.ReadString16(); + info->mInputSource = parcel.ReadString16(); + info->mCustomizedValue = parcel.ReadString16(); + return info; + } -/*! Read the details of object from parcel - \param parcel read the details of object from this parcel - \return ErrorCode::NO_ERROR - \return ErrorCode::ERROR_NULL_POINTER parcel is null -*/ -KeyboardType* KeyboardType::Unmarshalling(Parcel &parcel) -{ - auto info = new KeyboardType(); - info->mId = parcel.ReadInt32(); - info->mHashCode = parcel.ReadInt32(); - info->mLabelId = parcel.ReadInt32(); - info->mIconId = parcel.ReadInt32(); - info->mIsAsciiCapable = parcel.ReadBool(); - info->mLanguage = parcel.ReadString16(); - info->mInputSource = parcel.ReadString16(); - info->mCustomizedValue = parcel.ReadString16(); - return info; -} + void KeyboardType::setId(int32_t typeId) + { + mId = typeId; + if (typeId != ID_NONE) { + mHashCode = typeId; + } else { + mHashCode = ID_NONE; + } -void KeyboardType::setId(int32_t typeId) -{ - mId = typeId; - if (typeId != ID_NONE) { - mHashCode = typeId; - } else { - mHashCode = ID_NONE; } - -} -void KeyboardType::setLabelId(int32_t labelId) -{ - mLabelId = labelId; -} + void KeyboardType::setLabelId(int32_t labelId) + { + mLabelId = labelId; + } -void KeyboardType::setIconId(int32_t iconId) -{ - mIconId = iconId; -} + void KeyboardType::setIconId(int32_t iconId) + { + mIconId = iconId; + } -void KeyboardType::setAsciiCapability(bool isAsciiCapable) -{ - mIsAsciiCapable = isAsciiCapable; -} + void KeyboardType::setAsciiCapability(bool isAsciiCapable) + { + mIsAsciiCapable = isAsciiCapable; + } -void KeyboardType::setLanguage(u16string language) -{ - mLanguage = language; -} + void KeyboardType::setLanguage(u16string language) + { + mLanguage = language; + } -void KeyboardType::setInputSource(u16string inputSource) -{ - mInputSource = inputSource; -} + void KeyboardType::setInputSource(u16string inputSource) + { + mInputSource = inputSource; + } -void KeyboardType::setCustomizedValue(u16string keyBoardTypeCustomizedValue) -{ - mCustomizedValue = keyBoardTypeCustomizedValue; -} + void KeyboardType::setCustomizedValue(u16string keyBoardTypeCustomizedValue) + { + mCustomizedValue = keyBoardTypeCustomizedValue; + } -int32_t KeyboardType::getId() const -{ - return mId; -} + int32_t KeyboardType::getId() const + { + return mId; + } -int32_t KeyboardType::getLabelId() const -{ - return mLabelId; -} + int32_t KeyboardType::getLabelId() const + { + return mLabelId; + } -int32_t KeyboardType::getIconId() const -{ - return mIconId; -} + int32_t KeyboardType::getIconId() const + { + return mIconId; + } -/*! Get hash code of the object - \return return hashCode value -*/ -int KeyboardType::getHashCode() const -{ - return mHashCode; -} + /*! Get hash code of the object + \return return hashCode value + */ + int KeyboardType::getHashCode() const + { + return mHashCode; + } -/*! Get language of the object - \return return the language of this object -*/ -u16string KeyboardType::getLanguage() const -{ - return mLanguage; -} + /*! Get language of the object + \return return the language of this object + */ + u16string KeyboardType::getLanguage() const + { + return mLanguage; + } -u16string KeyboardType::getInputSource() const -{ - return mInputSource; -} + u16string KeyboardType::getInputSource() const + { + return mInputSource; + } -u16string KeyboardType::getCustomizedValue() const -{ - return mCustomizedValue; -} + u16string KeyboardType::getCustomizedValue() const + { + return mCustomizedValue; + } } } \ No newline at end of file diff --git a/services/src/message.cpp b/services/src/message.cpp index fa5d1c82cbdebe5ca7635792ca1b93b13c08fdd8..3868f78088e3a06cf5091e72b04a7f0e96e9da49 100644 --- a/services/src/message.cpp +++ b/services/src/message.cpp @@ -17,57 +17,56 @@ namespace OHOS { namespace MiscServices { -/*! Constructor -\param msgId a message Id -\param msgContent the content of a message -*/ -Message::Message(int32_t msgId, MessageParcel* msgContent) -{ - msgId_ = msgId; - msgContent_ = msgContent; - if (msgContent_) { - msgContent_->RewindRead(0); + /*! Constructor + \param msgId a message Id + \param msgContent the content of a message + */ + Message::Message(int32_t msgId, MessageParcel* msgContent) + { + msgId_ = msgId; + msgContent_ = msgContent; + if (msgContent_) { + msgContent_->RewindRead(0); + } } -} -/*! Constructor -\param msg a source message -*/ -Message::Message(const Message& msg) -{ - msgId_ = msg.msgId_; - if (msgContent_ != nullptr) { - delete msgContent_; - } - MessageParcel* src = msg.msgContent_; - if (src) { - msgContent_ = new MessageParcel(); - msgContent_->ParseFrom(src->GetData(), src->GetDataSize()); -// msgContent_->RewindRead(0); + /*! Constructor + \param msg a source message + */ + Message::Message(const Message& msg) + { + msgId_ = msg.msgId_; + if (msgContent_ != nullptr) { + delete msgContent_; + } + MessageParcel* src = msg.msgContent_; + if (src) { + msgContent_ = new MessageParcel(); + msgContent_->ParseFrom(src->GetData(), src->GetDataSize()); + } } -} -Message& Message::operator=(const Message& msg) -{ - if (this == &msg) { + Message& Message::operator=(const Message& msg) + { + if (this == &msg) { + return *this; + } + msgId_ = msg.msgId_; + if (msgContent_ != nullptr) { + delete msgContent_; + } + if (msg.msgContent_) { + msgContent_ = new MessageParcel(); + msgContent_->ParseFrom(msg.msgContent_->GetData(), msg.msgContent_->GetDataSize()); + msgContent_->RewindRead(0); + } return *this; } - msgId_ = msg.msgId_; - if (msgContent_ != nullptr) { - delete msgContent_; - } - if (msg.msgContent_) { - msgContent_ = new MessageParcel(); - msgContent_->ParseFrom(msg.msgContent_->GetData(), msg.msgContent_->GetDataSize()); - msgContent_->RewindRead(0); - } - return *this; -} -Message::~Message( ) { - if (msgContent_) { - delete msgContent_; + Message::~Message( ) { + if (msgContent_) { + delete msgContent_; + } } } -} } \ No newline at end of file diff --git a/services/src/peruser_session.cpp b/services/src/peruser_session.cpp index db7f4524dbc8da2942ccdace37c0aeb90871d0f4..259f1d03cbfd28f36ac229ac37e2ddfe8f05932c 100644 --- a/services/src/peruser_session.cpp +++ b/services/src/peruser_session.cpp @@ -115,639 +115,647 @@ namespace MiscServices { inputMethodAbility_ = inputMethodAbility; } - /*! Work thread for this user - */ - void PerUserSession::WorkThread() - { - if (msgHandler == nullptr) { - return ; - } - while(1){ - Message* msg = msgHandler->GetMessage(); - std::unique_lock lock(mtx); - switch(msg->msgId_) { - case MSG_ID_USER_LOCK: - case MSG_ID_EXIT_SERVICE: { - OnUserLocked(); - delete msg; - return; - } - case MSG_ID_PREPARE_INPUT: { - OnPrepareInput(msg); - break; - } - case MSG_ID_RELEASE_INPUT: { - OnReleaseInput(msg); - break; - } - case MSG_ID_START_INPUT: { - OnStartInput(msg); - break; - } - case MSG_ID_STOP_INPUT: { - OnStopInput(msg); - break; - } - case MSG_ID_SET_INPUT_METHOD_CORE:{ - onSetInputMethodCore(msg); - break; - } - case MSG_ID_CLIENT_DIED: { - wptr who = msg->msgContent_->ReadRemoteObject(); - OnClientDied(who); - break; - } - case MSG_ID_IMS_DIED: { - wptr who = msg->msgContent_->ReadRemoteObject(); - OnImsDied(who); - break; - } - case MSG_ID_HIDE_KEYBOARD_SELF: { - int flag = msg->msgContent_->ReadInt32(); - OnHideKeyboardSelf(flag); - break; - } - case MSG_ID_ADVANCE_TO_NEXT: { - OnAdvanceToNext(); - break; - } - case MSG_ID_SET_DISPLAY_MODE: { - int mode = msg->msgContent_->ReadInt32(); - OnSetDisplayMode(mode); - break; - } - case MSG_ID_RESTART_IMS: { - int index = msg->msgContent_->ReadInt32(); - std::u16string imeId = msg->msgContent_->ReadString16(); - OnRestartIms(index, imeId); - break; - } - default: { - break; - } + /*! Work thread for this user + */ + void PerUserSession::WorkThread() + { + if (msgHandler == nullptr) { + return ; + } + while(1){ + Message* msg = msgHandler->GetMessage(); + std::unique_lock lock(mtx); + switch(msg->msgId_) { + case MSG_ID_USER_LOCK: + case MSG_ID_EXIT_SERVICE: { + OnUserLocked(); + delete msg; + return; + } + case MSG_ID_PREPARE_INPUT: { + OnPrepareInput(msg); + break; + } + case MSG_ID_RELEASE_INPUT: { + OnReleaseInput(msg); + break; + } + case MSG_ID_START_INPUT: { + OnStartInput(msg); + break; + } + case MSG_ID_STOP_INPUT: { + OnStopInput(msg); + break; + } + case MSG_ID_SET_INPUT_METHOD_CORE:{ + onSetInputMethodCore(msg); + break; + } + case MSG_ID_CLIENT_DIED: { + wptr who = msg->msgContent_->ReadRemoteObject(); + OnClientDied(who); + break; + } + case MSG_ID_IMS_DIED: { + wptr who = msg->msgContent_->ReadRemoteObject(); + OnImsDied(who); + break; + } + case MSG_ID_HIDE_KEYBOARD_SELF: { + int flag = msg->msgContent_->ReadInt32(); + OnHideKeyboardSelf(flag); + break; + } + case MSG_ID_ADVANCE_TO_NEXT: { + OnAdvanceToNext(); + break; + } + case MSG_ID_SET_DISPLAY_MODE: { + int mode = msg->msgContent_->ReadInt32(); + OnSetDisplayMode(mode); + break; + } + case MSG_ID_RESTART_IMS: { + int index = msg->msgContent_->ReadInt32(); + std::u16string imeId = msg->msgContent_->ReadString16(); + OnRestartIms(index, imeId); + break; + } + default: { + break; } - delete msg; } + delete msg; } + } - /*! Set display Id - \param displayId the Id of display screen on which the input method keyboard show. - */ - void PerUserSession::SetDisplayId(int displayId) - { - this->displayId = displayId; - } - - /*! Set the current input method engine - \param ime the current (default) IME pointer referred to the instance in PerUserSetting. - */ - void PerUserSession::SetCurrentIme(InputMethodProperty* ime) - { - currentIme[DEFAULT_IME] = ime; - userState = UserState::USER_STATE_UNLOCKED; - } + /*! Set display Id + \param displayId the Id of display screen on which the input method keyboard show. + */ + void PerUserSession::SetDisplayId(int displayId) + { + this->displayId = displayId; + } - /*! Set the system security input method engine - \param ime system security IME pointer referred to the instance in PerUserSetting. - */ - void PerUserSession::SetSecurityIme(InputMethodProperty* ime) - { - currentIme[SECURITY_IME] = ime; - } + /*! Set the current input method engine + \param ime the current (default) IME pointer referred to the instance in PerUserSetting. + */ + void PerUserSession::SetCurrentIme(InputMethodProperty* ime) + { + currentIme[DEFAULT_IME] = ime; + userState = UserState::USER_STATE_UNLOCKED; + } - /*! Set the input method setting data - \param setting InputMethodSetting pointer referred to the instance in PerUserSetting. - */ - void PerUserSession::SetInputMethodSetting(InputMethodSetting* setting) - { - inputMethodSetting = setting; - } + /*! Set the system security input method engine + \param ime system security IME pointer referred to the instance in PerUserSetting. + */ + void PerUserSession::SetSecurityIme(InputMethodProperty* ime) + { + currentIme[SECURITY_IME] = ime; + } - /*! Reset input method engine - \param defaultIme default ime pointer referred to the instance in PerUserSetting - \param security security ime pointer referred to the instance in PerUserSetting - \n Two input method engines can be running at the same time for one user. - \n One is the default ime, another is security ime - */ - void PerUserSession::ResetIme(InputMethodProperty* defaultIme, InputMethodProperty* securityIme) - { - IMSA_HILOGI("PerUserSession::ResetIme"); - std::unique_lock lock(mtx); - InputMethodProperty* ime[] = {defaultIme, securityIme}; - for(int i=0; i<2; i++) { - if (currentIme[i] == ime[i] && ime[i] != nullptr) { - continue; - } - if (imsCore[i]) { - StopInputMethod(i); - } - IncreaseOrResetImeError(true, i); - currentIme[i] = ime[i]; - if (currentIme[i]==nullptr) { - if (needReshowClient && GetImeIndex(needReshowClient)==i) { - needReshowClient = nullptr; - } - continue; - } + /*! Set the input method setting data + \param setting InputMethodSetting pointer referred to the instance in PerUserSetting. + */ + void PerUserSession::SetInputMethodSetting(InputMethodSetting* setting) + { + inputMethodSetting = setting; + } - std::map, ClientInfo*>::const_iterator it; - bool flag = false; - for(it=mapClients.cbegin(); it!=mapClients.cend(); ++it) { - if ((i == DEFAULT_IME && it->second->attribute.GetSecurityFlag() == false) || - (i == SECURITY_IME && it->second->attribute.GetSecurityFlag() == true)) { - flag = true; - break; - } - } - if (flag) { - int ret = StartInputMethod(i); - if (needReshowClient && GetImeIndex(needReshowClient)==i) { - if (ret==ErrorCode::NO_ERROR) { - ShowKeyboard(needReshowClient); - } - needReshowClient = nullptr; - } + /*! Reset input method engine + \param defaultIme default ime pointer referred to the instance in PerUserSetting + \param security security ime pointer referred to the instance in PerUserSetting + \n Two input method engines can be running at the same time for one user. + \n One is the default ime, another is security ime + */ + void PerUserSession::ResetIme(InputMethodProperty* defaultIme, InputMethodProperty* securityIme) + { + IMSA_HILOGI("PerUserSession::ResetIme"); + std::unique_lock lock(mtx); + InputMethodProperty* ime[] = {defaultIme, securityIme}; + for(int i=0; i<2; i++) { + if (currentIme[i] == ime[i] && ime[i] != nullptr) { + continue; + } + if (imsCore[i]) { + StopInputMethod(i); + } + IncreaseOrResetImeError(true, i); + currentIme[i] = ime[i]; + if (currentIme[i]==nullptr) { + if (needReshowClient && GetImeIndex(needReshowClient)==i) { + needReshowClient = nullptr; } + continue; } - } - /*! Called when a package is removed - \param packageName the name of package removed - */ - void PerUserSession::OnPackageRemoved(const std::u16string& packageName) - { - IMSA_HILOGI("PerUserSession::OnPackageRemoved"); - InputMethodSetting tmpSetting; + std::map, ClientInfo*>::const_iterator it; bool flag = false; - std::unique_lock lock(mtx); - for(int i=0; imPackageName == packageName) { - if (currentClient && GetImeIndex(currentClient)==i) { - needReshowClient = currentClient; - HideKeyboard(currentClient); - } - StopInputMethod(i); - currentIme[i] = nullptr; - if (i==DEFAULT_IME) { - tmpSetting.SetCurrentKeyboardType(-1); - inputMethodSetting->SetCurrentKeyboardType(-1); - } else if (i==SECURITY_IME) { - tmpSetting.SetCurrentSysKeyboardType(-1); - inputMethodSetting->SetCurrentSysKeyboardType(-1); - } - currentKbdIndex[i] = 0; + for(it=mapClients.cbegin(); it!=mapClients.cend(); ++it) { + if ((i == DEFAULT_IME && it->second->attribute.GetSecurityFlag() == false) || + (i == SECURITY_IME && it->second->attribute.GetSecurityFlag() == true)) { flag = true; + break; } } if (flag) { - Platform::Instance()->SetInputMethodSetting(userId_, tmpSetting); + int ret = StartInputMethod(i); + if (needReshowClient && GetImeIndex(needReshowClient)==i) { + if (ret==ErrorCode::NO_ERROR) { + ShowKeyboard(needReshowClient); + } + needReshowClient = nullptr; + } } - } + } - /*! Add an input client - \param pid the process pid of the input client - \param uid the uid of the the input client - \param displayId the display id of the input client - \param inputClient the remote object handler of the input client - \param channel the remote InputDataChannel object handler for the input client. - \n It will be transferred to input method service - \param attribute the input attribute of the input client. - \return \li ErrorCode::NO_ERROR no error - \return \li ErrorCode::ERROR_CLIENT_DUPLICATED client is duplicated - */ - int PerUserSession::AddClient(int pid, int uid, int displayId, const sptr& inputClient, - const sptr& channel, - const InputAttribute& attribute) - { - IMSA_HILOGI("PerUserSession::AddClient"); - ClientInfo* clientInfo = GetClientInfo(inputClient); - if (clientInfo != nullptr) { - IMSA_HILOGE("PerUserSession::AddClient clientInfo is not nullptr"); - return ErrorCode::ERROR_CLIENT_DUPLICATED; + /*! Called when a package is removed + \param packageName the name of package removed + */ + void PerUserSession::OnPackageRemoved(const std::u16string& packageName) + { + IMSA_HILOGI("PerUserSession::OnPackageRemoved"); + InputMethodSetting tmpSetting; + bool flag = false; + std::unique_lock lock(mtx); + for(int i=0; imPackageName == packageName) { + if (currentClient && GetImeIndex(currentClient)==i) { + needReshowClient = currentClient; + HideKeyboard(currentClient); + } + StopInputMethod(i); + currentIme[i] = nullptr; + if (i==DEFAULT_IME) { + tmpSetting.SetCurrentKeyboardType(-1); + inputMethodSetting->SetCurrentKeyboardType(-1); + } else if (i==SECURITY_IME) { + tmpSetting.SetCurrentSysKeyboardType(-1); + inputMethodSetting->SetCurrentSysKeyboardType(-1); + } + currentKbdIndex[i] = 0; + flag = true; } + } + if (flag) { + Platform::Instance()->SetInputMethodSetting(userId_, tmpSetting); + } + } - sptr obj = inputClient->AsObject(); - if (obj == nullptr) { - IMSA_HILOGE("PerUserSession::AddClient inputClient AsObject is nullptr"); - return ErrorCode::ERROR_REMOTE_CLIENT_DIED; - } - clientInfo = new ClientInfo(pid, uid, userId_, displayId, inputClient, channel, attribute); - mapClients.insert(std::pair, ClientInfo*>(obj, clientInfo)); - int ret = obj->AddDeathRecipient(clientDeathRecipient); - if (ret != ErrorCode::NO_ERROR) { - IMSA_HILOGE("PerUserSession::AddClient AddDeathRecipient return : %{public}s [%{public}d]", ErrorCode::ToString(ret), userId_); - } - return ErrorCode::NO_ERROR; + /*! Add an input client + \param pid the process pid of the input client + \param uid the uid of the the input client + \param displayId the display id of the input client + \param inputClient the remote object handler of the input client + \param channel the remote InputDataChannel object handler for the input client. + \n It will be transferred to input method service + \param attribute the input attribute of the input client. + \return \li ErrorCode::NO_ERROR no error + \return \li ErrorCode::ERROR_CLIENT_DUPLICATED client is duplicated + */ + int PerUserSession::AddClient(int pid, int uid, int displayId, const sptr& inputClient, + const sptr& channel, + const InputAttribute& attribute) + { + IMSA_HILOGI("PerUserSession::AddClient"); + ClientInfo* clientInfo = GetClientInfo(inputClient); + if (clientInfo != nullptr) { + IMSA_HILOGE("PerUserSession::AddClient clientInfo is not nullptr"); + return ErrorCode::ERROR_CLIENT_DUPLICATED; } - /*! Remove an input client - \param inputClient remote object handler of the input client - \param[out] remainClientNum remained count of the same kinds of clients for this user - \n (i.e. if inputClient is an normal client, remainClientNum is the count of remained normal clients. - \n if inputClient is a security client, remainClientNum is the count of remained security clients.) - \return ErrorCode::NO_ERROR no error - \return ErrorCode::ERROR_CLIENT_NOT_FOUND client is not found - */ - int PerUserSession::RemoveClient(const sptr& inputClient, int *remainClientNum) - { - IMSA_HILOGE("PerUserSession::RemoveClient"); - sptr b = inputClient->AsObject(); - std::map, ClientInfo*>::iterator it = mapClients.find(b); - if (it == mapClients.end()) { - IMSA_HILOGE("PerUserSession::RemoveClient %{public}s [%{public}d]", ErrorCode::ToString(ErrorCode::ERROR_CLIENT_NOT_FOUND), userId_); - return ErrorCode::ERROR_CLIENT_NOT_FOUND; - } - ClientInfo* clientInfo = it->second; - bool flag = clientInfo->attribute.GetSecurityFlag(); - int ret = b->RemoveDeathRecipient(clientDeathRecipient); - if (ret != ErrorCode::NO_ERROR) { - IMSA_HILOGE("PerUserSession::RemoveClient RemoveDeathRecipient return : %{public}s [%{public}d]\n", ErrorCode::ToString(ret), userId_); - } - ret = clientInfo->client->onInputReleased(0); - if (ret != ErrorCode::NO_ERROR) { - IMSA_HILOGE("PerUserSession::RemoveClient onInputReleased return : %{public}s [%{public}d]\n", ErrorCode::ToString(ret), userId_); - } - delete clientInfo; - mapClients.erase(it); - - if(remainClientNum!=nullptr) { - *remainClientNum = 0; - for(it=mapClients.begin(); it!=mapClients.end(); ++it) { - if (it->second->attribute.GetSecurityFlag() == flag) { - (*remainClientNum)++; - } + sptr obj = inputClient->AsObject(); + if (obj == nullptr) { + IMSA_HILOGE("PerUserSession::AddClient inputClient AsObject is nullptr"); + return ErrorCode::ERROR_REMOTE_CLIENT_DIED; + } + clientInfo = new ClientInfo(pid, uid, userId_, displayId, inputClient, channel, attribute); + mapClients.insert(std::pair, ClientInfo*>(obj, clientInfo)); + int ret = obj->AddDeathRecipient(clientDeathRecipient); + if (ret != ErrorCode::NO_ERROR) { + IMSA_HILOGE("PerUserSession::AddClient AddDeathRecipient return : %{public}s", ErrorCode::ToString(ret)); + } + return ErrorCode::NO_ERROR; + } + + /*! Remove an input client + \param inputClient remote object handler of the input client + \param[out] remainClientNum remained count of the same kinds of clients for this user + \n (i.e. if inputClient is an normal client, remainClientNum is the count of remained normal clients. + \n if inputClient is a security client, remainClientNum is the count of remained security clients.) + \return ErrorCode::NO_ERROR no error + \return ErrorCode::ERROR_CLIENT_NOT_FOUND client is not found + */ + int PerUserSession::RemoveClient(const sptr& inputClient, int *remainClientNum) + { + IMSA_HILOGE("PerUserSession::RemoveClient"); + sptr b = inputClient->AsObject(); + std::map, ClientInfo*>::iterator it = mapClients.find(b); + if (it == mapClients.end()) { + IMSA_HILOGE("PerUserSession::RemoveClient ErrorCode::ERROR_CLIENT_NOT_FOUND"); + return ErrorCode::ERROR_CLIENT_NOT_FOUND; + } + ClientInfo* clientInfo = it->second; + bool flag = clientInfo->attribute.GetSecurityFlag(); + int ret = b->RemoveDeathRecipient(clientDeathRecipient); + if (ret != ErrorCode::NO_ERROR) { + IMSA_HILOGE("PerUserSession::RemoveClient RemoveDeathRecipient return : %{public}s", ErrorCode::ToString(ret)); + } + ret = clientInfo->client->onInputReleased(0); + if (ret != ErrorCode::NO_ERROR) { + IMSA_HILOGE("PerUserSession::RemoveClient onInputReleased return : %{public}s", ErrorCode::ToString(ret)); + } + delete clientInfo; + mapClients.erase(it); + + if(remainClientNum!=nullptr) { + *remainClientNum = 0; + for(it=mapClients.begin(); it!=mapClients.end(); ++it) { + if (it->second->attribute.GetSecurityFlag() == flag) { + (*remainClientNum)++; } } - return ErrorCode::NO_ERROR; } + return ErrorCode::NO_ERROR; + } - /*! Start input method service - \param index it can be 0 or 1. 0 - default ime, 1 - security ime - \return ErrorCode::NO_ERROR no error - \return ErrorCode::ERROR_IME_BIND_FAILED failed to bind ime - \return ErrorCode::ERROR_IME_NOT_AVAILABLE no ime is available - \return ErrorCode::ERROR_SECURITY_IME_NOT_AVAILABLE no security ime is available - \return ErrorCode::ERROR_TOKEN_CREATE_FAILED failed to create window token - \return other errors returned by binder driver - */ - int PerUserSession::StartInputMethod(int index) - { - IMSA_HILOGI("PerUserSession::StartInputMethod index=%{public}d [%{public}d]\n", index, userId_); - - if (imsCore[index] == nullptr) { - IMSA_HILOGI("PerUserSession::StartInputMethod imscore is null"); - return ErrorCode::ERROR_IME_BIND_FAILED; - } + /*! Start input method service + \param index it can be 0 or 1. 0 - default ime, 1 - security ime + \return ErrorCode::NO_ERROR no error + \return ErrorCode::ERROR_IME_BIND_FAILED failed to bind ime + \return ErrorCode::ERROR_IME_NOT_AVAILABLE no ime is available + \return ErrorCode::ERROR_SECURITY_IME_NOT_AVAILABLE no security ime is available + \return ErrorCode::ERROR_TOKEN_CREATE_FAILED failed to create window token + \return other errors returned by binder driver + */ + int PerUserSession::StartInputMethod(int index) + { + IMSA_HILOGI("PerUserSession::StartInputMethod index=%{public}d [%{public}d]\n", index, userId_); - sptr b = imsCore[index]->AsObject(); - inputMethodToken[index] = IPCSkeleton::GetInstance().GetContextObject(); - localControlChannel[index] = new InputControlChannelStub(userId_); - inputControlChannel[index] = localControlChannel[index]; - int ret_init = imsCore[index]->initializeInput(inputMethodToken[index], displayId, inputControlChannel[index]); - if (ret_init != ErrorCode::NO_ERROR) { - IMSA_HILOGE("PerUserSession::StartInputMethod initializeInput return : %{public}s [%{public}d]\n", ErrorCode::ToString(ret_init), userId_); - localControlChannel[index] = nullptr; - inputControlChannel[index] = nullptr; - return ret_init; - } - return ErrorCode::NO_ERROR; + if (imsCore[index] == nullptr) { + IMSA_HILOGI("PerUserSession::StartInputMethod imscore is null"); + return ErrorCode::ERROR_IME_BIND_FAILED; } - /*! Stop input method service - \param index it can be 0 or 1. 0 - default ime, 1 - security ime - \return ErrorCode::NO_ERROR no error - \return ErrorCode::ERROR_IME_NOT_STARTED ime not started - \return ErrorCode::ERROR_IME_UNBIND_FAILED failed to unbind ime - \return ErrorCode::ERROR_TOKEN_DESTROY_FAILED failed to destroy window token - \return other errors returned by binder driver - */ - int PerUserSession::StopInputMethod(int index) - { - IMSA_HILOGI("Start... index = %{public}d [%{public}d]\n", index, userId_); - if (index >= MAX_IME || index < 0) { - IMSA_HILOGE("Aborted! %{public}s [%{public}d]\n", ErrorCode::ToString(ErrorCode::ERROR_BAD_PARAMETERS), userId_); - return ErrorCode::ERROR_BAD_PARAMETERS; - } - if (imsCore[index] == nullptr || currentIme[index] == nullptr) { - IMSA_HILOGE("Aborted! %{public}s [%{public}d]\n", ErrorCode::ToString(ErrorCode::ERROR_IME_NOT_STARTED), userId_); - return ErrorCode::ERROR_IME_NOT_STARTED; - } - if (currentIme[index] == currentIme[1-index] && imsCore[1-index] != nullptr) { - imsCore[index] = nullptr; - inputControlChannel[index] = nullptr; - localControlChannel[index] = nullptr; - IMSA_HILOGI("End...[%{public}d]\n", userId_); - return ErrorCode::NO_ERROR; - } - - IMSA_HILOGD("unbindInputMethodService...\n"); + sptr b = imsCore[index]->AsObject(); + inputMethodToken[index] = IPCSkeleton::GetInstance().GetContextObject(); + localControlChannel[index] = new InputControlChannelStub(userId_); + inputControlChannel[index] = localControlChannel[index]; + int ret_init = imsCore[index]->initializeInput(inputMethodToken[index], displayId, inputControlChannel[index]); + if (ret_init != ErrorCode::NO_ERROR) { + IMSA_HILOGE("PerUserSession::StartInputMethod initializeInput return : %{public}s", ErrorCode::ToString(ret_init)); + localControlChannel[index] = nullptr; + inputControlChannel[index] = nullptr; + return ret_init; + } + return ErrorCode::NO_ERROR; + } - IMSA_HILOGD("destroyWindowToken...\n"); - int errorCode = ErrorCode::NO_ERROR; - int ret = Platform::Instance()->DestroyWindowToken(userId_, currentIme[index]->mPackageName); - inputMethodToken[index] = nullptr; - if (ret != ErrorCode::NO_ERROR) { - IMSA_HILOGE("destroyWindowToken return : %{public}s [%{public}d]\n", ErrorCode::ToString(ret), userId_); - errorCode = ErrorCode::ERROR_TOKEN_DESTROY_FAILED; - } - sptr b = imsCore[index]->AsObject(); - ret = b->RemoveDeathRecipient(imsDeathRecipient); - if (ret != ErrorCode::NO_ERROR) { - IMSA_HILOGE("RemoveDeathRecipient return : %{public}s [%{public}d]\n", ErrorCode::ToString(ret), userId_); - } + /*! Stop input method service + \param index it can be 0 or 1. 0 - default ime, 1 - security ime + \return ErrorCode::NO_ERROR no error + \return ErrorCode::ERROR_IME_NOT_STARTED ime not started + \return ErrorCode::ERROR_IME_UNBIND_FAILED failed to unbind ime + \return ErrorCode::ERROR_TOKEN_DESTROY_FAILED failed to destroy window token + \return other errors returned by binder driver + */ + int PerUserSession::StopInputMethod(int index) + { + IMSA_HILOGI("Start... index = %{public}d [%{public}d]\n", index, userId_); + if (index >= MAX_IME || index < 0) { + IMSA_HILOGE("Aborted! %{public}s", ErrorCode::ToString(ErrorCode::ERROR_BAD_PARAMETERS)); + return ErrorCode::ERROR_BAD_PARAMETERS; + } + if (imsCore[index] == nullptr || currentIme[index] == nullptr) { + IMSA_HILOGE("Aborted! %{public}s", ErrorCode::ToString(ErrorCode::ERROR_IME_NOT_STARTED)); + return ErrorCode::ERROR_IME_NOT_STARTED; + } + if (currentIme[index] == currentIme[1-index] && imsCore[1-index] != nullptr) { imsCore[index] = nullptr; inputControlChannel[index] = nullptr; localControlChannel[index] = nullptr; IMSA_HILOGI("End...[%{public}d]\n", userId_); - return errorCode; - } - - /*! Show keyboard - \param inputClient the remote object handler of the input client. - \return ErrorCode::NO_ERROR no error - \return ErrorCode::ERROR_IME_NOT_STARTED ime not started - \return ErrorCode::ERROR_KBD_IS_OCCUPIED keyboard is showing by other client - \return ErrorCode::ERROR_CLIENT_NOT_FOUND the input client is not found - \return ErrorCode::ERROR_IME_START_FAILED failed to start input method service - \return ErrorCode::ERROR_KBD_SHOW_FAILED failed to show keyboard - \return other errors returned by binder driver - */ - int PerUserSession::ShowKeyboard( const sptr& inputClient ) - { - IMSA_HILOGI("PerUserSession::ShowKeyboard"); - ClientInfo* clientInfo = GetClientInfo(inputClient); - int index = GetImeIndex(inputClient); - if (index == -1 || clientInfo == nullptr) { - IMSA_HILOGE("PerUserSession::ShowKeyboard Aborted! index = -1 or clientInfo is nullptr"); - return ErrorCode::ERROR_CLIENT_NOT_FOUND; - } - - lastImeIndex = index; - bool supportPhysicalKbd = Platform::Instance()->CheckPhysicalKeyboard(); - localControlChannel[index]->ResetFlag(); - bool ret = imsCore[index]->startInput(clientInfo->channel, clientInfo->attribute, supportPhysicalKbd); - if (!ret || - localControlChannel[index]->GetAgentAndChannel(&imsAgent, &imsChannel)==false) { - IMSA_HILOGE("PerUserSession::ShowKeyboard Aborted! client is not ready"); - int result = clientInfo->client->onInputReady(1, nullptr, nullptr); - if (result != ErrorCode::NO_ERROR) { - IMSA_HILOGE("PerUserSession::ShowKeyboard onInputReady return : %{public}s [%{public}d]\n", ErrorCode::ToString(ret), userId_); - } - return ErrorCode::ERROR_IME_START_FAILED; - } + return ErrorCode::NO_ERROR; + } - ret = imsCore[index]->showKeyboard(1); - if (!ret) { - IMSA_HILOGE("PerUserSession::ShowKeyboard Aborted! showKeyboard has error : %{public}s", ErrorCode::ToString(ret)); + IMSA_HILOGD("unbindInputMethodService...\n"); - 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)); - } - return ErrorCode::ERROR_KBD_SHOW_FAILED; - } + IMSA_HILOGD("destroyWindowToken...\n"); + int errorCode = ErrorCode::NO_ERROR; + int ret = Platform::Instance()->DestroyWindowToken(userId_, currentIme[index]->mPackageName); + inputMethodToken[index] = nullptr; + if (ret != ErrorCode::NO_ERROR) { + IMSA_HILOGE("destroyWindowToken return : %{public}s [%{public}d]\n", ErrorCode::ToString(ret), userId_); + errorCode = ErrorCode::ERROR_TOKEN_DESTROY_FAILED; + } + sptr b = imsCore[index]->AsObject(); + ret = b->RemoveDeathRecipient(imsDeathRecipient); + if (ret != ErrorCode::NO_ERROR) { + IMSA_HILOGE("RemoveDeathRecipient return : %{public}s [%{public}d]\n", ErrorCode::ToString(ret), userId_); + } + imsCore[index] = nullptr; + inputControlChannel[index] = nullptr; + localControlChannel[index] = nullptr; + IMSA_HILOGI("End...[%{public}d]\n", userId_); + return errorCode; + } - if(clientInfo->client == nullptr){ - IMSA_HILOGI("PerUserSession::ShowKeyboard clientInfo->client is nullptr"); - } + /*! Show keyboard + \param inputClient the remote object handler of the input client. + \return ErrorCode::NO_ERROR no error + \return ErrorCode::ERROR_IME_NOT_STARTED ime not started + \return ErrorCode::ERROR_KBD_IS_OCCUPIED keyboard is showing by other client + \return ErrorCode::ERROR_CLIENT_NOT_FOUND the input client is not found + \return ErrorCode::ERROR_IME_START_FAILED failed to start input method service + \return ErrorCode::ERROR_KBD_SHOW_FAILED failed to show keyboard + \return other errors returned by binder driver + */ + int PerUserSession::ShowKeyboard( const sptr& inputClient ) + { + IMSA_HILOGI("PerUserSession::ShowKeyboard"); + ClientInfo* clientInfo = GetClientInfo(inputClient); + int index = GetImeIndex(inputClient); + if (index == -1 || clientInfo == nullptr) { + IMSA_HILOGE("PerUserSession::ShowKeyboard Aborted! index = -1 or clientInfo is nullptr"); + return ErrorCode::ERROR_CLIENT_NOT_FOUND; + } - int result = clientInfo->client->onInputReady(0, imsAgent, imsChannel); + lastImeIndex = index; + bool supportPhysicalKbd = Platform::Instance()->CheckPhysicalKeyboard(); + localControlChannel[index]->ResetFlag(); + bool ret = imsCore[index]->startInput(clientInfo->channel, clientInfo->attribute, supportPhysicalKbd); + if (!ret || + localControlChannel[index]->GetAgentAndChannel(&imsAgent, &imsChannel)==false) { + IMSA_HILOGE("PerUserSession::ShowKeyboard Aborted! client is not ready"); + int result = clientInfo->client->onInputReady(1, nullptr, nullptr); if (result != ErrorCode::NO_ERROR) { - IMSA_HILOGE("PerUserSession::ShowKeyboard Aborted! onInputReady return : %{public}s", ErrorCode::ToString(ret)); - return result; + IMSA_HILOGE("PerUserSession::ShowKeyboard onInputReady return : %{public}s", ErrorCode::ToString(ret)); } - currentClient = inputClient; - return ErrorCode::NO_ERROR; + return ErrorCode::ERROR_IME_START_FAILED; } - /*! hide keyboard - \param inputClient the remote object handler of the input client. - \return ErrorCode::NO_ERROR no error - \return ErrorCode::ERROR_IME_NOT_STARTED ime not started - \return ErrorCode::ERROR_KBD_IS_NOT_SHOWING keyboard has not been showing - \return ErrorCode::ERROR_CLIENT_NOT_FOUND the input client is not found - \return ErrorCode::ERROR_KBD_HIDE_FAILED failed to hide keyboard - \return other errors returned by binder driver - */ - int PerUserSession::HideKeyboard(const sptr& inputClient) - { - IMSA_HILOGI("PerUserSession::HideKeyboard"); - int index = GetImeIndex(inputClient); - if (index == -1) { - IMSA_HILOGE("PerUserSession::HideKeyboard Aborted! %{public}s [%{public}d]\n", ErrorCode::ToString(ErrorCode::ERROR_CLIENT_NOT_FOUND), userId_); - return ErrorCode::ERROR_CLIENT_NOT_FOUND; - } - ClientInfo* clientInfo = GetClientInfo(inputClient); - if(clientInfo == nullptr){ - IMSA_HILOGE("PerUserSession::HideKeyboard GetClientInfo pointer nullptr"); - } - if (imsCore[index] == nullptr) { - IMSA_HILOGE("PerUserSession::HideKeyboard imsCore[index] is nullptr"); - clientInfo->client->onInputReady(1, nullptr, nullptr); - return ErrorCode::ERROR_IME_NOT_STARTED; - } + ret = imsCore[index]->showKeyboard(1); + if (!ret) { + IMSA_HILOGE("PerUserSession::ShowKeyboard Aborted! showKeyboard has error : %{public}s", ErrorCode::ToString(ret)); - if (currentClient == nullptr) { - clientInfo->client->onInputReady(1, nullptr, nullptr); - IMSA_HILOGE("PerUserSession::HideKeyboard Aborted! %{public}s [%{public}d]\n", ErrorCode::ToString(ErrorCode::ERROR_KBD_IS_NOT_SHOWING), userId_); - return ErrorCode::ERROR_KBD_IS_NOT_SHOWING; - } - bool ret = imsCore[index]->hideKeyboard(1); - if(!ret) { - IMSA_HILOGE("PerUserSession::HideKeyboard [imsCore->hideKeyboard] failed"); - ret=ErrorCode::ERROR_KBD_HIDE_FAILED; - } - int ret_stop = imsCore[index]->stopInput(); - if (ret_stop != ErrorCode::NO_ERROR) { - IMSA_HILOGE("PerUserSession::HideKeyboard Aborted! stopInput return : %{public}s [%{public}d]\n", ErrorCode::ToString(ret_stop), userId_); - ret = ErrorCode::ERROR_KBD_HIDE_FAILED; + 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)); } + return ErrorCode::ERROR_KBD_SHOW_FAILED; + } - 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 [%{public}d]\n", ErrorCode::ToString(ret_client_stop), userId_); - } - currentClient = nullptr; - imsAgent = nullptr; - if (imsChannel != nullptr) { - delete imsChannel; - imsChannel = nullptr; - } - return ErrorCode::NO_ERROR; + if(clientInfo->client == nullptr){ + IMSA_HILOGI("PerUserSession::ShowKeyboard clientInfo->client is nullptr"); } - /*! Get the display mode of the current keyboard showing - \return return display mode. - \n 0 - part sceen mode, 1 - full sceen mode - */ - int PerUserSession::GetDisplayMode() - { - return currentDisplayMode; + 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)); + return result; } + currentClient = inputClient; + return ErrorCode::NO_ERROR; + } - /*! Get the keyboard window height - \param[out] retHeight the height of keyboard window showing or showed returned to caller - \return ErrorCode - */ - int PerUserSession::GetKeyboardWindowHeight(int *retHeight) - { - if (retHeight == nullptr) { - return ErrorCode::ERROR_BAD_PARAMETERS; - } - if (imsCore[lastImeIndex] != nullptr) { - int ret = imsCore[lastImeIndex]->getKeyboardWindowHeight(retHeight); - if (ret != ErrorCode::NO_ERROR) { - IMSA_HILOGE("getKeyboardWindowHeight return : %{public}s [%{public}d]\n", ErrorCode::ToString(ret), userId_); - } - return ret; - } - IMSA_HILOGW("No IME is started [%{public}d]\n", userId_); + /*! hide keyboard + \param inputClient the remote object handler of the input client. + \return ErrorCode::NO_ERROR no error + \return ErrorCode::ERROR_IME_NOT_STARTED ime not started + \return ErrorCode::ERROR_KBD_IS_NOT_SHOWING keyboard has not been showing + \return ErrorCode::ERROR_CLIENT_NOT_FOUND the input client is not found + \return ErrorCode::ERROR_KBD_HIDE_FAILED failed to hide keyboard + \return other errors returned by binder driver + */ + int PerUserSession::HideKeyboard(const sptr& inputClient) + { + IMSA_HILOGI("PerUserSession::HideKeyboard"); + int index = GetImeIndex(inputClient); + if (index == -1) { + IMSA_HILOGE("PerUserSession::HideKeyboard Aborted! ErrorCode::ERROR_CLIENT_NOT_FOUND"); + return ErrorCode::ERROR_CLIENT_NOT_FOUND; + } + ClientInfo* clientInfo = GetClientInfo(inputClient); + if(clientInfo == nullptr){ + IMSA_HILOGE("PerUserSession::HideKeyboard GetClientInfo pointer nullptr"); + } + if (imsCore[index] == nullptr) { + IMSA_HILOGE("PerUserSession::HideKeyboard imsCore[index] is nullptr"); + clientInfo->client->onInputReady(1, nullptr, nullptr); return ErrorCode::ERROR_IME_NOT_STARTED; } - /*! Get the current keyboard type - \return return the pointer of the object of current keyboard type. - \n null if no keyboard type supported by the current ime. - \note The returned pointer should NOT be freed by the caller. - */ - KeyboardType* PerUserSession::GetCurrentKeyboardType() - { - if (inputMethodSetting == nullptr || currentIme[DEFAULT_IME] == nullptr) { - IMSA_HILOGI("Ime has not started ! [%{public}d]\n", userId_); - return nullptr; + if (currentClient == nullptr) { + clientInfo->client->onInputReady(1, nullptr, nullptr); + IMSA_HILOGE("PerUserSession::HideKeyboard Aborted! ErrorCode::ERROR_KBD_IS_NOT_SHOWING"); + return ErrorCode::ERROR_KBD_IS_NOT_SHOWING; + } + bool ret = imsCore[index]->hideKeyboard(1); + if(!ret) { + IMSA_HILOGE("PerUserSession::HideKeyboard [imsCore->hideKeyboard] failed"); + ret=ErrorCode::ERROR_KBD_HIDE_FAILED; + } + + 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)); + } + currentClient = nullptr; + imsAgent = nullptr; + imsCore[index] = nullptr; + if (imsChannel != nullptr) { + delete imsChannel; + imsChannel = nullptr; + } + return ErrorCode::NO_ERROR; + } + + /*! Get the display mode of the current keyboard showing + \return return display mode. + \n 0 - part sceen mode, 1 - full sceen mode + */ + int PerUserSession::GetDisplayMode() + { + return currentDisplayMode; + } + + /*! Get the keyboard window height + \param[out] retHeight the height of keyboard window showing or showed returned to caller + \return ErrorCode + */ + int PerUserSession::GetKeyboardWindowHeight(int *retHeight) + { + if (retHeight == nullptr) { + return ErrorCode::ERROR_BAD_PARAMETERS; + } + if (imsCore[lastImeIndex] != nullptr) { + int ret = imsCore[lastImeIndex]->getKeyboardWindowHeight(retHeight); + if (ret != ErrorCode::NO_ERROR) { + IMSA_HILOGE("getKeyboardWindowHeight return : %{public}s", ErrorCode::ToString(ret)); } - if (currentIme[DEFAULT_IME] == currentIme[SECURITY_IME]) { + return ret; + } + IMSA_HILOGW("No IME is started [%{public}d]\n", userId_); + return ErrorCode::ERROR_IME_NOT_STARTED; + } + + /*! Get the current keyboard type + \return return the pointer of the object of current keyboard type. + \n null if no keyboard type supported by the current ime. + \note The returned pointer should NOT be freed by the caller. + */ + KeyboardType* PerUserSession::GetCurrentKeyboardType() + { + if (inputMethodSetting == nullptr || currentIme[DEFAULT_IME] == nullptr) { + IMSA_HILOGI("Ime has not started ! [%{public}d]\n", userId_); + return nullptr; + } + if (currentIme[DEFAULT_IME] == currentIme[SECURITY_IME]) { + return nullptr; + } + int hashCode = inputMethodSetting->GetCurrentKeyboardType(); // To be checked. + if (hashCode == -1) { + std::vector hashCodeList = inputMethodSetting->GetEnabledKeyboardTypes(currentIme[DEFAULT_IME]->mImeId); + if (hashCodeList.size() == 0) { + IMSA_HILOGE("Cannot find any keyboard types for the current ime [%{public}d]\n", userId_); return nullptr; } - int hashCode = inputMethodSetting->GetCurrentKeyboardType(); // To be checked. - if (hashCode == -1) { - std::vector hashCodeList = inputMethodSetting->GetEnabledKeyboardTypes(currentIme[DEFAULT_IME]->mImeId); - if (hashCodeList.size() == 0) { - IMSA_HILOGE("Cannot find any keyboard types for the current ime [%{public}d]\n", userId_); - return nullptr; - } - hashCode = hashCodeList[0]; - } + hashCode = hashCodeList[0]; + } - for(int i=0; i<(int)currentIme[DEFAULT_IME]->mTypes.size(); i++) { - if (currentIme[DEFAULT_IME]->mTypes[i]->getHashCode() == hashCode) { - return currentIme[DEFAULT_IME]->mTypes[i]; - } + for(int i=0; i<(int)currentIme[DEFAULT_IME]->mTypes.size(); i++) { + if (currentIme[DEFAULT_IME]->mTypes[i]->getHashCode() == hashCode) { + return currentIme[DEFAULT_IME]->mTypes[i]; } - return nullptr; } + return nullptr; + } - /*! Handle the situation a remote input client died\n - It's called when a remote input client died - \param who the remote object handler of the input client died. - */ - void PerUserSession::OnClientDied(const wptr& who) - { - IMSA_HILOGI("PerUserSession::OnClientDied Start...[%{public}d]\n", userId_); - bool flag = false; - std::map, ClientInfo*>::iterator it; + /*! Handle the situation a remote input client died\n + It's called when a remote input client died + \param who the remote object handler of the input client died. + */ + void PerUserSession::OnClientDied(const wptr& who) + { + IMSA_HILOGI("PerUserSession::OnClientDied Start...[%{public}d]\n", userId_); + bool flag = false; + std::map, ClientInfo*>::iterator it; - for (it=mapClients.begin(); it!=mapClients.end(); ++it) { - if (it->first == who) { - flag = true; - break; - } - } - if (flag == false) { - IMSA_HILOGW("Aborted! The client died is not found! [%{public}d]\n", userId_); - return; + for (it=mapClients.begin(); it!=mapClients.end(); ++it) { + if (it->first == who) { + flag = true; + break; } + } + if (flag == false) { + IMSA_HILOGW("Aborted! The client died is not found! [%{public}d]\n", userId_); + return; + } - sptr client = iface_cast(it->first); - int remainClientNum = 0; - if (currentClient == client) { - HideKeyboard(client); - } - RemoveClient(client, &remainClientNum); + sptr client = it->second->client; + int remainClientNum = 0; + if (currentClient != nullptr) { + HideKeyboard(client); } + RemoveClient(client, &remainClientNum); + } - /*! Handle the situation a input method service died\n - It's called when an input method service died - \param who the remote object handler of input method service who died. - */ - void PerUserSession::OnImsDied(const wptr& who) - { - (void) who; // temporary void it, as we will add support for security IME. - IMSA_HILOGI("Start...[%{public}d]\n", userId_); - int index = 0; - for(int i=0; i b = imsCore[i]->AsObject(); - if (b == who) { - index = i; - break; - } - } - if (currentClient && (GetImeIndex(currentClient)==index || - currentIme[index] == currentIme[1-index])) { - needReshowClient = currentClient; - HideKeyboard(currentClient); - } - StopInputMethod(index); - if (currentIme[index] == currentIme[1-index]) { - StopInputMethod(1-index); + /*! Handle the situation a input method service died\n + It's called when an input method service died + \param who the remote object handler of input method service who died. + */ + void PerUserSession::OnImsDied(const wptr& who) + { + (void) who; // temporary void it, as we will add support for security IME. + IMSA_HILOGI("Start...[%{public}d]\n", userId_); + int index = 0; + for(int i=0; i b = imsCore[i]->AsObject(); + if (b == who) { + index = i; + break; } + } + if (currentClient && (GetImeIndex(currentClient)==index || + currentIme[index] == currentIme[1-index])) { + needReshowClient = currentClient; + HideKeyboard(currentClient); + } + StopInputMethod(index); + if (currentIme[index] == currentIme[1-index]) { + StopInputMethod(1-index); + } - if (IncreaseOrResetImeError(false, index) == 3) { - // call to disable the current input method. - MessageParcel *parcel = new MessageParcel(); - parcel->WriteInt32(userId_); - parcel->WriteString16(currentIme[index]->mImeId); - Message* msg = new Message(MSG_ID_DISABLE_IMS, parcel); - MessageHandler::Instance()->SendMessage(msg); - } else { - // restart current input method. - IMSA_HILOGI("IME died. Restart input method ! [%{public}d]\n", userId_); - MessageParcel *parcel = new MessageParcel(); - parcel->WriteInt32(userId_); - 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 - MessageHandler::Instance()->SendMessage(msg); - } - IMSA_HILOGI("End...[%{public}d]\n", userId_); + if (IncreaseOrResetImeError(false, index) == 3) { + // call to disable the current input method. + MessageParcel *parcel = new MessageParcel(); + parcel->WriteInt32(userId_); + parcel->WriteString16(currentIme[index]->mImeId); + Message* msg = new Message(MSG_ID_DISABLE_IMS, parcel); + MessageHandler::Instance()->SendMessage(msg); + } else { + // restart current input method. + IMSA_HILOGI("IME died. Restart input method ! [%{public}d]\n", userId_); + MessageParcel *parcel = new MessageParcel(); + parcel->WriteInt32(userId_); + 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 + MessageHandler::Instance()->SendMessage(msg); } + IMSA_HILOGI("End...[%{public}d]\n", userId_); + } - /*! It's called when input method setting data in the system is changed - \param key the name of setting item changed. - \param value the value of setting item changed. - \return ErrorCode::NO_ERROR no error - \return ErrorCode::ERROR_SETTING_SAME_VALUE the current value is same as the one in the system. - */ - int PerUserSession::OnSettingChanged(const std::u16string& key, const std::u16string& value) - { - IMSA_HILOGI("Start...[%{public}d]\n", userId_); - std::unique_lock lock(mtx); - if (inputMethodSetting == nullptr) { - return ErrorCode::ERROR_NULL_POINTER; - } - std::u16string currentValue = inputMethodSetting->GetValue(key); + /*! It's called when input method setting data in the system is changed + \param key the name of setting item changed. + \param value the value of setting item changed. + \return ErrorCode::NO_ERROR no error + \return ErrorCode::ERROR_SETTING_SAME_VALUE the current value is same as the one in the system. + */ + int PerUserSession::OnSettingChanged(const std::u16string& key, const std::u16string& value) + { + IMSA_HILOGI("Start...[%{public}d]\n", userId_); + std::unique_lock lock(mtx); + if (inputMethodSetting == nullptr) { + return ErrorCode::ERROR_NULL_POINTER; + } + std::u16string currentValue = inputMethodSetting->GetValue(key); - IMSA_HILOGD("%{public}s=%{public}s, currentValue = %{public}s\n", Utils::to_utf8(key).c_str(), Utils::to_utf8(value).c_str(), Utils::to_utf8(currentValue).c_str()); + IMSA_HILOGD("PerUserSession::OnSettingChanged key = %{public}s", Utils::to_utf8(key).c_str()); + IMSA_HILOGD("PerUserSession::OnSettingChanged value = %{public}s", Utils::to_utf8(value).c_str()); + IMSA_HILOGD("PerUserSession::OnSettingChanged currentValue = %{public}s", Utils::to_utf8(currentValue).c_str()); - if (currentValue == value) { - IMSA_HILOGI("End...[%{public}d]\n", userId_); - return ErrorCode::ERROR_SETTING_SAME_VALUE; - } + if (currentValue == value) { + IMSA_HILOGI("End...[%{public}d]\n", userId_); + return ErrorCode::ERROR_SETTING_SAME_VALUE; + } - if (key == InputMethodSetting::CURRENT_KEYBOARD_TYPE_TAG) { - return OnCurrentKeyboardTypeChanged(DEFAULT_IME, value); - } else if (key == InputMethodSetting::CURRENT_SYS_KEYBOARD_TYPE_TAG) { - return OnCurrentKeyboardTypeChanged(SECURITY_IME, value); - } else if (key == InputMethodSetting::CURRENT_INPUT_METHOD_TAG) { - if (currentIme[DEFAULT_IME] == nullptr || - value == currentIme[DEFAULT_IME]->mImeId) { - return ErrorCode::NO_ERROR; - } + if (key == InputMethodSetting::CURRENT_KEYBOARD_TYPE_TAG) { + return OnCurrentKeyboardTypeChanged(DEFAULT_IME, value); + } else if (key == InputMethodSetting::CURRENT_SYS_KEYBOARD_TYPE_TAG) { + return OnCurrentKeyboardTypeChanged(SECURITY_IME, value); + } else if (key == InputMethodSetting::CURRENT_INPUT_METHOD_TAG) { + if (currentIme[DEFAULT_IME] == nullptr || + value == currentIme[DEFAULT_IME]->mImeId) { + return ErrorCode::NO_ERROR; + } + if (currentClient != nullptr && GetImeIndex(currentClient)==DEFAULT_IME) { + needReshowClient = currentClient; + HideKeyboard(currentClient); + } + StopInputMethod(DEFAULT_IME); + currentIme[DEFAULT_IME] = nullptr; + currentKbdIndex[DEFAULT_IME] = 0; + inputMethodSetting->SetCurrentKeyboardType(-1); + } else if (key == InputMethodSetting::ENABLED_INPUT_METHODS_TAG) { + if (currentIme[DEFAULT_IME] && currentIme[DEFAULT_IME]!=currentIme[SECURITY_IME] && + value.find(currentIme[DEFAULT_IME]->mImeId) == std::string::npos) { if (currentClient != nullptr && GetImeIndex(currentClient)==DEFAULT_IME) { needReshowClient = currentClient; HideKeyboard(currentClient); @@ -756,623 +764,611 @@ namespace MiscServices { currentIme[DEFAULT_IME] = nullptr; currentKbdIndex[DEFAULT_IME] = 0; inputMethodSetting->SetCurrentKeyboardType(-1); - } else if (key == InputMethodSetting::ENABLED_INPUT_METHODS_TAG) { - if (currentIme[DEFAULT_IME] && currentIme[DEFAULT_IME]!=currentIme[SECURITY_IME] && - value.find(currentIme[DEFAULT_IME]->mImeId) == std::string::npos) { - if (currentClient != nullptr && GetImeIndex(currentClient)==DEFAULT_IME) { - needReshowClient = currentClient; - HideKeyboard(currentClient); - } - StopInputMethod(DEFAULT_IME); - currentIme[DEFAULT_IME] = nullptr; - currentKbdIndex[DEFAULT_IME] = 0; - inputMethodSetting->SetCurrentKeyboardType(-1); - } - } - IMSA_HILOGI("End...[%{public}d]\n", userId_); - return ErrorCode::NO_ERROR; - } - - /*! Change current keyboard type. - \param index it can be 0 or 1. 0 - default ime, 1 - security ime. - \param value the hash code of keyboard type - \return ErrorCode::NO_ERROR no error - \return ErrorCode::ERROR_SETTING_SAME_VALUE the current value is same as the one in the system. - */ - int PerUserSession::OnCurrentKeyboardTypeChanged(int index, const std::u16string& value) - { - std::string str = Utils::to_utf8(value); - int hashCode = std::atoi(str.c_str()); - if (hashCode == -1) { - return ErrorCode::ERROR_SETTING_SAME_VALUE;; - } - // switch within the current ime. - if (index == SECURITY_IME || currentIme[DEFAULT_IME] == currentIme[SECURITY_IME]) { - int num = currentKbdIndex[index]; - if (currentIme[index]->mTypes[num]->getHashCode() == hashCode) { - return ErrorCode::ERROR_SETTING_SAME_VALUE; - } - for(int i=0; i<(int)currentIme[index]->mTypes.size(); i++) { - if (currentIme[index]->mTypes[i]->getHashCode() == hashCode) { - currentKbdIndex[index] = i; - break; - } - } - } else { - std::u16string imeId = currentIme[index]->mImeId; - std::vector currentKbdTypes = inputMethodSetting->GetEnabledKeyboardTypes(imeId); - int num = currentKbdIndex[index]; - if (currentKbdTypes[num] == hashCode) { - return ErrorCode::ERROR_SETTING_SAME_VALUE; - } - for(int i=0; i<(int)currentKbdTypes.size(); i++) { - if (currentKbdTypes[i] == hashCode) { - currentKbdIndex[index] = i; - break; - } - } - } - KeyboardType* type = GetKeyboardType(index, currentKbdIndex[index]); - if (type != nullptr) { - if (currentClient != nullptr) { - int ret = imsCore[index]->setKeyboardType(*type); - if (ret != ErrorCode::NO_ERROR) { - IMSA_HILOGE("setKeyboardType return : %{public}s [%{public}d]\n", ErrorCode::ToString(ret), userId_); - } - } - if (imsCore[index] == imsCore[1-index]) { - inputMethodSetting->SetCurrentKeyboardType(type->getHashCode()); - inputMethodSetting->SetCurrentSysKeyboardType(type->getHashCode()); - currentKbdIndex[1-index] = currentKbdIndex[index]; - } else if (index == DEFAULT_IME) { - inputMethodSetting->SetCurrentKeyboardType(type->getHashCode()); - } else { - inputMethodSetting->SetCurrentSysKeyboardType(type->getHashCode()); - } } - return ErrorCode::NO_ERROR; } + IMSA_HILOGI("End...[%{public}d]\n", userId_); + return ErrorCode::NO_ERROR; + } - /*! Hide current keyboard - \param flag the flag to hide keyboard. - */ - void PerUserSession::OnHideKeyboardSelf(int flags) - { - IMSA_HILOGW("PerUserSession::OnHideKeyboardSelf"); - (void) flags; - HideKeyboard(currentClient); + /*! Change current keyboard type. + \param index it can be 0 or 1. 0 - default ime, 1 - security ime. + \param value the hash code of keyboard type + \return ErrorCode::NO_ERROR no error + \return ErrorCode::ERROR_SETTING_SAME_VALUE the current value is same as the one in the system. + */ + int PerUserSession::OnCurrentKeyboardTypeChanged(int index, const std::u16string& value) + { + std::string str = Utils::to_utf8(value); + int hashCode = std::atoi(str.c_str()); + if (hashCode == -1) { + return ErrorCode::ERROR_SETTING_SAME_VALUE;; } - - /*! Switch to next keyboard type - */ - void PerUserSession::OnAdvanceToNext( ) - { - int index = GetImeIndex(currentClient); - if (index == -1) { - IMSA_HILOGW("%{public}s [%{public}d]\n", ErrorCode::ToString(ErrorCode::ERROR_CLIENT_NOT_FOUND), userId_); - return ; + // switch within the current ime. + if (index == SECURITY_IME || currentIme[DEFAULT_IME] == currentIme[SECURITY_IME]) { + int num = currentKbdIndex[index]; + if (currentIme[index]->mTypes[num]->getHashCode() == hashCode) { + return ErrorCode::ERROR_SETTING_SAME_VALUE; } - int size = 0; - if (index==SECURITY_IME || currentIme[DEFAULT_IME] == currentIme[SECURITY_IME] ) { - size = currentIme[index]->mTypes.size(); - } else { - std::u16string imeId = currentIme[index]->mImeId; - std::vector currentKbdTypes = inputMethodSetting->GetEnabledKeyboardTypes(imeId); - size = currentKbdTypes.size(); + for(int i=0; i<(int)currentIme[index]->mTypes.size(); i++) { + if (currentIme[index]->mTypes[i]->getHashCode() == hashCode) { + currentKbdIndex[index] = i; + break; + } } - if (size < 2) { - IMSA_HILOGW("No next keyboard is available. [%{public}d]\n", userId_); - return ; + } else { + std::u16string imeId = currentIme[index]->mImeId; + std::vector currentKbdTypes = inputMethodSetting->GetEnabledKeyboardTypes(imeId); + int num = currentKbdIndex[index]; + if (currentKbdTypes[num] == hashCode) { + return ErrorCode::ERROR_SETTING_SAME_VALUE; } - - int num = currentKbdIndex[index]+1; - num %= size; - KeyboardType* type = GetKeyboardType(index, num); - if (type == nullptr) { - IMSA_HILOGW("No next keyboard is available. [%{public}d]\n", userId_); - return; + for(int i=0; i<(int)currentKbdTypes.size(); i++) { + if (currentKbdTypes[i] == hashCode) { + currentKbdIndex[index] = i; + break; + } } - InputMethodSetting tmpSetting; - if (imsCore[index] == imsCore[1-index]) { - tmpSetting.SetCurrentKeyboardType(type->getHashCode()); - tmpSetting.SetCurrentSysKeyboardType(type->getHashCode()); + } + KeyboardType* type = GetKeyboardType(index, currentKbdIndex[index]); + if (type != nullptr) { + if (currentClient != nullptr) { + int ret = imsCore[index]->setKeyboardType(*type); + if (ret != ErrorCode::NO_ERROR) { + IMSA_HILOGE("setKeyboardType return : %{public}s [%{public}d]\n", ErrorCode::ToString(ret), userId_); + } } - else if (index == DEFAULT_IME) { - tmpSetting.SetCurrentKeyboardType(type->getHashCode()); + if (imsCore[index] == imsCore[1-index]) { + inputMethodSetting->SetCurrentKeyboardType(type->getHashCode()); + inputMethodSetting->SetCurrentSysKeyboardType(type->getHashCode()); + currentKbdIndex[1-index] = currentKbdIndex[index]; + } else if (index == DEFAULT_IME) { + inputMethodSetting->SetCurrentKeyboardType(type->getHashCode()); } else { - tmpSetting.SetCurrentSysKeyboardType(type->getHashCode()); + inputMethodSetting->SetCurrentSysKeyboardType(type->getHashCode()); } - Platform::Instance()->SetInputMethodSetting(userId_, tmpSetting); } + return ErrorCode::NO_ERROR; + } - /*! Set display mode - \param mode the display mode of soft keyboard UI. - \n 0 - part sceen mode, 1 - full sceen mode - */ - void PerUserSession::OnSetDisplayMode(int mode) - { - currentDisplayMode = mode; - ClientInfo* clientInfo = GetClientInfo(currentClient); - if (clientInfo == nullptr) { - IMSA_HILOGE("%{public}s [%{public}d]\n", ErrorCode::ToString(ErrorCode::ERROR_CLIENT_NOT_FOUND), userId_); - return ; - } - int ret = clientInfo->client->setDisplayMode(mode); - if (ret != ErrorCode::NO_ERROR) { - IMSA_HILOGE("setDisplayMode return : %{public}s [%{public}d]\n", ErrorCode::ToString(ret), userId_); - } - } + /*! Hide current keyboard + \param flag the flag to hide keyboard. + */ + void PerUserSession::OnHideKeyboardSelf(int flags) + { + IMSA_HILOGW("PerUserSession::OnHideKeyboardSelf"); + (void) flags; + HideKeyboard(currentClient); + } - /*! Restart input method service - \param index it can be DEFAULT_IME or SECURITY_IME - \param imeId the id of the input method service going to restart - */ - void PerUserSession::OnRestartIms(int index, const std::u16string& imeId) - { - if (index<0 || index>=MAX_IME) { - return ; - } - IMSA_HILOGI("Start...[%{public}d]\n", userId_); - if (currentIme[index] && currentIme[index]->mImeId == imeId) { - int ret = StartInputMethod(index); - if (needReshowClient && GetImeIndex(needReshowClient)==index) { - if (ret == ErrorCode::NO_ERROR) { - ShowKeyboard(needReshowClient); - } - needReshowClient = nullptr; - } - } - IMSA_HILOGI("End...[%{public}d]\n", userId_); + /*! Switch to next keyboard type + */ + void PerUserSession::OnAdvanceToNext( ) + { + int index = GetImeIndex(currentClient); + if (index == -1) { + IMSA_HILOGW("%{public}s [%{public}d]\n", ErrorCode::ToString(ErrorCode::ERROR_CLIENT_NOT_FOUND), userId_); + return ; + } + int size = 0; + if (index==SECURITY_IME || currentIme[DEFAULT_IME] == currentIme[SECURITY_IME] ) { + size = currentIme[index]->mTypes.size(); + } else { + std::u16string imeId = currentIme[index]->mImeId; + std::vector currentKbdTypes = inputMethodSetting->GetEnabledKeyboardTypes(imeId); + size = currentKbdTypes.size(); + } + if (size < 2) { + IMSA_HILOGW("No next keyboard is available. [%{public}d]\n", userId_); + return ; } - /*! It's called when this user is locked - */ - void PerUserSession::OnUserLocked() - { - IMSA_HILOGI("PerUserSession::OnUserLocked"); - if (userState == UserState::USER_STATE_STARTED) { - IMSA_HILOGI("End...[%{public}d]\n", userId_); - return; - } - userState = UserState::USER_STATE_STARTED; - // hide current keyboard - if (currentClient != nullptr) { - HideKeyboard(currentClient); - } - for(int i=0; i<2; i++) { - StopInputMethod(i); - currentIme[i] = nullptr; - } - // disconnect all clients. - std::map, ClientInfo*>::iterator it; - for(it=mapClients.begin(); it!=mapClients.end();) { - sptr b = it->first; - b->RemoveDeathRecipient(clientDeathRecipient); - ClientInfo* clientInfo = it->second; - if (clientInfo != nullptr) { - int ret = clientInfo->client->onInputReleased(0); - if (ret != ErrorCode::NO_ERROR) { - IMSA_HILOGE("2-onInputReleased return : %{public}s [%{public}d]\n", ErrorCode::ToString(ret), userId_); - } - delete clientInfo; - } - IMSA_HILOGD("erase client..\n"); - it = mapClients.erase(it); - } - mapClients.clear(); + int num = currentKbdIndex[index]+1; + num %= size; + KeyboardType* type = GetKeyboardType(index, num); + if (type == nullptr) { + IMSA_HILOGW("No next keyboard is available. [%{public}d]\n", userId_); + return; + } + InputMethodSetting tmpSetting; + if (imsCore[index] == imsCore[1-index]) { + tmpSetting.SetCurrentKeyboardType(type->getHashCode()); + tmpSetting.SetCurrentSysKeyboardType(type->getHashCode()); + } + else if (index == DEFAULT_IME) { + tmpSetting.SetCurrentKeyboardType(type->getHashCode()); + } else { + tmpSetting.SetCurrentSysKeyboardType(type->getHashCode()); + } + Platform::Instance()->SetInputMethodSetting(userId_, tmpSetting); + } - // reset values - inputMethodSetting = nullptr; - currentClient = nullptr; - needReshowClient = nullptr; + /*! Set display mode + \param mode the display mode of soft keyboard UI. + \n 0 - part sceen mode, 1 - full sceen mode + */ + void PerUserSession::OnSetDisplayMode(int mode) + { + currentDisplayMode = mode; + ClientInfo* clientInfo = GetClientInfo(currentClient); + if (clientInfo == nullptr) { + IMSA_HILOGE("%{public}s [%{public}d]\n", ErrorCode::ToString(ErrorCode::ERROR_CLIENT_NOT_FOUND), userId_); + return ; } + int ret = clientInfo->client->setDisplayMode(mode); + if (ret != ErrorCode::NO_ERROR) { + IMSA_HILOGE("setDisplayMode return : %{public}s [%{public}d]\n", ErrorCode::ToString(ret), userId_); + } + } - /*! Print the session information of this user into the given stream - \n The information includes: - \li the information of all the input clients connected to the input method management system. - \li current input method engine information - \li security input method engine information - \li current session information - \param fd the raw file descriptor that the dump is being sent to - */ - void PerUserSession::Dump(int fd) - { - std::map, ClientInfo*>::const_iterator it; - dprintf(fd, "\n - User Session State :\n"); - dprintf(fd, " * Client count = %d\n", mapClients.size()); - int index = 0; - for(it=mapClients.cbegin(); it!=mapClients.cend(); ++it) { - if (currentClient != nullptr && - Platform::RemoteBrokerToObject(currentClient) == it->first) { - dprintf(fd, " *[%d] Client Information: (current client)\n", index++); - } else { - dprintf(fd, " [%d] Client Information:\n", index++); + /*! Restart input method service + \param index it can be DEFAULT_IME or SECURITY_IME + \param imeId the id of the input method service going to restart + */ + void PerUserSession::OnRestartIms(int index, const std::u16string& imeId) + { + if (index<0 || index>=MAX_IME) { + return ; + } + IMSA_HILOGI("Start...[%{public}d]\n", userId_); + if (currentIme[index] && currentIme[index]->mImeId == imeId) { + int ret = StartInputMethod(index); + if (needReshowClient && GetImeIndex(needReshowClient)==index) { + if (ret == ErrorCode::NO_ERROR) { + ShowKeyboard(needReshowClient); } - DumpClientInfo(fd, *(it->second)); + needReshowClient = nullptr; } - std::string header[2] = {"Current", "Security"}; - for(int i=0; i<2; i++) { - if (currentIme[i] != nullptr) { - dprintf(fd, "\n * %s IME mImeId = %s\n", header[i].c_str(), Utils::to_utf8(currentIme[i]->mImeId).c_str()); - KeyboardType* type = currentIme[i]->mTypes.at(currentKbdIndex[i]); - dprintf(fd, " %s KeyboardType mHashCode = %d, mLanguage = %s\n", header[i].c_str(), - type->getHashCode(), Utils::to_utf8(type->getLanguage()).c_str()); - - if (imsCore[i] != nullptr) { - sptr b = imsCore[i]->AsObject(); - dprintf(fd, " %s IME Service = %s#%p\n", header[i].c_str(), - Utils::to_utf8(b->GetObjectDescriptor()).c_str(), b.GetRefPtr()); - b=inputControlChannel[i]->AsObject(); - dprintf(fd, " %s InputControlChannel = %s#%p\n", - header[i].c_str(), Utils::to_utf8(b->GetObjectDescriptor()).c_str(), b.GetRefPtr()); - dprintf(fd, " %s inputMethodWindowToken = %p\n", header[i].c_str(), inputMethodToken[i].GetRefPtr()); - } else { - dprintf(fd, " %s IME Service = null (not started)\n", header[i].c_str()); - } - } else { - dprintf(fd, "\n * %s IME = null\n", header[i].c_str()); + } + IMSA_HILOGI("End...[%{public}d]\n", userId_); + } + + /*! It's called when this user is locked + */ + void PerUserSession::OnUserLocked() + { + IMSA_HILOGI("PerUserSession::OnUserLocked"); + if (userState == UserState::USER_STATE_STARTED) { + IMSA_HILOGI("End...[%{public}d]\n", userId_); + return; + } + userState = UserState::USER_STATE_STARTED; + // hide current keyboard + if (currentClient != nullptr) { + HideKeyboard(currentClient); + } + for(int i=0; i<2; i++) { + StopInputMethod(i); + currentIme[i] = nullptr; + } + // disconnect all clients. + std::map, ClientInfo*>::iterator it; + for(it=mapClients.begin(); it!=mapClients.end();) { + sptr b = it->first; + b->RemoveDeathRecipient(clientDeathRecipient); + ClientInfo* clientInfo = it->second; + if (clientInfo != nullptr) { + int ret = clientInfo->client->onInputReleased(0); + if (ret != ErrorCode::NO_ERROR) { + IMSA_HILOGE("2-onInputReleased return : %{public}s", ErrorCode::ToString(ret)); } + delete clientInfo; } - DumpCurrentSession(fd); + IMSA_HILOGD("erase client..\n"); + it = mapClients.erase(it); } + mapClients.clear(); - /*! dump current session - \param fd the file descriptor to output the information - */ - void PerUserSession::DumpCurrentSession(int fd) - { - if (currentClient == nullptr) { - dprintf(fd, "\n * Current Session = null (keyboard is not showing by any client)\n"); - return; + // reset values + inputMethodSetting = nullptr; + currentClient = nullptr; + needReshowClient = nullptr; + } + + /* Print the session information of this user into the given stream + * The information includes: + * the information of all the input clients connected to the input method management system. + * current input method engine information + * security input method engine information + * current session information + * param fd the raw file descriptor that the dump is being sent to + */ + void PerUserSession::Dump(int fd) + { + std::map, ClientInfo*>::const_iterator it; + dprintf(fd, "\n - User Session State :\n"); + dprintf(fd, " * Client count = %d\n", mapClients.size()); + int index = 0; + for(it=mapClients.cbegin(); it!=mapClients.cend(); ++it) { + if (currentClient != nullptr && + Platform::RemoteBrokerToObject(currentClient) == it->first) { + dprintf(fd, " *[%d] Client Information: (current client)\n", index++); + } else { + dprintf(fd, " [%d] Client Information:\n", index++); } - sptr b = Platform::RemoteBrokerToObject(currentClient); - std::map, ClientInfo*>::iterator it = mapClients.find(b); - int index = GetImeIndex(currentClient); - dprintf(fd, "\n * Current Session State :\n"); - dprintf(fd, " current client [= %s#%p] information :\n", - Utils::to_utf8(b->GetObjectDescriptor()).c_str(), b.GetRefPtr()); DumpClientInfo(fd, *(it->second)); - - dprintf(fd, " current IME mImeID = %s\n", Utils::to_utf8(currentIme[index]->mImeId).c_str()); - b = Platform::RemoteBrokerToObject(imsCore[index]); - dprintf(fd, " IME service = %s#%p\n", Utils::to_utf8(b->GetObjectDescriptor()).c_str(), b.GetRefPtr()); - b = Platform::RemoteBrokerToObject(imsAgent); - dprintf(fd, " inputAgent = %s#%p\n", Utils::to_utf8(b->GetObjectDescriptor()).c_str(), b.GetRefPtr()); - b = Platform::RemoteBrokerToObject(inputControlChannel[index]); - dprintf(fd, " inputControlChannel = %s#%p\n", Utils::to_utf8(b->GetObjectDescriptor()).c_str(), b.GetRefPtr()); - dprintf(fd, " inputMethodWindowToken = #%p\n", inputMethodToken[index].GetRefPtr()); - dprintf(fd, " displayId = %d\n", displayId); - if (currentDisplayMode == 0) { - dprintf(fd, " displayMode = %d [ part sceen ]\n", currentDisplayMode); + } + std::string header[2] = {"Current", "Security"}; + for(int i=0; i<2; i++) { + if (currentIme[i] != nullptr) { + dprintf(fd, "\n * %s IME mImeId = %s\n", header[i].c_str(), Utils::to_utf8(currentIme[i]->mImeId).c_str()); + KeyboardType* type = currentIme[i]->mTypes.at(currentKbdIndex[i]); + dprintf(fd, " %s KeyboardType mHashCode = %d, mLanguage = %s\n", header[i].c_str(), + type->getHashCode(), Utils::to_utf8(type->getLanguage()).c_str()); + + if (imsCore[i] != nullptr) { + sptr b = imsCore[i]->AsObject(); + dprintf(fd, " %s IME Service = %s#%p\n", header[i].c_str(), + Utils::to_utf8(b->GetObjectDescriptor()).c_str(), b.GetRefPtr()); + b=inputControlChannel[i]->AsObject(); + dprintf(fd, " %s InputControlChannel = %s#%p\n", + header[i].c_str(), Utils::to_utf8(b->GetObjectDescriptor()).c_str(), b.GetRefPtr()); + dprintf(fd, " %s inputMethodWindowToken = %p\n", header[i].c_str(), inputMethodToken[i].GetRefPtr()); + } else { + dprintf(fd, " %s IME Service = null (not started)\n", header[i].c_str()); + } } else { - dprintf(fd, " displayMode = %d [ full sceen ]\n", currentDisplayMode); + dprintf(fd, "\n * %s IME = null\n", header[i].c_str()); } - int height = 0; - GetKeyboardWindowHeight(&height); - dprintf(fd, " keyboard window height = %d\n", height); } + DumpCurrentSession(fd); + } - /*! dump a client information - \param fd the file descriptor to output the information - \param clientInfo client information of a remote input client - */ - void PerUserSession::DumpClientInfo(int fd, const ClientInfo& clientInfo) - { - dprintf(fd, " pid = %d\n", clientInfo.pid); - dprintf(fd, " uid = %d\n", clientInfo.uid); - dprintf(fd, " userId = %d\n", clientInfo.userId); - dprintf(fd, " displayId = %d\n", clientInfo.displayId); - - sptr b = Platform::RemoteBrokerToObject(clientInfo.client); - dprintf(fd, " inputClient = %s#%p\n", Utils::to_utf8(b->GetObjectDescriptor()).c_str(), b.GetRefPtr()); - b = Platform::RemoteBrokerToObject(clientInfo.channel); - dprintf(fd, " inputDataChannel = %s#%p\n", Utils::to_utf8(b->GetObjectDescriptor()).c_str(), b.GetRefPtr()); - } - - /*! Increase or reset ime error number - \param resetFlag the flag to increase or reset number. - \n resetFlag=true, reset error number to 0; - \n resetFlag=false, increase error number. - \param imeIndex index=0 default ime; index=1 security ime - \return return the error count value. It is less or equal 3. - */ - int PerUserSession::IncreaseOrResetImeError(bool resetFlag, int imeIndex) - { - static int errorNum[2] = {0, 0}; - static time_t past[2] = {time(0), time(0)}; - if (resetFlag == true) { - errorNum[imeIndex] = 0; - past[imeIndex] = 0; - return 0; - } + /*! dump current session + \param fd the file descriptor to output the information + */ + void PerUserSession::DumpCurrentSession(int fd) + { + if (currentClient == nullptr) { + dprintf(fd, "\n * Current Session = null (keyboard is not showing by any client)\n"); + return; + } + sptr b = Platform::RemoteBrokerToObject(currentClient); + std::map, ClientInfo*>::iterator it = mapClients.find(b); + int index = GetImeIndex(currentClient); + dprintf(fd, "\n * Current Session State :\n"); + dprintf(fd, " current client [= %s#%p] information :\n", + Utils::to_utf8(b->GetObjectDescriptor()).c_str(), b.GetRefPtr()); + DumpClientInfo(fd, *(it->second)); + + dprintf(fd, " current IME mImeID = %s\n", Utils::to_utf8(currentIme[index]->mImeId).c_str()); + b = Platform::RemoteBrokerToObject(imsCore[index]); + dprintf(fd, " IME service = %s#%p\n", Utils::to_utf8(b->GetObjectDescriptor()).c_str(), b.GetRefPtr()); + b = Platform::RemoteBrokerToObject(imsAgent); + dprintf(fd, " inputAgent = %s#%p\n", Utils::to_utf8(b->GetObjectDescriptor()).c_str(), b.GetRefPtr()); + b = Platform::RemoteBrokerToObject(inputControlChannel[index]); + dprintf(fd, " inputControlChannel = %s#%p\n", Utils::to_utf8(b->GetObjectDescriptor()).c_str(), b.GetRefPtr()); + dprintf(fd, " inputMethodWindowToken = #%p\n", inputMethodToken[index].GetRefPtr()); + dprintf(fd, " displayId = %d\n", displayId); + if (currentDisplayMode == 0) { + dprintf(fd, " displayMode = %d [ part sceen ]\n", currentDisplayMode); + } else { + dprintf(fd, " displayMode = %d [ full sceen ]\n", currentDisplayMode); + } + int height = 0; + GetKeyboardWindowHeight(&height); + dprintf(fd, " keyboard window height = %d\n", height); + } - errorNum[imeIndex]++; - time_t now = time(0); - double diffSeconds = difftime(now, past[imeIndex]); + /*! dump a client information + \param fd the file descriptor to output the information + \param clientInfo client information of a remote input client + */ + void PerUserSession::DumpClientInfo(int fd, const ClientInfo& clientInfo) + { + dprintf(fd, " pid = %d\n", clientInfo.pid); + dprintf(fd, " uid = %d\n", clientInfo.uid); + dprintf(fd, " userId = %d\n", clientInfo.userId); + dprintf(fd, " displayId = %d\n", clientInfo.displayId); + + sptr b = Platform::RemoteBrokerToObject(clientInfo.client); + dprintf(fd, " inputClient = %s#%p\n", Utils::to_utf8(b->GetObjectDescriptor()).c_str(), b.GetRefPtr()); + b = Platform::RemoteBrokerToObject(clientInfo.channel); + dprintf(fd, " inputDataChannel = %s#%p\n", Utils::to_utf8(b->GetObjectDescriptor()).c_str(), b.GetRefPtr()); + } - //time difference is more than 5 minutes, reset time and error num; - if (diffSeconds > 300) { - past[imeIndex] = now; - errorNum[imeIndex] = 1; - } - return errorNum[imeIndex]; + /*! Increase or reset ime error number + \param resetFlag the flag to increase or reset number. + \n resetFlag=true, reset error number to 0; + \n resetFlag=false, increase error number. + \param imeIndex index=0 default ime; index=1 security ime + \return return the error count value. It is less or equal 3. + */ + int PerUserSession::IncreaseOrResetImeError(bool resetFlag, int imeIndex) + { + static int errorNum[2] = {0, 0}; + static time_t past[2] = {time(0), time(0)}; + if (resetFlag == true) { + errorNum[imeIndex] = 0; + past[imeIndex] = 0; + return 0; } - /*! Get keyboard type - \param imeIndex it can be 0 or 1. 0 - default ime, 1 - security ime - \param typeIndex the index of keyboard type. - \return a KeyboardType pointer when it's found. - \return null when it's not found. - \note The returned pointer should not be freed by caller. - */ - KeyboardType* PerUserSession::GetKeyboardType(int imeIndex, int typeIndex) - { - if(typeIndex < 0) { + errorNum[imeIndex]++; + 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) { + past[imeIndex] = now; + errorNum[imeIndex] = 1; + } + return errorNum[imeIndex]; + } + + /*! Get keyboard type + \param imeIndex it can be 0 or 1. 0 - default ime, 1 - security ime + \param typeIndex the index of keyboard type. + \return a KeyboardType pointer when it's found. + \return null when it's not found. + \note The returned pointer should not be freed by caller. + */ + KeyboardType* PerUserSession::GetKeyboardType(int imeIndex, int typeIndex) + { + if(typeIndex < 0) { + return nullptr; + } + if (imeIndex == SECURITY_IME || currentIme[DEFAULT_IME] == currentIme[SECURITY_IME]) { + if (typeIndex >= (int)currentIme[imeIndex]->mTypes.size()) { return nullptr; } - if (imeIndex == SECURITY_IME || currentIme[DEFAULT_IME] == currentIme[SECURITY_IME]) { - if (typeIndex >= (int)currentIme[imeIndex]->mTypes.size()) { - return nullptr; - } - return currentIme[imeIndex]->mTypes[typeIndex]; - } else { - std::u16string imeId = currentIme[imeIndex]->mImeId; - std::vector currentKbdTypes = inputMethodSetting->GetEnabledKeyboardTypes(imeId); - int size = currentKbdTypes.size(); - if (typeIndex >= size) { - return nullptr; - } - int hashCode = currentKbdTypes[typeIndex]; - for(int i=0; i<(int)currentIme[imeIndex]->mTypes.size(); i++) { - if (currentIme[imeIndex]->mTypes[i]->getHashCode() == hashCode) { - return currentIme[imeIndex]->mTypes[i]; - } + return currentIme[imeIndex]->mTypes[typeIndex]; + } else { + std::u16string imeId = currentIme[imeIndex]->mImeId; + std::vector currentKbdTypes = inputMethodSetting->GetEnabledKeyboardTypes(imeId); + int size = currentKbdTypes.size(); + if (typeIndex >= size) { + return nullptr; + } + int hashCode = currentKbdTypes[typeIndex]; + for(int i=0; i<(int)currentIme[imeIndex]->mTypes.size(); i++) { + if (currentIme[imeIndex]->mTypes[i]->getHashCode() == hashCode) { + return currentIme[imeIndex]->mTypes[i]; } } - return nullptr; } + return nullptr; + } - /*! Reset current keyboard type - \param imeIndex it can be 0 or 1. 0 - default ime, 1 - security ime - */ - void PerUserSession::ResetCurrentKeyboardType(int imeIndex) - { - currentKbdIndex[imeIndex] = 0; - int hashCode = 0; - if (imeIndex == DEFAULT_IME) { - hashCode = inputMethodSetting->GetCurrentKeyboardType(); - } else { - hashCode = inputMethodSetting->GetCurrentSysKeyboardType(); - } - KeyboardType* type = nullptr; - if (hashCode == -1) { - type = GetKeyboardType(imeIndex, currentKbdIndex[imeIndex]); - } else { - bool flag = false; - if (imeIndex == SECURITY_IME || currentIme[DEFAULT_IME] == currentIme[SECURITY_IME]) { - for(int i=0; i<(int)currentIme[imeIndex]->mTypes.size(); i++) { - if (currentIme[imeIndex]->mTypes[i]->getHashCode()==hashCode) { - currentKbdIndex[imeIndex] = i; - flag = true; - break; - } - } - } else { - std::vector hashCodeList = inputMethodSetting->GetEnabledKeyboardTypes(currentIme[imeIndex]->mImeId); - for(int i=0; i<(int)hashCodeList.size(); i++) { - if (hashCode == hashCodeList[i]) { - currentKbdIndex[imeIndex] = i; - flag = true; - break; - } + /*! Reset current keyboard type + \param imeIndex it can be 0 or 1. 0 - default ime, 1 - security ime + */ + void PerUserSession::ResetCurrentKeyboardType(int imeIndex) + { + currentKbdIndex[imeIndex] = 0; + int hashCode = 0; + if (imeIndex == DEFAULT_IME) { + hashCode = inputMethodSetting->GetCurrentKeyboardType(); + } else { + hashCode = inputMethodSetting->GetCurrentSysKeyboardType(); + } + KeyboardType* type = nullptr; + if (hashCode == -1) { + type = GetKeyboardType(imeIndex, currentKbdIndex[imeIndex]); + } else { + bool flag = false; + if (imeIndex == SECURITY_IME || currentIme[DEFAULT_IME] == currentIme[SECURITY_IME]) { + for(int i=0; i<(int)currentIme[imeIndex]->mTypes.size(); i++) { + if (currentIme[imeIndex]->mTypes[i]->getHashCode()==hashCode) { + currentKbdIndex[imeIndex] = i; + flag = true; + break; } } - if (flag == false) { - IMSA_HILOGW("The current keyboard type [hashCode=%{public}d] is not found in the current IME. Reset it! [%{public}d]\n", - hashCode, userId_); - type = GetKeyboardType(imeIndex, currentKbdIndex[imeIndex]); - } else if (imsCore[imeIndex] == imsCore[1-imeIndex]) { - currentKbdIndex[1-imeIndex] = currentKbdIndex[imeIndex]; + } else { + std::vector hashCodeList = inputMethodSetting->GetEnabledKeyboardTypes(currentIme[imeIndex]->mImeId); + for(int i=0; i<(int)hashCodeList.size(); i++) { + if (hashCode == hashCodeList[i]) { + currentKbdIndex[imeIndex] = i; + flag = true; + break; + } } } - if (type != nullptr) { - InputMethodSetting tmpSetting; - if (imsCore[imeIndex] == imsCore[1-imeIndex]) { - inputMethodSetting->SetCurrentKeyboardType(type->getHashCode()); - inputMethodSetting->SetCurrentSysKeyboardType(type->getHashCode()); - currentKbdIndex[1-imeIndex] = currentKbdIndex[imeIndex]; - tmpSetting.SetCurrentKeyboardType(type->getHashCode()); - tmpSetting.SetCurrentSysKeyboardType(type->getHashCode()); - } else if (imeIndex == DEFAULT_IME) { - tmpSetting.SetCurrentKeyboardType(type->getHashCode()); - inputMethodSetting->SetCurrentKeyboardType(type->getHashCode()); - } else { - tmpSetting.SetCurrentSysKeyboardType(type->getHashCode()); - inputMethodSetting->SetCurrentSysKeyboardType(type->getHashCode()); - } - Platform::Instance()->SetInputMethodSetting(userId_, tmpSetting); + if (flag == false) { + IMSA_HILOGW("The current keyboard type is not found in the current IME. Reset it!"); + type = GetKeyboardType(imeIndex, currentKbdIndex[imeIndex]); + } else if (imsCore[imeIndex] == imsCore[1-imeIndex]) { + currentKbdIndex[1-imeIndex] = currentKbdIndex[imeIndex]; } } - - /*! Get ime index for the input client - \param inputClient the remote object handler of an input client. - \return 0 - default ime - \return 1 - security ime - \return -1 - input client is not found - */ - int PerUserSession::GetImeIndex(const sptr& inputClient) - { - if (inputClient == nullptr) { - IMSA_HILOGW("PerUserSession::GetImeIndex inputClient is nullptr"); - return -1; + if (type != nullptr) { + InputMethodSetting tmpSetting; + if (imsCore[imeIndex] == imsCore[1-imeIndex]) { + inputMethodSetting->SetCurrentKeyboardType(type->getHashCode()); + inputMethodSetting->SetCurrentSysKeyboardType(type->getHashCode()); + currentKbdIndex[1-imeIndex] = currentKbdIndex[imeIndex]; + tmpSetting.SetCurrentKeyboardType(type->getHashCode()); + tmpSetting.SetCurrentSysKeyboardType(type->getHashCode()); + } else if (imeIndex == DEFAULT_IME) { + tmpSetting.SetCurrentKeyboardType(type->getHashCode()); + inputMethodSetting->SetCurrentKeyboardType(type->getHashCode()); + } else { + tmpSetting.SetCurrentSysKeyboardType(type->getHashCode()); + inputMethodSetting->SetCurrentSysKeyboardType(type->getHashCode()); } + Platform::Instance()->SetInputMethodSetting(userId_, tmpSetting); + } + } - ClientInfo *clientInfo = GetClientInfo(inputClient); - if (clientInfo == nullptr) { - IMSA_HILOGW("PerUserSession::GetImeIndex clientInfo is nullptr"); - return -1; - } + /*! Get ime index for the input client + \param inputClient the remote object handler of an input client. + \return 0 - default ime + \return 1 - security ime + \return -1 - input client is not found + */ + int PerUserSession::GetImeIndex(const sptr& inputClient) + { + if (inputClient == nullptr) { + IMSA_HILOGW("PerUserSession::GetImeIndex inputClient is nullptr"); + return -1; + } - if (clientInfo->attribute.GetSecurityFlag() == true) { - return SECURITY_IME; - } - return DEFAULT_IME; + ClientInfo *clientInfo = GetClientInfo(inputClient); + if (clientInfo == nullptr) { + IMSA_HILOGW("PerUserSession::GetImeIndex clientInfo is nullptr"); + return -1; } - /*! Copy session data from one IME to another IME - \param imeIndex it can be 0 or 1. - \n 0 - default ime, 1 - security ime - */ - void PerUserSession::CopyInputMethodService(int imeIndex) - { - imsCore[imeIndex] = imsCore[1-imeIndex]; - localControlChannel[imeIndex] = localControlChannel[1-imeIndex]; - inputControlChannel[imeIndex] = inputControlChannel[1-imeIndex]; - inputMethodToken[imeIndex] = inputMethodToken[1-imeIndex]; - currentKbdIndex[imeIndex] = currentKbdIndex[1-imeIndex]; - int hashCode[2]; - hashCode[0] = inputMethodSetting->GetCurrentKeyboardType(); - hashCode[1] = inputMethodSetting->GetCurrentSysKeyboardType(); - if (hashCode[imeIndex] != hashCode[1-imeIndex]) { - hashCode[imeIndex] = hashCode[1-imeIndex]; - inputMethodSetting->SetCurrentKeyboardType(hashCode[0]); - inputMethodSetting->SetCurrentSysKeyboardType(hashCode[1]); - - InputMethodSetting tmpSetting; - tmpSetting.ClearData(); - tmpSetting.SetCurrentKeyboardType(hashCode[0]); - tmpSetting.SetCurrentSysKeyboardType(hashCode[1]); - Platform::Instance()->SetInputMethodSetting(userId_, tmpSetting); - } + if (clientInfo->attribute.GetSecurityFlag() == true) { + return SECURITY_IME; } + return DEFAULT_IME; + } - /*! Get ClientInfo - \param inputClient the IInputClient remote handler of given input client - \return a pointer of ClientInfo if client is found - \n null if client is not found - \note the clientInfo pointer should not be freed by caller - */ - ClientInfo* PerUserSession::GetClientInfo(const sptr& inputClient) - { - if (inputClient == nullptr) { - IMSA_HILOGE("PerUserSession::GetClientInfo inputClient is nullptr"); - return nullptr; - } - sptr b = Platform::RemoteBrokerToObject(inputClient); - std::map, ClientInfo*>::iterator it = mapClients.find(b); - if (it == mapClients.end()) { - return nullptr; - } + /*! Copy session data from one IME to another IME + \param imeIndex it can be 0 or 1. + \n 0 - default ime, 1 - security ime + */ + void PerUserSession::CopyInputMethodService(int imeIndex) + { + imsCore[imeIndex] = imsCore[1-imeIndex]; + localControlChannel[imeIndex] = localControlChannel[1-imeIndex]; + inputControlChannel[imeIndex] = inputControlChannel[1-imeIndex]; + inputMethodToken[imeIndex] = inputMethodToken[1-imeIndex]; + currentKbdIndex[imeIndex] = currentKbdIndex[1-imeIndex]; + int hashCode[2]; + hashCode[0] = inputMethodSetting->GetCurrentKeyboardType(); + hashCode[1] = inputMethodSetting->GetCurrentSysKeyboardType(); + if (hashCode[imeIndex] != hashCode[1-imeIndex]) { + hashCode[imeIndex] = hashCode[1-imeIndex]; + inputMethodSetting->SetCurrentKeyboardType(hashCode[0]); + inputMethodSetting->SetCurrentSysKeyboardType(hashCode[1]); + + InputMethodSetting tmpSetting; + tmpSetting.ClearData(); + tmpSetting.SetCurrentKeyboardType(hashCode[0]); + tmpSetting.SetCurrentSysKeyboardType(hashCode[1]); + Platform::Instance()->SetInputMethodSetting(userId_, tmpSetting); + } + } - return (ClientInfo*) it->second; + /*! Get ClientInfo + \param inputClient the IInputClient remote handler of given input client + \return a pointer of ClientInfo if client is found + \n null if client is not found + \note the clientInfo pointer should not be freed by caller + */ + ClientInfo* PerUserSession::GetClientInfo(const sptr& inputClient) + { + if (inputClient == nullptr) { + IMSA_HILOGE("PerUserSession::GetClientInfo inputClient is nullptr"); + return nullptr; + } + sptr b = Platform::RemoteBrokerToObject(inputClient); + std::map, ClientInfo*>::iterator it = mapClients.find(b); + if (it == mapClients.end()) { + return nullptr; } - void PerUserSession::BindInputAbility(){ - IMSA_HILOGE("PerUserSession::BindInputAbility"); - AAFwk::Want want; - want.SetAction("action.system.inputmethod"); - want.SetElementName("com.example.kikakeyboard","com.example.kikakeyboard.MainAbility"); - sptr stub(new (std::nothrow) InputMethodAbilityConnectionStub(0)); - sptr connCallback = new (std::nothrow) AAFwk::AbilityConnectionProxy(stub); - GetAbilityManagerService()->StartAbility(want); + return (ClientInfo*) it->second; + } + + void PerUserSession::BindInputAbility(){ + IMSA_HILOGE("PerUserSession::BindInputAbility"); + AAFwk::Want want; + want.SetAction("action.system.inputmethod"); + want.SetElementName("com.example.kikakeyboard","com.example.kikakeyboard.MainAbility"); + sptr stub(new (std::nothrow) InputMethodAbilityConnectionStub(0)); + sptr connCallback = new (std::nothrow) AAFwk::AbilityConnectionProxy(stub); + GetAbilityManagerService()->StartAbility(want); + } + + sptr PerUserSession::GetAbilityManagerService() + { + IMSA_HILOGE("GetAbilityManagerService start"); + sptr abilityMsObj = + OHOS::DelayedSingleton::GetInstance()->GetSystemAbility(ABILITY_MGR_SERVICE_ID); + if (abilityMsObj == nullptr) { + IMSA_HILOGE("failed to get ability manager service"); + return nullptr; } + return iface_cast(abilityMsObj); + } - sptr PerUserSession::GetAbilityManagerService() - { - IMSA_HILOGE("GetAbilityManagerService start"); - sptr abilityMsObj = - OHOS::DelayedSingleton::GetInstance()->GetSystemAbility(ABILITY_MGR_SERVICE_ID); - if (abilityMsObj == nullptr) { - IMSA_HILOGE("failed to get ability manager service"); - return nullptr; - } - return iface_cast(abilityMsObj); + /*! Prepare input. Called by an input client. + \n Run in work thread of this user + \param msg the parameters from remote client are saved in msg->msgContent_ + \return ErrorCode + */ + void PerUserSession::OnPrepareInput(Message* msg) + { + IMSA_HILOGI("PerUserSession::OnPrepareInput Start...[%{public}d]\n", userId_); + MessageParcel* data = msg->msgContent_; + int pid = data->ReadInt32(); + int uid = data->ReadInt32(); + int displayId = data->ReadInt32(); + + sptr clientObject = data->ReadRemoteObject(); + if (clientObject == nullptr) { + IMSA_HILOGI("PerUserSession::OnPrepareInput clientObject is null"); + } + sptr client = new InputClientProxy(clientObject); + sptr channelObject = data->ReadRemoteObject(); + if (channelObject == nullptr) { + IMSA_HILOGI("PerUserSession::OnPrepareInput channelObject is null"); + } + sptr channel = new InputDataChannelProxy(channelObject); + InputAttribute* attribute = data->ReadParcelable(); + if (attribute ==nullptr) { + IMSA_HILOGI("PerUserSession::OnPrepareInput attribute is nullptr"); } - /*! Prepare input. Called by an input client. - \n Run in work thread of this user - \param msg the parameters from remote client are saved in msg->msgContent_ - \return ErrorCode - */ - void PerUserSession::OnPrepareInput(Message* msg) - { - IMSA_HILOGI("PerUserSession::OnPrepareInput Start...[%{public}d]\n", userId_); - MessageParcel* data = msg->msgContent_; - int pid = data->ReadInt32(); - int uid = data->ReadInt32(); - int displayId = data->ReadInt32(); - - sptr clientObject = data->ReadRemoteObject(); - if (clientObject == nullptr) { - IMSA_HILOGI("PerUserSession::OnPrepareInput clientObject is null"); - } - sptr client = new InputClientProxy(clientObject); - sptr channelObject = data->ReadRemoteObject(); - if (channelObject == nullptr) { - IMSA_HILOGI("PerUserSession::OnPrepareInput channelObject is null"); - } - sptr channel = new InputDataChannelProxy(channelObject); - InputAttribute* attribute = data->ReadParcelable(); - if (attribute ==nullptr) { - IMSA_HILOGI("PerUserSession::OnPrepareInput attribute is nullptr"); - } + int ret = AddClient(pid, uid, displayId, client, channel, *attribute); + if (ret != ErrorCode::NO_ERROR) { + IMSA_HILOGE("PerUserSession::OnPrepareInput Aborted! %{public}s", ErrorCode::ToString(ret)); + return; + } + SetDisplayId(displayId); + int index = GetImeIndex(client); + IMSA_HILOGI("PerUserSession::OnPrepareInput index = %{public}d",index); + currentIndex = index; + IMSA_HILOGI("PerUserSession::OnPrepareInput BindInputAbility start"); + BindInputAbility(); + IMSA_HILOGI("PerUserSession::OnPrepareInput BindInputAbility end"); + } - int ret = AddClient(pid, uid, displayId, client, channel, *attribute); - if (ret != ErrorCode::NO_ERROR) { - IMSA_HILOGE("PerUserSession::OnPrepareInput Aborted! %{public}s [%{public}d]\n", ErrorCode::ToString(ret), userId_); - return; - } - SetDisplayId(displayId); - int index = GetImeIndex(client); - IMSA_HILOGI("PerUserSession::OnPrepareInput index = %{public}d",index); - currentIndex = index; - IMSA_HILOGI("PerUserSession::OnPrepareInput BindInputAbility start"); - BindInputAbility(); - IMSA_HILOGI("PerUserSession::OnPrepareInput BindInputAbility end"); - } - - /*! Release input. Called by an input client. - \n Run in work thread of this user - \param msg the parameters from remote client are saved in msg->msgContent_ - \return ErrorCode - */ - void PerUserSession::OnReleaseInput(Message* msg) - { - IMSA_HILOGI("PerUserSession::OnReleaseInput Start...[%{public}d]\n", userId_); - MessageParcel* data = msg->msgContent_; - - sptr clientObject = data->ReadRemoteObject(); - sptr client = new InputClientProxy(clientObject); - sptr interface = client; - int remainClientNum = 0; - if (currentClient == interface) { - HideKeyboard(client); - } - int ret = RemoveClient(client, &remainClientNum); - if (ret != ErrorCode::NO_ERROR) { - IMSA_HILOGE("PerUserSession::OnReleaseInput Aborted! Failed to RemoveClient [%{public}d]\n", userId_); - } - IMSA_HILOGI("PerUserSession::OnReleaseInput End...[%{public}d]\n", userId_); + /*! Release input. Called by an input client. + \n Run in work thread of this user + \param msg the parameters from remote client are saved in msg->msgContent_ + \return ErrorCode + */ + void PerUserSession::OnReleaseInput(Message* msg) + { + IMSA_HILOGI("PerUserSession::OnReleaseInput Start...[%{public}d]\n", userId_); + MessageParcel* data = msg->msgContent_; + + sptr clientObject = data->ReadRemoteObject(); + sptr client = new InputClientProxy(clientObject); + sptr interface = client; + int remainClientNum = 0; + if (currentClient == interface) { + HideKeyboard(client); + } + int ret = RemoveClient(client, &remainClientNum); + if (ret != ErrorCode::NO_ERROR) { + IMSA_HILOGE("PerUserSession::OnReleaseInput Aborted! Failed to RemoveClient [%{public}d]\n", userId_); } + IMSA_HILOGI("PerUserSession::OnReleaseInput End...[%{public}d]\n", userId_); + } - /*! Start input. Called by an input client. - \n Run in work thread of this user - \param msg the parameters from remote client are saved in msg->msgContent_ - \return ErrorCode - */ - void PerUserSession::OnStartInput(Message* msg) - { - IMSA_HILOGI("PerUserSession::OnStartInput"); - MessageParcel* data = msg->msgContent_; - sptr clientObject = data->ReadRemoteObject(); - sptr client = new InputClientProxy(clientObject); - int ret = ShowKeyboard(client); - if (ret != ErrorCode::NO_ERROR) { - IMSA_HILOGE("PerUserSession::OnStartInput Aborted! %{public}s [%{public}d]\n", ErrorCode::ToString(ret), userId_); - } else { - IMSA_HILOGI("PerUserSession::OnStartInput End...[%{public}d]\n", userId_); - } + /*! Start input. Called by an input client. + \n Run in work thread of this user + \param msg the parameters from remote client are saved in msg->msgContent_ + \return ErrorCode + */ + void PerUserSession::OnStartInput(Message* msg) + { + IMSA_HILOGI("PerUserSession::OnStartInput"); + MessageParcel* data = msg->msgContent_; + sptr clientObject = data->ReadRemoteObject(); + sptr client = new InputClientProxy(clientObject); + int ret = ShowKeyboard(client); + if (ret != ErrorCode::NO_ERROR) { + IMSA_HILOGE("PerUserSession::OnStartInput Aborted! %{public}s", ErrorCode::ToString(ret)); + } else { + IMSA_HILOGI("PerUserSession::OnStartInput End...[%{public}d]\n", userId_); } + } void PerUserSession::onSetInputMethodCore(Message* msg) { @@ -1384,40 +1380,40 @@ namespace MiscServices { int index = currentIndex; IMSA_HILOGI("PerUserSession::onSetInputMethodCore index = [%{public}d]\n", index); if (index >= MAX_IME || index < 0) { - IMSA_HILOGE("PerUserSession::onSetInputMethodCore Aborted! %{public}s [%{public}d]\n", ErrorCode::ToString(ErrorCode::ERROR_BAD_PARAMETERS), userId_); - return; + IMSA_HILOGE("PerUserSession::onSetInputMethodCore Aborted! ErrorCode::ERROR_BAD_PARAMETERS"); + return; } if (imsCore[index] != nullptr) { - IMSA_HILOGI("PerUserSession::onSetInputMethodCore End... Input Method Service has already been started ! [%{public}d]\n", userId_); - return; + IMSA_HILOGI("PerUserSession::onSetInputMethodCore End... Input Method Service has already been started ! "); + return; } imsCore[index]=core; int ret = StartInputMethod(index); if (ret != ErrorCode::NO_ERROR) { - IMSA_HILOGE("PerUserSession::onSetInputMethodCore Aborted! %{public}s [%{public}d]\n", ErrorCode::ToString(ret), userId_); + IMSA_HILOGE("PerUserSession::onSetInputMethodCore Aborted! %{public}s", ErrorCode::ToString(ret)); } else { - IMSA_HILOGI("PerUserSession::onSetInputMethodCore End...[%{public}d]\n", userId_); + IMSA_HILOGI("PerUserSession::onSetInputMethodCore End...[%{public}d]\n", userId_); } } - /*! Stop input. Called by an input client. - \n Run in work thread of this user - \param msg the parameters from remote client are saved in msg->msgContent_ - \return ErrorCode - */ - void PerUserSession::OnStopInput(Message* msg) - { - IMSA_HILOGI("PerUserSession::OnStopInput"); - MessageParcel* data = msg->msgContent_; + /*! Stop input. Called by an input client. + \n Run in work thread of this user + \param msg the parameters from remote client are saved in msg->msgContent_ + \return ErrorCode + */ + void PerUserSession::OnStopInput(Message* msg) + { + IMSA_HILOGI("PerUserSession::OnStopInput"); + MessageParcel* data = msg->msgContent_; - sptr clientObject = data->ReadRemoteObject(); - sptr client = new InputClientProxy(clientObject); - int ret = HideKeyboard(client); - if (ret != ErrorCode::NO_ERROR) { - IMSA_HILOGE("PerUserSession::OnStopInput Aborted! %{public}s [%{public}d]\n", ErrorCode::ToString(ret), userId_); - } else { - IMSA_HILOGI("PerUserSession::OnStopInput End...[%{public}d]\n", userId_); - } + sptr clientObject = data->ReadRemoteObject(); + sptr client = new InputClientProxy(clientObject); + int ret = HideKeyboard(client); + if (ret != ErrorCode::NO_ERROR) { + IMSA_HILOGE("PerUserSession::OnStopInput Aborted! %{public}s", ErrorCode::ToString(ret)); + } else { + IMSA_HILOGI("PerUserSession::OnStopInput End...[%{public}d]\n", userId_); } } } +} diff --git a/services/src/peruser_setting.cpp b/services/src/peruser_setting.cpp index 64608a7046babb6bd1f811f63d540e3a6cefc9cd..bafe60095d896318874c87679957c4f3eba19f83 100644 --- a/services/src/peruser_setting.cpp +++ b/services/src/peruser_setting.cpp @@ -13,7 +13,6 @@ * limitations under the License. */ - #include "unistd.h" //usleep #include "peruser_setting.h" #include "platform.h" @@ -23,8 +22,7 @@ namespace MiscServices { /*! Constructor \param userId the id number of this user */ - PerUserSetting::PerUserSetting(int userId) - { + PerUserSetting::PerUserSetting(int userId) { userId_ = userId; currentImeId = Utils::to_utf16(""); userState = UserState::USER_STATE_STARTED; @@ -39,13 +37,12 @@ namespace MiscServices { } } - /*! Initialize data for this user. - \n It's called when this user is unlocked. The work includes: - \li read all installed input method engine information from the system - \li read input method setting data from the system - */ - void PerUserSetting::Initialize() - { + /* Initialize data for this user. + * It's called when this user is unlocked. The work includes: + * read all installed input method engine information from the system + * read input method setting data from the system + */ + void PerUserSetting::Initialize() { userState = UserState::USER_STATE_UNLOCKED; inputMethodProperties.clear(); @@ -76,8 +73,7 @@ namespace MiscServices { \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) - { + int PerUserSetting::OnPackageAdded(std::u16string& packageName, bool* isSecurityIme) { if (isSecurityIme) { *isSecurityIme = false; } @@ -123,8 +119,7 @@ namespace MiscServices { \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) - { + int PerUserSetting::OnPackageRemoved(std::u16string& packageName, bool* isSecurityIme) { if (isSecurityIme) { *isSecurityIme = false; } @@ -175,8 +170,7 @@ namespace MiscServices { \return ErrorCode::NO_ERROR update the setting data to input method management system. \return ErrorCode::ERROR_SETTING_SAME_VALUE the current value is same as the one in the system. */ - int PerUserSetting::OnSettingChanged(const std::u16string& key, const std::u16string& value) - { + int PerUserSetting::OnSettingChanged(const std::u16string& key, const std::u16string& value) { std::u16string currentValue = inputMethodSetting.GetValue(key); if (currentValue == value) { @@ -203,8 +197,7 @@ namespace MiscServices { /*! Switch to the next input method service. */ - void PerUserSetting::OnAdvanceToNext() - { + void PerUserSetting::OnAdvanceToNext() { bool flag = false; std::u16string enabledInputMethods = inputMethodSetting.GetValue(InputMethodSetting::ENABLED_INPUT_METHODS_TAG); std::u16string imeId; @@ -240,13 +233,12 @@ namespace MiscServices { Platform::Instance()->SetInputMethodSetting(userId_, tmpSetting); } - /*! It's Called when this user is locked. - \n Release data for this user including: - \li release input method engine information - \li release input method setting data - */ - void PerUserSetting::OnUserLocked() - { + /* It's Called when this user is locked. + * Release data for this user including: + * release input method engine information + * release input method setting data + */ + void PerUserSetting::OnUserLocked() { if (userState == UserState::USER_STATE_STARTED) { return; } @@ -267,15 +259,14 @@ namespace MiscServices { inputMethodSetting.ClearData(); } - /*! Print the related information for this user into the given stream - \n The information includes: - \li The user id and user state - \li The information of all input method engine installed in the system - \li The input method setting data of this user. - \param fd the raw file descriptor that the dump is being sent to - */ - void PerUserSetting::Dump(int fd) - { + /* Print the related information for this user into the given stream + * The information includes: + * The user id and user state + * The information of all input method engine installed in the system + * The input method setting data of this user. + * param fd the raw file descriptor that the dump is being sent to + */ + void PerUserSetting::Dump(int fd) { int size = inputMethodProperties.size(); dprintf(fd, "\n - User Setting State :\n"); dprintf(fd, " * Installed IME count = %d\n", size); @@ -302,8 +293,7 @@ namespace MiscServices { \return UserState::USER_STATE_STARTED user is started \return UserState::USER_STATE_UNLOCKED user is unlocked */ - int PerUserSetting::GetUserState() - { + int PerUserSetting::GetUserState() { return userState; } @@ -312,8 +302,7 @@ namespace MiscServices { \return null when there is no enabled IME in the system. \note The returned pointer should NOT be freed by caller */ - InputMethodProperty* PerUserSetting::GetCurrentInputMethod() - { + InputMethodProperty* PerUserSetting::GetCurrentInputMethod() { for(int i=0; i<(int)inputMethodProperties.size(); i++) { if (currentImeId == inputMethodProperties[i]->mImeId) { return inputMethodProperties[i]; @@ -328,8 +317,7 @@ namespace MiscServices { \return null when there is no security IME in the system. \note The returned pointer should NOT be freed by caller */ - InputMethodProperty* PerUserSetting::GetSecurityInputMethod() - { + InputMethodProperty* PerUserSetting::GetSecurityInputMethod() { InputMethodProperty* ime = nullptr; std::u16string systemLocales = inputMethodSetting.GetValue(InputMethodSetting::SYSTEM_LOCALE_TAG); for(int i=0; i<(int)inputMethodProperties.size(); i++) { @@ -359,8 +347,7 @@ namespace MiscServices { \return null when the next enabled IME is not available. \note The returned pointer should NOT be freed by caller */ - InputMethodProperty* PerUserSetting::GetNextInputMethod() - { + InputMethodProperty* PerUserSetting::GetNextInputMethod() { bool flag = false; std::u16string enabledInputMethods = inputMethodSetting.GetValue(InputMethodSetting::ENABLED_INPUT_METHODS_TAG); std::u16string imeId; @@ -384,8 +371,7 @@ namespace MiscServices { \return a pointer of InputMethodSetting. \note The returned pointer should NOT be freed by caller */ - InputMethodSetting* PerUserSetting::GetInputMethodSetting() - { + InputMethodSetting* PerUserSetting::GetInputMethodSetting() { return &inputMethodSetting; } @@ -393,8 +379,7 @@ namespace MiscServices { \param[out] properties the details will be written to the param properties \return ErrorCode::NO_ERROR */ - int32_t PerUserSetting::ListInputMethodEnabled(std::vector *properties) - { + int32_t PerUserSetting::ListInputMethodEnabled(std::vector *properties) { std::u16string enabledInputMethods = inputMethodSetting.GetValue(InputMethodSetting::ENABLED_INPUT_METHODS_TAG); for(int i=0; i<(int)inputMethodProperties.size(); i++) { @@ -409,8 +394,7 @@ namespace MiscServices { \param[out] properties the details will be written to the param properties \return ErrorCode::NO_ERROR */ - int32_t PerUserSetting::ListInputMethod(std::vector *properties) - { + int32_t PerUserSetting::ListInputMethod(std::vector *properties) { for(int i=0; i<(int)inputMethodProperties.size(); i++) { properties->push_back(inputMethodProperties[i]); } @@ -422,8 +406,7 @@ namespace MiscServices { \param[out] types the data of type list of the given IME will be written to types \return ErrorCode::NO_ERROR */ - int32_t PerUserSetting::ListKeyboardType(const std::u16string& imeId, std::vector *types) - { + int32_t PerUserSetting::ListKeyboardType(const std::u16string& imeId, std::vector *types) { for(int i=0; i<(int)inputMethodProperties.size(); i++) { if (imeId == inputMethodProperties[i]->mImeId) { for(int j=0; j<(int)inputMethodProperties[i]->mTypes.size(); j++) { @@ -441,8 +424,7 @@ namespace MiscServices { \return null when the given IME is not available \note the returned pointer should not be freed by the caller. */ - InputMethodProperty* PerUserSetting::GetInputMethodProperty(const std::u16string& imeId) - { + InputMethodProperty* PerUserSetting::GetInputMethodProperty(const std::u16string& imeId) { for(int i=0; i<(int)inputMethodProperties.size(); i++) { if (inputMethodProperties[i]->mImeId == imeId) { return inputMethodProperties[i]; @@ -457,8 +439,7 @@ namespace MiscServices { \return language value when the given hashCode is found \return an empty string when the given hashCode is not found */ - std::u16string PerUserSetting::GetKeyboardTypeLanguage(const InputMethodProperty* property, int hashCode) - { + std::u16string PerUserSetting::GetKeyboardTypeLanguage(const InputMethodProperty* property, int hashCode) { for(int i=0; i<(int)property->mTypes.size(); i++) { if (property->mTypes[i]->getHashCode() == hashCode) { return property->mTypes[i]->getLanguage(); @@ -469,8 +450,7 @@ namespace MiscServices { /*! Init input method setting data */ - void PerUserSetting::InitInputMethodSetting() - { + void PerUserSetting::InitInputMethodSetting() { bool flag = inputMethodSetting.FindKey(InputMethodSetting::ENABLED_INPUT_METHODS_TAG); if (flag == false) { for(int i=0; i<(int)inputMethodProperties.size(); i++) { @@ -506,8 +486,7 @@ namespace MiscServices { \li If no system ime is there, we use the first enabled ime as current ime. \li If no enabled ime, set current ime as null. */ - void PerUserSetting::ResetCurrentInputMethod() - { + void PerUserSetting::ResetCurrentInputMethod() { std::u16string systemLocales = inputMethodSetting.GetValue(InputMethodSetting::SYSTEM_LOCALE_TAG); std::u16string enabledInputMethods = inputMethodSetting.GetValue(InputMethodSetting::ENABLED_INPUT_METHODS_TAG); std::u16string imeId; @@ -554,8 +533,7 @@ namespace MiscServices { \param packageName the packageName of the given IME \return the id of the given IME */ - std::u16string PerUserSetting::GetImeId(const std::u16string& packageName) - { + std::u16string PerUserSetting::GetImeId(const std::u16string& packageName) { for(int i=0; i<(int)inputMethodProperties.size(); i++) { if (inputMethodProperties[i]->mPackageName == packageName) { return inputMethodProperties[i]->mImeId; @@ -569,8 +547,7 @@ namespace MiscServices { \return true - It's a security Ime \n false - It's not a security Ime */ - bool PerUserSetting::CheckIfSecurityIme(const InputMethodProperty& property) - { + bool PerUserSetting::CheckIfSecurityIme(const InputMethodProperty& property) { return property.isSystemIme; } } diff --git a/services/src/platform.cpp b/services/src/platform.cpp index 9dc3ffa734febf8378bcbea2947494f7bec190e6..c9a3b1f8d4ed48b363eedab9f88bafba5a5a4699 100644 --- a/services/src/platform.cpp +++ b/services/src/platform.cpp @@ -13,15 +13,13 @@ * limitations under the License. */ - #include "global.h" #include "platform.h" #include "platform_callback_stub.h" namespace OHOS { namespace MiscServices { - void Platform::SetPlatform(const sptr < IPlatformApi >& platformApi) - { + void Platform::SetPlatform(const sptr < IPlatformApi >& platformApi) { this->platformApi = platformApi; sptr < IPlatformCallback > cb = new PlatformCallbackStub(); this->platformApi->registerCallback(cb); @@ -29,20 +27,17 @@ namespace MiscServices { /*! Constructor */ - Platform::Platform() - { + Platform::Platform() { } /*! Destructor */ - Platform::~Platform() - { + Platform::~Platform() { } /*! Single instance exists in the service */ - Platform* Platform::Instance() - { + Platform* Platform::Instance() { static Platform* platform = nullptr; if (platform == nullptr) { platform = new Platform(); @@ -57,8 +52,7 @@ namespace MiscServices { \return the remote object handler of started input method service. */ sptr < IInputMethodCore > Platform::BindInputMethodService(int userId, const std::u16string& packageName, - const std::u16string& intention) - { + const std::u16string& intention) { if (platformApi == nullptr) { return nullptr; } @@ -70,8 +64,7 @@ namespace MiscServices { \param packageName the packageName of the given input method engine which is going to stop \return ErrorCode */ - int Platform::UnbindInputMethodService(int userId, const std::u16string& packageName) - { + int Platform::UnbindInputMethodService(int userId, const std::u16string& packageName) { if (platformApi == nullptr) { return ErrorCode::ERROR_NULL_POINTER; } @@ -84,8 +77,7 @@ namespace MiscServices { \param packageName the packageName of the given input method engine \return ErrorCode */ - sptr < IRemoteObject > Platform::CreateWindowToken(int userId, int displayId, const std::u16string& packageName) - { + sptr < IRemoteObject > Platform::CreateWindowToken(int userId, int displayId, const std::u16string& packageName) { if (platformApi == nullptr) { return nullptr; } @@ -97,8 +89,7 @@ namespace MiscServices { \param packageName the packageName of the given input method engine \return ErrorCode */ - int Platform::DestroyWindowToken(int userId, const std::u16string& packageName) - { + int Platform::DestroyWindowToken(int userId, const std::u16string& packageName) { if (platformApi == nullptr) { return ErrorCode::ERROR_NULL_POINTER; } @@ -110,8 +101,7 @@ namespace MiscServices { \param[out] inputMethodProperties the input method engine list installed in the system for the given user \return ErrorCode */ - int Platform::ListInputMethod(int userId, std::vector < InputMethodProperty* > * inputMethodProperties) - { + int Platform::ListInputMethod(int userId, std::vector < InputMethodProperty* > * inputMethodProperties) { return 0; } @@ -121,8 +111,8 @@ namespace MiscServices { \param[out] inputMethodProperty the input method engine information for the given package \return ErrorCode */ - int Platform::GetInputMethodProperty(int userId, const std::u16string& packageName, InputMethodProperty * inputMethodProperty) - { + int Platform::GetInputMethodProperty(int userId, const std::u16string& packageName, + InputMethodProperty* inputMethodProperty) { if (platformApi == nullptr) { return ErrorCode::ERROR_NULL_POINTER; } @@ -134,8 +124,8 @@ namespace MiscServices { \param[out] inputMethodSetting the input method setting data for the given user \return ErrorCode */ - int Platform::GetInputMethodSetting(int userId, InputMethodSetting * inputMethodSetting) - { + + int Platform::GetInputMethodSetting(int userId, InputMethodSetting* inputMethodSetting) { return 0; } @@ -144,8 +134,7 @@ namespace MiscServices { \param inputMethodSetting the input method setting data for the given user \return ErrorCode */ - int Platform::SetInputMethodSetting(int userId, const InputMethodSetting& inputMethodSetting) - { + int Platform::SetInputMethodSetting(int userId, const InputMethodSetting& inputMethodSetting) { if (platformApi == nullptr) { return ErrorCode::ERROR_NULL_POINTER; } @@ -156,8 +145,7 @@ namespace MiscServices { \return true - a physical keyboard is connected \n false - no physical keyboard */ - bool Platform::CheckPhysicalKeyboard() - { + bool Platform::CheckPhysicalKeyboard() { return true; } @@ -165,8 +153,7 @@ namespace MiscServices { \return true - the remote caller is from a valid window \n false - the remote caller is not from a valid window */ - bool Platform::IsValidWindow(int uid, int pid, int displayId) - { + bool Platform::IsValidWindow(int uid, int pid, int displayId) { (void)uid; (void)pid; (void)displayId; @@ -177,8 +164,7 @@ namespace MiscServices { \return true - the remote caller is from a focused window \n false - the remote caller is not from a focused window */ - bool Platform::IsWindowFocused(int uid, int pid, int displayId) - { + bool Platform::IsWindowFocused(int uid, int pid, int displayId) { (void)uid; (void)pid; (void)displayId; diff --git a/services/src/platform_api_proxy.cpp b/services/src/platform_api_proxy.cpp index 3218f9a99b9e9aac512859d6edd5e45d39a87da5..67b9db4cf575fd0d7c5ad04435a8220a8c27accb 100644 --- a/services/src/platform_api_proxy.cpp +++ b/services/src/platform_api_proxy.cpp @@ -24,27 +24,21 @@ #include #include - /*! \class PlatformApiProxy \brief The proxy implementation of IPlatformApi - - \todo This class will be deleted on target platform */ namespace OHOS { namespace MiscServices { - class PlatformApi : public IRemoteProxy < IPlatformApi > { + class PlatformApiProxy : public IRemoteProxy < IPlatformApi > { public: - PlatformApi(const sptr < IRemoteObject >& impl) - : IRemoteProxy < IPlatformApi >(impl) - { + PlatformApiProxy(const sptr& impl) + : IRemoteProxy < IPlatformApi >(impl) { } - ~PlatformApi() - { + ~PlatformApiProxy() { } - int32_t registerCallback(const sptr < IPlatformCallback >& cb) - { + int32_t registerCallback(const sptr < IPlatformCallback >& cb) { MessageParcel data, reply; MessageOption option; data.WriteInterfaceToken(GetDescriptor()); @@ -64,8 +58,8 @@ namespace MiscServices { return Utils::to_utf16("20210814"); } - sptr < IInputMethodCore > bindInputMethodService(const std::u16string& packageName, const std::u16string& intention, int userId) - { + sptr < IInputMethodCore > bindInputMethodService(const std::u16string& packageName, + const std::u16string& intention, int userId) { MessageParcel data, reply; MessageOption option; data.WriteInterfaceToken(GetDescriptor()); @@ -87,8 +81,7 @@ namespace MiscServices { return ims; } - int32_t unbindInputMethodService(int userId, const std::u16string& packageName) - { + int32_t unbindInputMethodService(int userId, const std::u16string& packageName) { MessageParcel data, reply; MessageOption option; data.WriteInterfaceToken(GetDescriptor()); @@ -105,8 +98,7 @@ namespace MiscServices { return ErrorCode::NO_ERROR; } - sptr < IRemoteObject > createWindowToken(int userId, int displayId, const std::u16string& packageName) - { + sptr < IRemoteObject > createWindowToken(int userId, int displayId, const std::u16string& packageName) { MessageParcel data, reply; MessageOption option; data.WriteInterfaceToken(GetDescriptor()); @@ -126,8 +118,7 @@ namespace MiscServices { return token; } - int32_t destroyWindowToken(int userId, const std::u16string& packageName) - { + int32_t destroyWindowToken(int userId, const std::u16string& packageName) { MessageParcel data, reply; MessageOption option; data.WriteInterfaceToken(GetDescriptor()); @@ -138,13 +129,14 @@ namespace MiscServices { return status; } int code = reply.ReadException(); - if (code != 0) // code=0, means no exception. + if (code != 0) { + // code=0, means no exception. return code; + } return ErrorCode::NO_ERROR; } - int32_t listInputMethod(int userId, std::vector < InputMethodProperty* > * inputMethodProperties) - { + int32_t listInputMethod(int userId, std::vector < InputMethodProperty* >* inputMethodProperties) { MessageParcel data, reply; MessageOption option; data.WriteInterfaceToken(GetDescriptor()); @@ -154,11 +146,13 @@ namespace MiscServices { return status; } int code = reply.ReadException(); - if (code != 0) // code=0, means no exception. + if (code != 0) { + // code=0, means no exception. return code; + } int size = reply.ReadInt32(); for (int i = 0; i < size; i++) { - InputMethodProperty * property = new InputMethodProperty(); + InputMethodProperty* property = new InputMethodProperty(); property = reply.ReadParcelable(); inputMethodProperties->push_back(property); } @@ -166,8 +160,8 @@ namespace MiscServices { } - virtual int32_t getInputMethodProperty(int userId, const std::u16string& packageName, InputMethodProperty * inputMethodProperty) - { + virtual int32_t getInputMethodProperty(int userId, const std::u16string& packageName, + InputMethodProperty* inputMethodProperty) { MessageParcel data, reply; MessageOption option; data.WriteInterfaceToken(GetDescriptor()); @@ -178,14 +172,15 @@ namespace MiscServices { return status; } int code = reply.ReadException(); - if (code != 0) // code=0, means no exception. + if (code != 0) { + // code=0, means no exception. return code; + } inputMethodProperty = reply.ReadParcelable(); return status; } - int32_t getInputMethodSetting(int userId, InputMethodSetting * inputMethodSetting) - { + int32_t getInputMethodSetting(int userId, InputMethodSetting* inputMethodSetting) { MessageParcel data, reply; MessageOption option; data.WriteInterfaceToken(GetDescriptor()); @@ -195,14 +190,15 @@ namespace MiscServices { return status; } int code = reply.ReadException(); - if (code != 0) // code=0, means no exception. + if (code != 0) { + // code=0, means no exception. return code; + } inputMethodSetting = reply.ReadParcelable(); return status; } - int32_t setInputMethodSetting(int userId, const InputMethodSetting& inputMethodSetting) - { + int32_t setInputMethodSetting(int userId, const InputMethodSetting& inputMethodSetting) { MessageParcel data, reply; MessageOption option; data.WriteInterfaceToken(GetDescriptor()); @@ -213,8 +209,10 @@ namespace MiscServices { return status; } int code = reply.ReadException(); - if (code != 0) // code=0, means no exception. + if (code != 0) { + // code=0, means no exception. return code; + } return ErrorCode::NO_ERROR; } }; diff --git a/services/src/platform_callback_proxy.cpp b/services/src/platform_callback_proxy.cpp index 9f0563585aaee437ee6042f3720f6b7184741b36..4389700c73000514cb463bea6e71d44f8e8bcabc 100644 --- a/services/src/platform_callback_proxy.cpp +++ b/services/src/platform_callback_proxy.cpp @@ -19,27 +19,21 @@ #include "global.h" #include "i_platform_callback.h" - - /*! \class PlatformCallbackProxy \brief The proxy of IPlatformCallback - \todo This class will be deleted on target platform */ namespace OHOS { namespace MiscServices { class PlatformCallbackProxy : public IRemoteProxy < IPlatformCallback > { public: PlatformCallbackProxy(const sptr < IRemoteObject >& impl) - : IRemoteProxy < IPlatformCallback >(impl) - { + : IRemoteProxy < IPlatformCallback >(impl) { } - ~PlatformCallbackProxy() - { + ~PlatformCallbackProxy() { } - void notifyEvent(int eventId, int userId, const std::vector < std::u16string >& eventContent) - { + void notifyEvent(int eventId, int userId, const std::vector < std::u16string >& eventContent) { (void)eventId; (void)userId; (void)eventContent; diff --git a/services/src/platform_callback_stub.cpp b/services/src/platform_callback_stub.cpp index a9266cd6105b06ecb9b67218090f5f8d1861b990..ecb66227f06c609494135c5d87c191a628128239 100644 --- a/services/src/platform_callback_stub.cpp +++ b/services/src/platform_callback_stub.cpp @@ -13,7 +13,6 @@ * limitations under the License. */ - #include "message_handler.h" #include "message.h" #include "message_parcel.h" @@ -30,7 +29,8 @@ namespace MiscServices { PlatformCallbackStub::~PlatformCallbackStub() { } - int PlatformCallbackStub::OnRemoteRequest(uint32_t code, MessageParcel & data, MessageParcel & reply, MessageOption & option) { + int PlatformCallbackStub::OnRemoteRequest(uint32_t code, MessageParcel& data, MessageParcel& reply, + MessageOption& option) { switch (code) { case NOTIFY_EVENT: { int eventId = data.ReadInt32(); @@ -97,4 +97,4 @@ namespace MiscServices { MessageHandler::Instance()->SendMessage(msg); } } -} +} \ No newline at end of file diff --git a/unitest/BUILD.gn b/unitest/BUILD.gn index 6abde55d4f6f29b5ba2f37320306b61853f0004a..b3e6ba40ea062b00abed8c7e7df843a021aa055b 100644 --- a/unitest/BUILD.gn +++ b/unitest/BUILD.gn @@ -27,7 +27,7 @@ ohos_unittest("InputMethodControllerTest") { module_out_path = module_output_path sources = [ - "src/test_imc.cpp"] + "src/input_method_controller_test.cpp"] configs = [ ":module_private_config", @@ -60,7 +60,7 @@ ohos_unittest("InputMethodAbilityTest") { module_out_path = module_output_path sources = [ - "src/test_ima.cpp"] + "src/input_method_ability_test.cpp"] configs = [ ":module_private_config", diff --git a/unitest/src/test_ima.cpp b/unitest/src/input_method_ability_test.cpp similarity index 83% rename from unitest/src/test_ima.cpp rename to unitest/src/input_method_ability_test.cpp index 09c033075f0907f3bd22f1573f5aa3e6eb6825e7..f3ad35cf7b4f798c3533d05e088490271ac412af 100644 --- a/unitest/src/test_ima.cpp +++ b/unitest/src/input_method_ability_test.cpp @@ -31,14 +31,12 @@ #include "input_method_ability.h" #include "message_handler.h" - using namespace testing::ext; using namespace OHOS; using namespace OHOS::MiscServices; using namespace OHOS::AAFwk; -class InputMethodAbilityTest : public testing::Test -{ +class InputMethodAbilityTest : public testing::Test { public: static void SetUpTestCase(void); static void TearDownTestCase(void); @@ -46,23 +44,18 @@ public: void TearDown(); }; - -void InputMethodAbilityTest::SetUpTestCase(void) -{ +void InputMethodAbilityTest::SetUpTestCase(void) { IMSA_HILOGI("InputMethodAbilityTest::SetUpTestCase"); } -void InputMethodAbilityTest::TearDownTestCase(void) -{ +void InputMethodAbilityTest::TearDownTestCase(void) { IMSA_HILOGI("InputMethodAbilityTest::TearDownTestCase"); } -void InputMethodAbilityTest::SetUp(void) -{ +void InputMethodAbilityTest::SetUp(void) { IMSA_HILOGI("InputMethodAbilityTest::SetUp"); } -void InputMethodAbilityTest::TearDown(void) -{ +void InputMethodAbilityTest::TearDown(void) { IMSA_HILOGI("InputMethodAbilityTest::TearDown"); } \ No newline at end of file diff --git a/unitest/src/test_imc.cpp b/unitest/src/input_method_controller_test.cpp similarity index 84% rename from unitest/src/test_imc.cpp rename to unitest/src/input_method_controller_test.cpp index aa4a6331b70cc4d3c7bf664793c0a876b431303a..22ca331f205bbc6b67e073b6162fe9b8dc76634c 100644 --- a/unitest/src/test_imc.cpp +++ b/unitest/src/input_method_controller_test.cpp @@ -30,7 +30,6 @@ #include "iservice_registry.h" #include "system_ability_definition.h" - using namespace testing::ext; using namespace OHOS; using namespace OHOS::MiscServices; @@ -40,7 +39,7 @@ public: TextListener() {} ~TextListener() {} void InsertText(const std::u16string& text) { - IMSA_HILOGI("IMC TEST TextListener InsertText: %{public}s", Utils::to_utf8(text).c_str()); + IMSA_HILOGI("IMC TEST TextListener InsertText: %{public}s", MiscServices::Utils::to_utf8(text).c_str()); } void DeleteBackward(int32_t length){ @@ -51,8 +50,7 @@ public: IMSA_HILOGI("IMC TEST TextListener SetKeyboardStatus %{public}d", status); } }; -class InputMethodControllerTest : public testing::Test -{ +class InputMethodControllerTest : public testing::Test { public: static void SetUpTestCase(void); static void TearDownTestCase(void); @@ -60,23 +58,19 @@ public: void TearDown(); }; -void InputMethodControllerTest::SetUpTestCase(void) -{ +void InputMethodControllerTest::SetUpTestCase(void) { IMSA_HILOGI("InputMethodControllerTest::SetUpTestCase"); } -void InputMethodControllerTest::TearDownTestCase(void) -{ +void InputMethodControllerTest::TearDownTestCase(void) { IMSA_HILOGI("InputMethodControllerTest::TearDownTestCase"); } -void InputMethodControllerTest::SetUp(void) -{ +void InputMethodControllerTest::SetUp(void) { IMSA_HILOGI("InputMethodControllerTest::SetUp"); } -void InputMethodControllerTest::TearDown(void) -{ +void InputMethodControllerTest::TearDown(void) { IMSA_HILOGI("InputMethodControllerTest::TearDown"); } @@ -85,8 +79,7 @@ void InputMethodControllerTest::TearDown(void) * @tc.desc: Bind IMSA. * @tc.type: FUNC */ -HWTEST_F(InputMethodControllerTest, Imc001, TestSize.Level0) -{ +HWTEST_F(InputMethodControllerTest, Imc001, TestSize.Level0) { IMSA_HILOGI("IMC TEST START"); sptr imc = InputMethodController::GetInstance(); ASSERT_TRUE(imc!=nullptr);