• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #include "dm_common.h"
22 #ifdef WM_SUBSCRIBE_MOTION_ENABLE
23 #include "motion_agent.h"
24 #include "motion_callback_stub.h"
25 #endif
26 #include "screen_rotation_controller.h"
27 #include "sensor_agent.h"
28 #include "window_manager_hilog.h"
29 
30 namespace OHOS {
31 namespace Rosen {
32 class SensorConnector : public RefBase {
33 public:
34     SensorConnector() = delete;
35     ~SensorConnector() = default;
36 
37     static void SubscribeRotationSensor();
38     static void UnsubscribeRotationSensor();
39 };
40 
41 class GravitySensorSubscriber {
42 friend SensorConnector;
43 public:
44     GravitySensorSubscriber() = delete;
45     ~GravitySensorSubscriber() = default;
46 private:
47     static void SubscribeGravitySensor();
48     static void UnsubscribeGravitySensor();
49 
50     static void HandleGravitySensorEventCallback(SensorEvent *event);
51     static bool CheckCallbackTimeInterval();
52     static int CalcRotationDegree(GravityData* gravityData);
53     static SensorRotation CalcSensorRotation(int sensorDegree);
54 
55     static SensorUser user_;
56     static bool isGravitySensorSubscribed_;
57     static long lastCallbackTime_;
58 };
59 
60 #ifdef WM_SUBSCRIBE_MOTION_ENABLE
61 using OHOS::Msdp::MotionCallbackStub;
62 using OHOS::Msdp::MotionData;
63 
64 class RotationMotionEventCallback : public MotionCallbackStub {
65 public:
66     void OnMotionChanged(const MotionData& motionData) override;
67 };
68 
69 class MotionSubscriber {
70 friend SensorConnector;
71 public:
72     MotionSubscriber() = delete;
73     ~MotionSubscriber() = default;
74 private:
75     static void SubscribeMotionSensor();
76     static void UnsubscribeMotionSensor();
77 
78     static sptr<RotationMotionEventCallback> motionEventCallback_;
79     static bool isMotionSensorSubscribed_;
80 };
81 #endif
82 } // Rosen
83 } // OHOS
84 #endif // OHOS_ROSEN_SCREEN_CONNECTOR_H
85