/* * Copyright (C) 2021-2023 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #ifndef FRAMEWORKS_INPUTMETHOD_ABILITY_INCLUDE_INPUT_METHOD_ABILITY_H #define FRAMEWORKS_INPUTMETHOD_ABILITY_INCLUDE_INPUT_METHOD_ABILITY_H #include #include "calling_window_info.h" #include "concurrent_map.h" #include "context.h" #include "i_input_control_channel.h" #include "i_input_data_channel.h" #include "i_input_method_agent.h" #include "i_input_method_core.h" #include "i_input_method_system_ability.h" #include "input_attribute.h" #include "input_control_channel_proxy.h" #include "input_data_channel_proxy.h" #include "input_method_engine_listener.h" #include "input_method_panel.h" #include "iremote_object.h" #include "keyboard_listener.h" #include "keyevent_consumer_proxy.h" #include "message.h" #include "message_handler.h" #include "private_command_interface.h" #include "system_cmd_channel_proxy.h" #include "input_method_types.h" namespace OHOS { namespace MiscServices { class MessageHandler; class InputMethodAbility : public RefBase, public PrivateCommandInterface { public: InputMethodAbility(); ~InputMethodAbility(); static sptr GetInstance(); int32_t SetCoreAndAgent(); void SetCoreAndAgentAsync(); int32_t InitConnect(); int32_t UnRegisteredProxyIme(UnRegisteredType type); int32_t InsertText(const std::string text); void SetImeListener(std::shared_ptr imeListener); std::shared_ptr GetImeListener(); void SetKdListener(std::shared_ptr kdListener); int32_t DeleteForward(int32_t length); int32_t DeleteBackward(int32_t length); int32_t HideKeyboardSelf(); int32_t StartInput(const InputClientInfo &clientInfo, bool isBindFromClient); int32_t StopInput(const sptr &channelObject); int32_t ShowKeyboard(); int32_t HideKeyboard(); int32_t SendExtendAction(int32_t action); int32_t GetTextBeforeCursor(int32_t number, std::u16string &text); int32_t GetTextAfterCursor(int32_t number, std::u16string &text); int32_t SendFunctionKey(int32_t funcKey); int32_t MoveCursor(int32_t keyCode); int32_t SelectByRange(int32_t start, int32_t end); int32_t SelectByMovement(int32_t direction); int32_t DispatchKeyEvent(const std::shared_ptr &keyEvent, sptr &consumer); void SetCallingWindow(uint32_t windowId); int32_t GetEnterKeyType(int32_t &keyType); int32_t GetInputPattern(int32_t &inputPattern); int32_t GetTextIndexAtCursor(int32_t &index); int32_t GetTextConfig(TextTotalConfig &textConfig); int32_t CreatePanel(const std::shared_ptr &context, const PanelInfo &panelInfo, std::shared_ptr &inputMethodPanel); int32_t DestroyPanel(const std::shared_ptr &inputMethodPanel); int32_t ShowPanel(const std::shared_ptr &inputMethodPanel); int32_t HidePanel(const std::shared_ptr &inputMethodPanel); bool IsCurrentIme(); bool IsEnable(); int32_t ExitCurrentInputType(); int32_t IsPanelShown(const PanelInfo &panelInfo, bool &isShown); int32_t GetSecurityMode(int32_t &security); int32_t OnSecurityChange(int32_t security); int32_t OnConnectSystemCmd(const sptr &channel, sptr &agent); void OnClientInactive(const sptr &channel); void NotifyKeyboardHeight(uint32_t panelHeight, PanelFlag panelFlag); int32_t SendPrivateCommand(const std::unordered_map &privateCommand) override; int32_t ReceivePrivateCommand(const std::unordered_map &privateCommand) override; bool IsDefaultIme(); int32_t GetCallingWindowInfo(CallingWindowInfo &windowInfo); int32_t SetPreviewText(const std::string &text, const Range &range); int32_t FinishTextPreview(bool isAsync); int32_t NotifyPanelStatus(const std::shared_ptr &inputMethodPanel, SysPanelStatus &sysPanelStatus); InputAttribute GetInputAttribute(); int32_t OnStopInputService(bool isTerminateIme); private: std::thread workThreadHandler; MessageHandler *msgHandler_; bool stop_ = false; std::mutex controlChannelLock_; std::shared_ptr controlChannel_ = nullptr; std::mutex dataChannelLock_; sptr dataChannelObject_ = nullptr; std::shared_ptr dataChannelProxy_ = nullptr; std::mutex systemCmdChannelLock_; sptr systemCmdChannelProxy_ = nullptr; std::shared_ptr imeListener_; std::shared_ptr kdListener_; static std::mutex instanceLock_; static sptr instance_; std::mutex abilityLock_; sptr abilityManager_{ nullptr }; sptr deathRecipient_{ nullptr }; sptr GetImsaProxy(); void OnRemoteSaDied(const wptr &object); sptr GetSystemCmdChannelProxy(); void ClearSystemCmdChannel(); void SetInputDataChannel(const sptr &object); std::shared_ptr GetInputDataChannelProxy(); void ClearDataChannel(const sptr &channel); void SetInputControlChannel(sptr &object); void ClearInputControlChannel(); std::shared_ptr GetInputControlChannel(); void Initialize(); void WorkThread(); void QuitWorkThread(); void OnInitInputControlChannel(Message *msg); void OnSetSubtype(Message *msg); int32_t InvokeStartInputCallback(bool isNotifyInputStart); int32_t InvokeStartInputCallback(const TextTotalConfig &textConfig, bool isNotifyInputStart); void OnCursorUpdate(Message *msg); void OnSelectionChange(Message *msg); void OnAttributeChange(Message *msg); int32_t HideKeyboard(Trigger trigger); std::shared_ptr GetSoftKeyboardPanel(); /* param flag: ShowPanel is async, show/hide softkeyboard in alphabet keyboard attached, flag will be changed before finishing show/hide */ int32_t ShowPanel(const std::shared_ptr &inputMethodPanel, PanelFlag flag, Trigger trigger); int32_t HidePanel(const std::shared_ptr &inputMethodPanel, PanelFlag flag, Trigger trigger); void SetInputAttribute(const InputAttribute &inputAttribute); void ClearInputAttribute(); void NotifyPanelStatusInfo(const PanelStatusInfo &info); int32_t HideKeyboardImplWithoutLock(int32_t cmdId); int32_t ShowKeyboardImplWithLock(int32_t cmdId); int32_t ShowKeyboardImplWithoutLock(int32_t cmdId); void NotifyPanelStatusInfo(const PanelStatusInfo &info, std::shared_ptr &channelProxy); ConcurrentMap> panels_{}; std::atomic_bool isBound_{ false }; sptr coreStub_{ nullptr }; sptr agentStub_{ nullptr }; sptr systemAgentStub_{ nullptr }; bool isPendingShowKeyboard_ = false; double positionY_ = 0; double height_ = 0; std::mutex imeCheckMutex_; bool isCurrentIme_ = false; std::mutex defaultImeCheckMutex_; bool isDefaultIme_ = false; std::mutex inputAttrLock_; InputAttribute inputAttribute_{}; std::recursive_mutex keyboardCmdLock_; int32_t cmdId_ = 0; std::atomic isImeTerminating_ = false; }; } // namespace MiscServices } // namespace OHOS #endif // FRAMEWORKS_INPUTMETHOD_ABILITY_INCLUDE_INPUT_METHOD_ABILITY_H