mirror of
https://github.com/openharmony/distributedhardware_distributed_input.git
synced 2026-07-19 17:43:35 -04:00
Description:fix reboot and start touchpad, have no effort
Match-id-eacacd620c09a37e56a0579f4632f6ee6ecb2a77
This commit is contained in:
@@ -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;
|
||||
};
|
||||
|
||||
|
||||
@@ -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> 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)
|
||||
|
||||
@@ -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> 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;
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
-3
@@ -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";
|
||||
|
||||
|
||||
-4
@@ -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";
|
||||
|
||||
|
||||
Reference in New Issue
Block a user