!1890 add 'SetDamplingCoefficient'

Merge pull request !1890 from blueyouth/set_dampling_coefficient
This commit is contained in:
openharmony_ci 2024-08-30 10:04:32 +00:00 committed by Gitee
commit fcd8ed2ff3
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
18 changed files with 225 additions and 7 deletions

View File

@ -104,6 +104,15 @@ int32_t InteractionManager::UnregisterEventListener(const std::string &networkId
#endif // OHOS_BUILD_ENABLE_INTENTION_FRAMEWORK
}
int32_t InteractionManager::SetDamplingCoefficient(uint32_t direction, double coefficient)
{
#ifdef OHOS_BUILD_ENABLE_INTENTION_FRAMEWORK
return INTER_MGR_IMPL.SetDamplingCoefficient(direction, coefficient);
#else
return RET_OK;
#endif // OHOS_BUILD_ENABLE_INTENTION_FRAMEWORK
}
int32_t InteractionManager::UpdateDragStyle(DragCursorStyle style, int32_t eventId)
{
return INTER_MGR_IMPL.UpdateDragStyle(style, eventId);

View File

@ -82,6 +82,7 @@ public:
MouseLocationListenerPtr listener);
int32_t UnregisterEventListener(ITunnelClient &tunnel, const std::string &networkId,
MouseLocationListenerPtr listener = nullptr);
int32_t SetDamplingCoefficient(ITunnelClient &tunnel, uint32_t direction, double coefficient);
int32_t AddHotAreaListener(ITunnelClient &tunnel, HotAreaListenerPtr listener);
int32_t RemoveHotAreaListener(ITunnelClient &tunnel, HotAreaListenerPtr listener = nullptr);

View File

@ -286,6 +286,19 @@ int32_t CooperateClient::UnregisterEventListener(ITunnelClient &tunnel,
return RET_OK;
}
int32_t CooperateClient::SetDamplingCoefficient(ITunnelClient &tunnel, uint32_t direction, double coefficient)
{
FI_HILOGI("SetDamplingCoefficient(0x%{public}x, %{public}lf)", direction, coefficient);
SetDamplingCoefficientParam param { direction, coefficient };
DefaultReply reply;
auto ret = tunnel.SetParam(Intention::COOPERATE, CooperateRequestID::SET_DAMPLING_COEFFICIENT, param, reply);
if (ret != RET_OK) {
FI_HILOGE("ITunnelClient::SetParam fail, error:%{public}d", ret);
}
return ret;
}
int32_t CooperateClient::AddHotAreaListener(ITunnelClient &tunnel, HotAreaListenerPtr listener)
{
CALL_DEBUG_ENTER;

View File

@ -33,6 +33,7 @@ enum CooperateRequestID : uint32_t {
GET_COOPERATE_STATE_SYNC,
REGISTER_EVENT_LISTENER,
UNREGISTER_EVENT_LISTENER,
SET_DAMPLING_COEFFICIENT,
};
struct StartCooperateParam final : public ParamBase {
@ -80,6 +81,16 @@ struct RegisterEventListenerParam final : public ParamBase {
using UnregisterEventListenerParam = RegisterEventListenerParam;
struct SetDamplingCoefficientParam final : public ParamBase {
SetDamplingCoefficientParam() = default;
SetDamplingCoefficientParam(uint32_t direction, double coefficient);
bool Marshalling(MessageParcel &parcel) const override;
bool Unmarshalling(MessageParcel &parcel) override;
uint32_t direction {};
double coefficient { 1.0 };
};
struct GetCooperateStateSyncParam final : public ParamBase {
GetCooperateStateSyncParam() = default;
GetCooperateStateSyncParam(const std::string &udId);
@ -99,7 +110,6 @@ struct RegisterHotAreaListenerParam final : public ParamBase {
};
using UnregisterHotAreaListenerParam = RegisterHotAreaListenerParam;
} // namespace DeviceStatus
} // namespace Msdp
} // namespace OHOS

View File

@ -102,6 +102,25 @@ bool RegisterEventListenerParam::Unmarshalling(MessageParcel &parcel)
return parcel.ReadString(networkId);
}
SetDamplingCoefficientParam::SetDamplingCoefficientParam(uint32_t direction, double coefficient)
: direction(direction), coefficient(coefficient) {}
bool SetDamplingCoefficientParam::Marshalling(MessageParcel &parcel) const
{
return (
parcel.WriteUint32(direction) &&
parcel.WriteDouble(coefficient)
);
}
bool SetDamplingCoefficientParam::Unmarshalling(MessageParcel &parcel)
{
return (
parcel.ReadUint32(direction) &&
parcel.ReadDouble(coefficient)
);
}
GetCooperateStateSyncParam::GetCooperateStateSyncParam(const std::string &udId) : udId(udId)
{}

