• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2024-2024 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 POWERMGR_PROXIMITY_CONTROLLER_BASE_H
17 #define POWERMGR_PROXIMITY_CONTROLLER_BASE_H
18 
19 #ifdef HAS_SENSORS_SENSOR_PART
20 #include <mutex>
21 #endif
22 #include "sensor_agent.h"
23 #include "power_state_machine_info.h"
24 
25 namespace OHOS {
26 namespace PowerMgr {
27 typedef void (*SensorCallbackFunc)(SensorEvent *event);
28 
29 class ProximityControllerBase {
30 public:
31     ProximityControllerBase(const std::string& name, SensorCallbackFunc callback);
32     virtual ~ProximityControllerBase();
33     void Enable();
34     void Disable();
IsEnabled()35     bool IsEnabled()
36     {
37         return enabled_;
38     }
IsSupported()39     bool IsSupported()
40     {
41         return support_;
42     }
43     bool IsClose();
GetStatus()44     uint32_t GetStatus()
45     {
46         return status_;
47     }
48     void Clear();
49 
50 protected:
51     static const int32_t PROXIMITY_CLOSE_SCALAR = 0;
52     static const int32_t PROXIMITY_AWAY_SCALAR = 5;
53     static const uint32_t SAMPLING_RATE =  100000000;
54     bool support_ {false};
55     bool enabled_ {false};
56     bool isClose_ {false};
57     uint32_t status_ {0};
58     SensorUser user_ {};
59 };
60 
61 class ProximityNormalController : public ProximityControllerBase {
62 public:
63     explicit ProximityNormalController(const std::string& name = "ProximityNormalController", SensorCallbackFunc
ProximityControllerBase(name,callback)64         callback = &ProximityNormalController::RecordSensorCallback) : ProximityControllerBase(name, callback) {}
~ProximityNormalController()65     ~ProximityNormalController() override {}
66     void ActivateValidProximitySensor(PowerState state);
67     static void RecordSensorCallback(SensorEvent *event);
IsInactiveClose()68     static bool IsInactiveClose()
69     {
70         return isInactiveClose_;
71     }
72 
73 private:
74     bool proximitySensorEnabled_ {false};
75     static std::mutex userMutex_;
76     static bool isInactiveClose_;
77 };
78 } // namespace PowerMgr
79 } // namespace OHOS
80 #endif // POWERMGR_PROXIMITY_CONTROLLER_BASE_H