From 8bb6fda4a37cdd9b089e925a84f7debaf856ef44 Mon Sep 17 00:00:00 2001 From: cloud_nine Date: Wed, 6 Mar 2024 17:29:29 +0800 Subject: [PATCH] =?UTF-8?q?=E6=97=8B=E8=BD=AC=E6=9E=B6=E6=9E=84=E6=95=B4?= =?UTF-8?q?=E6=94=B9=EF=BC=8C=E5=88=A0=E9=99=A4=E5=86=97=E4=BD=99=E4=BB=A3?= =?UTF-8?q?=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: chenyunjiu --- .../include/screen_rotation_property.h | 63 -- .../include/screen_session_manager.h | 2 - .../src/screen_rotation_property.cpp | 480 +-------------- .../src/screen_sensor_connector.cpp | 6 +- .../src/screen_session_manager.cpp | 45 -- .../screen_rotation_property_test.cpp | 565 +----------------- .../unittest/screen_session_manager_test.cpp | 21 - 7 files changed, 26 insertions(+), 1156 deletions(-) diff --git a/window_scene/session_manager/include/screen_rotation_property.h b/window_scene/session_manager/include/screen_rotation_property.h index 98118fd25a..3fd595e025 100644 --- a/window_scene/session_manager/include/screen_rotation_property.h +++ b/window_scene/session_manager/include/screen_rotation_property.h @@ -28,14 +28,6 @@ namespace OHOS { namespace Rosen { -enum class SensorRotation: int32_t { - INVALID = -1, - ROTATION_0 = 0, - ROTATION_90, - ROTATION_180, - ROTATION_270, -}; - enum class DeviceRotation: int32_t { INVALID = -1, ROTATION_PORTRAIT = 0, @@ -48,64 +40,9 @@ class ScreenRotationProperty : public RefBase { public: ScreenRotationProperty() = delete; ~ScreenRotationProperty() = default; - static void Init(); static void HandleSensorEventInput(DeviceRotation deviceRotation); - static bool IsScreenRotationLocked(); - static DMError SetScreenRotationLocked(bool isLocked); - static void SetDefaultDeviceRotationOffset(uint32_t defaultDeviceRotationOffset); - static void ProcessOrientationSwitch(Orientation orientation); - - static bool IsDefaultDisplayRotationPortrait(); - static bool IsDisplayRotationVertical(Rotation rotation); - static bool IsDisplayRotationHorizontal(Rotation rotation); - static DeviceRotation ConvertSensorToDeviceRotation(SensorRotation sensorRotation); - static DisplayOrientation ConvertRotationToDisplayOrientation(Rotation rotation); private: -#ifdef SENSOR_ENABLE - static void HandleGravitySensorEventCallback(SensorEvent *event); -#endif - static Rotation GetCurrentDisplayRotation(); - static Orientation GetPreferredOrientation(); - static void SetScreenRotation(Rotation targetRotation); - static Rotation CalcTargetDisplayRotation(Orientation requestedOrientation, - DeviceRotation sensorRotationConverted); - 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); - static bool IsCurrentDisplayVertical(); - static bool IsCurrentDisplayHorizontal(); - static bool IsSensorRelatedOrientation(Orientation orientation); - - static void ProcessRotationMapping(); - static void ProcessSwitchToAutoRotationPortrait(DeviceRotation rotation); - static void ProcessSwitchToAutoRotationLandscape(DeviceRotation rotation); - static void ProcessSwitchToAutoRotation(DeviceRotation rotation); - static void ProcessSwitchToAutoRotationPortraitRestricted(); - static void ProcessSwitchToAutoRotationLandscapeRestricted(); - static void ProcessSwitchToSensorRelatedOrientation(Orientation orientation, DeviceRotation deviceRotation); - static void ProcessSwitchToSensorUnrelatedOrientation(Orientation orientation); - static Rotation ProcessAutoRotationPortraitOrientation(DeviceRotation sensorRotationConveted); - static Rotation ProcessAutoRotationLandscapeOrientation(DeviceRotation sensorRotationConveted); - - static DisplayId GetDefaultDisplayId(); - - static DisplayId defaultDisplayId_; - static uint32_t defaultDeviceRotationOffset_; - static uint32_t defaultDeviceRotation_; - static std::map sensorToDeviceRotationMap_; - static std::map deviceToDisplayRotationMap_; - static std::map deviceToFloatMap_; - static std::map displayToDisplayOrientationMap_; - static Orientation lastOrientationType_; - static Rotation currentDisplayRotation_; - static Rotation lastSensorDecidedRotation_; - static Rotation rotationLockedRotation_; - static bool isScreenRotationLocked_; - static DeviceRotation lastSensorRotationConverted_; }; } // Rosen } // OHOS diff --git a/window_scene/session_manager/include/screen_session_manager.h b/window_scene/session_manager/include/screen_session_manager.h index 0ef977fc78..3af92d92ea 100644 --- a/window_scene/session_manager/include/screen_session_manager.h +++ b/window_scene/session_manager/include/screen_session_manager.h @@ -116,8 +116,6 @@ public: DMError IsScreenRotationLocked(bool& isLocked) override; DMError SetScreenRotationLocked(bool isLocked) override; DMError SetOrientation(ScreenId screenId, Orientation orientation) override; - DMError SetOrientationFromWindow(DisplayId displayId, Orientation orientation); - DMError SetOrientationController(ScreenId screenId, Orientation newOrientation, bool isFromWindow); bool SetRotation(ScreenId screenId, Rotation rotationAfter, bool isFromWindow); void SetSensorSubscriptionEnabled(); bool SetRotationFromWindow(Rotation targetRotation); diff --git a/window_scene/session_manager/src/screen_rotation_property.cpp b/window_scene/session_manager/src/screen_rotation_property.cpp index a94d9a4a3c..327ae12964 100644 --- a/window_scene/session_manager/src/screen_rotation_property.cpp +++ b/window_scene/session_manager/src/screen_rotation_property.cpp @@ -14,12 +14,7 @@ */ #include "screen_rotation_property.h" - -#include -#include - #include "screen_session_manager.h" -#include "parameters.h" namespace OHOS { namespace Rosen { @@ -28,481 +23,46 @@ constexpr HiviewDFX::HiLogLabel LABEL = { LOG_CORE, HILOG_DOMAIN_DMS_SCREEN_SESS "ScreenRotationProperty" }; } -DisplayId ScreenRotationProperty::defaultDisplayId_ = 0; -Rotation ScreenRotationProperty::currentDisplayRotation_; -bool ScreenRotationProperty::isScreenRotationLocked_ = true; -uint32_t ScreenRotationProperty::defaultDeviceRotationOffset_ = 0; -Orientation ScreenRotationProperty::lastOrientationType_ = Orientation::UNSPECIFIED; -Rotation ScreenRotationProperty::lastSensorDecidedRotation_; -Rotation ScreenRotationProperty::rotationLockedRotation_; -uint32_t ScreenRotationProperty::defaultDeviceRotation_ = 0; -std::map ScreenRotationProperty::sensorToDeviceRotationMap_; -std::map ScreenRotationProperty::deviceToFloatMap_; -std::map ScreenRotationProperty::deviceToDisplayRotationMap_; -std::map ScreenRotationProperty::displayToDisplayOrientationMap_; -DeviceRotation ScreenRotationProperty::lastSensorRotationConverted_ = DeviceRotation::INVALID; - -void ScreenRotationProperty::Init() -{ - ProcessRotationMapping(); - currentDisplayRotation_ = GetCurrentDisplayRotation(); - defaultDisplayId_ = GetDefaultDisplayId(); - lastSensorDecidedRotation_ = currentDisplayRotation_; - rotationLockedRotation_ = currentDisplayRotation_; -} - -DisplayId ScreenRotationProperty::GetDefaultDisplayId() -{ - sptr defaultDisplayInfo = ScreenSessionManager::GetInstance().GetDefaultDisplayInfo(); - if (defaultDisplayInfo == nullptr) { - WLOGFW("GetDefaultDisplayId, defaultDisplayInfo is nullptr."); - return DISPLAY_ID_INVALID; - } - return defaultDisplayInfo->GetDisplayId(); -} - -bool ScreenRotationProperty::IsScreenRotationLocked() -{ - return isScreenRotationLocked_; -} - -DMError ScreenRotationProperty::SetScreenRotationLocked(bool isLocked) -{ - isScreenRotationLocked_ = isLocked; - if (isLocked) { - rotationLockedRotation_ = GetCurrentDisplayRotation(); - return DMError::DM_OK; - } - if (GetCurrentDisplayRotation() == ConvertDeviceToDisplayRotation(lastSensorRotationConverted_)) { - return DMError::DM_OK; - } - Orientation currentOrientation = GetPreferredOrientation(); - if (IsSensorRelatedOrientation(currentOrientation)) { - ProcessSwitchToSensorRelatedOrientation(currentOrientation, lastSensorRotationConverted_); - } - return DMError::DM_OK; -} - -void ScreenRotationProperty::SetDefaultDeviceRotationOffset(uint32_t defaultDeviceRotationOffset) -{ - // Available options for defaultDeviceRotationOffset: {0, 90, 180, 270} - if (defaultDeviceRotationOffset < 0 || defaultDeviceRotationOffset > 270 || defaultDeviceRotationOffset % 90 != 0) { - return; - } - defaultDeviceRotationOffset_ = defaultDeviceRotationOffset; -} - void ScreenRotationProperty::HandleSensorEventInput(DeviceRotation deviceRotation) { - WLOGFI("ScreenRotationProperty::HandleSensorEventInput deviceRotation: %{public}d", deviceRotation); - auto isPhone = system::GetParameter("const.product.devicetype", "unknown") == "phone"; - auto isPad = system::GetParameter("const.product.devicetype", "unknown") == "tablet"; - if (!isPhone && !isPad) { - WLOGFW("device is not phone or pad, return."); - return; - } + static DeviceRotation lastSensorRotationConverted_ = DeviceRotation::INVALID; + WLOGFI("ScreenRotationProperty::HandleSensorEventInput deviceRotation: %{public}d, " + "lastSensorRotationConverted: %{public}d", deviceRotation, lastSensorRotationConverted_); + if (deviceRotation != DeviceRotation::INVALID && lastSensorRotationConverted_ != deviceRotation) { lastSensorRotationConverted_ = deviceRotation; } auto screenSession = ScreenSessionManager::GetInstance().GetDefaultScreenSession(); if (!screenSession) { - WLOGFW("screenSession is null."); + WLOGFW("screenSession is null, sensor rotation status handle failed"); return; } screenSession->HandleSensorRotation(ConvertDeviceToFloat(deviceRotation)); } -Rotation ScreenRotationProperty::GetCurrentDisplayRotation() -{ - sptr defaultDisplayInfo = ScreenSessionManager::GetInstance().GetDefaultDisplayInfo(); - if (defaultDisplayInfo == nullptr) { - WLOGFW("Cannot get default display info"); - return defaultDeviceRotation_ == 0 ? ConvertDeviceToDisplayRotation(DeviceRotation::ROTATION_PORTRAIT) : - ConvertDeviceToDisplayRotation(DeviceRotation::ROTATION_LANDSCAPE); - } - return defaultDisplayInfo->GetRotation(); -} - -Orientation ScreenRotationProperty::GetPreferredOrientation() -{ - return Orientation::SENSOR; -} - -Rotation ScreenRotationProperty::CalcTargetDisplayRotation( - Orientation requestedOrientation, DeviceRotation sensorRotationConverted) -{ - switch (requestedOrientation) { - case Orientation::SENSOR: { - lastSensorDecidedRotation_ = ConvertDeviceToDisplayRotation(sensorRotationConverted); - return lastSensorDecidedRotation_; - } - case Orientation::SENSOR_VERTICAL: { - return ProcessAutoRotationPortraitOrientation(sensorRotationConverted); - } - case Orientation::SENSOR_HORIZONTAL: { - return ProcessAutoRotationLandscapeOrientation(sensorRotationConverted); - } - case Orientation::AUTO_ROTATION_RESTRICTED: { - if (isScreenRotationLocked_) { - return currentDisplayRotation_; - } - lastSensorDecidedRotation_ = ConvertDeviceToDisplayRotation(sensorRotationConverted); - return lastSensorDecidedRotation_; - } - case Orientation::AUTO_ROTATION_PORTRAIT_RESTRICTED: { - if (isScreenRotationLocked_) { - return currentDisplayRotation_; - } - return ProcessAutoRotationPortraitOrientation(sensorRotationConverted); - } - case Orientation::AUTO_ROTATION_LANDSCAPE_RESTRICTED: { - if (isScreenRotationLocked_) { - return currentDisplayRotation_; - } - return ProcessAutoRotationLandscapeOrientation(sensorRotationConverted); - } - default: { - return currentDisplayRotation_; - } - } -} - -Rotation ScreenRotationProperty::ProcessAutoRotationPortraitOrientation(DeviceRotation sensorRotationConverted) -{ - if (IsDeviceRotationHorizontal(sensorRotationConverted)) { - return currentDisplayRotation_; - } - lastSensorDecidedRotation_ = ConvertDeviceToDisplayRotation(sensorRotationConverted); - return lastSensorDecidedRotation_; -} - -Rotation ScreenRotationProperty::ProcessAutoRotationLandscapeOrientation(DeviceRotation sensorRotationConverted) -{ - if (IsDeviceRotationVertical(sensorRotationConverted)) { - return currentDisplayRotation_; - } - lastSensorDecidedRotation_ = ConvertDeviceToDisplayRotation(sensorRotationConverted); - return lastSensorDecidedRotation_; -} - -void ScreenRotationProperty::SetScreenRotation(Rotation targetRotation) -{ - if (targetRotation == GetCurrentDisplayRotation()) { - return; - } - ScreenSessionManager::GetInstance().SetRotationFromWindow(targetRotation); - WLOGFI("dms: Set screen rotation: %{public}u", targetRotation); -} - -DeviceRotation ScreenRotationProperty::CalcDeviceRotation(SensorRotation sensorRotation) -{ - if (sensorRotation == SensorRotation::INVALID) { - return DeviceRotation::INVALID; - } - // offset(in degree) divided by 90 to get rotation bias - int32_t bias = static_cast(defaultDeviceRotationOffset_ / 90); - int32_t deviceRotationValue = static_cast(sensorRotation) - bias; - while (deviceRotationValue < 0) { - // +4 is used to normalize the values into the range 0~3, corresponding to the four rotations. - deviceRotationValue += 4; - } - if (defaultDeviceRotation_ == 1) { - deviceRotationValue += static_cast(defaultDeviceRotation_); - // %2 to determine whether the rotation is horizontal or vertical. - if (deviceRotationValue % 2 == 0) { - // if device's default rotation is landscape, use -2 to swap 0 and 90, 180 and 270. - deviceRotationValue -= 2; - } - } - return static_cast(deviceRotationValue); -} - -bool ScreenRotationProperty::IsSensorRelatedOrientation(Orientation orientation) -{ - if ((orientation >= Orientation::UNSPECIFIED && orientation <= Orientation::REVERSE_HORIZONTAL) || - orientation == Orientation::LOCKED) { - return false; - } - return true; -} - -void ScreenRotationProperty::ProcessSwitchToSensorRelatedOrientation( - Orientation orientation, DeviceRotation sensorRotationConverted) -{ - lastOrientationType_ = orientation; - switch (orientation) { - case Orientation::AUTO_ROTATION_RESTRICTED: { - if (isScreenRotationLocked_) { - SetScreenRotation(rotationLockedRotation_); - return; - } - [[fallthrough]]; - } - case Orientation::SENSOR: { - ProcessSwitchToAutoRotation(sensorRotationConverted); - return; - } - case Orientation::AUTO_ROTATION_PORTRAIT_RESTRICTED: { - if (isScreenRotationLocked_) { - ProcessSwitchToAutoRotationPortraitRestricted(); - return; - } - [[fallthrough]]; - } - case Orientation::SENSOR_VERTICAL: { - ProcessSwitchToAutoRotationPortrait(sensorRotationConverted); - return; - } - case Orientation::AUTO_ROTATION_LANDSCAPE_RESTRICTED: { - if (isScreenRotationLocked_) { - ProcessSwitchToAutoRotationLandscapeRestricted(); - return; - } - [[fallthrough]]; - } - case Orientation::SENSOR_HORIZONTAL: { - ProcessSwitchToAutoRotationLandscape(sensorRotationConverted); - return; - } - default: { - return; - } - } -} - -void ScreenRotationProperty::ProcessSwitchToAutoRotation(DeviceRotation rotation) -{ - if (rotation != DeviceRotation::INVALID) { - SetScreenRotation(ConvertDeviceToDisplayRotation(rotation)); - } -} - -void ScreenRotationProperty::ProcessSwitchToAutoRotationPortrait(DeviceRotation rotation) -{ - if (IsDeviceRotationVertical(rotation)) { - SetScreenRotation(ConvertDeviceToDisplayRotation(rotation)); - return; - } - SetScreenRotation(ConvertDeviceToDisplayRotation(DeviceRotation::ROTATION_PORTRAIT)); -} - -void ScreenRotationProperty::ProcessSwitchToAutoRotationLandscape(DeviceRotation rotation) -{ - if (IsDeviceRotationHorizontal(rotation)) { - SetScreenRotation(ConvertDeviceToDisplayRotation(rotation)); - return; - } - SetScreenRotation(ConvertDeviceToDisplayRotation(DeviceRotation::ROTATION_LANDSCAPE)); -} - -void ScreenRotationProperty::ProcessSwitchToAutoRotationPortraitRestricted() -{ - if (IsCurrentDisplayVertical()) { - return; - } - if (IsDisplayRotationVertical(rotationLockedRotation_)) { - SetScreenRotation(rotationLockedRotation_); - return; - } - SetScreenRotation(ConvertDeviceToDisplayRotation(DeviceRotation::ROTATION_PORTRAIT)); -} - -void ScreenRotationProperty::ProcessSwitchToAutoRotationLandscapeRestricted() -{ - if (IsCurrentDisplayHorizontal()) { - return; - } - if (IsDisplayRotationHorizontal(rotationLockedRotation_)) { - SetScreenRotation(rotationLockedRotation_); - return; - } - SetScreenRotation(ConvertDeviceToDisplayRotation(DeviceRotation::ROTATION_LANDSCAPE)); -} - -DeviceRotation ScreenRotationProperty::ConvertSensorToDeviceRotation(SensorRotation sensorRotation) -{ - if (sensorToDeviceRotationMap_.empty()) { - ProcessRotationMapping(); - } - return sensorToDeviceRotationMap_.at(sensorRotation); -} - -DisplayOrientation ScreenRotationProperty::ConvertRotationToDisplayOrientation(Rotation rotation) -{ - if (displayToDisplayOrientationMap_.empty()) { - ProcessRotationMapping(); - } - return displayToDisplayOrientationMap_.at(rotation); -} - -Rotation ScreenRotationProperty::ConvertDeviceToDisplayRotation(DeviceRotation deviceRotation) -{ - if (deviceRotation == DeviceRotation::INVALID) { - return GetCurrentDisplayRotation(); - } - if (deviceToDisplayRotationMap_.empty()) { - ProcessRotationMapping(); - } - return deviceToDisplayRotationMap_.at(deviceRotation); -} - float ScreenRotationProperty::ConvertDeviceToFloat(DeviceRotation deviceRotation) { - if (deviceToFloatMap_.empty()) { - ProcessRotationMapping(); - } - return deviceToFloatMap_.at(deviceRotation); -} - -void ScreenRotationProperty::UpdateDefaultDeviceRotation() -{ - sptr modes = - ScreenSessionManager::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_)); -} - -void ScreenRotationProperty::ProcessRotationMapping() -{ - UpdateDefaultDeviceRotation(); - if (deviceToDisplayRotationMap_.empty()) { - deviceToDisplayRotationMap_ = { - {DeviceRotation::ROTATION_PORTRAIT, - defaultDeviceRotation_ == 0 ? Rotation::ROTATION_0 : Rotation::ROTATION_90}, - {DeviceRotation::ROTATION_LANDSCAPE, - defaultDeviceRotation_ == 1 ? Rotation::ROTATION_0 : Rotation::ROTATION_90}, - {DeviceRotation::ROTATION_PORTRAIT_INVERTED, - defaultDeviceRotation_ == 0 ? Rotation::ROTATION_180 : Rotation::ROTATION_270}, - {DeviceRotation::ROTATION_LANDSCAPE_INVERTED, - defaultDeviceRotation_ == 1 ? Rotation::ROTATION_180 : Rotation::ROTATION_270}, - }; - } - if (deviceToFloatMap_.empty()) { - deviceToFloatMap_ = { - {DeviceRotation::ROTATION_PORTRAIT, defaultDeviceRotation_ == 0 ? 0.0f : 90.0f}, // degree 0 or 90 - {DeviceRotation::ROTATION_LANDSCAPE, defaultDeviceRotation_ == 1 ? 0.0f : 90.0f}, // degree 0 or 90 - {DeviceRotation::ROTATION_PORTRAIT_INVERTED, - defaultDeviceRotation_ == 0 ? 180.0f : 270.0f}, // degree 180 or 270 - {DeviceRotation::ROTATION_LANDSCAPE_INVERTED, - defaultDeviceRotation_ == 1 ? 180.0f : 270.0f}, // degree 180 or 270 - {DeviceRotation::INVALID, -1.0f}, // keep degree - }; - } - if (displayToDisplayOrientationMap_.empty()) { - displayToDisplayOrientationMap_ = { - {defaultDeviceRotation_ == 0 ? Rotation::ROTATION_0 : Rotation::ROTATION_90, - DisplayOrientation::PORTRAIT}, - {defaultDeviceRotation_ == 1 ? Rotation::ROTATION_0 : Rotation::ROTATION_90, - DisplayOrientation::LANDSCAPE}, - {defaultDeviceRotation_ == 0 ? Rotation::ROTATION_180 : Rotation::ROTATION_270, - DisplayOrientation::PORTRAIT_INVERTED}, - {defaultDeviceRotation_ == 1 ? Rotation::ROTATION_180 : Rotation::ROTATION_270, - DisplayOrientation::LANDSCAPE_INVERTED}, - }; - } - if (sensorToDeviceRotationMap_.empty()) { - sensorToDeviceRotationMap_ = { - {SensorRotation::ROTATION_0, CalcDeviceRotation(SensorRotation::ROTATION_0)}, - {SensorRotation::ROTATION_90, CalcDeviceRotation(SensorRotation::ROTATION_90)}, - {SensorRotation::ROTATION_180, CalcDeviceRotation(SensorRotation::ROTATION_180)}, - {SensorRotation::ROTATION_270, CalcDeviceRotation(SensorRotation::ROTATION_270)}, - {SensorRotation::INVALID, DeviceRotation::INVALID}, - }; - } -} - -bool ScreenRotationProperty::IsDeviceRotationVertical(DeviceRotation deviceRotation) -{ - return (deviceRotation == DeviceRotation::ROTATION_PORTRAIT) || - (deviceRotation == DeviceRotation::ROTATION_PORTRAIT_INVERTED); -} - -bool ScreenRotationProperty::IsDeviceRotationHorizontal(DeviceRotation deviceRotation) -{ - return (deviceRotation == DeviceRotation::ROTATION_LANDSCAPE) || - (deviceRotation == DeviceRotation::ROTATION_LANDSCAPE_INVERTED); -} - -bool ScreenRotationProperty::IsCurrentDisplayVertical() -{ - return IsDisplayRotationVertical(GetCurrentDisplayRotation()); -} - -bool ScreenRotationProperty::IsCurrentDisplayHorizontal() -{ - return IsDisplayRotationHorizontal(GetCurrentDisplayRotation()); -} - -bool ScreenRotationProperty::IsDefaultDisplayRotationPortrait() -{ - return Rotation::ROTATION_0 == ConvertDeviceToDisplayRotation(DeviceRotation::ROTATION_PORTRAIT); -} - -bool ScreenRotationProperty::IsDisplayRotationVertical(Rotation rotation) -{ - return (rotation == ConvertDeviceToDisplayRotation(DeviceRotation::ROTATION_PORTRAIT)) || - (rotation == ConvertDeviceToDisplayRotation(DeviceRotation::ROTATION_PORTRAIT_INVERTED)); -} - -bool ScreenRotationProperty::IsDisplayRotationHorizontal(Rotation rotation) -{ - return (rotation == ConvertDeviceToDisplayRotation(DeviceRotation::ROTATION_LANDSCAPE)) || - (rotation == ConvertDeviceToDisplayRotation(DeviceRotation::ROTATION_LANDSCAPE_INVERTED)); -} - -void ScreenRotationProperty::ProcessSwitchToSensorUnrelatedOrientation(Orientation orientation) -{ - if (lastOrientationType_ == orientation) { - return; - } - lastOrientationType_ = orientation; - switch (orientation) { - case Orientation::UNSPECIFIED: { - SetScreenRotation(Rotation::ROTATION_0); + float sensorRotation = -1.0f; // -1 mean keep before degree + switch (deviceRotation) { + case DeviceRotation::ROTATION_PORTRAIT: + sensorRotation = 0.0f; // degree 0 break; - } - case Orientation::VERTICAL: { - SetScreenRotation(ConvertDeviceToDisplayRotation(DeviceRotation::ROTATION_PORTRAIT)); + case DeviceRotation::ROTATION_LANDSCAPE: + sensorRotation = 90.0f; // degree 90 break; - } - case Orientation::REVERSE_VERTICAL: { - SetScreenRotation(ConvertDeviceToDisplayRotation(DeviceRotation::ROTATION_PORTRAIT_INVERTED)); + case DeviceRotation::ROTATION_PORTRAIT_INVERTED: + sensorRotation = 180.0f; // degree 180 break; - } - case Orientation::HORIZONTAL: { - SetScreenRotation(ConvertDeviceToDisplayRotation(DeviceRotation::ROTATION_LANDSCAPE)); + case DeviceRotation::ROTATION_LANDSCAPE_INVERTED: + sensorRotation = 270.0f; // degree 270 break; - } - case Orientation::REVERSE_HORIZONTAL: { - SetScreenRotation(ConvertDeviceToDisplayRotation(DeviceRotation::ROTATION_LANDSCAPE_INVERTED)); + case DeviceRotation::INVALID: + sensorRotation = -1.0f; // keep before degree break; - } - default: { - return; - } - } -} - -void ScreenRotationProperty::ProcessOrientationSwitch(Orientation orientation) -{ - if (!IsSensorRelatedOrientation(orientation)) { - ProcessSwitchToSensorUnrelatedOrientation(orientation); - } else { - ProcessSwitchToSensorRelatedOrientation(orientation, lastSensorRotationConverted_); + default: + WLOGFW("invalid device rotation: %{public}d", deviceRotation); } + return sensorRotation; } } // Rosen } // OHOS \ No newline at end of file diff --git a/window_scene/session_manager/src/screen_sensor_connector.cpp b/window_scene/session_manager/src/screen_sensor_connector.cpp index bf5a44309f..ce8695aee1 100644 --- a/window_scene/session_manager/src/screen_sensor_connector.cpp +++ b/window_scene/session_manager/src/screen_sensor_connector.cpp @@ -96,8 +96,7 @@ void RotationMotionEventCallback::OnMotionChanged(const MotionEvent& motionData) break; } case MOTION_ACTION_LEFT_LANDSCAPE: { - motionRotation = ScreenRotationProperty::IsDefaultDisplayRotationPortrait() ? - DeviceRotation::ROTATION_LANDSCAPE_INVERTED : DeviceRotation::ROTATION_LANDSCAPE; + motionRotation = DeviceRotation::ROTATION_LANDSCAPE_INVERTED; break; } case MOTION_ACTION_PORTRAIT_INVERTED: { @@ -105,8 +104,7 @@ void RotationMotionEventCallback::OnMotionChanged(const MotionEvent& motionData) break; } case MOTION_ACTION_RIGHT_LANDSCAPE: { - motionRotation = ScreenRotationProperty::IsDefaultDisplayRotationPortrait() ? - DeviceRotation::ROTATION_LANDSCAPE : DeviceRotation::ROTATION_LANDSCAPE_INVERTED; + motionRotation = DeviceRotation::ROTATION_LANDSCAPE; break; } default: { diff --git a/window_scene/session_manager/src/screen_session_manager.cpp b/window_scene/session_manager/src/screen_session_manager.cpp index b92bff948e..109505c963 100644 --- a/window_scene/session_manager/src/screen_session_manager.cpp +++ b/window_scene/session_manager/src/screen_session_manager.cpp @@ -1265,49 +1265,6 @@ DMError ScreenSessionManager::SetOrientation(ScreenId screenId, Orientation orie return DMError::DM_OK; } -DMError ScreenSessionManager::SetOrientationFromWindow(DisplayId displayId, Orientation orientation) -{ - sptr displayInfo = GetDisplayInfoById(displayId); - if (displayInfo == nullptr) { - return DMError::DM_ERROR_NULLPTR; - } - HITRACE_METER_FMT(HITRACE_TAG_WINDOW_MANAGER, "ssm:SetOrientationFromWindow"); - return SetOrientationController(displayInfo->GetScreenId(), orientation, true); -} - -DMError ScreenSessionManager::SetOrientationController(ScreenId screenId, Orientation newOrientation, - bool isFromWindow) -{ - sptr screenSession = GetScreenSession(screenId); - if (screenSession == nullptr) { - WLOGFE("fail to set orientation, cannot find screen %{public}" PRIu64"", screenId); - return DMError::DM_ERROR_NULLPTR; - } - - if (isFromWindow) { - if (newOrientation == Orientation::UNSPECIFIED) { - newOrientation = screenSession->GetScreenRequestedOrientation(); - } - } else { - screenSession->SetScreenRequestedOrientation(newOrientation); - } - - if (screenSession->GetOrientation() == newOrientation) { - return DMError::DM_OK; - } - if (isFromWindow) { - ScreenRotationProperty::ProcessOrientationSwitch(newOrientation); - } else { - Rotation rotationAfter = screenSession->CalcRotation(newOrientation, GetFoldDisplayMode()); - SetRotation(screenId, rotationAfter, false); - } - screenSession->SetOrientation(newOrientation); - screenSession->PropertyChange(screenSession->GetScreenProperty(), ScreenPropertyChangeReason::ROTATION); - // Notify rotation event to ScreenManager - NotifyScreenChanged(screenSession->ConvertToScreenInfo(), ScreenChangeEvent::UPDATE_ORIENTATION); - return DMError::DM_OK; -} - bool ScreenSessionManager::SetRotation(ScreenId screenId, Rotation rotationAfter, bool isFromWindow) { WLOGFI("Enter SetRotation, screenId: %{public}" PRIu64 ", rotation: %{public}u, isFromWindow: %{public}u,", @@ -1335,10 +1292,8 @@ void ScreenSessionManager::SetSensorSubscriptionEnabled() isAutoRotationOpen_ = system::GetParameter("persist.display.ar.enabled", "1") == "1"; if (!isAutoRotationOpen_) { WLOGFE("autoRotation is not open"); - ScreenRotationProperty::Init(); return; } - ScreenRotationProperty::Init(); ScreenSensorConnector::SubscribeRotationSensor(); WLOGFI("subscribe rotation sensor successful"); } diff --git a/window_scene/test/unittest/screen_rotation_property_test.cpp b/window_scene/test/unittest/screen_rotation_property_test.cpp index 2df778de9a..2dcce998ac 100644 --- a/window_scene/test/unittest/screen_rotation_property_test.cpp +++ b/window_scene/test/unittest/screen_rotation_property_test.cpp @@ -12,13 +12,14 @@ * See the License for the specific language governing permissions and * limitations under the License. */ +#include -#include "session_manager/include/screen_rotation_property.h" #include #include "window_manager_hilog.h" #include "screen_session_manager.h" -#include + +#include "session_manager/include/screen_rotation_property.h" using namespace testing; using namespace testing::ext; @@ -50,296 +51,6 @@ void ScreenRotationPropertyTest::TearDown() } namespace { -/** - * @tc.name: Init - * @tc.desc: test function : Init - * @tc.type: FUNC - */ -HWTEST_F(ScreenRotationPropertyTest, Init, Function | SmallTest | Level1) -{ - int res = 0; - ScreenRotationProperty::Init(); - ASSERT_EQ(0, res); -} - -/** - * @tc.name: GetDefaultDisplayId - * @tc.desc: test function : GetDefaultDisplayId - * @tc.type: FUNC - */ -HWTEST_F(ScreenRotationPropertyTest, GetDefaultDisplayId, Function | SmallTest | Level1) -{ - ScreenRotationProperty::Init(); - int res = 0; - ScreenRotationProperty::GetDefaultDisplayId(); - ASSERT_EQ(0, res); -} - -/** - * @tc.name: IsScreenRotationLocked - * @tc.desc: test function : IsScreenRotationLocked - * @tc.type: FUNC - */ -HWTEST_F(ScreenRotationPropertyTest, IsScreenRotationLocked, Function | SmallTest | Level1) -{ - ScreenRotationProperty::Init(); - ScreenRotationProperty::SetScreenRotationLocked(true); - bool isLocked = ScreenRotationProperty::IsScreenRotationLocked(); - ASSERT_EQ(true, isLocked); -} - -/** - * @tc.name: SetScreenRotationLocked - * @tc.desc: test function : SetScreenRotationLocked - * @tc.type: FUNC - */ -HWTEST_F(ScreenRotationPropertyTest, SetScreenRotationLocked, Function | SmallTest | Level1) -{ - ScreenRotationProperty::Init(); - bool isLocked = true; - DMError ret = ScreenRotationProperty::SetScreenRotationLocked(isLocked); - ASSERT_EQ(DMError::DM_OK, ret); - isLocked = false; - ScreenRotationProperty::GetCurrentDisplayRotation(); - ScreenRotationProperty::ConvertDeviceToDisplayRotation(DeviceRotation::INVALID); - ret = ScreenRotationProperty::SetScreenRotationLocked(isLocked); - ASSERT_EQ(DMError::DM_OK, ret); - ScreenRotationProperty::ConvertDeviceToDisplayRotation(DeviceRotation::ROTATION_LANDSCAPE); - Orientation currentOrientation = ScreenRotationProperty::GetPreferredOrientation(); - ScreenRotationProperty::IsSensorRelatedOrientation(currentOrientation); - ret = ScreenRotationProperty::SetScreenRotationLocked(isLocked); - ScreenRotationProperty::IsSensorRelatedOrientation(Orientation::UNSPECIFIED); - ret = ScreenRotationProperty::SetScreenRotationLocked(isLocked); - ASSERT_EQ(DMError::DM_OK, ret); -} - -/** - * @tc.name: SetDefaultDeviceRotationOffset - * @tc.desc: test function : SetDefaultDeviceRotationOffset - * @tc.type: FUNC - */ -HWTEST_F(ScreenRotationPropertyTest, SetDefaultDeviceRotationOffset, Function | SmallTest | Level1) -{ - ScreenRotationProperty::Init(); - uint32_t offset = -1; - ScreenRotationProperty::SetDefaultDeviceRotationOffset(offset); - offset = 0; - ScreenRotationProperty::SetDefaultDeviceRotationOffset(offset); - ASSERT_EQ(offset, ScreenRotationProperty::defaultDeviceRotationOffset_); -} - -/** - * @tc.name: GetPreferredOrientation - * @tc.desc: test function : GetPreferredOrientation - * @tc.type: FUNC - */ -HWTEST_F(ScreenRotationPropertyTest, GetPreferredOrientation, Function | SmallTest | Level1) -{ - ScreenRotationProperty::Init(); - Orientation res = ScreenRotationProperty::GetPreferredOrientation(); - ASSERT_EQ(Orientation::SENSOR, res); -} - -/** - * @tc.name: SetScreenRotation - * @tc.desc: test function : SetScreenRotation - * @tc.type: FUNC - */ -HWTEST_F(ScreenRotationPropertyTest, SetScreenRotation, Function | SmallTest | Level1) -{ - GTEST_LOG_(INFO) << "ScreenRotationPropertyTest: SetScreenRotation start"; - ScreenRotationProperty::Init(); - Rotation targetRotation = ScreenRotationProperty::GetCurrentDisplayRotation(); - ScreenRotationProperty::SetScreenRotation(targetRotation); - targetRotation = Rotation::ROTATION_90; - ScreenRotationProperty::SetScreenRotation(targetRotation); - ASSERT_EQ(false, ScreenSessionManager::GetInstance().SetRotationFromWindow(targetRotation)); - GTEST_LOG_(INFO) << "ScreenRotationPropertyTest: SetScreenRotation end"; -} - -/** - * @tc.name: IsSensorRelatedOrientation - * @tc.desc: test function : IsSensorRelatedOrientation - * @tc.type: FUNC - */ -HWTEST_F(ScreenRotationPropertyTest, IsSensorRelatedOrientation, Function | SmallTest | Level1) -{ - GTEST_LOG_(INFO) << "ScreenRotationPropertyTest: IsSensorRelatedOrientation start"; - ScreenRotationProperty::Init(); - bool res = ScreenRotationProperty::IsSensorRelatedOrientation(Orientation::VERTICAL); - ASSERT_EQ(false, res); - res = ScreenRotationProperty::IsSensorRelatedOrientation(Orientation::SENSOR_VERTICAL); - ASSERT_EQ(true, res); - GTEST_LOG_(INFO) << "ScreenRotationPropertyTest: IsSensorRelatedOrientation end"; -} - -/** - * @tc.name: ProcessSwitchToAutoRotation - * @tc.desc: test function : ProcessSwitchToAutoRotation - * @tc.type: FUNC - */ -HWTEST_F(ScreenRotationPropertyTest, ProcessSwitchToAutoRotation, Function | SmallTest | Level1) -{ - GTEST_LOG_(INFO) << "ScreenRotationPropertyTest: ProcessSwitchToAutoRotation start"; - ScreenRotationProperty::Init(); - int32_t res = 0; - ScreenRotationProperty::ProcessSwitchToAutoRotation(DeviceRotation::ROTATION_PORTRAIT); - ASSERT_EQ(0, res); - GTEST_LOG_(INFO) << "ScreenRotationPropertyTest: ProcessSwitchToAutoRotation end"; -} - -/** - * @tc.name: ProcessSwitchToAutoRotation - * @tc.desc: test function : ProcessSwitchToAutoRotation - * @tc.type: FUNC - */ -HWTEST_F(ScreenRotationPropertyTest, ProcessSwitchToAutoRotationPortrait, Function | SmallTest | Level1) -{ - GTEST_LOG_(INFO) << "ScreenRotationPropertyTest: ProcessSwitchToAutoRotationPortrait start"; - ScreenRotationProperty::Init(); - int32_t res = 0; - ScreenRotationProperty::ProcessSwitchToAutoRotationPortrait(DeviceRotation::ROTATION_PORTRAIT); - ASSERT_EQ(0, res); - GTEST_LOG_(INFO) << "ScreenRotationPropertyTest: ProcessSwitchToAutoRotationPortrait end"; -} - -/** - * @tc.name: ProcessSwitchToAutoRotation - * @tc.desc: test function : ProcessSwitchToAutoRotation - * @tc.type: FUNC - */ -HWTEST_F(ScreenRotationPropertyTest, ProcessSwitchToAutoRotationLandscape, Function | SmallTest | Level1) -{ - GTEST_LOG_(INFO) << "ScreenRotationPropertyTest: ProcessSwitchToAutoRotationLandscape start"; - ScreenRotationProperty::Init(); - int32_t res = 0; - ScreenRotationProperty::ProcessSwitchToAutoRotationLandscape(DeviceRotation::ROTATION_PORTRAIT); - ASSERT_EQ(0, res); - GTEST_LOG_(INFO) << "ScreenRotationPropertyTest: ProcessSwitchToAutoRotationLandscape end"; -} - -/** - * @tc.name: ProcessSwitchToAutoRotation - * @tc.desc: test function : ProcessSwitchToAutoRotation - * @tc.type: FUNC - */ -HWTEST_F(ScreenRotationPropertyTest, ProcessSwitchToAutoRotationPortraitRestricted, Function | SmallTest | Level1) -{ - GTEST_LOG_(INFO) << "ScreenRotationPropertyTest: ProcessSwitchToAutoRotationPortraitRestricted start"; - ScreenRotationProperty::Init(); - int32_t res = 0; - ScreenRotationProperty::ProcessSwitchToAutoRotationPortraitRestricted(); - ASSERT_EQ(0, res); - GTEST_LOG_(INFO) << "ScreenRotationPropertyTest: ProcessSwitchToAutoRotationPortraitRestricted end"; -} - -/** - * @tc.name: ConvertSensorToDeviceRotation - * @tc.desc: test function : ConvertSensorToDeviceRotation - * @tc.type: FUNC - */ -HWTEST_F(ScreenRotationPropertyTest, ConvertSensorToDeviceRotation, Function | SmallTest | Level1) -{ - GTEST_LOG_(INFO) << "ScreenRotationPropertyTest: ConvertSensorToDeviceRotation start"; - ScreenRotationProperty::Init(); - int32_t res = 0; - ScreenRotationProperty::ConvertSensorToDeviceRotation(SensorRotation::ROTATION_90); - ASSERT_EQ(0, res); - GTEST_LOG_(INFO) << "ScreenRotationPropertyTest: ConvertSensorToDeviceRotation end"; -} - -/** - * @tc.name: ProcessSwitchToAutoRotationLandscapeRestricted - * @tc.desc: test function : ProcessSwitchToAutoRotationLandscapeRestricted - * @tc.type: FUNC - */ -HWTEST_F(ScreenRotationPropertyTest, ProcessSwitchToAutoRotationLandscapeRestricted, Function | SmallTest | Level1) -{ - GTEST_LOG_(INFO) << "ScreenRotationPropertyTest: ProcessSwitchToAutoRotationLandscapeRestricted start"; - ScreenRotationProperty::Init(); - int32_t res = 0; - ScreenRotationProperty::ProcessSwitchToAutoRotationLandscapeRestricted(); - ASSERT_EQ(0, res); - GTEST_LOG_(INFO) << "ScreenRotationPropertyTest: ProcessSwitchToAutoRotationLandscapeRestricted end"; -} - -/** - * @tc.name: ConvertRotationToDisplayOrientation - * @tc.desc: test function : ConvertRotationToDisplayOrientation - * @tc.type: FUNC - */ -HWTEST_F(ScreenRotationPropertyTest, ConvertRotationToDisplayOrientation, Function | SmallTest | Level1) -{ - GTEST_LOG_(INFO) << "ScreenRotationPropertyTest: ConvertRotationToDisplayOrientation start"; - ScreenRotationProperty::Init(); - int32_t res = 0; - ScreenRotationProperty::ConvertRotationToDisplayOrientation(Rotation::ROTATION_90); - ASSERT_EQ(0, res); - GTEST_LOG_(INFO) << "ScreenRotationPropertyTest: ConvertSensorToDeviceRotation end"; -} - -/** - * @tc.name: ConvertDeviceToDisplayRotation - * @tc.desc: test function : ConvertDeviceToDisplayRotation - * @tc.type: FUNC - */ -HWTEST_F(ScreenRotationPropertyTest, ConvertDeviceToDisplayRotation, Function | SmallTest | Level1) -{ - GTEST_LOG_(INFO) << "ScreenRotationPropertyTest: ConvertDeviceToDisplayRotation start"; - ScreenRotationProperty::Init(); - DeviceRotation deviceRotation = DeviceRotation::INVALID; - Rotation rotation = ScreenRotationProperty::ConvertDeviceToDisplayRotation(deviceRotation); - ASSERT_EQ(ScreenRotationProperty::GetCurrentDisplayRotation(), rotation); - deviceRotation = DeviceRotation::ROTATION_PORTRAIT; - rotation = ScreenRotationProperty::ConvertDeviceToDisplayRotation(deviceRotation); - ASSERT_EQ(ScreenRotationProperty::deviceToDisplayRotationMap_.at(deviceRotation), rotation); - GTEST_LOG_(INFO) << "ScreenRotationPropertyTest: ConvertDeviceToDisplayRotation end"; -} - -/** - * @tc.name: ProcessRotationMapping - * @tc.desc: test function : ProcessRotationMapping - * @tc.type: FUNC - */ -HWTEST_F(ScreenRotationPropertyTest, ProcessRotationMapping, Function | SmallTest | Level1) -{ - GTEST_LOG_(INFO) << "ScreenRotationPropertyTest: ProcessRotationMapping_PORTRAIT start"; - ScreenRotationProperty::defaultDeviceRotation_ = 0; - ScreenRotationProperty::ProcessRotationMapping(); - ASSERT_EQ(Rotation::ROTATION_0, - ScreenRotationProperty::deviceToDisplayRotationMap_.at(DeviceRotation::ROTATION_PORTRAIT)); - GTEST_LOG_(INFO) << "ScreenRotationPropertyTest: ProcessRotationMapping_PORTRAIT end"; -} - -/** - * @tc.name: ProcessSwitchToSensorRelatedOrientation - * @tc.desc: test function : ProcessSwitchToSensorRelatedOrientation - * @tc.type: FUNC - */ -HWTEST_F(ScreenRotationPropertyTest, ProcessSwitchToSensorRelatedOrientation, Function | SmallTest | Level1) -{ - GTEST_LOG_(INFO) << "ScreenRotationPropertyTest: ProcessSwitchToSensorRelatedOrientation start"; - ScreenRotationProperty::Init(); - Orientation orientation = Orientation::AUTO_ROTATION_RESTRICTED; - DeviceRotation sensorRotationConverted = DeviceRotation::INVALID; - ScreenRotationProperty::isScreenRotationLocked_ = true; - ScreenRotationProperty::ProcessSwitchToSensorRelatedOrientation(orientation, sensorRotationConverted); - ASSERT_EQ(ScreenRotationProperty::GetCurrentDisplayRotation(), ScreenRotationProperty::rotationLockedRotation_); - orientation = Orientation::SENSOR; - sensorRotationConverted = DeviceRotation::ROTATION_PORTRAIT; - ScreenRotationProperty::ProcessSwitchToSensorRelatedOrientation(orientation, sensorRotationConverted); - ASSERT_EQ(ScreenRotationProperty::deviceToDisplayRotationMap_.at(sensorRotationConverted), - ScreenRotationProperty::ConvertDeviceToDisplayRotation(sensorRotationConverted)); - orientation = Orientation::AUTO_ROTATION_PORTRAIT_RESTRICTED; - ScreenRotationProperty::ProcessSwitchToSensorRelatedOrientation(orientation, sensorRotationConverted); - orientation = Orientation::SENSOR_VERTICAL; - ScreenRotationProperty::ProcessSwitchToSensorRelatedOrientation(orientation, sensorRotationConverted); - orientation = Orientation::AUTO_ROTATION_LANDSCAPE_RESTRICTED; - ScreenRotationProperty::ProcessSwitchToSensorRelatedOrientation(orientation, sensorRotationConverted); - orientation = Orientation::SENSOR_HORIZONTAL; - ScreenRotationProperty::ProcessSwitchToSensorRelatedOrientation(orientation, sensorRotationConverted); - GTEST_LOG_(INFO) << "ScreenRotationPropertyTest: ProcessSwitchToSensorRelatedOrientation end"; -} /** * @tc.name: HandleSensorEventInput @@ -349,279 +60,11 @@ HWTEST_F(ScreenRotationPropertyTest, ProcessSwitchToSensorRelatedOrientation, Fu HWTEST_F(ScreenRotationPropertyTest, HandleSensorEventInput, Function | SmallTest | Level1) { GTEST_LOG_(INFO) << "ScreenRotationPropertyTest: HandleSensorEventInput start"; - ScreenRotationProperty::Init(); - DeviceRotation deviceRotation = DeviceRotation::INVALID; - ScreenRotationProperty::HandleSensorEventInput(deviceRotation); - deviceRotation = DeviceRotation::ROTATION_PORTRAIT; - ScreenSessionManager *screenSessionManager = new ScreenSessionManager; - auto defaultDisplayInfo = screenSessionManager->GetDefaultDisplayInfo(); - ScreenRotationProperty::HandleSensorEventInput(deviceRotation); - Orientation orientation = Orientation::BEGIN; - ScreenRotationProperty::IsSensorRelatedOrientation(orientation); - ScreenRotationProperty::HandleSensorEventInput(deviceRotation); - orientation = Orientation::SENSOR; - ScreenRotationProperty::GetCurrentDisplayRotation(); - ScreenRotationProperty::ConvertDeviceToDisplayRotation(deviceRotation); - ScreenRotationProperty::HandleSensorEventInput(deviceRotation); - int32_t res = 0; ScreenRotationProperty::HandleSensorEventInput(DeviceRotation::INVALID); - ASSERT_EQ(0, res); + ScreenRotationProperty::HandleSensorEventInput(DeviceRotation::ROTATION_PORTRAIT); GTEST_LOG_(INFO) << "ScreenRotationPropertyTest: HandleSensorEventInput end"; } -/** - * @tc.name: ProcessSwitchToSensorUnrelatedOrientation - * @tc.desc: test function : ProcessSwitchToSensorUnrelatedOrientation - * @tc.type: FUNC - */ -HWTEST_F(ScreenRotationPropertyTest, ProcessSwitchToSensorUnrelatedOrientation, Function | SmallTest | Level1) -{ - GTEST_LOG_(INFO) << "ScreenRotationPropertyTest: ProcessSwitchToSensorUnrelatedOrientation start"; - ScreenRotationProperty::Init(); - int32_t res = 0; - ScreenRotationProperty::ProcessSwitchToSensorUnrelatedOrientation(ScreenRotationProperty::lastOrientationType_); - ASSERT_EQ(0, res); - ScreenRotationProperty::ProcessSwitchToSensorUnrelatedOrientation(Orientation::UNSPECIFIED); - ASSERT_EQ(0, res); - ScreenRotationProperty::ProcessSwitchToSensorUnrelatedOrientation(Orientation::VERTICAL); - ASSERT_EQ(0, res); - ScreenRotationProperty::ProcessSwitchToSensorUnrelatedOrientation(Orientation::REVERSE_VERTICAL); - ASSERT_EQ(0, res); - ScreenRotationProperty::ProcessSwitchToSensorUnrelatedOrientation(Orientation::HORIZONTAL); - ASSERT_EQ(0, res); - ScreenRotationProperty::ProcessSwitchToSensorUnrelatedOrientation(Orientation::REVERSE_HORIZONTAL); - ASSERT_EQ(0, res); - ScreenRotationProperty::ProcessSwitchToSensorUnrelatedOrientation(Orientation::BEGIN); - ASSERT_EQ(0, res); - GTEST_LOG_(INFO) << "ScreenRotationPropertyTest: ProcessSwitchToSensorUnrelatedOrientation end"; -} - -/** - * @tc.name: ProcessAutoRotationPortraitOrientation - * @tc.desc: ProcessAutoRotationPortraitOrientation func - * @tc.type: FUNC - */ -HWTEST_F(ScreenRotationPropertyTest, ProcessAutoRotationPortraitOrientation, Function | SmallTest | Level1) -{ - GTEST_LOG_(INFO) << "ScreenRotationPropertyTest: ProcessAutoRotationPortraitOrientation start"; - ScreenRotationProperty::Init(); - DeviceRotation sensorRotationConverted = DeviceRotation::ROTATION_LANDSCAPE; - auto result = ScreenRotationProperty::ProcessAutoRotationPortraitOrientation(sensorRotationConverted); - ASSERT_EQ(ScreenRotationProperty::GetCurrentDisplayRotation(), result); - sensorRotationConverted = DeviceRotation::ROTATION_PORTRAIT; - result = ScreenRotationProperty::ProcessAutoRotationPortraitOrientation(sensorRotationConverted); - ASSERT_EQ(ScreenRotationProperty::ConvertDeviceToDisplayRotation(sensorRotationConverted), result); - GTEST_LOG_(INFO) << "ScreenRotationPropertyTest: ProcessAutoRotationPortraitOrientation end"; -} - -/** - * @tc.name: ProcessAutoRotationLandscapeOrientation - * @tc.desc: ProcessAutoRotationLandscapeOrientation func - * @tc.type: FUNC - */ -HWTEST_F(ScreenRotationPropertyTest, ProcessAutoRotationLandscapeOrientation, Function | SmallTest | Level1) -{ - GTEST_LOG_(INFO) << "ScreenRotationPropertyTest: ProcessAutoRotationLandscapeOrientation start"; - ScreenRotationProperty::Init(); - DeviceRotation sensorRotationConverted = DeviceRotation::ROTATION_PORTRAIT; - auto result = ScreenRotationProperty::ProcessAutoRotationPortraitOrientation(sensorRotationConverted); - ASSERT_EQ(ScreenRotationProperty::currentDisplayRotation_, result); - GTEST_LOG_(INFO) << "ScreenRotationPropertyTest: ProcessAutoRotationLandscapeOrientation end"; -} - -/** - * @tc.name: CalcDeviceRotation - * @tc.desc: CalcDeviceRotation func - * @tc.type: FUNC - */ -HWTEST_F(ScreenRotationPropertyTest, CalcDeviceRotation, Function | SmallTest | Level1) -{ - GTEST_LOG_(INFO) << "ScreenRotationPropertyTest: CalcDeviceRotation start"; - ScreenRotationProperty::Init(); - SensorRotation sensorRotation = SensorRotation::INVALID; - auto result = ScreenRotationProperty::CalcDeviceRotation(sensorRotation); - ASSERT_EQ(DeviceRotation::INVALID, result); - sensorRotation = SensorRotation::ROTATION_0; - ScreenRotationProperty::defaultDeviceRotationOffset_ = 90; - ScreenRotationProperty::defaultDeviceRotation_ = 1; - result = ScreenRotationProperty::CalcDeviceRotation(sensorRotation); - ASSERT_EQ(DeviceRotation::ROTATION_PORTRAIT_INVERTED, result); - GTEST_LOG_(INFO) << "ScreenRotationPropertyTest: CalcDeviceRotation end"; -} - -/** - * @tc.name: CalcTargetDisplayRotation - * @tc.desc: CalcTargetDisplayRotation func - * @tc.type: FUNC - */ -HWTEST_F(ScreenRotationPropertyTest, CalcTargetDisplayRotation, Function | SmallTest | Level1) -{ - GTEST_LOG_(INFO) << "ScreenRotationPropertyTest: CalcTargetDisplayRotation start"; - ScreenRotationProperty::Init(); - Orientation requestedOrientation = Orientation::SENSOR; - DeviceRotation sensorRotationConverted = DeviceRotation::ROTATION_LANDSCAPE; - auto result = ScreenRotationProperty::CalcTargetDisplayRotation(requestedOrientation, sensorRotationConverted); - ASSERT_EQ(ScreenRotationProperty::ConvertDeviceToDisplayRotation(sensorRotationConverted), result); - requestedOrientation = Orientation::SENSOR_VERTICAL; - result = ScreenRotationProperty::CalcTargetDisplayRotation(requestedOrientation, sensorRotationConverted); - ASSERT_EQ(ScreenRotationProperty::ProcessAutoRotationPortraitOrientation(sensorRotationConverted), result); - requestedOrientation = Orientation::SENSOR_HORIZONTAL; - result = ScreenRotationProperty::CalcTargetDisplayRotation(requestedOrientation, sensorRotationConverted); - ASSERT_EQ(ScreenRotationProperty::ProcessAutoRotationLandscapeOrientation(sensorRotationConverted), result); - requestedOrientation = Orientation::AUTO_ROTATION_RESTRICTED; - ScreenRotationProperty::isScreenRotationLocked_ = true; - result = ScreenRotationProperty::CalcTargetDisplayRotation(requestedOrientation, sensorRotationConverted); - ASSERT_EQ(ScreenRotationProperty::GetCurrentDisplayRotation(), result); - ScreenRotationProperty::isScreenRotationLocked_ = false; - result = ScreenRotationProperty::CalcTargetDisplayRotation(requestedOrientation, sensorRotationConverted); - ASSERT_EQ(ScreenRotationProperty::ConvertDeviceToDisplayRotation(sensorRotationConverted), result); - requestedOrientation = Orientation::AUTO_ROTATION_PORTRAIT_RESTRICTED; - ScreenRotationProperty::isScreenRotationLocked_ = true; - result = ScreenRotationProperty::CalcTargetDisplayRotation(requestedOrientation, sensorRotationConverted); - ASSERT_EQ(ScreenRotationProperty::GetCurrentDisplayRotation(), result); - ScreenRotationProperty::isScreenRotationLocked_ = false; - result = ScreenRotationProperty::CalcTargetDisplayRotation(requestedOrientation, sensorRotationConverted); - ASSERT_EQ(ScreenRotationProperty::ProcessAutoRotationPortraitOrientation(sensorRotationConverted), result); - requestedOrientation = Orientation::AUTO_ROTATION_LANDSCAPE_RESTRICTED; - ScreenRotationProperty::isScreenRotationLocked_ = true; - result = ScreenRotationProperty::CalcTargetDisplayRotation(requestedOrientation, sensorRotationConverted); - ASSERT_EQ(ScreenRotationProperty::GetCurrentDisplayRotation(), result); - ScreenRotationProperty::isScreenRotationLocked_ = false; - result = ScreenRotationProperty::CalcTargetDisplayRotation(requestedOrientation, sensorRotationConverted); - ASSERT_EQ(ScreenRotationProperty::ProcessAutoRotationLandscapeOrientation(sensorRotationConverted), result); - requestedOrientation = Orientation::LOCKED; - result = ScreenRotationProperty::CalcTargetDisplayRotation(requestedOrientation, sensorRotationConverted); - ASSERT_EQ(ScreenRotationProperty::GetCurrentDisplayRotation(), result); - GTEST_LOG_(INFO) << "ScreenRotationPropertyTest: CalcTargetDisplayRotation end"; -} - -/** - * @tc.name: IsCurrentDisplayVertical - * @tc.desc: IsCurrentDisplayVertical func - * @tc.type: FUNC - */ -HWTEST_F(ScreenRotationPropertyTest, IsCurrentDisplayVertical, Function | SmallTest | Level1) -{ - GTEST_LOG_(INFO) << "ScreenRotationPropertyTest: IsCurrentDisplayVertical start"; - ScreenRotationProperty::Init(); - auto result = ScreenRotationProperty::IsCurrentDisplayVertical(); - ASSERT_EQ(true, result); - GTEST_LOG_(INFO) << "ScreenRotationPropertyTest: IsCurrentDisplayVertical end"; -} - -/** - * @tc.name: IsDeviceRotationVertical - * @tc.desc: IsDeviceRotationVertical func - * @tc.type: FUNC - */ -HWTEST_F(ScreenRotationPropertyTest, IsDeviceRotationVertical, Function | SmallTest | Level1) -{ - GTEST_LOG_(INFO) << "ScreenRotationPropertyTest: IsDeviceRotationVertical start"; - ScreenRotationProperty::Init(); - DeviceRotation deviceRotation = DeviceRotation::ROTATION_PORTRAIT; - auto result = ScreenRotationProperty::IsDeviceRotationVertical(deviceRotation); - ASSERT_EQ(true, result); - deviceRotation = DeviceRotation::ROTATION_PORTRAIT_INVERTED; - result = ScreenRotationProperty::IsDeviceRotationVertical(deviceRotation); - ASSERT_EQ(true, result); - GTEST_LOG_(INFO) << "ScreenRotationPropertyTest: IsDeviceRotationVertical end"; -} - -/** - * @tc.name: IsDeviceRotationHorizontal - * @tc.desc: IsDeviceRotationHorizontal func - * @tc.type: FUNC - */ -HWTEST_F(ScreenRotationPropertyTest, IsDeviceRotationHorizontal, Function | SmallTest | Level1) -{ - GTEST_LOG_(INFO) << "ScreenRotationPropertyTest: IsDeviceRotationHorizontal start"; - ScreenRotationProperty::Init(); - DeviceRotation deviceRotation = DeviceRotation::ROTATION_LANDSCAPE; - auto result = ScreenRotationProperty::IsDeviceRotationHorizontal(deviceRotation); - ASSERT_EQ(true, result); - deviceRotation = DeviceRotation::ROTATION_LANDSCAPE_INVERTED; - result = ScreenRotationProperty::IsDeviceRotationHorizontal(deviceRotation); - ASSERT_EQ(true, result); - GTEST_LOG_(INFO) << "ScreenRotationPropertyTest: IsDeviceRotationHorizontal end"; -} - -/** - * @tc.name: IsCurrentDisplayHorizontal - * @tc.desc: IsCurrentDisplayHorizontal func - * @tc.type: FUNC - */ -HWTEST_F(ScreenRotationPropertyTest, IsCurrentDisplayHorizontal, Function | SmallTest | Level1) -{ - GTEST_LOG_(INFO) << "ScreenRotationPropertyTest: IsCurrentDisplayHorizontal start"; - ScreenRotationProperty::Init(); - auto result = ScreenRotationProperty::IsCurrentDisplayHorizontal(); - ASSERT_EQ(false, result); - GTEST_LOG_(INFO) << "ScreenRotationPropertyTest: IsCurrentDisplayHorizontal end"; -} - -/** - * @tc.name: IsDefaultDisplayRotationPortrait - * @tc.desc: IsDefaultDisplayRotationPortrait func - * @tc.type: FUNC - */ -HWTEST_F(ScreenRotationPropertyTest, IsDefaultDisplayRotationPortrait, Function | SmallTest | Level1) -{ - GTEST_LOG_(INFO) << "ScreenRotationPropertyTest: IsDefaultDisplayRotationPortrait start"; - ScreenRotationProperty::Init(); - auto result = ScreenRotationProperty::IsDefaultDisplayRotationPortrait(); - ASSERT_EQ(true, result); - GTEST_LOG_(INFO) << "ScreenRotationPropertyTest: IsDefaultDisplayRotationPortrait end"; -} - -/** - * @tc.name: IsDisplayRotationVertical - * @tc.desc: IsDisplayRotationVertical func - * @tc.type: FUNC - */ -HWTEST_F(ScreenRotationPropertyTest, IsDisplayRotationVertical, Function | SmallTest | Level1) -{ - GTEST_LOG_(INFO) << "ScreenRotationPropertyTest: IsDisplayRotationVertical start"; - ScreenRotationProperty::Init(); - Rotation rotation = Rotation::ROTATION_0; - auto result = ScreenRotationProperty::IsDisplayRotationVertical(rotation); - ASSERT_EQ(true, result); - GTEST_LOG_(INFO) << "ScreenRotationPropertyTest: IsDisplayRotationVertical end"; -} - -/** - * @tc.name: IsDisplayRotationHorizontal - * @tc.desc: IsDisplayRotationHorizontal func - * @tc.type: FUNC - */ -HWTEST_F(ScreenRotationPropertyTest, IsDisplayRotationHorizontal, Function | SmallTest | Level1) -{ - GTEST_LOG_(INFO) << "ScreenRotationPropertyTest: IsDisplayRotationHorizontal start"; - ScreenRotationProperty::Init(); - Rotation rotation = Rotation::ROTATION_90; - auto result = ScreenRotationProperty::IsDisplayRotationHorizontal(rotation); - ASSERT_EQ(true, result); - GTEST_LOG_(INFO) << "ScreenRotationPropertyTest: IsDisplayRotationHorizontal end"; -} - -/** - * @tc.name: ProcessOrientationSwitch - * @tc.desc: ProcessOrientationSwitch func - * @tc.type: FUNC - */ -HWTEST_F(ScreenRotationPropertyTest, ProcessOrientationSwitch, Function | SmallTest | Level1) -{ - GTEST_LOG_(INFO) << "ScreenRotationPropertyTest: ProcessOrientationSwitch start"; - ScreenRotationProperty::Init(); - Orientation orientation = Orientation::BEGIN; - int res = 0; - ScreenRotationProperty::ProcessOrientationSwitch(orientation); - ASSERT_EQ(res, 0); - orientation = Orientation::SENSOR; - ScreenRotationProperty::ProcessOrientationSwitch(orientation); - ASSERT_EQ(res, 0); - GTEST_LOG_(INFO) << "ScreenRotationPropertyTest: ProcessOrientationSwitch start"; -} - } } diff --git a/window_scene/test/unittest/screen_session_manager_test.cpp b/window_scene/test/unittest/screen_session_manager_test.cpp index 293fa9fb1d..fd8ad1e38f 100644 --- a/window_scene/test/unittest/screen_session_manager_test.cpp +++ b/window_scene/test/unittest/screen_session_manager_test.cpp @@ -889,27 +889,6 @@ HWTEST_F(ScreenSessionManagerTest, UpdateScreenRotationProperty, Function | Smal ASSERT_NE(screenSession, ScreenSessionManager::GetInstance().InitAndGetScreen(2)); } -/** - * @tc.name: SetOrientationFromWindow - * @tc.desc: SetOrientationFromWindow virtual screen - * @tc.type: FUNC - */ -HWTEST_F(ScreenSessionManagerTest, SetOrientationFromWindow, Function | SmallTest | Level3) -{ - sptr displayManagerAgent = new DisplayManagerAgentDefault(); - VirtualScreenOption virtualOption; - virtualOption.name_ = "SetOrientationFromWindow"; - ssm_->CreateVirtualScreen(virtualOption, displayManagerAgent->AsObject()); - sptr screenSession = nullptr; - screenSession = new (std::nothrow) ScreenSession("GetScreenGamutMap", 1, 1, 3); - std::map> screenSessionMap_{ - {1, screenSession}, - }; - ssm_->screenSessionMap_ = screenSessionMap_; - ASSERT_EQ(DMError::DM_ERROR_NULLPTR, ssm_->SetOrientationFromWindow(2, Orientation::AUTO_ROTATION_RESTRICTED)); - ASSERT_EQ(DMError::DM_OK, ssm_->SetOrientationFromWindow(1, Orientation::AUTO_ROTATION_RESTRICTED)); -} - /** * @tc.name: MakeUniqueScreen * @tc.desc: Make unique screen -- Gitee