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