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 a6f6bee40766970367d9ddad03360df3bdcfb5a1..793c5eb0c79c0856181cc62f00b5cae24aa56745 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 2d3763f50d16adc960c4f13137fe521a506469e5..9f6307fbf97602e2bcea845d7d5a7c12aaca4b02 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 17ff16a88ce4cc1c46bfe740a04ce69cb55e46df..68281738da23c42b91926c6efed910208bead323 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 8daeb11dfd030bffce74f6e1d542942bac70efea..17bf5c7acf30c2e9d3d11f2e79aa5a108bec8280 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 f4195524fcbf510983ec250e4c90e65dc601a915..21d45239ed5ca679e94579842795f0e5f3786470 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();