diff --git a/interfaces/innerkits/wm/window_manager.h b/interfaces/innerkits/wm/window_manager.h index bbdc7aec17925a0875dae445ff8e2bb3bc95b83d..05adbe9f7c477c7348e37561f420c85800455d0c 100644 --- a/interfaces/innerkits/wm/window_manager.h +++ b/interfaces/innerkits/wm/window_manager.h @@ -909,6 +909,16 @@ public: */ WMError SetWindowLayoutMode(WindowLayoutMode mode); + /** + * @brief Global coordinate to relative coordinate conversion in foldedPC + * + * @param rect global coordinates. + * @param newRect Converted relative coordinates + * @param newDisplayId Current window ID + * @return WM_OK means converted, others means not converted. + */ + WMError ConvertToRelativeCoordinateForFoldPC(const Rect& rect, Rect& newRect, DisplayId& newDisplayId); + /** * @brief Get accessibility window info. * diff --git a/test/common/mock/mock_window_adapter.h b/test/common/mock/mock_window_adapter.h index b5cd83e112e4b030541dc350748cd3765ec4673d..a29a7559b81a50edffa9f9c06e71b61aba58e2e1 100644 --- a/test/common/mock/mock_window_adapter.h +++ b/test/common/mock/mock_window_adapter.h @@ -50,6 +50,8 @@ public: const sptr& windowManagerAgent)); MOCK_METHOD1(GetVisibilityWindowInfo, WMError(std::vector>& infos)); MOCK_METHOD1(GetAccessibilityWindowInfo, WMError(std::vector>& infos)); + MOCK_METHOD3(ConvertToRelativeCoordinateForFoldPC, WMError(const Rect& rect, + Rect& newRect, DisplayId& newDisplayId)); MOCK_METHOD2(GetUnreliableWindowInfo, WMError(int32_t windowId, std::vector>& infos)); MOCK_METHOD1(RaiseToAppTop, WMError(uint32_t windowId)); MOCK_METHOD1(GetSystemConfig, WMError(SystemConfig& systemConfig)); diff --git a/window_scene/session_manager/include/scene_session_manager.h b/window_scene/session_manager/include/scene_session_manager.h index b8488c0c1479e8e6c731738b0a3966cee887a416..a949b7701e07cbcf401cf11b265d41f4a6a6a7ed 100644 --- a/window_scene/session_manager/include/scene_session_manager.h +++ b/window_scene/session_manager/include/scene_session_manager.h @@ -409,6 +409,7 @@ public: void NotifySessionTouchOutside(int32_t persistentId, DisplayId displayId); WMError GetAccessibilityWindowInfo(std::vector>& infos) override; + WMError ConvertToRelativeCoordinateForFoldPC(const Rect& rect, Rect& newRect, DisplayId& newDisplayId) override; WMError GetUnreliableWindowInfo(int32_t windowId, std::vector>& infos) override; WSError SetWindowFlags(const sptr& sceneSession, const sptr& property); diff --git a/window_scene/session_manager/include/zidl/scene_session_manager_interface.h b/window_scene/session_manager/include/zidl/scene_session_manager_interface.h index 8af9a8d0b3cda199844e7c369495ae94719e5f34..f6b9707823c232cfb6f0073ec4eaecfd1b65848e 100644 --- a/window_scene/session_manager/include/zidl/scene_session_manager_interface.h +++ b/window_scene/session_manager/include/zidl/scene_session_manager_interface.h @@ -156,6 +156,7 @@ public: TRANS_ID_REMOVE_SESSION_BLACK_LIST, TRANS_ID_GET_PIP_SWITCH_STATUS, TRANS_ID_RECOVER_WINDOW_PROPERTY_CHANGE_FLAG, + TRANS_ID_GLOBAL_COORDINATE_TO_RELATIVE_COORDINATE, }; virtual WSError SetSessionLabel(const sptr& token, const std::string& label) = 0; @@ -445,6 +446,11 @@ public: WMError RemoveSessionBlackList(const std::unordered_set& bundleNames, const std::unordered_set& privacyWindowTags) override { return WMError::WM_OK; } WMError GetPiPSettingSwitchStatus(bool& switchStatus) override { return WMError::WM_OK; } + WMError ConvertToRelativeCoordinateForFoldPC( + const Rect& rect, Rect& newRect, DisplayId& newDisplayId) override + { + return WMError::WM_OK; + } }; } // namespace OHOS::Rosen #endif // OHOS_ROSEN_WINDOW_SCENE_SESSION_MANAGER_INTERFACE_H diff --git a/window_scene/session_manager/include/zidl/scene_session_manager_proxy.h b/window_scene/session_manager/include/zidl/scene_session_manager_proxy.h index 285e7f6ac81855e9513b833c80bc496a72f9eb96..70e48004ba88de67525b8dd7f5e72cc9263189a0 100644 --- a/window_scene/session_manager/include/zidl/scene_session_manager_proxy.h +++ b/window_scene/session_manager/include/zidl/scene_session_manager_proxy.h @@ -63,6 +63,7 @@ public: WSError SetSessionIcon(const sptr& token, const std::shared_ptr& icon) override; WSError IsValidSessionIds(const std::vector& sessionIds, std::vector& results) override; WMError GetAccessibilityWindowInfo(std::vector>& infos) override; + WMError ConvertToRelativeCoordinateForFoldPC(const Rect& rect, Rect& newRect, DisplayId& newDisplayId) override; WMError GetUnreliableWindowInfo(int32_t windowId, std::vector>& infos) override; WSError PendingSessionToForeground(const sptr& token, int32_t windowMode = DEFAULT_INVALID_WINDOW_MODE) override; diff --git a/window_scene/session_manager/include/zidl/scene_session_manager_stub.h b/window_scene/session_manager/include/zidl/scene_session_manager_stub.h index 57ca3b9ae61b266f8c89582187592c9bc7bccf6c..85d64151516f8c934831fc097093d109caa004a5 100644 --- a/window_scene/session_manager/include/zidl/scene_session_manager_stub.h +++ b/window_scene/session_manager/include/zidl/scene_session_manager_stub.h @@ -33,6 +33,7 @@ public: private: int HandleGetAccessibilityWindowInfo(MessageParcel& data, MessageParcel& reply); + int HandleConvertToRelativeCoordinateForFoldPC(MessageParcel& data, MessageParcel& reply); int HandleGetUnreliableWindowInfo(MessageParcel& data, MessageParcel& reply); int HandleRequestFocusStatus(MessageParcel& data, MessageParcel& reply); int HandleRequestFocusStatusBySA(MessageParcel& data, MessageParcel& reply); diff --git a/window_scene/session_manager/src/scene_session_manager.cpp b/window_scene/session_manager/src/scene_session_manager.cpp index bb1d458c4efb53f5b8d8e163dc7c639ac7f18dd3..dd794b7c9492b475924ac4bc6b2693c8366b3eef 100644 --- a/window_scene/session_manager/src/scene_session_manager.cpp +++ b/window_scene/session_manager/src/scene_session_manager.cpp @@ -10863,6 +10863,24 @@ WMError SceneSessionManager::GetAccessibilityWindowInfo(std::vectorPostSyncTask(task, "GetAccessibilityWindowInfo"); } +WMError SceneSessionManager::ConvertToRelativeCoordinateForFoldPC(const Rect& rect, Rect& newRect, DisplayId& newDisplayId) +{ + newRect = rect; + auto& PcFoldScreenManagerInstance = PcFoldScreenManager::GetInstance(); + SuperFoldStatus foldStatus = PcFoldScreenManagerInstance.GetScreenFoldStatus(); + TLOGD(WmsLogTag::WMS_LAYOUT, "foldStatus=%{public}d", static_cast(foldStatus)); + const auto& [defaultDisplayRect, virtualDisplayRect, foldCreaseRect] = + PcFoldScreenManagerInstance.GetDisplayRects(); + bool flag = rect.posY_ > (defaultDisplayRect.height_ + foldCreaseRect.height_); + if (foldStatus == SuperFoldStatus::HALF_FOLDED && flag) { + newRect.posY_ = rect.posY_ - defaultDisplayRect.height_ - foldCreaseRect.height_; + newDisplayId = VIRTUAL_DISPLAY_ID; + return WMError::WM_OK; + } else { + return WMError::WM_DO_NOTHING; + } +} + static bool CheckUnreliableWindowType(WindowType windowType) { if (windowType == WindowType::WINDOW_TYPE_APP_SUB_WINDOW || diff --git a/window_scene/session_manager/src/zidl/scene_session_manager_proxy.cpp b/window_scene/session_manager/src/zidl/scene_session_manager_proxy.cpp index ff0e9f6d4dceef7e70ae8fd87ca3cea1dac638e6..56daaffade26eccfc58b271260a570e177b87a33 100644 --- a/window_scene/session_manager/src/zidl/scene_session_manager_proxy.cpp +++ b/window_scene/session_manager/src/zidl/scene_session_manager_proxy.cpp @@ -2698,6 +2698,58 @@ WSError SceneSessionManagerProxy::GetHostGlobalScaledRect(int32_t hostWindowId, return static_cast(reply.ReadInt32()); } +WMError SceneSessionManagerProxy::ConvertToRelativeCoordinateForFoldPC( + const Rect& rect, Rect& newRect, DisplayId& newDisplayId) +{ + TLOGD(WmsLogTag::WMS_LAYOUT, "in"); + MessageParcel data; + MessageParcel reply; + MessageOption option; + if (!data.WriteInterfaceToken(GetDescriptor())) { + TLOGE(WmsLogTag::WMS_LAYOUT, "Write interface token failed."); + return WMError::WM_ERROR_IPC_FAILED; + } + if (!data.WriteInt32(rect.posX_) || !data.WriteInt32(rect.posY_) || + !data.WriteUint32(rect.width_) || !data.WriteUint32(rect.height_)) { + TLOGE(WmsLogTag::WMS_LAYOUT, "Failed to write rect"); + return WMError::WM_ERROR_IPC_FAILED; + } + sptr remote = Remote(); + if (remote == nullptr) { + TLOGE(WmsLogTag::WMS_MULTI_WINDOW, "remote is nullptr"); + return WMError::WM_ERROR_NULLPTR; + } + auto sendRet = remote->SendRequest( + static_cast(SceneSessionManagerMessage::TRANS_ID_GLOBAL_COORDINATE_TO_RELATIVE_COORDINATE), + data, reply, option); + if (sendRet != ERR_NONE) { + TLOGE(WmsLogTag::WMS_MULTI_WINDOW, "SendRequest ConvertToRelativeCoordinateForFoldPC failed"); + return WMError::WM_ERROR_IPC_FAILED; + } + int32_t posX = 0; + int32_t posY = 0; + uint32_t width = 0; + uint32_t height = 0; + if (!reply.ReadInt32(posX) || !reply.ReadInt32(posY) || + !reply.ReadInt32(width) || !reply.ReadInt32(height)) { + TLOGE(WmsLogTag::WMS_MULTI_WINDOW, "Failed to read rect"); + return WMError::WM_ERROR_IPC_FAILED; + } + newRect = {posX, posY, width, height}; + uint64_t displayId = 0; + if (!reply.ReadUint64(dispalyId)) { + TLOGE(WmsLogTag::WMS_MULTI_WINDOW, "Failed to read displayId"); + return WMError::WM_ERROR_IPC_FAILED; + } + newDisplayId = displayId; + int32_t result = 0; + if (!reply.ReadInt(result)) { + TLOGE(WmsLogTag::WMS_MULTI_WINDOW, "Failed to read result"); + return WMError::WM_ERROR_IPC_FAILED; + } + return static_cast(result); +} + WSError SceneSessionManagerProxy::GetFreeMultiWindowEnableState(bool& enable) { TLOGD(WmsLogTag::WMS_MULTI_WINDOW, "in"); diff --git a/window_scene/session_manager/src/zidl/scene_session_manager_stub.cpp b/window_scene/session_manager/src/zidl/scene_session_manager_stub.cpp index 61331467e22be4e061bb1627add51dda2ad8cd5e..94dd18682bd2d789135afdd3a911ba874b8f6065 100644 --- a/window_scene/session_manager/src/zidl/scene_session_manager_stub.cpp +++ b/window_scene/session_manager/src/zidl/scene_session_manager_stub.cpp @@ -87,6 +87,8 @@ int SceneSessionManagerStub::ProcessRemoteRequest(uint32_t code, MessageParcel& return HandleSetGestureNavigationEnabled(data, reply); case static_cast(SceneSessionManagerMessage::TRANS_ID_GET_WINDOW_INFO): return HandleGetAccessibilityWindowInfo(data, reply); + case static_cast(SceneSessionManagerMessage::TRANS_ID_GLOBAL_COORDINATE_TO_RELATIVE_COORDINATE): + return HandleConvertToRelativeCoordinateForFoldPC(data, reply); case static_cast(SceneSessionManagerMessage::TRANS_ID_GET_UNRELIABLE_WINDOW_INFO): return HandleGetUnreliableWindowInfo(data, reply); case static_cast(SceneSessionManagerMessage::TRANS_ID_REGISTER_SESSION_LISTENER): @@ -912,6 +914,39 @@ int SceneSessionManagerStub::HandleSetGestureNavigationEnabled(MessageParcel& da return ERR_NONE; } +int SceneSessionManagerStub::HandleConvertToRelativeCoordinateForFoldPC(MessageParcel& data, MessageParcel& reply) +{ + int32_t posX_ = 0; + int32_t posY_ = 0; + uint32_t width_ = 0; + uint32_t height_ = 0; + if (!data.ReadInt32(posX_) || !data.ReadInt32(posY_) || !data.ReadUint32(width_) || !data.ReadUint32(height_)) { + TLOGE(WmsLogTag::WMS_LAYOUT, "Read window infos failed."); + return ERR_TRANSACTION_FAILED; + } + Rect rect = { posX_, posY_, width_, height_ }; + Rect newRect; + DisplayId newDisplayId; + WMError errCode = ConvertToRelativeCoordinateForFoldPC(rect, newRect, newDisplayId); + if (!reply.WriteInt32(static_cast(newRect.posX_)) || + !reply.WriteInt32(static_cast(newRect.posY_)) || + !reply.WriteUint32(static_cast(newRect.width_)) || + !reply.WriteUint32(static_cast(newRect.height_)) + ) { + TLOGE(WmsLogTag::WMS_LAYOUT, "Write rect failed."); + return ERR_TRANSACTION_FAILED; + } + if (!reply.WriteUint64(static_cast(newDisplayId))) { + TLOGE(WmsLogTag::WMS_LAYOUT, "Write newDisplayId failed."); + return ERR_TRANSACTION_FAILED; + } + if (!reply.WriteInt32(static_cast(errCode))) { + TLOGE(WmsLogTag::WMS_LAYOUT, "Write errCode failed."); + return ERR_TRANSACTION_FAILED; + } + return ERR_NONE; +} + int SceneSessionManagerStub::HandleGetAccessibilityWindowInfo(MessageParcel& data, MessageParcel& reply) { std::vector> infos; @@ -989,32 +1024,6 @@ int SceneSessionManagerStub::HandleUpdateSessionAvoidAreaListener(MessageParcel& return ERR_NONE; } -int SceneSessionManagerStub::HandleGetSessionSnapshot(MessageParcel& data, MessageParcel& reply) -{ - TLOGD(WmsLogTag::WMS_SYSTEM, "Handled!"); - std::u16string deviceIdData; - if (!data.ReadString16(deviceIdData)) { - TLOGE(WmsLogTag::WMS_SYSTEM, "read deviceId fail"); - return ERR_INVALID_DATA; - } - std::string deviceId = Str16ToStr8(deviceIdData); - int32_t persistentId = 0; - if (!data.ReadInt32(persistentId)) { - TLOGE(WmsLogTag::WMS_SYSTEM, "read persistentId fail"); - return ERR_INVALID_DATA; - } - bool isLowResolution = false; - if (!data.ReadBool(isLowResolution)) { - TLOGE(WmsLogTag::WMS_SYSTEM, "read isLowResolution fail"); - return ERR_INVALID_DATA; - } - std::shared_ptr snapshot = std::make_shared(); - WSError ret = GetSessionSnapshot(deviceId, persistentId, *snapshot, isLowResolution); - reply.WriteParcelable(snapshot.get()); - reply.WriteUint32(static_cast(ret)); - return ERR_NONE; -} - int SceneSessionManagerStub::HandleGetSessionSnapshotById(MessageParcel& data, MessageParcel& reply) { TLOGD(WmsLogTag::WMS_SYSTEM, "Handled!"); @@ -2483,4 +2492,31 @@ int SceneSessionManagerStub::HandleGetPiPSettingSwitchStatus(MessageParcel& data } return ERR_NONE; } + + +int SceneSessionManagerStub::HandleGetSessionSnapshot(MessageParcel& data, MessageParcel& reply) +{ + TLOGD(WmsLogTag::WMS_SYSTEM, "Handled!"); + std::u16string deviceIdData; + if (!data.ReadString16(deviceIdData)) { + TLOGE(WmsLogTag::WMS_SYSTEM, "read deviceId fail"); + return ERR_INVALID_DATA; + } + std::string deviceId = Str16ToStr8(deviceIdData); + int32_t persistentId = 0; + if (!data.ReadInt32(persistentId)) { + TLOGE(WmsLogTag::WMS_SYSTEM, "read persistentId fail"); + return ERR_INVALID_DATA; + } + bool isLowResolution = false; + if (!data.ReadBool(isLowResolution)) { + TLOGE(WmsLogTag::WMS_SYSTEM, "read isLowResolution fail"); + return ERR_INVALID_DATA; + } + std::shared_ptr snapshot = std::make_shared(); + WSError ret = GetSessionSnapshot(deviceId, persistentId, *snapshot, isLowResolution); + reply.WriteParcelable(snapshot.get()); + reply.WriteUint32(static_cast(ret)); + return ERR_NONE; +} } // namespace OHOS::Rosen \ No newline at end of file diff --git a/window_scene/test/unittest/layout/scene_session_manager_layout_test.cpp b/window_scene/test/unittest/layout/scene_session_manager_layout_test.cpp index 5971ebc5af1699268305fa7623c7d5a1ab0a61f2..408c05390fe33719c8009e158d377b020caa674d 100644 --- a/window_scene/test/unittest/layout/scene_session_manager_layout_test.cpp +++ b/window_scene/test/unittest/layout/scene_session_manager_layout_test.cpp @@ -227,6 +227,31 @@ HWTEST_F(SceneSessionManagerLayoutTest, NotifySingleHandInfoChange_TestMode, Tes ssm_->singleHandTransform_ = singleHandTransform; } +/** + * @tc.name: ConvertToRelativeCoordinateForFoldPC_TestMode + * @tc.desc: test function : ConvertToRelativeCoordinateForFoldPC + * @tc.type: FUNC + */ +HWTEST_F(SceneSessionManagerLayoutTest, ConvertToRelativeCoordinateForFoldPC_TestMode, TestSize.Level1) +{ + Rect rect = { 100, 3500, 400, 600}; + Rect newRect; + DisplayId newDisplayId; + // Convert success + PcFoldScreenManager::GetInstance().UpdateFoldScreenStatus(0, SuperFoldStatus::HALF_FOLDED, + { 0, 0, 2472, 1648}, {0, 1648, 2472, 1648}, {0, 1642, 2472, 1648}); + ssm_->ConvertToRelativeCoordinateForFoldPC(rect, newRect, newDisplayId); + EXPECT_EQ(204, newRect.posY_); + EXPECT_EQ(999, newDisplayId); + + // Convert Failed + newDisplayId = 0; + rect = { 100, 200, 400, 600 }; + ssm_->ConvertToRelativeCoordinateForFoldPC(rect, newRect, newDisplayId); + EXPECT_EQ(200, newRect.posY_); + EXPECT_EQ(0, newDisplayId); +} + /** * @tc.name: SetHasRootSceneRequestedVsyncFunc * @tc.desc: SetHasRootSceneRequestedVsyncFunc diff --git a/window_scene/test/unittest/scene_session_manager_proxy_test.cpp b/window_scene/test/unittest/scene_session_manager_proxy_test.cpp index abb741b14602a0b72481e2f31ca1f94343a05ac9..261805a901a11b5488144a31ba3147e535a4002b 100644 --- a/window_scene/test/unittest/scene_session_manager_proxy_test.cpp +++ b/window_scene/test/unittest/scene_session_manager_proxy_test.cpp @@ -2023,6 +2023,50 @@ HWTEST_F(sceneSessionManagerProxyTest, RemoveSessionBlackList02, TestSize.Level1 EXPECT_EQ(ret, WMError::WM_OK); } +/** + * @tc.name: ConvertToRelativeCoordinateForFoldPC01 + * @tc.desc: ConvertToRelativeCoordinateForFoldPC + * @tc.type: FUNC + */ +HWTEST_F(sceneSessionManagerProxyTest, ConvertToRelativeCoordinateForFoldPC01, TestSize.Level1) +{ + Rect rect; + Rect newRect; + DisplayId newDisplayId = 0; + rect = { 100, 2000, 400, 600 }; + newRect = { 0, 100, 200, 300 }; + + sptr remoteMocker = nullptr; + auto proxy = sptr::MakeSptr(remoteMocker); + auto ret = proxy->ConvertToRelativeCoordinateForFoldPC(rect, newRect, newDisplayId); + EXPECT_EQ(ret, WMError::WS_ERROR_NULLPTR); + ASSERT_NE(proxy, nullptr); + + // WriteInterfaceToken failed + MockMessageParcel::ClearAllErrorFlag(); + MockMessageParcel::SetWriteInterfaceTokenErrorFlag(true); + ret = proxy->ConvertToRelativeCoordinateForFoldPC(rect, newRect, newDisplayId); + EXPECT_EQ(WMError::WS_ERROR_NULLPTR, ret); + MockMessageParcel::SetWriteInterfaceTokenErrorFlag(false); + + MockMessageParcel::SetWriteInt32ErrorFlag(true); + ret = proxy->ConvertToRelativeCoordinateForFoldPC(rect, newRect, newDisplayId); + EXPECT_EQ(WMError::WM_ERROR_IPC_FAILED, ret); + MockMessageParcel::SetWriteInt32ErrorFlag(false); + + MockMessageParcel::SetWriteUint32ErrorFlag(true); + ret = proxy->ConvertToRelativeCoordinateForFoldPC(rect, newRect, newDisplayId); + EXPECT_EQ(WMError::WM_ERROR_IPC_FAILED, ret); + MockMessageParcel::SetWriteUint32ErrorFlag(false); + + // SendRequest failed + ASSERT_NE(proxy, nullptr); + remoteMocker->SetRequestResult(ERR_INVALID_DATA); + ret = proxy->ConvertToRelativeCoordinateForFoldPC(rect, newRect, newDisplayId); + EXPECT_EQ(ret, WMError::WM_ERROR_IPC_FAILED); + remoteMocker->SetRequestResult(ERR_NONE); +} + /** * @tc.name: RecoverWindowPropertyChangeFlag01 * @tc.desc: RecoverWindowPropertyChangeFlag diff --git a/window_scene/test/unittest/scene_session_manager_stub_test.cpp b/window_scene/test/unittest/scene_session_manager_stub_test.cpp index 4f901b1675d806e223f1e042e7a4380a8aba752e..26477522bfcbdcfd5706d6c0f39f4ca5661272e1 100644 --- a/window_scene/test/unittest/scene_session_manager_stub_test.cpp +++ b/window_scene/test/unittest/scene_session_manager_stub_test.cpp @@ -1672,6 +1672,46 @@ HWTEST_F(SceneSessionManagerStubTest, HandleSetGestureNavigationEnabled, TestSiz EXPECT_EQ(res, ERR_NONE); } +/** + * @tc.name: HandleConvertToRelativeCoordinateForFoldPC + * @tc.desc: test HandleConvertToRelativeCoordinateForFoldPC + * @tc.type: FUNC + */ +HWTEST_F(SceneSessionManagerStubTest, HandleConvertToRelativeCoordinateForFoldPC, TestSize.Level1) +{ + MessageParcel data1; + MessageParcel reply; + + data1.WriteInt32(rect_.posX_); + data1.WriteInt32(rect_.posY_); + data1.WriteInt32(rect_.width_); + data1.WriteInt32(rect_.height_); + int res1 = stub_->HandleConvertToRelativeCoordinateForFoldPC(data1, reply); + EXPECT_EQ(res1, ERR_NONE); + + MessageParcel data2; + data2.WriteInt32(rect_.posX_); + data2.WriteInt32(rect_.posY_); + data2.WriteInt32(rect_.width_); + int res2 = stub_->HandleConvertToRelativeCoordinateForFoldPC(data2, reply); + EXPECT_EQ(res2, ERR_TRANSACTION_FAILED); + + MessageParcel data3; + data3.WriteInt32(rect_.posX_); + data3.WriteInt32(rect_.posY_); + int res3 = stub_->HandleConvertToRelativeCoordinateForFoldPC(data3, reply); + EXPECT_EQ(res3, ERR_TRANSACTION_FAILED); + + MessageParcel data4; + data4.WriteInt32(rect_.posX_); + int res4 = stub_->HandleConvertToRelativeCoordinateForFoldPC(data4, reply); + EXPECT_EQ(res4, ERR_TRANSACTION_FAILED); + + MessageParcel data5; + int res5 = stub_->HandleConvertToRelativeCoordinateForFoldPC(data5, reply); + EXPECT_EQ(res5, ERR_TRANSACTION_FAILED); +} + /** * @tc.name: HandleGetAccessibilityWindowInfo * @tc.desc: test HandleGetAccessibilityWindowInfo diff --git a/wm/include/window_adapter.h b/wm/include/window_adapter.h index 6367df9994be86ed99f70f85e9f930cab2d7f870..86fa9296d4630e2dd8a51684438ebe1d80efbf7b 100644 --- a/wm/include/window_adapter.h +++ b/wm/include/window_adapter.h @@ -84,6 +84,7 @@ public: virtual void ClearWindowAdapter(); virtual WMError GetAccessibilityWindowInfo(std::vector>& infos); + virtual WMError ConvertToRelativeCoordinateForFoldPC(const Rect& rect, Rect& newRect, DisplayId& newDisplayId); virtual WMError GetUnreliableWindowInfo(int32_t windowId, std::vector>& infos); virtual WMError ListWindowInfo(const WindowInfoOption& windowInfoOption, std::vector>& infos); virtual WMError GetAllWindowLayoutInfo(DisplayId displayId, std::vector>& infos); diff --git a/wm/src/window_adapter.cpp b/wm/src/window_adapter.cpp index 5ca46b6e7b103f148a8d36b9152d5681bad8322e..db1a041582c9704b391858da343fac281a5bf4b5 100644 --- a/wm/src/window_adapter.cpp +++ b/wm/src/window_adapter.cpp @@ -292,6 +292,15 @@ WMError WindowAdapter::GetAccessibilityWindowInfo(std::vectorGetAccessibilityWindowInfo(infos); } +WMError WindowAdapter::ConvertToRelativeCoordinateForFoldPC(const Rect& rect, Rect& newRect, DisplayId& newDisplayId) +{ + INIT_PROXY_CHECK_RETURN(WMError::WM_ERROR_SAMGR); + + auto wmsProxy = GetWindowManagerServiceProxy(); + CHECK_PROXY_RETURN_ERROR_IF_NULL(wmsProxy, WMError::WM_DO_NOTHING); + return wmsProxy->ConvertToRelativeCoordinateForFoldPC(rect, newRect, newDisplayId); +} + WMError WindowAdapter::GetUnreliableWindowInfo(int32_t windowId, std::vector>& infos) { diff --git a/wm/src/window_manager.cpp b/wm/src/window_manager.cpp index aeff5a314cc6fecdb62a2dafdc61944f7cbf6189..e29aa423dcbdcea7de959f240ed9af41c0c3b8dd 100644 --- a/wm/src/window_manager.cpp +++ b/wm/src/window_manager.cpp @@ -1691,6 +1691,16 @@ WMError WindowManager::GetAccessibilityWindowInfo(std::vector().ConvertToRelativeCoordinateForFoldPC(rect, newRect, newDisplayId); + if (ret != WMError::WM_OK) { + TLOGE(WmsLogTag::WMS_LAYOUT, "change failed."); + } + return ret; +} + WMError WindowManager::GetUnreliableWindowInfo(int32_t windowId, std::vector>& infos) const { diff --git a/wm/test/unittest/window_adapter_test.cpp b/wm/test/unittest/window_adapter_test.cpp index e3c320e10753b67fc6ca00483adf99ff338943a6..41bbd3be8066248725e47e53705ceb18e135a1f6 100644 --- a/wm/test/unittest/window_adapter_test.cpp +++ b/wm/test/unittest/window_adapter_test.cpp @@ -157,6 +157,27 @@ HWTEST_F(WindowAdapterTest, GetAccessibilityWindowInfo, TestSize.Level1) ASSERT_EQ(WMError::WM_OK, windowAdapter.GetAccessibilityWindowInfo(infos)); } +/** + * @tc.name: ConvertToRelativeCoordinateForFoldPC + * @tc.desc: WindowAdapter/ConvertToRelativeCoordinateForFoldPC + * @tc.type: FUNC + */ +HWTEST_F(WindowAdapterTest, ConvertToRelativeCoordinateForFoldPC, TestSize.Level1) +{ + WindowAdapter windowAdapter; + Rect rect; + Rect newRect; + DisplayId newDisplayId = 0; + rect = { 100, 3000, 400, 600 }; + auto ret = windowAdapter.ConvertToRelativeCoordinateForFoldPC(rect, newRect, newDisplayId); + EXPECT_EQ(WMError::WM_DO_NOTHING, ret); + EXPECT_EQ(newRect.posX_, 100); + EXPECT_EQ(newRect.posY_, 3000); + EXPECT_EQ(newRect.width_, 400); + EXPECT_EQ(newRect.height_, 600); + EXPECT_EQ(newRect.newDisplayId, 0); +} + /** * @tc.name: GetGlobalWindowMode * @tc.desc: WindowAdapter/GetGlobalWindowMode diff --git a/wm/test/unittest/window_manager_test.cpp b/wm/test/unittest/window_manager_test.cpp index 4a44b92e9b1dcba760d9b4e6e9f74552b3bd9577..4f36f3c9af0f14345c1f54a98ef4848d80ae2995 100644 --- a/wm/test/unittest/window_manager_test.cpp +++ b/wm/test/unittest/window_manager_test.cpp @@ -291,6 +291,21 @@ HWTEST_F(WindowManagerTest, GetAccessibilityWindowInfo01, TestSize.Level1) ASSERT_EQ(WMError::WM_ERROR_INVALID_WINDOW, WindowManager::GetInstance().GetAccessibilityWindowInfo(infos)); } +/** + * @tc.name: ConvertToRelativeCoordinateForFoldPC + * @tc.desc: ConvertToRelativeCoordinateForFoldPC ok + * @tc.type: FUNC + */ +HWTEST_F(WindowManagerTest, ConvertToRelativeCoordinateForFoldPC, TestSize.Level1) +{ + Rect rect; + Rect newRect; + DisplayId newDisplayId = 0; + rect = { 100, 2000, 400, 600 }; + auto ret = WindowManager::GetInstance().ConvertToRelativeCoordinateForFoldPC(rect, newRect, newDisplayId); + EXPECT_EQ(WMError::WM_OK, ret); +} + /** * @tc.name: GetUnreliableWindowInfo * @tc.desc: GetUnreliableWindowInfo ok diff --git a/wmserver/include/zidl/window_manager_interface.h b/wmserver/include/zidl/window_manager_interface.h index 8fabfad55df58cc213081d83a4c1b03ba2538b7c..51ffe542f64a393ebdb81ddd2e5c4d7c2a5587db 100644 --- a/wmserver/include/zidl/window_manager_interface.h +++ b/wmserver/include/zidl/window_manager_interface.h @@ -257,6 +257,10 @@ public: { return WSError::WS_OK; } + virtual WMError ConvertToRelativeCoordinateForFoldPC(const Rect& rect, Rect& newRect, DisplayId& newDisplayId) + { + return WMError::WM_OK; + } virtual WSError GetHostWindowRect(int32_t hostWindowId, Rect& rect) { return WSError::WS_OK;