1 /* 2 * Copyright (c) 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 OHOS_ROSEN_SECONDARY_FOLD_SENSOR_MANAGER_H 17 #define OHOS_ROSEN_SECONDARY_FOLD_SENSOR_MANAGER_H 18 19 #ifdef SENSOR_ENABLE 20 #include <functional> 21 #include <mutex> 22 #include <climits> 23 24 #include "fold_screen_controller.h" 25 #include "fold_screen_controller/sensor_fold_state_manager/sensor_fold_state_manager.h" 26 #include "fold_screen_controller/fold_screen_sensor_manager.h" 27 #include "refbase.h" 28 #include "wm_single_instance.h" 29 #include "sensor_agent.h" 30 #include "sensor_agent_type.h" 31 32 namespace OHOS { 33 namespace Rosen { 34 35 class SecondaryFoldSensorManager : public RefBase { 36 WM_DECLARE_SINGLE_INSTANCE_BASE(SecondaryFoldSensorManager); 37 public: 38 void SetFoldScreenPolicy(sptr<FoldScreenPolicy> foldScreenPolicy); 39 void SetSensorFoldStateManager(sptr<SensorFoldStateManager> sensorFoldStateManager); 40 void RegisterPostureCallback(); 41 void RegisterHallCallback(); 42 void UnRegisterPostureCallback(); 43 void UnRegisterHallCallback(); 44 void HandlePostureData(const SensorEvent * const event); 45 void HandleHallDataExt(const SensorEvent * const event); 46 void PowerKeySetScreenActiveRect(); 47 bool IsPostureUserCallbackInvalid() const; 48 bool IsHallUserCallbackInvalid() const; 49 std::vector<float> GetGlobalAngle() const; 50 std::vector<uint16_t> GetGlobalHall() const; 51 bool isPowerRectExe_ = false; 52 private: 53 sptr<FoldScreenPolicy> foldScreenPolicy_; 54 sptr<SensorFoldStateManager> sensorFoldStateManager_; 55 56 SensorUser postureUser {}; 57 SensorUser hallUser {}; 58 std::vector<float> globalAngle_ = {-1.0F, -1.0F, -1.0F}; 59 std::vector<uint16_t> globalHall_ = {USHRT_MAX, USHRT_MAX}; 60 bool registerPosture_ = false; 61 62 SecondaryFoldSensorManager() = default; 63 ~SecondaryFoldSensorManager() = default; 64 void NotifyFoldAngleChanged(const std::vector<float> &angles); 65 bool GetPostureInner(const SensorEvent * const event, float &valueBc, float &valueAb, 66 float &valueAbAnti); 67 bool GetHallInner(const SensorEvent * const event, uint16_t &valueBc, uint16_t &valueAb); 68 bool IsDataBeyondBoundary(); 69 }; 70 } // namespace Rosen 71 } // namespace OHOS 72 #endif 73 #endif