diff --git a/dmserver/src/screen_rotation_controller.cpp b/dmserver/src/screen_rotation_controller.cpp index a8f6185d05dc730e1e79999be17b940cc07aead9..63bb91bf235c67eac23c65cf13331427ee4463d0 100644 --- a/dmserver/src/screen_rotation_controller.cpp +++ b/dmserver/src/screen_rotation_controller.cpp @@ -19,7 +19,6 @@ #include #include "display_manager_service_inner.h" -#include "parameters.h" namespace OHOS { namespace Rosen { @@ -348,19 +347,7 @@ void ScreenRotationController::ProcessRotationMapping() DisplayManagerServiceInner::GetInstance().GetScreenModesByDisplayId(defaultDisplayId_); // 0 means PORTRAIT, 1 means LANDSCAPE. - if (modes == nullptr) { - defaultDeviceRotation_ = 0; - WLOGFE("Get screen modes is nullptr."); - } else { - defaultDeviceRotation_ = (modes->width_ < modes->height_) ? 0 : 1; - WLOGFI("Get screen modes width: %{public}d, height: %{public}d", modes->width_, modes->height_); - } - if (OHOS::system::GetParameter("const.product.devicetype", "unknown") == "phone") { - WLOGFI("Current device type is phone, set defaultDeviceRotation is portrait"); - defaultDeviceRotation_ = 0; - } - WLOGFI("defaultDeviceRotation: %{public}u, defaultDisplayId: %{public}u", - defaultDeviceRotation_, static_cast(defaultDisplayId_)); + defaultDeviceRotation_ = (modes == nullptr || modes->width_ < modes->height_) ? 0 : 1; if (deviceToDisplayRotationMap_.empty()) { deviceToDisplayRotationMap_ = { diff --git a/window_scene/session_manager/include/screen_rotation_property.h b/window_scene/session_manager/include/screen_rotation_property.h index 3aa6c53a0577948ea47c2f9f677de26f58168298..98118fd25ada80b6f1903ee55b5fb8199dab8892 100644 --- a/window_scene/session_manager/include/screen_rotation_property.h +++ b/window_scene/session_manager/include/screen_rotation_property.h @@ -72,6 +72,7 @@ private: static DeviceRotation CalcDeviceRotation(SensorRotation sensorRotation); static Rotation ConvertDeviceToDisplayRotation(DeviceRotation sensorRotationConverted); static float ConvertDeviceToFloat(DeviceRotation deviceRotation); + static void UpdateDefaultDeviceRotation(); static bool IsDeviceRotationVertical(DeviceRotation deviceRotation); static bool IsDeviceRotationHorizontal(DeviceRotation deviceRotation); diff --git a/window_scene/session_manager/src/screen_cutout_controller.cpp b/window_scene/session_manager/src/screen_cutout_controller.cpp index 158d84a627af90dd5cc4990c21d6692650740994..ca36ab836f8e8a9b650832f7e34dbb275a890328 100644 --- a/window_scene/session_manager/src/screen_cutout_controller.cpp +++ b/window_scene/session_manager/src/screen_cutout_controller.cpp @@ -304,6 +304,8 @@ void ScreenCutoutController::ProcessRotationMapping() // 0 means PORTRAIT, 1 means LANDSCAPE. defaultDeviceRotation_ = (!displayInfo || (displayInfo && (displayInfo->GetWidth() < displayInfo->GetHeight()))) ? 0 : 1; + WLOGFI("defaultDeviceRotation: %{public}u", defaultDeviceRotation_); + if (deviceToDisplayRotationMap_.empty()) { deviceToDisplayRotationMap_ = { { DeviceRotationValue::ROTATION_PORTRAIT, diff --git a/window_scene/session_manager/src/screen_rotation_property.cpp b/window_scene/session_manager/src/screen_rotation_property.cpp index 58abe075236d14eb8ac6fd9b06dc52e100795dc8..a94d9a4a3c8d3757bbb4b4866fc68fb25e35edf4 100644 --- a/window_scene/session_manager/src/screen_rotation_property.cpp +++ b/window_scene/session_manager/src/screen_rotation_property.cpp @@ -354,13 +354,30 @@ float ScreenRotationProperty::ConvertDeviceToFloat(DeviceRotation deviceRotation return deviceToFloatMap_.at(deviceRotation); } -void ScreenRotationProperty::ProcessRotationMapping() +void ScreenRotationProperty::UpdateDefaultDeviceRotation() { sptr modes = ScreenSessionManager::GetInstance().GetScreenModesByDisplayId(defaultDisplayId_); // 0 means PORTRAIT, 1 means LANDSCAPE. - defaultDeviceRotation_ = (modes == nullptr || modes->width_ < modes->height_) ? 0 : 1; + if (modes == nullptr) { + defaultDeviceRotation_ = 0; + WLOGFE("Get screen modes is nullptr."); + } else { + defaultDeviceRotation_ = (modes->width_ < modes->height_) ? 0 : 1; + WLOGFI("Get screen modes width: %{public}d, height: %{public}d", modes->width_, modes->height_); + } + if (OHOS::system::GetParameter("const.product.devicetype", "unknown") == "phone") { + WLOGFI("Current device type is phone, set defaultDeviceRotation is portrait"); + defaultDeviceRotation_ = 0; + } + WLOGFI("defaultDeviceRotation: %{public}u, defaultDisplayId: %{public}u", + defaultDeviceRotation_, static_cast(defaultDisplayId_)); +} + +void ScreenRotationProperty::ProcessRotationMapping() +{ + UpdateDefaultDeviceRotation(); if (deviceToDisplayRotationMap_.empty()) { deviceToDisplayRotationMap_ = { {DeviceRotation::ROTATION_PORTRAIT,