Signed-off-by: hwzhangchuang <zhangchuang.zhang@huawei.com>
This commit is contained in:
hwzhangchuang
2023-12-02 11:11:51 +08:00
parent f855936bd6
commit becdd9273b
7 changed files with 41 additions and 78 deletions
+6
View File
@@ -136,6 +136,12 @@ namespace DistributedInput {
const std::string DINPUT_SPLIT_COMMA = ", ";
const char VIR_NODE_SPLIT = '|';
const char VIR_NODE_PID_SPLIT = '/';
const uint32_t VIR_NODE_PHY_LEN = 3;
const uint32_t VIR_NODE_PHY_DEVID_IDX = 1;
const uint32_t VIR_NODE_PHY_DHID_IDX = 2;
const std::string SOURCE_DEVICE_ID = "sourceDevId";
const std::string SINK_DEVICE_ID = "sinkDevId";
@@ -53,7 +53,6 @@ private:
DistributedInputHandler();
~DistributedInputHandler();
void StructTransJson(const InputDevice &pBuf, std::string &strDescriptor);
int32_t GetDeviceInfo(std::string &deviceId);
std::shared_ptr<PluginListener> m_listener;
bool InitCollectEventsThread();
void NotifyHardWare(int iCnt);
@@ -62,7 +61,7 @@ private:
bool isCollectingEvents_;
bool isStartCollectEventThread;
static void *CollectEventsThread(void *param);
void StartInputMonitorDeviceThread(const std::string deviceId);
void StartInputMonitorDeviceThread();
void StopInputMonitorDeviceThread();
// The event queue.
@@ -149,21 +149,6 @@ void DistributedInputHandler::UnRegisterPluginListener()
this->m_listener = nullptr;
}
int32_t DistributedInputHandler::GetDeviceInfo(std::string &deviceId)
{
std::unique_lock<std::mutex> my_lock(operationMutex_);
auto localNode = std::make_unique<NodeBasicInfo>();
int32_t retCode = GetLocalNodeDeviceInfo("ohos.dhardware", localNode.get());
if (retCode != 0) {
DHLOGE("Could not get device id.");
return ERR_DH_INPUT_HANDLER_GET_DEVICE_ID_FAIL;
}
deviceId = localNode->networkId;
DHLOGI("device id is %s", GetAnonyString(deviceId).c_str());
return DH_SUCCESS;
}
bool DistributedInputHandler::InitCollectEventsThread()
{
pthread_attr_t attr;
@@ -190,15 +175,12 @@ void *DistributedInputHandler::CollectEventsThread(void *param)
DHLOGE("CollectEventsThread setname failed.");
}
DistributedInputHandler *pThis = reinterpret_cast<DistributedInputHandler *>(param);
std::string deviceId;
pThis->GetDeviceInfo(deviceId);
pThis->StartInputMonitorDeviceThread(deviceId);
pThis->StartInputMonitorDeviceThread();
DHLOGI("DistributedInputHandler::CollectEventsThread exist!");
return nullptr;
}
void DistributedInputHandler::StartInputMonitorDeviceThread(const std::string deviceId)
void DistributedInputHandler::StartInputMonitorDeviceThread()
{
if (inputHub_ == nullptr) {
DHLOGE("inputHub_ not initialized");
@@ -67,7 +67,6 @@ public:
int32_t RemoveVirtualTouchScreenNode(const std::string &devId, const std::string &dhId);
int32_t GetVirtualTouchScreenFd();
int32_t GetDeviceInfo(std::string &devId);
void ProcessInjectEvent(const EventBatch &events);
/**
@@ -154,7 +154,7 @@ void DistributedInputNodeManager::ParseInputDeviceEvents(const nlohmann::json &i
void DistributedInputNodeManager::ScanSinkInputDevices(const std::string &devId, const std::string &dhId)
{
DHLOGI("ScanSinkInputDevices enter, deviceId:%s, dhId %s.",
DHLOGI("ScanSinkInputDevices enter, deviceId: %s, dhId: %s.",
GetAnonyString(devId).c_str(), GetAnonyString(dhId).c_str());
std::vector<std::string> vecInputDevPath;
ScanInputDevicesPath(DEVICE_PATH, vecInputDevPath);
@@ -250,13 +250,13 @@ bool DistributedInputNodeManager::GetDevDhUniqueIdByFd(int fd, DhUniqueID &dhUnq
DHLOGD("GetDevDhUniqueIdByFd physicalPath %s.", physicalPath.c_str());
std::vector<std::string> phyPathVec;
SplitStringToVector(physicalPath, '|', phyPathVec);
if (phyPathVec.size() != 3) {
SplitStringToVector(physicalPath, VIR_NODE_SPLIT, phyPathVec);
if (phyPathVec.size() != VIR_NODE_PHY_LEN) {
DHLOGE("The physical path is invalid");
return false;
}
std::string devId = phyPathVec[1];
std::string dhId = phyPathVec[2];
std::string devId = phyPathVec[VIR_NODE_PHY_DEVID_IDX];
std::string dhId = phyPathVec[VIR_NODE_PHY_DHID_IDX];
if (devId.empty() || dhId.empty()) {
DHLOGE("Get dev deviceid and dhid failed.");
return false;
@@ -272,7 +272,7 @@ void DistributedInputNodeManager::SetPathForVirDev(const DhUniqueID &dhUniqueId,
std::lock_guard<std::mutex> lock(virtualDeviceMapMutex_);
auto iter = virtualDeviceMap_.begin();
while (iter != virtualDeviceMap_.end()) {
DHLOGD("Check Virtual device deviceId %s, dhid %s.", iter->first.first.c_str(), iter->first.second.c_str());
DHLOGD("Check Virtual device, deviceId %s, dhid %s.", iter->first.first.c_str(), iter->first.second.c_str());
if (iter->first == dhUniqueId) {
DHLOGD("Found the virtual device, set path :%s", devicePath.c_str());
iter->second->SetPath(devicePath);
@@ -304,7 +304,7 @@ bool DistributedInputNodeManager::MatchAndSavePhysicalPath(const std::string &de
return false;
}
DHLOGD("This opening node deviceId: %s, dhId %s, to match node deviceId: %s, dhId: %s",
DHLOGD("This opening node deviceId: %s, dhId: %s, to match node deviceId: %s, dhId: %s",
GetAnonyString(curDhUniqueId.first).c_str(), GetAnonyString(curDhUniqueId.second).c_str(),
GetAnonyString(devId).c_str(), GetAnonyString(dhId).c_str());
@@ -536,21 +536,6 @@ void DistributedInputNodeManager::ProcessInjectEvent(const EventBatch &events)
}
}
}
int32_t DistributedInputNodeManager::GetDeviceInfo(std::string &devId)
{
std::unique_lock<std::mutex> my_lock(operationMutex_);
auto localNode = std::make_unique<NodeBasicInfo>();
int32_t retCode = GetLocalNodeDeviceInfo(DINPUT_PKG_NAME.c_str(), localNode.get());
if (retCode != 0) {
DHLOGE("Could not get device id.");
return ERR_DH_INPUT_HANDLER_GET_DEVICE_ID_FAIL;
}
devId = localNode->networkId;
DHLOGI("device id is %s", GetAnonyString(devId).c_str());
return DH_SUCCESS;
}
} // namespace DistributedInput
} // namespace DistributedHardware
} // namespace OHOS
@@ -110,8 +110,8 @@ void VirtualDevice::SetABSInfo(struct uinput_user_dev &inputUserDev, const Input
bool VirtualDevice::SetPhys(const std::string &deviceName, const std::string &dhId)
{
std::string phys;
phys.append(deviceName).append(pid_).append("/").append(pid_).append("|")
.append(netWorkId_).append("|").append(dhId);
phys.append(deviceName).append(pid_).append(VIR_NODE_PID_SPLIT).append(pid_).append(VIR_NODE_SPLIT)
.append(netWorkId_).append(VIR_NODE_SPLIT).append(dhId);
if (ioctl(fd_, UI_SET_PHYS, phys.c_str()) < 0) {
return false;
@@ -162,38 +162,38 @@ HWTEST_F(DistributedInputSourceInjectTest, RegisterDistributedEvent01, testing::
{
RawEvent event1 = {
.when = 0,
.type = EV_KEy,
.type = EV_KEY,
.code = KEY_D,
.value = 1,
.descriptor = "afv4s8b1dr1b8er1bd65fb16redb1dfb18d1b56df1b68d";
.descriptor = "afv4s8b1dr1b8er1bd65fb16redb1dfb18d1b56df1b68d"
};
RawEvent event2 = {
.when = 1,
.type = EV_KEy,
.type = EV_KEY,
.code = KEY_D,
.value = 0,
.descriptor = "afv4s8b1dr1b8er1bd65fb16redb1dfb18d1b56df1b68d";
.descriptor = "afv4s8b1dr1b8er1bd65fb16redb1dfb18d1b56df1b68d"
};
RawEvent event3 = {
.when = 2,
.type = EV_KEy,
.type = EV_KEY,
.code = KEY_D,
.value = 1,
.descriptor = "afv4s8b1dr1b8er1bd65fb16redb1dfb18d1b56df1b68d";
.descriptor = "afv4s8b1dr1b8er1bd65fb16redb1dfb18d1b56df1b68d"
};
RawEvent event4 = {
.when = 3,
.type = EV_KEy,
.type = EV_KEY,
.code = KEY_D,
.value = 0,
.descriptor = "afv4s8b1dr1b8er1bd65fb16redb1dfb18d1b56df1b68d";
.descriptor = "afv4s8b1dr1b8er1bd65fb16redb1dfb18d1b56df1b68d"
};
std::vector<RawEvent> writeBuffer = { event1, event2, event3, event4 };
DistributedInputInject::GetInstance().inputNodeManager_ = std::make_unique<DistributedInputNodeManager>();
DistributedInputInject::GetInstance().StartInjectThread();
DistributedInputInject::GetInstance().StopInjectThread();
std::string deviceId = "deviceId123";
std::string deviceId = "aefbg1nr81n521be8rb1erbe1w8bg1erb18";
int32_t ret = DistributedInputInject::GetInstance().RegisterDistributedEvent(deviceId, writeBuffer);
EXPECT_EQ(DH_SUCCESS, ret);
}
@@ -205,38 +205,38 @@ HWTEST_F(DistributedInputSourceInjectTest, RegisterDistributedEvent02, testing::
.type = EV_REL,
.code = REL_X,
.value = 2,
.descriptor = "rt12r1nr81n521be8rb1erbe1w8bg1erb18";
.descriptor = "rt12r1nr81n521be8rb1erbe1w8bg1erb18"
};
RawEvent event2 = {
.when = 1,
.type = EV_REL,
.code = REL_Y,
.value = 2,
.descriptor = "rt12r1nr81n521be8rb1erbe1w8bg1erb18";
.descriptor = "rt12r1nr81n521be8rb1erbe1w8bg1erb18"
};
RawEvent event3 = {
.when = 2,
.type = EV_REL,
.code = REL_X,
.value = 3,
.descriptor = "rt12r1nr81n521be8rb1erbe1w8bg1erb18";
.descriptor = "rt12r1nr81n521be8rb1erbe1w8bg1erb18"
};
RawEvent event4 = {
.when = 3,
.type = EV_REL,
.code = REL_Y,
.value = 3,
.descriptor = "rt12r1nr81n521be8rb1erbe1w8bg1erb18";
.descriptor = "rt12r1nr81n521be8rb1erbe1w8bg1erb18"
};
RawEvent event5 = {
.when = 4,
.type = EV_SYN,
.code = SYN_REPORT,
.value = 0,
.descriptor = "rt12r1nr81n521be8rb1erbe1w8bg1erb18";
.descriptor = "rt12r1nr81n521be8rb1erbe1w8bg1erb18"
};
std::vector<RawEvent> writeBuffer = { event1, event2, event3, event4, event5};
std::string deviceId = "deviceId123";
std::vector<RawEvent> writeBuffer = { event1, event2, event3, event4, event5 };
std::string deviceId = "aefbg1nr81n521be8rb1erbe1w8bg1erb18";
int32_t ret = DistributedInputInject::GetInstance().RegisterDistributedEvent(deviceId, writeBuffer);
EXPECT_EQ(DH_SUCCESS, ret);
}
@@ -248,39 +248,39 @@ HWTEST_F(DistributedInputSourceInjectTest, RegisterDistributedEvent03, testing::
.type = EV_ABS,
.code = ABS_X,
.value = 1,
.descriptor = "1ds56v18e1v21v8v1erv15r1v8r1j1ty8";
.descriptor = "1ds56v18e1v21v8v1erv15r1v8r1j1ty8"
};
RawEvent event2 = {
.when = 1,
.type = EV_ABS,
.code = ABS_X,
.value = 2,
.descriptor = "1ds56v18e1v21v8v1erv15r1v8r1j1ty8";
.descriptor = "1ds56v18e1v21v8v1erv15r1v8r1j1ty8"
};
RawEvent event3 = {
.when = 2,
.type = EV_ABS,
.code = ABS_X,
.value = 3,
.descriptor = "1ds56v18e1v21v8v1erv15r1v8r1j1ty8";
.descriptor = "1ds56v18e1v21v8v1erv15r1v8r1j1ty8"
};
RawEvent event4 = {
.when = 3,
.type = EV_ABS,
.code = ABS_X,
.value = 4,
.descriptor = "1ds56v18e1v21v8v1erv15r1v8r1j1ty8";
.descriptor = "1ds56v18e1v21v8v1erv15r1v8r1j1ty8"
};
std::vector<RawEvent> writeBuffer = { event1, event2, event3, event4 };
std::string deviceId = "deviceId123";
std::string deviceId = "aefbg1nr81n521be8rb1erbe1w8bg1erb18";
int32_t ret = DistributedInputInject::GetInstance().RegisterDistributedEvent(deviceId, writeBuffer);
EXPECT_EQ(DH_SUCCESS, ret);
}
HWTEST_F(DistributedInputSourceInjectTest, RegisterDistributedEvent04, testing::ext::TestSize.Level1)
{
std::string deviceId = "deviceId123";
struct RawEvent writeBuffer[4];
std::string deviceId = "aefbg1nr81n521be8rb1erbe1w8bg1erb18";
std::vector<RawEvent> writeBuffer(4);
DistributedInputInject::GetInstance().inputNodeManager_ = nullptr;
int32_t ret = DistributedInputInject::GetInstance().RegisterDistributedEvent(deviceId, writeBuffer);
EXPECT_EQ(ERR_DH_INPUT_SERVER_SOURCE_INJECT_NODE_MANAGER_IS_NULL, ret);
@@ -405,14 +405,6 @@ HWTEST_F(DistributedInputSourceInjectTest, OpenDevicesNode_002, testing::ext::Te
ret = DistributedInputInject::GetInstance().inputNodeManager_->OpenDevicesNode(devId, dhIdtest, param);
EXPECT_EQ(ERR_DH_INPUT_SERVER_SOURCE_OPEN_DEVICE_NODE_FAIL, ret);
}
HWTEST_F(DistributedInputSourceInjectTest, GetDeviceInfo_001, testing::ext::TestSize.Level1)
{
std::string deviceId = "";
DistributedInputInject::GetInstance().inputNodeManager_->InjectEvent();
int32_t ret = DistributedInputInject::GetInstance().inputNodeManager_->GetDeviceInfo(deviceId);
EXPECT_EQ(DH_SUCCESS, ret);
}
} // namespace DistributedInput
} // namespace DistributedHardware
} // namespace OHOS