diff --git a/dmserver/include/screen_rotation_controller.h b/dmserver/include/screen_rotation_controller.h index 22e72c80..cad5b873 100644 --- a/dmserver/include/screen_rotation_controller.h +++ b/dmserver/include/screen_rotation_controller.h @@ -48,6 +48,7 @@ public: ~ScreenRotationController() = default; static void SubscribeGravitySensor(); static void UnsubscribeGravitySensor(); + static void Init(); static bool IsScreenRotationLocked(); static void SetScreenRotationLocked(bool isLocked); static void SetDefaultDeviceRotationOffset(uint32_t defaultDeviceRotationOffset); diff --git a/dmserver/src/display_manager_service.cpp b/dmserver/src/display_manager_service.cpp index d3052bd0..8857ec93 100644 --- a/dmserver/src/display_manager_service.cpp +++ b/dmserver/src/display_manager_service.cpp @@ -585,6 +585,7 @@ void DisplayManagerService::SetGravitySensorSubscriptionEnabled() { if (!isAutoRotationOpen_) { WLOGFE("autoRotation is not open"); + ScreenRotationController::Init(); return; } ScreenRotationController::SubscribeGravitySensor(); diff --git a/dmserver/src/screen_rotation_controller.cpp b/dmserver/src/screen_rotation_controller.cpp index cb09fa43..03d68c40 100644 --- a/dmserver/src/screen_rotation_controller.cpp +++ b/dmserver/src/screen_rotation_controller.cpp @@ -52,11 +52,11 @@ void ScreenRotationController::SubscribeGravitySensor() WLOGFE("dms: gravity sensor's already subscribed"); return; } + Init(); if (strcpy_s(user_.name, sizeof(user_.name), "ScreenRotationController") != EOK) { WLOGFE("dms strcpy_s error"); return; } - ProcessRotationMapping(); user_.userData = nullptr; user_.callback = &HandleGravitySensorEventCallback; if (SubscribeSensor(SENSOR_TYPE_ID_GRAVITY, &user_) != 0) { @@ -69,9 +69,6 @@ void ScreenRotationController::SubscribeGravitySensor() WLOGFE("dms: Activate gravity sensor failed"); return; } - currentDisplayRotation_ = GetCurrentDisplayRotation(); - lastSensorDecidedRotation_ = currentDisplayRotation_; - rotationLockedRotation_ = currentDisplayRotation_; isGravitySensorSubscribed_ = true; } @@ -93,6 +90,14 @@ void ScreenRotationController::UnsubscribeGravitySensor() isGravitySensorSubscribed_ = false; } +void ScreenRotationController::Init() +{ + ProcessRotationMapping(); + currentDisplayRotation_ = GetCurrentDisplayRotation(); + lastSensorDecidedRotation_ = currentDisplayRotation_; + rotationLockedRotation_ = currentDisplayRotation_; +} + bool ScreenRotationController::IsScreenRotationLocked() { return isScreenRotationLocked_;