1 /*
2 * Copyright (c) 2021-2022 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 #include "input_manager.h"
17
18 #include "error_multimodal.h"
19 #include "input_manager_impl.h"
20 #include "define_multimodal.h"
21 #include "multimodal_event_handler.h"
22
23 namespace OHOS {
24 namespace MMI {
25 namespace {
26 constexpr OHOS::HiviewDFX::HiLogLabel LABEL = { LOG_CORE, MMI_LOG_DOMAIN, "InputManager" };
27 } // namespace
28
29 InputManager *InputManager::instance_ = new (std::nothrow) InputManager();
GetInstance()30 InputManager *InputManager::GetInstance()
31 {
32 return instance_;
33 }
34
UpdateDisplayInfo(const DisplayGroupInfo & displayGroupInfo)35 void InputManager::UpdateDisplayInfo(const DisplayGroupInfo &displayGroupInfo)
36 {
37 InputMgrImpl.UpdateDisplayInfo(displayGroupInfo);
38 }
39
AddInputEventFilter(std::function<bool (std::shared_ptr<PointerEvent>)> filter)40 int32_t InputManager::AddInputEventFilter(std::function<bool(std::shared_ptr<PointerEvent>)> filter)
41 {
42 return InputMgrImpl.AddInputEventFilter(filter);
43 }
44
SetWindowInputEventConsumer(std::shared_ptr<IInputEventConsumer> inputEventConsumer)45 void InputManager::SetWindowInputEventConsumer(std::shared_ptr<IInputEventConsumer> inputEventConsumer)
46 {
47 InputMgrImpl.SetWindowInputEventConsumer(inputEventConsumer, nullptr);
48 }
49
SetWindowInputEventConsumer(std::shared_ptr<IInputEventConsumer> inputEventConsumer,std::shared_ptr<AppExecFwk::EventHandler> eventHandler)50 void InputManager::SetWindowInputEventConsumer(std::shared_ptr<IInputEventConsumer> inputEventConsumer,
51 std::shared_ptr<AppExecFwk::EventHandler> eventHandler)
52 {
53 CHKPV(eventHandler);
54 InputMgrImpl.SetWindowInputEventConsumer(inputEventConsumer, eventHandler);
55 }
56
SubscribeKeyEvent(std::shared_ptr<KeyOption> keyOption,std::function<void (std::shared_ptr<KeyEvent>)> callback)57 int32_t InputManager::SubscribeKeyEvent(std::shared_ptr<KeyOption> keyOption,
58 std::function<void(std::shared_ptr<KeyEvent>)> callback)
59 {
60 return InputMgrImpl.SubscribeKeyEvent(keyOption, callback);
61 }
62
UnsubscribeKeyEvent(int32_t subscriberId)63 void InputManager::UnsubscribeKeyEvent(int32_t subscriberId)
64 {
65 InputMgrImpl.UnsubscribeKeyEvent(subscriberId);
66 }
67
AddMonitor(std::function<void (std::shared_ptr<KeyEvent>)> monitor)68 int32_t InputManager::AddMonitor(std::function<void(std::shared_ptr<KeyEvent>)> monitor)
69 {
70 return InputMgrImpl.AddMonitor(monitor);
71 }
72
AddMonitor(std::function<void (std::shared_ptr<PointerEvent>)> monitor)73 int32_t InputManager::AddMonitor(std::function<void(std::shared_ptr<PointerEvent>)> monitor)
74 {
75 return InputMgrImpl.AddMonitor(monitor);
76 }
77
AddMonitor(std::shared_ptr<IInputEventConsumer> monitor)78 int32_t InputManager::AddMonitor(std::shared_ptr<IInputEventConsumer> monitor)
79 {
80 return InputMgrImpl.AddMonitor(monitor);
81 }
82
RemoveMonitor(int32_t monitorId)83 void InputManager::RemoveMonitor(int32_t monitorId)
84 {
85 InputMgrImpl.RemoveMonitor(monitorId);
86 }
87
MarkConsumed(int32_t monitorId,int32_t eventId)88 void InputManager::MarkConsumed(int32_t monitorId, int32_t eventId)
89 {
90 InputMgrImpl.MarkConsumed(monitorId, eventId);
91 }
92
MoveMouse(int32_t offsetX,int32_t offsetY)93 void InputManager::MoveMouse(int32_t offsetX, int32_t offsetY)
94 {
95 InputMgrImpl.MoveMouse(offsetX, offsetY);
96 }
97
AddInterceptor(std::shared_ptr<IInputEventConsumer> interceptor)98 int32_t InputManager::AddInterceptor(std::shared_ptr<IInputEventConsumer> interceptor)
99 {
100 return InputMgrImpl.AddInterceptor(interceptor);
101 }
102
AddInterceptor(std::function<void (std::shared_ptr<KeyEvent>)> interceptor)103 int32_t InputManager::AddInterceptor(std::function<void(std::shared_ptr<KeyEvent>)> interceptor)
104 {
105 return InputMgrImpl.AddInterceptor(interceptor);
106 }
107
RemoveInterceptor(int32_t interceptorId)108 void InputManager::RemoveInterceptor(int32_t interceptorId)
109 {
110 InputMgrImpl.RemoveInterceptor(interceptorId);
111 }
112
SimulateInputEvent(std::shared_ptr<KeyEvent> keyEvent)113 void InputManager::SimulateInputEvent(std::shared_ptr<KeyEvent> keyEvent)
114 {
115 InputMgrImpl.SimulateInputEvent(keyEvent);
116 }
117
SimulateInputEvent(std::shared_ptr<PointerEvent> pointerEvent)118 void InputManager::SimulateInputEvent(std::shared_ptr<PointerEvent> pointerEvent)
119 {
120 InputMgrImpl.SimulateInputEvent(pointerEvent);
121 }
122
RegisterDevListener(std::string type,std::shared_ptr<IInputDeviceListener> listener)123 int32_t InputManager::RegisterDevListener(std::string type, std::shared_ptr<IInputDeviceListener> listener)
124 {
125 return InputMgrImpl.RegisterDevListener(type, listener);
126 }
127
UnregisterDevListener(std::string type,std::shared_ptr<IInputDeviceListener> listener)128 int32_t InputManager::UnregisterDevListener(std::string type, std::shared_ptr<IInputDeviceListener> listener)
129 {
130 return InputMgrImpl.UnregisterDevListener(type, listener);
131 }
132
GetDeviceIds(std::function<void (std::vector<int32_t> &)> callback)133 int32_t InputManager::GetDeviceIds(std::function<void(std::vector<int32_t>&)> callback)
134 {
135 return InputMgrImpl.GetDeviceIds(callback);
136 }
137
GetDevice(int32_t deviceId,std::function<void (std::shared_ptr<InputDevice>)> callback)138 int32_t InputManager::GetDevice(int32_t deviceId,
139 std::function<void(std::shared_ptr<InputDevice>)> callback)
140 {
141 return InputMgrImpl.GetDevice(deviceId, callback);
142 }
143
SupportKeys(int32_t deviceId,std::vector<int32_t> keyCodes,std::function<void (std::vector<bool> &)> callback)144 int32_t InputManager::SupportKeys(int32_t deviceId, std::vector<int32_t> keyCodes,
145 std::function<void(std::vector<bool>&)> callback)
146 {
147 return InputMgrImpl.SupportKeys(deviceId, keyCodes, callback);
148 }
149
SetPointerVisible(bool visible)150 int32_t InputManager::SetPointerVisible(bool visible)
151 {
152 return InputMgrImpl.SetPointerVisible(visible);
153 }
154
IsPointerVisible()155 bool InputManager::IsPointerVisible()
156 {
157 return InputMgrImpl.IsPointerVisible();
158 }
159
SetPointerSpeed(int32_t speed)160 int32_t InputManager::SetPointerSpeed(int32_t speed)
161 {
162 return InputMgrImpl.SetPointerSpeed(speed);
163 }
164
GetPointerSpeed(int32_t & speed)165 int32_t InputManager::GetPointerSpeed(int32_t &speed)
166 {
167 return InputMgrImpl.GetPointerSpeed(speed);
168 }
169
GetKeyboardType(int32_t deviceId,std::function<void (int32_t)> callback)170 int32_t InputManager::GetKeyboardType(int32_t deviceId, std::function<void(int32_t)> callback)
171 {
172 return InputMgrImpl.GetKeyboardType(deviceId, callback);
173 }
174
SetAnrObserver(std::shared_ptr<IAnrObserver> observer)175 void InputManager::SetAnrObserver(std::shared_ptr<IAnrObserver> observer)
176 {
177 InputMgrImpl.SetAnrObserver(observer);
178 }
179
SetPointerStyle(int32_t windowId,int32_t pointerStyle)180 int32_t InputManager::SetPointerStyle(int32_t windowId, int32_t pointerStyle)
181 {
182 return InputMgrImpl.SetPointerStyle(windowId, pointerStyle);
183 }
184
GetPointerStyle(int32_t windowId,int32_t & pointerStyle)185 int32_t InputManager::GetPointerStyle(int32_t windowId, int32_t &pointerStyle)
186 {
187 return InputMgrImpl.GetPointerStyle(windowId, pointerStyle);
188 }
189
SetInputDevice(const std::string & dhid,const std::string & screenId)190 int32_t InputManager::SetInputDevice(const std::string& dhid, const std::string& screenId)
191 {
192 return InputMgrImpl.SetInputDevice(dhid, screenId);
193 }
194
RegisterCooperateListener(std::shared_ptr<IInputDeviceCooperateListener> listener)195 int32_t InputManager::RegisterCooperateListener(std::shared_ptr<IInputDeviceCooperateListener> listener)
196 {
197 return InputMgrImpl.RegisterCooperateListener(listener);
198 }
199
UnregisterCooperateListener(std::shared_ptr<IInputDeviceCooperateListener> listener)200 int32_t InputManager::UnregisterCooperateListener(std::shared_ptr<IInputDeviceCooperateListener> listener)
201 {
202 return InputMgrImpl.UnregisterCooperateListener(listener);
203 }
204
EnableInputDeviceCooperate(bool enabled,std::function<void (std::string,CooperationMessage)> callback)205 int32_t InputManager::EnableInputDeviceCooperate(bool enabled,
206 std::function<void(std::string, CooperationMessage)> callback)
207 {
208 return InputMgrImpl.EnableInputDeviceCooperate(enabled, callback);
209 }
210
StartInputDeviceCooperate(const std::string & sinkDeviceId,int32_t srcInputDeviceId,std::function<void (std::string,CooperationMessage)> callback)211 int32_t InputManager::StartInputDeviceCooperate(const std::string &sinkDeviceId, int32_t srcInputDeviceId,
212 std::function<void(std::string, CooperationMessage)> callback)
213 {
214 return InputMgrImpl.StartInputDeviceCooperate(sinkDeviceId, srcInputDeviceId, callback);
215 }
216
StopDeviceCooperate(std::function<void (std::string,CooperationMessage)> callback)217 int32_t InputManager::StopDeviceCooperate(std::function<void(std::string, CooperationMessage)> callback)
218 {
219 return InputMgrImpl.StopDeviceCooperate(callback);
220 }
221
GetInputDeviceCooperateState(const std::string & deviceId,std::function<void (bool)> callback)222 int32_t InputManager::GetInputDeviceCooperateState(const std::string &deviceId, std::function<void(bool)> callback)
223 {
224 return InputMgrImpl.GetInputDeviceCooperateState(deviceId, callback);
225 }
226
GetFunctionKeyState(int32_t funcKey)227 bool InputManager::GetFunctionKeyState(int32_t funcKey)
228 {
229 return InputMgrImpl.GetFunctionKeyState(funcKey);
230 }
231
SetFunctionKeyState(int32_t funcKey,bool enable)232 int32_t InputManager::SetFunctionKeyState(int32_t funcKey, bool enable)
233 {
234 return InputMgrImpl.SetFunctionKeyState(funcKey, enable);
235 }
236 } // namespace MMI
237 } // namespace OHOS