From 33c37b8d91a03da24c3f6f02cdd594b548a13fe9 Mon Sep 17 00:00:00 2001 From: li-yaoyao777 Date: Mon, 28 Mar 2022 11:04:42 +0800 Subject: [PATCH 1/8] =?UTF-8?q?=E4=BF=AE=E6=94=B9sensor=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: li-yaoyao777 --- .../native/sensor/src/sensor_agent_proxy.cpp | 16 ++++++++-------- services/sensor/src/sensor_service.cpp | 4 ++++ 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/frameworks/native/sensor/src/sensor_agent_proxy.cpp b/frameworks/native/sensor/src/sensor_agent_proxy.cpp index 37691a6f..288a9be5 100644 --- a/frameworks/native/sensor/src/sensor_agent_proxy.cpp +++ b/frameworks/native/sensor/src/sensor_agent_proxy.cpp @@ -93,7 +93,7 @@ const SensorAgentProxy *SensorAgentProxy::GetSensorsObj() void SensorAgentProxy::HandleSensorData(struct SensorEvent *events, int32_t num, void *data) { if (events == nullptr || num <= 0) { - SEN_HILOGE("events is null or num is invalid"); + SEN_HILOGE("events is nullptr or num is invalid"); return; } struct SensorEvent eventStream; @@ -161,7 +161,7 @@ int32_t SensorAgentProxy::DestroySensorDataChannel() const int32_t SensorAgentProxy::ActivateSensor(int32_t sensorId, const SensorUser *user) const { if (user == nullptr || sensorId < 0 || user->callback == nullptr) { - HiLog::Error(LABEL, "%{public}s user is null or sensorId is invalid", __func__); + HiLog::Error(LABEL, "%{public}s user is nullptr or sensorId is invalid", __func__); return OHOS::Sensors::ERROR; } if (g_samplingInterval < 0 || g_reportInterval < 0) { @@ -189,7 +189,7 @@ int32_t SensorAgentProxy::ActivateSensor(int32_t sensorId, const SensorUser *use int32_t SensorAgentProxy::DeactivateSensor(int32_t sensorId, const SensorUser *user) const { if (user == nullptr || sensorId < 0 || user->callback == nullptr) { - HiLog::Error(LABEL, "%{public}s user is null or sensorId is invalid", __func__); + HiLog::Error(LABEL, "%{public}s user is nullptr or sensorId is invalid", __func__); return OHOS::Sensors::ERROR; } std::lock_guard subscribeLock(subscribeMutex_); @@ -212,7 +212,7 @@ int32_t SensorAgentProxy::SetBatch(int32_t sensorId, const SensorUser *user, int int64_t reportInterval) const { if (user == nullptr || sensorId < 0) { - HiLog::Error(LABEL, "%{public}s user is null or sensorId is invalid", __func__); + HiLog::Error(LABEL, "%{public}s user is nullptr or sensorId is invalid", __func__); return OHOS::Sensors::ERROR; } if (samplingInterval < 0 || reportInterval < 0) { @@ -250,7 +250,7 @@ int32_t SensorAgentProxy::UnsubscribeSensor(int32_t sensorId, const SensorUser * { HiLog::Info(LABEL, "%{public}s in, sensorId: %{public}d", __func__, sensorId); if (user == nullptr || sensorId < 0 || user->callback == nullptr) { - HiLog::Error(LABEL, "%{public}s user is null or sensorId is invalid", __func__); + HiLog::Error(LABEL, "%{public}s user is nullptr or sensorId is invalid", __func__); return OHOS::Sensors::ERROR; } std::lock_guard subscribeLock(subscribeMutex_); @@ -272,7 +272,7 @@ int32_t SensorAgentProxy::UnsubscribeSensor(int32_t sensorId, const SensorUser * int32_t SensorAgentProxy::SetMode(int32_t sensorId, const SensorUser *user, int32_t mode) const { if (user == nullptr || sensorId < 0 || user->callback == nullptr) { - HiLog::Error(LABEL, "%{public}s user is null or sensorId is invalid", __func__); + HiLog::Error(LABEL, "%{public}s user is nullptr or sensorId is invalid", __func__); return OHOS::Sensors::ERROR; } std::lock_guard subscribeLock(subscribeMutex_); @@ -286,7 +286,7 @@ int32_t SensorAgentProxy::SetMode(int32_t sensorId, const SensorUser *user, int3 int32_t SensorAgentProxy::SetOption(int32_t sensorId, const SensorUser *user, int32_t option) const { if (user == nullptr || sensorId < 0 || user->callback == nullptr) { - HiLog::Error(LABEL, "%{public}s user is null or sensorId is invalid", __func__); + HiLog::Error(LABEL, "%{public}s user is nullptr or sensorId is invalid", __func__); return OHOS::Sensors::ERROR; } std::lock_guard subscribeLock(subscribeMutex_); @@ -300,7 +300,7 @@ int32_t SensorAgentProxy::SetOption(int32_t sensorId, const SensorUser *user, in int32_t SensorAgentProxy::GetAllSensors(SensorInfo **sensorInfo, int32_t *count) const { if (sensorInfo == nullptr || count == nullptr) { - HiLog::Error(LABEL, "%{public}s sensorInfo or count is null", __func__); + HiLog::Error(LABEL, "%{public}s sensorInfo or count is nullptr", __func__); return OHOS::Sensors::ERROR; } SensorServiceClient &client = SensorServiceClient::GetInstance(); diff --git a/services/sensor/src/sensor_service.cpp b/services/sensor/src/sensor_service.cpp index e59d414c..c5b2e16e 100644 --- a/services/sensor/src/sensor_service.cpp +++ b/services/sensor/src/sensor_service.cpp @@ -132,6 +132,10 @@ bool SensorService::InitSensorList() std::lock_guard sensorMapLock(sensorMapMutex_); for (const auto &it : sensors_) { sensorMap_.insert(std::make_pair(it.GetSensorId(), it)); + if (state_ == SensorServiceState::STATE_STOPPED) { + HiLog::Warn(LABEL, "%{public}s already stopped", __func__); + return(0); + } } } return true; -- Gitee From 45f5a41440eca8d0d88c8d31aa9f2b4b89be7b73 Mon Sep 17 00:00:00 2001 From: li-yaoyao777 Date: Mon, 28 Mar 2022 12:08:06 +0800 Subject: [PATCH 2/8] =?UTF-8?q?=E4=BF=AE=E6=94=B9sensor=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: li-yaoyao777 --- .../native/sensor/src/sensor_agent_proxy.cpp | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/frameworks/native/sensor/src/sensor_agent_proxy.cpp b/frameworks/native/sensor/src/sensor_agent_proxy.cpp index 288a9be5..37691a6f 100644 --- a/frameworks/native/sensor/src/sensor_agent_proxy.cpp +++ b/frameworks/native/sensor/src/sensor_agent_proxy.cpp @@ -93,7 +93,7 @@ const SensorAgentProxy *SensorAgentProxy::GetSensorsObj() void SensorAgentProxy::HandleSensorData(struct SensorEvent *events, int32_t num, void *data) { if (events == nullptr || num <= 0) { - SEN_HILOGE("events is nullptr or num is invalid"); + SEN_HILOGE("events is null or num is invalid"); return; } struct SensorEvent eventStream; @@ -161,7 +161,7 @@ int32_t SensorAgentProxy::DestroySensorDataChannel() const int32_t SensorAgentProxy::ActivateSensor(int32_t sensorId, const SensorUser *user) const { if (user == nullptr || sensorId < 0 || user->callback == nullptr) { - HiLog::Error(LABEL, "%{public}s user is nullptr or sensorId is invalid", __func__); + HiLog::Error(LABEL, "%{public}s user is null or sensorId is invalid", __func__); return OHOS::Sensors::ERROR; } if (g_samplingInterval < 0 || g_reportInterval < 0) { @@ -189,7 +189,7 @@ int32_t SensorAgentProxy::ActivateSensor(int32_t sensorId, const SensorUser *use int32_t SensorAgentProxy::DeactivateSensor(int32_t sensorId, const SensorUser *user) const { if (user == nullptr || sensorId < 0 || user->callback == nullptr) { - HiLog::Error(LABEL, "%{public}s user is nullptr or sensorId is invalid", __func__); + HiLog::Error(LABEL, "%{public}s user is null or sensorId is invalid", __func__); return OHOS::Sensors::ERROR; } std::lock_guard subscribeLock(subscribeMutex_); @@ -212,7 +212,7 @@ int32_t SensorAgentProxy::SetBatch(int32_t sensorId, const SensorUser *user, int int64_t reportInterval) const { if (user == nullptr || sensorId < 0) { - HiLog::Error(LABEL, "%{public}s user is nullptr or sensorId is invalid", __func__); + HiLog::Error(LABEL, "%{public}s user is null or sensorId is invalid", __func__); return OHOS::Sensors::ERROR; } if (samplingInterval < 0 || reportInterval < 0) { @@ -250,7 +250,7 @@ int32_t SensorAgentProxy::UnsubscribeSensor(int32_t sensorId, const SensorUser * { HiLog::Info(LABEL, "%{public}s in, sensorId: %{public}d", __func__, sensorId); if (user == nullptr || sensorId < 0 || user->callback == nullptr) { - HiLog::Error(LABEL, "%{public}s user is nullptr or sensorId is invalid", __func__); + HiLog::Error(LABEL, "%{public}s user is null or sensorId is invalid", __func__); return OHOS::Sensors::ERROR; } std::lock_guard subscribeLock(subscribeMutex_); @@ -272,7 +272,7 @@ int32_t SensorAgentProxy::UnsubscribeSensor(int32_t sensorId, const SensorUser * int32_t SensorAgentProxy::SetMode(int32_t sensorId, const SensorUser *user, int32_t mode) const { if (user == nullptr || sensorId < 0 || user->callback == nullptr) { - HiLog::Error(LABEL, "%{public}s user is nullptr or sensorId is invalid", __func__); + HiLog::Error(LABEL, "%{public}s user is null or sensorId is invalid", __func__); return OHOS::Sensors::ERROR; } std::lock_guard subscribeLock(subscribeMutex_); @@ -286,7 +286,7 @@ int32_t SensorAgentProxy::SetMode(int32_t sensorId, const SensorUser *user, int3 int32_t SensorAgentProxy::SetOption(int32_t sensorId, const SensorUser *user, int32_t option) const { if (user == nullptr || sensorId < 0 || user->callback == nullptr) { - HiLog::Error(LABEL, "%{public}s user is nullptr or sensorId is invalid", __func__); + HiLog::Error(LABEL, "%{public}s user is null or sensorId is invalid", __func__); return OHOS::Sensors::ERROR; } std::lock_guard subscribeLock(subscribeMutex_); @@ -300,7 +300,7 @@ int32_t SensorAgentProxy::SetOption(int32_t sensorId, const SensorUser *user, in int32_t SensorAgentProxy::GetAllSensors(SensorInfo **sensorInfo, int32_t *count) const { if (sensorInfo == nullptr || count == nullptr) { - HiLog::Error(LABEL, "%{public}s sensorInfo or count is nullptr", __func__); + HiLog::Error(LABEL, "%{public}s sensorInfo or count is null", __func__); return OHOS::Sensors::ERROR; } SensorServiceClient &client = SensorServiceClient::GetInstance(); -- Gitee From f91c965fa83828a8cb5a459fc8b89bed76c8e66c Mon Sep 17 00:00:00 2001 From: li-yaoyao777 Date: Mon, 28 Mar 2022 14:50:34 +0800 Subject: [PATCH 3/8] =?UTF-8?q?=E4=BF=AE=E6=94=B9sensor=E4=BB=A3=E7=A0=81?= =?UTF-8?q?=E5=91=8A=E8=AD=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: li-yaoyao777 --- services/sensor/src/sensor_service.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/services/sensor/src/sensor_service.cpp b/services/sensor/src/sensor_service.cpp index c5b2e16e..8d5f649e 100644 --- a/services/sensor/src/sensor_service.cpp +++ b/services/sensor/src/sensor_service.cpp @@ -132,9 +132,9 @@ bool SensorService::InitSensorList() std::lock_guard sensorMapLock(sensorMapMutex_); for (const auto &it : sensors_) { sensorMap_.insert(std::make_pair(it.GetSensorId(), it)); - if (state_ == SensorServiceState::STATE_STOPPED) { - HiLog::Warn(LABEL, "%{public}s already stopped", __func__); - return(0); + if (sensorMap_.insert(std::make_pair(it.GetSensorId(), it)).second){ + HiLog::Warn(LABEL, "%{public}s sensorMap_ Insert failed", __func__); + return false; } } } -- Gitee From 7484760cbc8bdc533e5e9c3b7211fde92314dbae Mon Sep 17 00:00:00 2001 From: li-yaoyao777 Date: Mon, 28 Mar 2022 19:17:58 +0800 Subject: [PATCH 4/8] =?UTF-8?q?=E4=BF=AE=E6=94=B9sensor=E4=BB=A3=E7=A0=81?= =?UTF-8?q?=E5=91=8A=E8=AD=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: li-yaoyao777 --- frameworks/native/sensor/src/sensor_agent_proxy.cpp | 4 ++++ services/sensor/src/sensor_service.cpp | 3 +-- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/frameworks/native/sensor/src/sensor_agent_proxy.cpp b/frameworks/native/sensor/src/sensor_agent_proxy.cpp index 37691a6f..0262a258 100644 --- a/frameworks/native/sensor/src/sensor_agent_proxy.cpp +++ b/frameworks/native/sensor/src/sensor_agent_proxy.cpp @@ -104,6 +104,10 @@ void SensorAgentProxy::HandleSensorData(struct SensorEvent *events, int32_t num, SEN_HILOGE("sensorTypeId not in g_subscribeMap"); return; } + if (g_subscribeMap[eventStream.sensorTypeId] == nullptr) { + SEN_HILOGE("sensorTypeId in g_subscribeMap is nullptr"); + return; + } g_subscribeMap[eventStream.sensorTypeId]->callback(&eventStream); } } diff --git a/services/sensor/src/sensor_service.cpp b/services/sensor/src/sensor_service.cpp index 8d5f649e..bf0cc9b5 100644 --- a/services/sensor/src/sensor_service.cpp +++ b/services/sensor/src/sensor_service.cpp @@ -131,8 +131,7 @@ bool SensorService::InitSensorList() { std::lock_guard sensorMapLock(sensorMapMutex_); for (const auto &it : sensors_) { - sensorMap_.insert(std::make_pair(it.GetSensorId(), it)); - if (sensorMap_.insert(std::make_pair(it.GetSensorId(), it)).second){ + if (!(sensorMap_.insert(std::make_pair(it.GetSensorId(), it)).second)) { HiLog::Warn(LABEL, "%{public}s sensorMap_ Insert failed", __func__); return false; } -- Gitee From ed6f2d82d3781895111bef0462ce5f15e67c5735 Mon Sep 17 00:00:00 2001 From: li-yaoyao777 Date: Mon, 28 Mar 2022 19:41:54 +0800 Subject: [PATCH 5/8] =?UTF-8?q?=E4=BF=AE=E6=94=B9sensor=E4=BB=A3=E7=A0=81?= =?UTF-8?q?=E5=91=8A=E8=AD=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: li-yaoyao777 --- frameworks/native/sensor/src/sensor_agent_proxy.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frameworks/native/sensor/src/sensor_agent_proxy.cpp b/frameworks/native/sensor/src/sensor_agent_proxy.cpp index 0262a258..3e63ce6a 100644 --- a/frameworks/native/sensor/src/sensor_agent_proxy.cpp +++ b/frameworks/native/sensor/src/sensor_agent_proxy.cpp @@ -105,7 +105,7 @@ void SensorAgentProxy::HandleSensorData(struct SensorEvent *events, int32_t num, return; } if (g_subscribeMap[eventStream.sensorTypeId] == nullptr) { - SEN_HILOGE("sensorTypeId in g_subscribeMap is nullptr"); + SEN_HILOGE("sensor user is null"); return; } g_subscribeMap[eventStream.sensorTypeId]->callback(&eventStream); -- Gitee From c0b6c9dfe197030246867f90e9f320643e8c47a7 Mon Sep 17 00:00:00 2001 From: li-yaoyao777 Date: Mon, 28 Mar 2022 19:46:28 +0800 Subject: [PATCH 6/8] =?UTF-8?q?=E4=BF=AE=E6=94=B9sensor=E4=BB=A3=E7=A0=81?= =?UTF-8?q?=E5=91=8A=E8=AD=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: li-yaoyao777 --- frameworks/native/sensor/src/sensor_agent_proxy.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frameworks/native/sensor/src/sensor_agent_proxy.cpp b/frameworks/native/sensor/src/sensor_agent_proxy.cpp index 3e63ce6a..a8764cc5 100644 --- a/frameworks/native/sensor/src/sensor_agent_proxy.cpp +++ b/frameworks/native/sensor/src/sensor_agent_proxy.cpp @@ -105,7 +105,7 @@ void SensorAgentProxy::HandleSensorData(struct SensorEvent *events, int32_t num, return; } if (g_subscribeMap[eventStream.sensorTypeId] == nullptr) { - SEN_HILOGE("sensor user is null"); + SEN_HILOGE("sensor user is null"); return; } g_subscribeMap[eventStream.sensorTypeId]->callback(&eventStream); -- Gitee From ac3bb877d2912c5117d5b8c32a7f21f80713a69d Mon Sep 17 00:00:00 2001 From: li-yaoyao777 Date: Mon, 28 Mar 2022 19:54:14 +0800 Subject: [PATCH 7/8] =?UTF-8?q?=E4=BF=AE=E6=94=B9sensor=E4=BB=A3=E7=A0=81?= =?UTF-8?q?=E5=91=8A=E8=AD=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: li-yaoyao777 --- frameworks/native/sensor/src/sensor_agent_proxy.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frameworks/native/sensor/src/sensor_agent_proxy.cpp b/frameworks/native/sensor/src/sensor_agent_proxy.cpp index a8764cc5..a86d66f3 100644 --- a/frameworks/native/sensor/src/sensor_agent_proxy.cpp +++ b/frameworks/native/sensor/src/sensor_agent_proxy.cpp @@ -105,7 +105,7 @@ void SensorAgentProxy::HandleSensorData(struct SensorEvent *events, int32_t num, return; } if (g_subscribeMap[eventStream.sensorTypeId] == nullptr) { - SEN_HILOGE("sensor user is null"); + SEN_HILOGE("sensor user is null"); return; } g_subscribeMap[eventStream.sensorTypeId]->callback(&eventStream); -- Gitee From eec6d5dd441136d6800f95a9fd2040a6191505d8 Mon Sep 17 00:00:00 2001 From: li-yaoyao777 Date: Mon, 28 Mar 2022 19:57:26 +0800 Subject: [PATCH 8/8] =?UTF-8?q?=E4=BF=AE=E6=94=B9sensor=E4=BB=A3=E7=A0=81?= =?UTF-8?q?=E5=91=8A=E8=AD=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: li-yaoyao777 --- frameworks/native/sensor/src/sensor_agent_proxy.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frameworks/native/sensor/src/sensor_agent_proxy.cpp b/frameworks/native/sensor/src/sensor_agent_proxy.cpp index a86d66f3..5f941182 100644 --- a/frameworks/native/sensor/src/sensor_agent_proxy.cpp +++ b/frameworks/native/sensor/src/sensor_agent_proxy.cpp @@ -106,7 +106,7 @@ void SensorAgentProxy::HandleSensorData(struct SensorEvent *events, int32_t num, } if (g_subscribeMap[eventStream.sensorTypeId] == nullptr) { SEN_HILOGE("sensor user is null"); - return; + return; } g_subscribeMap[eventStream.sensorTypeId]->callback(&eventStream); } -- Gitee