diff --git a/common/include/constants_dinput.h b/common/include/constants_dinput.h index 53f4bcd..67a7a33 100644 --- a/common/include/constants_dinput.h +++ b/common/include/constants_dinput.h @@ -163,7 +163,7 @@ namespace DistributedInput { */ struct InputDevice { inline InputDevice() : name(""), location(""), uniqueId(""), bus(0), vendor(0), product(0), - version(0), descriptor(""), nonce(0), classes(0) {} + version(0), descriptor(""), classes(0) {} std::string name; std::string location; std::string uniqueId; @@ -172,7 +172,6 @@ namespace DistributedInput { uint16_t product; uint16_t version; std::string descriptor; - uint16_t nonce; uint32_t classes; }; diff --git a/common/include/input_hub.cpp b/common/include/input_hub.cpp index 3d33cf5..36858ff 100644 --- a/common/include/input_hub.cpp +++ b/common/include/input_hub.cpp @@ -447,7 +447,7 @@ int32_t InputHub::OpenInputDeviceLocked(const std::string& devicePath) if (QueryInputDeviceInfo(fd, identifier) < 0) { return ERR_DH_INPUT_HUB_QUERY_INPUT_DEVICE_INFO_FAIL; } - AssignDescriptorLocked(identifier); + GenerateDescriptor(identifier); // Allocate device. (The device object takes ownership of the fd at this point.) int32_t deviceId = nextDeviceId_++; @@ -564,23 +564,6 @@ int32_t InputHub::MakeDevice(int fd, std::unique_ptr device) return DH_SUCCESS; } -void InputHub::AssignDescriptorLocked(InputDevice& identifier) -{ - identifier.nonce = 0; - std::string rawDescriptor = GenerateDescriptor(identifier); - if (identifier.uniqueId.empty()) { - // If it didn't have a unique id check for conflicts and enforce - // uniqueness if necessary. - while (GetDeviceByDescriptorLocked(identifier.descriptor) != nullptr) { - identifier.nonce++; - rawDescriptor = GenerateDescriptor(identifier); - } - } - DHLOGI( - "Created descriptor: raw=%s, cooked=%s", rawDescriptor.c_str(), - identifier.descriptor.c_str()); -} - std::string InputHub::StringPrintf(const char* format, ...) const { static const int kSpaceLength = 1024; @@ -614,7 +597,7 @@ std::string InputHub::Sha256(const std::string& in) const return out; } -std::string InputHub::GenerateDescriptor(InputDevice& identifier) const +void InputHub::GenerateDescriptor(InputDevice& identifier) const { std::string rawDescriptor; rawDescriptor += StringPrintf(":%04x:%04x:", identifier.vendor, @@ -623,25 +606,23 @@ std::string InputHub::GenerateDescriptor(InputDevice& identifier) const if (!identifier.uniqueId.empty()) { rawDescriptor += "uniqueId:"; rawDescriptor += identifier.uniqueId; - } else if (identifier.nonce != 0) { - rawDescriptor += StringPrintf("nonce:%04x", identifier.nonce); + } else if (!identifier.location.empty()) { + rawDescriptor += "location:"; + rawDescriptor += identifier.location; } if (identifier.vendor == 0 && identifier.product == 0) { // If we don't know the vendor and product id, then the device is probably // built-in so we need to rely on other information to uniquely identify - // the input device. Usually we try to avoid relying on the device name or - // location but for built-in input device, they are unlikely to ever change. + // the input device. Usually we try to avoid relying on the device name + // but for built-in input device, they are unlikely to ever change. if (!identifier.name.empty()) { rawDescriptor += "name:"; rawDescriptor += identifier.name; - } else if (!identifier.location.empty()) { - rawDescriptor += "location:"; - rawDescriptor += identifier.location; } } identifier.descriptor = DH_ID_PREFIX + Sha256(rawDescriptor); - return rawDescriptor; + DHLOGI("Created descriptor: raw=%s, cooked=%s", rawDescriptor.c_str(), identifier.descriptor.c_str()); } int32_t InputHub::RegisterDeviceForEpollLocked(const Device& device) diff --git a/common/include/input_hub.h b/common/include/input_hub.h index be08d1f..ff4ff8f 100644 --- a/common/include/input_hub.h +++ b/common/include/input_hub.h @@ -76,8 +76,7 @@ private: int32_t OpenInputDeviceLocked(const std::string& devicePath); int32_t QueryInputDeviceInfo(int fd, InputDevice& identifier); int32_t MakeDevice(int fd, std::unique_ptr device); - void AssignDescriptorLocked(InputDevice& identifier); - std::string GenerateDescriptor(InputDevice& identifier) const; + void GenerateDescriptor(InputDevice& identifier) const; std::string StringPrintf(const char* format, ...) const; std::string Sha256(const std::string& in) const; diff --git a/inputdevicehandler/src/distributed_input_handler.cpp b/inputdevicehandler/src/distributed_input_handler.cpp index b62781a..d7068b8 100644 --- a/inputdevicehandler/src/distributed_input_handler.cpp +++ b/inputdevicehandler/src/distributed_input_handler.cpp @@ -65,7 +65,6 @@ void DistributedInputHandler::StructTransJson(const InputDevice& pBuf, std::stri tmpJson["product"] = pBuf.product; tmpJson["version"] = pBuf.version; tmpJson["descriptor"] = pBuf.descriptor; - tmpJson["nonce"] = pBuf.nonce; tmpJson["classes"] = pBuf.classes; std::ostringstream stream; diff --git a/services/source/inputinject/src/distributed_input_inject.cpp b/services/source/inputinject/src/distributed_input_inject.cpp index 3c52ce1..9cbb3ae 100644 --- a/services/source/inputinject/src/distributed_input_inject.cpp +++ b/services/source/inputinject/src/distributed_input_inject.cpp @@ -88,7 +88,6 @@ int32_t DistributedInputInject::StructTransJson(const InputDevice& pBuf, std::st tmpJson["product"] = pBuf.product; tmpJson["version"] = pBuf.version; tmpJson["descriptor"] = pBuf.descriptor; - tmpJson["nonce"] = pBuf.nonce; tmpJson["classes"] = pBuf.classes; std::ostringstream stream; diff --git a/services/source/inputinject/src/distributed_input_node_manager.cpp b/services/source/inputinject/src/distributed_input_node_manager.cpp index 53fca1a..db1368e 100644 --- a/services/source/inputinject/src/distributed_input_node_manager.cpp +++ b/services/source/inputinject/src/distributed_input_node_manager.cpp @@ -74,7 +74,6 @@ void DistributedInputNodeManager::stringTransJsonTransStruct(const std::string& recMsg.at("product").get_to(pBuf.product); recMsg.at("version").get_to(pBuf.version); recMsg.at("descriptor").get_to(pBuf.descriptor); - recMsg.at("nonce").get_to(pBuf.nonce); recMsg.at("classes").get_to(pBuf.classes); } 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 68d1a1a..25b1153 100644 --- a/services/source/inputinject/test/sourceinjectunittest/distributed_input_sourceinject_test.cpp +++ b/services/source/inputinject/test/sourceinjectunittest/distributed_input_sourceinject_test.cpp @@ -60,7 +60,6 @@ HWTEST_F(DistributedInputSourceInjectTest, RegisterDistributedHardware01, testin pBuffer.version = 1; pBuffer.location = "usb-hiusb-ehci-2.1/input1"; pBuffer.uniqueId = "1"; - pBuffer.nonce = 0; pBuffer.classes = INPUT_DEVICE_CLASS_KEYBOARD; pBuffer.descriptor = "afv4s8b1dr1b8er1bd65fb16redb1dfb18d1b56df1b68d"; @@ -82,7 +81,6 @@ HWTEST_F(DistributedInputSourceInjectTest, RegisterDistributedHardware02, testin pBuffer.version = 2; pBuffer.location = "usb-hiusb-ehci-2.1/input1"; pBuffer.uniqueId = "2"; - pBuffer.nonce = 0; pBuffer.classes = INPUT_DEVICE_CLASS_CURSOR; pBuffer.descriptor = "rt12r1nr81n521be8rb1erbe1w8bg1erb18"; @@ -104,7 +102,6 @@ HWTEST_F(DistributedInputSourceInjectTest, RegisterDistributedHardware03, testin pBuffer.version = 3; pBuffer.location = "usb-hiusb-ehci-2.1/input1"; pBuffer.uniqueId = "3"; - pBuffer.nonce = 0; 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 cf2229b..c78f1b0 100644 --- a/services/source/sourcemanager/test/sourcemanagerunittest/distributed_input_sourcemanager_test.cpp +++ b/services/source/sourcemanager/test/sourcemanagerunittest/distributed_input_sourcemanager_test.cpp @@ -131,7 +131,6 @@ int32_t DistributedInputSourceManagerTest::StructTransJson(const InputDevice& pB tmpJson["product"] = pBuf.product; tmpJson["version"] = pBuf.version; tmpJson["descriptor"] = pBuf.descriptor; - tmpJson["nonce"] = pBuf.nonce; tmpJson["classes"] = pBuf.classes; std::ostringstream stream; @@ -156,7 +155,6 @@ HWTEST_F(DistributedInputSourceManagerTest, RegisterDistributedHardware01, testi pBuffer.version = 3; pBuffer.location = "usb-hiusb-ehci-2.1/input1"; pBuffer.uniqueId = "3"; - pBuffer.nonce = 0; pBuffer.classes = INPUT_DEVICE_CLASS_TOUCH; pBuffer.descriptor = "1ds56v18e1v21v8v1erv15r1v8r1j1ty8"; @@ -181,7 +179,6 @@ HWTEST_F(DistributedInputSourceManagerTest, RegisterDistributedHardware02, testi pBuffer.version = 2; pBuffer.location = "usb-hiusb-ehci-2.1/input1"; pBuffer.uniqueId = "2"; - pBuffer.nonce = 0; pBuffer.classes = INPUT_DEVICE_CLASS_CURSOR; pBuffer.descriptor = "rt12r1nr81n521be8rb1erbe1w8bg1erb18"; @@ -204,7 +201,6 @@ HWTEST_F(DistributedInputSourceManagerTest, RegisterDistributedHardware03, testi pBuffer.version = 1; pBuffer.location = "usb-hiusb-ehci-2.1/input1"; pBuffer.uniqueId = "1"; - pBuffer.nonce = 0; pBuffer.classes = INPUT_DEVICE_CLASS_KEYBOARD; pBuffer.descriptor = "afv4s8b1dr1b8er1bd65fb16redb1dfb18d1b56df1b68d";