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_SUPER_FOLD_SENSOR_MANAGER_H 17 #define OHOS_ROSEN_SUPER_FOLD_SENSOR_MANAGER_H 18 19 #include <deque> 20 #include <memory> 21 #include <mutex> 22 #include <sstream> 23 #include <functional> 24 #include <climits> 25 26 #include "refbase.h" 27 #include "wm_single_instance.h" 28 #include "ws_common.h" 29 #include "sensor_agent.h" 30 #include "sensor_agent_type.h" 31 #include "common/include/task_scheduler.h" 32 #include "session/screen/include/screen_property.h" 33 #include "dm_common.h" 34 35 namespace OHOS { 36 37 namespace Rosen { 38 39 class SuperFoldSensorManager : public RefBase { 40 WM_DECLARE_SINGLE_INSTANCE_BASE(SuperFoldSensorManager); 41 42 public: 43 44 void RegisterPostureCallback(); //折叠角度注册回调 45 46 void RegisterHallCallback(); // 磁吸键盘 47 48 void UnregisterPostureCallback(); 49 50 void UnregisterHallCallback(); 51 52 void HandlePostureData(const SensorEvent * const event); 53 54 void HandleHallData(const SensorEvent * const event); 55 56 void HandleSuperSensorChange(SuperFoldStatusChangeEvents events); 57 58 float GetCurAngle(); 59 60 void HandleScreenConnectChange(); 61 void HandleScreenDisconnectChange(); 62 void HandleFoldStatusLockedToExpand(); 63 void HandleFoldStatusUnlocked(); 64 void SetTaskScheduler(std::shared_ptr<TaskScheduler> scheduler); 65 66 private: 67 68 std::recursive_mutex mutex_; 69 70 SensorUser postureUser {}; 71 72 SensorUser hallUser {}; 73 74 float curAngle_ = 170.0F; 75 76 int32_t curInterval_ = 0; 77 78 uint16_t curHall_ = USHRT_MAX; 79 80 void NotifyFoldAngleChanged(float foldAngle); 81 82 void NotifyHallChanged(uint16_t hall); 83 84 void NotifySoftKeyboardChanged(); 85 86 SuperFoldSensorManager(); 87 88 ~SuperFoldSensorManager(); 89 90 std::shared_ptr<TaskScheduler> taskScheduler_ = nullptr; 91 }; 92 } 93 } 94 95 #endif // OHOS_ROSEN_SUPER_FOLD_SENSOR_MANAGER_H