diff --git a/common/include/constants_dinput.h b/common/include/constants_dinput.h index 2add0fd7e188bc21fe0bf16ce2e4e1e085cb3f1c..34d7ed1e2c49e516c1388a3afb67544e06d2d7c1 100644 --- a/common/include/constants_dinput.h +++ b/common/include/constants_dinput.h @@ -187,6 +187,14 @@ namespace DistributedInput { const std::string PROPERTIES = "properties"; + const std::string MISCELLANEOUS = "miscellaneous"; + + const std::string LEDS = "leds"; + + const std::string REPEATS = "repeats"; + + const std::string SWITCHS = "switchs"; + const std::string DH_TOUCH_PAD = "touchpad"; const std::string DINPUT_LOG_TITLE_TAG = "DINPUT"; @@ -258,6 +266,11 @@ namespace DistributedInput { std::map> absInfos; std::vector relTypes; std::vector properties; + + std::vector miscellaneous; + std::vector leds; + std::vector switchs; + std::vector repeats; }; /* diff --git a/common/include/input_hub.cpp b/common/include/input_hub.cpp index dec0a9c45b97da92ad1cff97be9fae838411bc27..8389a6e822017c6ed0535f63ef0190ecd71c65ff 100644 --- a/common/include/input_hub.cpp +++ b/common/include/input_hub.cpp @@ -454,17 +454,17 @@ int32_t InputHub::OpenInputDeviceLocked(const std::string &devicePath) return ERR_DH_INPUT_HUB_OPEN_DEVICEPATH_FAIL; } - InputDevice identifier; - if (QueryInputDeviceInfo(fd, identifier) < 0) { + // Allocate device. (The device object takes ownership of the fd at this point.) + int32_t deviceId = nextDeviceId_++; + std::unique_ptr device = std::make_unique(fd, deviceId, devicePath); + + if (QueryInputDeviceInfo(fd, device) < 0) { CloseFd(fd); return ERR_DH_INPUT_HUB_QUERY_INPUT_DEVICE_INFO_FAIL; } - GenerateDescriptor(identifier); + GenerateDescriptor(device->identifier); - // Allocate device. (The device object takes ownership of the fd at this point.) - int32_t deviceId = nextDeviceId_++; - std::unique_ptr device = std::make_unique(fd, deviceId, devicePath, identifier); - RecordDeviceLog(deviceId, devicePath, identifier); + RecordDeviceLog(deviceId, devicePath, device->identifier); if (MakeDevice(fd, std::move(device)) < 0) { CloseFd(fd); @@ -474,7 +474,7 @@ int32_t InputHub::OpenInputDeviceLocked(const std::string &devicePath) return DH_SUCCESS; } -int32_t InputHub::QueryInputDeviceInfo(int fd, InputDevice &identifier) +int32_t InputHub::QueryInputDeviceInfo(int fd, std::unique_ptr &device) { char buffer[INPUT_EVENT_BUFFER_SIZE] = {0}; // Get device name. @@ -483,11 +483,11 @@ int32_t InputHub::QueryInputDeviceInfo(int fd, InputDevice &identifier) "Could not get device name for %s", ConvertErrNo().c_str()); } else { buffer[sizeof(buffer) - 1] = '\0'; - identifier.name = buffer; + device->identifier.name = buffer; } DHLOGD("QueryInputDeviceInfo deviceName: %s", buffer); // If the device is already a virtual device, don't monitor it. - if (identifier.name.find(VIRTUAL_DEVICE_NAME) != std::string::npos) { + if (device->identifier.name.find(VIRTUAL_DEVICE_NAME) != std::string::npos) { return ERR_DH_INPUT_HUB_IS_VIRTUAL_DEVICE; } // Get device driver version. @@ -502,46 +502,112 @@ int32_t InputHub::QueryInputDeviceInfo(int fd, InputDevice &identifier) DHLOGE("could not get device input id for %s\n", ConvertErrNo().c_str()); return ERR_DH_INPUT_HUB_QUERY_INPUT_DEVICE_INFO_FAIL; } - identifier.bus = inputId.bustype; - identifier.product = inputId.product; - identifier.vendor = inputId.vendor; - identifier.version = inputId.version; + device->identifier.bus = inputId.bustype; + device->identifier.product = inputId.product; + device->identifier.vendor = inputId.vendor; + device->identifier.version = inputId.version; // Get device physical physicalPath. if (ioctl(fd, EVIOCGPHYS(sizeof(buffer) - 1), &buffer) < 1) { DHLOGE("could not get physicalPath for %s\n", ConvertErrNo().c_str()); } else { buffer[sizeof(buffer) - 1] = '\0'; - identifier.physicalPath = buffer; + device->identifier.physicalPath = buffer; } // Get device unique id. if (ioctl(fd, EVIOCGUNIQ(sizeof(buffer) - 1), &buffer) < 1) { DHLOGE("could not get idstring for %s\n", ConvertErrNo().c_str()); } else { buffer[sizeof(buffer) - 1] = '\0'; - identifier.uniqueId = buffer; + device->identifier.uniqueId = buffer; } - QueryEventInfo(fd, identifier); + QueryEventInfo(fd, device); return DH_SUCCESS; } -void InputHub::QueryEventInfo(int fd, InputDevice &identifier) +void InputHub::QueryEventInfo(int fd, std::unique_ptr &device) { - DHLOGI("QueryEventInfo: devName: %s, dhId: %s!", identifier.name.c_str(), - GetAnonyString(identifier.descriptor).c_str()); + DHLOGI("QueryEventInfo: devName: %s, dhId: %s!", device->identifier.name.c_str(), + GetAnonyString(device->identifier.descriptor).c_str()); struct libevdev *dev = GetLibEvDev(fd); if (dev == nullptr) { DHLOGE("dev is nullptr"); return; } - GetEventTypes(dev, identifier); - GetEventKeys(dev, identifier); - GetABSInfo(dev, identifier); - GetRELTypes(dev, identifier); - GetProperties(dev, identifier); + GetEventTypes(dev, device->identifier); + GetEventKeys(dev, device->identifier); + GetABSInfo(dev, device->identifier); + GetRELTypes(dev, device->identifier); + GetProperties(dev, device->identifier); + + GetMSCBits(fd, device); + GetLEDBits(fd, device); + GetSwitchBits(fd, device); + GetRepeatBits(fd, device); + libevdev_free(dev); } +void InputHub::GetEventMask(int fd, const std::string &eventName, uint32_t type, + std::size_t arrayLength, uint8_t *whichBitMask) const +{ + int32_t rc = ioctl(fd, EVIOCGBIT(type, arrayLength), whichBitMask); + if (rc < 0) { + DHLOGE("Could not get events %{public}s mask: %{public}s", eventName.c_str(), strerror(errno)); + } +} + +void InputHub::GetMSCBits(int fd, std::unique_ptr &device) +{ + uint8_t mscBitmask_[NBYTES(MSC_MAX)] {}; + GetEventMask(fd, "msc", EV_MSC, sizeof(mscBitmask_), mscBitmask_); + + for (uint32_t msc = MSC_SERIAL; msc < MSC_MAX; ++msc) { + if (TestBit(EV_MSC, device->evBitmask) && TestBit(msc, mscBitmask_)) { + DHLOGI("Get MSC event: %d", msc); + device->identifier.miscellaneous.push_back(msc); + } + } +} + +void InputHub::GetLEDBits(int fd, std::unique_ptr &device) +{ + uint8_t ledBitmask_[NBYTES(LED_MAX)] {}; + GetEventMask(fd, "led", EV_LED, sizeof(ledBitmask_), ledBitmask_); + for (uint32_t led = LED_NUML; led < LED_MAX; ++led) { + if (TestBit(EV_LED, device->evBitmask) && TestBit(led, ledBitmask_)) { + DHLOGI("Get LED event: %d", led); + device->identifier.leds.push_back(led); + } + } +} + +void InputHub::GetSwitchBits(int fd, std::unique_ptr &device) +{ + uint8_t switchBitmask_[NBYTES(SW_MAX)] {}; + GetEventMask(fd, "switch", EV_SW, sizeof(switchBitmask_), switchBitmask_); + + for (uint32_t sw = SW_LID; sw < SW_MAX; ++sw) { + if (TestBit(EV_SW, device->evBitmask) && TestBit(sw, switchBitmask_)) { + DHLOGI("Get Switch event: %d", sw); + device->identifier.switchs.push_back(sw); + } + } +} + +void InputHub::GetRepeatBits(int fd, std::unique_ptr &device) +{ + uint8_t repBitmask_[NBYTES(REP_MAX)] {}; + GetEventMask(fd, "repeat", EV_REP, sizeof(repBitmask_), repBitmask_); + + for (uint32_t rep = REP_DELAY; rep < REP_MAX; ++rep) { + if (TestBit(EV_REP, device->evBitmask) && TestBit(rep, repBitmask_)) { + DHLOGI("Get Repeat event: %d", rep); + device->identifier.repeats.push_back(rep); + } + } +} + struct libevdev* InputHub::GetLibEvDev(int fd) { struct libevdev *dev = nullptr; @@ -644,11 +710,6 @@ void InputHub::GetProperties(struct libevdev *dev, InputDevice &identifier) int32_t InputHub::MakeDevice(int fd, std::unique_ptr device) { - // Figure out the kinds of events the device reports. - ioctl(fd, EVIOCGBIT(EV_KEY, sizeof(device->keyBitmask)), device->keyBitmask); - ioctl(fd, EVIOCGBIT(EV_ABS, sizeof(device->absBitmask)), device->absBitmask); - ioctl(fd, EVIOCGBIT(EV_REL, sizeof(device->relBitmask)), device->relBitmask); - // See if this is a multi-touch touchscreen device. if (TestBit(BTN_TOUCH, device->keyBitmask) && TestBit(ABS_MT_POSITION_X, device->absBitmask) && @@ -702,13 +763,12 @@ int32_t InputHub::MakeDevice(int fd, std::unique_ptr device) int32_t InputHub::QueryLocalTouchScreenInfo(int fd) { LocalTouchScreenInfo info = DInputContext::GetInstance().GetLocalTouchScreenInfo(); - - InputDevice identifier; - if (QueryInputDeviceInfo(fd, identifier) < 0) { + std::unique_ptr device = std::make_unique(fd, 0, ""); + if (QueryInputDeviceInfo(fd, device) < 0) { return ERR_DH_INPUT_HUB_QUERY_INPUT_DEVICE_INFO_FAIL; } - identifier.classes |= INPUT_DEVICE_CLASS_TOUCH_MT; - info.localAbsInfo.deviceInfo = identifier; + device->identifier.classes |= INPUT_DEVICE_CLASS_TOUCH_MT; + info.localAbsInfo.deviceInfo = device->identifier; struct input_absinfo absInfo; ioctl(fd, EVIOCGABS(ABS_MT_POSITION_X), &absInfo); @@ -1264,12 +1324,15 @@ bool InputHub::CheckTouchPointRegion(struct input_event readBuffer[], const AbsI return false; } -InputHub::Device::Device(int fd, int32_t id, const std::string &path, - const InputDevice &identifier) : next(nullptr), fd(fd), id(id), path(path), identifier(identifier), - classes(0), enabled(false), isShare(false), isVirtual(fd < 0) { - memset_s(keyBitmask, sizeof(keyBitmask), 0, sizeof(keyBitmask)); - memset_s(absBitmask, sizeof(absBitmask), 0, sizeof(absBitmask)); - memset_s(relBitmask, sizeof(relBitmask), 0, sizeof(relBitmask)); +InputHub::Device::Device(int fd, int32_t id, const std::string &path) + : next(nullptr), fd(fd), id(id), path(path), identifier({}), classes(0), enabled(false), + isShare(false), isVirtual(fd < 0) { + // Figure out the kinds of events the device reports. + DHLOGE("Ctor Device for get event mask, fd: %d, id: %d, path: %d", fd, id, path.c_str()); + ioctl(fd, EVIOCGBIT(0, sizeof(evBitmask)), evBitmask); + ioctl(fd, EVIOCGBIT(EV_KEY, sizeof(keyBitmask)), keyBitmask); + ioctl(fd, EVIOCGBIT(EV_ABS, sizeof(absBitmask)), absBitmask); + ioctl(fd, EVIOCGBIT(EV_REL, sizeof(relBitmask)), relBitmask); } InputHub::Device::~Device() diff --git a/common/include/input_hub.h b/common/include/input_hub.h index b7344f9658400f41c7b894b354a1a6d9c0d15264..8068a56234463f3acef33a8d552ddb8b495e42d3 100644 --- a/common/include/input_hub.h +++ b/common/include/input_hub.h @@ -36,6 +36,12 @@ struct AffectDhIds { std::vector noSharingDhIds; }; +inline constexpr size_t BITS_PER_UINT8 { 8 }; +inline constexpr size_t NBYTES(size_t nbits) +{ + return (nbits + BITS_PER_UINT8 - 1) / BITS_PER_UINT8; +} + class InputHub { public: InputHub(); @@ -67,11 +73,12 @@ private: const std::string path; InputDevice identifier; uint32_t classes; - uint8_t keyBitmask[(KEY_MAX + 1) / 8]; - uint8_t absBitmask[(ABS_MAX + 1) / 8]; - uint8_t relBitmask[(REL_MAX + 1) / 8]; + uint8_t evBitmask[NBYTES(EV_MAX)] {}; + uint8_t keyBitmask[NBYTES(KEY_MAX)] {}; + uint8_t absBitmask[NBYTES(ABS_MAX)] {}; + uint8_t relBitmask[NBYTES(REL_MAX)] {}; - Device(int fd, int32_t id, const std::string &path, const InputDevice &identifier); + Device(int fd, int32_t id, const std::string &path); ~Device(); void Close(); bool enabled; // initially true @@ -98,14 +105,23 @@ private: int32_t RefreshEpollItem(bool isSleep); int32_t OpenInputDeviceLocked(const std::string &devicePath); - int32_t QueryInputDeviceInfo(int fd, InputDevice &identifier); - void QueryEventInfo(int fd, InputDevice &identifier); + int32_t QueryInputDeviceInfo(int fd, std::unique_ptr &device); + void QueryEventInfo(int fd, std::unique_ptr &device); struct libevdev* GetLibEvDev(int fd); void GetEventTypes(struct libevdev *dev, InputDevice &identifier); int32_t GetEventKeys(struct libevdev *dev, InputDevice &identifier); int32_t GetABSInfo(struct libevdev *dev, InputDevice &identifier); int32_t GetRELTypes(struct libevdev *dev, InputDevice &identifier); void GetProperties(struct libevdev *dev, InputDevice &identifier); + + void GetMSCBits(int fd, std::unique_ptr &device); + void GetLEDBits(int fd, std::unique_ptr &device); + void GetSwitchBits(int fd, std::unique_ptr &device); + void GetRepeatBits(int fd, std::unique_ptr &device); + + void GetEventMask(int fd, const std::string &eventName, uint32_t type, + std::size_t arrayLength, uint8_t *whichBitMask) const; + int32_t MakeDevice(int fd, std::unique_ptr device); void GenerateDescriptor(InputDevice &identifier) const; std::string StringPrintf(const char *format, ...) const; diff --git a/inputdevicehandler/src/distributed_input_handler.cpp b/inputdevicehandler/src/distributed_input_handler.cpp index 6c0a5f0bd3cfa566b76dd6001410f42f53b4990d..004e9e3598ede36de18d552cd6d6666eb8507ded 100644 --- a/inputdevicehandler/src/distributed_input_handler.cpp +++ b/inputdevicehandler/src/distributed_input_handler.cpp @@ -74,9 +74,15 @@ void DistributedInputHandler::StructTransJson(const InputDevice &pBuf, std::stri tmpJson[REL_TYPES] = pBuf.relTypes; tmpJson[PROPERTIES] = pBuf.properties; + tmpJson[MISCELLANEOUS] = pBuf.miscellaneous; + tmpJson[LEDS] = pBuf.leds; + tmpJson[REPEATS] = pBuf.repeats; + tmpJson[SWITCHS] = pBuf.switchs; + std::ostringstream stream; stream << tmpJson.dump(); strDescriptor = stream.str(); + DHLOGI("Record InputDevice json info: %s", strDescriptor.c_str()); return; } diff --git a/services/source/inputinject/src/distributed_input_node_manager.cpp b/services/source/inputinject/src/distributed_input_node_manager.cpp index 28889a477121d05b4c36906954f287d4e8921ddb..5c2c603e763940efddb6a2dba7be81b3ded89237 100644 --- a/services/source/inputinject/src/distributed_input_node_manager.cpp +++ b/services/source/inputinject/src/distributed_input_node_manager.cpp @@ -129,6 +129,18 @@ void DistributedInputNodeManager::VerifyInputDevice(const nlohmann::json &inputD if (IsArray(inputDeviceJson, PROPERTIES)) { pBuf.properties = inputDeviceJson[PROPERTIES].get>(); } + if (IsArray(inputDeviceJson, MISCELLANEOUS)) { + pBuf.miscellaneous = inputDeviceJson[MISCELLANEOUS].get>(); + } + if (IsArray(inputDeviceJson, LEDS)) { + pBuf.leds = inputDeviceJson[LEDS].get>(); + } + if (IsArray(inputDeviceJson, REPEATS)) { + pBuf.repeats = inputDeviceJson[REPEATS].get>(); + } + if (IsArray(inputDeviceJson, SWITCHS)) { + pBuf.switchs = inputDeviceJson[SWITCHS].get>(); + } } void DistributedInputNodeManager::ScanSinkInputDevices(const std::string &dhId) diff --git a/services/source/inputinject/src/virtual_device.cpp b/services/source/inputinject/src/virtual_device.cpp index a0b83c58178cfb1b927b882a8baa84afa59edfe3..799890efc2fb1f76396dda1fd6890e8342cbced5 100644 --- a/services/source/inputinject/src/virtual_device.cpp +++ b/services/source/inputinject/src/virtual_device.cpp @@ -73,6 +73,12 @@ bool VirtualDevice::CreateKey(const InputDevice &inputDevice) evt_type[UI_SET_PROPBIT] = inputDevice.properties; evt_type[UI_SET_ABSBIT] = inputDevice.absTypes; evt_type[UI_SET_RELBIT] = inputDevice.relTypes; + + evt_type[UI_SET_MSCBIT] = inputDevice.miscellaneous; + evt_type[UI_SET_LEDBIT] = inputDevice.leds; + evt_type[UI_SET_SWBIT] = inputDevice.switchs; + evt_type[UI_SET_FFBIT] = inputDevice.repeats; + for (auto &it : evt_type) { if (!fun(it.first, it.second)) { return false; @@ -219,7 +225,7 @@ void VirtualDevice::RecordEventLog(const input_event &event) eventType = "EV_ABS"; break; default: - eventType = "other type"; + eventType = "other type " + std::to_string(event.type); break; } DHLOGD("4.E2E-Test Source write event into input driver, EventType: %s, Code: %d, Value: %d, Sec: %ld, Sec1: %ld", diff --git a/services/state/src/dinput_state.cpp b/services/state/src/dinput_state.cpp index 6c19bca820e7fe029e6b3c58c179689c5a19f153..16717283aec021df29fc7e5e0d2d3d9d333cc95b 100644 --- a/services/state/src/dinput_state.cpp +++ b/services/state/src/dinput_state.cpp @@ -116,7 +116,7 @@ void DInputState::RecordEventLog(const input_event &event) eventType = "EV_SYN"; break; default: - eventType = "other type"; + eventType = "other type " + std::to_string(event.type); break; } DHLOGD("5.E2E-Test Source write event into input driver, EventType: %s, Code: %d, Value: %d",