diff --git a/common/include/constants_dinput.h b/common/include/constants_dinput.h index 9e2f058..a4437ad 100644 --- a/common/include/constants_dinput.h +++ b/common/include/constants_dinput.h @@ -20,6 +20,8 @@ #include #include +#include + namespace OHOS { namespace DistributedHardware { namespace DistributedInput { @@ -115,6 +117,8 @@ namespace DistributedInput { /* The input device is external (not built-in). */ constexpr uint32_t INPUT_DEVICE_CLASS_EXTERNAL = 0x80000000; + constexpr uint32_t MAX_SIZE_OF_DEVICE_NAME = UINPUT_MAX_NAME_SIZE - 1; + const std::string DH_ID_PREFIX = "Input_"; const std::string DINPUT_SPLIT_COMMA = ", "; @@ -179,10 +183,10 @@ namespace DistributedInput { * Input device Info retrieved from the kernel. */ struct InputDevice { - inline InputDevice() : name(""), location(""), uniqueId(""), bus(0), vendor(0), product(0), + inline InputDevice() : name(""), physicalPath(""), uniqueId(""), bus(0), vendor(0), product(0), version(0), descriptor(""), classes(0) {} std::string name; - std::string location; + std::string physicalPath; std::string uniqueId; uint16_t bus; uint16_t vendor; diff --git a/common/include/input_hub.cpp b/common/include/input_hub.cpp index 868b72a..011117d 100644 --- a/common/include/input_hub.cpp +++ b/common/include/input_hub.cpp @@ -535,12 +535,12 @@ int32_t InputHub::QueryInputDeviceInfo(int fd, InputDevice& identifier) identifier.product = inputId.product; identifier.vendor = inputId.vendor; identifier.version = inputId.version; - // Get device physical location. + // Get device physical physicalPath. if (ioctl(fd, EVIOCGPHYS(sizeof(buffer) - 1), &buffer) < 1) { - DHLOGE("could not get location for %s\n", ConvertErrNo().c_str()); + DHLOGE("could not get physicalPath for %s\n", ConvertErrNo().c_str()); } else { buffer[sizeof(buffer) - 1] = '\0'; - identifier.location = buffer; + identifier.physicalPath = buffer; } // Get device unique id. if (ioctl(fd, EVIOCGUNIQ(sizeof(buffer) - 1), &buffer) < 1) { @@ -695,9 +695,10 @@ void InputHub::GenerateDescriptor(InputDevice& identifier) const if (!identifier.uniqueId.empty()) { rawDescriptor += "uniqueId:"; rawDescriptor += identifier.uniqueId; - } else if (!identifier.location.empty()) { - rawDescriptor += "location:"; - rawDescriptor += identifier.location; + } + if (!identifier.physicalPath.empty()) { + rawDescriptor += "physicalPath:"; + rawDescriptor += identifier.physicalPath; } if (!identifier.name.empty()) { rawDescriptor += "name:"; @@ -1071,7 +1072,7 @@ void InputHub::RecordDeviceLog(const int32_t deviceId, const std::string& device " version %04x\n", identifier.bus, identifier.vendor, identifier.product, identifier.version); DHLOGI(" name: \"%s\"\n", identifier.name.c_str()); - DHLOGI(" location: \"%s\"\n", identifier.location.c_str()); + DHLOGI(" physicalPath: \"%s\"\n", identifier.physicalPath.c_str()); DHLOGI(" unique id: \"%s\"\n", identifier.uniqueId.c_str()); DHLOGI(" descriptor: \"%s\"\n", GetAnonyString(identifier.descriptor).c_str()); } diff --git a/inputdevicehandler/src/distributed_input_handler.cpp b/inputdevicehandler/src/distributed_input_handler.cpp index 981d15b..3b5671f 100644 --- a/inputdevicehandler/src/distributed_input_handler.cpp +++ b/inputdevicehandler/src/distributed_input_handler.cpp @@ -58,7 +58,7 @@ void DistributedInputHandler::StructTransJson(const InputDevice& pBuf, std::stri GetAnonyString(pBuf.descriptor).c_str()); nlohmann::json tmpJson; tmpJson["name"] = pBuf.name; - tmpJson["location"] = pBuf.location; + tmpJson["physicalPath"] = pBuf.physicalPath; tmpJson["uniqueId"] = pBuf.uniqueId; tmpJson["bus"] = pBuf.bus; tmpJson["vendor"] = pBuf.vendor; diff --git a/services/source/inputinject/src/distributed_input_inject.cpp b/services/source/inputinject/src/distributed_input_inject.cpp index 90d8bbb..3ba943d 100644 --- a/services/source/inputinject/src/distributed_input_inject.cpp +++ b/services/source/inputinject/src/distributed_input_inject.cpp @@ -132,7 +132,7 @@ int32_t DistributedInputInject::StructTransJson(const InputDevice &pBuf, std::st GetAnonyString(pBuf.descriptor).c_str()); nlohmann::json tmpJson; tmpJson["name"] = pBuf.name; - tmpJson["location"] = pBuf.location; + tmpJson["physicalPath"] = pBuf.physicalPath; tmpJson["uniqueId"] = pBuf.uniqueId; tmpJson["bus"] = pBuf.bus; tmpJson["vendor"] = pBuf.vendor; diff --git a/services/source/inputinject/src/distributed_input_node_manager.cpp b/services/source/inputinject/src/distributed_input_node_manager.cpp index f14629f..49804ba 100644 --- a/services/source/inputinject/src/distributed_input_node_manager.cpp +++ b/services/source/inputinject/src/distributed_input_node_manager.cpp @@ -73,7 +73,7 @@ void DistributedInputNodeManager::stringTransJsonTransStruct(const std::string& { nlohmann::json recMsg = nlohmann::json::parse(str); recMsg.at("name").get_to(pBuf.name); - recMsg.at("location").get_to(pBuf.location); + recMsg.at("physicalPath").get_to(pBuf.physicalPath); recMsg.at("uniqueId").get_to(pBuf.uniqueId); recMsg.at("bus").get_to(pBuf.bus); recMsg.at("vendor").get_to(pBuf.vendor); diff --git a/services/source/inputinject/src/virtual_device.cpp b/services/source/inputinject/src/virtual_device.cpp index 44df5e8..58a064b 100644 --- a/services/source/inputinject/src/virtual_device.cpp +++ b/services/source/inputinject/src/virtual_device.cpp @@ -103,6 +103,9 @@ bool VirtualDevice::SetUp(const std::string& devId, const std::string& dhId) } deviceName_ = VIRTUAL_DEVICE_NAME + deviceName_; + if (deviceName_.size() > MAX_SIZE_OF_DEVICE_NAME) { + deviceName_ = deviceName_.substr(0, MAX_SIZE_OF_DEVICE_NAME); + } if (strncpy_s(dev_.name, sizeof(dev_.name), deviceName_.c_str(), deviceName_.size()) != 0) { return false; } diff --git a/services/source/inputinject/test/sourceinjectunittest/distributed_input_sourceinject_test.cpp b/services/source/inputinject/test/sourceinjectunittest/distributed_input_sourceinject_test.cpp index ddba008..c20e8e1 100644 --- a/services/source/inputinject/test/sourceinjectunittest/distributed_input_sourceinject_test.cpp +++ b/services/source/inputinject/test/sourceinjectunittest/distributed_input_sourceinject_test.cpp @@ -59,7 +59,7 @@ HWTEST_F(DistributedInputSourceInjectTest, RegisterDistributedHardware01, testin pBuffer.vendor = 0x1234; pBuffer.product = 0xfedc; pBuffer.version = 1; - pBuffer.location = "usb-hiusb-ehci-2.1/input1"; + pBuffer.physicalPath = "usb-hiusb-ehci-2.1/input1"; pBuffer.uniqueId = "1"; pBuffer.classes = INPUT_DEVICE_CLASS_KEYBOARD; pBuffer.descriptor = "afv4s8b1dr1b8er1bd65fb16redb1dfb18d1b56df1b68d"; @@ -80,7 +80,7 @@ HWTEST_F(DistributedInputSourceInjectTest, RegisterDistributedHardware02, testin pBuffer.vendor = 0x1222; pBuffer.product = 0xfeda; pBuffer.version = 2; - pBuffer.location = "usb-hiusb-ehci-2.1/input1"; + pBuffer.physicalPath = "usb-hiusb-ehci-2.1/input1"; pBuffer.uniqueId = "2"; pBuffer.classes = INPUT_DEVICE_CLASS_CURSOR; pBuffer.descriptor = "rt12r1nr81n521be8rb1erbe1w8bg1erb18"; @@ -101,7 +101,7 @@ HWTEST_F(DistributedInputSourceInjectTest, RegisterDistributedHardware03, testin pBuffer.vendor = 0x1233; pBuffer.product = 0xfedb; pBuffer.version = 3; - pBuffer.location = "usb-hiusb-ehci-2.1/input1"; + pBuffer.physicalPath = "usb-hiusb-ehci-2.1/input1"; pBuffer.uniqueId = "3"; pBuffer.classes = INPUT_DEVICE_CLASS_TOUCH; pBuffer.descriptor = "1ds56v18e1v21v8v1erv15r1v8r1j1ty8"; diff --git a/services/source/sourcemanager/test/sourcemanagerunittest/distributed_input_sourcemanager_test.cpp b/services/source/sourcemanager/test/sourcemanagerunittest/distributed_input_sourcemanager_test.cpp index c8ded3e..42fb609 100644 --- a/services/source/sourcemanager/test/sourcemanagerunittest/distributed_input_sourcemanager_test.cpp +++ b/services/source/sourcemanager/test/sourcemanagerunittest/distributed_input_sourcemanager_test.cpp @@ -169,7 +169,7 @@ int32_t DistributedInputSourceManagerTest::StructTransJson(const InputDevice& pB { nlohmann::json tmpJson; tmpJson["name"] = pBuf.name; - tmpJson["location"] = pBuf.location; + tmpJson["physicalPath"] = pBuf.physicalPath; tmpJson["uniqueId"] = pBuf.uniqueId; tmpJson["bus"] = pBuf.bus; tmpJson["vendor"] = pBuf.vendor; @@ -198,7 +198,7 @@ HWTEST_F(DistributedInputSourceManagerTest, RegisterDistributedHardware01, testi pBuffer.vendor = 0x1233; pBuffer.product = 0xfedb; pBuffer.version = 3; - pBuffer.location = "usb-hiusb-ehci-2.1/input1"; + pBuffer.physicalPath = "usb-hiusb-ehci-2.1/input1"; pBuffer.uniqueId = "3"; pBuffer.classes = INPUT_DEVICE_CLASS_TOUCH; pBuffer.descriptor = "1ds56v18e1v21v8v1erv15r1v8r1j1ty8"; @@ -222,7 +222,7 @@ HWTEST_F(DistributedInputSourceManagerTest, RegisterDistributedHardware02, testi pBuffer.vendor = 0x1222; pBuffer.product = 0xfeda; pBuffer.version = 2; - pBuffer.location = "usb-hiusb-ehci-2.1/input1"; + pBuffer.physicalPath = "usb-hiusb-ehci-2.1/input1"; pBuffer.uniqueId = "2"; pBuffer.classes = INPUT_DEVICE_CLASS_CURSOR; pBuffer.descriptor = "rt12r1nr81n521be8rb1erbe1w8bg1erb18"; @@ -244,7 +244,7 @@ HWTEST_F(DistributedInputSourceManagerTest, RegisterDistributedHardware03, testi pBuffer.vendor = 0x1234; pBuffer.product = 0xfedc; pBuffer.version = 1; - pBuffer.location = "usb-hiusb-ehci-2.1/input1"; + pBuffer.physicalPath = "usb-hiusb-ehci-2.1/input1"; pBuffer.uniqueId = "1"; pBuffer.classes = INPUT_DEVICE_CLASS_KEYBOARD; pBuffer.descriptor = "afv4s8b1dr1b8er1bd65fb16redb1dfb18d1b56df1b68d"; diff --git a/utils/src/dinput_utils_tool.cpp b/utils/src/dinput_utils_tool.cpp index 9e3ee2b..8850b89 100644 --- a/utils/src/dinput_utils_tool.cpp +++ b/utils/src/dinput_utils_tool.cpp @@ -129,16 +129,17 @@ std::string GetNodeDesc(std::string parameters) { nlohmann::json parObj = nlohmann::json::parse(parameters); std::string nodeName = "N/A"; - std::string location = "N/A"; + std::string physicalPath = "N/A"; int32_t classes = -1; - if (parObj.find("name") != parObj.end() && parObj.find("location") != parObj.end() && + if (parObj.find("name") != parObj.end() && parObj.find("physicalPath") != parObj.end() && parObj.find("classes") != parObj.end()) { nodeName = parObj.at("name").get(); - location = parObj.at("location").get(); + physicalPath = parObj.at("physicalPath").get(); classes = parObj.at("classes").get(); } - return "{ nodeName: " + nodeName + ", location: " + location + ", classes: " + std::to_string(classes) + " }"; + return "{ nodeName: " + nodeName + ", physicalPath: " + physicalPath + ", classes: " + + std::to_string(classes) + " }"; } } // namespace DistributedInput } // namespace DistributedHardware