/* * Copyright (C) 2024 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 INPUTMETHOD_CONTROLLER_IME_SYSTEM_CHANNEL_H #define INPUTMETHOD_CONTROLLER_IME_SYSTEM_CHANNEL_H #include "bundle_mgr_client.h" #include "i_input_method_agent.h" #include "i_input_method_system_ability.h" #include "input_method_utils.h" #include "ipc_skeleton.h" #include "iremote_object.h" #include "private_command_interface.h" #include "refbase.h" #include "visibility.h" namespace OHOS { namespace MiscServices { using namespace OHOS::AppExecFwk; class OnSystemCmdListener : public virtual RefBase { public: virtual void ReceivePrivateCommand(const std::unordered_map &privateCommand) { } virtual void NotifyPanelStatus(const SysPanelStatus &sysPanelStatus) { } }; using PrivateDataValue = std::variant; class ImeSystemCmdChannel : public RefBase, public PrivateCommandInterface { public: /** * @brief Get the instance of ImeSystemCmdChannel. * * This function is used to get the instance of ImeSystemCmdChannel. * * @return The instance of ImeSystemCmdChannel. * @since 12 */ IMF_API static sptr GetInstance(); /** * @brief Connect system channel, set listener and bind IMSA. * * This function is used to connect the system app and input method. * * @param listener Indicates the listener in order to receive private command. * @return Returns 0 for success, others for failure. * @since 12 */ IMF_API int32_t ConnectSystemCmd(const sptr &listener); /** * @brief Send private command to ime. * * This function is used to send private command to ime. * * @param privateCommand Indicates the private command which will be send. * @return Returns 0 for success, others for failure. * @since 12 */ IMF_API int32_t SendPrivateCommand( const std::unordered_map &privateCommand) override; /** * @brief Get smart menue config from default input method. * * This function is used to get smart menue config from default input method. *. * @return string. * @since 12 */ IMF_API std::string GetSmartMenuCfg(); int32_t ReceivePrivateCommand( const std::unordered_map &privateCommand) override; int32_t NotifyPanelStatus(const SysPanelStatus &sysPanelStatus); void OnConnectCmdReady(const sptr &agentObject); IMF_API int32_t GetDefaultImeCfg(std::shared_ptr &property); private: ImeSystemCmdChannel(); ~ImeSystemCmdChannel(); int32_t RunConnectSystemCmd(); sptr GetSystemAbilityProxy(); void OnRemoteSaDied(const wptr &object); void SetSystemCmdListener(const sptr &listener); sptr GetSystemCmdAgent(); sptr GetSystemCmdListener(); void ClearSystemCmdAgent(); void GetExtensionInfo(std::vector extensionInfos, ExtensionAbilityInfo &extInfo); void OnSystemCmdAgentDied(const wptr &remote); static std::mutex instanceLock_; static sptr instance_; std::mutex abilityLock_; sptr systemAbility_ = nullptr; sptr deathRecipient_; std::mutex systemCmdListenerLock_; sptr systemCmdListener_ = nullptr; std::mutex systemAgentLock_; sptr systemAgent_ = nullptr; sptr agentDeathRecipient_; std::atomic_bool isSystemCmdConnect_{ false }; std::mutex systemChannelMutex_; sptr systemChannelStub_; }; } // namespace MiscServices } // namespace OHOS #endif // INPUTMETHOD_CONTROLLER_IME_SYSTEM_CHANNEL_H