mirror of
https://github.com/openharmony/distributedhardware_distributed_input.git
synced 2026-07-21 05:45:23 -04:00
Description:add IsTouchEventNeedFilterOut api
Match-id-ee92e60df14843b2ef715f711f2f5167eb914519
This commit is contained in:
@@ -150,6 +150,11 @@ namespace DistributedInput {
|
||||
int32_t keyAction;
|
||||
};
|
||||
|
||||
struct TouchScreenEvent {
|
||||
uint32_t absX;
|
||||
uint32_t absY;
|
||||
};
|
||||
|
||||
/*
|
||||
* A raw event as retrieved from the input_event.
|
||||
*/
|
||||
|
||||
@@ -970,12 +970,12 @@ void InputHub::HandleTouchScreenEvent(struct input_event readBuffer[], const siz
|
||||
|
||||
for (size_t i = 0; i < count; i++) {
|
||||
struct input_event& iev = readBuffer[i];
|
||||
if ((iev.type == EV_ABS) && (iev.code == ABS_MT_POSITION_X || iev.code == ABS_X)) {
|
||||
if ((iev.type == EV_ABS) && (iev.code == ABS_X || iev.code == ABS_MT_POSITION_X)) {
|
||||
firstIndex = (int32_t)i;
|
||||
} else if (iev.type == EV_SYN) {
|
||||
lastIndex = (int32_t)i;
|
||||
}
|
||||
if ((firstIndex >= 0) && (lastIndex > 0)) {
|
||||
if ((firstIndex >= 0) && (lastIndex > firstIndex)) {
|
||||
absIndexs.emplace_back(std::make_pair((size_t)firstIndex, (size_t)lastIndex));
|
||||
}
|
||||
}
|
||||
@@ -992,11 +992,11 @@ void InputHub::HandleTouchScreenEvent(struct input_event readBuffer[], const siz
|
||||
|
||||
for (size_t j = iter.first; j <= iter.second; j++) {
|
||||
struct input_event &iev = readBuffer[j];
|
||||
if (iev.code == ABS_MT_POSITION_X || iev.code == ABS_X) {
|
||||
if (iev.code == ABS_X || iev.code == ABS_MT_POSITION_X) {
|
||||
absInfo.absX = iev.value;
|
||||
absInfo.absXIndex = (int32_t)j;
|
||||
}
|
||||
if (iev.code == ABS_MT_POSITION_Y || iev.code == ABS_Y) {
|
||||
if (iev.code == ABS_Y || iev.code == ABS_MT_POSITION_Y) {
|
||||
absInfo.absY = iev.value;
|
||||
absInfo.absYIndex = (int32_t)j;
|
||||
}
|
||||
|
||||
@@ -47,6 +47,8 @@ public:
|
||||
|
||||
static bool IsNeedFilterOut(const std::string &deviceId, const BusinessEvent &event);
|
||||
|
||||
static bool IsTouchEventNeedFilterOut(const TouchScreenEvent &event);
|
||||
|
||||
static DInputServerType IsStartDistributedInput(const uint32_t& inputType);
|
||||
};
|
||||
} // namespace DistributedInput
|
||||
|
||||
@@ -47,6 +47,11 @@ bool DistributedInputKit::IsNeedFilterOut(const std::string& deviceId, const Bus
|
||||
return DistributedInputClient::GetInstance().IsNeedFilterOut(deviceId, event);
|
||||
}
|
||||
|
||||
bool DistributedInputKit::IsTouchEventNeedFilterOut(const TouchScreenEvent &event)
|
||||
{
|
||||
return DistributedInputClient::GetInstance().IsTouchEventNeedFilterOut(event);
|
||||
}
|
||||
|
||||
DInputServerType DistributedInputKit::IsStartDistributedInput(const uint32_t& inputType)
|
||||
{
|
||||
return DistributedInputClient::GetInstance().IsStartDistributedInput(inputType);
|
||||
|
||||
@@ -292,6 +292,37 @@ HWTEST_F(DistributedInputInnerTest, IsNeedFilterOut03, testing::ext::TestSize.Le
|
||||
EXPECT_EQ(true, ret);
|
||||
}
|
||||
|
||||
HWTEST_F(DistributedInputInnerTest, IsTouchEventNeedFilterOut01, testing::ext::TestSize.Level0)
|
||||
{
|
||||
std::string sourceWinId = "123";
|
||||
SinkScreenInfo sinkScreenInfo = DInputContext::GetInstance().GetSinkScreenInfo(sourceWinId);
|
||||
const TransformInfo trans{10, 10, 100, 100, 1.0, 1.0};
|
||||
sinkScreenInfo.transformInfo = trans;
|
||||
DInputContext::GetInstance().UpdateSinkScreenInfo(sourceWinId, sinkScreenInfo);
|
||||
|
||||
sourceWinId = "456";
|
||||
sinkScreenInfo = DInputContext::GetInstance().GetSinkScreenInfo(sourceWinId);
|
||||
const TransformInfo trans1{120, 130, 50, 50, 1.0, 1.0};
|
||||
sinkScreenInfo.transformInfo = trans1;
|
||||
DInputContext::GetInstance().UpdateSinkScreenInfo(sourceWinId, sinkScreenInfo);
|
||||
|
||||
TouchScreenEvent event;
|
||||
event.absX = 100;
|
||||
event.absY = 100;
|
||||
bool ret = DistributedInputKit::IsTouchEventNeedFilterOut(event);
|
||||
EXPECT_EQ(true, ret);
|
||||
|
||||
event.absX = 140;
|
||||
event.absY = 150;
|
||||
ret = DistributedInputKit::IsTouchEventNeedFilterOut(event);
|
||||
EXPECT_EQ(true, ret);
|
||||
|
||||
event.absX = 150;
|
||||
event.absY = 20;
|
||||
ret = DistributedInputKit::IsTouchEventNeedFilterOut(event);
|
||||
EXPECT_EQ(false, ret);
|
||||
}
|
||||
|
||||
HWTEST_F(DistributedInputInnerTest, IsStartDistributedInput1, testing::ext::TestSize.Level0)
|
||||
{
|
||||
DistributedInputClient::GetInstance().ReleaseSource();
|
||||
|
||||
@@ -154,6 +154,22 @@ bool DistributedInputClient::IsNeedFilterOut(const std::string& deviceId, const
|
||||
return true;
|
||||
}
|
||||
|
||||
bool DistributedInputClient::IsTouchEventNeedFilterOut(const TouchScreenEvent &event)
|
||||
{
|
||||
auto sinkInfos = DInputContext::GetInstance().GetAllSinkScreenInfo();
|
||||
|
||||
for (const auto& [id, sinkInfo] : sinkInfos) {
|
||||
auto info = sinkInfo.transformInfo;
|
||||
DHLOGI("event.absX:%d, info.sinkWinPhyX:%d, info.sinkProjPhyWidth:%d\n", event.absX, info.sinkWinPhyX,
|
||||
info.sinkProjPhyWidth);
|
||||
if ((event.absX >= info.sinkWinPhyX) && (event.absX <= (info.sinkWinPhyX + info.sinkProjPhyWidth))
|
||||
&& (event.absY >= info.sinkWinPhyY) && (event.absY <= (info.sinkWinPhyY + info.sinkProjPhyHeight))) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
DInputServerType DistributedInputClient::IsStartDistributedInput(const uint32_t& inputType)
|
||||
{
|
||||
return serverType;
|
||||
|
||||
@@ -68,6 +68,8 @@ public:
|
||||
|
||||
bool IsNeedFilterOut(const std::string &deviceId, const BusinessEvent &event);
|
||||
|
||||
bool IsTouchEventNeedFilterOut(const TouchScreenEvent &event);
|
||||
|
||||
DInputServerType IsStartDistributedInput(const uint32_t& inputType);
|
||||
|
||||
int32_t NotifyStartDScreen(const std::string &networkId, const std::string& srcDevId, const uint64_t srcWinId);
|
||||
|
||||
@@ -22,6 +22,7 @@
|
||||
#include "system_ability_definition.h"
|
||||
|
||||
#include "constants_dinput.h"
|
||||
#include "dinput_context.h"
|
||||
#include "dinput_errcode.h"
|
||||
#include "dinput_utils_tool.h"
|
||||
#include "softbus_bus_center.h"
|
||||
@@ -296,6 +297,20 @@ bool DistributedInputClient::IsNeedFilterOut(const std::string& deviceId, const
|
||||
return WhiteListUtil::GetInstance().IsNeedFilterOut(deviceId, event);
|
||||
}
|
||||
|
||||
bool DistributedInputClient::IsTouchEventNeedFilterOut(const TouchScreenEvent &event)
|
||||
{
|
||||
auto sinkInfos = DInputContext::GetInstance().GetAllSinkScreenInfo();
|
||||
|
||||
for (const auto& [id, sinkInfo] : sinkInfos) {
|
||||
auto info = sinkInfo.transformInfo;
|
||||
if ((event.absX >= info.sinkWinPhyX) && (event.absX <= (info.sinkWinPhyX + info.sinkProjPhyWidth))
|
||||
&& (event.absY >= info.sinkWinPhyY) && (event.absY <= (info.sinkWinPhyY + info.sinkProjPhyHeight))) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
DInputServerType DistributedInputClient::IsStartDistributedInput(const uint32_t& inputType)
|
||||
{
|
||||
DHLOGI("%s called, inputType: %d, inputTypes: %d, ", __func__, inputType, static_cast<uint32_t>(inputTypes_));
|
||||
|
||||
@@ -53,6 +53,7 @@ static SessionAttribute g_sessionAttr = {
|
||||
|
||||
DistributedInputSourceTransport::~DistributedInputSourceTransport()
|
||||
{
|
||||
DHLOGI("Dtor DistributedInputSourceTransport");
|
||||
Release();
|
||||
}
|
||||
|
||||
|
||||
@@ -131,6 +131,21 @@ void IsNeedFilterOutFuzzTest(const uint8_t* data, size_t size)
|
||||
|
||||
DistributedInput::DistributedInputKit::IsNeedFilterOut(deviceId, event);
|
||||
}
|
||||
|
||||
void IsTouchEventNeedFilterOutFuzzTest(const uint8_t* data, size_t size)
|
||||
{
|
||||
if ((data == nullptr) || (size <= 0)) {
|
||||
return;
|
||||
}
|
||||
|
||||
uint32_t absX = *(reinterpret_cast<const uint32_t*>(data));
|
||||
uint32_t absY = *(reinterpret_cast<const uint32_t*>(data));
|
||||
DistributedInput::TouchScreenEvent event;
|
||||
event.absX = absX;
|
||||
event.absY = absY;
|
||||
|
||||
DistributedInput::DistributedInputKit::IsTouchEventNeedFilterOut(event);
|
||||
}
|
||||
} // namespace DistributedHardware
|
||||
} // namespace OHOS
|
||||
|
||||
@@ -141,5 +156,6 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)
|
||||
OHOS::DistributedHardware::PrepareInputFuzzTest(data, size);
|
||||
OHOS::DistributedHardware::StartRemoteInputFuzzTest(data, size);
|
||||
OHOS::DistributedHardware::IsNeedFilterOutFuzzTest(data, size);
|
||||
OHOS::DistributedHardware::IsTouchEventNeedFilterOutFuzzTest(data, size);
|
||||
return 0;
|
||||
}
|
||||
+2
@@ -25,6 +25,7 @@
|
||||
#include <refbase.h>
|
||||
|
||||
#include "constants_dinput.h"
|
||||
#include "distributed_input_inject.h"
|
||||
#include "distributed_input_source_transport.h"
|
||||
|
||||
namespace OHOS {
|
||||
@@ -73,6 +74,7 @@ void OnBytesReceivedFuzzTest(const uint8_t* data, size_t size)
|
||||
/* Fuzzer entry point */
|
||||
extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)
|
||||
{
|
||||
OHOS::DistributedHardware::DistributedInput::DistributedInputInject::GetInstance();
|
||||
/* Run your code on data */
|
||||
OHOS::DistributedHardware::OpenInputSoftbusFuzzTest(data, size);
|
||||
OHOS::DistributedHardware::OnSessionOpenedFuzzTest(data, size);
|
||||
|
||||
Reference in New Issue
Block a user