!1035 Added the interface for get drag state

Merge pull request !1035 from Bumblebee/mrsong_branch
This commit is contained in:
openharmony_ci 2023-10-27 13:52:06 +00:00 committed by Gitee
commit b4dc5b32cb
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
20 changed files with 147 additions and 1 deletions

View File

@ -31,7 +31,7 @@
namespace OHOS {
namespace Msdp {
namespace DeviceStatus {
class DragManagerImpl {
class DragManagerImpl {
public:
DragManagerImpl() = default;
~DragManagerImpl() = default;
@ -49,6 +49,7 @@ public:
int32_t GetShadowOffset(int32_t& offsetX, int32_t& offsetY, int32_t& width, int32_t& height);
int32_t UpdateShadowPic(const ShadowInfo &shadowInfo);
int32_t GetDragData(DragData &dragData);
int32_t GetDragState(DragState &dragState);
private:
std::mutex mtx_;

View File

@ -52,6 +52,7 @@ public:
int32_t GetShadowOffset(int32_t& offsetX, int32_t& offsetY, int32_t& width, int32_t& height);
int32_t UpdateShadowPic(const ShadowInfo &shadowInfo);
int32_t GetDragData(DragData &dragData);
int32_t GetDragState(DragState &dragState);
int32_t AddHotAreaListener(std::shared_ptr<IHotAreaListener> listener);
int32_t RemoveHotAreaListener(std::shared_ptr<IHotAreaListener> listener = nullptr);

View File

@ -196,6 +196,12 @@ int32_t DragManagerImpl::GetDragData(DragData &dragData)
CALL_DEBUG_ENTER;
return DeviceStatusClient::GetInstance().GetDragData(dragData);
}
int32_t DragManagerImpl::GetDragState(DragState &dragState)
{
CALL_DEBUG_ENTER;
return DeviceStatusClient::GetInstance().GetDragState(dragState);
}
} // namespace DeviceStatus
} // namespace Msdp
} // namespace OHOS

View File

@ -123,6 +123,11 @@ int32_t InteractionManager::GetDragData(DragData &dragData)
return INTER_MGR_IMPL.GetDragData(dragData);
}
int32_t InteractionManager::GetDragState(DragState &dragState)
{
return INTER_MGR_IMPL.GetDragState(dragState);
}
int32_t InteractionManager::AddHotAreaListener(std::shared_ptr<IHotAreaListener> listener)
{
return INTER_MGR_IMPL.AddHotAreaListener(listener);

View File

@ -274,6 +274,12 @@ int32_t InteractionManagerImpl::GetDragData(DragData &dragData)
return dragManagerImpl_.GetDragData(dragData);
}
int32_t InteractionManagerImpl::GetDragState(DragState &dragState)
{
CALL_DEBUG_ENTER;
return dragManagerImpl_.GetDragState(dragState);
}
int32_t InteractionManagerImpl::AddHotAreaListener(std::shared_ptr<IHotAreaListener> listener)
{
CALL_DEBUG_ENTER;

View File

@ -1322,6 +1322,47 @@ HWTEST_F(InteractionManagerTest, GetDragData_Failed, TestSize.Level1)
}
}
/**
* @tc.name: InteractionManagerTest_GetDragState
* @tc.desc: Get the dragState from interface
* @tc.type: FUNC
* @tc.require:
*/
HWTEST_F(InteractionManagerTest, GetDragState, TestSize.Level1)
{
CALL_TEST_DEBUG;
std::promise<bool> promiseFlag;
std::future<bool> futureFlag = promiseFlag.get_future();
auto callback = [&promiseFlag](const DragNotifyMsg& notifyMessage) {
FI_HILOGD("displayX:%{public}d, displayY:%{public}d, result:%{public}d, target:%{public}d",
notifyMessage.displayX, notifyMessage.displayY, notifyMessage.result, notifyMessage.targetPid);
promiseFlag.set_value(true);
};
SimulateDownEvent({ DRAG_SRC_X, DRAG_SRC_Y }, MMI::PointerEvent::SOURCE_TYPE_MOUSE, MOUSE_POINTER_ID);
std::optional<DragData> dragData = CreateDragData({ TEST_PIXEL_MAP_WIDTH, TEST_PIXEL_MAP_HEIGHT },
MMI::PointerEvent::SOURCE_TYPE_MOUSE, MOUSE_POINTER_ID, DISPLAY_ID, { DRAG_SRC_X, DRAG_SRC_Y });
ASSERT_TRUE(dragData);
int32_t ret = InteractionManager::GetInstance()->StartDrag(dragData.value(), callback);
ASSERT_EQ(ret, RET_OK);
DragState dragState;
ret = InteractionManager::GetInstance()->GetDragState(dragState);
FI_HILOGD("dragState:%{public}d", dragState);
EXPECT_EQ(ret, RET_OK);
EXPECT_EQ(dragState, DragState::START);
SimulateUpEvent({ DRAG_SRC_X, DRAG_SRC_Y }, MMI::PointerEvent::SOURCE_TYPE_TOUCHSCREEN, TOUCH_POINTER_ID);
DragDropResult dropResult { DragResult::DRAG_SUCCESS, HAS_CUSTOM_ANIMATION, WINDOW_ID };
ret = InteractionManager::GetInstance()->StopDrag(dropResult);
ASSERT_EQ(ret, RET_OK);
ASSERT_TRUE(futureFlag.wait_for(std::chrono::milliseconds(PROMISE_WAIT_SPAN_MS)) !=
std::future_status::timeout);
ret = InteractionManager::GetInstance()->GetDragState(dragState);
FI_HILOGD("dragState:%{public}d", dragState);
EXPECT_EQ(ret, RET_OK);
EXPECT_EQ(dragState, DragState::STOP);
}
class HotAreaListenerTest : public IHotAreaListener {
public:
HotAreaListenerTest() {}

View File

@ -416,6 +416,13 @@ int32_t DeviceStatusClient::GetDragData(DragData &dragData)
return devicestatusProxy_->GetDragData(dragData);
}
int32_t DeviceStatusClient::GetDragState(DragState &dragState)
{
CALL_DEBUG_ENTER;
DEV_RET_IF_NULL_WITH_RET((Connect() != RET_OK), RET_ERR);
return devicestatusProxy_->GetDragState(dragState);
}
int32_t DeviceStatusClient::AddHotAreaListener()
{
CALL_DEBUG_ENTER;

View File

@ -64,6 +64,7 @@ public:
int32_t GetShadowOffset(int32_t& offsetX, int32_t& offsetY, int32_t& width, int32_t& height);
int32_t UpdateShadowPic(const ShadowInfo &shadowInfo);
int32_t GetDragData(DragData &dragData);
int32_t GetDragState(DragState &dragState);
int32_t AllocSocketPair(int32_t moduleType);
int32_t GetClientSocketFdOfAllocedSocketPair() const;
int32_t AddHotAreaListener();

View File

@ -205,6 +205,14 @@ public:
*/
int32_t AddHotAreaListener(std::shared_ptr<IHotAreaListener> listener);
/**
* @brief Obtains the dragging state.
* @param dragState Dragging state.
* @return Returns <b>0</b> if the operation is successful; returns other values if the operation fails.
* @since 10
*/
int32_t GetDragState(DragState &dragState);
/**
* @brief Unregisters a listener for screen hot area of the mouse pointer.
* @param listener Indicates the listener for screen hot area of the mouse pointer.

View File

@ -47,6 +47,7 @@
"OHOS::Msdp::DeviceStatus::InteractionManager::UpdateDragStyle(OHOS::Msdp::DeviceStatus::DragCursorStyle)";
"OHOS::Msdp::DeviceStatus::InteractionManager::UpdateShadowPic(OHOS::Msdp::DeviceStatus::ShadowInfo const&)";
"OHOS::Msdp::DeviceStatus::InteractionManager::GetDragData(OHOS::Msdp::DeviceStatus::DragData&)";
"OHOS::Msdp::DeviceStatus::InteractionManager::GetDragState(OHOS::Msdp::DeviceStatus::DragState&)";
"OHOS::Msdp::DeviceStatus::InteractionManager::AddHotAreaListener(std::__h::shared_ptr<OHOS::Msdp::IHotAreaListener>)";
"OHOS::Msdp::DeviceStatus::InteractionManager::RemoveHotAreaListener(std::__h::shared_ptr<OHOS::Msdp::IHotAreaListener>)";
};

View File

@ -58,6 +58,7 @@ public:
virtual int32_t GetShadowOffset(int32_t& offsetX, int32_t& offsetY, int32_t& width, int32_t& height) = 0;
virtual int32_t UpdateShadowPic(const ShadowInfo &shadowInfo) = 0;
virtual int32_t GetDragData(DragData &dragData) = 0;
virtual int32_t GetDragState(DragState &dragState) = 0;
virtual bool IsRunning() const
{
return true;

View File

@ -41,6 +41,7 @@ enum class DeviceInterfaceCode {
GET_SHADOW_OFFSET,
UPDATE_SHADOW_PIC,
GET_DRAG_DATA,
GET_DRAG_STATE,
ALLOC_SOCKET_FD = 40,
ADD_HOT_AREA_MONITOR = 50,
REMOVE_HOT_AREA_MONITOR

View File

@ -52,6 +52,7 @@ public:
virtual int32_t UpdateDragStyle(DragCursorStyle style) override;
virtual int32_t UpdateShadowPic(const ShadowInfo &shadowInfo) override;
virtual int32_t GetDragData(DragData &dragData) override;
virtual int32_t GetDragState(DragState &dragState) override;
virtual int32_t GetDragTargetPid() override;
virtual int32_t GetUdKey(std::string &udKey) override;
virtual int32_t AddDraglistener() override;

View File

@ -363,6 +363,30 @@ int32_t DeviceStatusSrvProxy::GetDragData(DragData &dragData)
return ret;
}
int32_t DeviceStatusSrvProxy::GetDragState(DragState &dragState)
{
CALL_DEBUG_ENTER;
MessageParcel data;
if (!data.WriteInterfaceToken(DeviceStatusSrvProxy::GetDescriptor())) {
FI_HILOGE("Failed to write descriptor");
return ERR_INVALID_VALUE;
}
MessageParcel reply;
MessageOption option;
sptr<IRemoteObject> remote = Remote();
CHKPR(remote, RET_ERR);
int32_t ret = remote->SendRequest(static_cast<uint32_t>(DeviceInterfaceCode::GET_DRAG_STATE), data, reply, option);
if (ret != RET_OK) {
FI_HILOGE("Send request failed, ret:%{public}d", ret);
return ret;
}
int32_t dragStateTmp = 0;
READINT32(reply, dragStateTmp, E_DEVICESTATUS_READ_PARCEL_ERROR);
dragState = static_cast<DragState>(dragStateTmp);
return ret;
}
int32_t DeviceStatusSrvProxy::GetCoordinationState(int32_t userData, const std::string &networkId)
{
CALL_DEBUG_ENTER;

View File

@ -61,6 +61,7 @@ private:
int32_t GetShadowOffsetStub(MessageParcel& data, MessageParcel& reply);
int32_t UpdateShadowPicStub(MessageParcel& data, MessageParcel& reply);
int32_t GetDragDataStub(MessageParcel& data, MessageParcel& reply);
int32_t GetDragStateStub(MessageParcel &data, MessageParcel &reply);
int32_t AddHotAreaListenerStub(MessageParcel& data, MessageParcel& reply);
int32_t RemoveHotAreaListenerStub(MessageParcel& data, MessageParcel& reply);
bool CheckCooperatePermission();

View File

@ -86,6 +86,8 @@ DeviceStatusSrvStub::DeviceStatusSrvStub()
&DeviceStatusSrvStub::GetDragDataStub},
{static_cast<uint32_t>(DeviceInterfaceCode::ADD_HOT_AREA_MONITOR),
&DeviceStatusSrvStub::AddHotAreaListenerStub},
{static_cast<uint32_t>(DeviceInterfaceCode::GET_DRAG_STATE),
&DeviceStatusSrvStub::GetDragStateStub},
{static_cast<uint32_t>(DeviceInterfaceCode::REMOVE_HOT_AREA_MONITOR),
&DeviceStatusSrvStub::RemoveHotAreaListenerStub}
};
@ -520,6 +522,20 @@ int32_t DeviceStatusSrvStub::AddHotAreaListenerStub(MessageParcel& data, Message
return ret;
}
int32_t DeviceStatusSrvStub::GetDragStateStub(MessageParcel &data, MessageParcel &reply)
{
CALL_DEBUG_ENTER;
DragState dragState;
int32_t ret = GetDragState(dragState);
if (ret != RET_OK) {
FI_HILOGE("Get DragState failed, ret:%{public}d", ret);
return RET_ERR;
}
int32_t dragStateTmp = static_cast<int32_t>(dragState);
WRITEINT32(reply, dragStateTmp, ERR_INVALID_VALUE);
return ret;
}
int32_t DeviceStatusSrvStub::RemoveHotAreaListenerStub(MessageParcel& data, MessageParcel& reply)
{
CALL_DEBUG_ENTER;

View File

@ -51,6 +51,7 @@ public:
int32_t UpdateDragStyle(DragCursorStyle style, int32_t targetPid, int32_t targetTid);
int32_t UpdateShadowPic(const ShadowInfo &shadowInfo);
int32_t GetDragData(DragData &dragData);
int32_t GetDragState(DragState &dragState);
void DragCallback(std::shared_ptr<MMI::PointerEvent> pointerEvent);
void OnDragUp(std::shared_ptr<MMI::PointerEvent> pointerEvent);
void OnDragMove(std::shared_ptr<MMI::PointerEvent> pointerEvent);

View File

@ -193,6 +193,17 @@ int32_t DragManager::GetDragData(DragData &dragData)
return RET_OK;
}
int32_t DragManager::GetDragState(DragState &dragState)
{
CALL_DEBUG_ENTER;
dragState = GetDragState();
if (dragState == DragState::ERROR) {
FI_HILOGE("dragState_ is error");
return RET_ERR;
}
return RET_OK;
}
int32_t DragManager::NotifyDragResult(DragResult result)
{
CALL_DEBUG_ENTER;

View File

@ -82,6 +82,7 @@ public:
int32_t GetShadowOffset(int32_t& offsetX, int32_t& offsetY, int32_t& width, int32_t& height) override;
int32_t UpdateShadowPic(const ShadowInfo &shadowInfo) override;
int32_t GetDragData(DragData &dragData) override;
int32_t GetDragState(DragState &dragState) override;
int32_t AllocSocketFd(const std::string &programName, int32_t moduleType,
int32_t &toReturnClientFd, int32_t &tokenType) override;
void OnConnected(SessionPtr s) override;

View File

@ -752,6 +752,18 @@ int32_t DeviceStatusService::GetDragData(DragData &dragData)
return ret;
}
int32_t DeviceStatusService::GetDragState(DragState &dragState)
{
CALL_DEBUG_ENTER;
int32_t ret = delegateTasks_.PostSyncTask(
std::bind(static_cast<int32_t(DragManager::*)(DragState&)>(&DragManager::GetDragState),
&dragMgr_, std::ref(dragState)));
if (ret != RET_OK) {
FI_HILOGE("Get drag state failed, ret:%{public}d", ret);
}
return ret;
}
int32_t DeviceStatusService::UpdateDragStyle(DragCursorStyle style)
{
CALL_DEBUG_ENTER;