• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2024 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #ifndef INPUTMETHOD_CONTROLLER_IME_SYSTEM_CHANNEL_H
17 #define INPUTMETHOD_CONTROLLER_IME_SYSTEM_CHANNEL_H
18 
19 #include "bundle_mgr_client.h"
20 #include "iinput_method_agent.h"
21 #include "iinput_method_system_ability.h"
22 #include "input_method_utils.h"
23 #include "ipc_skeleton.h"
24 #include "iremote_object.h"
25 #include "private_command_interface.h"
26 #include "refbase.h"
27 #include "visibility.h"
28 #include "sys_panel_status.h"
29 #include "isystem_cmd_channel.h"
30 
31 namespace OHOS {
32 namespace MiscServices {
33 using namespace OHOS::AppExecFwk;
34 class OnSystemCmdListener : public virtual RefBase {
35 public:
ReceivePrivateCommand(const std::unordered_map<std::string,PrivateDataValue> & privateCommand)36     virtual void ReceivePrivateCommand(const std::unordered_map<std::string, PrivateDataValue> &privateCommand)
37     {
38     }
NotifyPanelStatus(const SysPanelStatus & sysPanelStatus)39     virtual void NotifyPanelStatus(const SysPanelStatus &sysPanelStatus)
40     {
41     }
42 };
43 using PrivateDataValue = std::variant<std::string, bool, int32_t>;
44 class ImeSystemCmdChannel : public RefBase, public PrivateCommandInterface {
45 public:
46     /**
47      * @brief Get the instance of ImeSystemCmdChannel.
48      *
49      * This function is used to get the instance of ImeSystemCmdChannel.
50      *
51      * @return The instance of ImeSystemCmdChannel.
52      * @since 12
53      */
54     IMF_API static sptr<ImeSystemCmdChannel> GetInstance();
55 
56     /**
57      * @brief Connect system channel, set listener and bind IMSA.
58      *
59      * This function is used to connect the system app and  input method.
60      *
61      * @param listener Indicates the listener in order to receive private command.
62      * @return Returns 0 for success, others for failure.
63      * @since 12
64      */
65     IMF_API int32_t ConnectSystemCmd(const sptr<OnSystemCmdListener> &listener);
66 
67     /**
68      * @brief Send private command to ime.
69      *
70      * This function is used to send private command to ime.
71      *
72      * @param privateCommand Indicates the private command which will be send.
73      * @return Returns 0 for success, others for failure.
74      * @since 12
75      */
76     IMF_API int32_t SendPrivateCommand(
77         const std::unordered_map<std::string, PrivateDataValue> &privateCommand) override;
78 
79     /**
80      * @brief Get smart menue config from default input method.
81      *
82      * This function is used to get smart menue config from default input method.
83      *.
84      * @return string.
85      * @since 12
86      */
87     IMF_API std::string GetSmartMenuCfg();
88     int32_t ReceivePrivateCommand(
89         const std::unordered_map<std::string, PrivateDataValue> &privateCommand) override;
90     int32_t NotifyPanelStatus(const SysPanelStatus &sysPanelStatus);
91     void OnConnectCmdReady(const sptr<IRemoteObject> &agentObject);
92     IMF_API int32_t GetDefaultImeCfg(std::shared_ptr<Property> &property);
93 
94 private:
95     ImeSystemCmdChannel();
96     ~ImeSystemCmdChannel();
97     int32_t RunConnectSystemCmd();
98     sptr<IInputMethodSystemAbility> GetSystemAbilityProxy();
99     void OnRemoteSaDied(const wptr<IRemoteObject> &object);
100     void SetSystemCmdListener(const sptr<OnSystemCmdListener> &listener);
101     sptr<IInputMethodAgent> GetSystemCmdAgent();
102     sptr<OnSystemCmdListener> GetSystemCmdListener();
103     void ClearSystemCmdAgent();
104     void GetExtensionInfo(std::vector<ExtensionAbilityInfo> extensionInfos, ExtensionAbilityInfo &extInfo);
105     void OnSystemCmdAgentDied(const wptr<IRemoteObject> &remote);
106 
107     static std::mutex instanceLock_;
108     static sptr<ImeSystemCmdChannel> instance_;
109 
110     std::mutex abilityLock_;
111     sptr<IInputMethodSystemAbility> systemAbility_ = nullptr;
112     sptr<InputDeathRecipient> deathRecipient_;
113 
114     std::mutex systemCmdListenerLock_;
115     sptr<OnSystemCmdListener> systemCmdListener_ = nullptr;
116 
117     std::mutex systemAgentLock_;
118     sptr<IInputMethodAgent> systemAgent_ = nullptr;
119     sptr<InputDeathRecipient> agentDeathRecipient_;
120     std::atomic_bool isSystemCmdConnect_{ false };
121 
122     std::mutex systemChannelMutex_;
123     sptr<ISystemCmdChannel> systemChannelStub_;
124 };
125 } // namespace MiscServices
126 } // namespace OHOS
127 #endif // INPUTMETHOD_CONTROLLER_IME_SYSTEM_CHANNEL_H