diff --git a/frameworks/js/napi/include/sensor_js.h b/frameworks/js/napi/include/sensor_js.h index ac9839ea45090390e9b1583df2b650330c0cae47..1a2f4d522227307c8f6cd4f6aa52aa50dbbb0e7e 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 c34466769a915456f25a34284aea75c07bc0325d..e8945a0fd8684548229bce006425626e7cfb2134 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 ab4cf4773b8fec19bd935fe31888d169a517fd41..dd6198ccc7aa17384a29b945de7d123c462dd019 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 e89c504df8771d6e407449f948fc27a6323706aa..cadeabbcc79cc0558f83b7a8579af5a9f5418f73 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 b5b6796886d920037a66df0a421c357c8f3c1705..8c023e7a36eef1a66d78ea0f687e19d6ba2df96e 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 b98ffb93ac0b2ffd8eb9a3f485e412b2528ec75d..e130c5e09df84c394c52e88a3b0d4e6f40dc7850 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 f15d3b6b4136cd7f1b355890343118012ebe0a55..b56beefddb90b00275f699e8c07fdc36a64b1965 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 f4e1fbae73755b956db771d43fc71723748b7af6..3fe764e60fd3afdad46edfd362d9f06491de158f 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 0c9ebd77186ac9e5fe222d84c8edcd11fb299ce0..2f4273cb39950a9ccdb26a3085263808ae62c0c3 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_);