diff --git a/window_scene/screen_session_manager/src/screen_aod_plugin.cpp b/window_scene/screen_session_manager/src/screen_aod_plugin.cpp index 26c1e83461acaaacb4bb9066f65dde5c45c8e745..d9a46b7a2c60394284c4dbf64962247489ff9b45 100644 --- a/window_scene/screen_session_manager/src/screen_aod_plugin.cpp +++ b/window_scene/screen_session_manager/src/screen_aod_plugin.cpp @@ -31,9 +31,14 @@ bool LoadAodLib(void) } int32_t cnt = 0; int32_t retryTimes = 3; + const char* dlopenError; do { cnt++; g_handle = dlopen(PLUGIN_AOD_SO_PATH.c_str(), RTLD_LAZY); + dlopenError = dlerror(); + if (dlopenError) { + TLOGE(WmsLogTag::DMS, "dlopen error: %{public}s", dlopenError); + } TLOGI(WmsLogTag::DMS, "dlopen %{public}s, retry cnt: %{public}d", PLUGIN_AOD_SO_PATH.c_str(), cnt); usleep(SLEEP_TIME_US); } while (!g_handle && cnt < retryTimes); diff --git a/window_scene/screen_session_manager/src/screen_sensor_plugin.cpp b/window_scene/screen_session_manager/src/screen_sensor_plugin.cpp index 2a5d33b0c9b641b3629e072ec3808046c4aaf7e4..489fcb89be0bff78d271ae9dc3ba4e7dc37c3994 100644 --- a/window_scene/screen_session_manager/src/screen_sensor_plugin.cpp +++ b/window_scene/screen_session_manager/src/screen_sensor_plugin.cpp @@ -31,9 +31,14 @@ bool LoadMotionSensor(void) } int32_t cnt = 0; int32_t retryTimes = 3; + const char* dlopenError; do { cnt++; g_handle = dlopen(PLUGIN_SO_PATH.c_str(), RTLD_LAZY); + dlopenError = dlerror(); + if (dlopenError) { + TLOGE(WmsLogTag::DMS, "dlopen error: %{public}s", dlopenError); + } TLOGI(WmsLogTag::DMS, "dlopen %{public}s, retry cnt: %{public}d", PLUGIN_SO_PATH.c_str(), cnt); usleep(SLEEP_TIME_US); } while (!g_handle && cnt < retryTimes); diff --git a/window_scene/screen_session_manager/src/screen_session_manager.cpp b/window_scene/screen_session_manager/src/screen_session_manager.cpp index 693884c894fcc65a3a003a29e311be70a29c5019..7bdfa57ee82451f7f682a0af89d97f960d65ef45 100644 --- a/window_scene/screen_session_manager/src/screen_session_manager.cpp +++ b/window_scene/screen_session_manager/src/screen_session_manager.cpp @@ -11843,7 +11843,7 @@ Rotation ScreenSessionManager::RemoveRotationCorrection(Rotation rotation) Rotation ScreenSessionManager::GetConfigCorrectionByDisplayMode(FoldDisplayMode displayMode) { if (!CORRECTION_ENABLE) { - return Rotation::ROTATION_0; + return Rotation::ROTATION_0; } InitRotationCorrectionMap(DISPLAYMODE_CORRECTION); std::shared_lock lock(rotationCorrectionMutex_); diff --git a/window_scene/session/screen/include/screen_session.h b/window_scene/session/screen/include/screen_session.h index dbb4b80795a168b6d2f7019a3cf2eb04e71dda1a..5ab1768dd6cad1e4c19fd7fdee6b927f8075481e 100644 --- a/window_scene/session/screen/include/screen_session.h +++ b/window_scene/session/screen/include/screen_session.h @@ -388,6 +388,8 @@ public: void UpdateMirrorHeight(uint32_t mirrorHeight); private: + bool IsVertical(Rotation rotation) const; + Orientation CalcDisplayOrientationToOrientation(DisplayOrientation displayOrientation) const; ScreenProperty property_; mutable std::mutex propertyMutex_; // above guarded by clientProxyMutex_ std::shared_ptr displayNode_; diff --git a/window_scene/session/screen/src/screen_session.cpp b/window_scene/session/screen/src/screen_session.cpp index 6873db100d031da14d913643293566cfd37db257..8acee96ce267742c61f569616b9aafd2cfeb341f 100644 --- a/window_scene/session/screen/src/screen_session.cpp +++ b/window_scene/session/screen/src/screen_session.cpp @@ -1317,16 +1317,16 @@ void ScreenSession::SetScreenType(ScreenType type) Rotation ScreenSession::CalcRotation(Orientation orientation, FoldDisplayMode foldDisplayMode) const { - sptr info = GetActiveScreenMode(); - if (info == nullptr) { - return Rotation::ROTATION_0; - } - // vertical: phone(Plugin screen); horizontal: pad & external screen - bool isVerticalScreen = info->width_ < info->height_; - if (foldDisplayMode != FoldDisplayMode::UNKNOWN && - (g_screenRotationOffSet == ROTATION_90 || g_screenRotationOffSet == ROTATION_270)) { - isVerticalScreen = info->width_ > info->height_; - } + // Calculate the width and height based on the 0-degree rotation direction, and set the orientation + Rotation deviceRotation = property_.GetDeviceRotation(); + auto bounds = property_.GetBounds(); + uint32_t width = bounds.rect_.GetWidth(); + uint32_t height = bounds.rect_.GetHeight(); + if (!IsVertical(deviceRotation)) { + width = bounds.rect_.GetHeight(); + height = bounds.rect_.GetWidth(); + } + bool isVerticalScreen = width < height; switch (orientation) { case Orientation::UNSPECIFIED: { return Rotation::ROTATION_0; @@ -1335,13 +1335,13 @@ Rotation ScreenSession::CalcRotation(Orientation orientation, FoldDisplayMode fo return isVerticalScreen ? Rotation::ROTATION_0 : Rotation::ROTATION_90; } case Orientation::HORIZONTAL: { - return isVerticalScreen ? Rotation::ROTATION_90 : Rotation::ROTATION_0; + return isVerticalScreen ? Rotation::ROTATION_90 : Rotation::ROTATION_180; } case Orientation::REVERSE_VERTICAL: { return isVerticalScreen ? Rotation::ROTATION_180 : Rotation::ROTATION_270; } case Orientation::REVERSE_HORIZONTAL: { - return isVerticalScreen ? Rotation::ROTATION_270 : Rotation::ROTATION_180; + return isVerticalScreen ? Rotation::ROTATION_270 : Rotation::ROTATION_0; } default: { TLOGE(WmsLogTag::DMS, "unknown orientation %{public}u", orientation); @@ -1350,6 +1350,11 @@ Rotation ScreenSession::CalcRotation(Orientation orientation, FoldDisplayMode fo } } +bool ScreenSession::IsVertical(Rotation rotation) const +{ + return (rotation == Rotation::ROTATION_0 || rotation == Rotation::ROTATION_180); +} + DisplayOrientation ScreenSession::CalcDisplayOrientation(Rotation rotation, FoldDisplayMode foldDisplayMode) { @@ -1581,7 +1586,7 @@ void ScreenSession::FillScreenInfo(sptr info) const info->SetVirtualHeight(height / virtualPixelRatio); info->SetVirtualWidth(width / virtualPixelRatio); info->SetRotation(property_.GetScreenRotation()); - info->SetOrientation(static_cast(property_.GetDisplayOrientation())); + info->SetOrientation(CalcDisplayOrientationToOrientation(property_.GetDisplayOrientation())); info->SetSourceMode(sourceMode); info->SetType(property_.GetScreenType()); info->SetModeId(activeIdx_); @@ -1595,6 +1600,33 @@ void ScreenSession::FillScreenInfo(sptr info) const info->modes_ = modes_; } +Orientation ScreenSession::CalcDisplayOrientationToOrientation(DisplayOrientation displayOrientation) const +{ + Orientation orientation = Orientation::UNSPECIFIED; + switch (displayOrientation) { + case DisplayOrientation::PORTRAIT: { + orientation = Orientation::VERTICAL; + break; + } + case DisplayOrientation::LANDSCAPE: { + orientation = Orientation::HORIZONTAL; + break; + } + case DisplayOrientation::PORTRAIT_INVERTED: { + orientation = Orientation::REVERSE_VERTICAL; + break; + } + case DisplayOrientation::LANDSCAPE_INVERTED: { + orientation = Orientation::REVERSE_HORIZONTAL; + break; + } + default: { + TLOGE(WmsLogTag::DMS, "unknown displayOrientation %{public}d", displayOrientation); + } + } + return orientation; +} + sptr ScreenSession::ConvertToScreenInfo() const { sptr info = new(std::nothrow) ScreenInfo(); diff --git a/window_scene/test/dms_unittest/screen_session_test.cpp b/window_scene/test/dms_unittest/screen_session_test.cpp index 545d230bc26810e4344b5d587d9691a0149d7c5e..7ff4d543d433dabcc395208cbf9c3d628059861c 100644 --- a/window_scene/test/dms_unittest/screen_session_test.cpp +++ b/window_scene/test/dms_unittest/screen_session_test.cpp @@ -2228,115 +2228,93 @@ HWTEST_F(ScreenSessionTest, GetRSScreenId, TestSize.Level1) } /** - * @tc.name: CalcRotation01 + * @tc.name: CalcRotation * @tc.desc: normal function * @tc.type: FUNC */ -HWTEST_F(ScreenSessionTest, CalcRotation01, TestSize.Level1) +HWTEST_F(ScreenSessionTest, CalcRotation, TestSize.Level1) { - GTEST_LOG_(INFO) << "ScreenSessionTest: CalcRotation start"; - Orientation orientation { Orientation::BEGIN }; - FoldDisplayMode foldDisplayMode { FoldDisplayMode::COORDINATION }; sptr session = sptr::MakeSptr(); - session->activeIdx_ = -1; + ScreenProperty property; + RRect bounds; + bounds.rect_.width_ = 1344; + bounds.rect_.height_ = 2772; + property.SetBounds(bounds); + property.UpdateDeviceRotation(Rotation::ROTATION_0); + session->SetScreenProperty(property); + Orientation orientation = Orientation::BEGIN; + FoldDisplayMode foldDisplayMode = FoldDisplayMode::UNKNOWN; auto res = session->CalcRotation(orientation, foldDisplayMode); EXPECT_EQ(Rotation::ROTATION_0, res); - - sptr supportedScreenModes = new SupportedScreenModes; - supportedScreenModes->width_ = 40; - supportedScreenModes->height_ = 20; - session->modes_ = { supportedScreenModes }; - session->activeIdx_ = 0; - orientation = Orientation::UNSPECIFIED; res = session->CalcRotation(orientation, foldDisplayMode); EXPECT_EQ(Rotation::ROTATION_0, res); - orientation = Orientation::VERTICAL; res = session->CalcRotation(orientation, foldDisplayMode); - if (ScreenSessionManager::GetInstance().IsFoldable() && !FoldScreenStateInternel::IsSuperFoldDisplayDevice()) { - EXPECT_EQ(Rotation::ROTATION_0, res); - } else { - EXPECT_EQ(Rotation::ROTATION_90, res); - } - + EXPECT_EQ(Rotation::ROTATION_0, res); orientation = Orientation::HORIZONTAL; res = session->CalcRotation(orientation, foldDisplayMode); - if (ScreenSessionManager::GetInstance().IsFoldable() && !FoldScreenStateInternel::IsSuperFoldDisplayDevice()) { - EXPECT_EQ(Rotation::ROTATION_90, res); - } else { - EXPECT_EQ(Rotation::ROTATION_0, res); - } - + EXPECT_EQ(Rotation::ROTATION_90, res); orientation = Orientation::REVERSE_VERTICAL; res = session->CalcRotation(orientation, foldDisplayMode); - if (ScreenSessionManager::GetInstance().IsFoldable() && !FoldScreenStateInternel::IsSuperFoldDisplayDevice()) { - EXPECT_EQ(Rotation::ROTATION_180, res); - } else { - EXPECT_EQ(Rotation::ROTATION_270, res); - } - + EXPECT_EQ(Rotation::ROTATION_180, res); orientation = Orientation::REVERSE_HORIZONTAL; res = session->CalcRotation(orientation, foldDisplayMode); - if (ScreenSessionManager::GetInstance().IsFoldable() && !FoldScreenStateInternel::IsSuperFoldDisplayDevice()) { - EXPECT_EQ(Rotation::ROTATION_270, res); - } else { - EXPECT_EQ(Rotation::ROTATION_180, res); - } - + EXPECT_EQ(Rotation::ROTATION_270, res); orientation = Orientation::LOCKED; res = session->CalcRotation(orientation, foldDisplayMode); EXPECT_EQ(Rotation::ROTATION_0, res); - GTEST_LOG_(INFO) << "ScreenSessionTest: CalcRotation end"; -} - -/** - * @tc.name: CalcRotation02 - * @tc.desc: normal function - * @tc.type: FUNC - */ -HWTEST_F(ScreenSessionTest, CalcRotation02, TestSize.Level1) -{ - GTEST_LOG_(INFO) << "ScreenSessionTest: CalcRotation start"; - Orientation orientation { Orientation::BEGIN }; - FoldDisplayMode foldDisplayMode { FoldDisplayMode::UNKNOWN }; - sptr session = sptr::MakeSptr(); - session->activeIdx_ = -1; - auto res = session->CalcRotation(orientation, foldDisplayMode); - EXPECT_EQ(Rotation::ROTATION_0, res); - - sptr supportedScreenModes = new SupportedScreenModes; - supportedScreenModes->width_ = 40; - supportedScreenModes->height_ = 20; - session->modes_ = { supportedScreenModes }; - session->activeIdx_ = 0; - - orientation = Orientation::UNSPECIFIED; - res = session->CalcRotation(orientation, foldDisplayMode); - EXPECT_EQ(Rotation::ROTATION_0, res); - + property.UpdateDeviceRotation(Rotation::ROTATION_90); + session->SetScreenProperty(property); orientation = Orientation::VERTICAL; res = session->CalcRotation(orientation, foldDisplayMode); EXPECT_EQ(Rotation::ROTATION_90, res); - orientation = Orientation::HORIZONTAL; res = session->CalcRotation(orientation, foldDisplayMode); - EXPECT_EQ(Rotation::ROTATION_0, res); - + EXPECT_EQ(Rotation::ROTATION_180, res); orientation = Orientation::REVERSE_VERTICAL; res = session->CalcRotation(orientation, foldDisplayMode); EXPECT_EQ(Rotation::ROTATION_270, res); - orientation = Orientation::REVERSE_HORIZONTAL; res = session->CalcRotation(orientation, foldDisplayMode); - EXPECT_EQ(Rotation::ROTATION_180, res); - - orientation = Orientation::LOCKED; - res = session->CalcRotation(orientation, foldDisplayMode); EXPECT_EQ(Rotation::ROTATION_0, res); +} - GTEST_LOG_(INFO) << "ScreenSessionTest: CalcRotation end"; +/** + * @tc.name: IsVertical + * @tc.desc: IsVertical + * @tc.type: FUNC + */ +HWTEST_F(ScreenSessionTest, IsVertical, TestSize.Level1) +{ + sptr session = sptr::MakeSptr(); + EXPECT_TRUE(session->IsVertical(Rotation::ROTATION_0)); + EXPECT_FALSE(session->IsVertical(Rotation::ROTATION_90)); + EXPECT_TRUE(session->IsVertical(Rotation::ROTATION_180)); + EXPECT_FALSE(session->IsVertical(Rotation::ROTATION_270)); +} + +/** + * @tc.name: CalcDisplayOrientationToOrientation + * @tc.desc: CalcDisplayOrientationToOrientation Test + * @tc.type: FUNC + */ +HWTEST_F(ScreenSessionTest, CalcDisplayOrientationToOrientation, TestSize.Level2) +{ + ScreenId screenId = 0; + ScreenProperty screenProperty; + sptr screenSession = sptr::MakeSptr(screenId, screenProperty, screenId); + Orientation orientation = screenSession->CalcDisplayOrientationToOrientation(DisplayOrientation::UNKNOWN); + EXPECT_EQ(orientation, Orientation::UNSPECIFIED); + orientation = screenSession->CalcDisplayOrientationToOrientation(DisplayOrientation::PORTRAIT); + EXPECT_EQ(orientation, Orientation::VERTICAL); + orientation = screenSession->CalcDisplayOrientationToOrientation(DisplayOrientation::LANDSCAPE); + EXPECT_EQ(orientation, Orientation::HORIZONTAL); + orientation = screenSession->CalcDisplayOrientationToOrientation(DisplayOrientation::PORTRAIT_INVERTED); + EXPECT_EQ(orientation, Orientation::REVERSE_VERTICAL); + orientation = screenSession->CalcDisplayOrientationToOrientation(DisplayOrientation::LANDSCAPE_INVERTED); + EXPECT_EQ(orientation, Orientation::REVERSE_HORIZONTAL); } /**