diff --git a/frameworks/native/include/sensor_agent_proxy.h b/frameworks/native/include/sensor_agent_proxy.h index b5258f7da594da4b4559e2c6aa942647383d1033..047d9bc38592c341566af642f1dfba6cc1ccc2ac 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 53b1715ea2632ac5a6b72f362f0080e0f5f30daf..4f2384bbcb3ff7d70195901b1189d44e6ce0881b 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 e9ac013186cce9b18d279d092563d3e72d4035f3..337fab6f8ce108646f5771e1d5d6f73733dd6776 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 0e3ab6cda4424e4a12511a8f34ccaf68d13650c4..97c8ae67b67f8bc6d2b2683ab24a64983756c728 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 155c4e12bd621651f005c31d604c9d683b10ac77..1466ed56a94381d81c6c25ed0f4a8ccc4645b5c8 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 86e0bfa886b5577b92f67b5d133402f1c82bbba7..abff3a80d4abf2eea1864fab160e6b9867b48052 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 a6ab3df94ceabc4df6d5309635c777e6c135d924..2a052ee1c344eaec9b2e625ca74592f4ba2d0913 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;