mirror of
https://github.com/openharmony/distributedhardware_distributed_input.git
synced 2026-07-18 16:04:40 -04:00
resolve DTS2023121217154
Signed-off-by: l30054665 <lishang21@huawei.com>
This commit is contained in:
@@ -532,7 +532,6 @@ int32_t InputHub::OpenInputDeviceLocked(const std::string &devicePath)
|
||||
int fd = OpenInputDeviceFdByPath(devicePath);
|
||||
if (fd == UN_INIT_FD_VALUE) {
|
||||
DHLOGE("The fd open failed, devicePath %s.", devicePath.c_str());
|
||||
RecordSkipDevicePath(devicePath);
|
||||
return ERR_DH_INPUT_HUB_OPEN_DEVICEPATH_FAIL;
|
||||
}
|
||||
|
||||
@@ -1562,6 +1561,13 @@ void InputHub::ClearDeviceStates()
|
||||
DInputState::GetInstance().ClearDeviceStates();
|
||||
}
|
||||
|
||||
void InputHub::ClearSkipDevicePaths()
|
||||
{
|
||||
DHLOGI("Clear Skip device path");
|
||||
std::lock_guard<std::mutex> lock(skipDevicePathsMutex_);
|
||||
skipDevicePaths_.clear();
|
||||
}
|
||||
|
||||
InputHub::Device::Device(int fd, const std::string &path)
|
||||
: next(nullptr), fd(fd), path(path), identifier({}), classes(0), enabled(false),
|
||||
isShare(false), isVirtual(fd < 0) {
|
||||
|
||||
@@ -101,6 +101,7 @@ public:
|
||||
void CheckTargetKeyState(const InputHub::Device *dev, const unsigned long *keyState, const unsigned long len);
|
||||
void SavePressedKeyState(const Device *dev, int32_t keyCode);
|
||||
void ClearDeviceStates();
|
||||
void ClearSkipDevicePaths();
|
||||
private:
|
||||
int32_t Initialize();
|
||||
int32_t Release();
|
||||
|
||||
@@ -41,8 +41,8 @@ public:
|
||||
// PreInit for get the local input devices basic info.
|
||||
// Collect all the local input basic info cost too much time(200+ ms).
|
||||
void PreInit();
|
||||
int32_t Init(std::shared_ptr<AppExecFwk::EventHandler> sinkHandler);
|
||||
void Release();
|
||||
int32_t StartCollectionThread(std::shared_ptr<AppExecFwk::EventHandler> sinkHandler);
|
||||
void StopCollectionThread();
|
||||
AffectDhIds SetSharingTypes(bool enabled, const uint32_t &inputType);
|
||||
AffectDhIds SetSharingDhIds(bool enabled, std::vector<std::string> dhIds);
|
||||
void GetMouseNodePath(const std::vector<std::string> &dhIds, std::string &mouseNodePath, std::string &dhid);
|
||||
@@ -54,6 +54,7 @@ public:
|
||||
void ReportDhIdSharingState(const AffectDhIds &dhIds);
|
||||
void GetDeviceInfoByType(const uint32_t inputTypes, std::map<int32_t, std::string> &deviceInfo);
|
||||
void ResetSpecEventStatus();
|
||||
void ClearSkipDevicePaths();
|
||||
|
||||
private:
|
||||
DistributedInputCollector();
|
||||
|
||||
@@ -59,7 +59,7 @@ void DistributedInputCollector::PreInit()
|
||||
inputHub_->RecordDeviceStates();
|
||||
}
|
||||
|
||||
int32_t DistributedInputCollector::Init(std::shared_ptr<AppExecFwk::EventHandler> sinkHandler)
|
||||
int32_t DistributedInputCollector::StartCollectionThread(std::shared_ptr<AppExecFwk::EventHandler> sinkHandler)
|
||||
{
|
||||
sinkHandler_ = sinkHandler;
|
||||
if (sinkHandler_ == nullptr || inputHub_ == nullptr) {
|
||||
@@ -201,7 +201,7 @@ void DistributedInputCollector::ReportDhIdSharingState(const AffectDhIds &dhIds)
|
||||
}
|
||||
}
|
||||
|
||||
void DistributedInputCollector::Release()
|
||||
void DistributedInputCollector::StopCollectionThread()
|
||||
{
|
||||
StopCollectEventsThread();
|
||||
}
|
||||
@@ -257,6 +257,15 @@ void DistributedInputCollector::GetDeviceInfoByType(const uint32_t inputTypes, s
|
||||
}
|
||||
inputHub_->GetDevicesInfoByType(inputTypes, deviceInfo);
|
||||
}
|
||||
|
||||
void DistributedInputCollector::ClearSkipDevicePaths()
|
||||
{
|
||||
if (inputHub_ == nullptr) {
|
||||
DHLOGE("inputHub is nullptr!");
|
||||
return;
|
||||
}
|
||||
inputHub_->ClearSkipDevicePaths();
|
||||
}
|
||||
} // namespace DistributedInput
|
||||
} // namespace DistributedHardware
|
||||
} // namespace OHOS
|
||||
|
||||
+3
-3
@@ -29,7 +29,7 @@ void DistributedInputCollectorTest::SetUp()
|
||||
|
||||
void DistributedInputCollectorTest::TearDown()
|
||||
{
|
||||
DistributedInputCollector::GetInstance().Release();
|
||||
DistributedInputCollector::GetInstance().StopCollectionThread();
|
||||
}
|
||||
|
||||
void DistributedInputCollectorTest::SetUpTestCase()
|
||||
@@ -54,7 +54,7 @@ void DistributedInputCollectorTest::DInputSinkCollectorEventHandler::ProcessEven
|
||||
HWTEST_F(DistributedInputCollectorTest, Init01, testing::ext::TestSize.Level1)
|
||||
{
|
||||
std::shared_ptr<AppExecFwk::EventHandler> eventHandler_ = nullptr;
|
||||
int32_t ret = DistributedInputCollector::GetInstance().Init(eventHandler_);
|
||||
int32_t ret = DistributedInputCollector::GetInstance().StartCollectionThread(eventHandler_);
|
||||
EXPECT_EQ(ERR_DH_INPUT_SERVER_SINK_COLLECTOR_INIT_FAIL, ret);
|
||||
}
|
||||
|
||||
@@ -64,7 +64,7 @@ HWTEST_F(DistributedInputCollectorTest, Init02, testing::ext::TestSize.Level1)
|
||||
std::shared_ptr<AppExecFwk::EventHandler> eventHandler_ =
|
||||
std::make_shared<DistributedInputCollectorTest::DInputSinkCollectorEventHandler>(runner);
|
||||
|
||||
int32_t ret = DistributedInputCollector::GetInstance().Init(eventHandler_);
|
||||
int32_t ret = DistributedInputCollector::GetInstance().StartCollectionThread(eventHandler_);
|
||||
EXPECT_EQ(DH_SUCCESS, ret);
|
||||
}
|
||||
|
||||
|
||||
@@ -111,6 +111,13 @@ public:
|
||||
DistributedInputSinkManager *sinkManagerObj_;
|
||||
};
|
||||
|
||||
class PluginStartListener : public PublisherListenerStub {
|
||||
public:
|
||||
explicit PluginStartListener() = default;
|
||||
~PluginStartListener() override;
|
||||
void OnMessage(const DHTopic topic, const std::string &message) override;
|
||||
};
|
||||
|
||||
class DScreenSinkSvrRecipient : public IRemoteObject::DeathRecipient {
|
||||
public:
|
||||
DScreenSinkSvrRecipient(const std::string &srcDevId, const uint64_t srcWinId);
|
||||
@@ -179,6 +186,7 @@ private:
|
||||
bool InitAuto();
|
||||
DInputDeviceType inputTypes_;
|
||||
sptr<ProjectWindowListener> projectWindowListener_ = nullptr;
|
||||
sptr<PluginStartListener> pluginStartListener_ = nullptr;
|
||||
std::set<std::string> sharingDhIds_;
|
||||
std::map<int32_t, std::set<std::string>> sharingDhIdsMap_;
|
||||
void StoreStartDhids(int32_t sessionId, const std::vector<std::string> &dhIds);
|
||||
|
||||
@@ -58,6 +58,7 @@ DistributedInputSinkManager::~DistributedInputSinkManager()
|
||||
{
|
||||
DHLOGI("DistributedInputSinkManager dtor!");
|
||||
projectWindowListener_ = nullptr;
|
||||
pluginStartListener_ = nullptr;
|
||||
}
|
||||
|
||||
DistributedInputSinkManager::DInputSinkMgrListener::DInputSinkMgrListener(DistributedInputSinkManager *manager)
|
||||
@@ -132,7 +133,7 @@ void DistributedInputSinkManager::DInputSinkListener::OnPrepareRemoteInput(
|
||||
nlohmann::json jsonStr;
|
||||
jsonStr[DINPUT_SOFTBUS_KEY_CMD_TYPE] = TRANS_SINK_MSG_ONPREPARE;
|
||||
std::string smsg = "";
|
||||
int32_t ret = DistributedInputCollector::GetInstance().Init(
|
||||
int32_t ret = DistributedInputCollector::GetInstance().StartCollectionThread(
|
||||
DistributedInputSinkTransport::GetInstance().GetEventHandler());
|
||||
if (ret != DH_SUCCESS) {
|
||||
DHLOGE("DInputSinkListener init InputCollector error.");
|
||||
@@ -172,7 +173,7 @@ void DistributedInputSinkManager::DInputSinkListener::OnRelayPrepareRemoteInput(
|
||||
jsonStr[DINPUT_SOFTBUS_KEY_CMD_TYPE] = TRANS_SINK_MSG_ON_RELAY_PREPARE;
|
||||
jsonStr[DINPUT_SOFTBUS_KEY_SESSION_ID] = toSrcSessionId;
|
||||
std::string smsg = "";
|
||||
int ret = DistributedInputCollector::GetInstance().Init(
|
||||
int ret = DistributedInputCollector::GetInstance().StartCollectionThread(
|
||||
DistributedInputSinkTransport::GetInstance().GetEventHandler());
|
||||
if (ret != DH_SUCCESS) {
|
||||
DHLOGE("DInputSinkListener init InputCollector error.");
|
||||
@@ -631,7 +632,8 @@ int32_t DistributedInputSinkManager::Init()
|
||||
}
|
||||
projectWindowListener_ = new ProjectWindowListener(this);
|
||||
dhFwkKit->RegisterPublisherListener(DHTopic::TOPIC_SINK_PROJECT_WINDOW_INFO, projectWindowListener_);
|
||||
|
||||
pluginStartListener_ = new PluginStartListener();
|
||||
dhFwkKit->RegisterPublisherListener(DHTopic::TOPIC_PHY_DEV_PLUGIN, pluginStartListener_);
|
||||
DistributedInputCollector::GetInstance().PreInit();
|
||||
|
||||
return DH_SUCCESS;
|
||||
@@ -652,7 +654,7 @@ int32_t DistributedInputSinkManager::Release()
|
||||
// notify callback servertype
|
||||
SetStartTransFlag(DInputServerType::NULL_SERVER_TYPE);
|
||||
// Release input collect resource
|
||||
DistributedInputCollector::GetInstance().Release();
|
||||
DistributedInputCollector::GetInstance().StopCollectionThread();
|
||||
|
||||
serviceRunningState_ = ServiceSinkRunningState::STATE_NOT_START;
|
||||
std::shared_ptr<DistributedHardwareFwkKit> dhFwkKit = DInputContext::GetInstance().GetDHFwkKit();
|
||||
@@ -660,6 +662,10 @@ int32_t DistributedInputSinkManager::Release()
|
||||
DHLOGI("UnPublish ProjectWindowListener");
|
||||
dhFwkKit->UnregisterPublisherListener(DHTopic::TOPIC_SINK_PROJECT_WINDOW_INFO, projectWindowListener_);
|
||||
}
|
||||
if (dhFwkKit != nullptr && pluginStartListener_ != nullptr) {
|
||||
DHLOGI("UnPublish PluginStartListener");
|
||||
dhFwkKit->UnregisterPublisherListener(DHTopic::TOPIC_PHY_DEV_PLUGIN, pluginStartListener_);
|
||||
}
|
||||
if (dhFwkKit != nullptr) {
|
||||
DHLOGD("Disable low Latency!");
|
||||
dhFwkKit->PublishMessage(DHTopic::TOPIC_LOW_LATENCY, DISABLE_LOW_LATENCY.dump());
|
||||
@@ -860,6 +866,26 @@ uint32_t DistributedInputSinkManager::ProjectWindowListener::GetScreenHeight()
|
||||
return screen_->GetHeight();
|
||||
}
|
||||
|
||||
DistributedInputSinkManager::PluginStartListener::~PluginStartListener()
|
||||
{
|
||||
DHLOGI("PluginStartListener dtor!");
|
||||
}
|
||||
|
||||
void DistributedInputSinkManager::PluginStartListener::OnMessage(const DHTopic topic,
|
||||
const std::string &message)
|
||||
{
|
||||
DHLOGI("PluginStartListener OnMessage!");
|
||||
if (topic != DHTopic::TOPIC_PHY_DEV_PLUGIN) {
|
||||
DHLOGE("this topic is wrong, %d", static_cast<uint32_t>(topic));
|
||||
return;
|
||||
}
|
||||
if (message.empty()) {
|
||||
DHLOGE("this message is empty");
|
||||
return;
|
||||
}
|
||||
DistributedInputCollector::GetInstance().ClearSkipDevicePaths();
|
||||
}
|
||||
|
||||
DistributedInputSinkManager::DScreenSinkSvrRecipient::DScreenSinkSvrRecipient(const std::string &srcDevId,
|
||||
const uint64_t srcWinId)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user