Lines Matching defs:device
70 DHLOGI("Init InputHub for device plugin monitor");
87 DHLOGI("Init InputHub for read device events");
141 std::unique_ptr<Device> device = std::move(*openingDevices_.rbegin());
143 DHLOGI("Reporting device opened: path=%{public}s, name=%{public}s\n",
144 device->path.c_str(), device->identifier.name.c_str());
145 std::string devPath = device->path;
146 auto [dev_it, inserted] = devices_.insert_or_assign(device->path, std::move(device));
194 DHLOGE("Find device by fd: %{public}d failed", eventItem.data.fd);
198 Device* device = GetSupportDeviceByFd(eventItem.data.fd);
199 if (!device) {
200 DHLOGE("Can not find device by fd: %{public}d", eventItem.data.fd);
203 if (!sharedDHIds_[device->identifier.descriptor]) {
204 RecordDeviceChangeStates(device, readBuffer, count);
205 DHLOGD("Not in sharing stat, device descriptor: %{public}s",
206 GetAnonyString(device->identifier.descriptor).c_str());
210 event += CollectEvent(event, capacity, device, readBuffer, count);
217 DHLOGI("Removing device %{public}s due to epoll hang-up event.", device->identifier.name.c_str());
218 CloseDeviceLocked(*device);
224 bool InputHub::IsCuror(Device *device)
226 return device->classes & INPUT_DEVICE_CLASS_CURSOR;
229 bool InputHub::IsTouchPad(Device *device)
231 return ((device->classes & INPUT_DEVICE_CLASS_TOUCH_MT) || (device->classes & INPUT_DEVICE_CLASS_TOUCH)) &&
232 IsTouchPad(device->identifier);
245 void InputHub::MatchAndDealEvent(Device *device, const RawEvent &event)
247 bool isTouchPad = IsTouchPad(device);
250 DealNormalKeyEvent(device, event);
265 void InputHub::DealNormalKeyEvent(Device *device, const RawEvent &event)
273 if (IsCuror(device) && event.code == BTN_MOUSE &&
287 void InputHub::RecordDeviceChangeStates(Device *device, struct input_event readBuffer[], const size_t count)
290 if ((device->classes & INPUT_DEVICE_CLASS_TOUCH_MT) || (device->classes & INPUT_DEVICE_CLASS_TOUCH)) {
291 if (!IsTouchPad(device->identifier)) {
303 event.path = device->path;
304 event.descriptor = isTouchEvent ? touchDescriptor : device->identifier.descriptor;
305 MatchAndDealEvent(device, event);
309 size_t InputHub::CollectEvent(RawEvent *buffer, size_t &capacity, Device *device, struct input_event readBuffer[],
314 if ((device->classes & INPUT_DEVICE_CLASS_TOUCH_MT) || (device->classes & INPUT_DEVICE_CLASS_TOUCH)) {
315 if (!IsTouchPad(device->identifier)) {
331 event->path = device->path;
332 event->descriptor = isTouchEvent ? touchDescriptor : device->identifier.descriptor;
343 size_t InputHub::ReadInputEvent(int32_t readSize, Device &device)
349 device.fd, readSize, errno);
350 CloseDeviceLocked(device);
372 std::unique_ptr<Device> device = std::move(*it);
373 DHLOGI("Reporting device closed: id=%{public}s, name=%{public}s",
374 device->path.c_str(), device->identifier.name.c_str());
376 event->deviceInfo = device->identifier;
394 std::unique_ptr<Device> device = std::move(*openingDevices_.rbegin());
396 DHLOGI("Reporting device opened: id=%{public}s, name=%{public}s",
397 device->path.c_str(), device->identifier.name.c_str());
399 event->deviceInfo = device->identifier;
402 std::string devPath = device->path;
403 auto [dev_it, inserted] = devices_.insert_or_assign(device->path, std::move(device));
468 Device* device = GetDeviceByFdLocked(eventItem.data.fd);
469 if (!device) {
474 DHLOGI("Removing device %{public}s due to epoll hang-up event.", device->identifier.name.c_str());
476 CloseDeviceLocked(*device);
515 for (const auto &[id, device] : devices_) {
516 vecDevice.push_back(device->identifier);
536 for (const auto &[deviceId, device] : devices_) {
537 if (device->path == devicePath) {
538 DHLOGI("Device node already registered, node path: %{public}s", device->path.c_str());
539 return true; // device was already registered
552 DHLOGD("Opening device start: %{public}s", devicePath.c_str());
559 // Allocate device. (The device object takes ownership of the fd at this point.)
560 std::unique_ptr<Device> device = std::make_unique<Device>(fd, devicePath);
562 if (QueryInputDeviceInfo(fd, device) < 0) {
566 GenerateDescriptor(device->identifier);
567 IncreaseLogTimes(device->identifier.descriptor);
568 RecordDeviceLog(devicePath, device->identifier);
569 std::string descriptor = device->identifier.descriptor;
570 if (MakeDevice(fd, std::move(device)) < 0) {
573 DHLOGI("Opening device error: %{public}s", devicePath.c_str());
578 DHLOGI("Opening device finish: %{public}s", devicePath.c_str());
608 int32_t InputHub::QueryInputDeviceInfo(int fd, std::unique_ptr<Device> &device)
611 // Get device name.
613 DHLOGE("Could not get device name for %{public}s", ConvertErrNo().c_str());
616 device->identifier.name = buffer;
619 // If the device is already a virtual device, don't monitor it.
620 if (device->identifier.name.find(VIRTUAL_DEVICE_NAME) != std::string::npos) {
622 RecordSkipDevicePath(device->path);
625 // Get device driver version.
629 RecordSkipDevicePath(device->path);
632 // Get device identifier.
635 DHLOGE("could not get device input id for %{public}s\n", ConvertErrNo().c_str());
636 RecordSkipDevicePath(device->path);
639 device->identifier.bus = inputId.bustype;
640 device->identifier.product = inputId.product;
641 device->identifier.vendor = inputId.vendor;
642 device->identifier.version = inputId.version;
643 // Get device physical physicalPath.
648 device->identifier.physicalPath = buffer;
650 // Get device unique id.
655 device->identifier.uniqueId = buffer;
658 QueryEventInfo(fd, device);
662 void InputHub::QueryEventInfo(int fd, std::unique_ptr<Device> &device)
664 if (device == nullptr) {
665 DHLOGE("device is nullptr!");
668 if (IsNeedPrintLog(device->identifier.descriptor)) {
669 DHLOGI("QueryEventInfo: devName: %{public}s, dhId: %{public}s!", device->identifier.name.c_str(),
670 GetAnonyString(device->identifier.descriptor).c_str());
674 if (IsNeedPrintLog(device->identifier.descriptor)) {
679 GetEventTypes(dev, device->identifier);
680 GetEventKeys(dev, device->identifier);
681 GetABSInfo(dev, device->identifier);
682 GetRELTypes(dev, device->identifier);
683 GetProperties(dev, device->identifier);
685 GetMSCBits(fd, device);
686 GetLEDBits(fd, device);
687 GetSwitchBits(fd, device);
688 GetRepeatBits(fd, device);
702 void InputHub::GetMSCBits(int fd, std::unique_ptr<Device> &device)
708 if (TestBit(EV_MSC, device->evBitmask) && TestBit(msc, mscBitmask)) {
710 device->identifier.miscellaneous.push_back(msc);
715 void InputHub::GetLEDBits(int fd, std::unique_ptr<Device> &device)
720 if (TestBit(EV_LED, device->evBitmask) && TestBit(led, ledBitmask)) {
722 device->identifier.leds.push_back(led);
727 void InputHub::GetSwitchBits(int fd, std::unique_ptr<Device> &device)
733 if (TestBit(EV_SW, device->evBitmask) && TestBit(sw, switchBitmask)) {
735 device->identifier.switchs.push_back(sw);
740 void InputHub::GetRepeatBits(int fd, std::unique_ptr<Device> &device)
746 if (TestBit(EV_REP, device->evBitmask) && TestBit(rep, repBitmask)) {
748 device->identifier.repeats.push_back(rep);
769 DHLOGD("The device is not support eventType: %{public}d", eventType);
780 DHLOGE("The device doesn't has EV_KEY type!");
786 DHLOGD("The device is not support eventKey: %{public}d", eventKey);
798 DHLOGE("The device doesn't has EV_ABS type!");
802 DHLOGI("The device has abs info, devName: %{public}s, dhId: %{public}s!",
806 DHLOGD("The device is not support absType: %{public}d", absType);
829 DHLOGE("The device doesn't has EV_REL type!");
835 DHLOGD("The device is not support rel code: %{public}d", code);
853 int32_t InputHub::MakeDevice(int fd, std::unique_ptr<Device> device)
855 // See if this is a multi-touch touchscreen device.
856 if (TestBit(BTN_TOUCH, device->keyBitmask) &&
857 TestBit(ABS_MT_POSITION_X, device->absBitmask) &&
858 TestBit(ABS_MT_POSITION_Y, device->absBitmask)) {
859 QueryLocalTouchScreenInfo(fd, device);
860 device->classes |= INPUT_DEVICE_CLASS_TOUCH | INPUT_DEVICE_CLASS_TOUCH_MT;
861 } else if (TestBit(BTN_TOUCH, device->keyBitmask) &&
862 TestBit(ABS_X, device->absBitmask) &&
863 TestBit(ABS_Y, device->absBitmask)) {
864 QueryLocalTouchScreenInfo(fd, device);
865 device->classes |= INPUT_DEVICE_CLASS_TOUCH;
868 // See if this is a cursor device such as a trackball or mouse.
869 if (TestBit(BTN_MOUSE, device->keyBitmask)
870 && TestBit(REL_X, device->relBitmask)
871 && TestBit(REL_Y, device->relBitmask)) {
872 device->classes |= INPUT_DEVICE_CLASS_CURSOR;
876 // need to avoid device->classes to be 0x09, which mmi can't handler.
878 if (device->classes == 0) {
879 bool haveKeyboardKeys = ContainsNonZeroByte(device->keyBitmask, 0, SizeofBitArray(BTN_MISC));
881 device->classes |= INPUT_DEVICE_CLASS_KEYBOARD;
885 // If the device isn't recognized as something we handle, don't monitor it.
886 if (device->classes == 0) {
887 if (IsNeedPrintLog(device->identifier.descriptor)) {
888 DHLOGI("Dropping device: name='%{public}s'", device->identifier.name.c_str());
893 if (RegisterDeviceForEpollLocked(*device) != DH_SUCCESS) {
897 device->identifier.classes = device->classes;
900 DHLOGI("New device: fd=%{public}d, name='%{public}s', classes=0x%{public}x", fd, device->identifier.name.c_str(),
901 device->classes);
903 AddDeviceLocked(std::move(device));
907 int32_t InputHub::QueryLocalTouchScreenInfo(int fd, std::unique_ptr<Device> &device)
910 device->identifier.classes |= INPUT_DEVICE_CLASS_TOUCH_MT;
911 info.localAbsInfo.deviceInfo = device->identifier;
1002 int32_t InputHub::RegisterDeviceForEpollLocked(const Device &device)
1004 int32_t result = RegisterFdForEpoll(device.fd);
1006 DHLOGE("Could not add input device fd to epoll for device, path: %{public}s", device.path.c_str());
1024 void InputHub::AddDeviceLocked(std::unique_ptr<Device> device)
1027 openingDevices_.push_back(std::move(device));
1030 void InputHub::CloseDeviceLocked(Device &device)
1032 DHLOGI("Removed device: path=%{public}s name=%{public}s fd=%{public}d classes=0x%{public}x",
1033 device.path.c_str(), device.identifier.name.c_str(), device.fd, device.classes);
1035 UnregisterDeviceFromEpollLocked(device);
1036 device.Close();
1039 closingDevices_.push_back(std::move(devices_[device.path]));
1040 devices_.erase(device.path);
1044 void InputHub::CloseDeviceForAllLocked(Device &device)
1046 DHLOGI("Removed device: path=%{public}s name=%{public}s fd=%{public}d classes=0x%{public}x",
1047 device.path.c_str(), device.identifier.name.c_str(), device.fd, device.classes);
1049 UnregisterDeviceFromEpollLocked(device);
1050 device.Close();
1051 closingDevices_.push_back(std::move(devices_[device.path]));
1052 devices_.erase(device.path);
1055 int32_t InputHub::UnregisterDeviceFromEpollLocked(const Device &device) const
1057 if (device.HasValidFd()) {
1058 int32_t result = UnregisterFdFromEpoll(device.fd);
1060 DHLOGE("Could not remove input device fd from epoll for device, path: %{public}s", device.path.c_str());
1114 DHLOGI("Removing device '%{public}s' due to inotify event\n", filename.c_str());
1125 Device* device = GetDeviceByPathLocked(devicePath);
1126 if (device) {
1127 CloseDeviceLocked(*device);
1130 DHLOGI("Remove device: %{public}s not found, device may already have been removed.", devicePath.c_str());
1145 for (const auto &[id, device] : devices_) {
1146 if (device->path == devicePath) {
1147 return device.get();
1156 for (const auto &[id, device] : devices_) {
1157 if (device->fd == fd) {
1158 return device.get();
1167 for (const auto &[id, device] : devices_) {
1168 if (device != nullptr && device->fd == fd) {
1169 return device.get();
1221 for (const auto &[id, device] : devices_) {
1222 if (device->classes & inputTypes_) {
1223 device->isShare = enabled;
1225 GetAnonyString(device->identifier.descriptor).c_str(), enabled);
1226 SaveAffectDhId(enabled, device->identifier.descriptor, affDhIds);
1242 for (const auto &[id, device] : devices_) {
1243 DHLOGI("deviceName %{public}s ,dhId: %{public}s ", device->identifier.name.c_str(),
1244 GetAnonyString(device->identifier.descriptor).c_str());
1245 if (device->identifier.descriptor == dhId) {
1246 device->isShare = enabled;
1248 GetAnonyString(device->identifier.descriptor).c_str(), enabled);
1249 SaveAffectDhId(enabled, device->identifier.descriptor, affDhIds);
1262 for (const auto &[id, device] : devices_) {
1263 if (device->isShare) {
1264 DHLOGI("Find sharing dhid: %{public}s", GetAnonyString(device->identifier.descriptor).c_str());
1265 sharingDevices.push_back(device->identifier.descriptor);
1277 for (const auto &[id, device] : devices_) {
1278 if (device == nullptr) {
1279 DHLOGE("device is nullptr");
1283 GetAnonyString(device->identifier.descriptor).c_str(), device->isShare, device->classes);
1284 if ((device->identifier.descriptor == dhId) && ((device->classes & INPUT_DEVICE_CLASS_CURSOR) != 0 ||
1285 (device->classes & INPUT_DEVICE_CLASS_TOUCH) != 0 ||
1286 ((device->classes & INPUT_DEVICE_CLASS_TOUCH_MT) != 0 && IsTouchPad(device->identifier)))) {
1288 sharedMousePath = device->path;
1301 for (const auto &[id, device] : devices_) {
1302 if (device == nullptr) {
1303 DHLOGE("device is nullptr");
1307 GetAnonyString(device->identifier.descriptor).c_str(), device->isShare, device->classes);
1308 if ((device->identifier.descriptor == dhId) &&
1309 ((device->classes & INPUT_DEVICE_CLASS_KEYBOARD) != 0)) {
1311 sharedKeyboardPaths.push_back(device->path);
1334 for (const auto &[id, device] : devices_) {
1335 if (device->classes & dhType) {
1336 datas.insert(std::pair<int32_t, std::string>(device->fd, device->identifier.descriptor));
1345 for (const auto &[id, device] : devices_) {
1346 if (device->identifier.descriptor == dhId) {
1347 datas.insert(std::pair<int32_t, std::string>(device->fd, dhId));
1368 DHLOGI("add device: %{public}s\n", devicePath.c_str());
1531 DHLOGI("Find Pressed key: %{public}d, device path: %{public}s, dhId: %{public}s", keyCode, dev->path.c_str(),
1546 // If device is a mouse, record the mouse pressed key.
1571 // If device is a keyboard, record all the pressed keys.
1583 // If device is a touchscreen or touchpad, record the touch event.
1624 DHLOGI("Check target states device num: %{public}zu", tarDevices.size());
1637 DHLOGI("Clear Skip device path");
1645 // Figure out the kinds of events the device reports.