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 SENSOR_POWER_POLICY_H 17 #define SENSOR_POWER_POLICY_H 18 19 #include "active_info.h" 20 #include "sensor_agent_type.h" 21 #include "sensor_manager.h" 22 #include "stream_session.h" 23 #ifdef HDF_DRIVERS_INTERFACE_SENSOR 24 #include "sensor_hdi_connection.h" 25 #endif // HDF_DRIVERS_INTERFACE_SENSOR 26 27 namespace OHOS { 28 namespace Sensors { 29 class SensorPowerPolicy : public Singleton<SensorPowerPolicy> { 30 public: 31 ErrCode SuspendSensors(int32_t pid); 32 ErrCode ResumeSensors(int32_t pid); 33 ErrCode ResetSensors(); 34 std::vector<ActiveInfo> GetActiveInfoList(int32_t pid); 35 void ReportActiveInfo(const ActiveInfo &activeInfo, const std::vector<SessionPtr> &sessionList); 36 void DeleteDeathPidSensorInfo(int32_t pid); 37 38 private: 39 bool CheckFreezingSensor(int32_t sensorType); 40 bool Suspend(int32_t pid, const std::vector<SensorDescription> &sensorDescList, 41 std::unordered_map<SensorDescription, SensorBasicInfo> &SensorInfoMap); 42 bool Resume(int32_t pid, const SensorDescription &sensorDesc, int64_t samplingPeriodNs, int64_t maxReportDelayNs); 43 ErrCode RestoreSensorInfo(int32_t pid, const SensorDescription &sensorDesc, int64_t samplingPeriodNs, 44 int64_t maxReportDelayNs); 45 std::vector<int32_t> GetSuspendPidList(); 46 std::mutex pidSensorInfoMutex_; 47 std::unordered_map<int32_t, std::unordered_map<SensorDescription, SensorBasicInfo>> pidSensorInfoMap_; 48 }; 49 } // namespace Sensors 50 } // namespace OHOS 51 #endif // SENSOR_POWER_POLICY_H