View File

@ -51,6 +51,7 @@ public:
int32_t GetCooperateState(int32_t pid, int32_t userData, const std::string &networkId) override;
int32_t GetCooperateState(const std::string &udId, bool &state) override;
int32_t Update(uint32_t mask, uint32_t flag) override;
int32_t SetDamplingCoefficient(uint32_t direction, double coefficient) override;
void Dump(int32_t fd) override;
private:
@ -58,7 +59,7 @@ private:
void StartWorker();
void StopWorker();
void LoadMotionDrag();
void UnloadMotionDrag();
void SetDamplingCoefficient(const CooperateEvent &event);
IContext *env_ { nullptr };
Context context_;

View File

@ -51,6 +51,8 @@ enum class CooperateEventType {
GET_COOPERATE_STATE,
REGISTER_EVENT_LISTENER,
UNREGISTER_EVENT_LISTENER,
UPDATE_COOPERATE_FLAG,
SET_DAMPLING_COEFFICIENT,
DUMP,
APP_CLOSED,
DDM_BOARD_ONLINE,
@ -70,7 +72,6 @@ enum class CooperateEventType {
DSOFTBUS_REPLY_SUBSCRIBE_MOUSE_LOCATION,
DSOFTBUS_REPLY_UNSUBSCRIBE_MOUSE_LOCATION,
DSOFTBUS_MOUSE_LOCATION,
UPDATE_COOPERATE_FLAG,
DSOFTBUS_INPUT_DEV_SYNC,
DSOFTBUS_INPUT_DEV_HOT_PLUG,
};
@ -232,6 +233,11 @@ struct UpdateCooperateFlagEvent {
uint32_t flag;
};
struct SetDamplingCoefficientEvent {
uint32_t direction;
double coefficient;
};
struct CooperateEvent {
CooperateEvent() : type(CooperateEventType::QUIT) {}
@ -260,6 +266,7 @@ struct CooperateEvent {
DSoftbusRelayCooperate,
ClientDiedEvent,
UpdateCooperateFlagEvent,
SetDamplingCoefficientEvent,
DSoftbusSyncInputDevice,
DSoftbusHotPlugEvent
> event;

View File

@ -61,6 +61,14 @@ class InputEventBuilder final {
Coordinate pos {};
};
enum DamplingDirection : size_t {
DAMPLING_DIRECTION_UP = 0,
DAMPLING_DIRECTION_DOWN,
DAMPLING_DIRECTION_LEFT,
DAMPLING_DIRECTION_RIGHT,
N_DAMPLING_DIRECTIONS,
};
public:
InputEventBuilder(IContext *env);
~InputEventBuilder();
@ -71,6 +79,7 @@ public:
void Update(Context &context);
void Freeze();
void Thaw();
void SetDamplingCoefficient(uint32_t direction, double coefficient);
static bool IsLocalEvent(const InputPointerEvent &event);
@ -81,6 +90,8 @@ private:
bool UpdatePointerEvent(std::shared_ptr<MMI::PointerEvent> pointerEvent);
bool IsActive(std::shared_ptr<MMI::PointerEvent> pointerEvent);
void ResetPressedEvents();
double GetDamplingCoefficient(DamplingDirection direction) const;
bool DampPointerMotion(std::shared_ptr<MMI::PointerEvent> pointerEvent) const;
IContext *env_ { nullptr };
bool enable_ { false };
@ -89,6 +100,7 @@ private:
int32_t movement_ { 0 };
size_t nDropped_ { 0 };
std::string remoteNetworkId_;
std::array<double, N_DAMPLING_DIRECTIONS> damplingCoefficients_;
std::shared_ptr<DSoftbusObserver> observer_;
std::shared_ptr<MMI::PointerEvent> pointerEvent_;
std::shared_ptr<MMI::KeyEvent> keyEvent_;

View File

@ -267,6 +267,20 @@ int32_t Cooperate::Update(uint32_t mask, uint32_t flag)
return RET_OK;
}
int32_t Cooperate::SetDamplingCoefficient(uint32_t direction, double coefficient)
{
auto ret = context_.Sender().Send(CooperateEvent(
CooperateEventType::SET_DAMPLING_COEFFICIENT,
SetDamplingCoefficientEvent {
.direction = direction,
.coefficient = coefficient,
}));
if (ret != Channel<CooperateEvent>::NO_ERROR) {
FI_HILOGE("Failed to send event via channel, error:%{public}d", ret);
}
return RET_OK;
}
void Cooperate::Dump(int32_t fd)
{
CALL_DEBUG_ENTER;
@ -298,6 +312,10 @@ void Cooperate::Loop()
running = false;
break;
}
case CooperateEventType::SET_DAMPLING_COEFFICIENT: {
SetDamplingCoefficient(event);
break;
}
default: {
sm_.OnEvent(context_, event);
break;
@ -343,6 +361,12 @@ void Cooperate::LoadMotionDrag()
motionDrag->Enable(context_.EventHandler());
}
void Cooperate::SetDamplingCoefficient(const CooperateEvent &event)
{
SetDamplingCoefficientEvent notice = std::get<SetDamplingCoefficientEvent>(event.event);
context_.inputEventBuilder_.SetDamplingCoefficient(notice.direction, notice.coefficient);
}
extern "C" ICooperate* CreateInstance(IContext *env)
{
CHKPP(env);

View File

@ -32,6 +32,9 @@ namespace Cooperate {
namespace {
constexpr size_t LOG_PERIOD { 10 };
constexpr int32_t DEFAULT_SCREEN_WIDTH { 512 };
constexpr double MIN_DAMPLING_COEFFICENT { 0.05 };
constexpr double MAX_DAMPLING_COEFFICENT { 1.5 };
constexpr double DEFAULT_DAMPLING_COEFFICIENT { 1.0 };
}
InputEventBuilder::InputEventBuilder(IContext *env)
@ -40,6 +43,10 @@ InputEventBuilder::InputEventBuilder(IContext *env)
observer_ = std::make_shared<DSoftbusObserver>(*this);
pointerEvent_ = MMI::PointerEvent::Create();
keyEvent_ = MMI::KeyEvent::Create();
for (size_t index = 0, cnt = damplingCoefficients_.size(); index < cnt; ++index) {
damplingCoefficients_[index] = DEFAULT_DAMPLING_COEFFICIENT;
}
}
InputEventBuilder::~InputEventBuilder()
@ -99,6 +106,33 @@ void InputEventBuilder::Thaw()
FI_HILOGI("Thaw remote input from '%{public}s'", Utility::Anonymize(remoteNetworkId_).c_str());
}
void InputEventBuilder::SetDamplingCoefficient(uint32_t direction, double coefficient)
{
coefficient = std::clamp(coefficient, MIN_DAMPLING_COEFFICENT, MAX_DAMPLING_COEFFICENT);
FI_HILOGI("SetDamplingCoefficient(0x%{public}x, %{public}lf)", direction, coefficient);
if ((direction & COORDINATION_DAMPLING_UP) == COORDINATION_DAMPLING_UP) {
damplingCoefficients_[DamplingDirection::DAMPLING_DIRECTION_UP] = coefficient;
}
if ((direction & COORDINATION_DAMPLING_DOWN) == COORDINATION_DAMPLING_DOWN) {
damplingCoefficients_[DamplingDirection::DAMPLING_DIRECTION_DOWN] = coefficient;
}
if ((direction & COORDINATION_DAMPLING_LEFT) == COORDINATION_DAMPLING_LEFT) {
damplingCoefficients_[DamplingDirection::DAMPLING_DIRECTION_LEFT] = coefficient;
}
if ((direction & COORDINATION_DAMPLING_RIGHT) == COORDINATION_DAMPLING_RIGHT) {
damplingCoefficients_[DamplingDirection::DAMPLING_DIRECTION_RIGHT] = coefficient;
}
}
double InputEventBuilder::GetDamplingCoefficient(DamplingDirection direction) const
{
if ((direction >= DamplingDirection::DAMPLING_DIRECTION_UP) &&
(direction < DamplingDirection::N_DAMPLING_DIRECTIONS)) {
return damplingCoefficients_[direction];
}
return DEFAULT_DAMPLING_COEFFICIENT;
}
bool InputEventBuilder::OnPacket(const std::string &networkId, Msdp::NetPacket &packet)
{
if (networkId != remoteNetworkId_) {
@ -162,9 +196,8 @@ bool InputEventBuilder::UpdatePointerEvent(std::shared_ptr<MMI::PointerEvent> po
if (pointerEvent->GetSourceType() != MMI::PointerEvent::SOURCE_TYPE_MOUSE) {
return true;
}
MMI::PointerEvent::PointerItem item;
if (!pointerEvent->GetPointerItem(pointerEvent->GetPointerId(), item)) {
FI_HILOGE("Corrupted pointer event");
if (!DampPointerMotion(pointerEvent)) {
FI_HILOGE("DampPointerMotion fail");
return false;
}
pointerEvent->AddFlag(MMI::InputEvent::EVENT_FLAG_RAW_POINTER_MOVEMENT);
@ -177,6 +210,35 @@ bool InputEventBuilder::UpdatePointerEvent(std::shared_ptr<MMI::PointerEvent> po
return true;
}
bool InputEventBuilder::DampPointerMotion(std::shared_ptr<MMI::PointerEvent> pointerEvent) const
{
MMI::PointerEvent::PointerItem item;
if (!pointerEvent->GetPointerItem(pointerEvent->GetPointerId(), item)) {
FI_HILOGE("Corrupted pointer event");
return false;
}
// Dampling pointer movement.
// First transition will trigger special effect which would damp pointer movement. We want to
// damp pointer movement even further than that could be achieved by setting pointer speed.
// By scaling increment of pointer movement, we want to enlarge the range of pointer speed setting.
if (item.GetRawDx() >= 0) {
item.SetRawDx(static_cast<int32_t>(
item.GetRawDx() * GetDamplingCoefficient(DamplingDirection::DAMPLING_DIRECTION_RIGHT)));
} else {
item.SetRawDx(static_cast<int32_t>(
item.GetRawDx() * GetDamplingCoefficient(DamplingDirection::DAMPLING_DIRECTION_LEFT)));
}
if (item.GetRawDy() >= 0) {
item.SetRawDy(static_cast<int32_t>(
item.GetRawDy() * GetDamplingCoefficient(DamplingDirection::DAMPLING_DIRECTION_DOWN)));
} else {
item.SetRawDy(static_cast<int32_t>(
item.GetRawDy() * GetDamplingCoefficient(DamplingDirection::DAMPLING_DIRECTION_UP)));
}
pointerEvent->UpdatePointerItem(pointerEvent->GetPointerId(), item);
return true;
}
void InputEventBuilder::TagRemoteEvent(std::shared_ptr<MMI::PointerEvent> pointerEvent)
{
pointerEvent->SetDeviceId(

View File

@ -193,7 +193,24 @@ int32_t CooperateServer::RemoveWatch(CallingContext &context, uint32_t id, Messa
int32_t CooperateServer::SetParam(CallingContext &context, uint32_t id, MessageParcel &data, MessageParcel &reply)
{
CALL_DEBUG_ENTER;
return RET_ERR;
if (int32_t ret = CheckPermission(context); ret != RET_OK) {
FI_HILOGE("CheckPermission failed, ret:%{public}d", ret);
return ret;
}
if (id != CooperateRequestID::SET_DAMPLING_COEFFICIENT) {
FI_HILOGE("Unexpected request (%{public}u)", id);
return RET_ERR;
}
SetDamplingCoefficientParam param {};
if (!param.Unmarshalling(data)) {
FI_HILOGE("SetDamplingCoefficientParam::Unmarshalling fail");
return RET_ERR;
}
CHKPR(context_, RET_ERR);
ICooperate* cooperate = context_->GetPluginManager().LoadCooperate();
CHKPR(cooperate, RET_ERR);
FI_HILOGI("SetDamplingCoefficient(0x%{public}x, %{public}lf)", param.direction, param.coefficient);
return cooperate->SetDamplingCoefficient(param.direction, param.coefficient);
}
int32_t CooperateServer::GetParam(CallingContext &context, uint32_t id, MessageParcel &data, MessageParcel &reply)

View File

@ -56,6 +56,7 @@ public:
int32_t GetCoordinationState(const std::string &udId, bool &state);
int32_t RegisterEventListener(const std::string &networkId, std::shared_ptr<IEventListener> listener);
int32_t UnregisterEventListener(const std::string &networkId, std::shared_ptr<IEventListener> listener = nullptr);
int32_t SetDamplingCoefficient(uint32_t direction, double coefficient);
int32_t UpdateDragStyle(DragCursorStyle style, int32_t eventId = -1);
int32_t StartDrag(const DragData &dragData, std::shared_ptr<IStartDragListener> listener);
int32_t StopDrag(const DragDropResult &dropResult);

View File

@ -268,6 +268,20 @@ int32_t IntentionManager::UnregisterEventListener(const std::string &networkId,
#endif // OHOS_BUILD_ENABLE_COORDINATION
}
int32_t IntentionManager::SetDamplingCoefficient(uint32_t direction, double coefficient)
{
CALL_INFO_TRACE;
#ifdef OHOS_BUILD_ENABLE_COORDINATION
InitClient();
return cooperate_.SetDamplingCoefficient(*tunnel_, direction, coefficient);
#else
(void)(direction);
(void)(coefficient);
FI_HILOGW("Coordination does not support");
return ERROR_UNSUPPORT;
#endif // OHOS_BUILD_ENABLE_COORDINATION
}
int32_t IntentionManager::UpdateDragStyle(DragCursorStyle style, int32_t eventId)
{
CALL_DEBUG_ENTER;

View File

@ -78,6 +78,7 @@ public:
virtual int32_t RegisterEventListener(int32_t pid, const std::string &networkId) = 0;
virtual int32_t UnregisterEventListener(int32_t pid, const std::string &networkId) = 0;
virtual int32_t GetCooperateState(const std::string &udId, bool &state) = 0;
virtual int32_t SetDamplingCoefficient(uint32_t direction, double coefficient) = 0;
virtual void Dump(int32_t fd) = 0;
};
} // namespace DeviceStatus

View File

@ -51,6 +51,14 @@ enum class HotAreaType {
AREA_BOTTOM = 3,
AREA_NONE = 4
};
inline constexpr uint32_t COORDINATION_DAMPLING_UP { 0x1 };
inline constexpr uint32_t COORDINATION_DAMPLING_DOWN { COORDINATION_DAMPLING_UP << 0x1 };
inline constexpr uint32_t COORDINATION_DAMPLING_LEFT { COORDINATION_DAMPLING_DOWN << 0x1 };
inline constexpr uint32_t COORDINATION_DAMPLING_RIGHT { COORDINATION_DAMPLING_LEFT << 0x1 };
inline constexpr uint32_t COORDINATION_DAMPLING_ALL {
COORDINATION_DAMPLING_UP | COORDINATION_DAMPLING_DOWN |
COORDINATION_DAMPLING_LEFT | COORDINATION_DAMPLING_RIGHT };
} // namespace Msdp
} // namespace OHOS
#endif // COORDINATION_MESSAGE_H

View File

@ -143,6 +143,8 @@ public:
*/
int32_t UnregisterEventListener(const std::string &networkId, std::shared_ptr<IEventListener> listener = nullptr);
int32_t SetDamplingCoefficient(uint32_t direction, double coefficient);
/**
* @brief Starts dragging.
* @param dragData Indicates additional data used for dragging.

View File

@ -45,6 +45,7 @@
"OHOS::Msdp::DeviceStatus::InteractionManager::GetCoordinationState(std::__h::basic_string<char, std::__h::char_traits<char>, std::__h::allocator<char>> const&, bool&)";
"OHOS::Msdp::DeviceStatus::InteractionManager::RegisterEventListener(std::__h::basic_string<char, std::__h::char_traits<char>, std::__h::allocator<char>> const&, std::__h::shared_ptr<OHOS::Msdp::IEventListener>)";
"OHOS::Msdp::DeviceStatus::InteractionManager::UnregisterEventListener(std::__h::basic_string<char, std::__h::char_traits<char>, std::__h::allocator<char>> const&, std::__h::shared_ptr<OHOS::Msdp::IEventListener>)";
"OHOS::Msdp::DeviceStatus::InteractionManager::SetDamplingCoefficient(unsigned int, double)";
"OHOS::Msdp::DeviceStatus::InteractionManager::StartDrag(OHOS::Msdp::DeviceStatus::DragData const&, std::__h::shared_ptr<OHOS::Msdp::DeviceStatus::IStartDragListener>)";
"OHOS::Msdp::DeviceStatus::InteractionManager::StopDrag(OHOS::Msdp::DeviceStatus::DragDropResult const&)";
"OHOS::Msdp::DeviceStatus::InteractionManager::SetDragWindowVisible(bool, bool)";

View File

@ -1049,6 +1049,22 @@ HWTEST_F(InteractionManagerTest, AddHotAreaListener_002, TestSize.Level1)
RemovePermission();
}
/**
* @tc.name: Set
* @tc.desc: Set dampling coefficient.
* @tc.type: FUNC
* @tc.require:
*/
HWTEST_F(InteractionManagerTest, InteractionManagerTest_SetDamplingCoefficient, TestSize.Level1)
{
CALL_TEST_DEBUG;
SetPermission(SYSTEM_BASIC, g_basics, sizeof(g_basics) / sizeof(g_basics[0]));
constexpr double damplingCoefficient { 0.1 };
auto ret = InteractionManager::GetInstance()->SetDamplingCoefficient(
COORDINATION_DAMPLING_RIGHT, damplingCoefficient);
ASSERT_EQ(ret, RET_OK);
}
/**
* @tc.name: InteractionManagerTest_Draglistener_Mouse
* @tc.desc: Drag listener