demend motion rotation

Signed-off-by: zhangkai <zhangkai324@huawei.com>
Change-Id: I67bb9dc0c43f5c6d30017c8f6b85b86dc0cc9098
This commit is contained in:
zhangkai 2022-12-23 16:51:48 +08:00
parent e624107a2a
commit 3b9157ea9e
9 changed files with 377 additions and 159 deletions

View File

@ -13,7 +13,10 @@
"name": "window_manager",
"subsystem": "window",
"syscap": ["SystemCapability.WindowManager.WindowManager.Core"],
"features": [ "window_manager_feature_coverage = false" ],
"features": [
"window_manager_feature_coverage = false",
"window_manager_feature_subscribe_motion"
],
"adapted_system_type": [ "standard" ],
"rom": "8000KB",
"ram": "8000KB",

View File

@ -12,6 +12,7 @@
# limitations under the License.
import("//build/ohos.gni")
import("//foundation/window/window_manager/windowmanager_aafwk.gni")
## Build libdms.so
config("libdms_private_config") {
@ -41,6 +42,7 @@ ohos_shared_library("libdms") {
"src/display_manager_stub.cpp",
"src/display_power_controller.cpp",
"src/screen_rotation_controller.cpp",
"src/sensor_connector.cpp",
]
configs = [
@ -71,6 +73,12 @@ ohos_shared_library("libdms") {
include_dirs = [ "//third_party/flutter/skia/src" ]
defines = []
if (window_manager_feature_subscribe_motion) {
external_deps += [ "motion:motion_interface_native" ]
defines += [ "WM_SUBSCRIBE_MOTION_ENABLE" ]
}
if (is_standard_system) {
external_deps += [ "init:libbegetutil" ]
} else {

View File

@ -46,29 +46,24 @@ class ScreenRotationController : public RefBase {
public:
ScreenRotationController() = delete;
~ScreenRotationController() = default;
static void SubscribeGravitySensor();
static void UnsubscribeGravitySensor();
static void Init();
static void HandleSensorEventInput(DeviceRotation deviceRotation);
static bool IsScreenRotationLocked();
static void SetScreenRotationLocked(bool isLocked);
static void SetDefaultDeviceRotationOffset(uint32_t defaultDeviceRotationOffset);
static bool IsGravitySensorEnabled();
static void ProcessOrientationSwitch(Orientation orientation);
static bool IsDisplayRotationVertical(Rotation rotation);
static bool IsDisplayRotationHorizontal(Rotation rotation);
static DeviceRotation ConvertSensorToDeviceRotation(SensorRotation sensorRotation);
private:
static void HandleGravitySensorEventCallback(SensorEvent *event);
static bool CheckCallbackTimeInterval();
static Rotation GetCurrentDisplayRotation();
static Orientation GetPreferredOrientation();
static void SetScreenRotation(Rotation targetRotation);
static int CalcRotationDegree(GravityData* gravityData);
static Rotation CalcTargetDisplayRotation(Orientation requestedOrientation,
DeviceRotation sensorRotationConverted);
static DeviceRotation CalcDeviceRotation(SensorRotation sensorRotation);
static SensorRotation CalcSensorRotation(int sensorDegree);
static DeviceRotation ConvertSensorToDeviceRotation(SensorRotation sensorRotation);
static Rotation ConvertDeviceToDisplayRotation(DeviceRotation sensorRotationConverted);
static bool IsDeviceRotationVertical(DeviceRotation deviceRotation);
@ -89,17 +84,14 @@ private:
static Rotation ProcessAutoRotationLandscapeOrientation(DeviceRotation sensorRotationConveted);
static DisplayId defaultDisplayId_;
static SensorUser user_;
static uint32_t defaultDeviceRotationOffset_;
static uint32_t defaultDeviceRotation_;
static std::map<SensorRotation, DeviceRotation> sensorToDeviceRotationMap_;
static std::map<DeviceRotation, Rotation> deviceToDisplayRotationMap_;
static long lastCallbackTime_;
static Orientation lastOrientationType_;
static Rotation currentDisplayRotation_;
static Rotation lastSensorDecidedRotation_;
static Rotation rotationLockedRotation_;
static bool isGravitySensorSubscribed_;
static bool isScreenRotationLocked_;
static DeviceRotation lastSensorRotationConverted_;
};

View File

@ -0,0 +1,84 @@
/*
* Copyright (c) 2022 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef OHOS_ROSEN_SCREEN_CONNECTOR_H
#define OHOS_ROSEN_SCREEN_CONNECTOR_H
#include <map>
#include <refbase.h>
#include "dm_common.h"
#ifdef WM_SUBSCRIBE_MOTION_ENABLE
#include "motion_agent.h"
#include "motion_callback_stub.h"
#endif
#include "screen_rotation_controller.h"
#include "sensor_agent.h"
#include "window_manager_hilog.h"
namespace OHOS {
namespace Rosen {
class SensorConnector : public RefBase {
public:
SensorConnector() = delete;
~SensorConnector() = default;
static void SubscribeRotationSensor();
static void UnsubscribeRotationSensor();
};
class GravitySensorSubscriber {
friend SensorConnector;
public:
GravitySensorSubscriber() = delete;
~GravitySensorSubscriber() = default;
private:
static void SubscribeGravitySensor();
static void UnsubscribeGravitySensor();
static void HandleGravitySensorEventCallback(SensorEvent *event);
static bool CheckCallbackTimeInterval();
static int CalcRotationDegree(GravityData* gravityData);
static SensorRotation CalcSensorRotation(int sensorDegree);
static SensorUser user_;
static bool isGravitySensorSubscribed_;
static long lastCallbackTime_;
};
#ifdef WM_SUBSCRIBE_MOTION_ENABLE
using OHOS::Msdp::MotionCallbackStub;
using OHOS::Msdp::MotionData;
class RotationMotionEventCallback : public MotionCallbackStub {
public:
void OnMotionChanged(const MotionData& motionData) override;
};
class MotionSubscriber {
friend SensorConnector;
public:
MotionSubscriber() = delete;
~MotionSubscriber() = default;
private:
static void SubscribeMotionSensor();
static void UnsubscribeMotionSensor();
static sptr<RotationMotionEventCallback> motionEventCallback_;
static bool isMotionSensorSubscribed_;
};
#endif
} // Rosen
} // OHOS
#endif // OHOS_ROSEN_SCREEN_CONNECTOR_H

View File

@ -26,7 +26,7 @@
#include "dm_common.h"
#include "parameters.h"
#include "permission.h"
#include "screen_rotation_controller.h"
#include "sensor_connector.h"
#include "transaction/rs_interfaces.h"
#include "window_manager_hilog.h"
@ -694,7 +694,7 @@ void DisplayManagerService::SetGravitySensorSubscriptionEnabled()
ScreenRotationController::Init();
return;
}
ScreenRotationController::SubscribeGravitySensor();
SensorConnector::SubscribeRotationSensor();
}
sptr<CutoutInfo> DisplayManagerService::GetCutoutInfo(DisplayId displayId)

View File

@ -24,18 +24,11 @@ namespace OHOS {
namespace Rosen {
namespace {
constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, HILOG_DOMAIN_DISPLAY, "ScreenRotationController"};
constexpr int64_t ORIENTATION_SENSOR_SAMPLING_RATE = 200000000; // 200ms
constexpr int64_t ORIENTATION_SENSOR_REPORTING_RATE = 0;
constexpr long ORIENTATION_SENSOR_CALLBACK_TIME_INTERVAL = 200; // 200ms
constexpr int VALID_INCLINATION_ANGLE_THRESHOLD_COEFFICIENT = 3;
}
DisplayId ScreenRotationController::defaultDisplayId_ = 0;
bool ScreenRotationController::isGravitySensorSubscribed_ = false;
SensorUser ScreenRotationController::user_;
Rotation ScreenRotationController::currentDisplayRotation_;
bool ScreenRotationController::isScreenRotationLocked_ = true;
long ScreenRotationController::lastCallbackTime_ = 0;
uint32_t ScreenRotationController::defaultDeviceRotationOffset_ = 0;
Orientation ScreenRotationController::lastOrientationType_ = Orientation::UNSPECIFIED;
Rotation ScreenRotationController::lastSensorDecidedRotation_;
@ -45,51 +38,6 @@ std::map<SensorRotation, DeviceRotation> ScreenRotationController::sensorToDevic
std::map<DeviceRotation, Rotation> ScreenRotationController::deviceToDisplayRotationMap_;
DeviceRotation ScreenRotationController::lastSensorRotationConverted_ = DeviceRotation::INVALID;
void ScreenRotationController::SubscribeGravitySensor()
{
WLOGFI("dms: Subscribe gravity Sensor");
if (isGravitySensorSubscribed_) {
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;
}
user_.userData = nullptr;
user_.callback = &HandleGravitySensorEventCallback;
if (SubscribeSensor(SENSOR_TYPE_ID_GRAVITY, &user_) != 0) {
WLOGFE("dms: Subscribe gravity sensor failed");
return;
}
SetBatch(SENSOR_TYPE_ID_GRAVITY, &user_, ORIENTATION_SENSOR_SAMPLING_RATE, ORIENTATION_SENSOR_REPORTING_RATE);
SetMode(SENSOR_TYPE_ID_GRAVITY, &user_, SENSOR_ON_CHANGE);
if (ActivateSensor(SENSOR_TYPE_ID_GRAVITY, &user_) != 0) {
WLOGFE("dms: Activate gravity sensor failed");
return;
}
isGravitySensorSubscribed_ = true;
}
void ScreenRotationController::UnsubscribeGravitySensor()
{
WLOGFI("dms: Unsubscribe gravity Sensor");
if (!isGravitySensorSubscribed_) {
WLOGFE("dms: Orientation Sensor is not subscribed");
return;
}
if (DeactivateSensor(SENSOR_TYPE_ID_GRAVITY, &user_) != 0) {
WLOGFE("dms: Deactivate gravity sensor failed");
return;
}
if (UnsubscribeSensor(SENSOR_TYPE_ID_GRAVITY, &user_) != 0) {
WLOGFE("dms: Unsubscribe gravity sensor failed");
return;
}
isGravitySensorSubscribed_ = false;
}
void ScreenRotationController::Init()
{
ProcessRotationMapping();
@ -120,50 +68,25 @@ void ScreenRotationController::SetDefaultDeviceRotationOffset(uint32_t defaultDe
defaultDeviceRotationOffset_ = defaultDeviceRotationOffset;
}
void ScreenRotationController::HandleGravitySensorEventCallback(SensorEvent *event)
void ScreenRotationController::HandleSensorEventInput(DeviceRotation deviceRotation)
{
if (!CheckCallbackTimeInterval()) {
return;
}
if (event->sensorTypeId != SENSOR_TYPE_ID_GRAVITY) {
WLOGE("dms: Orientation Sensor Callback is not SENSOR_TYPE_ID_GRAVITY");
return;
}
Orientation orientation = GetPreferredOrientation();
currentDisplayRotation_ = GetCurrentDisplayRotation();
GravityData* gravityData = reinterpret_cast<GravityData*>(event->data);
int sensorDegree = CalcRotationDegree(gravityData);
DeviceRotation sensorRotationConverted = ConvertSensorToDeviceRotation(CalcSensorRotation(sensorDegree));
lastSensorRotationConverted_ = sensorRotationConverted;
lastSensorRotationConverted_ = deviceRotation;
if (!IsSensorRelatedOrientation(orientation)) {
return;
}
if (sensorRotationConverted == DeviceRotation::INVALID) {
if (deviceRotation == DeviceRotation::INVALID) {
return;
}
if (currentDisplayRotation_ == ConvertDeviceToDisplayRotation(sensorRotationConverted)) {
if (currentDisplayRotation_ == ConvertDeviceToDisplayRotation(deviceRotation)) {
return;
}
Rotation targetDisplayRotation = CalcTargetDisplayRotation(orientation, sensorRotationConverted);
Rotation targetDisplayRotation = CalcTargetDisplayRotation(orientation, deviceRotation);
SetScreenRotation(targetDisplayRotation);
}
int ScreenRotationController::CalcRotationDegree(GravityData* gravityData)
{
float x = gravityData->x;
float y = gravityData->y;
float z = gravityData->z;
int degree = -1;
if ((x * x + y * y) * VALID_INCLINATION_ANGLE_THRESHOLD_COEFFICIENT < z * z) {
return degree;
}
// arccotx = pi / 2 - arctanx, 90 is used to calculate acot(in degree); degree = rad / pi * 180
degree = 90 - static_cast<int>(round(atan2(y, -x) / M_PI * 180));
// Normalize the degree to the range of 0~360
return degree >= 0 ? degree % 360 : degree % 360 + 360;
}
Rotation ScreenRotationController::GetCurrentDisplayRotation()
{
sptr<DisplayInfo> defaultDisplayInfo = DisplayManagerServiceInner::GetInstance().GetDefaultDisplay();
@ -253,18 +176,6 @@ void ScreenRotationController::SetScreenRotation(Rotation targetRotation)
WLOGFI("dms: Set screen rotation: %{public}u", targetRotation);
}
bool ScreenRotationController::CheckCallbackTimeInterval()
{
std::chrono::milliseconds ms = std::chrono::time_point_cast<std::chrono::milliseconds>(
std::chrono::steady_clock::now()).time_since_epoch();
long currentTimeInMillitm = ms.count();
if (currentTimeInMillitm - lastCallbackTime_ < ORIENTATION_SENSOR_CALLBACK_TIME_INTERVAL) {
return false;
}
lastCallbackTime_ = currentTimeInMillitm;
return true;
}
DeviceRotation ScreenRotationController::CalcDeviceRotation(SensorRotation sensorRotation)
{
if (sensorRotation == SensorRotation::INVALID) {
@ -394,22 +305,6 @@ void ScreenRotationController::ProcessSwitchToAutoRotationLandscapeRestricted()
SetScreenRotation(ConvertDeviceToDisplayRotation(DeviceRotation::ROTATION_LANDSCAPE));
}
SensorRotation ScreenRotationController::CalcSensorRotation(int sensorDegree)
{
// Use ROTATION_0 when degree range is [0, 30][330, 359]
if (sensorDegree >= 0 && (sensorDegree <= 30 || sensorDegree >= 330)) {
return SensorRotation::ROTATION_0;
} else if (sensorDegree >= 60 && sensorDegree <= 120) { // Use ROTATION_90 when degree range is [60, 120]
return SensorRotation::ROTATION_90;
} else if (sensorDegree >= 150 && sensorDegree <= 210) { // Use ROTATION_180 when degree range is [150, 210]
return SensorRotation::ROTATION_180;
} else if (sensorDegree >= 240 && sensorDegree <= 300) { // Use ROTATION_270 when degree range is [240, 300]
return SensorRotation::ROTATION_270;
} else {
return SensorRotation::INVALID;
}
}
DeviceRotation ScreenRotationController::ConvertSensorToDeviceRotation(SensorRotation sensorRotation)
{
if (sensorToDeviceRotationMap_.empty()) {
@ -492,11 +387,6 @@ bool ScreenRotationController::IsDisplayRotationHorizontal(Rotation rotation)
(rotation == ConvertDeviceToDisplayRotation(DeviceRotation::ROTATION_LANDSCAPE_INVERTED));
}
bool ScreenRotationController::IsGravitySensorEnabled()
{
return isGravitySensorSubscribed_;
}
void ScreenRotationController::ProcessSwitchToSensorUnrelatedOrientation(Orientation orientation)
{
if (lastOrientationType_ == orientation) {

View File

@ -0,0 +1,235 @@
/*
* Copyright (c) 2022 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "sensor_connector.h"
#include <chrono>
#include <securec.h>
#include "display_manager_service_inner.h"
namespace OHOS {
namespace Rosen {
namespace {
constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, HILOG_DOMAIN_DISPLAY, "SensorConnector"};
constexpr int64_t ORIENTATION_SENSOR_SAMPLING_RATE = 200000000; // 200ms
constexpr int64_t ORIENTATION_SENSOR_REPORTING_RATE = 0;
constexpr long ORIENTATION_SENSOR_CALLBACK_TIME_INTERVAL = 200; // 200ms
constexpr int VALID_INCLINATION_ANGLE_THRESHOLD_COEFFICIENT = 3;
#ifdef WM_SUBSCRIBE_MOTION_ENABLE
constexpr int32_t MOTION_ACTION_PORTRAIT = 0;
constexpr int32_t MOTION_ACTION_LANDSCAPE = 1;
constexpr int32_t MOTION_ACTION_PORTRAIT_INVERTED = 2;
constexpr int32_t MOTION_ACTION_LANDSCAPE_INVERTED = 3;
#endif
}
bool GravitySensorSubscriber::isGravitySensorSubscribed_ = false;
SensorUser GravitySensorSubscriber::user_;
long GravitySensorSubscriber::lastCallbackTime_ = 0;
#ifdef WM_SUBSCRIBE_MOTION_ENABLE
bool MotionSubscriber::isMotionSensorSubscribed_ = false;
sptr<RotationMotionEventCallback> MotionSubscriber::motionEventCallback_ = nullptr;
#endif
void SensorConnector::SubscribeRotationSensor()
{
WLOGFI("dms: subscribe rotation-related sensor");
ScreenRotationController::Init();
#ifdef WM_SUBSCRIBE_MOTION_ENABLE
MotionSubscriber::SubscribeMotionSensor();
if (MotionSubscriber::isMotionSensorSubscribed_) {
return;
}
#endif
GravitySensorSubscriber::SubscribeGravitySensor();
}
void SensorConnector::UnsubscribeRotationSensor()
{
#ifdef WM_SUBSCRIBE_MOTION_ENABLE
MotionSubscriber::UnsubscribeMotionSensor();
#endif
GravitySensorSubscriber::UnsubscribeGravitySensor();
}
// Gravity Sensor
void GravitySensorSubscriber::SubscribeGravitySensor()
{
WLOGFI("dms: Subscribe gravity Sensor");
if (isGravitySensorSubscribed_) {
WLOGFE("dms: gravity sensor's already subscribed");
return;
}
if (strcpy_s(user_.name, sizeof(user_.name), "ScreenRotationController") != EOK) {
WLOGFE("dms strcpy_s error");
return;
}
user_.userData = nullptr;
user_.callback = &HandleGravitySensorEventCallback;
if (SubscribeSensor(SENSOR_TYPE_ID_GRAVITY, &user_) != 0) {
WLOGFE("dms: Subscribe gravity sensor failed");
return;
}
SetBatch(SENSOR_TYPE_ID_GRAVITY, &user_, ORIENTATION_SENSOR_SAMPLING_RATE, ORIENTATION_SENSOR_REPORTING_RATE);
SetMode(SENSOR_TYPE_ID_GRAVITY, &user_, SENSOR_ON_CHANGE);
if (ActivateSensor(SENSOR_TYPE_ID_GRAVITY, &user_) != 0) {
WLOGFE("dms: Activate gravity sensor failed");
return;
}
isGravitySensorSubscribed_ = true;
}
void GravitySensorSubscriber::UnsubscribeGravitySensor()
{
WLOGFI("dms: Unsubscribe gravity Sensor");
if (!isGravitySensorSubscribed_) {
WLOGFE("dms: Orientation Sensor is not subscribed");
return;
}
if (DeactivateSensor(SENSOR_TYPE_ID_GRAVITY, &user_) != 0) {
WLOGFE("dms: Deactivate gravity sensor failed");
return;
}
if (UnsubscribeSensor(SENSOR_TYPE_ID_GRAVITY, &user_) != 0) {
WLOGFE("dms: Unsubscribe gravity sensor failed");
return;
}
isGravitySensorSubscribed_ = false;
}
void GravitySensorSubscriber::HandleGravitySensorEventCallback(SensorEvent *event)
{
if (!CheckCallbackTimeInterval()) {
return;
}
if (event->sensorTypeId != SENSOR_TYPE_ID_GRAVITY) {
WLOGE("dms: Orientation Sensor Callback is not SENSOR_TYPE_ID_GRAVITY");
return;
}
GravityData* gravityData = reinterpret_cast<GravityData*>(event->data);
int sensorDegree = CalcRotationDegree(gravityData);
DeviceRotation sensorRotationConverted = ScreenRotationController::ConvertSensorToDeviceRotation(
CalcSensorRotation(sensorDegree));
ScreenRotationController::HandleSensorEventInput(sensorRotationConverted);
}
SensorRotation GravitySensorSubscriber::CalcSensorRotation(int sensorDegree)
{
// Use ROTATION_0 when degree range is [0, 30][330, 359]
if (sensorDegree >= 0 && (sensorDegree <= 30 || sensorDegree >= 330)) {
return SensorRotation::ROTATION_0;
} else if (sensorDegree >= 60 && sensorDegree <= 120) { // Use ROTATION_90 when degree range is [60, 120]
return SensorRotation::ROTATION_90;
} else if (sensorDegree >= 150 && sensorDegree <= 210) { // Use ROTATION_180 when degree range is [150, 210]
return SensorRotation::ROTATION_180;
} else if (sensorDegree >= 240 && sensorDegree <= 300) { // Use ROTATION_270 when degree range is [240, 300]
return SensorRotation::ROTATION_270;
} else {
return SensorRotation::INVALID;
}
}
int GravitySensorSubscriber::CalcRotationDegree(GravityData* gravityData)
{
float x = gravityData->x;
float y = gravityData->y;
float z = gravityData->z;
int degree = -1;
if ((x * x + y * y) * VALID_INCLINATION_ANGLE_THRESHOLD_COEFFICIENT < z * z) {
return degree;
}
// arccotx = pi / 2 - arctanx, 90 is used to calculate acot(in degree); degree = rad / pi * 180
degree = 90 - static_cast<int>(round(atan2(y, -x) / M_PI * 180));
// Normalize the degree to the range of 0~360
return degree >= 0 ? degree % 360 : degree % 360 + 360;
}
bool GravitySensorSubscriber::CheckCallbackTimeInterval()
{
std::chrono::milliseconds ms = std::chrono::time_point_cast<std::chrono::milliseconds>(
std::chrono::steady_clock::now()).time_since_epoch();
long currentTimeInMillitm = ms.count();
if (currentTimeInMillitm - lastCallbackTime_ < ORIENTATION_SENSOR_CALLBACK_TIME_INTERVAL) {
return false;
}
lastCallbackTime_ = currentTimeInMillitm;
return true;
}
// Motion
#ifdef WM_SUBSCRIBE_MOTION_ENABLE
void MotionSubscriber::SubscribeMotionSensor()
{
WLOGFI("dms: Subscribe motion Sensor");
if (isMotionSensorSubscribed_) {
WLOGFE("dms: motion sensor's already subscribed");
return;
}
sptr<RotationMotionEventCallback> callback = new (std::nothrow) RotationMotionEventCallback();
int32_t ret = OHOS::Msdp::SubscribeCallback(OHOS::Msdp::TYPE_ROTATION, callback);
if (ret != 0) {
return;
}
motionEventCallback_ = callback;
isMotionSensorSubscribed_ = true;
}
void MotionSubscriber::UnsubscribeMotionSensor()
{
if (!isMotionSensorSubscribed_) {
WLOGFI("dms: Unsubscribe motion sensor");
return;
}
int32_t ret = OHOS::Msdp::UnsubscribeCallback(OHOS::Msdp::TYPE_ROTATION, motionEventCallback_);
if (ret != 0) {
return;
}
isMotionSensorSubscribed_ = false;
}
void RotationMotionEventCallback::OnMotionChanged(const MotionData& motionData)
{
if (motionData.result != 1) {
return;
}
DeviceRotation motionRotation = DeviceRotation::INVALID;
switch (motionData.rotateAction) {
case MOTION_ACTION_PORTRAIT: {
motionRotation = DeviceRotation::ROTATION_PORTRAIT;
break;
}
case MOTION_ACTION_LANDSCAPE: {
motionRotation = DeviceRotation::ROTATION_LANDSCAPE;
break;
}
case MOTION_ACTION_PORTRAIT_INVERTED: {
motionRotation = DeviceRotation::ROTATION_PORTRAIT_INVERTED;
break;
}
case MOTION_ACTION_LANDSCAPE_INVERTED: {
motionRotation = DeviceRotation::ROTATION_LANDSCAPE_INVERTED;
break;
}
default: {
break;
}
}
ScreenRotationController::HandleSensorEventInput(motionRotation);
}
#endif
} // Rosen
} // OHOS

View File

@ -16,6 +16,7 @@
#include <gtest/gtest.h>
#include "display_manager_service.h"
#include "sensor_connector.h"
#include "screen_rotation_controller.h"
using namespace testing;
@ -81,18 +82,18 @@ namespace {
*/
HWTEST_F(ScreenRotationControllerTest, GravitySensor, Function | SmallTest | Level3)
{
ScreenRotationController::isGravitySensorSubscribed_ = true;
ScreenRotationController::SubscribeGravitySensor();
ASSERT_EQ(true, ScreenRotationController::isGravitySensorSubscribed_);
GravitySensorSubscriber::isGravitySensorSubscribed_ = true;
GravitySensorSubscriber::SubscribeGravitySensor();
ASSERT_EQ(true, GravitySensorSubscriber::isGravitySensorSubscribed_);
ScreenRotationController::isGravitySensorSubscribed_ = false;
ScreenRotationController::SubscribeGravitySensor();
GravitySensorSubscriber::isGravitySensorSubscribed_ = false;
GravitySensorSubscriber::SubscribeGravitySensor();
ScreenRotationController::isGravitySensorSubscribed_ = false;
ScreenRotationController::UnsubscribeGravitySensor();
GravitySensorSubscriber::isGravitySensorSubscribed_ = false;
GravitySensorSubscriber::UnsubscribeGravitySensor();
ScreenRotationController::isGravitySensorSubscribed_ = true;
ScreenRotationController::UnsubscribeGravitySensor();
GravitySensorSubscriber::isGravitySensorSubscribed_ = true;
GravitySensorSubscriber::UnsubscribeGravitySensor();
}
/**
@ -139,11 +140,11 @@ HWTEST_F(ScreenRotationControllerTest, CheckCallbackTimeInterval, Function | Sma
std::chrono::steady_clock::now()).time_since_epoch();
long currentTimeInMillitm = ms.count();
ScreenRotationController::lastCallbackTime_ = currentTimeInMillitm;
ASSERT_EQ(false, ScreenRotationController::CheckCallbackTimeInterval());
GravitySensorSubscriber::lastCallbackTime_ = currentTimeInMillitm;
ASSERT_EQ(false, GravitySensorSubscriber::CheckCallbackTimeInterval());
ScreenRotationController::lastCallbackTime_ = currentTimeInMillitm - 200;
ASSERT_EQ(true, ScreenRotationController::CheckCallbackTimeInterval());
GravitySensorSubscriber::lastCallbackTime_ = currentTimeInMillitm - 200;
ASSERT_EQ(true, GravitySensorSubscriber::CheckCallbackTimeInterval());
}
/**
@ -162,19 +163,19 @@ HWTEST_F(ScreenRotationControllerTest, HandleGravitySensorEventCallback, Functio
std::chrono::system_clock::now()).time_since_epoch();
long currentTimeInMillitm = ms.count();
ScreenRotationController::lastCallbackTime_ = currentTimeInMillitm;
ScreenRotationController::HandleGravitySensorEventCallback(&event);
GravitySensorSubscriber::lastCallbackTime_ = currentTimeInMillitm;
GravitySensorSubscriber::HandleGravitySensorEventCallback(&event);
ScreenRotationController::lastCallbackTime_ = currentTimeInMillitm - 200;
ScreenRotationController::HandleGravitySensorEventCallback(&event);
GravitySensorSubscriber::lastCallbackTime_ = currentTimeInMillitm - 200;
GravitySensorSubscriber::HandleGravitySensorEventCallback(&event);
event.sensorTypeId = SENSOR_TYPE_ID_GRAVITY;
ScreenRotationController::lastCallbackTime_ = currentTimeInMillitm - 200;
ScreenRotationController::HandleGravitySensorEventCallback(&event);
GravitySensorSubscriber::lastCallbackTime_ = currentTimeInMillitm - 200;
GravitySensorSubscriber::HandleGravitySensorEventCallback(&event);
data.z = 1.f;
ScreenRotationController::lastCallbackTime_ = currentTimeInMillitm - 200;
ScreenRotationController::HandleGravitySensorEventCallback(&event);
GravitySensorSubscriber::lastCallbackTime_ = currentTimeInMillitm - 200;
GravitySensorSubscriber::HandleGravitySensorEventCallback(&event);
ASSERT_EQ(DeviceRotation::INVALID, ScreenRotationController::lastSensorRotationConverted_);
}
@ -186,13 +187,13 @@ HWTEST_F(ScreenRotationControllerTest, HandleGravitySensorEventCallback, Functio
HWTEST_F(ScreenRotationControllerTest, CalcRotationDegree, Function | SmallTest | Level3)
{
GravityData data0 = {0.f, 0.f, 0.f};
ASSERT_EQ(270, ScreenRotationController::CalcRotationDegree(&data0));
ASSERT_EQ(270, GravitySensorSubscriber::CalcRotationDegree(&data0));
GravityData data1 = {0.f, 0.f, 1.f};
ASSERT_EQ(-1, ScreenRotationController::CalcRotationDegree(&data1));
ASSERT_EQ(-1, GravitySensorSubscriber::CalcRotationDegree(&data1));
GravityData data2 = {1.f, 1.f, 1.f};
ASSERT_EQ(315, ScreenRotationController::CalcRotationDegree(&data2));
ASSERT_EQ(315, GravitySensorSubscriber::CalcRotationDegree(&data2));
}
/**
@ -418,13 +419,13 @@ HWTEST_F(ScreenRotationControllerTest, ProcessSwitchToAutoRotation, Function | S
*/
HWTEST_F(ScreenRotationControllerTest, CalcSensorRotation, Function | SmallTest | Level3)
{
ASSERT_EQ(SensorRotation::INVALID, ScreenRotationController::CalcSensorRotation(-30));
ASSERT_EQ(SensorRotation::ROTATION_0, ScreenRotationController::CalcSensorRotation(15));
ASSERT_EQ(SensorRotation::ROTATION_0, ScreenRotationController::CalcSensorRotation(345));
ASSERT_EQ(SensorRotation::ROTATION_90, ScreenRotationController::CalcSensorRotation(75));
ASSERT_EQ(SensorRotation::ROTATION_180, ScreenRotationController::CalcSensorRotation(180));
ASSERT_EQ(SensorRotation::ROTATION_270, ScreenRotationController::CalcSensorRotation(270));
ASSERT_EQ(SensorRotation::ROTATION_0, ScreenRotationController::CalcSensorRotation(600));
ASSERT_EQ(SensorRotation::INVALID, GravitySensorSubscriber::CalcSensorRotation(-30));
ASSERT_EQ(SensorRotation::ROTATION_0, GravitySensorSubscriber::CalcSensorRotation(15));
ASSERT_EQ(SensorRotation::ROTATION_0, GravitySensorSubscriber::CalcSensorRotation(345));
ASSERT_EQ(SensorRotation::ROTATION_90, GravitySensorSubscriber::CalcSensorRotation(75));
ASSERT_EQ(SensorRotation::ROTATION_180, GravitySensorSubscriber::CalcSensorRotation(180));
ASSERT_EQ(SensorRotation::ROTATION_270, GravitySensorSubscriber::CalcSensorRotation(270));
ASSERT_EQ(SensorRotation::ROTATION_0, GravitySensorSubscriber::CalcSensorRotation(600));
}
/**

View File

@ -19,8 +19,13 @@ ability_runtime_napi_path = "${ability_runtime_path}/frameworks/js/napi"
declare_args() {
efficiency_manager_enable = true
window_manager_feature_subscribe_motion = false
if (defined(global_parts_info) &&
!defined(global_parts_info.resourceschedule_efficiency_manager)) {
efficiency_manager_enable = false
}
}
print(
"window_manager_feature_subscribe_motion = ${window_manager_feature_subscribe_motion}")