From 703fd8f0d8e8421746134fdc1ba666dfc3c4a905 Mon Sep 17 00:00:00 2001 From: hui1975 Date: Mon, 25 Sep 2023 13:13:01 +0000 Subject: [PATCH 1/2] =?UTF-8?q?=E6=A3=80=E8=A7=86=E6=84=8F=E8=A7=81?= =?UTF-8?q?=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: hui1975 Change-Id: Ie83c3d6f742e880c995862d265ee3dd54e010c43 --- .../adapter/src/sensor_event_callback.cpp | 2 +- .../hardware/src/hdi_service_impl.cpp | 3 +-- services/sensor/include/sensor_power_policy.h | 2 +- services/sensor/src/client_info.cpp | 13 +++++++++---- services/sensor/src/sensor_power_policy.cpp | 12 ++++++++++-- 5 files changed, 22 insertions(+), 10 deletions(-) diff --git a/services/sensor/hdi_connection/adapter/src/sensor_event_callback.cpp b/services/sensor/hdi_connection/adapter/src/sensor_event_callback.cpp index a6f6bee4..793c5eb0 100644 --- a/services/sensor/hdi_connection/adapter/src/sensor_event_callback.cpp +++ b/services/sensor/hdi_connection/adapter/src/sensor_event_callback.cpp @@ -45,7 +45,7 @@ int32_t SensorEventCallback::OnDataEvent(const HdfSensorEvents &event) .dataLen = event.dataLen }; CHKPR(sensorData.data, ERR_NO_INIT); - for (int32_t i = 0; i < static_cast(dataSize); i++) { + for (int32_t i = 0; i < dataSize; i++) { sensorData.data[i] = event.data[i]; } std::unique_lock lk(ISensorHdiConnection::dataMutex_); diff --git a/services/sensor/hdi_connection/hardware/src/hdi_service_impl.cpp b/services/sensor/hdi_connection/hardware/src/hdi_service_impl.cpp index 2d3763f5..9f6307fb 100644 --- a/services/sensor/hdi_connection/hardware/src/hdi_service_impl.cpp +++ b/services/sensor/hdi_connection/hardware/src/hdi_service_impl.cpp @@ -29,7 +29,6 @@ using namespace OHOS::HiviewDFX; namespace { constexpr HiLogLabel LABEL = { LOG_CORE, SENSOR_LOG_DOMAIN, "HdiServiceImpl" }; constexpr int64_t SAMPLING_INTERVAL_NS = 200000000; -constexpr int32_t CONVERT_MULTIPLES = 1000; constexpr float TARGET_SUM = 9.8F * 9.8F; constexpr float MAX_RANGE = 9999.0F; std::vector g_sensorInfos = { @@ -136,7 +135,7 @@ void HdiServiceImpl::DataReportThread() CALL_LOG_ENTER; while (true) { GenerateEvent(); - usleep(samplingInterval_ / CONVERT_MULTIPLES); + std::this_thread::sleep_for(std::chrono::nanoseconds(samplingInterval_)); for (const auto &it : callbacks_) { if (it == nullptr) { SEN_HILOGW("RecordSensorCallback is null"); diff --git a/services/sensor/include/sensor_power_policy.h b/services/sensor/include/sensor_power_policy.h index 17ff16a8..68281738 100644 --- a/services/sensor/include/sensor_power_policy.h +++ b/services/sensor/include/sensor_power_policy.h @@ -43,7 +43,7 @@ public: private: bool CheckFreezingSensor(int32_t sensorId); - bool Suspend(int32_t pid, std::vector &sensorIdList, + bool Suspend(int32_t pid, const std::vector &sensorIdList, std::unordered_map &SensorInfoMap); bool Resume(int32_t pid, int32_t sensorId, int64_t samplingPeriodNs, int64_t maxReportDelayNs); ErrCode RestoreSensorInfo(int32_t pid, int32_t sensorId, int64_t samplingPeriodNs, int64_t maxReportDelayNs); diff --git a/services/sensor/src/client_info.cpp b/services/sensor/src/client_info.cpp index 8daeb11d..17bf5c7a 100644 --- a/services/sensor/src/client_info.cpp +++ b/services/sensor/src/client_info.cpp @@ -19,8 +19,8 @@ #include "permission_util.h" #include "securec.h" -#include "sensor_manager.h" #include "sensor_errors.h" +#include "sensor_manager.h" #ifdef HDF_DRIVERS_INTERFACE_SENSOR #include "sensor_hdi_connection.h" #endif // HDF_DRIVERS_INTERFACE_SENSOR @@ -59,7 +59,7 @@ bool ClientInfo::GetSensorState(int32_t sensorId) return false; } for (const auto &pidIt : it->second) { - if (pidIt.second.GetSensorState() == true) { + if (pidIt.second.GetSensorState()) { return true; } } @@ -115,6 +115,7 @@ bool ClientInfo::OnlyCurPidSensorEnabled(int32_t sensorId, int32_t pid) continue; } if (pidIt.first != pid) { + SEN_HILOGE("Current sensor is also used by other pid"); return false; } ret = true; @@ -154,7 +155,7 @@ void ClientInfo::DestroyAppThreadInfo(int32_t pid) std::lock_guard uidLock(uidMutex_); auto appThreadInfoItr = appThreadInfoMap_.find(pid); if (appThreadInfoItr == appThreadInfoMap_.end()) { - SEN_HILOGD("uid not exist, no need to destroy it"); + SEN_HILOGD("pid not exist, no need to destroy it"); return; } appThreadInfoMap_.erase(appThreadInfoItr); @@ -269,7 +270,7 @@ bool ClientInfo::UpdateSensorChannel(int32_t pid, const sptr channelLock(channelMutex_); @@ -552,6 +553,10 @@ AppThreadInfo ClientInfo::GetAppInfoByChannel(const sptr { CALL_LOG_ENTER; AppThreadInfo appThreadInfo; + if (channel == nullptr) { + SEN_HILOGE("channel is nullptr"); + return appThreadInfo; + } { std::lock_guard channelLock(channelMutex_); for (auto channelIt = channelMap_.begin(); channelIt != channelMap_.end(); channelIt++) { diff --git a/services/sensor/src/sensor_power_policy.cpp b/services/sensor/src/sensor_power_policy.cpp index f4195524..488c458a 100644 --- a/services/sensor/src/sensor_power_policy.cpp +++ b/services/sensor/src/sensor_power_policy.cpp @@ -71,7 +71,7 @@ ErrCode SensorPowerPolicy::SuspendSensors(int32_t pid) return ERR_OK; } -bool SensorPowerPolicy::Suspend(int32_t pid, std::vector &sensorIdList, +bool SensorPowerPolicy::Suspend(int32_t pid, const std::vector &sensorIdList, std::unordered_map &sensorInfoMap) { CALL_LOG_ENTER; @@ -226,7 +226,11 @@ std::vector SensorPowerPolicy::GetActiveInfoList(int32_t pid) sensorInfo.GetMaxReportDelayNs()); activeInfoList.push_back(activeInfo); } - SEN_HILOGI("Get active info list success, pid:%{public}d", pid); + if (activeInfoList.size() > 0) { + SEN_HILOGI("Get active info list success, pid:%{public}d", pid); + } else { + SEN_HILOGW("activeInfoList is empty"); + } return activeInfoList; } @@ -234,6 +238,10 @@ void SensorPowerPolicy::ReportActiveInfo(const ActiveInfo &activeInfo, const std::vector &sessionList) { CALL_LOG_ENTER; + if (activeInfo.GetPid() < 0 || activeInfo.GetSensorId() < 0) { + SEN_HILOGE(Invalid activeInfo); + return; + } NetPacket pkt(MessageId::ACTIVE_INFO); pkt << activeInfo.GetPid() << activeInfo.GetSensorId() << activeInfo.GetSamplingPeriodNs() << activeInfo.GetMaxReportDelayNs(); -- Gitee From 194ac3f376e97de94dfb7457ae01e499ebcb0321 Mon Sep 17 00:00:00 2001 From: hui1975 Date: Tue, 26 Sep 2023 01:48:22 +0000 Subject: [PATCH 2/2] update Signed-off-by: hui1975 Change-Id: I95c633adc02a6f5adb3b4db004c2384e5ef480a8 --- services/sensor/src/sensor_power_policy.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/services/sensor/src/sensor_power_policy.cpp b/services/sensor/src/sensor_power_policy.cpp index 488c458a..21d45239 100644 --- a/services/sensor/src/sensor_power_policy.cpp +++ b/services/sensor/src/sensor_power_policy.cpp @@ -229,7 +229,7 @@ std::vector SensorPowerPolicy::GetActiveInfoList(int32_t pid) if (activeInfoList.size() > 0) { SEN_HILOGI("Get active info list success, pid:%{public}d", pid); } else { - SEN_HILOGW("activeInfoList is empty"); + SEN_HILOGW("activeInfoList is empty"); } return activeInfoList; } @@ -239,7 +239,7 @@ void SensorPowerPolicy::ReportActiveInfo(const ActiveInfo &activeInfo, { CALL_LOG_ENTER; if (activeInfo.GetPid() < 0 || activeInfo.GetSensorId() < 0) { - SEN_HILOGE(Invalid activeInfo); + SEN_HILOGE("Invalid activeInfo"); return; } NetPacket pkt(MessageId::ACTIVE_INFO); -- Gitee