diff --git a/bundle.json b/bundle.json index 2dba8d02e..c950f53a5 100644 --- a/bundle.json +++ b/bundle.json @@ -81,8 +81,10 @@ "include/stationary_manager.h", "interaction/include/coordination_message.h", "interaction/include/drag_data.h", + "interaction/include/drag_data_util.h", "interaction/include/i_coordination_listener.h", "interaction/include/i_drag_listener.h", + "interaction/include/i_start_drag_listener.h", "interaction/include/interaction_manager.h" ], "header_base": "//base/msdp/device_status/interfaces/innerkits" diff --git a/frameworks/native/interaction/include/drag_manager_impl.h b/frameworks/native/interaction/include/drag_manager_impl.h index c3dcf0106..cc243fed0 100644 --- a/frameworks/native/interaction/include/drag_manager_impl.h +++ b/frameworks/native/interaction/include/drag_manager_impl.h @@ -26,6 +26,7 @@ #include "devicestatus_define.h" #include "drag_data.h" #include "i_drag_listener.h" +#include "i_start_drag_listener.h" #include "i_subscript_listener.h" #include "include/util.h" @@ -37,9 +38,10 @@ public: DragManagerImpl() = default; ~DragManagerImpl() = default; - int32_t StartDrag(const DragData &dragData, std::function callback); + int32_t StartDrag(const DragData &dragData, std::shared_ptr listener); int32_t StopDrag(const DragDropResult &dropResult); int32_t OnNotifyResult(const StreamClient &client, NetPacket &pkt); + int32_t OnNotifyHideIcon(const StreamClient& client, NetPacket& pkt); int32_t OnStateChangedMessage(const StreamClient &client, NetPacket &pkt); int32_t OnDragStyleChangedMessage(const StreamClient &client, NetPacket &pkt); int32_t AddDraglistener(DragListenerPtr listener); @@ -66,8 +68,8 @@ private: std::atomic_bool hasRegistered_ { false }; std::atomic_bool hasSubscriptRegistered_ { false }; std::list dragListener_; + std::shared_ptr startDragListener_ { nullptr }; std::list subscriptListener_; - std::function stopCallback_ { nullptr }; }; } // namespace DeviceStatus } // namespace Msdp diff --git a/frameworks/native/interaction/include/interaction_manager_impl.h b/frameworks/native/interaction/include/interaction_manager_impl.h index 4cf7ab52b..d7de503d4 100644 --- a/frameworks/native/interaction/include/interaction_manager_impl.h +++ b/frameworks/native/interaction/include/interaction_manager_impl.h @@ -48,7 +48,7 @@ public: int32_t GetCoordinationState(const std::string &networkId, std::function callback, bool isCheckPermission = false); int32_t UpdateDragStyle(DragCursorStyle style); - int32_t StartDrag(const DragData &dragData, std::function callback); + int32_t StartDrag(const DragData &dragData, std::shared_ptr listener); int32_t StopDrag(const DragDropResult &dropResult); int32_t GetDragTargetPid(); int32_t GetUdKey(std::string &udKey); diff --git a/frameworks/native/interaction/src/drag_data_util.cpp b/frameworks/native/interaction/src/drag_data_util.cpp new file mode 100644 index 000000000..69e4cee7e --- /dev/null +++ b/frameworks/native/interaction/src/drag_data_util.cpp @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "drag_data_util.h" + +#include "parcel.h" + +#include "drag_data_packer.h" + +namespace OHOS { +namespace Msdp { +namespace DeviceStatus { +int32_t DragDataUtil::Marshalling(const DragData &dragData, Parcel &data) +{ + return DragDataPacker::Marshalling(dragData, data); +} + +int32_t DragDataUtil::UnMarshalling(Parcel &data, DragData &dragData) +{ + return DragDataPacker::UnMarshalling(data, dragData); +} +} // namespace DeviceStatus +} // namespace Msdp +} // namespace OHOS diff --git a/frameworks/native/interaction/src/drag_manager_impl.cpp b/frameworks/native/interaction/src/drag_manager_impl.cpp index cbafba7a4..ddc90c6f5 100644 --- a/frameworks/native/interaction/src/drag_manager_impl.cpp +++ b/frameworks/native/interaction/src/drag_manager_impl.cpp @@ -37,17 +37,19 @@ int32_t DragManagerImpl::UpdateDragStyle(DragCursorStyle style) return DeviceStatusClient::GetInstance().UpdateDragStyle(style); } -int32_t DragManagerImpl::StartDrag(const DragData &dragData, std::function callback) +int32_t DragManagerImpl::StartDrag(const DragData &dragData, std::shared_ptr listener) { CALL_DEBUG_ENTER; - CHKPR(callback, RET_ERR); - CHKPR(dragData.shadowInfo.pixelMap, RET_ERR); - if ((dragData.shadowInfo.x > 0) || (dragData.shadowInfo.y > 0) || - (dragData.shadowInfo.x < -dragData.shadowInfo.pixelMap->GetWidth()) || - (dragData.shadowInfo.y < -dragData.shadowInfo.pixelMap->GetHeight())) { - FI_HILOGE("Start drag, invalid parameter, shadowInfox:%{public}d, shadowInfoy:%{public}d", - dragData.shadowInfo.x, dragData.shadowInfo.y); - return RET_ERR; + CHKPR(listener, RET_ERR); + for (const auto& shadowInfo : dragData.shadowInfos) { + CHKPR(shadowInfo.pixelMap, RET_ERR); + if ((shadowInfo.x > 0) || (shadowInfo.y > 0) || + (shadowInfo.x < -shadowInfo.pixelMap->GetWidth()) || + (shadowInfo.y < -shadowInfo.pixelMap->GetHeight())) { + FI_HILOGE("Invalid parameter, shadowInfox:%{public}d, shadowInfoy:%{public}d", + shadowInfo.x, shadowInfo.y); + return RET_ERR; + } } if ((dragData.dragNum <= 0) || (dragData.buffer.size() > MAX_BUFFER_SIZE) || (dragData.displayX < 0) || (dragData.displayY < 0)) { @@ -58,7 +60,7 @@ int32_t DragManagerImpl::StartDrag(const DragData &dragData, std::function guard(mtx_); - stopCallback_ = callback; + startDragListener_ = listener; } return DeviceStatusClient::GetInstance().StartDrag(dragData); } @@ -98,8 +100,17 @@ int32_t DragManagerImpl::OnNotifyResult(const StreamClient &client, NetPacket &p } notifyMsg.result = static_cast(result); std::lock_guard guard(mtx_); - CHKPR(stopCallback_, RET_ERR); - stopCallback_(notifyMsg); + CHKPR(startDragListener_, RET_ERR); + startDragListener_->OnDragEndMessage(notifyMsg); + return RET_OK; +} + +int32_t DragManagerImpl::OnNotifyHideIcon(const StreamClient& client, NetPacket& pkt) +{ + CALL_DEBUG_ENTER; + std::lock_guard guard(mtx_); + CHKPR(startDragListener_, RET_ERR); + startDragListener_->OnHideIconMessage(); return RET_OK; } diff --git a/frameworks/native/interaction/src/interaction_manager.cpp b/frameworks/native/interaction/src/interaction_manager.cpp index cb8e2fe10..76be1ceb4 100644 --- a/frameworks/native/interaction/src/interaction_manager.cpp +++ b/frameworks/native/interaction/src/interaction_manager.cpp @@ -77,9 +77,9 @@ int32_t InteractionManager::UpdateDragStyle(DragCursorStyle style) return INTER_MGR_IMPL.UpdateDragStyle(style); } -int32_t InteractionManager::StartDrag(const DragData &dragData, std::function callback) +int32_t InteractionManager::StartDrag(const DragData &dragData, std::shared_ptr listener) { - return INTER_MGR_IMPL.StartDrag(dragData, callback); + return INTER_MGR_IMPL.StartDrag(dragData, listener); } int32_t InteractionManager::StopDrag(const DragDropResult &dropResult) diff --git a/frameworks/native/interaction/src/interaction_manager_impl.cpp b/frameworks/native/interaction/src/interaction_manager_impl.cpp index 25d48046d..372a3559d 100644 --- a/frameworks/native/interaction/src/interaction_manager_impl.cpp +++ b/frameworks/native/interaction/src/interaction_manager_impl.cpp @@ -68,6 +68,8 @@ void InteractionManagerImpl::InitMsgHandler() MsgCallbackBind2(&DragManagerImpl::OnNotifyResult, &dragManagerImpl_)}, {MessageId::DRAG_STATE_LISTENER, MsgCallbackBind2(&DragManagerImpl::OnStateChangedMessage, &dragManagerImpl_)}, + {MessageId::DRAG_NOTIFY_HIDE_ICON, + MsgCallbackBind2(&DragManagerImpl::OnNotifyHideIcon, &dragManagerImpl_)}, {MessageId::DRAG_STYLE_LISTENER, MsgCallbackBind2(&DragManagerImpl::OnDragStyleChangedMessage, &dragManagerImpl_)} }; @@ -217,7 +219,7 @@ int32_t InteractionManagerImpl::UpdateDragStyle(DragCursorStyle style) return dragManagerImpl_.UpdateDragStyle(style); } -int32_t InteractionManagerImpl::StartDrag(const DragData &dragData, std::function callback) +int32_t InteractionManagerImpl::StartDrag(const DragData &dragData, std::shared_ptr listener) { CALL_DEBUG_ENTER; std::lock_guard guard(mutex_); @@ -225,7 +227,7 @@ int32_t InteractionManagerImpl::StartDrag(const DragData &dragData, std::functio FI_HILOGE("Get client is nullptr"); return RET_ERR; } - return dragManagerImpl_.StartDrag(dragData, callback); + return dragManagerImpl_.StartDrag(dragData, listener); } int32_t InteractionManagerImpl::StopDrag(const DragDropResult &dropResult) diff --git a/frameworks/native/interaction/test/unittest/src/interaction_drag_drawing_test.cpp b/frameworks/native/interaction/test/unittest/src/interaction_drag_drawing_test.cpp index fbd1e7de8..c65319c8a 100644 --- a/frameworks/native/interaction/test/unittest/src/interaction_drag_drawing_test.cpp +++ b/frameworks/native/interaction/test/unittest/src/interaction_drag_drawing_test.cpp @@ -46,6 +46,9 @@ constexpr int32_t DISPLAY_ID { 0 }; constexpr int32_t DISPLAY_X { 50 }; constexpr int32_t DISPLAY_Y { 50 }; constexpr int32_t DRAG_NUM_ONE { 1 }; +constexpr int32_t SHADOW_NUM_ONE { 1 }; +constexpr int32_t SHADOW_NUM_MULTIPLE { 3 }; +constexpr int32_t SHADOW_NUM_TOO_MUCH { 5 }; constexpr int32_t DRAG_NUM_MULTIPLE { 10 }; constexpr int32_t INT32_BYTE { 4 }; constexpr int32_t PROMISE_WAIT_SPAN_MS { 2000 }; @@ -67,7 +70,7 @@ public: static void SetUpTestCase(); static std::shared_ptr CreatePixelMap(int32_t width, int32_t height); static std::optional CreateDragData(int32_t sourceType, int32_t pointerId, int32_t dragNum, - bool hasCoordinateCorrected); + bool hasCoordinateCorrected, int32_t shadowNum); }; void InteractionDragDrawingTest::SetUpTestCase() {} @@ -113,19 +116,40 @@ std::shared_ptr InteractionDragDrawingTest::CreatePixelMap(int3 return pixelMap; } +class TestStartDragListener : public IStartDragListener { +public: + explicit TestStartDragListener(std::function function) : function_(function) { } + void OnDragEndMessage(const DragNotifyMsg &msg) override + { + FI_HILOGD("DisplayX:%{public}d, displayY:%{public}d, targetPid:%{public}d, result:%{public}d", + msg.displayX, msg.displayY, msg.targetPid, static_cast(msg.result)); + if (function_ != nullptr) { + function_(msg); + } + FI_HILOGD("Test OnDragEndMessage"); + } + + void OnHideIconMessage() override + { + FI_HILOGI("Test OnHideIconMessage"); + } +private: + std::function function_; +}; + std::optional InteractionDragDrawingTest::CreateDragData(int32_t sourceType, - int32_t pointerId, int32_t dragNum, bool hasCoordinateCorrected) + int32_t pointerId, int32_t dragNum, bool hasCoordinateCorrected, int32_t shadowNum) { CALL_DEBUG_ENTER; - std::shared_ptr pixelMap = CreatePixelMap(PIXEL_MAP_WIDTH, PIXEL_MAP_HEIGHT); - if (pixelMap == nullptr) { - FI_HILOGE("CreatePixelMap failed"); - return std::nullopt; - } DragData dragData; - dragData.shadowInfo.pixelMap = pixelMap; - dragData.shadowInfo.x = 0; - dragData.shadowInfo.y = 0; + for (int32_t i = 0; i < shadowNum; i++) { + std::shared_ptr pixelMap = CreatePixelMap(PIXEL_MAP_WIDTH, PIXEL_MAP_HEIGHT); + if (pixelMap == nullptr) { + FI_HILOGE("CreatePixelMap failed"); + return std::nullopt; + } + dragData.shadowInfos.push_back({ pixelMap, 0, 0 }); + } dragData.buffer = std::vector(MAX_BUFFER_SIZE, 0); dragData.udKey = UD_KEY; dragData.extraInfo = FILTER_INFO; @@ -151,7 +175,7 @@ HWTEST_F(InteractionDragDrawingTest, InteractionDragDrawingTest_Mouse_DragNum_On { CALL_TEST_DEBUG; std::optional dragData = CreateDragData( - MMI::PointerEvent::SOURCE_TYPE_MOUSE, POINTER_ID, DRAG_NUM_ONE, false); + MMI::PointerEvent::SOURCE_TYPE_MOUSE, POINTER_ID, DRAG_NUM_ONE, false, SHADOW_NUM_ONE); ASSERT_TRUE(dragData); std::promise promiseFlag; std::future futureFlag = promiseFlag.get_future(); @@ -160,7 +184,8 @@ HWTEST_F(InteractionDragDrawingTest, InteractionDragDrawingTest_Mouse_DragNum_On notifyMessage.displayX, notifyMessage.displayY, notifyMessage.result, notifyMessage.targetPid); promiseFlag.set_value(true); }; - int32_t ret = InteractionManager::GetInstance()->StartDrag(dragData.value(), callback); + int32_t ret = InteractionManager::GetInstance()->StartDrag(dragData.value(), + std::make_shared(callback)); ASSERT_EQ(ret, RET_OK); ret = InteractionManager::GetInstance()->SetDragWindowVisible(DRAG_WINDOW_VISIBLE); ASSERT_EQ(ret, RET_OK); @@ -202,9 +227,10 @@ HWTEST_F(InteractionDragDrawingTest, InteractionDragDrawingTest_Mouse_DragNum_Mu promiseFlag.set_value(true); }; std::optional dragData = CreateDragData( - MMI::PointerEvent::SOURCE_TYPE_MOUSE, POINTER_ID, DRAG_NUM_MULTIPLE, false); + MMI::PointerEvent::SOURCE_TYPE_MOUSE, POINTER_ID, DRAG_NUM_MULTIPLE, false, SHADOW_NUM_ONE); ASSERT_TRUE(dragData); - int32_t ret = InteractionManager::GetInstance()->StartDrag(dragData.value(), callback); + int32_t ret = InteractionManager::GetInstance()->StartDrag(dragData.value(), + std::make_shared(callback)); ASSERT_EQ(ret, RET_OK); ret = InteractionManager::GetInstance()->SetDragWindowVisible(DRAG_WINDOW_VISIBLE); ASSERT_EQ(ret, RET_OK); @@ -246,9 +272,10 @@ HWTEST_F(InteractionDragDrawingTest, InteractionDragDrawingTest_Touchscreen_Drag promiseFlag.set_value(true); }; std::optional dragData = CreateDragData( - MMI::PointerEvent::SOURCE_TYPE_TOUCHSCREEN, POINTER_ID, DRAG_NUM_ONE, false); + MMI::PointerEvent::SOURCE_TYPE_TOUCHSCREEN, POINTER_ID, DRAG_NUM_ONE, false, SHADOW_NUM_ONE); ASSERT_TRUE(dragData); - int32_t ret = InteractionManager::GetInstance()->StartDrag(dragData.value(), callback); + int32_t ret = InteractionManager::GetInstance()->StartDrag(dragData.value(), + std::make_shared(callback)); ASSERT_EQ(ret, RET_OK); ret = InteractionManager::GetInstance()->SetDragWindowVisible(DRAG_WINDOW_VISIBLE); ASSERT_EQ(ret, RET_OK); @@ -280,7 +307,7 @@ HWTEST_F(InteractionDragDrawingTest, InteractionDragDrawingTest_Touchscreen_Drag { CALL_TEST_DEBUG; std::optional dragData = CreateDragData( - MMI::PointerEvent::SOURCE_TYPE_TOUCHSCREEN, POINTER_ID, DRAG_NUM_MULTIPLE, false); + MMI::PointerEvent::SOURCE_TYPE_TOUCHSCREEN, POINTER_ID, DRAG_NUM_MULTIPLE, false, SHADOW_NUM_ONE); ASSERT_TRUE(dragData); std::promise promiseFlag; std::future futureFlag = promiseFlag.get_future(); @@ -289,7 +316,8 @@ HWTEST_F(InteractionDragDrawingTest, InteractionDragDrawingTest_Touchscreen_Drag notifyMessage.displayX, notifyMessage.displayY, notifyMessage.result); promiseFlag.set_value(true); }; - int32_t ret = InteractionManager::GetInstance()->StartDrag(dragData.value(), callback); + int32_t ret = InteractionManager::GetInstance()->StartDrag(dragData.value(), + std::make_shared(callback)); ASSERT_EQ(ret, RET_OK); ret = InteractionManager::GetInstance()->SetDragWindowVisible(DRAG_WINDOW_VISIBLE); ASSERT_EQ(ret, RET_OK); @@ -328,9 +356,10 @@ HWTEST_F(InteractionDragDrawingTest, InteractionDragDrawingTest_UpdateShadowPic, promiseFlag.set_value(true); }; std::optional dragData = CreateDragData( - MMI::PointerEvent::SOURCE_TYPE_MOUSE, POINTER_ID, DRAG_NUM_ONE, false); + MMI::PointerEvent::SOURCE_TYPE_MOUSE, POINTER_ID, DRAG_NUM_ONE, false, SHADOW_NUM_ONE); ASSERT_TRUE(dragData); - int32_t ret = InteractionManager::GetInstance()->StartDrag(dragData.value(), callback); + int32_t ret = InteractionManager::GetInstance()->StartDrag(dragData.value(), + std::make_shared(callback)); ASSERT_EQ(ret, RET_OK); std::shared_ptr pixelMap = CreatePixelMap(MIDDLE_PIXEL_MAP_WIDTH, MIDDLE_PIXEL_MAP_HEIGHT); ASSERT_NE(pixelMap, nullptr); @@ -365,9 +394,10 @@ HWTEST_F(InteractionDragDrawingTest, InteractionDragDrawingTest_Mouse_Animation, promiseFlag.set_value(true); }; std::optional dragData = CreateDragData( - MMI::PointerEvent::SOURCE_TYPE_MOUSE, POINTER_ID, DRAG_NUM_ONE, false); + MMI::PointerEvent::SOURCE_TYPE_MOUSE, POINTER_ID, DRAG_NUM_ONE, false, SHADOW_NUM_ONE); ASSERT_TRUE(dragData); - int32_t ret = InteractionManager::GetInstance()->StartDrag(dragData.value(), callback); + int32_t ret = InteractionManager::GetInstance()->StartDrag(dragData.value(), + std::make_shared(callback)); ASSERT_EQ(ret, RET_OK); ret = InteractionManager::GetInstance()->SetDragWindowVisible(DRAG_WINDOW_VISIBLE); ASSERT_EQ(ret, RET_OK); @@ -397,9 +427,106 @@ HWTEST_F(InteractionDragDrawingTest, InteractionDragDrawingTest_Touchscreen_Anim promiseFlag.set_value(true); }; std::optional dragData = CreateDragData( - MMI::PointerEvent::SOURCE_TYPE_TOUCHSCREEN, POINTER_ID, DRAG_NUM_ONE, false); + MMI::PointerEvent::SOURCE_TYPE_TOUCHSCREEN, POINTER_ID, DRAG_NUM_ONE, false, SHADOW_NUM_ONE); ASSERT_TRUE(dragData); - int32_t ret = InteractionManager::GetInstance()->StartDrag(dragData.value(), callback); + int32_t ret = InteractionManager::GetInstance()->StartDrag(dragData.value(), + std::make_shared(callback)); + ASSERT_EQ(ret, RET_OK); + ret = InteractionManager::GetInstance()->SetDragWindowVisible(DRAG_WINDOW_VISIBLE); + ASSERT_EQ(ret, RET_OK); + ret = InteractionManager::GetInstance()->UpdateDragStyle(DragCursorStyle::COPY); + ASSERT_EQ(ret, RET_OK); + DragDropResult dropResult { DragResult::DRAG_FAIL, 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); +} + +/** + * @tc.name: InteractionDragDrawingTest_Multiple_Shadow + * @tc.desc: Drag Drawing + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(InteractionDragDrawingTest, InteractionDragDrawingTest_ONE_Shadow, TestSize.Level1) +{ + CALL_TEST_DEBUG; + std::promise promiseFlag; + std::future 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); + }; + std::optional dragData = CreateDragData( + MMI::PointerEvent::SOURCE_TYPE_TOUCHSCREEN, POINTER_ID, DRAG_NUM_ONE, false, SHADOW_NUM_ONE); + ASSERT_TRUE(dragData); + int32_t ret = InteractionManager::GetInstance()->StartDrag(dragData.value(), + std::make_shared(callback)); + ASSERT_EQ(ret, RET_OK); + ret = InteractionManager::GetInstance()->SetDragWindowVisible(DRAG_WINDOW_VISIBLE); + ASSERT_EQ(ret, RET_OK); + ret = InteractionManager::GetInstance()->UpdateDragStyle(DragCursorStyle::COPY); + ASSERT_EQ(ret, RET_OK); + DragDropResult dropResult { DragResult::DRAG_FAIL, 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); +} + +/** + * @tc.name: InteractionDragDrawingTest_Multiple_Shadow + * @tc.desc: Drag Drawing + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(InteractionDragDrawingTest, InteractionDragDrawingTest_Multiple_Shadow, TestSize.Level1) +{ + CALL_TEST_DEBUG; + std::promise promiseFlag; + std::future 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); + }; + std::optional dragData = CreateDragData( + MMI::PointerEvent::SOURCE_TYPE_TOUCHSCREEN, POINTER_ID, DRAG_NUM_ONE, false, SHADOW_NUM_MULTIPLE); + ASSERT_TRUE(dragData); + int32_t ret = InteractionManager::GetInstance()->StartDrag(dragData.value(), + std::make_shared(callback)); + ASSERT_EQ(ret, RET_OK); + ret = InteractionManager::GetInstance()->SetDragWindowVisible(DRAG_WINDOW_VISIBLE); + ASSERT_EQ(ret, RET_OK); + ret = InteractionManager::GetInstance()->UpdateDragStyle(DragCursorStyle::COPY); + ASSERT_EQ(ret, RET_OK); + DragDropResult dropResult { DragResult::DRAG_FAIL, 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); +} + +/** + * @tc.name: InteractionDragDrawingTest_Multiple_Shadow + * @tc.desc: Drag Drawing + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(InteractionDragDrawingTest, InteractionDragDrawingTest_Too_Much_Shadow, TestSize.Level1) +{ + CALL_TEST_DEBUG; + std::promise promiseFlag; + std::future 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); + }; + std::optional dragData = CreateDragData( + MMI::PointerEvent::SOURCE_TYPE_TOUCHSCREEN, POINTER_ID, DRAG_NUM_ONE, false, SHADOW_NUM_TOO_MUCH); + ASSERT_TRUE(dragData); + int32_t ret = InteractionManager::GetInstance()->StartDrag(dragData.value(), + std::make_shared(callback)); ASSERT_EQ(ret, RET_OK); ret = InteractionManager::GetInstance()->SetDragWindowVisible(DRAG_WINDOW_VISIBLE); ASSERT_EQ(ret, RET_OK); @@ -409,7 +536,6 @@ HWTEST_F(InteractionDragDrawingTest, InteractionDragDrawingTest_Touchscreen_Anim 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); - std::this_thread::sleep_for(std::chrono::milliseconds(TIME_WAIT_FOR_ANIMATION_END)); } /** @@ -429,9 +555,10 @@ HWTEST_F(InteractionDragDrawingTest, EnterTextEditorArea001, TestSize.Level1) promiseFlag.set_value(true); }; std::optional dragData = CreateDragData( - MMI::PointerEvent::SOURCE_TYPE_TOUCHSCREEN, POINTER_ID, DRAG_NUM_ONE, false); + MMI::PointerEvent::SOURCE_TYPE_TOUCHSCREEN, POINTER_ID, DRAG_NUM_ONE, false, SHADOW_NUM_ONE); ASSERT_TRUE(dragData); - int32_t ret = InteractionManager::GetInstance()->StartDrag(dragData.value(), callback); + int32_t ret = InteractionManager::GetInstance()->StartDrag(dragData.value(), + std::make_shared(callback)); ASSERT_EQ(ret, RET_OK); ret = InteractionManager::GetInstance()->EnterTextEditorArea(true); EXPECT_EQ(ret, RET_OK); @@ -461,9 +588,10 @@ HWTEST_F(InteractionDragDrawingTest, EnterTextEditorArea002, TestSize.Level1) promiseFlag.set_value(true); }; std::optional dragData = CreateDragData( - MMI::PointerEvent::SOURCE_TYPE_TOUCHSCREEN, POINTER_ID, DRAG_NUM_ONE, false); + MMI::PointerEvent::SOURCE_TYPE_TOUCHSCREEN, POINTER_ID, DRAG_NUM_ONE, false, SHADOW_NUM_ONE); ASSERT_TRUE(dragData); - int32_t ret = InteractionManager::GetInstance()->StartDrag(dragData.value(), callback); + int32_t ret = InteractionManager::GetInstance()->StartDrag(dragData.value(), + std::make_shared(callback)); ASSERT_EQ(ret, RET_OK); ret = InteractionManager::GetInstance()->EnterTextEditorArea(false); EXPECT_EQ(ret, RET_ERR); @@ -483,7 +611,7 @@ HWTEST_F(InteractionDragDrawingTest, EnterTextEditorArea003, TestSize.Level1) { CALL_TEST_DEBUG; std::optional dragData = CreateDragData( - MMI::PointerEvent::SOURCE_TYPE_TOUCHSCREEN, POINTER_ID, DRAG_NUM_ONE, true); + MMI::PointerEvent::SOURCE_TYPE_TOUCHSCREEN, POINTER_ID, DRAG_NUM_ONE, true, SHADOW_NUM_ONE); ASSERT_TRUE(dragData); int32_t ret = InteractionManager::GetInstance()->EnterTextEditorArea(true); EXPECT_EQ(ret, RET_ERR); diff --git a/frameworks/native/interaction/test/unittest/src/interaction_manager_test.cpp b/frameworks/native/interaction/test/unittest/src/interaction_manager_test.cpp index e047d84f7..834da39f5 100644 --- a/frameworks/native/interaction/test/unittest/src/interaction_manager_test.cpp +++ b/frameworks/native/interaction/test/unittest/src/interaction_manager_test.cpp @@ -25,12 +25,14 @@ #include #include "input_device.h" #include "input_manager.h" +#include "parcel.h" #include "pointer_event.h" #include "securec.h" #include "coordination_message.h" #include "devicestatus_define.h" #include "devicestatus_errors.h" +#include "drag_data_util.h" #include "interaction_manager.h" #include "nativetoken_kit.h" #include "token_setproc.h" @@ -242,6 +244,27 @@ private: std::string moduleName_; }; +class TestStartDragListener : public IStartDragListener { +public: + explicit TestStartDragListener(std::function function) : function_(function) { } + void OnDragEndMessage(const DragNotifyMsg &msg) override + { + FI_HILOGD("DisplayX:%{public}d, displayY:%{public}d, targetPid:%{public}d, result:%{public}d", + msg.displayX, msg.displayY, msg.targetPid, static_cast(msg.result)); + if (function_ != nullptr) { + function_(msg); + } + FI_HILOGD("Test OnDragEndMessage"); + } + + void OnHideIconMessage() override + { + FI_HILOGI("Test OnHideIconMessage"); + } +private: + std::function function_; +}; + std::vector InteractionManagerTest::GetInputDeviceIds() { std::vector realDeviceIds; @@ -339,10 +362,9 @@ std::optional InteractionManagerTest::CreateDragData(const std::pair(MAX_BUFFER_SIZE, 0); dragData.udKey = UD_KEY; dragData.sourceType = sourceType; @@ -464,17 +486,19 @@ void InteractionManagerTest::TestRemoveMonitor(int32_t monitorId) void InteractionManagerTest::PrintDragData(const DragData &dragData) { CALL_DEBUG_ENTER; - FI_HILOGD("PixelAlphaType:%{public}d, PixelFormat:%{public}d, PixelAllocatorType:%{public}d," - " PixelWidth:%{public}d, PixelHeight:%{public}d, shadowX:%{public}d, shadowY:%{public}d," - " sourceType:%{public}d, pointerId:%{public}d, displayId:%{public}d, displayX:%{public}d," + for (const auto &shadowInfo : dragData.shadowInfos) { + CHKPV(shadowInfo.pixelMap); + FI_HILOGD("PixelFormat:%{public}d, PixelAlphaType:%{public}d, PixelAllocatorType:%{public}d," + " PixelWidth:%{public}d, PixelHeight:%{public}d, shadowX:%{public}d, shadowY:%{public}d", + static_cast(shadowInfo.pixelMap->GetPixelFormat()), + static_cast(shadowInfo.pixelMap->GetAlphaType()), + static_cast(shadowInfo.pixelMap->GetAllocatorType()), + shadowInfo.pixelMap->GetWidth(), shadowInfo.pixelMap->GetHeight(), shadowInfo.x, shadowInfo.y); + } + FI_HILOGD("SourceType:%{public}d, pointerId:%{public}d, displayId:%{public}d, displayX:%{public}d," " displayY:%{public}d, dragNum:%{public}d, hasCanceledAnimation:%{public}d, udKey:%{public}s", - static_cast(dragData.shadowInfo.pixelMap->GetAlphaType()), - static_cast(dragData.shadowInfo.pixelMap->GetPixelFormat()), - static_cast(dragData.shadowInfo.pixelMap->GetAllocatorType()), - dragData.shadowInfo.pixelMap->GetWidth(), dragData.shadowInfo.pixelMap->GetHeight(), - dragData.shadowInfo.x, dragData.shadowInfo.y, dragData.sourceType, dragData.pointerId, - dragData.displayId, dragData.displayX, dragData.displayY, dragData.dragNum, dragData.hasCanceledAnimation, - dragData.udKey.substr(0, SUBSTR_UDKEY_LEN).c_str()); + dragData.sourceType, dragData.pointerId, dragData.displayId, dragData.displayX, dragData.displayY, + dragData.dragNum, dragData.hasCanceledAnimation, dragData.udKey.substr(0, SUBSTR_UDKEY_LEN).c_str()); } void InteractionManagerTest::SetupKeyEvent( @@ -833,7 +857,8 @@ HWTEST_F(InteractionManagerTest, InteractionManagerTest_Draglistener_Mouse, Test std::optional 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); - ret = InteractionManager::GetInstance()->StartDrag(dragData.value(), callback); + ret = InteractionManager::GetInstance()->StartDrag(dragData.value(), + std::make_shared(callback)); ASSERT_EQ(ret, RET_OK); ret = InteractionManager::GetInstance()->SetDragWindowVisible(true); EXPECT_EQ(ret, RET_OK); @@ -875,7 +900,8 @@ HWTEST_F(InteractionManagerTest, InteractionManagerTest_Draglistener_Touch, Test std::optional dragData = CreateDragData({ MAX_PIXEL_MAP_WIDTH, MAX_PIXEL_MAP_HEIGHT }, MMI::PointerEvent::SOURCE_TYPE_TOUCHSCREEN, TOUCH_POINTER_ID, DISPLAY_ID, { DRAG_SRC_X, DRAG_SRC_Y }); ASSERT_TRUE(dragData); - ret = InteractionManager::GetInstance()->StartDrag(dragData.value(), callback); + ret = InteractionManager::GetInstance()->StartDrag(dragData.value(), + std::make_shared(callback)); ASSERT_EQ(ret, RET_OK); SimulateMovePointerEvent({ DRAG_SRC_X, DRAG_SRC_Y }, { DRAG_DST_X, DRAG_DST_Y }, MMI::PointerEvent::SOURCE_TYPE_TOUCHSCREEN, TOUCH_POINTER_ID, true); @@ -923,7 +949,8 @@ HWTEST_F(InteractionManagerTest, InteractionManagerTest_Draglistener, TestSize.L notifyMessage.displayX, notifyMessage.displayY, notifyMessage.result, notifyMessage.targetPid); promiseFlag.set_value(true); }; - ret = InteractionManager::GetInstance()->StartDrag(dragData.value(), callback); + ret = InteractionManager::GetInstance()->StartDrag(dragData.value(), + std::make_shared(callback)); ASSERT_EQ(ret, RET_OK); SimulateMovePointerEvent({ DRAG_SRC_X, DRAG_SRC_Y }, { DRAG_DST_X, DRAG_DST_Y }, MMI::PointerEvent::SOURCE_TYPE_TOUCHSCREEN, TOUCH_POINTER_ID, true); @@ -971,7 +998,8 @@ HWTEST_F(InteractionManagerTest, InteractionManagerTest_SubscriptListener_001, T std::optional dragData = CreateDragData({ MAX_PIXEL_MAP_WIDTH, MAX_PIXEL_MAP_HEIGHT }, MMI::PointerEvent::SOURCE_TYPE_TOUCHSCREEN, TOUCH_POINTER_ID, DISPLAY_ID, { DRAG_SRC_X, DRAG_SRC_Y }); ASSERT_TRUE(dragData); - ret = InteractionManager::GetInstance()->StartDrag(dragData.value(), callback); + ret = InteractionManager::GetInstance()->StartDrag(dragData.value(), + std::make_shared(callback)); ASSERT_EQ(ret, RET_OK); SimulateMovePointerEvent({ DRAG_SRC_X, DRAG_SRC_Y }, { DRAG_DST_X, DRAG_DST_Y }, MMI::PointerEvent::SOURCE_TYPE_TOUCHSCREEN, TOUCH_POINTER_ID, true); @@ -1016,7 +1044,8 @@ HWTEST_F(InteractionManagerTest, InteractionManagerTest_SubscriptListener_002, T ASSERT_TRUE(dragData); SimulateDownPointerEvent( { DRAG_SRC_X, DRAG_SRC_Y }, MMI::PointerEvent::SOURCE_TYPE_TOUCHSCREEN, TOUCH_POINTER_ID); - ret = InteractionManager::GetInstance()->StartDrag(dragData.value(), callback); + ret = InteractionManager::GetInstance()->StartDrag(dragData.value(), + std::make_shared(callback)); ASSERT_EQ(ret, RET_OK); ret = InteractionManager::GetInstance()->SetDragWindowVisible(true); ASSERT_EQ(ret, RET_OK); @@ -1065,7 +1094,8 @@ HWTEST_F(InteractionManagerTest, InteractionManagerTest_StartDrag_Mouse, TestSiz std::optional 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); + int32_t ret = InteractionManager::GetInstance()->StartDrag(dragData.value(), + std::make_shared(callback)); ASSERT_EQ(ret, RET_OK); ret = InteractionManager::GetInstance()->SetDragWindowVisible(true); EXPECT_EQ(ret, RET_OK); @@ -1105,9 +1135,9 @@ HWTEST_F(InteractionManagerTest, InteractionManagerTest_StartDrag_Failed_Mouse, int32_t ret = InteractionManager::GetInstance()->StartDrag(dragData.value(), nullptr); ASSERT_EQ(ret, RET_ERR); - - dragData->shadowInfo.pixelMap = nullptr; - ret = InteractionManager::GetInstance()->StartDrag(dragData.value(), callback); + dragData->shadowInfos = {}; + ret = InteractionManager::GetInstance()->StartDrag(dragData.value(), + std::make_shared(callback)); ASSERT_EQ(ret, RET_ERR); } } @@ -1136,7 +1166,8 @@ HWTEST_F(InteractionManagerTest, InteractionManagerTest_StopDrag_Mouse, TestSize std::optional 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); + int32_t ret = InteractionManager::GetInstance()->StartDrag(dragData.value(), + std::make_shared(callback)); ASSERT_EQ(ret, RET_OK); DragDropResult dropResult { DragResult::DRAG_SUCCESS, HAS_CUSTOM_ANIMATION, WINDOW_ID }; InteractionManager::GetInstance()->StopDrag(dropResult); @@ -1195,7 +1226,8 @@ HWTEST_F(InteractionManagerTest, InteractionManagerTest_StartDrag_Touch, TestSiz notifyMessage.displayX, notifyMessage.displayY, notifyMessage.result, notifyMessage.targetPid); promiseFlag.set_value(true); }; - int32_t ret = InteractionManager::GetInstance()->StartDrag(dragData.value(), callback); + int32_t ret = InteractionManager::GetInstance()->StartDrag(dragData.value(), + std::make_shared(callback)); ASSERT_EQ(ret, RET_OK); ret = InteractionManager::GetInstance()->SetDragWindowVisible(true); EXPECT_EQ(ret, RET_OK); @@ -1233,7 +1265,8 @@ HWTEST_F(InteractionManagerTest, InteractionManagerTest_StopDrag_Touch, TestSize std::optional dragData = CreateDragData({ TEST_PIXEL_MAP_WIDTH, TEST_PIXEL_MAP_HEIGHT }, MMI::PointerEvent::SOURCE_TYPE_TOUCHSCREEN, TOUCH_POINTER_ID, DISPLAY_ID, { DRAG_SRC_X, DRAG_SRC_Y }); ASSERT_TRUE(dragData); - int32_t ret = InteractionManager::GetInstance()->StartDrag(dragData.value(), callback); + int32_t ret = InteractionManager::GetInstance()->StartDrag(dragData.value(), + std::make_shared(callback)); ASSERT_EQ(ret, RET_OK); DragDropResult dropResult { DragResult::DRAG_SUCCESS, HAS_CUSTOM_ANIMATION, WINDOW_ID }; InteractionManager::GetInstance()->StopDrag(dropResult); @@ -1266,7 +1299,8 @@ HWTEST_F(InteractionManagerTest, GetDragTargetPid_Mouse, TestSize.Level1) std::optional 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); + int32_t ret = InteractionManager::GetInstance()->StartDrag(dragData.value(), + std::make_shared(callback)); ASSERT_EQ(ret, RET_OK); ret = InteractionManager::GetInstance()->SetDragWindowVisible(true); EXPECT_EQ(ret, RET_OK); @@ -1307,7 +1341,8 @@ HWTEST_F(InteractionManagerTest, GetDragTargetPid_Touch, TestSize.Level1) std::optional dragData = CreateDragData({ TEST_PIXEL_MAP_WIDTH, TEST_PIXEL_MAP_HEIGHT }, MMI::PointerEvent::SOURCE_TYPE_TOUCHSCREEN, TOUCH_POINTER_ID, DISPLAY_ID, { DRAG_SRC_X, DRAG_SRC_Y }); ASSERT_TRUE(dragData); - int32_t ret = InteractionManager::GetInstance()->StartDrag(dragData.value(), callback); + int32_t ret = InteractionManager::GetInstance()->StartDrag(dragData.value(), + std::make_shared(callback)); ASSERT_EQ(ret, RET_OK); ret = InteractionManager::GetInstance()->SetDragWindowVisible(true); EXPECT_EQ(ret, RET_OK); @@ -1346,7 +1381,8 @@ HWTEST_F(InteractionManagerTest, TouchEventDispatch, TestSize.Level1) std::optional dragData = CreateDragData({ TEST_PIXEL_MAP_WIDTH, TEST_PIXEL_MAP_HEIGHT }, MMI::PointerEvent::SOURCE_TYPE_TOUCHSCREEN, TOUCH_POINTER_ID, DISPLAY_ID, { DRAG_SRC_X, DRAG_SRC_Y }); ASSERT_TRUE(dragData); - int32_t ret = InteractionManager::GetInstance()->StartDrag(dragData.value(), callback); + int32_t ret = InteractionManager::GetInstance()->StartDrag(dragData.value(), + std::make_shared(callback)); ASSERT_EQ(ret, RET_OK); std::promise promiseEventFlag; std::future futureEventFlag = promiseEventFlag.get_future(); @@ -1387,7 +1423,8 @@ HWTEST_F(InteractionManagerTest, MouseEventDispatch, TestSize.Level1) std::optional dragData = CreateDragData({ TEST_PIXEL_MAP_WIDTH, TEST_PIXEL_MAP_HEIGHT }, MMI::PointerEvent::SOURCE_TYPE_MOUSE, 0, DISPLAY_ID, { DRAG_SRC_X, DRAG_SRC_Y }); ASSERT_TRUE(dragData); - int32_t ret = InteractionManager::GetInstance()->StartDrag(dragData.value(), callback); + int32_t ret = InteractionManager::GetInstance()->StartDrag(dragData.value(), + std::make_shared(callback)); ASSERT_EQ(ret, RET_OK); std::promise promiseEventFlag; std::future futureEventFlag = promiseEventFlag.get_future(); @@ -1449,7 +1486,8 @@ HWTEST_F(InteractionManagerTest, InteractionManagerTest_GetShadowOffset, TestSiz std::optional dragData = CreateDragData({ TEST_PIXEL_MAP_WIDTH, TEST_PIXEL_MAP_HEIGHT }, MMI::PointerEvent::SOURCE_TYPE_TOUCHSCREEN, TOUCH_POINTER_ID, DISPLAY_ID, { DRAG_SRC_X, DRAG_SRC_Y }); ASSERT_TRUE(dragData); - int32_t ret = InteractionManager::GetInstance()->StartDrag(dragData.value(), callback); + int32_t ret = InteractionManager::GetInstance()->StartDrag(dragData.value(), + std::make_shared(callback)); ASSERT_EQ(ret, RET_OK); ret = InteractionManager::GetInstance()->GetShadowOffset(offsetX, offsetY, width, height); FI_HILOGD("offsetX:%{public}d, offsetY:%{public}d, width:%{public}d, height:%{public}d", @@ -1485,7 +1523,8 @@ HWTEST_F(InteractionManagerTest, GetUdKey_Mouse, TestSize.Level1) notifyMessage.displayX, notifyMessage.displayY, notifyMessage.result, notifyMessage.targetPid); promiseFlag.set_value(true); }; - int32_t ret = InteractionManager::GetInstance()->StartDrag(dragData.value(), callback); + int32_t ret = InteractionManager::GetInstance()->StartDrag(dragData.value(), + std::make_shared(callback)); ASSERT_EQ(ret, RET_OK); std::string udKey; ret = InteractionManager::GetInstance()->GetUdKey(udKey); @@ -1524,7 +1563,8 @@ HWTEST_F(InteractionManagerTest, GetUdKey_Touch, TestSize.Level1) std::optional dragData = CreateDragData({ TEST_PIXEL_MAP_WIDTH, TEST_PIXEL_MAP_HEIGHT }, MMI::PointerEvent::SOURCE_TYPE_TOUCHSCREEN, TOUCH_POINTER_ID, DISPLAY_ID, { DRAG_SRC_X, DRAG_SRC_Y }); ASSERT_TRUE(dragData); - int32_t ret = InteractionManager::GetInstance()->StartDrag(dragData.value(), callback); + int32_t ret = InteractionManager::GetInstance()->StartDrag(dragData.value(), + std::make_shared(callback)); ASSERT_EQ(ret, RET_OK); std::string udKey; ret = InteractionManager::GetInstance()->GetUdKey(udKey); @@ -1562,25 +1602,14 @@ HWTEST_F(InteractionManagerTest, GetDragData_Success, TestSize.Level1) std::optional 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); + int32_t ret = InteractionManager::GetInstance()->StartDrag(dragData.value(), + std::make_shared(callback)); ASSERT_EQ(ret, RET_OK); DragData replyDragData; ret = InteractionManager::GetInstance()->GetDragData(replyDragData); ASSERT_EQ(ret, RET_OK); - ASSERT_NE(replyDragData.shadowInfo.pixelMap, nullptr); - ASSERT_EQ(replyDragData.shadowInfo.pixelMap->GetWidth(), TEST_PIXEL_MAP_WIDTH); - ASSERT_EQ(replyDragData.shadowInfo.pixelMap->GetHeight(), TEST_PIXEL_MAP_HEIGHT); - ASSERT_EQ(dragData->udKey, replyDragData.udKey); - ASSERT_EQ(dragData->shadowInfo.x, replyDragData.shadowInfo.x); - ASSERT_EQ(dragData->shadowInfo.y, replyDragData.shadowInfo.y); - ASSERT_EQ(dragData->sourceType, replyDragData.sourceType); - ASSERT_EQ(dragData->pointerId, replyDragData.pointerId); - ASSERT_EQ(dragData->dragNum, replyDragData.dragNum); - ASSERT_EQ(dragData->displayX, replyDragData.displayX); - ASSERT_EQ(dragData->displayY, replyDragData.displayY); - ASSERT_EQ(dragData->displayId, replyDragData.displayId); - ASSERT_EQ(dragData->hasCanceledAnimation, replyDragData.hasCanceledAnimation); + ASSERT_EQ(replyDragData, dragData.value()); PrintDragData(replyDragData); SimulateUpPointerEvent( { DRAG_SRC_X, DRAG_SRC_Y }, MMI::PointerEvent::SOURCE_TYPE_MOUSE, MOUSE_POINTER_ID); @@ -1635,7 +1664,8 @@ HWTEST_F(InteractionManagerTest, GetDragState, TestSize.Level1) std::optional 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); + int32_t ret = InteractionManager::GetInstance()->StartDrag(dragData.value(), + std::make_shared(callback)); ASSERT_EQ(ret, RET_OK); DragState dragState; @@ -1781,7 +1811,8 @@ HWTEST_F(InteractionManagerTest, InteractionManagerTest_GetDragSummary, TestSize constexpr int64_t recordSize = 20; std::map summarys = { { udType, recordSize } }; dragData.value().summarys = summarys; - int32_t ret = InteractionManager::GetInstance()->StartDrag(dragData.value(), callback); + int32_t ret = InteractionManager::GetInstance()->StartDrag(dragData.value(), + std::make_shared(callback)); ASSERT_EQ(ret, RET_OK); summarys.clear(); ret = InteractionManager::GetInstance()->GetDragSummary(summarys); @@ -1814,7 +1845,8 @@ HWTEST_F(InteractionManagerTest, InteractionManagerTest_UpdatePreviewStyle, Test std::optional dragData = CreateDragData({ TEST_PIXEL_MAP_WIDTH, TEST_PIXEL_MAP_HEIGHT }, MMI::PointerEvent::SOURCE_TYPE_TOUCHSCREEN, TOUCH_POINTER_ID, DISPLAY_ID, { DRAG_SRC_X, DRAG_SRC_Y }); ASSERT_TRUE(dragData); - int32_t ret = InteractionManager::GetInstance()->StartDrag(dragData.value(), callback); + int32_t ret = InteractionManager::GetInstance()->StartDrag(dragData.value(), + std::make_shared(callback)); ASSERT_EQ(ret, RET_OK); ret = InteractionManager::GetInstance()->SetDragWindowVisible(true); EXPECT_EQ(ret, RET_OK); @@ -1865,7 +1897,8 @@ HWTEST_F(InteractionManagerTest, InteractionManagerTest_UpdatePreviewStyleWithAn std::optional dragData = CreateDragData({ TEST_PIXEL_MAP_WIDTH, TEST_PIXEL_MAP_HEIGHT }, MMI::PointerEvent::SOURCE_TYPE_TOUCHSCREEN, TOUCH_POINTER_ID, DISPLAY_ID, { DRAG_SRC_X, DRAG_SRC_Y }); ASSERT_TRUE(dragData); - int32_t ret = InteractionManager::GetInstance()->StartDrag(dragData.value(), callback); + int32_t ret = InteractionManager::GetInstance()->StartDrag(dragData.value(), + std::make_shared(callback)); ASSERT_EQ(ret, RET_OK); ret = InteractionManager::GetInstance()->SetDragWindowVisible(true); EXPECT_EQ(ret, RET_OK); @@ -1926,7 +1959,8 @@ HWTEST_F(InteractionManagerTest, InteractionManagerTest_GetExtraInfo, TestSize.L notifyMessage.displayX, notifyMessage.displayY, notifyMessage.result, notifyMessage.targetPid); promiseFlag.set_value(true); }; - int32_t ret = InteractionManager::GetInstance()->StartDrag(dragData.value(), callback); + int32_t ret = InteractionManager::GetInstance()->StartDrag(dragData.value(), + std::make_shared(callback)); ASSERT_EQ(ret, RET_OK); std::string extraInfo; ret = InteractionManager::GetInstance()->GetExtraInfo(extraInfo); @@ -1940,6 +1974,27 @@ HWTEST_F(InteractionManagerTest, InteractionManagerTest_GetExtraInfo, TestSize.L } } +/** + * @tc.name: TestDragDataUtil_Packer + * @tc.desc: Pack up dragData + * @tc.type: FUNC + * @tc.require: + */ +HWTEST_F(InteractionManagerTest, TestDragDataUtil_Packer, TestSize.Level1) +{ + CALL_TEST_DEBUG; + std::optional 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); + Parcel parcel; + int32_t ret = DragDataUtil::Marshalling(dragData.value(), parcel); + ASSERT_EQ(ret, RET_OK); + DragData dragDataFromParcel; + ret = DragDataUtil::UnMarshalling(parcel, dragDataFromParcel); + ASSERT_EQ(ret, RET_OK); + ASSERT_EQ(dragData.value(), dragDataFromParcel); +} + /** * @tc.name: InteractionManagerTest_GetDragAction_001 * @tc.desc: Get drag action with no keyboard events of keys in dragging @@ -1961,7 +2016,8 @@ HWTEST_F(InteractionManagerTest, GetDragAction_001, TestSize.Level1) std::optional 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); + int32_t ret = InteractionManager::GetInstance()->StartDrag(dragData.value(), + std::make_shared(callback)); ASSERT_EQ(ret, RET_OK); DragAction dragAction { DragAction::INVALID }; ret = InteractionManager::GetInstance()->GetDragAction(dragAction); @@ -1990,7 +2046,7 @@ HWTEST_F(InteractionManagerTest, GetDragAction_002, TestSize.Level1) std::promise promiseFlag; std::future futureFlag = promiseFlag.get_future(); auto callback = [&promiseFlag](const DragNotifyMsg& notifyMessage) { - FI_HILOGD("displayX:%{public}d, displayY:%{public}d, result:%{public}d, target:%{public}d", + 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); }; @@ -2000,7 +2056,8 @@ HWTEST_F(InteractionManagerTest, GetDragAction_002, TestSize.Level1) std::optional 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); + int32_t ret = InteractionManager::GetInstance()->StartDrag(dragData.value(), + std::make_shared(callback)); ASSERT_EQ(ret, RET_OK); SimulateDownKeyEvent(MMI::KeyEvent::KEYCODE_CTRL_LEFT); DragAction dragAction { DragAction::INVALID }; diff --git a/intention/cooperate/state_machine/BUILD.gn b/intention/cooperate/state_machine/BUILD.gn new file mode 100644 index 000000000..85e141dd4 --- /dev/null +++ b/intention/cooperate/state_machine/BUILD.gn @@ -0,0 +1,49 @@ +# Copyright (c) 2023 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import("../../../device_status.gni") + +config("cooperate_public_config") { + include_dirs = [ "include" ] +} + +ohos_shared_library("state_machine") { + include_dirs = [ + "include", + "${device_status_root_path}/intention/cooperate/server/include", + ] + + sources = [ + "src/cooperate.cpp", + "src/cooperate_free.cpp", + "src/cooperate_in.cpp", + "src/cooperate_out.cpp", + "src/i_cooperate_state.cpp", + "src/state_machine.cpp", + ] + + public_configs = [ ":cooperate_public_config" ] + + deps = [ + "${device_status_root_path}/utils/ipc:devicestatus_ipc", + "${device_status_utils_path}:devicestatus_util", + ] + + external_deps = [ + "c_utils:utils", + "hilog:libhilog", + ] + + subsystem_name = "${device_status_subsystem_name}" + part_name = "${device_status_part_name}" +} diff --git a/intention/cooperate/state_machine/include/cooperate.h b/intention/cooperate/state_machine/include/cooperate.h new file mode 100644 index 000000000..a23d2e189 --- /dev/null +++ b/intention/cooperate/state_machine/include/cooperate.h @@ -0,0 +1,49 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef COOPERATE_H +#define COOPERATE_H + +#include +#include +#include +#include + +#include "state_machine.h" + +namespace OHOS { +namespace Msdp { +namespace DeviceStatus { +class Cooperate { +public: + int32_t Init(); + int32_t Enable(); + void Disable(); + int32_t StartCooperate(int32_t userData, const std::string &remoteNetworkId, int32_t startDeviceId); + int32_t StopCooperate(int32_t userData, bool isUnchained); + +private: + void Loop(); + + StateMachine sm_; + std::thread worker_; + std::atomic_bool running_ { false }; + Channel::Sender sender_; + Channel::Receiver receiver_; +}; +} // namespace DeviceStatus +} // namespace Msdp +} // namespace OHOS +#endif // COOPERATE_H \ No newline at end of file diff --git a/intention/cooperate/state_machine/include/cooperate_define.h b/intention/cooperate/state_machine/include/cooperate_define.h new file mode 100644 index 000000000..1e5fb6841 --- /dev/null +++ b/intention/cooperate/state_machine/include/cooperate_define.h @@ -0,0 +1,147 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef COOPERATE_DEFINE_H +#define COOPERATE_DEFINE_H + +#include +#include +#include + +#include "channel.h" + +namespace OHOS { +namespace Msdp { +namespace DeviceStatus { +enum class CooperateEventType { + NOOP, + QUIT, + UPDATE_STATE, + ENABLE, + DISABLE, + START, + STOP, + APP_CLOSED, + UNPLUG_POINTER, + PLUG_KEYBOARD, + POINTER_MOVE, + PREPARE_DINPUT_RESULT, + START_DINPUT_RESULT, + DINPUT_CLOSED, + DSOFTBUS_CLOSED, + INTERCEPTOR, + SESSION_OPEND, +}; + +struct UpdateStateEvent { + size_t current; +}; + +struct StartCooperateEvent { + int32_t userData; + std::string remoteNetworkId; + int32_t startDeviceId; +}; + +struct StartRemoteInputResult { + std::string source; + std::string sink; + int32_t startDeviceId; + bool success; +}; + +struct PointerMoveEvent { + int32_t deviceId; +}; + +struct SessionOpened { + int32_t sessionId; + int32_t result; +}; + +struct CooperateEvent { + CooperateEvent() : type(CooperateEventType::QUIT) {} + + explicit CooperateEvent(CooperateEventType ty) : type(ty) {} + + template + CooperateEvent(CooperateEventType ty, Event ev) : type(ty), event(ev) {} + + CooperateEventType type; + std::variant< + UpdateStateEvent, + StartCooperateEvent, + StartRemoteInputResult, + PointerMoveEvent + > event; +}; + +std::ostream& operator<<(std::ostream &oss, CooperateEvent &event) +{ + oss << "CooperateEvent(id:"; + switch (event.type) { + case CooperateEventType::POINTER_MOVE : { + PointerMoveEvent e = std::get(event.event); + oss << "pointer move, pointer:" << e.deviceId; + break; + } + case CooperateEventType::START: { + StartCooperateEvent e = std::get(event.event); + oss << "start cooperate, remote:" << e.remoteNetworkId << ", startDeviceId:" << e.startDeviceId; + break; + } + case CooperateEventType::PREPARE_DINPUT_RESULT : { + StartRemoteInputResult e = std::get(event.event); + oss << "prepare remote input result, source:" << e.source << ", sink:" << e.sink + << ", startDeviceId:" << e.startDeviceId << ", isSuccess:" << std::boolalpha << e.success; + break; + } + case CooperateEventType::START_DINPUT_RESULT : { + StartRemoteInputResult e = std::get(event.event); + oss << "start remote input result, source:" << e.source << ", sink:" << e.sink + << ", startDeviceId:" << e.startDeviceId << ", isSuccess:" << std::boolalpha << e.success; + break; + } + default : { + oss << static_cast(event.type); + break; + } + } + oss << ")"; + return oss; +} + +class DeviceManager { +public: + std::string GetDhid(int32_t deviceId); +}; + +std::string DeviceManager::GetDhid(int32_t deviceId) +{ + return std::to_string(deviceId); +} + +class Context { +public: + DeviceManager devMgr_; + Channel::Sender sender_; + std::string cooperated_; + std::string startDeviceId_; + bool isUnchain_; +}; +} // namespace DeviceStatus +} // namespace Msdp +} // namespace OHOS +#endif // COOPERATE_DEFINE_H \ No newline at end of file diff --git a/intention/cooperate/state_machine/include/cooperate_in.h b/intention/cooperate/state_machine/include/cooperate_in.h new file mode 100644 index 000000000..943ce25b5 --- /dev/null +++ b/intention/cooperate/state_machine/include/cooperate_in.h @@ -0,0 +1,64 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef COOPERATE_IN_H +#define COOPERATE_IN_H + +#include +#include + +#include "i_cooperate_state.h" + +namespace OHOS { +namespace Msdp { +namespace DeviceStatus { +class CooperateIn : public ICooperateState { +public: + CooperateIn(); + ~CooperateIn() = default; + + void OnEvent(Context &context, const CooperateEvent &event) override; + void OnEnterState(Context &event) override; + void OnLeaveState(Context &event) override; + +private: + class Initial final : public ICooperateStep { + public: + void OnEvent(Context &context, const CooperateEvent &event) override; + void OnProgress(Context &context, const CooperateEvent &event) override; + void OnReset(Context &context, const CooperateEvent &event) override; + }; + + class PrepareRemoteInput final : public ICooperateStep { + public: + void OnEvent(Context &context, const CooperateEvent &event) override; + void OnProgress(Context &context, const CooperateEvent &event) override; + void OnReset(Context &context, const CooperateEvent &event) override; + + private: + std::pair prepared_; + }; + + class StartRemoteInput final : public ICooperateStep { + public: + void OnEvent(Context &context, const CooperateEvent &event) override; + void OnProgress(Context &context, const CooperateEvent &event) override; + void OnReset(Context &context, const CooperateEvent &event) override; + }; +}; +} // namespace DeviceStatus +} // namespace Msdp +} // namespace OHOS +#endif // COOPERATE_IN_H \ No newline at end of file diff --git a/intention/cooperate/state_machine/src/i_cooperate_state.cpp b/intention/cooperate/state_machine/src/i_cooperate_state.cpp new file mode 100644 index 000000000..4a205fafd --- /dev/null +++ b/intention/cooperate/state_machine/src/i_cooperate_state.cpp @@ -0,0 +1,74 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "i_cooperate_state.h" + +namespace OHOS { +namespace Msdp { +namespace DeviceStatus { + +ICooperateState::ICooperateStep::ICooperateStep(ICooperateState &parent, std::shared_ptr prev) + : parent_(parent), prev_(prev) +{} + +void ICooperateState::Switch(std::shared_ptr step) +{ + if (step == nullptr) { + FI_HILOGE("In ICooperateState::Switch, step is null"); + return; + } + current_ = step; +} + +void ICooperateState::ICooperateStep::SetNext(std::shared_ptr next) +{ + if (next == nullptr) { + FI_HILOGE("In ICooperateState::ICooperateStep::SetNext, next is nullptr"); + return; + } + next_ = next; +} + +void ICooperateState::ICooperateStep::Switch(std::shared_ptr step) +{ + if (step == nullptr) { + FI_HILOGE("In ICooperateState::ICooperateStep::Switch, step is nullptr"); + return; + } + parent_.Switch(step); +} + +void ICooperateState::ICooperateStep::Proceed(Context &context, CooperateEvent &event) +{ + if (next_ == nullptr) { + FI_HILOGE("In ICooperateState::ICooperateStep::Proceed, next_ is nullptr"); + return; + } + Switch(next_); + next_->OnProgress(context, event); +} + +void ICooperateState::ICooperateStep::Reset(Context &context, CooperateEvent &event) +{ + if (prev_ == nullptr) { + FI_HILOGE("In ICooperateState::ICooperateStep::Reset, prev_ is nullptr"); + return; + } + Switch(prev_); + prev_->OnReset(context, event); +} +} // namespace DeviceStatus +} // namespace Msdp +} // namespace OHOS diff --git a/intention/data/drag/include/drag_data.h b/intention/data/drag/include/drag_data.h index 328f458b7..9f81e635b 100644 --- a/intention/data/drag/include/drag_data.h +++ b/intention/data/drag/include/drag_data.h @@ -29,7 +29,7 @@ struct ShadowInfo { }; struct DragData { - ShadowInfo shadowInfo; + std::vector shadowInfos; std::vector buffer; std::string udKey; std::string filterInfo; diff --git a/intention/data/drag/src/drag_data_manager.cpp b/intention/data/drag/src/drag_data_manager.cpp index 039f0c4b9..35b9a3b64 100644 --- a/intention/data/drag/src/drag_data_manager.cpp +++ b/intention/data/drag/src/drag_data_manager.cpp @@ -51,7 +51,6 @@ DragData DragDataManager::GetDragData() const void DragDataManager::ResetDragData() { - CALL_DEBUG_ENTER; dragData_ = { }; previewStyle_ = { }; } diff --git a/interfaces/innerkits/BUILD.gn b/interfaces/innerkits/BUILD.gn index 60ce49624..e72a5c8f9 100755 --- a/interfaces/innerkits/BUILD.gn +++ b/interfaces/innerkits/BUILD.gn @@ -43,6 +43,7 @@ ohos_shared_library("devicestatus_client") { version_script = "libdevicestatus_client_map" sources = [ + "${device_status_frameworks_path}/native/interaction/src/drag_data_util.cpp", "${device_status_frameworks_path}/native/interaction/src/drag_manager_impl.cpp", "${device_status_frameworks_path}/native/interaction/src/interaction_manager.cpp", "${device_status_frameworks_path}/native/interaction/src/interaction_manager_impl.cpp", diff --git a/interfaces/innerkits/interaction/include/drag_data.h b/interfaces/innerkits/interaction/include/drag_data.h index 7165b7cd3..052275e82 100644 --- a/interfaces/innerkits/interaction/include/drag_data.h +++ b/interfaces/innerkits/interaction/include/drag_data.h @@ -30,14 +30,31 @@ namespace DeviceStatus { constexpr size_t MAX_BUFFER_SIZE { 512 }; constexpr size_t MAX_UDKEY_SIZE { 100 }; constexpr size_t MAX_SUMMARY_SIZE { 200 }; +constexpr int32_t SHADOW_NUM_LIMIT { 3 }; struct ShadowInfo { std::shared_ptr pixelMap { nullptr }; int32_t x { -1 }; int32_t y { -1 }; + + bool operator == (const ShadowInfo &other) const + { + if (pixelMap == nullptr && other.pixelMap == nullptr) { + return x == other.x && y == other.y; + } + if (pixelMap == nullptr || other.pixelMap == nullptr) { + return false; + } + return pixelMap->IsSameImage(*(other.pixelMap)) && x == other.x && y == other.y; + } + + bool operator != (const ShadowInfo &other) const + { + return !(*this == other); + } }; struct DragData { - ShadowInfo shadowInfo; + std::vector shadowInfos; std::vector buffer; std::string udKey; std::string extraInfo; @@ -51,6 +68,20 @@ struct DragData { bool hasCanceledAnimation { false }; bool hasCoordinateCorrected { false }; std::map summarys; + + bool operator == (const DragData &other) const + { + return shadowInfos == other.shadowInfos && buffer == other.buffer && udKey == other.udKey && + filterInfo == other.filterInfo && extraInfo == other.extraInfo && sourceType == other.sourceType && + dragNum == other.dragNum && pointerId == other.pointerId && displayX == other.displayX && + displayY == other.displayY && displayId == other.displayId && + hasCanceledAnimation == other.hasCanceledAnimation && summarys == other.summarys; + } + + bool operator != (const DragData &other) const + { + return !(*this == other); + } }; enum class DragState { diff --git a/interfaces/innerkits/interaction/include/drag_data_util.h b/interfaces/innerkits/interaction/include/drag_data_util.h new file mode 100644 index 000000000..2a355585b --- /dev/null +++ b/interfaces/innerkits/interaction/include/drag_data_util.h @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef DRAG_DATA_UTIL_H +#define DRAG_DATA_UTIL_H + +#include "parcel.h" + +#include "drag_data.h" + +namespace OHOS { +namespace Msdp { +namespace DeviceStatus { +class DragDataUtil { +public: + static int32_t Marshalling(const DragData &dragData, Parcel &data); + static int32_t UnMarshalling(Parcel &data, DragData &dragData); +}; +} // namespace DeviceStatus +} // namespace Msdp +} // namespace OHOS +#endif // DRAG_DATA_UTIL_H diff --git a/interfaces/innerkits/interaction/include/i_start_drag_listener.h b/interfaces/innerkits/interaction/include/i_start_drag_listener.h new file mode 100644 index 000000000..a007e03bf --- /dev/null +++ b/interfaces/innerkits/interaction/include/i_start_drag_listener.h @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef I_START_DRAG_LISTENER_H +#define I_START_DRAG_LISTENER_H + +#include "drag_data.h" + +namespace OHOS { +namespace Msdp { +namespace DeviceStatus { +class IStartDragListener { +public: + IStartDragListener() = default; + virtual ~IStartDragListener() = default; + virtual void OnDragEndMessage(const DragNotifyMsg &msg) = 0; + virtual void OnHideIconMessage() = 0; +}; +} +} // namespace Msdp +} // namespace OHOS +#endif // I_START_DRAG_LISTENER_H \ No newline at end of file diff --git a/interfaces/innerkits/interaction/include/interaction_manager.h b/interfaces/innerkits/interaction/include/interaction_manager.h index e88351cdf..009c524d6 100644 --- a/interfaces/innerkits/interaction/include/interaction_manager.h +++ b/interfaces/innerkits/interaction/include/interaction_manager.h @@ -25,6 +25,7 @@ #include "drag_data.h" #include "i_coordination_listener.h" #include "i_drag_listener.h" +#include "i_start_drag_listener.h" #include "i_hotarea_listener.h" #include "i_subscript_listener.h" @@ -108,11 +109,11 @@ public: /** * @brief Starts dragging. * @param dragData Indicates additional data used for dragging. - * @param callback Indicates the callback used to return the dragging result. + * @param listener Indicates the listener used to notify dragging result etc. * @return Returns 0 if the operation is successful; returns a non-zero value otherwise. * @since 10 */ - int32_t StartDrag(const DragData &dragData, std::function callback); + int32_t StartDrag(const DragData &dragData, std::shared_ptr listener); /** * @brief Stops dragging. diff --git a/interfaces/innerkits/libdevicestatus_client_map b/interfaces/innerkits/libdevicestatus_client_map index 4fb1c37f6..c91c96a59 100644 --- a/interfaces/innerkits/libdevicestatus_client_map +++ b/interfaces/innerkits/libdevicestatus_client_map @@ -42,7 +42,7 @@ "OHOS::Msdp::DeviceStatus::InteractionManager::ActivateCoordination(std::__h::basic_string, std::__h::allocator> const&, int, std::__h::function, std::__h::allocator> const&, OHOS::Msdp::CoordinationMessage)>, bool)"; "OHOS::Msdp::DeviceStatus::InteractionManager::DeactivateCoordination(bool, std::__h::function, std::__h::allocator> const&, OHOS::Msdp::CoordinationMessage)>, bool)"; "OHOS::Msdp::DeviceStatus::InteractionManager::GetCoordinationState(std::__h::basic_string, std::__h::allocator> const&, std::__h::function, bool)"; - "OHOS::Msdp::DeviceStatus::InteractionManager::StartDrag(OHOS::Msdp::DeviceStatus::DragData const&, std::__h::function)"; + "OHOS::Msdp::DeviceStatus::InteractionManager::StartDrag(OHOS::Msdp::DeviceStatus::DragData const&, std::__h::shared_ptr)"; "OHOS::Msdp::DeviceStatus::InteractionManager::StopDrag(OHOS::Msdp::DeviceStatus::DragDropResult const&)"; "OHOS::Msdp::DeviceStatus::InteractionManager::SetDragWindowVisible(bool)"; "OHOS::Msdp::DeviceStatus::InteractionManager::GetShadowOffset(int&, int&, int&, int&)"; @@ -56,6 +56,9 @@ "OHOS::Msdp::DeviceStatus::InteractionManager::UpdatePreviewStyleWithAnimation(OHOS::Msdp::DeviceStatus::PreviewStyle const&, OHOS::Msdp::DeviceStatus::PreviewAnimation const&)"; "OHOS::Msdp::DeviceStatus::InteractionManager::GetDragSummary(std::__h::map, std::__h::allocator>, long long, std::__h::less, std::__h::allocator>>, std::__h::allocator, std::__h::allocator> const, long long>>>&)"; "OHOS::Msdp::DeviceStatus::InteractionManager::GetDragSummary(std::__h::map, std::__h::allocator>, long, std::__h::less, std::__h::allocator>>, std::__h::allocator, std::__h::allocator> const, long>>>&)"; + "OHOS::Msdp::DeviceStatus::InteractionManager::GetDropType(OHOS::Msdp::DeviceStatus::DropType&)"; + "OHOS::Msdp::DeviceStatus::DragDataUtil::Marshalling(OHOS::Msdp::DeviceStatus::DragData const&, OHOS::Parcel&)"; + "OHOS::Msdp::DeviceStatus::DragDataUtil::UnMarshalling(OHOS::Parcel&, OHOS::Msdp::DeviceStatus::DragData&)"; "OHOS::Msdp::DeviceStatus::InteractionManager::EnterTextEditorArea(bool)"; "OHOS::Msdp::DeviceStatus::InteractionManager::GetDragAction(OHOS::Msdp::DeviceStatus::DragAction&)"; "OHOS::Msdp::DeviceStatus::InteractionManager::GetExtraInfo(std::__h::basic_string, std::__h::allocator>&)"; diff --git a/services/communication/client/src/devicestatus_srv_proxy.cpp b/services/communication/client/src/devicestatus_srv_proxy.cpp index ffe3a72d6..a0475af2d 100644 --- a/services/communication/client/src/devicestatus_srv_proxy.cpp +++ b/services/communication/client/src/devicestatus_srv_proxy.cpp @@ -22,6 +22,7 @@ #include "devicestatus_common.h" #include "devicestatus_define.h" +#include "drag_data_packer.h" #include "preview_style_packer.h" #include "stationary_callback.h" #include "stationary_data.h" @@ -352,24 +353,9 @@ int32_t DeviceStatusSrvProxy::GetDragData(DragData &dragData) FI_HILOGE("Get DragData failed"); return ret; } - - auto pixelMap = OHOS::Media::PixelMap::Unmarshalling(reply); - CHKPR(pixelMap, RET_ERR); - dragData.shadowInfo.pixelMap = std::shared_ptr (pixelMap); - READINT32(reply, dragData.shadowInfo.x, E_DEVICESTATUS_READ_PARCEL_ERROR); - READINT32(reply, dragData.shadowInfo.y, E_DEVICESTATUS_READ_PARCEL_ERROR); - READUINT8VECTOR(reply, dragData.buffer, E_DEVICESTATUS_READ_PARCEL_ERROR); - READSTRING(reply, dragData.udKey, E_DEVICESTATUS_READ_PARCEL_ERROR); - READINT32(reply, dragData.sourceType, E_DEVICESTATUS_READ_PARCEL_ERROR); - READINT32(reply, dragData.dragNum, E_DEVICESTATUS_READ_PARCEL_ERROR); - READINT32(reply, dragData.pointerId, E_DEVICESTATUS_READ_PARCEL_ERROR); - READINT32(reply, dragData.displayX, E_DEVICESTATUS_READ_PARCEL_ERROR); - READINT32(reply, dragData.displayY, E_DEVICESTATUS_READ_PARCEL_ERROR); - READINT32(reply, dragData.displayId, E_DEVICESTATUS_READ_PARCEL_ERROR); - READBOOL(reply, dragData.hasCanceledAnimation, E_DEVICESTATUS_READ_PARCEL_ERROR); - if (!Utility::Unmarshalling(dragData.summarys, reply)) { - FI_HILOGE("Failed to summarys unmarshalling"); - return E_DEVICESTATUS_READ_PARCEL_ERROR; + if (DragDataPacker::UnMarshalling(reply, dragData) != RET_OK) { + FI_HILOGE("UnMarshalling dragData failed"); + return RET_ERR; } return ret; } @@ -430,26 +416,8 @@ int32_t DeviceStatusSrvProxy::StartDrag(const DragData &dragData) FI_HILOGE("Failed to write descriptor"); return ERR_INVALID_VALUE; } - CHKPR(dragData.shadowInfo.pixelMap, RET_ERR); - if (!dragData.shadowInfo.pixelMap->Marshalling(data)) { - FI_HILOGE("Failed to marshalling pixelMap"); - return ERR_INVALID_VALUE; - } - WRITEINT32(data, dragData.shadowInfo.x, ERR_INVALID_VALUE); - WRITEINT32(data, dragData.shadowInfo.y, ERR_INVALID_VALUE); - WRITEUINT8VECTOR(data, dragData.buffer, ERR_INVALID_VALUE); - WRITESTRING(data, dragData.udKey, ERR_INVALID_VALUE); - WRITESTRING(data, dragData.extraInfo, ERR_INVALID_VALUE); - WRITESTRING(data, dragData.filterInfo, ERR_INVALID_VALUE); - WRITEINT32(data, dragData.sourceType, ERR_INVALID_VALUE); - WRITEINT32(data, dragData.dragNum, ERR_INVALID_VALUE); - WRITEINT32(data, dragData.pointerId, ERR_INVALID_VALUE); - WRITEINT32(data, dragData.displayX, ERR_INVALID_VALUE); - WRITEINT32(data, dragData.displayY, ERR_INVALID_VALUE); - WRITEINT32(data, dragData.displayId, ERR_INVALID_VALUE); - WRITEBOOL(data, dragData.hasCanceledAnimation, ERR_INVALID_VALUE); - if (!Utility::Marshalling(dragData.summarys, data)) { - FI_HILOGE("Failed to summarys marshalling"); + if (DragDataPacker::Marshalling(dragData, data) != RET_OK) { + FI_HILOGE("Failed to marshalling dragData"); return ERR_INVALID_VALUE; } MessageParcel reply; @@ -789,7 +757,7 @@ int32_t DeviceStatusSrvProxy::GetDragSummary(std::map &sum FI_HILOGE("Send request failed, ret:%{public}d", ret); return RET_ERR; } - if (!Utility::Unmarshalling(summarys, reply)) { + if (SummaryPacker::UnMarshalling(reply, summarys) != RET_OK) { FI_HILOGE("Failed to summarys unmarshalling"); return RET_ERR; } diff --git a/services/communication/service/src/devicestatus_srv_stub.cpp b/services/communication/service/src/devicestatus_srv_stub.cpp index 690bbfc1a..27a71cba4 100644 --- a/services/communication/service/src/devicestatus_srv_stub.cpp +++ b/services/communication/service/src/devicestatus_srv_stub.cpp @@ -25,6 +25,7 @@ #include "devicestatus_define.h" #include "devicestatus_service.h" #include "devicestatus_srv_proxy.h" +#include "drag_data_packer.h" #include "fi_log.h" #include "preview_style_packer.h" #include "stationary_callback.h" @@ -377,7 +378,7 @@ int32_t DeviceStatusSrvStub::GetUdKeyStub(MessageParcel &data, MessageParcel &re FI_HILOGE("Get udKey failed, ret:%{public}d", ret); } WRITESTRING(reply, udKey, IPC_STUB_WRITE_PARCEL_ERR); - FI_HILOGD("Target udKey:%{public}s", udKey.c_str()); + FI_HILOGD("Target udKey:%{public}s", GetAnonyString(udKey).c_str()); return RET_OK; } @@ -425,33 +426,19 @@ int32_t DeviceStatusSrvStub::HandleAllocSocketFdStub(MessageParcel &data, Messag int32_t DeviceStatusSrvStub::StartDragStub(MessageParcel &data, MessageParcel &reply) { - auto pixelMap = OHOS::Media::PixelMap::Unmarshalling(data); - CHKPR(pixelMap, RET_ERR); + CALL_DEBUG_ENTER; DragData dragData; - dragData.shadowInfo.pixelMap = std::shared_ptr(pixelMap); - READINT32(data, dragData.shadowInfo.x, E_DEVICESTATUS_READ_PARCEL_ERROR); - READINT32(data, dragData.shadowInfo.y, E_DEVICESTATUS_READ_PARCEL_ERROR); - READUINT8VECTOR(data, dragData.buffer, E_DEVICESTATUS_READ_PARCEL_ERROR); - READSTRING(data, dragData.udKey, E_DEVICESTATUS_READ_PARCEL_ERROR); - READSTRING(data, dragData.extraInfo, E_DEVICESTATUS_READ_PARCEL_ERROR); - READSTRING(data, dragData.filterInfo, E_DEVICESTATUS_READ_PARCEL_ERROR); - READINT32(data, dragData.sourceType, E_DEVICESTATUS_READ_PARCEL_ERROR); - READINT32(data, dragData.dragNum, E_DEVICESTATUS_READ_PARCEL_ERROR); - READINT32(data, dragData.pointerId, E_DEVICESTATUS_READ_PARCEL_ERROR); - READINT32(data, dragData.displayX, E_DEVICESTATUS_READ_PARCEL_ERROR); - READINT32(data, dragData.displayY, E_DEVICESTATUS_READ_PARCEL_ERROR); - READINT32(data, dragData.displayId, E_DEVICESTATUS_READ_PARCEL_ERROR); - READBOOL(data, dragData.hasCanceledAnimation, E_DEVICESTATUS_READ_PARCEL_ERROR); - if (!Utility::Unmarshalling(dragData.summarys, data)) { - FI_HILOGE("Failed to summarys unmarshalling"); + if (DragDataPacker::UnMarshalling(data, dragData) != RET_OK) { + FI_HILOGE("UnMarshalling dragData failed"); return E_DEVICESTATUS_READ_PARCEL_ERROR; } - if ((dragData.shadowInfo.x > 0) || (dragData.shadowInfo.y > 0) || - (dragData.shadowInfo.x < -dragData.shadowInfo.pixelMap->GetWidth()) || - (dragData.shadowInfo.y < -dragData.shadowInfo.pixelMap->GetHeight())) { - FI_HILOGE("Start drag invalid parameter, shadowInfox:%{public}d, shadowInfoy:%{public}d", - dragData.shadowInfo.x, dragData.shadowInfo.y); - return RET_ERR; + for (const auto& shadowInfo : dragData.shadowInfos) { + CHKPR(shadowInfo.pixelMap, RET_ERR); + if ((shadowInfo.x > 0) || (shadowInfo.y > 0) || + (shadowInfo.x < -shadowInfo.pixelMap->GetWidth()) || (shadowInfo.y < -shadowInfo.pixelMap->GetHeight())) { + FI_HILOGE("Invalid parameter, shadowInfox:%{public}d, shadowInfoy:%{public}d", shadowInfo.x, shadowInfo.y); + return RET_ERR; + } } if ((dragData.dragNum <= 0) || (dragData.buffer.size() > MAX_BUFFER_SIZE) || (dragData.displayX < 0) || (dragData.displayY < 0)) { @@ -565,6 +552,7 @@ int32_t DeviceStatusSrvStub::UpdateShadowPicStub(MessageParcel &data, MessagePar shadowInfo.pixelMap = std::shared_ptr(pixelMap); READINT32(data, shadowInfo.x, E_DEVICESTATUS_READ_PARCEL_ERROR); READINT32(data, shadowInfo.y, E_DEVICESTATUS_READ_PARCEL_ERROR); + CHKPR(shadowInfo.pixelMap, RET_ERR); if ((shadowInfo.x > 0) || (shadowInfo.y > 0) || (shadowInfo.x < -shadowInfo.pixelMap->GetWidth()) || (shadowInfo.y < -shadowInfo.pixelMap->GetHeight())) { @@ -589,25 +577,9 @@ int32_t DeviceStatusSrvStub::GetDragDataStub(MessageParcel &data, MessageParcel FI_HILOGE("Get DragData failed, ret:%{public}d", ret); return RET_ERR; } - CHKPR(dragData.shadowInfo.pixelMap, RET_ERR); - if (!dragData.shadowInfo.pixelMap->Marshalling(reply)) { - FI_HILOGE("Failed to marshalling pixelMap"); - return ERR_INVALID_VALUE; - } - WRITEINT32(reply, dragData.shadowInfo.x, ERR_INVALID_VALUE); - WRITEINT32(reply, dragData.shadowInfo.y, ERR_INVALID_VALUE); - WRITEUINT8VECTOR(reply, dragData.buffer, ERR_INVALID_VALUE); - WRITESTRING(reply, dragData.udKey, ERR_INVALID_VALUE); - WRITEINT32(reply, dragData.sourceType, ERR_INVALID_VALUE); - WRITEINT32(reply, dragData.dragNum, ERR_INVALID_VALUE); - WRITEINT32(reply, dragData.pointerId, ERR_INVALID_VALUE); - WRITEINT32(reply, dragData.displayX, ERR_INVALID_VALUE); - WRITEINT32(reply, dragData.displayY, ERR_INVALID_VALUE); - WRITEINT32(reply, dragData.displayId, ERR_INVALID_VALUE); - WRITEBOOL(reply, dragData.hasCanceledAnimation, ERR_INVALID_VALUE); - if (!Utility::Marshalling(dragData.summarys, reply)) { - FI_HILOGE("Failed to summarys unmarshalling"); - return ERR_INVALID_VALUE; + if (DragDataPacker::Marshalling(dragData, reply) != RET_OK) { + FI_HILOGE("Marshalling dragData failed"); + return RET_ERR; } return ret; } @@ -695,7 +667,7 @@ int32_t DeviceStatusSrvStub::GetDragSummaryStub(MessageParcel &data, MessageParc FI_HILOGE("Get summarys failed"); return RET_ERR; } - if (!Utility::Marshalling(summarys, reply)) { + if (SummaryPacker::Marshalling(summarys, reply) != RET_OK) { FI_HILOGE("Failed to summarys unmarshalling"); return ERR_INVALID_VALUE; } diff --git a/services/interaction/drag/include/drag_data_manager.h b/services/interaction/drag/include/drag_data_manager.h index 6ac0b3925..fe85f7abc 100644 --- a/services/interaction/drag/include/drag_data_manager.h +++ b/services/interaction/drag/include/drag_data_manager.h @@ -35,7 +35,7 @@ public: void Init(const DragData &dragData); void SetDragStyle(DragCursorStyle style); - void SetShadowInfo(const ShadowInfo &shadowInfo); + void SetShadowInfos(const std::vector &shadowInfos); DragCursorStyle GetDragStyle() const; void SetDragWindowVisible(bool visible); bool GetDragWindowVisible() const; diff --git a/services/interaction/drag/include/drag_manager.h b/services/interaction/drag/include/drag_manager.h index 52b839abe..022f78e23 100644 --- a/services/interaction/drag/include/drag_manager.h +++ b/services/interaction/drag/include/drag_manager.h @@ -115,6 +115,7 @@ private: int32_t RemoveKeyEventMointor(); int32_t RemovePointerEventHandler(); int32_t NotifyDragResult(DragResult result); + int32_t NotifyHideIcon(); int32_t InitDataManager(const DragData &dragData) const; int32_t OnStartDrag(); int32_t OnStopDrag(DragResult result, bool hasCustomAnimation); diff --git a/services/interaction/drag/src/drag_data_manager.cpp b/services/interaction/drag/src/drag_data_manager.cpp index f08f3abc3..28c7acc2d 100644 --- a/services/interaction/drag/src/drag_data_manager.cpp +++ b/services/interaction/drag/src/drag_data_manager.cpp @@ -48,9 +48,9 @@ void DragDataManager::Init(const DragData &dragData) targetTid_ = -1; } -void DragDataManager::SetShadowInfo(const ShadowInfo &shadowInfo) +void DragDataManager::SetShadowInfos(const std::vector &shadowInfos) { - dragData_.shadowInfo = shadowInfo; + dragData_.shadowInfos = shadowInfos; } DragCursorStyle DragDataManager::GetDragStyle() const @@ -95,9 +95,13 @@ int32_t DragDataManager::GetTargetPid() const int32_t DragDataManager::GetShadowOffset(int32_t &offsetX, int32_t &offsetY, int32_t &width, int32_t &height) const { - offsetX = dragData_.shadowInfo.x; - offsetY = dragData_.shadowInfo.y; - auto pixelMap = dragData_.shadowInfo.pixelMap; + if (dragData_.shadowInfos.empty()) { + FI_HILOGE("ShadowInfos is empty"); + return RET_ERR; + } + offsetX = dragData_.shadowInfos.front().x; + offsetY = dragData_.shadowInfos.front().y; + auto pixelMap = dragData_.shadowInfos.front().pixelMap; CHKPR(pixelMap, RET_ERR); width = pixelMap->GetWidth(); height = pixelMap->GetHeight(); diff --git a/services/interaction/drag/src/drag_drawing.cpp b/services/interaction/drag/src/drag_drawing.cpp index 3c51c0710..b62f98479 100644 --- a/services/interaction/drag/src/drag_drawing.cpp +++ b/services/interaction/drag/src/drag_drawing.cpp @@ -223,7 +223,11 @@ int32_t DragDrawing::CheckDragData(const DragData &dragData) FI_HILOGE("Drag drawing is running, can not init again"); return INIT_CANCEL; } - CHKPR(dragData.shadowInfo.pixelMap, INIT_FAIL); + if (dragData.shadowInfos.empty()) { + FI_HILOGE("ShadowInfos is empty"); + return INIT_FAIL; + } + CHKPR(dragData.shadowInfos.front().pixelMap, INIT_FAIL); if ((dragData.sourceType != MMI::PointerEvent::SOURCE_TYPE_MOUSE) && (dragData.sourceType != MMI::PointerEvent::SOURCE_TYPE_TOUCHSCREEN)) { FI_HILOGE("Invalid sourceType:%{public}d", dragData.sourceType); @@ -708,14 +712,18 @@ void DragDrawing::OnVsync() void DragDrawing::InitDrawingInfo(const DragData &dragData) { g_drawingInfo.isRunning = true; + if (dragData.shadowInfos.empty()) { + FI_HILOGE("ShadowInfos is empty"); + return; + } + g_drawingInfo.pixelMap = dragData.shadowInfos.front().pixelMap; + g_drawingInfo.pixelMapX = dragData.shadowInfos.front().x; + g_drawingInfo.pixelMapY = dragData.shadowInfos.front().y; g_drawingInfo.currentDragNum = dragData.dragNum; g_drawingInfo.sourceType = dragData.sourceType; g_drawingInfo.displayId = dragData.displayId; g_drawingInfo.displayX = dragData.displayX; g_drawingInfo.displayY = dragData.displayY; - g_drawingInfo.pixelMap = dragData.shadowInfo.pixelMap; - g_drawingInfo.pixelMapX = dragData.shadowInfo.x; - g_drawingInfo.pixelMapY = dragData.shadowInfo.y; g_drawingInfo.extraInfo = dragData.extraInfo; g_drawingInfo.filterInfo = dragData.filterInfo; } diff --git a/services/interaction/drag/src/drag_manager.cpp b/services/interaction/drag/src/drag_manager.cpp index b87252058..4003e298e 100644 --- a/services/interaction/drag/src/drag_manager.cpp +++ b/services/interaction/drag/src/drag_manager.cpp @@ -123,23 +123,26 @@ int32_t DragManager::RemoveSubscriptListener(SessionPtr session) void DragManager::PrintDragData(const DragData &dragData) { + CALL_INFO_TRACE; + for (const auto& shadowInfo : dragData.shadowInfos) { + CHKPV(shadowInfo.pixelMap); + FI_HILOGI("PixelFormat:%{public}d, PixelAlphaType:%{public}d, PixelAllocatorType:%{public}d," + " PixelWidth:%{public}d, PixelHeight:%{public}d, shadowX:%{public}d, shadowY:%{public}d", + static_cast(shadowInfo.pixelMap->GetPixelFormat()), + static_cast(shadowInfo.pixelMap->GetAlphaType()), + static_cast(shadowInfo.pixelMap->GetAllocatorType()), + shadowInfo.pixelMap->GetWidth(), shadowInfo.pixelMap->GetHeight(), shadowInfo.x, shadowInfo.y); + } std::string summarys; for (const auto &[udKey, recordSize] : dragData.summarys) { std::string str = udKey + "-" + std::to_string(recordSize) + ";"; summarys += str; } - FI_HILOGI("dragData value Contains PixelFormat:%{public}d, PixelAlphaType:%{public}d," - " PixelAllocatorType:%{public}d, PixelWidth:%{public}d, PixelHeight:%{public}d, shadowX:%{public}d," - " shadowY:%{public}d, sourceType:%{public}d, pointerId:%{public}d, displayId:%{public}d," + FI_HILOGI("SourceType:%{public}d, pointerId:%{public}d, displayId:%{public}d," " displayX:%{public}d, displayY:%{public}d, dragNum:%{public}d," - " hasCanceledAnimation:%{public}d, udKey:%{public}s," - " hasCoordinateCorrected:%{public}d, summarys:%{public}s", - static_cast(dragData.shadowInfo.pixelMap->GetPixelFormat()), - static_cast(dragData.shadowInfo.pixelMap->GetAllocatorType()), - static_cast(dragData.shadowInfo.pixelMap->GetAlphaType()), - dragData.shadowInfo.pixelMap->GetWidth(), dragData.shadowInfo.pixelMap->GetHeight(), - dragData.shadowInfo.x, dragData.shadowInfo.y, dragData.sourceType, dragData.pointerId, - dragData.displayId, dragData.displayX, dragData.displayY, dragData.dragNum, dragData.hasCanceledAnimation, + " hasCanceledAnimation:%{public}d, udKey:%{public}s, hasCoordinateCorrected:%{public}d, summarys:%{public}s", + dragData.sourceType, dragData.pointerId, dragData.displayId, dragData.displayX, + dragData.displayY, dragData.dragNum, dragData.hasCanceledAnimation, GetAnonyString(dragData.udKey).c_str(), dragData.hasCoordinateCorrected, summarys.c_str()); } @@ -253,7 +256,7 @@ int32_t DragManager::UpdateShadowPic(const ShadowInfo &shadowInfo) FI_HILOGE("No drag instance running, can not update shadow picture"); return RET_ERR; } - DRAG_DATA_MGR.SetShadowInfo(shadowInfo); + DRAG_DATA_MGR.SetShadowInfos({ shadowInfo }); return dragDrawing_.UpdateShadowPic(shadowInfo); } @@ -302,6 +305,22 @@ int32_t DragManager::NotifyDragResult(DragResult result) return RET_OK; } +int32_t DragManager::NotifyHideIcon() +{ + CALL_DEBUG_ENTER; + NetPacket pkt(MessageId::DRAG_NOTIFY_HIDE_ICON); + if (pkt.ChkRWError()) { + FI_HILOGE("Packet write data failed"); + return RET_ERR; + } + CHKPR(dragOutSession_, RET_ERR); + if (!dragOutSession_->SendMsg(pkt)) { + FI_HILOGE("Send message failed"); + return MSG_SEND_FAIL; + } + return RET_OK; +} + void DragManager::DragCallback(std::shared_ptr pointerEvent) { CHKPV(pointerEvent); @@ -450,16 +469,21 @@ void DragManager::Dump(int32_t fd) const FI_HILOGE("Target udKey is empty"); udKey = ""; } + for (const auto& shadowInfo : dragData.shadowInfos) { + dprintf(fd, "dragData = {\n""\tshadowInfoX:%d\n\tshadowInfoY\n", shadowInfo.x, shadowInfo.y); + } dprintf(fd, "dragData = {\n" - "\tshadowInfoX:%d\n\tshadowInfoY:%d\n\tudKey:%s\n\tfilterInfo:%s\n\textraInfo:%s\n\tsourceType:%d" + "\tudKey:%s\n\tfilterInfo:%s\n\textraInfo:%s\n\tsourceType:%d" "\tdragNum:%d\n\tpointerId:%d\n\tdisplayX:%d\n\tdisplayY:%d\n""\tdisplayId:%d\n\thasCanceledAnimation:%s\n", - dragData.shadowInfo.x, dragData.shadowInfo.y, udKey.c_str(), dragData.filterInfo.c_str(), - dragData.extraInfo.c_str(), dragData.sourceType, dragData.dragNum, dragData.pointerId, dragData.displayX, - dragData.displayY, dragData.displayId, dragData.hasCanceledAnimation ? "true" : "false"); + GetAnonyString(dragData.udKey).c_str(), dragData.filterInfo.c_str(), dragData.extraInfo.c_str(), dragData.sourceType, + dragData.dragNum, dragData.pointerId, dragData.displayX, dragData.displayY, dragData.displayId, + dragData.hasCanceledAnimation ? "true" : "false"); if (dragState_ != DragState::STOP) { - std::shared_ptr pixelMap = dragData.shadowInfo.pixelMap; - CHKPV(pixelMap); - dprintf(fd, "\tpixelMapWidth:%d\n\tpixelMapHeight:%d\n", pixelMap->GetWidth(), pixelMap->GetHeight()); + for (const auto& shadowInfo : dragData.shadowInfos) { + CHKPV(shadowInfo.pixelMap); + dprintf(fd, "\tpixelMapWidth:%d\n\tpixelMapHeight:%d\n", shadowInfo.pixelMap->GetWidth(), + shadowInfo.pixelMap->GetHeight()); + } } dprintf(fd, "}\n"); } diff --git a/services/native/test/unittest/src/drag_data_manager_test.cpp b/services/native/test/unittest/src/drag_data_manager_test.cpp index 5a05b297a..a8a2d8d82 100644 --- a/services/native/test/unittest/src/drag_data_manager_test.cpp +++ b/services/native/test/unittest/src/drag_data_manager_test.cpp @@ -102,10 +102,9 @@ std::optional DragDataManagerTest::CreateDragData(int32_t sourceType, FI_HILOGE("Create pixelmap failed"); return std::nullopt; } + DragData dragData; - dragData.shadowInfo.x = 0; - dragData.shadowInfo.y = 0; - dragData.shadowInfo.pixelMap = pixelMap; + dragData.shadowInfos.push_back({ pixelMap, 0, 0 }); dragData.buffer = std::vector(MAX_BUFFER_SIZE, 0); dragData.udKey = UD_KEY; dragData.sourceType = sourceType; @@ -206,9 +205,7 @@ HWTEST_F(DragDataManagerTest, DragDataManagerTest005, TestSize.Level0) std::shared_ptr pixelMap = CreatePixelMap(PIXEL_MAP_WIDTH, PIXEL_MAP_HEIGHT); EXPECT_FALSE(pixelMap == nullptr); DragData dragData; - dragData.shadowInfo.pixelMap = pixelMap; - dragData.shadowInfo.x = SHADOWINFO_X; - dragData.shadowInfo.y = SHADOWINFO_Y; + dragData.shadowInfos.push_back({ pixelMap, SHADOWINFO_X, SHADOWINFO_Y }); dragData.displayX = DISPLAY_X; dragData.displayY = DISPLAY_Y; DRAG_DATA_MGR.Init(dragData); @@ -239,9 +236,7 @@ HWTEST_F(DragDataManagerTest, DragDataManagerTest006, TestSize.Level0) { CALL_TEST_DEBUG; DragData dragData; - dragData.shadowInfo.pixelMap = nullptr; - dragData.shadowInfo.x = SHADOWINFO_X; - dragData.shadowInfo.y = SHADOWINFO_Y; + dragData.shadowInfos.push_back({ nullptr, SHADOWINFO_X, SHADOWINFO_Y }); dragData.displayX = DISPLAY_X; dragData.displayY = DISPLAY_Y; DRAG_DATA_MGR.Init(dragData); diff --git a/utils/common/BUILD.gn b/utils/common/BUILD.gn index f524ef18a..570c494cf 100755 --- a/utils/common/BUILD.gn +++ b/utils/common/BUILD.gn @@ -40,6 +40,7 @@ ohos_shared_library("devicestatus_util") { version_script = "libdevicestatus_util_map" sources = [ "src/animation_curve.cpp", + "src/drag_data_packer.cpp", "src/preview_style_packer.cpp", "src/util.cpp", "src/util_napi.cpp", diff --git a/utils/common/include/drag_data_packer.h b/utils/common/include/drag_data_packer.h new file mode 100644 index 000000000..74c0f6025 --- /dev/null +++ b/utils/common/include/drag_data_packer.h @@ -0,0 +1,52 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef DRAG_DATA_PACKER_H +#define DRAG_DATA_PACKER_H + +#include +#include +#include + +#include "parcel.h" + +#include "drag_data.h" + +namespace OHOS { +namespace Msdp { +namespace DeviceStatus { + +using SummaryMap = std::map; +class DragDataPacker { +public: + static int32_t Marshalling(const DragData &dragData, Parcel &data); + static int32_t UnMarshalling(Parcel &data, DragData &dragData); +}; + +class ShadowPacker { +public: + static int32_t Marshalling(const std::vector &shadowInfos, Parcel &data); + static int32_t UnMarshalling(Parcel &data, std::vector &shadowInfos); +}; + +class SummaryPacker { +public: + static int32_t Marshalling(const SummaryMap &val, Parcel &parcel); + static int32_t UnMarshalling(Parcel &parcel, SummaryMap &val); +}; +} // namespace DeviceStatus +} // namespace Msdp +} // namespace OHOS +#endif // DRAG_DATA_PACKER_H diff --git a/utils/common/include/proto.h b/utils/common/include/proto.h index 31e9e070c..81a0de403 100644 --- a/utils/common/include/proto.h +++ b/utils/common/include/proto.h @@ -51,6 +51,7 @@ enum class MessageId : int32_t { DRAG_NOTIFY_RESULT, DRAG_STATE_LISTENER, + DRAG_NOTIFY_HIDE_ICON, DRAG_STYLE_LISTENER }; diff --git a/utils/common/include/utility.h b/utils/common/include/utility.h index 28de88d8c..a9bb13f10 100644 --- a/utils/common/include/utility.h +++ b/utils/common/include/utility.h @@ -29,7 +29,6 @@ namespace DeviceStatus { template> struct IsStreamable : public std::false_type {}; -using summaryMap = std::map; template struct IsStreamable(), std::declval()))>> @@ -63,8 +62,6 @@ public: static void ShowFileAttributes(const char *path); static void ShowUserAndGroup(); - static bool Marshalling(const summaryMap &val, Parcel &parcel); - static bool Unmarshalling(summaryMap &val, Parcel &parcel); }; inline bool Utility::IsEmpty(const char *str) diff --git a/utils/common/libdevicestatus_util_map b/utils/common/libdevicestatus_util_map index f05bf0fb9..cb9a631a0 100644 --- a/utils/common/libdevicestatus_util_map +++ b/utils/common/libdevicestatus_util_map @@ -36,10 +36,12 @@ "OHOS::Msdp::DeviceStatus::StringSplit(std::__h::basic_string, std::__h::allocator> const&, std::__h::basic_string, std::__h::allocator> const&, std::__h::vector, std::__h::allocator>, std::__h::allocator, std::__h::allocator>>>&)"; "OHOS::Msdp::DeviceStatus::StringPrintf(char const*, ...)"; "OHOS::Msdp::DeviceStatus::GetAnonyString(std::__h::basic_string, std::__h::allocator> const&)"; - "OHOS::Msdp::DeviceStatus::Utility::Unmarshalling(std::__h::map, std::__h::allocator>, long, std::__h::less, std::__h::allocator>>, std::__h::allocator, std::__h::allocator> const, long>>>&, OHOS::Parcel&)"; - "OHOS::Msdp::DeviceStatus::Utility::Marshalling(std::__h::map, std::__h::allocator>, long, std::__h::less, std::__h::allocator>>, std::__h::allocator, std::__h::allocator> const, long>>> const&, OHOS::Parcel&)"; - "OHOS::Msdp::DeviceStatus::Utility::Unmarshalling(std::__h::map, std::__h::allocator>, long long, std::__h::less, std::__h::allocator>>, std::__h::allocator, std::__h::allocator> const, long long>>>&, OHOS::Parcel&)"; - "OHOS::Msdp::DeviceStatus::Utility::Marshalling(std::__h::map, std::__h::allocator>, long long, std::__h::less, std::__h::allocator>>, std::__h::allocator, std::__h::allocator> const, long long>>> const&, OHOS::Parcel&)"; + "OHOS::Msdp::DeviceStatus::DragDataPacker::Marshalling(OHOS::Msdp::DeviceStatus::DragData const&, OHOS::Parcel&)"; + "OHOS::Msdp::DeviceStatus::DragDataPacker::UnMarshalling(OHOS::Parcel&, OHOS::Msdp::DeviceStatus::DragData&)"; + "OHOS::Msdp::DeviceStatus::SummaryPacker::UnMarshalling(OHOS::Parcel&, std::__h::map, std::__h::allocator>, long long, std::__h::less, std::__h::allocator>>, std::__h::allocator, std::__h::allocator> const, long long>>>&)"; + "OHOS::Msdp::DeviceStatus::SummaryPacker::Marshalling(std::__h::map, std::__h::allocator>, long long, std::__h::less, std::__h::allocator>>, std::__h::allocator, std::__h::allocator> const, long long>>> const&, OHOS::Parcel&)"; + "OHOS::Msdp::DeviceStatus::SummaryPacker::UnMarshalling(OHOS::Parcel&, std::__h::map, std::__h::allocator>, long, std::__h::less, std::__h::allocator>>, std::__h::allocator, std::__h::allocator> const, long>>>&)"; + "OHOS::Msdp::DeviceStatus::SummaryPacker::Marshalling(std::__h::map, std::__h::allocator>, long, std::__h::less, std::__h::allocator>>, std::__h::allocator, std::__h::allocator> const, long>>> const&, OHOS::Parcel&)"; "OHOS::Msdp::DeviceStatus::PreviewStylePacker::Marshalling(OHOS::Msdp::DeviceStatus::PreviewStyle const&, OHOS::Parcel&)"; "OHOS::Msdp::DeviceStatus::PreviewStylePacker::UnMarshalling(OHOS::Parcel&, OHOS::Msdp::DeviceStatus::PreviewStyle&)"; "OHOS::Msdp::DeviceStatus::PreviewAnimationPacker::Marshalling(OHOS::Msdp::DeviceStatus::PreviewAnimation const&, OHOS::Parcel&)"; diff --git a/utils/common/src/drag_data_packer.cpp b/utils/common/src/drag_data_packer.cpp new file mode 100644 index 000000000..020cacb2b --- /dev/null +++ b/utils/common/src/drag_data_packer.cpp @@ -0,0 +1,157 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "drag_data_packer.h" + +#include "devicestatus_common.h" +#include "devicestatus_define.h" +#include "devicestatus_errors.h" + +namespace OHOS { +namespace Msdp { +namespace { +constexpr OHOS::HiviewDFX::HiLogLabel LABEL { LOG_CORE, MSDP_DOMAIN_ID, "DragDataPacker" }; +} // namespace + +namespace DeviceStatus { + +int32_t DragDataPacker::Marshalling(const DragData &dragData, Parcel &data) +{ + if (ShadowPacker::Marshalling(dragData.shadowInfos, data) != RET_OK) { + FI_HILOGE("Failed to marshalling shadowInfos"); + return RET_ERR; + } + WRITEUINT8VECTOR(data, dragData.buffer, ERR_INVALID_VALUE); + WRITESTRING(data, dragData.udKey, ERR_INVALID_VALUE); + WRITESTRING(data, dragData.extraInfo, ERR_INVALID_VALUE); + WRITESTRING(data, dragData.filterInfo, ERR_INVALID_VALUE); + WRITEINT32(data, dragData.sourceType, ERR_INVALID_VALUE); + WRITEINT32(data, dragData.dragNum, ERR_INVALID_VALUE); + WRITEINT32(data, dragData.pointerId, ERR_INVALID_VALUE); + WRITEINT32(data, dragData.displayX, ERR_INVALID_VALUE); + WRITEINT32(data, dragData.displayY, ERR_INVALID_VALUE); + WRITEINT32(data, dragData.displayId, ERR_INVALID_VALUE); + WRITEBOOL(data, dragData.hasCanceledAnimation, ERR_INVALID_VALUE); + if (SummaryPacker::Marshalling(dragData.summarys, data) != RET_OK) { + FI_HILOGE("Failed to summarys marshalling"); + return RET_ERR; + } + return RET_OK; +} + +int32_t DragDataPacker::UnMarshalling(Parcel &data, DragData &dragData) +{ + if (ShadowPacker::UnMarshalling(data, dragData.shadowInfos) != RET_OK) { + FI_HILOGE("UnMarshallingShadowInfos failed"); + return RET_ERR; + } + READUINT8VECTOR(data, dragData.buffer, E_DEVICESTATUS_READ_PARCEL_ERROR); + READSTRING(data, dragData.udKey, E_DEVICESTATUS_READ_PARCEL_ERROR); + READSTRING(data, dragData.extraInfo, E_DEVICESTATUS_READ_PARCEL_ERROR); + READSTRING(data, dragData.filterInfo, E_DEVICESTATUS_READ_PARCEL_ERROR); + READINT32(data, dragData.sourceType, E_DEVICESTATUS_READ_PARCEL_ERROR); + READINT32(data, dragData.dragNum, E_DEVICESTATUS_READ_PARCEL_ERROR); + READINT32(data, dragData.pointerId, E_DEVICESTATUS_READ_PARCEL_ERROR); + READINT32(data, dragData.displayX, E_DEVICESTATUS_READ_PARCEL_ERROR); + READINT32(data, dragData.displayY, E_DEVICESTATUS_READ_PARCEL_ERROR); + READINT32(data, dragData.displayId, E_DEVICESTATUS_READ_PARCEL_ERROR); + READBOOL(data, dragData.hasCanceledAnimation, E_DEVICESTATUS_READ_PARCEL_ERROR); + if (SummaryPacker::UnMarshalling(data, dragData.summarys) != RET_OK) { + FI_HILOGE("Failed to summarys unmarshalling"); + return RET_ERR; + } + return RET_OK; +} + +int32_t ShadowPacker::Marshalling(const std::vector &shadowInfos, Parcel &data) +{ + CALL_DEBUG_ENTER; + if (shadowInfos.empty()) { + FI_HILOGE("Invalid parameter shadowInfos"); + return ERR_INVALID_VALUE; + } + int32_t shadowNum = static_cast(shadowInfos.size()); + if (shadowNum > SHADOW_NUM_LIMIT) { + FI_HILOGW("Only %{public}d shadowInfos are allowed to be packaged at most, now %{public}d exceeding the limit", + SHADOW_NUM_LIMIT, shadowNum); + shadowNum = SHADOW_NUM_LIMIT; + } + WRITEINT32(data, shadowNum, ERR_INVALID_VALUE); + for (int32_t i = 0; i < shadowNum; i++) { + CHKPR(shadowInfos[i].pixelMap, RET_ERR); + if (!shadowInfos[i].pixelMap->Marshalling(data)) { + FI_HILOGE("Failed to marshalling pixelMap"); + return ERR_INVALID_VALUE; + } + WRITEINT32(data, shadowInfos[i].x, ERR_INVALID_VALUE); + WRITEINT32(data, shadowInfos[i].y, ERR_INVALID_VALUE); + } + return RET_OK; +} + +int32_t ShadowPacker::UnMarshalling(Parcel &data, std::vector &shadowInfos) +{ + CALL_DEBUG_ENTER; + int32_t shadowNum { 0 }; + READINT32(data, shadowNum, E_DEVICESTATUS_READ_PARCEL_ERROR); + if (shadowNum <= 0 || shadowNum > SHADOW_NUM_LIMIT) { + FI_HILOGE("Invalid shadowNum:%{public}d", shadowNum); + return RET_ERR; + } + for (int32_t i = 0; i < shadowNum; i++) { + ShadowInfo shadowInfo; + auto pixelMap = OHOS::Media::PixelMap::Unmarshalling(data); + CHKPR(pixelMap, RET_ERR); + shadowInfo.pixelMap = std::shared_ptr(pixelMap); + READINT32(data, shadowInfo.x, E_DEVICESTATUS_READ_PARCEL_ERROR); + READINT32(data, shadowInfo.y, E_DEVICESTATUS_READ_PARCEL_ERROR); + shadowInfos.push_back(shadowInfo); + } + return RET_OK; +} + +int32_t SummaryPacker::Marshalling(const SummaryMap &val, Parcel &parcel) +{ + WRITEINT32(parcel, static_cast(val.size()), ERR_INVALID_VALUE); + for (auto const &[k, v] : val) { + WRITESTRING(parcel, k, ERR_INVALID_VALUE); + WRITEINT64(parcel, v, ERR_INVALID_VALUE); + } + return RET_OK; +} + +int32_t SummaryPacker::UnMarshalling(Parcel &parcel, SummaryMap &val) +{ + int32_t size = 0; + READINT32(parcel, size, E_DEVICESTATUS_READ_PARCEL_ERROR); + if (size < 0) { + FI_HILOGE("Invalid size:%{public}d", size); + return RET_ERR; + } + size_t readAbleSize = parcel.GetReadableBytes(); + if ((static_cast(size) > readAbleSize) || static_cast(size) > val.max_size()) { + FI_HILOGE("Invalid size:%{public}d", size); + return RET_ERR; + } + for (int32_t i = 0; i < size; ++i) { + std::string key; + READSTRING(parcel, key, E_DEVICESTATUS_READ_PARCEL_ERROR); + READINT64(parcel, val[key], E_DEVICESTATUS_READ_PARCEL_ERROR); + } + return RET_OK; +} +} // namespace DeviceStatus +} // namespace Msdp +} // namespace OHOS diff --git a/utils/common/src/utility.cpp b/utils/common/src/utility.cpp index b6c3835b3..10c2e1c2a 100644 --- a/utils/common/src/utility.cpp +++ b/utils/common/src/utility.cpp @@ -215,37 +215,6 @@ void Utility::ShowUserAndGroup() } } } - -bool Utility::Marshalling(const summaryMap &val, Parcel &parcel) -{ - WRITEINT32(parcel, static_cast(val.size()), false); - for (auto const &[k, v] : val) { - WRITESTRING(parcel, k, false); - WRITEINT64(parcel, v, false); - } - return true; -} - -bool Utility::Unmarshalling(summaryMap &val, Parcel &parcel) -{ - int32_t size = 0; - READINT32(parcel, size, false); - if (size < 0) { - FI_HILOGE("Invalid size:%{public}d", size); - return false; - } - size_t readAbleSize = parcel.GetReadableBytes(); - if ((static_cast(size) > readAbleSize) || static_cast(size) > val.max_size()) { - return false; - } - - for (int32_t i = 0; i < size; ++i) { - std::string key; - READSTRING(parcel, key, E_DEVICESTATUS_READ_PARCEL_ERROR); - READINT64(parcel, val[key], E_DEVICESTATUS_READ_PARCEL_ERROR); - } - return true; -} } // namespace DeviceStatus } // namespace Msdp } // namespace OHOS