modify unprepare can not stop all dhid

Signed-off-by: hwzhangchuang <zhangchuang.zhang@huawei.com>
This commit is contained in:
hwzhangchuang
2024-02-07 00:16:29 +08:00
parent dbd404361d
commit 8479e954f7
10 changed files with 48 additions and 29 deletions
+13
View File
@@ -1210,6 +1210,19 @@ AffectDhIds InputHub::SetSharingDevices(bool enabled, std::vector<std::string> d
return affDhIds;
}
std::vector<std::string> InputHub::GetSharingDevices()
{
std::vector<std::string> sharingDevices;
std::lock_guard<std::mutex> deviceLock(devicesMutex_);
for (const auto &[id, device] : devices_) {
if (device->isShare) {
DHLOGI("Find sharing dhid: %s", GetAnonyString(device->identifier.descriptor).c_str());
sharingDevices.push_back(device->identifier.descriptor);
}
}
return sharingDevices;
}
void InputHub::GetSharedMousePathByDhId(const std::vector<std::string> &dhIds, std::string &sharedMousePath,
std::string &sharedMouseDhId)
{
+1
View File
@@ -87,6 +87,7 @@ public:
AffectDhIds SetSupportInputType(bool enabled, const uint32_t &inputTypes);
// return efftive dhids
AffectDhIds SetSharingDevices(bool enabled, std::vector<std::string> dhIds);
std::vector<std::string> GetSharingDevices();
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 GetSharedMousePathByDhId(const std::vector<std::string> &dhIds, std::string &sharedMousePath,
@@ -45,6 +45,7 @@ public:
void StopCollectionThread();
AffectDhIds SetSharingTypes(bool enabled, const uint32_t &inputType);
AffectDhIds SetSharingDhIds(bool enabled, std::vector<std::string> dhIds);
std::vector<std::string> GetSharingDhIds();
void GetMouseNodePath(const std::vector<std::string> &dhIds, std::string &mouseNodePath, std::string &dhid);
void GetSharedKeyboardPathsByDhIds(const std::vector<std::string> &dhIds,
std::vector<std::string> &sharedKeyboardPaths, std::vector<std::string> &sharedKeyboardDhIds);
@@ -211,6 +211,11 @@ AffectDhIds DistributedInputCollector::SetSharingDhIds(bool enabled, std::vector
return inputHub_->SetSharingDevices(enabled, dhIds);
}
std::vector<std::string> DistributedInputCollector::GetSharingDhIds()
{
return inputHub_->GetSharingDevices();
}
void DistributedInputCollector::GetMouseNodePath(const std::vector<std::string> &dhIds,
std::string &mouseNodePath, std::string &dhId)
{
@@ -144,7 +144,10 @@ void DistributedInputSinkManager::DInputSinkListener::OnPrepareRemoteInput(
void DistributedInputSinkManager::DInputSinkListener::OnUnprepareRemoteInput(const int32_t &sessionId)
{
DHLOGI("OnUnprepareRemoteInput called, sessionId: %d", sessionId);
OnStopRemoteInput(sessionId, static_cast<uint32_t>(DInputDeviceType::ALL));
std::vector<std::string> sharingDhIds = DistributedInputCollector::GetInstance().GetSharingDhIds();
if (!sharingDhIds.empty()) {
OnStopRemoteInputDhid(sessionId, JointDhIds(sharingDhIds));
}
DistributedInputSinkSwitch::GetInstance().RemoveSession(sessionId);
nlohmann::json jsonStr;
@@ -176,7 +179,10 @@ void DistributedInputSinkManager::DInputSinkListener::OnRelayUnprepareRemoteInpu
{
DHLOGI("OnRelayUnprepareRemoteInput called, toSinkSessionId: %d, devId: %s", toSinkSessionId,
GetAnonyString(deviceId).c_str());
OnStopRemoteInput(toSinkSessionId, static_cast<uint32_t>(DInputDeviceType::ALL));
std::vector<std::string> sharingDhIds = DistributedInputCollector::GetInstance().GetSharingDhIds();
if (!sharingDhIds.empty()) {
OnStopRemoteInputDhid(toSinkSessionId, JointDhIds(sharingDhIds));
}
DistributedInputSinkSwitch::GetInstance().RemoveSession(toSinkSessionId);
nlohmann::json jsonStr;
@@ -135,8 +135,6 @@ private:
void ReceiveRelayStopTypeResult(int32_t sessionId, const nlohmann::json &recMsg);
void CalculateLatency(int32_t sessionId, const nlohmann::json &recMsg);
std::string JointDhIds(const std::vector<std::string> &dhids);
std::vector<std::string> SplitDhIdString(const std::string &dhIdsString);
void RegRespFunMap();
void ResetKeyboardKeyState(const std::string &deviceId, const std::vector<std::string> &dhids);
@@ -15,7 +15,6 @@
#include "distributed_input_source_transport.h"
#include <algorithm>
#include <cstring>
#include <pthread.h>
@@ -40,7 +39,6 @@ namespace OHOS {
namespace DistributedHardware {
namespace DistributedInput {
namespace {
const char DHID_SPLIT = '.';
const uint64_t MSG_LATENCY_ALARM_US = 20 * 1000;
}
DistributedInputSourceTransport::~DistributedInputSourceTransport()
@@ -893,22 +891,6 @@ int32_t DistributedInputSourceTransport::SendRelayStopTypeRequest(const std::str
return DH_SUCCESS;
}
std::string DistributedInputSourceTransport::JointDhIds(const std::vector<std::string> &dhids)
{
if (dhids.size() <= 0) {
return "";
}
auto dotFold = [](std::string a, std::string b) {return std::move(a) + DHID_SPLIT + std::move(b);};
return std::accumulate(std::next(dhids.begin()), dhids.end(), dhids[0], dotFold);
}
std::vector<std::string> DistributedInputSourceTransport::SplitDhIdString(const std::string &dhIdsString)
{
std::vector<std::string> dhIdsVec;
SplitStringToVector(dhIdsString, DHID_SPLIT, dhIdsVec);
return dhIdsVec;
}
int32_t DistributedInputSourceTransport::SendMessage(int32_t sessionId, std::string &message)
{
return DistributedInputTransportBase::GetInstance().SendMsg(sessionId, message);
@@ -483,13 +483,6 @@ HWTEST_F(DistributedInputSourceTransTest, SendRelayStopTypeRequest_02, testing::
EXPECT_EQ(ERR_DH_INPUT_SERVER_SOURCE_TRANSPORT_STOP_FAIL, ret);
}
HWTEST_F(DistributedInputSourceTransTest, JointDhIds01, testing::ext::TestSize.Level0)
{
std::vector<std::string> dhids;
std::string ret = DistributedInputSourceTransport::GetInstance().JointDhIds(dhids);
EXPECT_EQ("", ret);
}
HWTEST_F(DistributedInputSourceTransTest, NotifyResponsePrepareRemoteInput01, testing::ext::TestSize.Level0)
{
int32_t sessionId = 0;
+2
View File
@@ -66,6 +66,8 @@ void ResetVirtualDevicePressedKeys(const std::vector<std::string> &nodePaths);
std::string GetString(const std::vector<std::string> &vec);
int32_t GetRandomInt32();
std::string JointDhIds(const std::vector<std::string> &dhids);
std::vector<std::string> SplitDhIdString(const std::string &dhIdsString);
} // namespace DistributedInput
} // namespace DistributedHardware
} // namespace OHOS
+18
View File
@@ -15,6 +15,7 @@
#include "dinput_utils_tool.h"
#include <algorithm>
#include <climits>
#include <cstdarg>
#include <cstdio>
@@ -52,6 +53,7 @@ namespace {
constexpr uint32_t ERROR_MSG_MAX_LEN = 256;
constexpr int32_t MAX_RETRY_COUNT = 3;
constexpr uint32_t SLEEP_TIME_US = 10 * 1000;
constexpr char DHID_SPLIT = '.';
}
DevInfo GetLocalDeviceInfo()
{
@@ -445,6 +447,22 @@ int32_t GetRandomInt32()
std::uniform_int_distribution<int> distribution(0, INT32_MAX);
return distribution(engine);
}
std::string JointDhIds(const std::vector<std::string> &dhids)
{
if (dhids.size() <= 0) {
return "";
}
auto dotFold = [](std::string a, std::string b) {return std::move(a) + DHID_SPLIT + std::move(b);};
return std::accumulate(std::next(dhids.begin()), dhids.end(), dhids[0], dotFold);
}
std::vector<std::string> SplitDhIdString(const std::string &dhIdsString)
{
std::vector<std::string> dhIdsVec;
SplitStringToVector(dhIdsString, DHID_SPLIT, dhIdsVec);
return dhIdsVec;
}
} // namespace DistributedInput
} // namespace DistributedHardware
} // namespace OHOS