• 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 <thread>
20 
21 #ifdef HDF_DRIVERS_INTERFACE_SENSOR
22 #include "sensor_data_processer.h"
23 #include "sensor_hdi_connection.h"
24 #else
25 #include "sensor.h"
26 #endif // HDF_DRIVERS_INTERFACE_SENSOR
27 
28 namespace OHOS {
29 namespace Sensors {
30 using namespace Security::AccessToken;
31 class SensorManager : public Singleton<SensorManager> {
32 public:
33 #ifdef HDF_DRIVERS_INTERFACE_SENSOR
34     void InitSensorMap(const std::unordered_map<SensorDescription, Sensor> &sensorMap,
35         sptr<SensorDataProcesser> dataProcesser, sptr<ReportDataCallback> dataCallback);
36     bool SetBestSensorParams(const SensorDescription &sensorDesc, int64_t samplingPeriodNs, int64_t maxReportDelayNs);
37     bool ResetBestSensorParams(const SensorDescription &sensorDesc);
38     void StartDataReportThread();
39 #else
40     void InitSensorMap(const std::unordered_map<SensorDescription, Sensor> &sensorMap);
41 #endif // HDF_DRIVERS_INTERFACE_SENSOR
42     bool SaveSubscriber(const SensorDescription &sensorDesc, uint32_t pid, int64_t samplingPeriodNs,
43         int64_t maxReportDelayNs);
44     SensorBasicInfo GetSensorInfo(const SensorDescription &sensorDesc, int64_t samplingPeriodNs,
45         int64_t maxReportDelayNs);
46     bool IsOtherClientUsingSensor(const SensorDescription &sensorDesc, int32_t clientPid);
47     ErrCode AfterDisableSensor(const SensorDescription &sensorDesc);
48     void GetPackageName(AccessTokenID tokenId, std::string &packageName, bool isAccessTokenServiceActive = false);
49 
50 private:
51 #ifdef HDF_DRIVERS_INTERFACE_SENSOR
52     SensorHdiConnection &sensorHdiConnection_ = SensorHdiConnection::GetInstance();
53     std::thread dataThread_;
54     sptr<SensorDataProcesser> sensorDataProcesser_ = nullptr;
55     sptr<ReportDataCallback> reportDataCallback_ = nullptr;
56 #endif // HDF_DRIVERS_INTERFACE_SENSOR
57     ClientInfo &clientInfo_ = ClientInfo::GetInstance();
58     std::unordered_map<SensorDescription, Sensor> sensorMap_;
59     std::mutex sensorMapMutex_;
60 };
61 } // namespace Sensors
62 } // namespace OHOS
63 #endif // SENSOR_MANAGER_H
64