mirror of
https://github.com/openharmony/distributedhardware_distributed_input.git
synced 2026-07-20 01:53:34 -04:00
Description:fix pageDown bug
Match-id-42e70cfa912355c240ea2c739be74ae8d7d7c1b3
This commit is contained in:
@@ -1016,7 +1016,7 @@ void InputHub::GetShareMousePathByDhId(std::vector<std::string> dhIds, std::stri
|
||||
}
|
||||
}
|
||||
|
||||
void InputHub::GetDevicesInfoByType(int32_t inputTypes, std::map<int32_t, std::string> &datas)
|
||||
void InputHub::GetDevicesInfoByType(const uint32_t inputTypes, std::map<int32_t, std::string> &datas)
|
||||
{
|
||||
uint32_t input_types_ = 0;
|
||||
|
||||
|
||||
@@ -51,7 +51,7 @@ public:
|
||||
// return efftive dhids
|
||||
AffectDhIds SetSharingDevices(bool enabled, std::vector<std::string> dhIds);
|
||||
void GetDeviceDhIdByFd(int32_t fd, std::string &dhId);
|
||||
void GetDevicesInfoByType(int32_t inputTypes, std::map<int32_t, std::string> &datas);
|
||||
void GetDevicesInfoByType(const uint32_t inputTypes, std::map<int32_t, std::string> &datas);
|
||||
void GetDevicesInfoByDhId(std::vector<std::string> dhidsVec, std::map<int32_t, std::string> &datas);
|
||||
void GetShareMousePathByDhId(std::vector<std::string> dhIds, std::string &path, std::string &dhId);
|
||||
bool IsAllDevicesStoped();
|
||||
|
||||
@@ -47,7 +47,7 @@ public:
|
||||
API_EXPORT virtual void RegisterPluginListener(std::shared_ptr<PluginListener> listener) override;
|
||||
API_EXPORT virtual void UnRegisterPluginListener() override;
|
||||
|
||||
API_EXPORT void FindDevicesInfoByType(int32_t inputTypes, std::map<int32_t, std::string> &datas);
|
||||
API_EXPORT void FindDevicesInfoByType(const uint32_t inputTypes, std::map<int32_t, std::string> &datas);
|
||||
API_EXPORT void FindDevicesInfoByDhId(std::vector<std::string> dhidsVec, std::map<int32_t, std::string> &datas);
|
||||
private:
|
||||
DistributedInputHandler();
|
||||
|
||||
@@ -82,7 +82,7 @@ int32_t DistributedInputHandler::Initialize()
|
||||
return DH_SUCCESS;
|
||||
}
|
||||
|
||||
void DistributedInputHandler::FindDevicesInfoByType(int32_t inputTypes, std::map<int32_t, std::string> &datas)
|
||||
void DistributedInputHandler::FindDevicesInfoByType(const uint32_t inputTypes, std::map<int32_t, std::string> &datas)
|
||||
{
|
||||
if (inputHub_ != nullptr) {
|
||||
inputHub_->GetDevicesInfoByType(inputTypes, datas);
|
||||
|
||||
@@ -47,6 +47,7 @@ public:
|
||||
bool IsAllDevicesStoped();
|
||||
int32_t RegisterSharingDhIdListener(sptr<ISharingDhIdListener> sharingDhIdListener);
|
||||
void ReportDhIdSharingState(const AffectDhIds &dhIds);
|
||||
void GetDeviceInfoByType(const uint32_t inputTypes, std::map<int32_t, std::string>& deviceInfo);
|
||||
|
||||
private:
|
||||
DistributedInputCollector();
|
||||
|
||||
@@ -97,6 +97,10 @@ void DistributedInputCollector::StartCollectEventsThread()
|
||||
{
|
||||
while (isCollectingEvents_) {
|
||||
memset_s(&mEventBuffer, sizeof(mEventBuffer), 0, sizeof(mEventBuffer));
|
||||
if (inputHub_ == nullptr) {
|
||||
DHLOGI("inputHub is nullptr!");
|
||||
return;
|
||||
}
|
||||
size_t count = inputHub_->StartCollectInputEvents(mEventBuffer, INPUT_EVENT_BUFFER_SIZE);
|
||||
if (count > 0) {
|
||||
DHLOGI("Count: %zu", count);
|
||||
@@ -131,6 +135,10 @@ void DistributedInputCollector::StopCollectEventsThread()
|
||||
{
|
||||
isCollectingEvents_ = false;
|
||||
isStartGetDeviceHandlerThread = false;
|
||||
if (inputHub_ == nullptr) {
|
||||
DHLOGI("inputHub is nullptr!");
|
||||
return;
|
||||
}
|
||||
inputHub_->StopCollectInputEvents();
|
||||
if (collectThreadID_ != (pthread_t)(-1)) {
|
||||
DHLOGI("DistributedInputCollector::Wait collect thread exit");
|
||||
@@ -193,11 +201,19 @@ AffectDhIds DistributedInputCollector::SetSharingDhIds(bool enabled, std::vector
|
||||
void DistributedInputCollector::GetMouseNodePath(
|
||||
std::vector<std::string> dhIds, std::string &mouseNodePath, std::string &dhid)
|
||||
{
|
||||
if (inputHub_ == nullptr) {
|
||||
DHLOGI("inputHub is nullptr!");
|
||||
return;
|
||||
}
|
||||
inputHub_->GetShareMousePathByDhId(dhIds, mouseNodePath, dhid);
|
||||
}
|
||||
|
||||
bool DistributedInputCollector::IsAllDevicesStoped()
|
||||
{
|
||||
if (inputHub_ == nullptr) {
|
||||
DHLOGI("inputHub is nullptr!");
|
||||
return false;
|
||||
}
|
||||
return inputHub_->IsAllDevicesStoped();
|
||||
}
|
||||
|
||||
@@ -208,6 +224,16 @@ int32_t DistributedInputCollector::RegisterSharingDhIdListener(sptr<ISharingDhId
|
||||
sharingDhIdListeners_.insert(sharingDhIdListener);
|
||||
return DH_SUCCESS;
|
||||
}
|
||||
|
||||
void DistributedInputCollector::GetDeviceInfoByType(const uint32_t inputTypes, std::map<int32_t,
|
||||
std::string>& deviceInfo)
|
||||
{
|
||||
if (inputHub_ == nullptr) {
|
||||
DHLOGI("inputHub is nullptr!");
|
||||
return;
|
||||
}
|
||||
inputHub_->GetDevicesInfoByType(inputTypes, deviceInfo);
|
||||
}
|
||||
} // namespace DistributedInput
|
||||
} // namespace DistributedHardware
|
||||
} // namespace OHOS
|
||||
|
||||
@@ -161,6 +161,18 @@ void DistributedInputSinkManager::DInputSinkListener::onStartRemoteInput(
|
||||
sinkManagerObj_->StoreStartDhids(sessionId, affDhIds.sharingDhIds);
|
||||
DistributedInputCollector::GetInstance().ReportDhIdSharingState(affDhIds);
|
||||
}
|
||||
|
||||
bool isMouse = (sinkManagerObj_->GetInputTypes() & static_cast<uint32_t>(DInputDeviceType::MOUSE)) != 0;
|
||||
if (isMouse) {
|
||||
std::map<int32_t, std::string> deviceInfos;
|
||||
DistributedInputCollector::GetInstance().GetDeviceInfoByType(static_cast<uint32_t>(DInputDeviceType::MOUSE),
|
||||
deviceInfos);
|
||||
for (auto deviceInfo : deviceInfos) {
|
||||
DHLOGI("deviceInfo dhId, %s", GetAnonyString(deviceInfo.second).c_str());
|
||||
std::thread(&DistributedInputSinkManager::DInputSinkListener::CheckKeyState, this, sessionId,
|
||||
deviceInfo.second).detach();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void DistributedInputSinkManager::DInputSinkListener::onStopRemoteInput(
|
||||
@@ -221,7 +233,7 @@ void DistributedInputSinkManager::DInputSinkListener::onStartRemoteInputDhid(con
|
||||
DHLOGW("onStartRemoteInputDhid called, this is the only session.");
|
||||
}
|
||||
|
||||
CheckKeyState(sessionId, strDhids);
|
||||
std::thread(&DistributedInputSinkManager::DInputSinkListener::CheckKeyState, this, sessionId, strDhids).detach();
|
||||
// add the dhids
|
||||
if (startRes == DH_SUCCESS) {
|
||||
std::vector<std::string> vecStr;
|
||||
@@ -309,11 +321,12 @@ void DistributedInputSinkManager::DInputSinkListener::CheckKeyState(const int32_
|
||||
DHLOGE("open mouse Node Path error:", errno);
|
||||
return;
|
||||
}
|
||||
DHLOGI("mouse Node Path fd: %d", fd);
|
||||
|
||||
uint32_t count = 0;
|
||||
int rc = 0;
|
||||
int keyVal = 0;
|
||||
int leftKeyVal = 0;
|
||||
int rightKeyVal = 0;
|
||||
int midKeyVal = 0;
|
||||
unsigned long keystate[NLONGS(KEY_CNT)] = { 0 };
|
||||
while (true) {
|
||||
if (count > READ_RETRY_MAX) {
|
||||
@@ -323,25 +336,23 @@ void DistributedInputSinkManager::DInputSinkListener::CheckKeyState(const int32_
|
||||
rc = ioctl(fd, EVIOCGKEY(sizeof(keystate)), keystate);
|
||||
if (rc < 0) {
|
||||
DHLOGE("read all key state failed, rc: ", rc);
|
||||
count += 1;
|
||||
SleepTimeMs();
|
||||
continue;
|
||||
}
|
||||
|
||||
keyVal = bit_is_set(keystate, BTN_LEFT);
|
||||
if (keyVal != 0) {
|
||||
DHLOGI("mouse left button is down.");
|
||||
nlohmann::json jsonStr;
|
||||
jsonStr[DINPUT_SOFTBUS_KEY_CMD_TYPE] = TRANS_SINK_MSG_KEY_STATE;
|
||||
jsonStr[DINPUT_SOFTBUS_KEY_KEYSTATE_DHID] = dhid;
|
||||
jsonStr[DINPUT_SOFTBUS_KEY_KEYSTATE_TYPE] = EV_KEY;
|
||||
jsonStr[DINPUT_SOFTBUS_KEY_KEYSTATE_CODE] = BTN_LEFT;
|
||||
jsonStr[DINPUT_SOFTBUS_KEY_KEYSTATE_VALUE] = KEY_DOWN_STATE;
|
||||
std::string smsg = jsonStr.dump();
|
||||
DistributedInputSinkTransport::GetInstance().SendKeyStateNodeMsg(sessionId, smsg);
|
||||
break;
|
||||
leftKeyVal = bit_is_set(keystate, BTN_LEFT);
|
||||
if (leftKeyVal != 0) {
|
||||
DistributedInputSinkTransport::GetInstance().SendKeyStateNodeMsg(sessionId, dhid, BTN_LEFT);
|
||||
}
|
||||
SleepTimeMs();
|
||||
count += 1;
|
||||
rightKeyVal = bit_is_set(keystate, BTN_RIGHT);
|
||||
if (rightKeyVal != 0) {
|
||||
DistributedInputSinkTransport::GetInstance().SendKeyStateNodeMsg(sessionId, dhid, BTN_RIGHT);
|
||||
}
|
||||
midKeyVal = bit_is_set(keystate, BTN_MIDDLE);
|
||||
if (midKeyVal != 0) {
|
||||
DistributedInputSinkTransport::GetInstance().SendKeyStateNodeMsg(sessionId, dhid, BTN_MIDDLE);
|
||||
}
|
||||
break;
|
||||
}
|
||||
if (fd > 0) {
|
||||
close(fd);
|
||||
|
||||
@@ -46,7 +46,7 @@ public:
|
||||
int32_t RespStartRemoteInput(const int32_t sessionId, std::string &smsg);
|
||||
int32_t RespStopRemoteInput(const int32_t sessionId, std::string &smsg);
|
||||
int32_t RespLatency(const int32_t sessionId, std::string &smsg);
|
||||
void SendKeyStateNodeMsg(const int32_t sessionId, std::string &smsg);
|
||||
void SendKeyStateNodeMsg(const int32_t sessionId, const std::string& dhId, const uint32_t btnCode);
|
||||
|
||||
int32_t OnSessionOpened(int32_t sessionId, int32_t result);
|
||||
void OnSessionClosed(int32_t sessionId);
|
||||
|
||||
@@ -243,14 +243,22 @@ int32_t DistributedInputSinkTransport::RespLatency(const int32_t sessionId, std:
|
||||
return DH_SUCCESS;
|
||||
}
|
||||
|
||||
void DistributedInputSinkTransport::SendKeyStateNodeMsg(const int32_t sessionId, std::string &smsg)
|
||||
void DistributedInputSinkTransport::SendKeyStateNodeMsg(const int32_t sessionId, const std::string& dhId,
|
||||
const uint32_t btnCode)
|
||||
{
|
||||
if (sessionId <= 0) {
|
||||
DHLOGE("SendKeyStateNodeMsg error, sessionId <= 0.");
|
||||
return;
|
||||
}
|
||||
DHLOGI("SendKeyStateNodeMsg sessionId: %d, smsg:%s.", sessionId, smsg.c_str());
|
||||
int32_t ret = SendMessage(sessionId, smsg);
|
||||
DHLOGI("SendKeyStateNodeMsg sessionId: %d, btnCode: %d.", sessionId, btnCode);
|
||||
nlohmann::json jsonStr;
|
||||
jsonStr[DINPUT_SOFTBUS_KEY_CMD_TYPE] = TRANS_SINK_MSG_KEY_STATE;
|
||||
jsonStr[DINPUT_SOFTBUS_KEY_KEYSTATE_DHID] = dhId;
|
||||
jsonStr[DINPUT_SOFTBUS_KEY_KEYSTATE_TYPE] = EV_KEY;
|
||||
jsonStr[DINPUT_SOFTBUS_KEY_KEYSTATE_CODE] = btnCode;
|
||||
jsonStr[DINPUT_SOFTBUS_KEY_KEYSTATE_VALUE] = KEY_DOWN_STATE;
|
||||
std::string msg = jsonStr.dump();
|
||||
int32_t ret = SendMessage(sessionId, msg);
|
||||
if (ret != DH_SUCCESS) {
|
||||
DHLOGE("SendKeyStateNodeMsg error, SendMessage fail.");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user