From d497f5c95013a473c553a39ab3e537668a28da66 Mon Sep 17 00:00:00 2001 From: h00514358 Date: Wed, 26 Jan 2022 17:30:19 +0800 Subject: [PATCH 1/3] Signed-off-by:hellohyh001 Signed-off-by: h00514358 --- .../adapter/include/compatible_connection.h | 8 +- .../adapter/include/hdi_connection.h | 18 +- .../adapter/src/compatible_connection.cpp | 8 +- .../adapter/src/hdi_connection.cpp | 188 ++++++++++++++++-- .../include/i_sensor_hdi_connection.h | 8 +- .../interface/include/sensor_hdi_connection.h | 8 +- .../interface/src/sensor_hdi_connection.cpp | 8 +- services/sensor/src/sensor_service.cpp | 7 +- 8 files changed, 215 insertions(+), 38 deletions(-) diff --git a/services/sensor/hdi_connection/adapter/include/compatible_connection.h b/services/sensor/hdi_connection/adapter/include/compatible_connection.h index cf5d1900..958fb80d 100644 --- a/services/sensor/hdi_connection/adapter/include/compatible_connection.h +++ b/services/sensor/hdi_connection/adapter/include/compatible_connection.h @@ -31,17 +31,17 @@ public: int32_t GetSensorList(std::vector& sensorList) override; - int32_t EnableSensor(uint32_t sensorId) override; + int32_t EnableSensor(int32_t sensorId) override; - int32_t DisableSensor(uint32_t sensorId) override; + int32_t DisableSensor(int32_t sensorId) override; int32_t SetBatch(int32_t sensorId, int64_t samplingInterval, int64_t reportInterval) override; int32_t SetMode(int32_t sensorId, int32_t mode) override; - int32_t SetOption(int32_t sensorId, uint32_t option) override; + int32_t SetOption(int32_t sensorId, int32_t option) override; - int32_t RunCommand(uint32_t sensorId, int32_t cmd, int32_t params) override; + int32_t RunCommand(int32_t sensorId, int32_t cmd, int32_t params) override; int32_t RegisteDataReport(ZReportDataCb cb, sptr reportDataCallback) override; diff --git a/services/sensor/hdi_connection/adapter/include/hdi_connection.h b/services/sensor/hdi_connection/adapter/include/hdi_connection.h index 8444072c..6fc45084 100644 --- a/services/sensor/hdi_connection/adapter/include/hdi_connection.h +++ b/services/sensor/hdi_connection/adapter/include/hdi_connection.h @@ -16,7 +16,9 @@ #ifndef HDI_CONNECTION_H #define HDI_CONNECTION_H +#include "death_recipient_template.h" #include "i_sensor_hdi_connection.h" +#include "sensor_basic_info.h" namespace OHOS { namespace Sensors { @@ -30,17 +32,17 @@ public: int32_t GetSensorList(std::vector& sensorList) override; - int32_t EnableSensor(uint32_t sensorId) override; + int32_t EnableSensor(int32_t sensorId) override; - int32_t DisableSensor(uint32_t sensorId) override; + int32_t DisableSensor(int32_t sensorId) override; int32_t SetBatch(int32_t sensorId, int64_t samplingInterval, int64_t reportInterval) override; int32_t SetMode(int32_t sensorId, int32_t mode) override; - int32_t SetOption(int32_t sensorId, uint32_t option) override; + int32_t SetOption(int32_t sensorId, int32_t option) override; - int32_t RunCommand(uint32_t sensorId, int32_t cmd, int32_t params) override; + int32_t RunCommand(int32_t sensorId, int32_t cmd, int32_t params) override; int32_t RegisteDataReport(ZReportDataCb cb, sptr reportDataCallback) override; @@ -50,10 +52,18 @@ public: sptr getReportDataCallback(); + void ProcessDeathObserver(const wptr &object); private: DISALLOW_COPY_AND_MOVE(HdiConnection); static ZReportDataCb reportDataCb_; static sptr reportDataCallback_; + sptr hdiDeathObserver_; + void RegisterHdiDeathRecipient(); + void UnregisterHdiDeathRecipient(); + void reconnect(); + void updateSensorBasicInfo(int32_t sensorId, int64_t samplingPeriodNs, int64_t maxReportDelayNs); + void setSensorBasicInfoState(int32_t sensorId, enum SensorState state); + void deleteSensorBasicInfoState(int32_t sensorId); }; } // namespace Sensors } // namespace OHOS diff --git a/services/sensor/hdi_connection/adapter/src/compatible_connection.cpp b/services/sensor/hdi_connection/adapter/src/compatible_connection.cpp index 25d5d025..ac93b115 100644 --- a/services/sensor/hdi_connection/adapter/src/compatible_connection.cpp +++ b/services/sensor/hdi_connection/adapter/src/compatible_connection.cpp @@ -59,7 +59,7 @@ int32_t CompatibleConnection::GetSensorList(std::vector& sensorList) return ERR_OK; } -int32_t CompatibleConnection::EnableSensor(uint32_t sensorId) +int32_t CompatibleConnection::EnableSensor(int32_t sensorId) { int32_t ret = hdiServiceImpl_.EnableSensor(sensorId); if (ret < 0) { @@ -69,7 +69,7 @@ int32_t CompatibleConnection::EnableSensor(uint32_t sensorId) return ERR_OK; }; -int32_t CompatibleConnection::DisableSensor(uint32_t sensorId) +int32_t CompatibleConnection::DisableSensor(int32_t sensorId) { int32_t ret = hdiServiceImpl_.DisableSensor(sensorId); if (ret < 0) { @@ -99,12 +99,12 @@ int32_t CompatibleConnection::SetMode(int32_t sensorId, int32_t mode) return ERR_OK; } -int32_t CompatibleConnection::RunCommand(uint32_t sensorId, int32_t cmd, int32_t params) +int32_t CompatibleConnection::RunCommand(int32_t sensorId, int32_t cmd, int32_t params) { return ERR_OK; } -int32_t CompatibleConnection::SetOption(int32_t sensorId, uint32_t option) +int32_t CompatibleConnection::SetOption(int32_t sensorId, int32_t option) { int32_t ret = hdiServiceImpl_.SetOption(sensorId, option); if (ret != 0) { diff --git a/services/sensor/hdi_connection/adapter/src/hdi_connection.cpp b/services/sensor/hdi_connection/adapter/src/hdi_connection.cpp index e3b69071..48b113f7 100644 --- a/services/sensor/hdi_connection/adapter/src/hdi_connection.cpp +++ b/services/sensor/hdi_connection/adapter/src/hdi_connection.cpp @@ -18,6 +18,9 @@ #include "sensor_event_callback.h" #include "sensors_errors.h" #include "sensors_log_domain.h" +#include +#include +#include namespace OHOS { namespace Sensors { @@ -28,7 +31,11 @@ using hdi::sensor::v1_0::HdfSensorInformation; namespace { constexpr HiLogLabel LABEL = { LOG_CORE, SensorsLogDomain::SENSOR_SERVICE, "HdiConnection" }; sptr sensorInterface_ = nullptr; -sptr eventCallback_ = new SensorEventCallback(); +sptr eventCallback_ = nullptr; +std::map sensorBasicInfoMap_; +std::mutex sensorBasicInfoMutex_; +constexpr int32_t GET_HDI_SERVICE_COUNT = 10; +constexpr uint32_t WAIT_MS = 100; } ZReportDataCb HdiConnection::reportDataCb_ = nullptr; @@ -36,17 +43,35 @@ sptr HdiConnection::reportDataCallback_ = nullptr; int32_t HdiConnection::ConnectHdi() { - sensorInterface_ = ISensorInterface::Get(); - if (sensorInterface_ == nullptr) { - HiLog::Error(LABEL, "%{public}s connect v1_0 hdi failed", __func__); - return ERR_NO_INIT; + HiLog::Debug(LABEL, "%{public}s begin", __func__); + int32_t retry = 0; + while (retry < GET_HDI_SERVICE_COUNT) { + sensorInterface_ = ISensorInterface::Get(); + if (sensorInterface_ != nullptr) { + HiLog::Info(LABEL, "%{public}s connect v1_0 hdi success", __func__); + eventCallback_ = new (std::nothrow) SensorEventCallback(); + if (eventCallback_ == nullptr) { + HiLog::Error(LABEL, "%{public}s failed to initialize eventCallback", __func__); + return ERR_NO_INIT; + } + RegisterHdiDeathRecipient(); + return ERR_OK; + } + retry++; + HiLog::Warn(LABEL, "%{public}s connect hdi service failed, retry : %{public}d", __func__, retry); + std::this_thread::sleep_for(std::chrono::milliseconds(WAIT_MS)); } - return ERR_OK; + HiLog::Error(LABEL, "%{public}s connect v1_0 hdi failed", __func__); + return ERR_NO_INIT; } int32_t HdiConnection::GetSensorList(std::vector& sensorList) { - HiLog::Info(LABEL, "%{public}s in", __func__); + HiLog::Debug(LABEL, "%{public}s begin", __func__); + if (sensorInterface_ == nullptr) { + HiLog::Error(LABEL, "%{public}s connect v1_0 hdi failed", __func__); + return ERR_NO_INIT; + } std::vector sensorInfos; int32_t ret = sensorInterface_->GetAllSensorInfo(sensorInfos); if (ret != 0) { @@ -68,38 +93,58 @@ int32_t HdiConnection::GetSensorList(std::vector& sensorList) return ERR_OK; } -int32_t HdiConnection::EnableSensor(uint32_t sensorId) +int32_t HdiConnection::EnableSensor(int32_t sensorId) { + if (sensorInterface_ == nullptr) { + HiLog::Error(LABEL, "%{public}s connect v1_0 hdi failed", __func__); + return ERR_NO_INIT; + } int32_t ret = sensorInterface_->Enable(sensorId); if (ret < 0) { HiLog::Error(LABEL, "%{public}s is failed", __func__); return ret; } + setSensorBasicInfoState(sensorId, SENSOR_ENABLED); return ERR_OK; } -int32_t HdiConnection::DisableSensor(uint32_t sensorId) +int32_t HdiConnection::DisableSensor(int32_t sensorId) { + if (sensorInterface_ == nullptr) { + HiLog::Error(LABEL, "%{public}s connect v1_0 hdi failed", __func__); + return ERR_NO_INIT; + } int32_t ret = sensorInterface_->Disable(sensorId); if (ret < 0) { HiLog::Error(LABEL, "%{public}s is failed", __func__); return ret; } + deleteSensorBasicInfoState(sensorId); return ERR_OK; } int32_t HdiConnection::SetBatch(int32_t sensorId, int64_t samplingInterval, int64_t reportInterval) { + if (sensorInterface_ == nullptr) { + HiLog::Error(LABEL, "%{public}s connect v1_0 hdi failed", __func__); + return ERR_NO_INIT; + } int32_t ret = sensorInterface_->SetBatch(sensorId, samplingInterval, reportInterval); if (ret < 0) { HiLog::Error(LABEL, "%{public}s failed", __func__); return ret; } + updateSensorBasicInfo(sensorId, samplingInterval, reportInterval); return ERR_OK; } int32_t HdiConnection::SetMode(int32_t sensorId, int32_t mode) { + HiLog::Debug(LABEL, "%{public}s begin", __func__); + if (sensorInterface_ == nullptr) { + HiLog::Error(LABEL, "%{public}s connect v1_0 hdi failed", __func__); + return ERR_NO_INIT; + } int32_t ret = sensorInterface_->SetMode(sensorId, mode); if (ret < 0) { HiLog::Error(LABEL, "%{public}s is failed", __func__); @@ -108,8 +153,13 @@ int32_t HdiConnection::SetMode(int32_t sensorId, int32_t mode) return ERR_OK; } -int32_t HdiConnection::SetOption(int32_t sensorId, uint32_t option) +int32_t HdiConnection::SetOption(int32_t sensorId, int32_t option) { + HiLog::Debug(LABEL, "%{public}s begin", __func__); + if (sensorInterface_ == nullptr) { + HiLog::Error(LABEL, "%{public}s connect v1_0 hdi failed", __func__); + return ERR_NO_INIT; + } int32_t ret = sensorInterface_->SetOption(sensorId, option); if (ret < 0) { HiLog::Error(LABEL, "%{public}s is failed", __func__); @@ -120,8 +170,9 @@ int32_t HdiConnection::SetOption(int32_t sensorId, uint32_t option) int32_t HdiConnection::RegisteDataReport(ZReportDataCb cb, sptr reportDataCallback) { - if (reportDataCallback == nullptr) { - HiLog::Error(LABEL, "%{public}s failed, reportDataCallback cannot be null", __func__); + HiLog::Debug(LABEL, "%{public}s begin", __func__); + if (reportDataCallback == nullptr || sensorInterface_ == nullptr) { + HiLog::Error(LABEL, "%{public}s failed, reportDataCallback or sensorInterface_ or eventCallback_ cannot be null", __func__); return ERR_NO_INIT; } int32_t ret = sensorInterface_->Register(0, eventCallback_); @@ -136,21 +187,29 @@ int32_t HdiConnection::RegisteDataReport(ZReportDataCb cb, sptrUnregister(0, eventCallback_); if (ret < 0) { HiLog::Error(LABEL, "%{public}s failed", __func__); return ret; } + eventCallback_ = nullptr; + UnregisterHdiDeathRecipient(); return ERR_OK; } -int32_t HdiConnection::RunCommand(uint32_t sensorId, int32_t cmd, int32_t params) +int32_t HdiConnection::RunCommand(int32_t sensorId, int32_t cmd, int32_t params) { return 0; } ZReportDataCb HdiConnection::getReportDataCb() { + HiLog::Debug(LABEL, "%{public}s begin", __func__); if (reportDataCb_ == nullptr) { HiLog::Error(LABEL, "%{public}s reportDataCb_ cannot be null", __func__); } @@ -159,10 +218,113 @@ ZReportDataCb HdiConnection::getReportDataCb() sptr HdiConnection::getReportDataCallback() { + HiLog::Debug(LABEL, "%{public}s begin", __func__); if (reportDataCallback_ == nullptr) { HiLog::Error(LABEL, "%{public}s reportDataCallback_ cannot be null", __func__); } return reportDataCallback_; } + +void HdiConnection::updateSensorBasicInfo(int32_t sensorId, int64_t samplingPeriodNs, int64_t maxReportDelayNs) +{ + std::lock_guard sensorInfoLock(sensorBasicInfoMutex_); + SensorBasicInfo sensorBasicInfo; + sensorBasicInfo.SetSamplingPeriodNs(samplingPeriodNs); + sensorBasicInfo.SetMaxReportDelayNs(maxReportDelayNs); + sensorBasicInfoMap_[sensorId] = sensorBasicInfo; +} + +void HdiConnection::setSensorBasicInfoState(int32_t sensorId, enum SensorState state) +{ + std::lock_guard sensorInfoLock(sensorBasicInfoMutex_); + auto it = sensorBasicInfoMap_.find(sensorId); + if (it == sensorBasicInfoMap_.end()) { + HiLog::Warn(LABEL, "%{public}s should set batch first", __func__); + } + sensorBasicInfoMap_[sensorId].SetSensorState(state); +} + +void HdiConnection::deleteSensorBasicInfoState(int32_t sensorId) +{ + std::lock_guard sensorInfoLock(sensorBasicInfoMutex_); + auto it = sensorBasicInfoMap_.find(sensorId); + if (it != sensorBasicInfoMap_.end()) { + sensorBasicInfoMap_.erase(sensorId); + } +} + +void HdiConnection::RegisterHdiDeathRecipient() +{ + HiLog::Debug(LABEL, "%{public}s begin", __func__); + if (sensorInterface_ == nullptr) { + HiLog::Error(LABEL, "%{public}s connect v1_0 hdi failed", __func__); + return; + } + hdiDeathObserver_ = new (std::nothrow) DeathRecipientTemplate(*const_cast(this)); + if (hdiDeathObserver_ == nullptr) { + HiLog::Error(LABEL, "%{public}s hdiDeathObserver_ cannot be null", __func__); + return; + } + sensorInterface_->AsObject()->AddDeathRecipient(hdiDeathObserver_); +} + +void HdiConnection::UnregisterHdiDeathRecipient() +{ + HiLog::Debug(LABEL, "%{public}s begin", __func__); + if (sensorInterface_ == nullptr || hdiDeathObserver_ == nullptr) { + HiLog::Error(LABEL, "%{public}s sensorInterface_ or hdiDeathObserver_ is null", __func__); + return; + } + sensorInterface_->AsObject()->RemoveDeathRecipient(hdiDeathObserver_); +} + +void HdiConnection::ProcessDeathObserver(const wptr &object) +{ + HiLog::Debug(LABEL, "%{public}s begin", __func__); + sptr hdiService = object.promote(); + if (hdiService == nullptr) { + HiLog::Error(LABEL, "%{public}s invalid remote object", __func__); + return; + } + hdiService->RemoveDeathRecipient(hdiDeathObserver_); + eventCallback_ = nullptr; + reconnect(); +} + +void HdiConnection::reconnect() +{ + HiLog::Debug(LABEL, "%{public}s begin", __func__); + int32_t ret = ConnectHdi(); + if (ret < 0) { + HiLog::Error(LABEL, "%{public}s failed to get an instance of hdi service", __func__); + return; + } + ret = sensorInterface_->Register(0, eventCallback_); + if (ret < 0) { + HiLog::Error(LABEL, "%{public}s register callback fail", __func__); + return; + } + std::vector sensorList; + ret = GetSensorList(sensorList); + if (ret < 0) { + HiLog::Error(LABEL, "%{public}s get sensor list fail", __func__); + return; + } + std::lock_guard sensorInfoLock(sensorBasicInfoMutex_); + for(const auto &sensorInfo : sensorBasicInfoMap_) { + int32_t sensorTypeId = sensorInfo.first; + ret = SetBatch(sensorTypeId, sensorInfo.second.GetSamplingPeriodNs(), + sensorInfo.second.GetMaxReportDelayNs()); + if (ret < 0 || sensorInfo.second.GetSensorState() != SENSOR_ENABLED) { + HiLog::Error(LABEL, "%{public}s sensorTypeId: %{public}d set batch fail or not need enable sensor", + __func__, sensorTypeId); + continue; + } + ret = EnableSensor(sensorTypeId); + if (ret < 0) { + HiLog::Error(LABEL, "%{public}s enable sensor fail, sensorTypeId: %{public}d", __func__, sensorTypeId); + } + } +} } // namespace Sensors } // namespace OHOS diff --git a/services/sensor/hdi_connection/interface/include/i_sensor_hdi_connection.h b/services/sensor/hdi_connection/interface/include/i_sensor_hdi_connection.h index 85ef4c1c..d3cc38aa 100644 --- a/services/sensor/hdi_connection/interface/include/i_sensor_hdi_connection.h +++ b/services/sensor/hdi_connection/interface/include/i_sensor_hdi_connection.h @@ -33,17 +33,17 @@ public: virtual int32_t GetSensorList(std::vector& sensorList) = 0; - virtual int32_t EnableSensor(uint32_t sensorId) = 0; + virtual int32_t EnableSensor(int32_t sensorId) = 0; - virtual int32_t DisableSensor(uint32_t sensorId) = 0; + virtual int32_t DisableSensor(int32_t sensorId) = 0; virtual int32_t SetBatch(int32_t sensorId, int64_t samplingInterval, int64_t reportInterval) = 0; virtual int32_t SetMode(int32_t sensorId, int32_t mode) = 0; - virtual int32_t SetOption(int32_t sensorId, uint32_t option) = 0; + virtual int32_t SetOption(int32_t sensorId, int32_t option) = 0; - virtual int32_t RunCommand(uint32_t sensorId, int32_t cmd, int32_t params) = 0; + virtual int32_t RunCommand(int32_t sensorId, int32_t cmd, int32_t params) = 0; virtual int32_t RegisteDataReport(ZReportDataCb cb, sptr reportDataCallback) = 0; diff --git a/services/sensor/hdi_connection/interface/include/sensor_hdi_connection.h b/services/sensor/hdi_connection/interface/include/sensor_hdi_connection.h index a4a30a4d..809d83e5 100644 --- a/services/sensor/hdi_connection/interface/include/sensor_hdi_connection.h +++ b/services/sensor/hdi_connection/interface/include/sensor_hdi_connection.h @@ -31,17 +31,17 @@ public: int32_t GetSensorList(std::vector& sensorList) override; - int32_t EnableSensor(uint32_t sensorId) override; + int32_t EnableSensor(int32_t sensorId) override; - int32_t DisableSensor(uint32_t sensorId) override; + int32_t DisableSensor(int32_t sensorId) override; int32_t SetBatch(int32_t sensorId, int64_t samplingInterval, int64_t reportInterval) override; int32_t SetMode(int32_t sensorId, int32_t mode) override; - int32_t SetOption(int32_t sensorId, uint32_t option) override; + int32_t SetOption(int32_t sensorId, int32_t option) override; - int32_t RunCommand(uint32_t sensorId, int32_t cmd, int32_t params) override; + int32_t RunCommand(int32_t sensorId, int32_t cmd, int32_t params) override; int32_t RegisteDataReport(ZReportDataCb cb, sptr reportDataCallback) override; diff --git a/services/sensor/hdi_connection/interface/src/sensor_hdi_connection.cpp b/services/sensor/hdi_connection/interface/src/sensor_hdi_connection.cpp index 2b9e59ae..2384713d 100644 --- a/services/sensor/hdi_connection/interface/src/sensor_hdi_connection.cpp +++ b/services/sensor/hdi_connection/interface/src/sensor_hdi_connection.cpp @@ -64,7 +64,7 @@ int32_t SensorHdiConnection::GetSensorList(std::vector& sensorList) return ERR_OK; } -int32_t SensorHdiConnection::EnableSensor(uint32_t sensorId) +int32_t SensorHdiConnection::EnableSensor(int32_t sensorId) { int32_t ret = iSensorHdiConnection_->EnableSensor(sensorId); if (ret != 0) { @@ -74,7 +74,7 @@ int32_t SensorHdiConnection::EnableSensor(uint32_t sensorId) return ret; }; -int32_t SensorHdiConnection::DisableSensor(uint32_t sensorId) +int32_t SensorHdiConnection::DisableSensor(int32_t sensorId) { int32_t ret = iSensorHdiConnection_->DisableSensor(sensorId); if (ret != 0) { @@ -104,7 +104,7 @@ int32_t SensorHdiConnection::SetMode(int32_t sensorId, int32_t mode) return ret; } -int32_t SensorHdiConnection::SetOption(int32_t sensorId, uint32_t option) +int32_t SensorHdiConnection::SetOption(int32_t sensorId, int32_t option) { int32_t ret = iSensorHdiConnection_->SetOption(sensorId, option); if (ret != 0) { @@ -114,7 +114,7 @@ int32_t SensorHdiConnection::SetOption(int32_t sensorId, uint32_t option) return ret; } -int32_t SensorHdiConnection::RunCommand(uint32_t sensorId, int32_t cmd, int32_t params) +int32_t SensorHdiConnection::RunCommand(int32_t sensorId, int32_t cmd, int32_t params) { int32_t ret = iSensorHdiConnection_->RunCommand(sensorId, cmd, params); if (ret != 0) { diff --git a/services/sensor/src/sensor_service.cpp b/services/sensor/src/sensor_service.cpp index d2fffa49..a7e736a7 100644 --- a/services/sensor/src/sensor_service.cpp +++ b/services/sensor/src/sensor_service.cpp @@ -61,7 +61,7 @@ void SensorService::OnDump() void SensorService::OnStart() { - HiLog::Info(LABEL, "%{public}s begin", __func__); + HiLog::Debug(LABEL, "%{public}s begin", __func__); if (state_ == SensorServiceState::STATE_RUNNING) { HiLog::Warn(LABEL, "%{public}s SensorService has already started", __func__); return; @@ -147,11 +147,16 @@ bool SensorService::InitSensorPolicy() void SensorService::OnStop() { + HiLog::Debug(LABEL, "%{public}s begin", __func__); if (state_ == SensorServiceState::STATE_STOPPED) { HiLog::Warn(LABEL, "%{public}s already stopped", __func__); return; } state_ = SensorServiceState::STATE_STOPPED; + int32_t ret = sensorHdiConnection_.DestroyHdiConnection(); + if (ret != ERR_OK) { + HiLog::Error(LABEL, "%{public}s destroy hdi connect fail", __func__); + } } void SensorService::ReportSensorUsedInfo(uint32_t sensorId, bool enable) -- Gitee From f3987ff22cce29a1b59bd0d4838be0526760eee5 Mon Sep 17 00:00:00 2001 From: h00514358 Date: Wed, 26 Jan 2022 19:44:38 +0800 Subject: [PATCH 2/3] Signed-off-by:hellohyh001 Signed-off-by: h00514358 --- .../adapter/include/hdi_connection.h | 2 +- .../hdi_connection/adapter/src/hdi_connection.cpp | 15 ++++++++------- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/services/sensor/hdi_connection/adapter/include/hdi_connection.h b/services/sensor/hdi_connection/adapter/include/hdi_connection.h index 6fc45084..b5f26cb5 100644 --- a/services/sensor/hdi_connection/adapter/include/hdi_connection.h +++ b/services/sensor/hdi_connection/adapter/include/hdi_connection.h @@ -62,7 +62,7 @@ private: void UnregisterHdiDeathRecipient(); void reconnect(); void updateSensorBasicInfo(int32_t sensorId, int64_t samplingPeriodNs, int64_t maxReportDelayNs); - void setSensorBasicInfoState(int32_t sensorId, enum SensorState state); + void setSensorBasicInfoState(int32_t sensorId, SensorState state); void deleteSensorBasicInfoState(int32_t sensorId); }; } // namespace Sensors diff --git a/services/sensor/hdi_connection/adapter/src/hdi_connection.cpp b/services/sensor/hdi_connection/adapter/src/hdi_connection.cpp index 48b113f7..98c3d46e 100644 --- a/services/sensor/hdi_connection/adapter/src/hdi_connection.cpp +++ b/services/sensor/hdi_connection/adapter/src/hdi_connection.cpp @@ -14,14 +14,15 @@ */ #include "hdi_connection.h" -#include "sensor_interface_proxy.h" -#include "sensor_event_callback.h" -#include "sensors_errors.h" -#include "sensors_log_domain.h" #include #include #include +#include "sensor_event_callback.h" +#include "sensor_interface_proxy.h" +#include "sensors_errors.h" +#include "sensors_log_domain.h" + namespace OHOS { namespace Sensors { using namespace OHOS::HiviewDFX; @@ -172,7 +173,7 @@ int32_t HdiConnection::RegisteDataReport(ZReportDataCb cb, sptrRegister(0, eventCallback_); @@ -234,7 +235,7 @@ void HdiConnection::updateSensorBasicInfo(int32_t sensorId, int64_t samplingPeri sensorBasicInfoMap_[sensorId] = sensorBasicInfo; } -void HdiConnection::setSensorBasicInfoState(int32_t sensorId, enum SensorState state) +void HdiConnection::setSensorBasicInfoState(int32_t sensorId, SensorState state) { std::lock_guard sensorInfoLock(sensorBasicInfoMutex_); auto it = sensorBasicInfoMap_.find(sensorId); @@ -311,7 +312,7 @@ void HdiConnection::reconnect() return; } std::lock_guard sensorInfoLock(sensorBasicInfoMutex_); - for(const auto &sensorInfo : sensorBasicInfoMap_) { + for(const auto &sensorInfo: sensorBasicInfoMap_) { int32_t sensorTypeId = sensorInfo.first; ret = SetBatch(sensorTypeId, sensorInfo.second.GetSamplingPeriodNs(), sensorInfo.second.GetMaxReportDelayNs()); -- Gitee From 4d21754d62a27e7dbeeddfa67e60458d5a0f3c2f Mon Sep 17 00:00:00 2001 From: h00514358 Date: Wed, 26 Jan 2022 20:06:20 +0800 Subject: [PATCH 3/3] Signed-off-by:hellohyh001 Signed-off-by: h00514358 --- services/sensor/hdi_connection/adapter/src/hdi_connection.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/services/sensor/hdi_connection/adapter/src/hdi_connection.cpp b/services/sensor/hdi_connection/adapter/src/hdi_connection.cpp index 98c3d46e..7e892ca5 100644 --- a/services/sensor/hdi_connection/adapter/src/hdi_connection.cpp +++ b/services/sensor/hdi_connection/adapter/src/hdi_connection.cpp @@ -312,7 +312,7 @@ void HdiConnection::reconnect() return; } std::lock_guard sensorInfoLock(sensorBasicInfoMutex_); - for(const auto &sensorInfo: sensorBasicInfoMap_) { + for (const auto &sensorInfo: sensorBasicInfoMap_) { int32_t sensorTypeId = sensorInfo.first; ret = SetBatch(sensorTypeId, sensorInfo.second.GetSamplingPeriodNs(), sensorInfo.second.GetMaxReportDelayNs()); -- Gitee