1 /* 2 * Copyright (c) 2023 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_FOLD_SCREEN_SENSOR_MANAGER_H 17 #define OHOS_ROSEN_FOLD_SCREEN_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 "refbase.h" 27 #include "wm_single_instance.h" 28 #include "sensor_agent.h" 29 #include "sensor_agent_type.h" 30 31 namespace OHOS { 32 namespace Rosen { 33 34 class FoldScreenSensorManager : public RefBase { 35 WM_DECLARE_SINGLE_INSTANCE_BASE(FoldScreenSensorManager); 36 37 public: 38 void RegisterPostureCallback(); 39 40 void RegisterHallCallback(); 41 42 void RegisterApplicationStateObserver(); 43 44 void UnRegisterPostureCallback(); 45 46 void UnRegisterHallCallback(); 47 48 void SetFoldScreenPolicy(sptr<FoldScreenPolicy> foldScreenPolicy); 49 50 void SetSensorFoldStateManager(sptr<SensorFoldStateManager> sensorFoldStateManager); 51 52 void HandlePostureData(const SensorEvent * const event); 53 54 void HandleHallData(const SensorEvent * const event); 55 56 void TriggerDisplaySwitch(); 57 58 protected: 59 FoldStatus GetCurrentState(); 60 61 private: 62 sptr<FoldScreenPolicy> foldScreenPolicy_; 63 64 sptr<SensorFoldStateManager> sensorFoldStateManager_; 65 66 std::recursive_mutex mutex_; 67 68 FoldStatus mState_ = FoldStatus::UNKNOWN; 69 70 SensorUser postureUser {}; 71 72 SensorUser hallUser {}; 73 74 void notifyFoldAngleChanged(float foldAngle); 75 76 FoldScreenSensorManager(); 77 78 ~FoldScreenSensorManager() = default; 79 80 float globalAngle = -1.0F; 81 82 uint16_t globalHall = USHRT_MAX; 83 84 bool registerPosture_ = false; 85 86 typedef struct EXTHALLData { 87 float flag = 0.0; 88 float hall = 0.0; 89 } ExtHallData; 90 }; 91 } // namespace Rosen 92 } // namespace OHOS 93 #endif 94 #endif