From 1a5673ae7d48476bf0d339131db369347bfa4bac Mon Sep 17 00:00:00 2001 From: lixiangpeng5 Date: Tue, 10 Jun 2025 09:41:57 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A4=9A=E4=BC=A0=E6=84=9F=E5=99=A8updataSenso?= =?UTF-8?q?rList=E5=87=BD=E6=95=B0=E5=90=8D=E4=BF=AE=E6=94=B9=E5=8F=8Aloca?= =?UTF-8?q?tion=E8=B5=8B=E5=80=BC=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: lixiangpeng5 --- frameworks/js/napi/include/sensor_js.h | 4 ++-- frameworks/js/napi/src/sensor_js.cpp | 8 ++++---- frameworks/native/include/sensor_agent_proxy.h | 4 ++-- frameworks/native/src/sensor_agent_proxy.cpp | 15 +++++++-------- .../interface/include/sensor_hdi_connection.h | 4 ++-- .../interface/src/sensor_hdi_connection.cpp | 6 +++--- services/include/sensor_data_processer.h | 2 +- services/src/sensor_data_processer.cpp | 2 +- services/src/sensor_service.cpp | 4 ++-- 9 files changed, 24 insertions(+), 25 deletions(-) diff --git a/frameworks/js/napi/include/sensor_js.h b/frameworks/js/napi/include/sensor_js.h index ac9839ea..1a2f4d52 100644 --- a/frameworks/js/napi/include/sensor_js.h +++ b/frameworks/js/napi/include/sensor_js.h @@ -26,9 +26,9 @@ namespace OHOS { namespace Sensors { -int32_t UnsubscribeSensor(SensorDescription sensorDesc); +int32_t UnsubscribeSensor(const SensorDescription &sensorDesc); void DataCallbackImpl(SensorEvent *event); -int32_t SubscribeSensor(SensorDescription sensorDesc, int64_t interval, RecordSensorCallback callback); +int32_t SubscribeSensor(const SensorDescription &sensorDesc, int64_t interval, RecordSensorCallback callback); napi_value Subscribe(napi_env env, napi_callback_info info, int32_t sensorTypeId, CallbackDataType type); napi_value Unsubscribe(napi_env env, napi_callback_info info, int32_t sensorTypeId); napi_value GetBodyState(napi_env env, napi_callback_info info); diff --git a/frameworks/js/napi/src/sensor_js.cpp b/frameworks/js/napi/src/sensor_js.cpp index c3446676..e8945a0f 100644 --- a/frameworks/js/napi/src/sensor_js.cpp +++ b/frameworks/js/napi/src/sensor_js.cpp @@ -212,7 +212,7 @@ const SensorUser user = { .plugCallback = PlugDataCallbackImpl }; -int32_t UnsubscribeSensor(SensorDescription sensorDesc) +int32_t UnsubscribeSensor(const SensorDescription &sensorDesc) { CALL_LOG_ENTER; int32_t ret = DeactivateSensorEnhanced({sensorDesc.deviceId, sensorDesc.sensorType, sensorDesc.sensorId, @@ -225,7 +225,7 @@ int32_t UnsubscribeSensor(SensorDescription sensorDesc) sensorDesc.location}, &user); } -int32_t SubscribeSensor(SensorDescription sensorDesc, int64_t interval, RecordSensorCallback callback) +int32_t SubscribeSensor(const SensorDescription &sensorDesc, int64_t interval, RecordSensorCallback callback) { CALL_LOG_ENTER; int32_t ret = SubscribeSensorEnhanced({sensorDesc.deviceId, sensorDesc.sensorType, sensorDesc.sensorId, @@ -334,7 +334,7 @@ static bool GetDeviceId(napi_env env, napi_value value, int32_t &deviceId) return false; } if (!GetNativeInt32(env, napi_deviceId, deviceId)) { - SEN_HILOGE("GetNativeInt64 failed"); + SEN_HILOGE("GetNativeInt32 failed"); return false; } return true; @@ -348,7 +348,7 @@ static bool GetSensorId(napi_env env, napi_value value, int32_t &sensorId) return false; } if (!GetNativeInt32(env, napi_sensorId, sensorId)) { - SEN_HILOGE("GetNativeInt64 failed"); + SEN_HILOGE("GetNativeInt32 failed"); return false; } return true; diff --git a/frameworks/native/include/sensor_agent_proxy.h b/frameworks/native/include/sensor_agent_proxy.h index ab4cf477..dd6198cc 100644 --- a/frameworks/native/include/sensor_agent_proxy.h +++ b/frameworks/native/include/sensor_agent_proxy.h @@ -66,8 +66,8 @@ private: int32_t UpdateSensorInfo(SensorInfo* sensorInfo, const Sensor& sensor); int32_t UpdateSensorInfosCache(const std::vector& deviceSensorList); bool FindSensorInfo(int32_t deviceId, int32_t sensorIndex, int32_t sensorTypeId); - void UpdataSensorStatusEvent(SensorStatusEvent &event, SensorPlugData info); - bool UpdataSensorInfo(SensorPlugData info); + void UpdateSensorStatusEvent(SensorStatusEvent &event, SensorPlugData info); + bool UpdateSensorInfo(SensorPlugData info); void EraseCacheSensorInfos(SensorPlugData info); static std::recursive_mutex subscribeMutex_; static std::recursive_mutex subscribePlugMutex_; diff --git a/frameworks/native/src/sensor_agent_proxy.cpp b/frameworks/native/src/sensor_agent_proxy.cpp index e89c504d..cadeabbc 100644 --- a/frameworks/native/src/sensor_agent_proxy.cpp +++ b/frameworks/native/src/sensor_agent_proxy.cpp @@ -785,25 +785,24 @@ int32_t SensorAgentProxy::UnsubscribeSensorPlug(const SensorUser *user) return OHOS::Sensors::SUCCESS; } -void SensorAgentProxy::UpdataSensorStatusEvent(SensorStatusEvent &event, SensorPlugData info) +void SensorAgentProxy::UpdateSensorStatusEvent(SensorStatusEvent &event, SensorPlugData info) { event.sensorType = info.sensorTypeId; event.sensorId = info.sensorId; + event.isSensorOnline = false; if (info.status == SENSOR_ONLINE) { event.isSensorOnline = true; - } else { - event.isSensorOnline = false; } event.deviceId = info.deviceId; event.deviceName = info.deviceName; + event.location = false; if (info.location == IS_LOCAL_DEVICE) { event.location = true; } - event.location = false; event.timestamp = info.timestamp; } -bool SensorAgentProxy::UpdataSensorInfo(SensorPlugData info) +bool SensorAgentProxy::UpdateSensorInfo(SensorPlugData info) { CALL_LOG_ENTER; if (info.status == SENSOR_ONLINE) { @@ -811,7 +810,7 @@ bool SensorAgentProxy::UpdataSensorInfo(SensorPlugData info) int32_t count = 0; int32_t ret = GetDeviceSensors(info.deviceId, &sensorInfos, &count); if (ret != ERR_OK) { - SEN_HILOGE("UpdataSensorInfo failed"); + SEN_HILOGE("UpdateSensorInfo failed"); return false; } free(sensorInfos); @@ -846,11 +845,11 @@ bool SensorAgentProxy::HandlePlugSensorData(const SensorPlugData &info) __attrib { CALL_LOG_ENTER; std::lock_guard subscribePlugLock(subscribePlugMutex_); - if (!UpdataSensorInfo(info)) { + if (!UpdateSensorInfo(info)) { return false; } SensorStatusEvent event; - UpdataSensorStatusEvent(event, info); + UpdateSensorStatusEvent(event, info); for (const auto &it : subscribeSet_) { if (it->plugCallback != nullptr) { SEN_HILOGD("plug callback is run"); diff --git a/services/hdi_connection/interface/include/sensor_hdi_connection.h b/services/hdi_connection/interface/include/sensor_hdi_connection.h index b5b67968..8c023e7a 100644 --- a/services/hdi_connection/interface/include/sensor_hdi_connection.h +++ b/services/hdi_connection/interface/include/sensor_hdi_connection.h @@ -38,7 +38,7 @@ public: int32_t DestroyHdiConnection() override; int32_t RegSensorPlugCallback(DevicePlugCallback cb) override; DevicePlugCallback GetSensorPlugCb() override; - bool PlugEraseSensorData(SensorPlugInfo info); + bool PlugEraseSensorData(const SensorPlugInfo &info); private: DISALLOW_COPY_AND_MOVE(SensorHdiConnection); @@ -56,7 +56,7 @@ private: Sensor GenerateSarSensor(); Sensor GenerateHeadPostureSensor(); Sensor GenerateProximitySensor(); - void UpdataSensorList(std::vector &singleDevSensors); + void UpdateSensorList(std::vector &singleDevSensors); std::atomic_bool hdiConnectionStatus_ = false; }; } // namespace Sensors diff --git a/services/hdi_connection/interface/src/sensor_hdi_connection.cpp b/services/hdi_connection/interface/src/sensor_hdi_connection.cpp index b98ffb93..e130c5e0 100644 --- a/services/hdi_connection/interface/src/sensor_hdi_connection.cpp +++ b/services/hdi_connection/interface/src/sensor_hdi_connection.cpp @@ -443,7 +443,7 @@ int32_t SensorHdiConnection::DestroyHdiConnection() return ret; } -void SensorHdiConnection::UpdataSensorList(std::vector &singleDevSensors) +void SensorHdiConnection::UpdateSensorList(std::vector &singleDevSensors) { CALL_LOG_ENTER; for (const auto& newSensor : singleDevSensors) { @@ -476,7 +476,7 @@ int32_t SensorHdiConnection::GetSensorListByDevice(int32_t deviceId, std::vector SEN_HILOGW("Get sensor list is empty"); return ERR_OK; } - UpdataSensorList(singleDevSensors); + UpdateSensorList(singleDevSensors); #ifdef BUILD_VARIANT_ENG if (singleDevSensors[0].GetLocation() == IS_LOCAL_DEVICE) { if (!hdiConnectionStatus_) { @@ -537,7 +537,7 @@ DevicePlugCallback SensorHdiConnection::GetSensorPlugCb() return NULL; } -bool SensorHdiConnection::PlugEraseSensorData(SensorPlugInfo info) +bool SensorHdiConnection::PlugEraseSensorData(const SensorPlugInfo &info) { CALL_LOG_ENTER; std::lock_guard sensorLock(sensorMutex_); diff --git a/services/include/sensor_data_processer.h b/services/include/sensor_data_processer.h index f15d3b6b..b56beefd 100755 --- a/services/include/sensor_data_processer.h +++ b/services/include/sensor_data_processer.h @@ -30,7 +30,7 @@ public: int32_t SendEvents(sptr &channel, SensorData &data); static int DataThread(sptr dataProcesser, sptr dataCallback); int32_t CacheSensorEvent(const SensorData &data, sptr &channel); - void UpdataSensorMap(const std::unordered_map &sensorMap); + void UpdateSensorMap(const std::unordered_map &sensorMap); private: DISALLOW_COPY_AND_MOVE(SensorDataProcesser); diff --git a/services/src/sensor_data_processer.cpp b/services/src/sensor_data_processer.cpp index f4e1fbae..3fe764e6 100644 --- a/services/src/sensor_data_processer.cpp +++ b/services/src/sensor_data_processer.cpp @@ -48,7 +48,7 @@ SensorDataProcesser::~SensorDataProcesser() sensorMap_.clear(); } -void SensorDataProcesser::UpdataSensorMap(const std::unordered_map &sensorMap) +void SensorDataProcesser::UpdateSensorMap(const std::unordered_map &sensorMap) { sensorMap_.clear(); sensorMap_.insert(sensorMap.begin(), sensorMap.end()); diff --git a/services/src/sensor_service.cpp b/services/src/sensor_service.cpp index 0c9ebd77..2f4273cb 100644 --- a/services/src/sensor_service.cpp +++ b/services/src/sensor_service.cpp @@ -612,7 +612,7 @@ std::vector SensorService::GetSensorListByDevice(int32_t deviceId) sensorMap_.insert(std::pair( {it.GetDeviceId(), it.GetSensorTypeId(), it.GetSensorId(), it.GetLocation()}, it)); if (sensorDataProcesser_ != nullptr) { - sensorDataProcesser_->UpdataSensorMap(sensorMap_); + sensorDataProcesser_->UpdateSensorMap(sensorMap_); } } } @@ -997,7 +997,7 @@ void SensorService::ReportPlugEventCallback(const SensorPlugInfo info) GetSensorListByDevice(info.deviceSensorInfo.deviceId); } } else { - if (sensorHdiConnection_.PlugEraseSensorData(info)) { + if (!sensorHdiConnection_.PlugEraseSensorData(info)) { SEN_HILOGW("sensorHdiConnection Cache update failure"); } std::lock_guard sensorMapLock(sensorMapMutex_); -- Gitee