• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
GetDisplayBindInfo(DisplayBindInfos & infos)35 int32_t InputManager::GetDisplayBindInfo(DisplayBindInfos &infos)
36 {
37     return InputMgrImpl.GetDisplayBindInfo(infos);
38 }
39 
SetDisplayBind(int32_t deviceId,int32_t displayId,std::string & msg)40 int32_t InputManager::SetDisplayBind(int32_t deviceId, int32_t displayId, std::string &msg)
41 {
42     return InputMgrImpl.SetDisplayBind(deviceId, displayId, msg);
43 }
44 
GetWindowPid(int32_t windowId)45 int32_t InputManager::GetWindowPid(int32_t windowId)
46 {
47     return InputMgrImpl.GetWindowPid(windowId);
48 }
49 
UpdateDisplayInfo(const DisplayGroupInfo & displayGroupInfo)50 void InputManager::UpdateDisplayInfo(const DisplayGroupInfo &displayGroupInfo)
51 {
52     InputMgrImpl.UpdateDisplayInfo(displayGroupInfo);
53 }
54 
AddInputEventFilter(std::shared_ptr<IInputEventFilter> filter,int32_t priority,uint32_t deviceTags)55 int32_t InputManager::AddInputEventFilter(std::shared_ptr<IInputEventFilter> filter, int32_t priority,
56     uint32_t deviceTags)
57 {
58     return InputMgrImpl.AddInputEventFilter(filter, priority, deviceTags);
59 }
60 
RemoveInputEventFilter(int32_t filterId)61 int32_t InputManager::RemoveInputEventFilter(int32_t filterId)
62 {
63     return InputMgrImpl.RemoveInputEventFilter(filterId);
64 }
65 
SetWindowInputEventConsumer(std::shared_ptr<IInputEventConsumer> inputEventConsumer)66 void InputManager::SetWindowInputEventConsumer(std::shared_ptr<IInputEventConsumer> inputEventConsumer)
67 {
68     InputMgrImpl.SetWindowInputEventConsumer(inputEventConsumer, nullptr);
69 }
70 
SetWindowInputEventConsumer(std::shared_ptr<IInputEventConsumer> inputEventConsumer,std::shared_ptr<AppExecFwk::EventHandler> eventHandler)71 void InputManager::SetWindowInputEventConsumer(std::shared_ptr<IInputEventConsumer> inputEventConsumer,
72     std::shared_ptr<AppExecFwk::EventHandler> eventHandler)
73 {
74     CHKPV(eventHandler);
75     InputMgrImpl.SetWindowInputEventConsumer(inputEventConsumer, eventHandler);
76 }
77 
SubscribeKeyEvent(std::shared_ptr<KeyOption> keyOption,std::function<void (std::shared_ptr<KeyEvent>)> callback)78 int32_t InputManager::SubscribeKeyEvent(std::shared_ptr<KeyOption> keyOption,
79     std::function<void(std::shared_ptr<KeyEvent>)> callback)
80 {
81     return InputMgrImpl.SubscribeKeyEvent(keyOption, callback);
82 }
83 
UnsubscribeKeyEvent(int32_t subscriberId)84 void InputManager::UnsubscribeKeyEvent(int32_t subscriberId)
85 {
86     InputMgrImpl.UnsubscribeKeyEvent(subscriberId);
87 }
88 
SubscribeSwitchEvent(std::function<void (std::shared_ptr<SwitchEvent>)> callback)89 int32_t InputManager::SubscribeSwitchEvent(std::function<void(std::shared_ptr<SwitchEvent>)> callback)
90 {
91     return InputMgrImpl.SubscribeSwitchEvent(callback);
92 }
93 
UnsubscribeSwitchEvent(int32_t subscriberId)94 void InputManager::UnsubscribeSwitchEvent(int32_t subscriberId)
95 {
96     InputMgrImpl.UnsubscribeSwitchEvent(subscriberId);
97 }
98 
AddMonitor(std::function<void (std::shared_ptr<KeyEvent>)> monitor)99 int32_t InputManager::AddMonitor(std::function<void(std::shared_ptr<KeyEvent>)> monitor)
100 {
101     return InputMgrImpl.AddMonitor(monitor);
102 }
103 
AddMonitor(std::function<void (std::shared_ptr<PointerEvent>)> monitor)104 int32_t InputManager::AddMonitor(std::function<void(std::shared_ptr<PointerEvent>)> monitor)
105 {
106     return InputMgrImpl.AddMonitor(monitor);
107 }
108 
AddMonitor(std::shared_ptr<IInputEventConsumer> monitor)109 int32_t InputManager::AddMonitor(std::shared_ptr<IInputEventConsumer> monitor)
110 {
111     return InputMgrImpl.AddMonitor(monitor);
112 }
113 
RemoveMonitor(int32_t monitorId)114 void InputManager::RemoveMonitor(int32_t monitorId)
115 {
116     InputMgrImpl.RemoveMonitor(monitorId);
117 }
118 
MarkConsumed(int32_t monitorId,int32_t eventId)119 void InputManager::MarkConsumed(int32_t monitorId, int32_t eventId)
120 {
121     InputMgrImpl.MarkConsumed(monitorId, eventId);
122 }
123 
MoveMouse(int32_t offsetX,int32_t offsetY)124 void InputManager::MoveMouse(int32_t offsetX, int32_t offsetY)
125 {
126     InputMgrImpl.MoveMouse(offsetX, offsetY);
127 }
128 
AddInterceptor(std::shared_ptr<IInputEventConsumer> interceptor)129 int32_t InputManager::AddInterceptor(std::shared_ptr<IInputEventConsumer> interceptor)
130 {
131     return InputMgrImpl.AddInterceptor(interceptor);
132 }
133 
AddInterceptor(std::function<void (std::shared_ptr<KeyEvent>)> interceptor)134 int32_t InputManager::AddInterceptor(std::function<void(std::shared_ptr<KeyEvent>)> interceptor)
135 {
136     return InputMgrImpl.AddInterceptor(interceptor);
137 }
138 
AddInterceptor(std::shared_ptr<IInputEventConsumer> interceptor,int32_t priority,uint32_t deviceTags)139 int32_t InputManager::AddInterceptor(std::shared_ptr<IInputEventConsumer> interceptor, int32_t priority,
140     uint32_t deviceTags)
141 {
142     return InputMgrImpl.AddInterceptor(interceptor, priority, deviceTags);
143 }
144 
RemoveInterceptor(int32_t interceptorId)145 void InputManager::RemoveInterceptor(int32_t interceptorId)
146 {
147     InputMgrImpl.RemoveInterceptor(interceptorId);
148 }
149 
SimulateInputEvent(std::shared_ptr<KeyEvent> keyEvent)150 void InputManager::SimulateInputEvent(std::shared_ptr<KeyEvent> keyEvent)
151 {
152     InputMgrImpl.SimulateInputEvent(keyEvent);
153 }
154 
SimulateInputEvent(std::shared_ptr<PointerEvent> pointerEvent)155 void InputManager::SimulateInputEvent(std::shared_ptr<PointerEvent> pointerEvent)
156 {
157     InputMgrImpl.SimulateInputEvent(pointerEvent);
158 }
159 
SimulateInputEventToHmosContainer(std::shared_ptr<KeyEvent> keyEvent)160 void InputManager::SimulateInputEventToHmosContainer(std::shared_ptr<KeyEvent> keyEvent)
161 {
162     keyEvent->AddFlag(InputEvent::EVENT_FLAG_HMOS);
163     InputMgrImpl.SimulateInputEvent(keyEvent);
164 }
165 
SimulateInputEventToHmosContainer(std::shared_ptr<PointerEvent> pointerEvent)166 void InputManager::SimulateInputEventToHmosContainer(std::shared_ptr<PointerEvent> pointerEvent)
167 {
168     pointerEvent->AddFlag(InputEvent::EVENT_FLAG_HMOS);
169     InputMgrImpl.SimulateInputEvent(pointerEvent);
170 }
171 
RegisterDevListener(std::string type,std::shared_ptr<IInputDeviceListener> listener)172 int32_t InputManager::RegisterDevListener(std::string type, std::shared_ptr<IInputDeviceListener> listener)
173 {
174     return InputMgrImpl.RegisterDevListener(type, listener);
175 }
176 
UnregisterDevListener(std::string type,std::shared_ptr<IInputDeviceListener> listener)177 int32_t InputManager::UnregisterDevListener(std::string type, std::shared_ptr<IInputDeviceListener> listener)
178 {
179     return InputMgrImpl.UnregisterDevListener(type, listener);
180 }
181 
GetDeviceIds(std::function<void (std::vector<int32_t> &)> callback)182 int32_t InputManager::GetDeviceIds(std::function<void(std::vector<int32_t>&)> callback)
183 {
184     return InputMgrImpl.GetDeviceIds(callback);
185 }
186 
GetDevice(int32_t deviceId,std::function<void (std::shared_ptr<InputDevice>)> callback)187 int32_t InputManager::GetDevice(int32_t deviceId,
188     std::function<void(std::shared_ptr<InputDevice>)> callback)
189 {
190     return InputMgrImpl.GetDevice(deviceId, callback);
191 }
192 
SupportKeys(int32_t deviceId,std::vector<int32_t> keyCodes,std::function<void (std::vector<bool> &)> callback)193 int32_t InputManager::SupportKeys(int32_t deviceId, std::vector<int32_t> keyCodes,
194     std::function<void(std::vector<bool>&)> callback)
195 {
196     return InputMgrImpl.SupportKeys(deviceId, keyCodes, callback);
197 }
198 
SetMouseScrollRows(int32_t Rows)199 int32_t InputManager::SetMouseScrollRows(int32_t Rows)
200 {
201     return InputMgrImpl.SetMouseScrollRows(Rows);
202 }
203 
GetMouseScrollRows(int32_t & Rows)204 int32_t InputManager::GetMouseScrollRows(int32_t &Rows)
205 {
206     return InputMgrImpl.GetMouseScrollRows(Rows);
207 }
208 
SetMouseIcon(int32_t windowId,void * pixelMap)209 int32_t InputManager::SetMouseIcon(int32_t windowId, void* pixelMap)
210 {
211     return InputMgrImpl.SetMouseIcon(windowId, pixelMap);
212 }
213 
SetPointerSize(int32_t size)214 int32_t InputManager::SetPointerSize(int32_t size)
215 {
216     return InputMgrImpl.SetPointerSize(size);
217 }
218 
GetPointerSize(int32_t & size)219 int32_t InputManager::GetPointerSize(int32_t &size)
220 {
221     return InputMgrImpl.GetPointerSize(size);
222 }
223 
SetMouseHotSpot(int32_t windowId,int32_t hotSpotX,int32_t hotSpotY)224 int32_t InputManager::SetMouseHotSpot(int32_t windowId, int32_t hotSpotX, int32_t hotSpotY)
225 {
226     return InputMgrImpl.SetMouseHotSpot(windowId, hotSpotX, hotSpotY);
227 }
228 
SetMousePrimaryButton(int32_t primaryButton)229 int32_t InputManager::SetMousePrimaryButton(int32_t primaryButton)
230 {
231     return InputMgrImpl.SetMousePrimaryButton(primaryButton);
232 }
233 
GetMousePrimaryButton(int32_t & primaryButton)234 int32_t InputManager::GetMousePrimaryButton(int32_t &primaryButton)
235 {
236     return InputMgrImpl.GetMousePrimaryButton(primaryButton);
237 }
238 
SetHoverScrollState(bool state)239 int32_t InputManager::SetHoverScrollState(bool state)
240 {
241     return InputMgrImpl.SetHoverScrollState(state);
242 }
243 
GetHoverScrollState(bool & state)244 int32_t InputManager::GetHoverScrollState(bool &state)
245 {
246     return InputMgrImpl.GetHoverScrollState(state);
247 }
248 
SetPointerVisible(bool visible)249 int32_t InputManager::SetPointerVisible(bool visible)
250 {
251     return InputMgrImpl.SetPointerVisible(visible);
252 }
253 
IsPointerVisible()254 bool InputManager::IsPointerVisible()
255 {
256     return InputMgrImpl.IsPointerVisible();
257 }
258 
SetPointerColor(int32_t color)259 int32_t InputManager::SetPointerColor(int32_t color)
260 {
261     return InputMgrImpl.SetPointerColor(color);
262 }
263 
GetPointerColor(int32_t & color)264 int32_t InputManager::GetPointerColor(int32_t &color)
265 {
266     return InputMgrImpl.GetPointerColor(color);
267 }
268 
269 
SetPointerSpeed(int32_t speed)270 int32_t InputManager::SetPointerSpeed(int32_t speed)
271 {
272     return InputMgrImpl.SetPointerSpeed(speed);
273 }
274 
GetPointerSpeed(int32_t & speed)275 int32_t InputManager::GetPointerSpeed(int32_t &speed)
276 {
277     return InputMgrImpl.GetPointerSpeed(speed);
278 }
279 
GetKeyboardType(int32_t deviceId,std::function<void (int32_t)> callback)280 int32_t InputManager::GetKeyboardType(int32_t deviceId, std::function<void(int32_t)> callback)
281 {
282     return InputMgrImpl.GetKeyboardType(deviceId, callback);
283 }
284 
SetAnrObserver(std::shared_ptr<IAnrObserver> observer)285 void InputManager::SetAnrObserver(std::shared_ptr<IAnrObserver> observer)
286 {
287     InputMgrImpl.SetAnrObserver(observer);
288 }
289 
SetPointerStyle(int32_t windowId,PointerStyle pointerStyle)290 int32_t InputManager::SetPointerStyle(int32_t windowId, PointerStyle pointerStyle)
291 {
292     return InputMgrImpl.SetPointerStyle(windowId, pointerStyle);
293 }
294 
GetPointerStyle(int32_t windowId,PointerStyle & pointerStyle)295 int32_t InputManager::GetPointerStyle(int32_t windowId, PointerStyle &pointerStyle)
296 {
297     return InputMgrImpl.GetPointerStyle(windowId, pointerStyle);
298 }
299 
GetFunctionKeyState(int32_t funcKey)300 bool InputManager::GetFunctionKeyState(int32_t funcKey)
301 {
302     return InputMgrImpl.GetFunctionKeyState(funcKey);
303 }
304 
SetFunctionKeyState(int32_t funcKey,bool enable)305 int32_t InputManager::SetFunctionKeyState(int32_t funcKey, bool enable)
306 {
307     return InputMgrImpl.SetFunctionKeyState(funcKey, enable);
308 }
309 
SetPointerLocation(int32_t x,int32_t y)310 void InputManager::SetPointerLocation(int32_t x, int32_t y)
311 {
312     InputMgrImpl.SetPointerLocation(x, y);
313 }
314 
EnterCaptureMode(int32_t windowId)315 int32_t InputManager::EnterCaptureMode(int32_t windowId)
316 {
317     return InputMgrImpl.EnterCaptureMode(windowId);
318 }
319 
LeaveCaptureMode(int32_t windowId)320 int32_t InputManager::LeaveCaptureMode(int32_t windowId)
321 {
322     return InputMgrImpl.LeaveCaptureMode(windowId);
323 }
324 
AppendExtraData(const ExtraData & extraData)325 void InputManager::AppendExtraData(const ExtraData& extraData)
326 {
327     InputMgrImpl.AppendExtraData(extraData);
328 }
329 
EnableInputDevice(bool enable)330 int32_t InputManager::EnableInputDevice(bool enable)
331 {
332     return InputMgrImpl.EnableInputDevice(enable);
333 }
334 
SetKeyDownDuration(const std::string & businessId,int32_t delay)335 int32_t InputManager::SetKeyDownDuration(const std::string& businessId, int32_t delay)
336 {
337     return InputMgrImpl.SetKeyDownDuration(businessId, delay);
338 }
339 
SetKeyboardRepeatDelay(int32_t delay)340 int32_t InputManager::SetKeyboardRepeatDelay(int32_t delay)
341 {
342     return InputMgrImpl.SetKeyboardRepeatDelay(delay);
343 }
344 
SetKeyboardRepeatRate(int32_t rate)345 int32_t InputManager::SetKeyboardRepeatRate(int32_t rate)
346 {
347     return InputMgrImpl.SetKeyboardRepeatRate(rate);
348 }
349 
GetKeyboardRepeatDelay(std::function<void (int32_t)> callback)350 int32_t InputManager::GetKeyboardRepeatDelay(std::function<void(int32_t)> callback)
351 {
352     return InputMgrImpl.GetKeyboardRepeatDelay(callback);
353 }
354 
GetKeyboardRepeatRate(std::function<void (int32_t)> callback)355 int32_t InputManager::GetKeyboardRepeatRate(std::function<void(int32_t)> callback)
356 {
357     return InputMgrImpl.GetKeyboardRepeatRate(callback);
358 }
359 
360 #ifdef OHOS_BUILD_ENABLE_SECURITY_COMPONENT
SetEnhanceConfig(uint8_t * cfg,uint32_t cfgLen)361 void InputManager::SetEnhanceConfig(uint8_t *cfg, uint32_t cfgLen)
362 {
363     InputMgrImpl.SetEnhanceConfig(cfg, cfgLen);
364 }
365 #endif // OHOS_BUILD_ENABLE_SECURITY_COMPONENT
366 
SetTouchpadScrollSwitch(bool switchFlag)367 int32_t InputManager::SetTouchpadScrollSwitch(bool switchFlag)
368 {
369     return InputMgrImpl.SetTouchpadScrollSwitch(switchFlag);
370 }
371 
GetTouchpadScrollSwitch(bool & switchFlag)372 int32_t InputManager::GetTouchpadScrollSwitch(bool &switchFlag)
373 {
374     return InputMgrImpl.GetTouchpadScrollSwitch(switchFlag);
375 }
SetTouchpadScrollDirection(bool state)376 int32_t InputManager::SetTouchpadScrollDirection(bool state)
377 {
378     return InputMgrImpl.SetTouchpadScrollDirection(state);
379 }
380 
GetTouchpadScrollDirection(bool & state)381 int32_t InputManager::GetTouchpadScrollDirection(bool &state)
382 {
383     return InputMgrImpl.GetTouchpadScrollDirection(state);
384 }
SetTouchpadTapSwitch(bool switchFlag)385 int32_t InputManager::SetTouchpadTapSwitch(bool switchFlag)
386 {
387     return InputMgrImpl.SetTouchpadTapSwitch(switchFlag);
388 }
389 
GetTouchpadTapSwitch(bool & switchFlag)390 int32_t InputManager::GetTouchpadTapSwitch(bool &switchFlag)
391 {
392     return InputMgrImpl.GetTouchpadTapSwitch(switchFlag);
393 }
394 
SetTouchpadPointerSpeed(int32_t speed)395 int32_t InputManager::SetTouchpadPointerSpeed(int32_t speed)
396 {
397     return InputMgrImpl.SetTouchpadPointerSpeed(speed);
398 }
399 
GetTouchpadPointerSpeed(int32_t & speed)400 int32_t InputManager::GetTouchpadPointerSpeed(int32_t &speed)
401 {
402     return InputMgrImpl.GetTouchpadPointerSpeed(speed);
403 }
404 
SetTouchpadPinchSwitch(bool switchFlag)405 int32_t InputManager::SetTouchpadPinchSwitch(bool switchFlag)
406 {
407     return InputMgrImpl.SetTouchpadPinchSwitch(switchFlag);
408 }
409 
GetTouchpadPinchSwitch(bool & switchFlag)410 int32_t InputManager::GetTouchpadPinchSwitch(bool &switchFlag)
411 {
412     return InputMgrImpl.GetTouchpadPinchSwitch(switchFlag);
413 }
414 
SetTouchpadSwipeSwitch(bool switchFlag)415 int32_t InputManager::SetTouchpadSwipeSwitch(bool switchFlag)
416 {
417     return InputMgrImpl.SetTouchpadSwipeSwitch(switchFlag);
418 }
419 
GetTouchpadSwipeSwitch(bool & switchFlag)420 int32_t InputManager::GetTouchpadSwipeSwitch(bool &switchFlag)
421 {
422     return InputMgrImpl.GetTouchpadSwipeSwitch(switchFlag);
423 }
424 
SetTouchpadRightClickType(int32_t type)425 int32_t InputManager::SetTouchpadRightClickType(int32_t type)
426 {
427     return InputMgrImpl.SetTouchpadRightClickType(type);
428 }
429 
GetTouchpadRightClickType(int32_t & type)430 int32_t InputManager::GetTouchpadRightClickType(int32_t &type)
431 {
432     return InputMgrImpl.GetTouchpadRightClickType(type);
433 }
434 } // namespace MMI
435 } // namespace OHOS
436