From 48033acd87abc79c054aa93367398605ef78b503 Mon Sep 17 00:00:00 2001 From: li-yaoyao777 Date: Tue, 24 Sep 2024 14:58:43 +0800 Subject: [PATCH] Modified 5.0release branch view Signed-off-by: li-yaoyao777 --- .../native/include/sensor_agent_proxy.h | 2 +- frameworks/native/src/sensor_agent_proxy.cpp | 2 +- .../native/src/sensor_service_client.cpp | 2 +- services/include/sensor_service.h | 2 +- services/src/sensor_service.cpp | 4 ++-- utils/common/include/print_sensor_data.h | 17 ++++--------- utils/common/src/print_sensor_data.cpp | 24 ++++++++++++------- 7 files changed, 26 insertions(+), 27 deletions(-) diff --git a/frameworks/native/include/sensor_agent_proxy.h b/frameworks/native/include/sensor_agent_proxy.h index b5258f7d..047d9bc3 100644 --- a/frameworks/native/include/sensor_agent_proxy.h +++ b/frameworks/native/include/sensor_agent_proxy.h @@ -42,7 +42,7 @@ public: int32_t UnsubscribeSensor(int32_t sensorId, const SensorUser *user); int32_t SetMode(int32_t sensorId, const SensorUser *user, int32_t mode); int32_t SetOption(int32_t sensorId, const SensorUser *user, int32_t option); - void SetIsChannelCreated(bool isChannelCreated); + void SetChannelStatus(bool isChannelCreated); int32_t GetAllSensors(SensorInfo **sensorInfo, int32_t *count) const; int32_t SuspendSensors(int32_t pid); int32_t ResumeSensors(int32_t pid); diff --git a/frameworks/native/src/sensor_agent_proxy.cpp b/frameworks/native/src/sensor_agent_proxy.cpp index 53b1715e..4f2384bb 100644 --- a/frameworks/native/src/sensor_agent_proxy.cpp +++ b/frameworks/native/src/sensor_agent_proxy.cpp @@ -87,7 +87,7 @@ void SensorAgentProxy::HandleSensorData(SensorEvent *events, } } -void SensorAgentProxy::SetIsChannelCreated(bool isChannelCreated) +void SensorAgentProxy::SetChannelStatus(bool isChannelCreated) { CALL_LOG_ENTER; std::lock_guard chanelLock(chanelMutex_); diff --git a/frameworks/native/src/sensor_service_client.cpp b/frameworks/native/src/sensor_service_client.cpp index e9ac0131..337fab6f 100644 --- a/frameworks/native/src/sensor_service_client.cpp +++ b/frameworks/native/src/sensor_service_client.cpp @@ -286,7 +286,7 @@ void SensorServiceClient::ProcessDeathObserver(const wptr &object if (InitServiceClient() != ERR_OK) { SEN_HILOGE("InitServiceClient failed"); dataChannel_->DestroySensorDataChannel(); - SENSOR_AGENT_IMPL->SetIsChannelCreated(false); + SENSOR_AGENT_IMPL->SetChannelStatus(false); return; } if (sensorServer_ != nullptr && sensorClientStub_ != nullptr) { diff --git a/services/include/sensor_service.h b/services/include/sensor_service.h index 0e3ab6cd..97c8ae67 100644 --- a/services/include/sensor_service.h +++ b/services/include/sensor_service.h @@ -70,7 +70,7 @@ public: private: DISALLOW_COPY_AND_MOVE(SensorService); void OnAddSystemAbility(int32_t systemAbilityId, const std::string &deviceId) override; - bool CheckParameter(int32_t sensorId, int64_t samplingPeriodNs, int64_t maxReportDelayNs); + bool IsParamsValid(int32_t sensorId, int64_t samplingPeriodNs, int64_t maxReportDelayNs); class PermStateChangeCb : public Security::AccessToken::PermStateChangeCallbackCustomize { public: diff --git a/services/src/sensor_service.cpp b/services/src/sensor_service.cpp index 155c4e12..1466ed56 100644 --- a/services/src/sensor_service.cpp +++ b/services/src/sensor_service.cpp @@ -263,7 +263,7 @@ bool SensorService::CheckSensorId(int32_t sensorId) return true; } -bool SensorService::CheckParameter(int32_t sensorId, int64_t samplingPeriodNs, int64_t maxReportDelayNs) +bool SensorService::IsParamsValid(int32_t sensorId, int64_t samplingPeriodNs, int64_t maxReportDelayNs) { if ((!CheckSensorId(sensorId)) || ((samplingPeriodNs != 0L) && ((maxReportDelayNs / samplingPeriodNs) > MAX_EVENT_COUNT))) { @@ -276,7 +276,7 @@ bool SensorService::CheckParameter(int32_t sensorId, int64_t samplingPeriodNs, i ErrCode SensorService::EnableSensor(int32_t sensorId, int64_t samplingPeriodNs, int64_t maxReportDelayNs) { CALL_LOG_ENTER; - if (!CheckParameter(sensorId, samplingPeriodNs, maxReportDelayNs)) { + if (!IsParamsValid(sensorId, samplingPeriodNs, maxReportDelayNs)) { SEN_HILOGE("sensorId, samplingPeriodNs or maxReportDelayNs is invalid"); return ERR_NO_INIT; } diff --git a/utils/common/include/print_sensor_data.h b/utils/common/include/print_sensor_data.h index 86e0bfa8..abff3a80 100644 --- a/utils/common/include/print_sensor_data.h +++ b/utils/common/include/print_sensor_data.h @@ -26,6 +26,10 @@ namespace OHOS { namespace Sensors { +struct LogPrintInfo { + int32_t count { 0 }; + int64_t lastTime { 0 }; +}; class PrintSensorData : public Singleton { public: @@ -42,21 +46,8 @@ private: void PrintClientData(const SensorEvent &event); void PrintHdiData(const SensorData &sensorData); int32_t GetDataDimension(int32_t sensorId); - struct LogPrintInfo { - int32_t count { 0 }; - int64_t lastTime { 0 }; - }; std::mutex hdiLoginfoMutex_; std::mutex clientLoginfoMutex_; - LogPrintInfo info_; - std::map hdiLoginfo_ = { - {SENSOR_TYPE_ID_ACCELEROMETER, info_}, - {SENSOR_TYPE_ID_GYROSCOPE, info_}, - {SENSOR_TYPE_ID_POSTURE, info_}, - {SENSOR_TYPE_ID_AMBIENT_LIGHT, info_}, - {SENSOR_TYPE_ID_AMBIENT_LIGHT1, info_}, - {SENSOR_TYPE_ID_MAGNETIC_FIELD, info_}, - }; std::map clientLoginfo_; }; } // namespace Sensors diff --git a/utils/common/src/print_sensor_data.cpp b/utils/common/src/print_sensor_data.cpp index a6ab3df9..2a052ee1 100644 --- a/utils/common/src/print_sensor_data.cpp +++ b/utils/common/src/print_sensor_data.cpp @@ -51,17 +51,25 @@ const std::vector g_continuousSensorType = { SENSOR_TYPE_ID_GYROSCOPE, SENSOR_TYPE_ID_MAGNETIC_FIELD, }; -} +std::map g_hdiLoginfo = { + { SENSOR_TYPE_ID_ACCELEROMETER, { 0, 0 } }, + { SENSOR_TYPE_ID_GYROSCOPE, { 0, 0 } }, + { SENSOR_TYPE_ID_POSTURE, { 0, 0 } }, + { SENSOR_TYPE_ID_AMBIENT_LIGHT, { 0, 0 } }, + { SENSOR_TYPE_ID_AMBIENT_LIGHT1, { 0, 0 } }, + { SENSOR_TYPE_ID_MAGNETIC_FIELD, { 0, 0 } }, +}; +} // namespace void PrintSensorData::ControlSensorHdiPrint(const SensorData &sensorData) { + std::lock_guard hdiLoginfoLock(hdiLoginfoMutex_); auto triggerIt = std::find(g_triggerSensorType.begin(), g_triggerSensorType.end(), sensorData.sensorTypeId); if (triggerIt != g_triggerSensorType.end()) { PrintHdiData(sensorData); } - std::lock_guard hdiLoginfoLock(hdiLoginfoMutex_); - auto it = hdiLoginfo_.find(sensorData.sensorTypeId); - if (it == hdiLoginfo_.end()) { + auto it = g_hdiLoginfo.find(sensorData.sensorTypeId); + if (it == g_hdiLoginfo.end()) { return; } if (it->second.count < FIRST_PRINT_TIMES) { @@ -84,8 +92,8 @@ void PrintSensorData::PrintHdiData(const SensorData &sensorData) str += "sensorId: " + std::to_string(sensorData.sensorTypeId) + ", "; str += "timestamp: " + std::to_string(sensorData.timestamp / LOG_FORMAT_DIVIDER) + ", "; int32_t dataDim = GetDataDimension(sensorData.sensorTypeId); + CHKPV(sensorData.data); auto data = reinterpret_cast(sensorData.data); - CHKPV(data); for (int32_t i = 0; i < dataDim; ++i) { str.append(std::to_string(*data)); if (i != dataDim - 1) { @@ -122,6 +130,7 @@ int32_t PrintSensorData::GetDataDimension(int32_t sensorId) void PrintSensorData::ControlSensorClientPrint(const RecordSensorCallback callback, const SensorEvent &event) { + std::lock_guard clientLoginfoLock(clientLoginfoMutex_); auto triggerIt = std::find(g_triggerSensorType.begin(), g_triggerSensorType.end(), event.sensorTypeId); if (triggerIt != g_triggerSensorType.end()) { PrintClientData(event); @@ -131,7 +140,6 @@ void PrintSensorData::ControlSensorClientPrint(const RecordSensorCallback callba if (continuosIt == g_continuousSensorType.end()) { return; } - std::lock_guard clientLoginfoLock(clientLoginfoMutex_); auto it = clientLoginfo_.find(callback); if (it == clientLoginfo_.end()) { return; @@ -202,8 +210,8 @@ void PrintSensorData::RemovePrintUserInfo(const RecordSensorCallback callback) void PrintSensorData::ResetHdiCounter(int32_t sensorId) { std::lock_guard hdiLoginfoLock(hdiLoginfoMutex_); - auto it = hdiLoginfo_.find(sensorId); - if (it == hdiLoginfo_.end()) { + auto it = g_hdiLoginfo.find(sensorId); + if (it == g_hdiLoginfo.end()) { return; } it->second.count = 0; -- Gitee