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