1/* 2 * Copyright (c) 2022 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16#ifndef OHOS_ROSEN_SCREEN_CONNECTOR_H 17#define OHOS_ROSEN_SCREEN_CONNECTOR_H 18 19#include <map> 20#include <refbase.h> 21 22#include "dm_common.h" 23#include "screen_rotation_controller.h" 24#include "window_manager_hilog.h" 25 26#ifdef WM_SUBSCRIBE_MOTION_ENABLE 27#include "motion_agent.h" 28#include "motion_callback_stub.h" 29#endif 30 31#ifdef SENSOR_ENABLE 32#include "sensor_agent.h" 33#endif 34 35namespace OHOS { 36namespace Rosen { 37class SensorConnector : public RefBase { 38public: 39 SensorConnector() = delete; 40 ~SensorConnector() = default; 41 42 static void SubscribeRotationSensor(); 43 static void UnsubscribeRotationSensor(); 44}; 45 46#ifdef SENSOR_ENABLE 47class GravitySensorSubscriber { 48friend SensorConnector; 49public: 50 GravitySensorSubscriber() = delete; 51 ~GravitySensorSubscriber() = default; 52private: 53 static void SubscribeGravitySensor(); 54 static void UnsubscribeGravitySensor(); 55 56 static void HandleGravitySensorEventCallback(SensorEvent *event); 57 static bool CheckCallbackTimeInterval(); 58 static int CalcRotationDegree(GravityData* gravityData); 59 static SensorRotation CalcSensorRotation(int sensorDegree); 60 61 static SensorUser user_; 62 static bool isGravitySensorSubscribed_; 63 static long lastCallbackTime_; 64}; 65#endif 66 67#ifdef WM_SUBSCRIBE_MOTION_ENABLE 68using OHOS::Msdp::MotionCallbackStub; 69using OHOS::Msdp::MotionEvent; 70 71class RotationMotionEventCallback : public MotionCallbackStub { 72public: 73 void OnMotionChanged(const MotionEvent& motionData) override; 74}; 75 76class MotionSubscriber { 77friend SensorConnector; 78public: 79 MotionSubscriber() = delete; 80 ~MotionSubscriber() = default; 81private: 82 static void SubscribeMotionSensor(); 83 static void UnsubscribeMotionSensor(); 84 85 static sptr<RotationMotionEventCallback> motionEventCallback_; 86 static bool isMotionSensorSubscribed_; 87}; 88#endif 89} // Rosen 90} // OHOS 91#endif // OHOS_ROSEN_SCREEN_CONNECTOR_H 92