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 #include "sensor_plugin.h" 26 27 #ifdef SENSOR_ENABLE 28 #include "sensor_agent.h" 29 #endif 30 31 namespace OHOS { 32 namespace Rosen { 33 class SensorConnector : public RefBase { 34 public: 35 SensorConnector() = delete; 36 ~SensorConnector() = default; 37 38 static void SubscribeRotationSensor(); 39 static void UnsubscribeRotationSensor(); 40 }; 41 42 #ifdef SENSOR_ENABLE 43 class GravitySensorSubscriber { 44 friend SensorConnector; 45 public: 46 GravitySensorSubscriber() = delete; 47 ~GravitySensorSubscriber() = default; 48 private: 49 static void SubscribeGravitySensor(); 50 static void UnsubscribeGravitySensor(); 51 52 static void HandleGravitySensorEventCallback(SensorEvent *event); 53 static bool CheckCallbackTimeInterval(); 54 static int CalcRotationDegree(GravityData* gravityData); 55 static SensorRotation CalcSensorRotation(int sensorDegree); 56 57 static SensorUser user_; 58 static bool isGravitySensorSubscribed_; 59 static long lastCallbackTime_; 60 }; 61 #endif 62 63 #ifdef WM_SUBSCRIBE_MOTION_ENABLE 64 class MotionSubscriber { 65 friend SensorConnector; 66 public: 67 MotionSubscriber() = delete; 68 ~MotionSubscriber() = default; 69 private: 70 static void SubscribeMotionSensor(); 71 static void UnsubscribeMotionSensor(); 72 73 static bool isMotionSensorSubscribed_; 74 }; 75 #endif 76 } // Rosen 77 } // OHOS 78 #endif // OHOS_ROSEN_SCREEN_CONNECTOR_H 79