• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021 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_MANAGER_H
17 #define SENSOR_MANAGER_H
18 
19 #include <mutex>
20 #include <thread>
21 #include <unordered_map>
22 
23 #include "client_info.h"
24 #include "flush_info_record.h"
25 #include "sensor_data_processer.h"
26 #include "sensor_hdi_connection.h"
27 #include "sensor_agent_type.h"
28 namespace OHOS {
29 namespace Sensors {
30 using namespace Security::AccessToken;
31 class SensorManager : public Singleton<SensorManager> {
32 public:
33     bool SetBestSensorParams(uint32_t sensorId, int64_t samplingPeriodNs, int64_t maxReportDelayNs);
34     bool ResetBestSensorParams(uint32_t sensorId);
35     ErrCode SaveSubscriber(uint32_t sensorId, uint32_t pid, int64_t samplingPeriodNs, int64_t maxReportDelayNs);
36     void StartDataReportThread();
37     SensorBasicInfo GetSensorInfo(uint32_t sensorId, int64_t samplingPeriodNs, int64_t maxReportDelayNs);
38     bool IsOtherClientUsingSensor(uint32_t sensorId, int32_t clientPid);
39     ErrCode AfterDisableSensor(uint32_t sensorId);
40     void InitSensorMap(std::unordered_map<uint32_t, Sensor> &sensorMap, sptr<SensorDataProcesser> dataProcesser,
41                        sptr<ReportDataCallback> dataCallback);
42     uint32_t GetSensorFlag(uint32_t sensorId);
43     void GetPackageName(AccessTokenID tokenId, std::string &packageName);
44 
45 private:
46     SensorHdiConnection &sensorHdiConnection_ = SensorHdiConnection::GetInstance();
47     ClientInfo &clientInfo_ = ClientInfo::GetInstance();
48     std::thread dataThread_;
49     sptr<SensorDataProcesser> sensorDataProcesser_;
50     sptr<ReportDataCallback> reportDataCallback_;
51     std::unordered_map<uint32_t, Sensor> sensorMap_;
52     std::mutex sensorMapMutex_;
53 };
54 }  // namespace Sensors
55 }  // namespace OHOS
56 #endif  // SENSOR_MANAGER_H
57