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_device_manager.h"
17
18 #include <linux/input.h>
19 #include <regex>
20
21 #include "input_event_handler.h"
22 #include "key_auto_repeat.h"
23 #ifndef OHOS_BUILD_ENABLE_WATCH
24 #include "pointer_drawing_manager.h"
25 #endif // OHOS_BUILD_ENABLE_WATCH
26 #include "util_ex.h"
27 #include "dfx_hisysevent_device.h"
28
29 #undef MMI_LOG_DOMAIN
30 #define MMI_LOG_DOMAIN MMI_LOG_SERVER
31 #undef MMI_LOG_TAG
32 #define MMI_LOG_TAG "InputDeviceManager"
33
34 namespace OHOS {
35 namespace MMI {
36 namespace {
37 constexpr int32_t INVALID_DEVICE_ID { -1 };
38 constexpr int32_t SUPPORT_KEY { 1 };
39 const char* INPUT_VIRTUAL_DEVICE_NAME { "DistributedInput " };
40 constexpr int32_t MIN_VIRTUAL_INPUT_DEVICE_ID { 1000 };
41 constexpr int32_t MAX_VIRTUAL_INPUT_DEVICE_NUM { 128 };
42 constexpr int32_t COMMON_PARAMETER_ERROR { 401 };
43
44 std::unordered_map<int32_t, std::string> axisType{
45 { ABS_MT_TOUCH_MAJOR, "TOUCH_MAJOR" }, { ABS_MT_TOUCH_MINOR, "TOUCH_MINOR" }, { ABS_MT_ORIENTATION, "ORIENTATION" },
46 { ABS_MT_POSITION_X, "POSITION_X" }, { ABS_MT_POSITION_Y, "POSITION_Y" }, { ABS_MT_PRESSURE, "PRESSURE" },
47 { ABS_MT_WIDTH_MAJOR, "WIDTH_MAJOR" }, { ABS_MT_WIDTH_MINOR, "WIDTH_MINOR" }
48 };
49
50 std::vector<std::pair<enum libinput_device_capability, InputDeviceCapability>> devCapEnumMaps{
51 { LIBINPUT_DEVICE_CAP_KEYBOARD, InputDeviceCapability::INPUT_DEV_CAP_KEYBOARD },
52 { LIBINPUT_DEVICE_CAP_POINTER, InputDeviceCapability::INPUT_DEV_CAP_POINTER },
53 { LIBINPUT_DEVICE_CAP_TOUCH, InputDeviceCapability::INPUT_DEV_CAP_TOUCH },
54 { LIBINPUT_DEVICE_CAP_TABLET_TOOL, InputDeviceCapability::INPUT_DEV_CAP_TABLET_TOOL },
55 { LIBINPUT_DEVICE_CAP_TABLET_PAD, InputDeviceCapability::INPUT_DEV_CAP_TABLET_PAD },
56 { LIBINPUT_DEVICE_CAP_GESTURE, InputDeviceCapability::INPUT_DEV_CAP_GESTURE },
57 { LIBINPUT_DEVICE_CAP_SWITCH, InputDeviceCapability::INPUT_DEV_CAP_SWITCH },
58 { LIBINPUT_DEVICE_CAP_JOYSTICK, InputDeviceCapability::INPUT_DEV_CAP_JOYSTICK },
59 };
60
61 constexpr size_t EXPECTED_N_SUBMATCHES{ 2 };
62 constexpr size_t EXPECTED_SUBMATCH{ 1 };
63 } // namespace
64
65 std::shared_ptr<InputDeviceManager> InputDeviceManager::instance_ = nullptr;
66 std::mutex InputDeviceManager::mutex_;
67
GetInstance()68 std::shared_ptr<InputDeviceManager> InputDeviceManager::GetInstance()
69 {
70 if (instance_ == nullptr) {
71 std::lock_guard<std::mutex> lock(mutex_);
72 if (instance_ == nullptr) {
73 instance_ = std::make_shared<InputDeviceManager>();
74 }
75 }
76 return instance_;
77 }
78
GetInputDevice(int32_t deviceId,bool checked) const79 std::shared_ptr<InputDevice> InputDeviceManager::GetInputDevice(int32_t deviceId, bool checked) const
80 {
81 CALL_DEBUG_ENTER;
82 if (virtualInputDevices_.find(deviceId) != virtualInputDevices_.end()) {
83 MMI_HILOGI("Virtual device with id:%{public}d", deviceId);
84 std::shared_ptr<InputDevice> dev = virtualInputDevices_.at(deviceId);
85 CHKPP(dev);
86 MMI_HILOGI("DeviceId:%{public}d, name:%{public}s", dev->GetId(), dev->GetName().c_str());
87 return dev;
88 }
89 auto iter = inputDevice_.find(deviceId);
90 if (iter == inputDevice_.end()) {
91 MMI_HILOGE("Failed to search for the device");
92 return nullptr;
93 }
94 if (checked && !iter->second.enable) {
95 MMI_HILOGE("The current device has been disabled");
96 return nullptr;
97 }
98 std::shared_ptr<InputDevice> inputDevice = std::make_shared<InputDevice>();
99 inputDevice->SetId(iter->first);
100 struct libinput_device *inputDeviceOrigin = iter->second.inputDeviceOrigin;
101 FillInputDevice(inputDevice, inputDeviceOrigin);
102
103 InputDevice::AxisInfo axis;
104 for (const auto &item : axisType) {
105 int32_t min = libinput_device_get_axis_min(inputDeviceOrigin, item.first);
106 if (min == -1) {
107 MMI_HILOGD("The device does not support this axis");
108 continue;
109 }
110 if (item.first == ABS_MT_PRESSURE) {
111 axis.SetMinimum(0);
112 axis.SetMaximum(1);
113 } else {
114 axis.SetMinimum(min);
115 axis.SetMaximum(libinput_device_get_axis_max(inputDeviceOrigin, item.first));
116 }
117 axis.SetAxisType(item.first);
118 axis.SetFuzz(libinput_device_get_axis_fuzz(inputDeviceOrigin, item.first));
119 axis.SetFlat(libinput_device_get_axis_flat(inputDeviceOrigin, item.first));
120 axis.SetResolution(libinput_device_get_axis_resolution(inputDeviceOrigin, item.first));
121 inputDevice->AddAxisInfo(axis);
122 }
123 return inputDevice;
124 }
125
FillInputDevice(std::shared_ptr<InputDevice> inputDevice,libinput_device * deviceOrigin) const126 void InputDeviceManager::FillInputDevice(std::shared_ptr<InputDevice> inputDevice, libinput_device *deviceOrigin) const
127 {
128 CHKPV(inputDevice);
129 CHKPV(deviceOrigin);
130 inputDevice->SetType(static_cast<int32_t>(libinput_device_get_tags(deviceOrigin)));
131 const char *name = libinput_device_get_name(deviceOrigin);
132 inputDevice->SetName((name == nullptr) ? ("null") : (name));
133 inputDevice->SetBus(libinput_device_get_id_bustype(deviceOrigin));
134 inputDevice->SetVersion(libinput_device_get_id_version(deviceOrigin));
135 inputDevice->SetProduct(libinput_device_get_id_product(deviceOrigin));
136 inputDevice->SetVendor(libinput_device_get_id_vendor(deviceOrigin));
137 const char *phys = libinput_device_get_phys(deviceOrigin);
138 inputDevice->SetPhys((phys == nullptr) ? ("null") : (phys));
139 const char *uniq = libinput_device_get_uniq(deviceOrigin);
140 inputDevice->SetUniq((uniq == nullptr) ? ("null") : (uniq));
141
142 for (const auto &[first, second] : devCapEnumMaps) {
143 if (libinput_device_has_capability(deviceOrigin, first)) {
144 inputDevice->AddCapability(second);
145 }
146 }
147 }
148
GetInputDeviceIds() const149 std::vector<int32_t> InputDeviceManager::GetInputDeviceIds() const
150 {
151 CALL_DEBUG_ENTER;
152 std::vector<int32_t> ids;
153 for (const auto &item : inputDevice_) {
154 ids.push_back(item.first);
155 }
156 for (const auto &item : virtualInputDevices_) {
157 ids.push_back(item.first);
158 }
159 return ids;
160 }
161
SupportKeys(int32_t deviceId,std::vector<int32_t> & keyCodes,std::vector<bool> & keystroke)162 int32_t InputDeviceManager::SupportKeys(int32_t deviceId, std::vector<int32_t> &keyCodes, std::vector<bool> &keystroke)
163 {
164 CALL_DEBUG_ENTER;
165 auto iter = inputDevice_.find(deviceId);
166 if (iter == inputDevice_.end()) {
167 return COMMON_PARAMETER_ERROR;
168 }
169 if (!iter->second.enable) {
170 MMI_HILOGE("The current device has been disabled");
171 return RET_ERR;
172 }
173 for (const auto &item : keyCodes) {
174 bool ret = false;
175 for (const auto &it : KeyMapMgr->InputTransferKeyValue(deviceId, item)) {
176 ret |= libinput_device_has_key(iter->second.inputDeviceOrigin, it) == SUPPORT_KEY;
177 }
178 keystroke.push_back(ret);
179 }
180 return RET_OK;
181 }
182
IsMatchKeys(struct libinput_device * device,const std::vector<int32_t> & keyCodes) const183 bool InputDeviceManager::IsMatchKeys(struct libinput_device *device, const std::vector<int32_t> &keyCodes) const
184 {
185 CHKPF(device);
186 for (const auto &key : keyCodes) {
187 int32_t value = InputTransformationKeyValue(key);
188 if (libinput_device_keyboard_has_key(device, value) == SUPPORT_KEY) {
189 return true;
190 }
191 }
192 return false;
193 }
194
GetDeviceConfig(int32_t deviceId,int32_t & keyboardType)195 bool InputDeviceManager::GetDeviceConfig(int32_t deviceId, int32_t &keyboardType)
196 {
197 CALL_DEBUG_ENTER;
198 if (auto iter = inputDevice_.find(deviceId); iter == inputDevice_.end()) {
199 MMI_HILOGE("Failed to search for the deviceId");
200 return false;
201 }
202 auto deviceConfig = KeyRepeat->GetDeviceConfig();
203 auto it = deviceConfig.find(deviceId);
204 if (it == deviceConfig.end()) {
205 MMI_HILOGD("Failed to obtain the keyboard type of the configuration file");
206 return false;
207 }
208 keyboardType = it->second.keyboardType;
209 MMI_HILOGD("Get keyboard type results from the configuration file:%{public}d", keyboardType);
210 return true;
211 }
212
GetKeyboardBusMode(int32_t deviceId)213 int32_t InputDeviceManager::GetKeyboardBusMode(int32_t deviceId)
214 {
215 CALL_DEBUG_ENTER;
216 std::shared_ptr dev = GetInputDevice(deviceId);
217 CHKPR(dev, ERROR_NULL_POINTER);
218 return dev->GetBus();
219 }
220
GetDeviceSupportKey(int32_t deviceId,int32_t & keyboardType)221 int32_t InputDeviceManager::GetDeviceSupportKey(int32_t deviceId, int32_t &keyboardType)
222 {
223 CALL_DEBUG_ENTER;
224 std::vector<int32_t> keyCodes;
225 keyCodes.push_back(KeyEvent::KEYCODE_Q);
226 keyCodes.push_back(KeyEvent::KEYCODE_NUMPAD_1);
227 keyCodes.push_back(KeyEvent::KEYCODE_HOME);
228 keyCodes.push_back(KeyEvent::KEYCODE_CTRL_LEFT);
229 keyCodes.push_back(KeyEvent::KEYCODE_SHIFT_RIGHT);
230 keyCodes.push_back(KeyEvent::KEYCODE_F20);
231 std::vector<bool> supportKey;
232 int32_t ret = SupportKeys(deviceId, keyCodes, supportKey);
233 if (ret != RET_OK) {
234 MMI_HILOGE("SupportKey call failed");
235 return ret;
236 }
237 std::map<int32_t, bool> determineKbType;
238 for (size_t i = 0; i < keyCodes.size(); i++) {
239 determineKbType[keyCodes[i]] = supportKey[i];
240 }
241 if (determineKbType[KeyEvent::KEYCODE_HOME] && GetKeyboardBusMode(deviceId) == BUS_BLUETOOTH) {
242 keyboardType = KEYBOARD_TYPE_REMOTECONTROL;
243 MMI_HILOGD("The keyboard type is remote control:%{public}d", keyboardType);
244 } else if (determineKbType[KeyEvent::KEYCODE_NUMPAD_1] && !determineKbType[KeyEvent::KEYCODE_Q]) {
245 keyboardType = KEYBOARD_TYPE_DIGITALKEYBOARD;
246 MMI_HILOGD("The keyboard type is digital keyboard:%{public}d", keyboardType);
247 } else if (determineKbType[KeyEvent::KEYCODE_Q]) {
248 keyboardType = KEYBOARD_TYPE_ALPHABETICKEYBOARD;
249 MMI_HILOGD("The keyboard type is standard:%{public}d", keyboardType);
250 } else if (determineKbType[KeyEvent::KEYCODE_CTRL_LEFT] && determineKbType[KeyEvent::KEYCODE_SHIFT_RIGHT] &&
251 determineKbType[KeyEvent::KEYCODE_F20]) {
252 keyboardType = KEYBOARD_TYPE_HANDWRITINGPEN;
253 MMI_HILOGD("The keyboard type is handwriting pen:%{public}d", keyboardType);
254 } else {
255 keyboardType = KEYBOARD_TYPE_UNKNOWN;
256 MMI_HILOGD("Undefined keyboard type");
257 }
258 MMI_HILOGD("Get keyboard type results by supporting keys:%{public}d", keyboardType);
259 return RET_OK;
260 }
261
GetKeyboardType(int32_t deviceId,int32_t & keyboardType)262 int32_t InputDeviceManager::GetKeyboardType(int32_t deviceId, int32_t &keyboardType)
263 {
264 CALL_DEBUG_ENTER;
265 auto item = virtualInputDevices_.find(deviceId);
266 if (item != virtualInputDevices_.end()) {
267 if (!IsKeyboardDevice(item->second)) {
268 MMI_HILOGW("Virtual device with id:%{public}d is not keyboard", deviceId);
269 keyboardType = KEYBOARD_TYPE_NONE;
270 return RET_OK;
271 }
272 MMI_HILOGI("Virtual device with id:%{public}d, only KEYBOARD_TYPE_ALPHABETICKEYBOARD supported", deviceId);
273 keyboardType = KEYBOARD_TYPE_ALPHABETICKEYBOARD;
274 return RET_OK;
275 }
276 int32_t tempKeyboardType = KEYBOARD_TYPE_NONE;
277 auto iter = inputDevice_.find(deviceId);
278 if (iter == inputDevice_.end()) {
279 MMI_HILOGD("Failed to search for the deviceID");
280 return COMMON_PARAMETER_ERROR;
281 }
282 if (!iter->second.enable) {
283 MMI_HILOGE("The current device has been disabled");
284 return RET_ERR;
285 }
286 if (GetDeviceConfig(deviceId, tempKeyboardType)) {
287 keyboardType = tempKeyboardType;
288 return RET_OK;
289 }
290 return GetDeviceSupportKey(deviceId, keyboardType);
291 }
292
SetInputStatusChangeCallback(inputDeviceCallback callback)293 void InputDeviceManager::SetInputStatusChangeCallback(inputDeviceCallback callback)
294 {
295 CALL_DEBUG_ENTER;
296 devCallbacks_ = callback;
297 }
298
AddDevListener(SessionPtr sess)299 void InputDeviceManager::AddDevListener(SessionPtr sess)
300 {
301 CALL_DEBUG_ENTER;
302 InitSessionLostCallback();
303 devListeners_.push_back(sess);
304 }
305
RemoveDevListener(SessionPtr sess)306 void InputDeviceManager::RemoveDevListener(SessionPtr sess)
307 {
308 CALL_DEBUG_ENTER;
309 devListeners_.remove(sess);
310 }
311
312 #ifdef OHOS_BUILD_ENABLE_POINTER_DRAWING
HasPointerDevice()313 bool InputDeviceManager::HasPointerDevice()
314 {
315 for (auto it = inputDevice_.begin(); it != inputDevice_.end(); ++it) {
316 if (it->second.isPointerDevice) {
317 return true;
318 }
319 }
320 return false;
321 }
322
HasVirtualPointerDevice()323 bool InputDeviceManager::HasVirtualPointerDevice()
324 {
325 for (auto it = virtualInputDevices_.begin(); it != virtualInputDevices_.end(); ++it) {
326 if (it->second->HasCapability(InputDeviceCapability::INPUT_DEV_CAP_POINTER)) {
327 return true;
328 }
329 }
330 return false;
331 }
332 #endif // OHOS_BUILD_ENABLE_POINTER_DRAWING
333
HasTouchDevice()334 bool InputDeviceManager::HasTouchDevice()
335 {
336 CALL_DEBUG_ENTER;
337 for (auto it = inputDevice_.begin(); it != inputDevice_.end(); ++it) {
338 if (it->second.isTouchableDevice) {
339 return true;
340 }
341 }
342 return false;
343 }
344
GetInputIdentification(struct libinput_device * inputDevice)345 std::string InputDeviceManager::GetInputIdentification(struct libinput_device *inputDevice)
346 {
347 CALL_DEBUG_ENTER;
348 int32_t deviceVendor = libinput_device_get_id_vendor(inputDevice);
349 int32_t deviceProduct = libinput_device_get_id_product(inputDevice);
350 struct udev_device *udevDevice = libinput_device_get_udev_device(inputDevice);
351 std::string sysPath = udev_device_get_syspath(udevDevice);
352 udev_device_unref(udevDevice);
353 if ((deviceVendor < 0) || (deviceProduct < 0) || sysPath.empty()) {
354 MMI_HILOGE("Get device identification failed");
355 return "";
356 }
357 const size_t bufSize = 10;
358 char vid[bufSize] = "";
359 char pid[bufSize] = "";
360 sprintf_s(vid, sizeof(vid), "%04X", deviceVendor);
361 sprintf_s(pid, sizeof(pid), "%04X", deviceProduct);
362 std::string strVid(vid);
363 std::string strPid(pid);
364 std::string vendorProduct = strVid + ":" + strPid;
365 std::string deviceIdentification = sysPath.substr(0, sysPath.find(vendorProduct)) + vendorProduct;
366 MMI_HILOGI("Device identification is:%{public}s", deviceIdentification.c_str());
367 return deviceIdentification;
368 }
369
NotifyDevCallback(int32_t deviceId,struct InputDeviceInfo inDevice)370 void InputDeviceManager::NotifyDevCallback(int32_t deviceId, struct InputDeviceInfo inDevice)
371 {
372 if (!inDevice.isTouchableDevice || (deviceId < 0)) {
373 MMI_HILOGI("The device is not touchable device already existent");
374 return;
375 }
376 if (!inDevice.sysUid.empty()) {
377 devCallbacks_(deviceId, inDevice.sysUid, "add");
378 MMI_HILOGI("Send device info to window manager, device id:%{public}d, system uid:%s, status:add",
379 deviceId, inDevice.sysUid.c_str());
380 } else {
381 MMI_HILOGE("Get device system uid id is empty, deviceId:%{public}d", deviceId);
382 }
383 }
384
ParseDeviceId(struct libinput_device * inputDevice)385 int32_t InputDeviceManager::ParseDeviceId(struct libinput_device *inputDevice)
386 {
387 CALL_DEBUG_ENTER;
388 std::regex pattern("^event(\\d+)$");
389 std::smatch mr;
390 const char *sysName = libinput_device_get_sysname(inputDevice);
391 CHKPR(sysName, RET_ERR);
392 std::string strName(sysName);
393 if (std::regex_match(strName, mr, pattern)) {
394 if (mr.ready() && mr.size() == EXPECTED_N_SUBMATCHES) {
395 return std::stoi(mr[EXPECTED_SUBMATCH].str());
396 }
397 }
398 std::string errStr = "Parsing strName failed: \'" + strName + "\'";
399 MMI_HILOGE("%{public}s", errStr.c_str());
400 #ifdef OHOS_BUILD_ENABLE_DFX_RADAR
401 DfxHisyseventDeivce::ReportDeviceFault(DfxHisyseventDeivce::DeviceFaultType::DEVICE_FAULT_TYPE_INNER, errStr);
402 #endif
403 return RET_ERR;
404 }
405
OnInputDeviceAdded(struct libinput_device * inputDevice)406 void InputDeviceManager::OnInputDeviceAdded(struct libinput_device *inputDevice)
407 {
408 CALL_DEBUG_ENTER;
409 CHKPV(inputDevice);
410 bool hasPointer = false;
411 for (const auto &item : inputDevice_) {
412 if (item.second.inputDeviceOrigin == inputDevice) {
413 MMI_HILOGI("The device is already existent");
414 #ifdef OHOS_BUILD_ENABLE_DFX_RADAR
415 DfxHisyseventDeivce::ReportDeviceFault(item.first,
416 DfxHisyseventDeivce::DeviceFaultType::DEVICE_FAULT_TYPE_INNER,
417 "The device is already existent");
418 #endif
419 return;
420 }
421 if ((!item.second.isRemote && item.second.isPointerDevice) ||
422 (item.second.isRemote && item.second.isPointerDevice && item.second.enable)) {
423 hasPointer = true;
424 }
425 }
426 int32_t deviceId = ParseDeviceId(inputDevice);
427 if (deviceId < 0) {
428 return;
429 }
430 struct InputDeviceInfo info;
431 MakeDeviceInfo(inputDevice, info);
432 inputDevice_[deviceId] = info;
433 if (info.enable) {
434 for (const auto& item : devListeners_) {
435 CHKPC(item);
436 NotifyMessage(item, deviceId, "add");
437 }
438 }
439 NotifyDevCallback(deviceId, info);
440 if (!hasPointer && info.isPointerDevice) {
441 #if defined(OHOS_BUILD_ENABLE_POINTER) && defined(OHOS_BUILD_ENABLE_POINTER_DRAWING)
442 if (HasTouchDevice()) {
443 IPointerDrawingManager::GetInstance()->SetMouseDisplayState(false);
444 }
445 #endif // OHOS_BUILD_ENABLE_POINTER && OHOS_BUILD_ENABLE_POINTER_DRAWING
446 NotifyPointerDevice(true, true, true);
447 OHOS::system::SetParameter(INPUT_POINTER_DEVICES, "true");
448 MMI_HILOGI("Set para input.pointer.device true");
449 }
450 #if defined(OHOS_BUILD_ENABLE_POINTER) && defined(OHOS_BUILD_ENABLE_POINTER_DRAWING)
451 if (IsPointerDevice(inputDevice)) {
452 WIN_MGR->UpdatePointerChangeAreas();
453 }
454 if (IsPointerDevice(inputDevice) && !HasPointerDevice() &&
455 IPointerDrawingManager::GetInstance()->GetMouseDisplayState()) {
456 WIN_MGR->DispatchPointer(PointerEvent::POINTER_ACTION_ENTER_WINDOW);
457 }
458 #endif // OHOS_BUILD_ENABLE_POINTER && OHOS_BUILD_ENABLE_POINTER_DRAWING
459 #ifdef OHOS_BUILD_ENABLE_DFX_RADAR
460 DfxHisyseventDeivce::ReportDeviceBehavior(deviceId, "Device added successfully");
461 #endif
462 }
463
MakeDeviceInfo(struct libinput_device * inputDevice,struct InputDeviceInfo & info)464 void InputDeviceManager::MakeDeviceInfo(struct libinput_device *inputDevice, struct InputDeviceInfo &info)
465 {
466 info.inputDeviceOrigin = inputDevice;
467 info.isRemote = IsRemote(inputDevice);
468 info.enable = info.isRemote ? false : true;
469 info.isPointerDevice = IsPointerDevice(inputDevice);
470 info.isTouchableDevice = IsTouchDevice(inputDevice);
471 info.sysUid = GetInputIdentification(inputDevice);
472 #ifndef OHOS_BUILD_ENABLE_WATCH
473 info.vendorConfig = configManagement_.GetVendorConfig(inputDevice);
474 #endif // OHOS_BUILD_ENABLE_WATCH
475 }
476
OnInputDeviceRemoved(struct libinput_device * inputDevice)477 void InputDeviceManager::OnInputDeviceRemoved(struct libinput_device *inputDevice)
478 {
479 CALL_DEBUG_ENTER;
480 CHKPV(inputDevice);
481 int32_t deviceId = INVALID_DEVICE_ID;
482 bool enable = false;
483 for (auto it = inputDevice_.begin(); it != inputDevice_.end(); ++it) {
484 if (it->second.inputDeviceOrigin == inputDevice) {
485 deviceId = it->first;
486 enable = it->second.enable;
487 #ifdef OHOS_BUILD_ENABLE_DFX_RADAR
488 DfxHisyseventDeivce::ReportDeviceBehavior(deviceId, "Device removed successfully");
489 #endif
490 inputDevice_.erase(it);
491 break;
492 }
493 }
494 std::string sysUid = GetInputIdentification(inputDevice);
495 if (!sysUid.empty()) {
496 CHKPV(devCallbacks_);
497 devCallbacks_(deviceId, sysUid, "remove");
498 MMI_HILOGI("Send device info to window manager, device id:%{public}d, system uid:%s, status:remove",
499 deviceId, sysUid.c_str());
500 }
501
502 #if defined(OHOS_BUILD_ENABLE_POINTER) && defined(OHOS_BUILD_ENABLE_POINTER_DRAWING)
503 if (IsPointerDevice(inputDevice) && !HasPointerDevice() &&
504 IPointerDrawingManager::GetInstance()->GetMouseDisplayState()) {
505 WIN_MGR->DispatchPointer(PointerEvent::POINTER_ACTION_LEAVE_WINDOW);
506 }
507 #endif // OHOS_BUILD_ENABLE_POINTER && OHOS_BUILD_ENABLE_POINTER_DRAWING
508 if (enable) {
509 for (const auto& item : devListeners_) {
510 CHKPV(item);
511 NotifyMessage(item, deviceId, "remove");
512 }
513 }
514 ScanPointerDevice();
515 if (deviceId == INVALID_DEVICE_ID) {
516 #ifdef OHOS_BUILD_ENABLE_DFX_RADAR
517 DfxHisyseventDeivce::ReportDeviceFault(DfxHisyseventDeivce::DeviceFaultType::DEVICE_FAULT_TYPE_INNER,
518 "Device reomved failed becaused of not found");
519 #endif
520 }
521 }
522
ScanPointerDevice()523 void InputDeviceManager::ScanPointerDevice()
524 {
525 bool hasPointerDevice = false;
526 for (auto it = inputDevice_.begin(); it != inputDevice_.end(); ++it) {
527 if (it->second.isPointerDevice && it->second.enable) {
528 hasPointerDevice = true;
529 break;
530 }
531 }
532 if (!hasPointerDevice) {
533 NotifyPointerDevice(false, false, true);
534 OHOS::system::SetParameter(INPUT_POINTER_DEVICES, "false");
535 MMI_HILOGI("Set para input.pointer.device false");
536 }
537 }
538
IsPointerDevice(struct libinput_device * device) const539 bool InputDeviceManager::IsPointerDevice(struct libinput_device *device) const
540 {
541 CHKPF(device);
542 enum evdev_device_udev_tags udevTags = libinput_device_get_tags(device);
543 MMI_HILOGD("The current device udev tag:%{public}d", static_cast<int32_t>(udevTags));
544 std::string name = libinput_device_get_name(device);
545 if (name == "hw_fingerprint_mouse") {
546 return false;
547 }
548 if (name.find("TouchPad") == std::string::npos) {
549 return (udevTags & (EVDEV_UDEV_TAG_MOUSE | EVDEV_UDEV_TAG_TRACKBALL | EVDEV_UDEV_TAG_POINTINGSTICK |
550 EVDEV_UDEV_TAG_TOUCHPAD | EVDEV_UDEV_TAG_TABLET_PAD)) != 0;
551 }
552 return (udevTags & (EVDEV_UDEV_TAG_MOUSE | EVDEV_UDEV_TAG_TRACKBALL | EVDEV_UDEV_TAG_POINTINGSTICK |
553 EVDEV_UDEV_TAG_TOUCHPAD | EVDEV_UDEV_TAG_TABLET_PAD)) != 0;
554 }
555
IsKeyboardDevice(struct libinput_device * device) const556 bool InputDeviceManager::IsKeyboardDevice(struct libinput_device *device) const
557 {
558 CHKPF(device);
559 enum evdev_device_udev_tags udevTags = libinput_device_get_tags(device);
560 MMI_HILOGD("The current device udev tag:%{public}d", static_cast<int32_t>(udevTags));
561 return udevTags & EVDEV_UDEV_TAG_KEYBOARD;
562 }
563
IsTouchDevice(struct libinput_device * device) const564 bool InputDeviceManager::IsTouchDevice(struct libinput_device *device) const
565 {
566 CHKPF(device);
567 return libinput_device_has_capability(device, LIBINPUT_DEVICE_CAP_TOUCH);
568 }
569
Attach(std::shared_ptr<IDeviceObserver> observer)570 void InputDeviceManager::Attach(std::shared_ptr<IDeviceObserver> observer)
571 {
572 CALL_DEBUG_ENTER;
573 observers_.push_back(observer);
574 }
575
Detach(std::shared_ptr<IDeviceObserver> observer)576 void InputDeviceManager::Detach(std::shared_ptr<IDeviceObserver> observer)
577 {
578 CALL_DEBUG_ENTER;
579 observers_.remove(observer);
580 }
581
NotifyPointerDevice(bool hasPointerDevice,bool isVisible,bool isHotPlug)582 void InputDeviceManager::NotifyPointerDevice(bool hasPointerDevice, bool isVisible, bool isHotPlug)
583 {
584 MMI_HILOGI("The observers_ size:%{public}zu", observers_.size());
585 for (auto observer = observers_.begin(); observer != observers_.end(); observer++) {
586 (*observer)->UpdatePointerDevice(hasPointerDevice, isVisible, isHotPlug);
587 }
588 }
589
FindInputDeviceId(struct libinput_device * inputDevice)590 int32_t InputDeviceManager::FindInputDeviceId(struct libinput_device *inputDevice)
591 {
592 CALL_DEBUG_ENTER;
593 CHKPR(inputDevice, INVALID_DEVICE_ID);
594 for (const auto &item : inputDevice_) {
595 if (item.second.inputDeviceOrigin == inputDevice) {
596 MMI_HILOGD("Find input device id success");
597 return item.first;
598 }
599 }
600 MMI_HILOGE("Find input device id failed");
601 return INVALID_DEVICE_ID;
602 }
603
GetKeyboardDevice() const604 struct libinput_device *InputDeviceManager::GetKeyboardDevice() const
605 {
606 CALL_DEBUG_ENTER;
607 std::vector<int32_t> keyCodes;
608 keyCodes.push_back(KeyEvent::KEYCODE_Q);
609 keyCodes.push_back(KeyEvent::KEYCODE_NUMPAD_1);
610 for (const auto &item : inputDevice_) {
611 const auto &device = item.second.inputDeviceOrigin;
612 if (IsMatchKeys(device, keyCodes)) {
613 MMI_HILOGI("Find keyboard device success");
614 return device;
615 }
616 }
617 MMI_HILOGW("No keyboard device is currently available");
618 return nullptr;
619 }
620
GetMultiKeyboardDevice(std::vector<struct libinput_device * > & inputDevice)621 void InputDeviceManager::GetMultiKeyboardDevice(std::vector<struct libinput_device*> &inputDevice)
622 {
623 CALL_DEBUG_ENTER;
624 std::vector<int32_t> keyCodes;
625 keyCodes.push_back(KeyEvent::KEYCODE_Q);
626 keyCodes.push_back(KeyEvent::KEYCODE_NUMPAD_1);
627 for (const auto &item : inputDevice_) {
628 const auto &device = item.second.inputDeviceOrigin;
629 if (IsMatchKeys(device, keyCodes)) {
630 MMI_HILOGI("Find keyboard device success id %{public}d", item.first);
631 inputDevice.push_back(device);
632 }
633 }
634 }
635
Dump(int32_t fd,const std::vector<std::string> & args)636 void InputDeviceManager::Dump(int32_t fd, const std::vector<std::string> &args)
637 {
638 CALL_DEBUG_ENTER;
639 mprintf(fd, "Device information:\t");
640 mprintf(fd, "Input devices: count=%zu", inputDevice_.size());
641 mprintf(fd, "Virtual input devices: count=%zu", virtualInputDevices_.size());
642 std::vector<int32_t> deviceIds = GetInputDeviceIds();
643 for (auto deviceId : deviceIds) {
644 std::shared_ptr<InputDevice> inputDevice = GetInputDevice(deviceId, false);
645 CHKPV(inputDevice);
646 mprintf(fd,
647 "deviceId:%d | deviceName:%s | deviceType:%d | bus:%d | version:%d "
648 "| product:%d | vendor:%d | phys:%s\t",
649 inputDevice->GetId(), inputDevice->GetName().c_str(), inputDevice->GetType(), inputDevice->GetBus(),
650 inputDevice->GetVersion(), inputDevice->GetProduct(), inputDevice->GetVendor(),
651 inputDevice->GetPhys().c_str());
652 std::vector<InputDevice::AxisInfo> axisinfo = inputDevice->GetAxisInfo();
653 mprintf(fd, "axis: count=%zu", axisinfo.size());
654 for (const auto &axis : axisinfo) {
655 auto iter = axisType.find(axis.GetAxisType());
656 if (iter == axisType.end()) {
657 MMI_HILOGE("The axisType is not found");
658 return;
659 }
660 mprintf(fd, "\t axisType:%s | minimum:%d | maximum:%d | fuzz:%d | flat:%d | resolution:%d\t",
661 iter->second.c_str(), axis.GetMinimum(), axis.GetMaximum(), axis.GetFuzz(), axis.GetFlat(),
662 axis.GetResolution());
663 }
664 }
665 }
666
DumpDeviceList(int32_t fd,const std::vector<std::string> & args)667 void InputDeviceManager::DumpDeviceList(int32_t fd, const std::vector<std::string> &args)
668 {
669 CALL_DEBUG_ENTER;
670 std::vector<int32_t> ids = GetInputDeviceIds();
671 mprintf(fd, "Total device:%zu, Device list:\t", ids.size());
672 for (const auto &item : inputDevice_) {
673 std::shared_ptr<InputDevice> inputDevice = GetInputDevice(item.first, false);
674 CHKPV(inputDevice);
675 int32_t deviceId = inputDevice->GetId();
676 mprintf(fd, "deviceId:%d | deviceName:%s | deviceType:%d | bus:%d | version:%d | product:%d | vendor:%d\t",
677 deviceId, inputDevice->GetName().c_str(), inputDevice->GetType(), inputDevice->GetBus(),
678 inputDevice->GetVersion(), inputDevice->GetProduct(), inputDevice->GetVendor());
679 }
680 }
681
IsRemote(struct libinput_device * inputDevice) const682 bool InputDeviceManager::IsRemote(struct libinput_device *inputDevice) const
683 {
684 CHKPF(inputDevice);
685 bool isRemote = false;
686 const char *name = libinput_device_get_name(inputDevice);
687 if (name == nullptr || name[0] == '\0') {
688 MMI_HILOGD("Device name is empty");
689 return false;
690 }
691 std::string strName = name;
692 std::string::size_type pos = strName.find(INPUT_VIRTUAL_DEVICE_NAME);
693 if (pos != std::string::npos) {
694 isRemote = true;
695 }
696 MMI_HILOGD("The isRemote:%{public}s", isRemote ? "true" : "false");
697 return isRemote;
698 }
699
IsRemote(int32_t id) const700 bool InputDeviceManager::IsRemote(int32_t id) const
701 {
702 bool isRemote = false;
703 auto device = inputDevice_.find(id);
704 if (device != inputDevice_.end()) {
705 isRemote = device->second.isRemote;
706 }
707 MMI_HILOGD("The isRemote:%{public}s", isRemote ? "true" : "false");
708 return isRemote;
709 }
710
GetVendorConfig(int32_t deviceId) const711 VendorConfig InputDeviceManager::GetVendorConfig(int32_t deviceId) const
712 {
713 CALL_DEBUG_ENTER;
714 auto it = inputDevice_.find(deviceId);
715 if (it == inputDevice_.end()) {
716 MMI_HILOGE("Device info not find id:%{public}d", deviceId);
717 return {};
718 }
719 return it->second.vendorConfig;
720 }
721
OnEnableInputDevice(bool enable)722 int32_t InputDeviceManager::OnEnableInputDevice(bool enable)
723 {
724 CALL_DEBUG_ENTER;
725 MMI_HILOGD("Enable input device:%{public}s", enable ? "true" : "false");
726 for (auto &item : inputDevice_) {
727 if (item.second.isRemote && item.second.enable != enable) {
728 int32_t keyboardType = KEYBOARD_TYPE_NONE;
729 if (enable) {
730 item.second.enable = enable;
731 GetKeyboardType(item.first, keyboardType);
732 } else {
733 GetKeyboardType(item.first, keyboardType);
734 item.second.enable = enable;
735 }
736 if (keyboardType != KEYBOARD_TYPE_ALPHABETICKEYBOARD) {
737 continue;
738 }
739 for (const auto& listener : devListeners_) {
740 CHKPC(listener);
741 NotifyMessage(listener, item.first, enable ? "add" : "remove");
742 }
743 }
744 }
745 for (const auto &item : inputDevice_) {
746 if (item.second.isPointerDevice && item.second.enable) {
747 NotifyPointerDevice(true, true, false);
748 break;
749 }
750 }
751 return RET_OK;
752 }
753
AddVirtualInputDevice(std::shared_ptr<InputDevice> device,int32_t & deviceId)754 int32_t InputDeviceManager::AddVirtualInputDevice(std::shared_ptr<InputDevice> device, int32_t &deviceId)
755 {
756 CALL_INFO_TRACE;
757 CHKPR(device, RET_ERR);
758 if (GenerateVirtualDeviceId(deviceId) != RET_OK) {
759 MMI_HILOGE("GenerateVirtualDeviceId failed");
760 deviceId = INVALID_DEVICE_ID;
761 return RET_ERR;
762 }
763 device->SetId(deviceId);
764 virtualInputDevices_[deviceId] = device;
765 MMI_HILOGI("AddVirtualInputDevice successfully, deviceId:%{public}d", deviceId);
766 for (const auto& item : devListeners_) {
767 CHKPC(item);
768 NotifyMessage(item, deviceId, "add");
769 }
770 InputDeviceInfo deviceInfo;
771 if (MakeVirtualDeviceInfo(device, deviceInfo) != RET_OK) {
772 MMI_HILOGE("MakeVirtualDeviceInfo failed");
773 return RET_ERR;
774 }
775 NotifyDevCallback(deviceId, deviceInfo);
776 #ifdef OHOS_BUILD_ENABLE_DFX_RADAR
777 DfxHisyseventDeivce::ReportDeviceBehavior(deviceId, "AddVirtualInputDevice successfully");
778 #endif
779 return RET_OK;
780 }
781
RemoveVirtualInputDevice(int32_t deviceId)782 int32_t InputDeviceManager::RemoveVirtualInputDevice(int32_t deviceId)
783 {
784 CALL_INFO_TRACE;
785 auto iter = virtualInputDevices_.find(deviceId);
786 if (iter == virtualInputDevices_.end()) {
787 MMI_HILOGE("No virtual deviceId:%{public}d existed", deviceId);
788 return RET_ERR;
789 }
790 InputDeviceInfo deviceInfo;
791 if (MakeVirtualDeviceInfo(iter->second, deviceInfo) != RET_OK) {
792 MMI_HILOGE("MakeVirtualDeviceInfo failed");
793 return RET_ERR;
794 }
795 NotifyDevRemoveCallback(deviceId, deviceInfo);
796 virtualInputDevices_.erase(deviceId);
797 MMI_HILOGI("RemoveVirtualInputDevice successfully, deviceId:%{public}d", deviceId);
798 for (const auto& item : devListeners_) {
799 CHKPC(item);
800 NotifyMessage(item, deviceId, "remove");
801 }
802 #ifdef OHOS_BUILD_ENABLE_DFX_RADAR
803 DfxHisyseventDeivce::ReportDeviceBehavior(deviceId, "RemoveVirtualInputDevice successfully");
804 #endif
805 return RET_OK;
806 }
807
MakeVirtualDeviceInfo(std::shared_ptr<InputDevice> device,InputDeviceInfo & deviceInfo)808 int32_t InputDeviceManager::MakeVirtualDeviceInfo(std::shared_ptr<InputDevice> device, InputDeviceInfo &deviceInfo)
809 {
810 CALL_INFO_TRACE;
811 CHKPR(device, ERROR_NULL_POINTER);
812 deviceInfo = {
813 .isRemote = false,
814 .isPointerDevice = device->HasCapability(InputDeviceCapability::INPUT_DEV_CAP_POINTER),
815 .isTouchableDevice = device->HasCapability(InputDeviceCapability::INPUT_DEV_CAP_TOUCH),
816 .enable = true,
817 };
818 return RET_OK;
819 }
820
GenerateVirtualDeviceId(int32_t & deviceId)821 int32_t InputDeviceManager::GenerateVirtualDeviceId(int32_t &deviceId)
822 {
823 CALL_INFO_TRACE;
824 static int32_t virtualDeviceId { MIN_VIRTUAL_INPUT_DEVICE_ID };
825 if (virtualInputDevices_.size() >= MAX_VIRTUAL_INPUT_DEVICE_NUM) {
826 MMI_HILOGE("Virtual device num exceeds limit:%{public}d", MAX_VIRTUAL_INPUT_DEVICE_NUM);
827 return RET_ERR;
828 }
829 if (virtualDeviceId == std::numeric_limits<int32_t>::max()) {
830 MMI_HILOGW("Request id exceeds the maximum");
831 virtualDeviceId = MIN_VIRTUAL_INPUT_DEVICE_ID;
832 }
833 deviceId = virtualDeviceId++;
834 if (virtualInputDevices_.find(deviceId) != virtualInputDevices_.end()) {
835 MMI_HILOGE("Repeated deviceId:%{public}d", deviceId);
836 deviceId = INVALID_DEVICE_ID;
837 return RET_ERR;
838 }
839 return RET_OK;
840 }
841
NotifyDevRemoveCallback(int32_t deviceId,const InputDeviceInfo & deviceInfo)842 void InputDeviceManager::NotifyDevRemoveCallback(int32_t deviceId, const InputDeviceInfo &deviceInfo)
843 {
844 CALL_DEBUG_ENTER;
845 if (auto sysUid = deviceInfo.sysUid; !sysUid.empty()) {
846 devCallbacks_(deviceId, sysUid, "remove");
847 MMI_HILOGI("Send device info to window manager, deivceId:%{public}d, status:remove", deviceId);
848 }
849 }
850
NotifyMessage(SessionPtr sess,int32_t id,const std::string & type)851 int32_t InputDeviceManager::NotifyMessage(SessionPtr sess, int32_t id, const std::string &type)
852 {
853 CALL_DEBUG_ENTER;
854 CHKPR(sess, ERROR_NULL_POINTER);
855 NetPacket pkt(MmiMessageId::ADD_INPUT_DEVICE_LISTENER);
856 pkt << type << id;
857 if (pkt.ChkRWError()) {
858 MMI_HILOGE("Packet write data failed");
859 return RET_ERR;
860 }
861 if (!sess->SendMsg(pkt)) {
862 MMI_HILOGE("Sending failed");
863 }
864 return RET_OK;
865 }
866
InitSessionLostCallback()867 void InputDeviceManager::InitSessionLostCallback()
868 {
869 if (sessionLostCallbackInitialized_) {
870 MMI_HILOGD("Init session is failed");
871 return;
872 }
873 auto udsServerPtr = InputHandler->GetUDSServer();
874 CHKPV(udsServerPtr);
875 udsServerPtr->AddSessionDeletedCallback([this] (SessionPtr session) {
876 return this->OnSessionLost(session);
877 }
878 );
879 sessionLostCallbackInitialized_ = true;
880 MMI_HILOGI("The callback on session deleted is registered successfully");
881 }
882
OnSessionLost(SessionPtr session)883 void InputDeviceManager::OnSessionLost(SessionPtr session)
884 {
885 CALL_DEBUG_ENTER;
886 RecoverInputDeviceEnabled(session);
887 devListeners_.remove(session);
888 }
889
GetTouchPadIds()890 std::vector<int32_t> InputDeviceManager::GetTouchPadIds()
891 {
892 CALL_DEBUG_ENTER;
893 std::vector<int32_t> ids;
894 for (const auto &item : inputDevice_) {
895 auto inputDevice = item.second.inputDeviceOrigin;
896 if (inputDevice == nullptr) {
897 continue;
898 }
899 enum evdev_device_udev_tags udevTags = libinput_device_get_tags(inputDevice);
900 if ((udevTags & EVDEV_UDEV_TAG_TOUCHPAD) != 0) {
901 ids.push_back(item.first);
902 }
903 }
904 return ids;
905 }
906
GetTouchPadDeviceOrigin()907 struct libinput_device *InputDeviceManager::GetTouchPadDeviceOrigin()
908 {
909 CALL_DEBUG_ENTER;
910 struct libinput_device *touchPadDevice = nullptr;
911 for (const auto &item : inputDevice_) {
912 auto inputDevice = item.second.inputDeviceOrigin;
913 if (inputDevice == nullptr) {
914 continue;
915 }
916 enum evdev_device_udev_tags udevTags = libinput_device_get_tags(inputDevice);
917 if ((udevTags & EVDEV_UDEV_TAG_TOUCHPAD) != 0) {
918 touchPadDevice = inputDevice;
919 break;
920 }
921 }
922 return touchPadDevice;
923 }
924
IsPointerDevice(std::shared_ptr<InputDevice> inputDevice) const925 bool InputDeviceManager::IsPointerDevice(std::shared_ptr<InputDevice> inputDevice) const
926 {
927 CHKPR(inputDevice, false);
928 return inputDevice->HasCapability(InputDeviceCapability::INPUT_DEV_CAP_POINTER);
929 }
930
IsTouchableDevice(std::shared_ptr<InputDevice> inputDevice) const931 bool InputDeviceManager::IsTouchableDevice(std::shared_ptr<InputDevice> inputDevice) const
932 {
933 CHKPR(inputDevice, false);
934 return inputDevice->HasCapability(InputDeviceCapability::INPUT_DEV_CAP_TOUCH);
935 }
936
IsKeyboardDevice(std::shared_ptr<InputDevice> inputDevice) const937 bool InputDeviceManager::IsKeyboardDevice(std::shared_ptr<InputDevice> inputDevice) const
938 {
939 CHKPR(inputDevice, false);
940 return inputDevice->HasCapability(InputDeviceCapability::INPUT_DEV_CAP_KEYBOARD);
941 }
942
NotifyInputdeviceMessage(SessionPtr session,int32_t index,int32_t result)943 int32_t InputDeviceManager::NotifyInputdeviceMessage(SessionPtr session, int32_t index, int32_t result)
944 {
945 CALL_DEBUG_ENTER;
946 CHKPR(session, ERROR_NULL_POINTER);
947 NetPacket pkt(MmiMessageId::SET_INPUT_DEVICE_ENABLED);
948 pkt << index << result;
949 if (pkt.ChkRWError()) {
950 MMI_HILOGE("Packet write data failed");
951 return RET_ERR;
952 }
953 if (!session->SendMsg(pkt)) {
954 MMI_HILOGE("Sending failed");
955 return RET_ERR;
956 }
957 return RET_OK;
958 }
959
SetInputDeviceEnabled(int32_t deviceId,bool enable,int32_t index,int32_t pid,SessionPtr session)960 int32_t InputDeviceManager::SetInputDeviceEnabled(
961 int32_t deviceId, bool enable, int32_t index, int32_t pid, SessionPtr session)
962 {
963 CALL_DEBUG_ENTER;
964 MMI_HILOGI("The deviceId:%{public}d, enable:%{public}d, pid:%{public}d", deviceId, enable, pid);
965 auto item = inputDevice_.find(deviceId);
966 if (item == inputDevice_.end()) {
967 NotifyInputdeviceMessage(session, index, ERROR_DEVICE_NOT_EXIST);
968 MMI_HILOGD("Set inputDevice enabled failed, Invalid deviceId");
969 return RET_ERR;
970 }
971 item->second.enable = enable;
972 if (!enable) {
973 MMI_HILOGD("Disable inputdevice, save calling pid:%{public}d to recoverlist", pid);
974 recoverList_.insert(std::pair<int32_t, int32_t>(deviceId, pid));
975 InitSessionLostCallback();
976 }
977 NotifyInputdeviceMessage(session, index, RET_OK);
978 return RET_OK;
979 }
980
RecoverInputDeviceEnabled(SessionPtr session)981 void InputDeviceManager::RecoverInputDeviceEnabled(SessionPtr session)
982 {
983 CALL_DEBUG_ENTER;
984 CHKPV(session);
985 std::lock_guard<std::mutex> lock(mutex_);
986 for (auto item = recoverList_.begin(); item != recoverList_.end();) {
987 if (session->GetPid() == item->second) {
988 auto device = inputDevice_.find(item->first);
989 if (device != inputDevice_.end()) {
990 MMI_HILOGI("Recover input device:%{public}d", item->first);
991 device->second.enable = true;
992 }
993 item = recoverList_.erase(item);
994 } else {
995 item++;
996 }
997 }
998 }
999
IsInputDeviceEnable(int32_t deviceId)1000 bool InputDeviceManager::IsInputDeviceEnable(int32_t deviceId)
1001 {
1002 bool enable = false;
1003 CALL_DEBUG_ENTER;
1004 auto item = inputDevice_.find(deviceId);
1005 if (item == inputDevice_.end()) {
1006 MMI_HILOGD("Get inputDevice enabled failed, Invalid deviceId.");
1007 return enable;
1008 }
1009 enable = item->second.enable;
1010 return enable;
1011 }
1012 } // namespace MMI
1013 } // namespace OHOS
1014