From 638095d42e90c11ba0cdc8360a6299626b107d4e Mon Sep 17 00:00:00 2001 From: li-yaoyao777 Date: Tue, 31 Dec 2024 10:21:03 +0800 Subject: [PATCH] Modified branch difference Signed-off-by: li-yaoyao777 --- frameworks/native/src/sensor_agent_proxy.cpp | 2 +- .../adapter/src/compatible_connection.cpp | 5 +++-- .../adapter/src/sensor_event_callback.cpp | 1 + .../interface/include/i_sensor_hdi_connection.h | 7 ++++--- .../interface/src/sensor_hdi_connection.cpp | 3 ++- services/src/client_info.cpp | 2 -- services/src/sensor_data_processer.cpp | 15 ++++++++++++--- services/src/sensor_manager.cpp | 8 ++++---- services/src/sensor_service.cpp | 1 + 9 files changed, 28 insertions(+), 16 deletions(-) diff --git a/frameworks/native/src/sensor_agent_proxy.cpp b/frameworks/native/src/sensor_agent_proxy.cpp index c2a5aa78..cf7a43f1 100644 --- a/frameworks/native/src/sensor_agent_proxy.cpp +++ b/frameworks/native/src/sensor_agent_proxy.cpp @@ -258,7 +258,7 @@ int32_t SensorAgentProxy::SubscribeSensor(int32_t sensorId, const SensorUser *us std::lock_guard subscribeLock(subscribeMutex_); auto status = subscribeMap_[sensorId].insert(user); if (!status.second) { - SEN_HILOGE("User has been unsubscribed"); + SEN_HILOGE("User has been subscribed"); } if (PrintSensorData::GetInstance().IsContinuousType(sensorId)) { PrintSensorData::GetInstance().SavePrintUserInfo(user->callback); diff --git a/services/hdi_connection/adapter/src/compatible_connection.cpp b/services/hdi_connection/adapter/src/compatible_connection.cpp index f7096eaa..8f9d813c 100644 --- a/services/hdi_connection/adapter/src/compatible_connection.cpp +++ b/services/hdi_connection/adapter/src/compatible_connection.cpp @@ -137,6 +137,7 @@ void CompatibleConnection::ReportSensorDataCallback(SensorEvent *event) CHKPV(reportDataCb_); std::unique_lock lk(ISensorHdiConnection::dataMutex_); (void)(reportDataCallback_->*reportDataCb_)(&sensorData, reportDataCallback_); + ISensorHdiConnection::dataReady_.store(true); ISensorHdiConnection::dataCondition_.notify_one(); } @@ -162,5 +163,5 @@ int32_t CompatibleConnection::DestroyHdiConnection() } return ERR_OK; } -} // namespace Sensors -} // namespace OHOS \ No newline at end of file +} // namespace Sensors +} // namespace OHOS \ No newline at end of file diff --git a/services/hdi_connection/adapter/src/sensor_event_callback.cpp b/services/hdi_connection/adapter/src/sensor_event_callback.cpp index 70b96e50..c8e6af4a 100644 --- a/services/hdi_connection/adapter/src/sensor_event_callback.cpp +++ b/services/hdi_connection/adapter/src/sensor_event_callback.cpp @@ -86,6 +86,7 @@ int32_t SensorEventCallback::OnDataEvent(const HdfSensorEvents &event) if (sensorData.sensorTypeId == SENSOR_TYPE_ID_HALL_EXT) { SEN_HILOGI("dataCondition notify one sensorId: %{public}d", sensorData.sensorTypeId); } + ISensorHdiConnection::dataReady_.store(true); ISensorHdiConnection::dataCondition_.notify_one(); return ERR_OK; } diff --git a/services/hdi_connection/interface/include/i_sensor_hdi_connection.h b/services/hdi_connection/interface/include/i_sensor_hdi_connection.h index 7e3a7b5e..ff9cff64 100644 --- a/services/hdi_connection/interface/include/i_sensor_hdi_connection.h +++ b/services/hdi_connection/interface/include/i_sensor_hdi_connection.h @@ -37,10 +37,11 @@ public: virtual int32_t DestroyHdiConnection() = 0; static std::mutex dataMutex_; static std::condition_variable dataCondition_; + static std::atomic dataReady_; private: DISALLOW_COPY_AND_MOVE(ISensorHdiConnection); }; -} // namespace Sensors -} // namespace OHOS -#endif // I_SENSOR_HDI_CONNECTION_H \ No newline at end of file +} // namespace Sensors +} // namespace OHOS +#endif // I_SENSOR_HDI_CONNECTION_H \ No newline at end of file diff --git a/services/hdi_connection/interface/src/sensor_hdi_connection.cpp b/services/hdi_connection/interface/src/sensor_hdi_connection.cpp index 0f755ac9..7234e920 100644 --- a/services/hdi_connection/interface/src/sensor_hdi_connection.cpp +++ b/services/hdi_connection/interface/src/sensor_hdi_connection.cpp @@ -26,6 +26,7 @@ #define LOG_TAG "SensorHdiConnection" std::mutex OHOS::Sensors::ISensorHdiConnection::dataMutex_; std::condition_variable OHOS::Sensors::ISensorHdiConnection::dataCondition_; +std::atomic OHOS::Sensors::ISensorHdiConnection::dataReady_ = false; namespace OHOS { namespace Sensors { @@ -53,7 +54,7 @@ int32_t SensorHdiConnection::ConnectHdi() int32_t ret = ConnectHdiService(); if (ret != ERR_OK) { SEN_HILOGE("Connect hdi service failed, try to connect compatible connection, ret:%{public}d", ret); -#ifdef BUILD_VARIANT_ENG +#ifdef BUILD_VARIANT_ENG iSensorHdiConnection_ = std::make_unique(); ret = ConnectHdiService(); if (ret != ERR_OK) { diff --git a/services/src/client_info.cpp b/services/src/client_info.cpp index e9640068..f7fc39d3 100644 --- a/services/src/client_info.cpp +++ b/services/src/client_info.cpp @@ -278,7 +278,6 @@ void ClientInfo::RemoveSubscriber(int32_t sensorId, uint32_t pid) bool ClientInfo::UpdateSensorChannel(int32_t pid, const sptr &channel) { SEN_HILOGI("In, pid:%{public}d", pid); - CALL_LOG_ENTER; CHKPR(channel, false); if (pid <= INVALID_PID) { SEN_HILOGE("pid is invalid"); @@ -303,7 +302,6 @@ bool ClientInfo::UpdateSensorChannel(int32_t pid, const sptr &>(channel->GetDataCacheBuf()); int32_t sensorId = data.sensorTypeId; + if (sensorId == SENSOR_TYPE_ID_HALL_EXT) { + PrintSensorData::GetInstance().PrintSensorDataLog("CacheSensorEvent", data); + } auto cacheEvent = cacheBuf.find(sensorId); if (cacheEvent != cacheBuf.end()) { // Try to send the last failed value, if it still fails, replace the previous cache directly @@ -261,11 +264,16 @@ int32_t SensorDataProcesser::CacheSensorEvent(const SensorData &data, sptr> channelList = clientInfo_.GetSensorChannel(sensorId); for (auto &channel : channelList) { - if (channel->GetSensorStatus()) { - SendEvents(channel, eventsBuf.circularBuf[eventsBuf.readPos]); + if (!channel->GetSensorStatus()) { + SEN_HILOGW("Sensor status is not active"); + continue; } + SendEvents(channel, eventsBuf.circularBuf[eventsBuf.readPos]); } } @@ -273,7 +281,8 @@ int32_t SensorDataProcesser::ProcessEvents(sptr dataCallback { CHKPR(dataCallback, INVALID_POINTER); std::unique_lock lk(ISensorHdiConnection::dataMutex_); - ISensorHdiConnection::dataCondition_.wait(lk); + ISensorHdiConnection::dataCondition_.wait(lk, [this] { return ISensorHdiConnection::dataReady_.load(); }); + ISensorHdiConnection::dataReady_.store(false); auto &eventsBuf = dataCallback->GetEventData(); if (eventsBuf.eventNum <= 0) { SEN_HILOGE("Data cannot be empty"); diff --git a/services/src/sensor_manager.cpp b/services/src/sensor_manager.cpp index b245fa5e..cf079eba 100644 --- a/services/src/sensor_manager.cpp +++ b/services/src/sensor_manager.cpp @@ -148,13 +148,13 @@ SensorBasicInfo SensorManager::GetSensorInfo(int32_t sensorId, int64_t samplingP sensorInfo.SetSamplingPeriodNs(curSamplingPeriodNs); sensorInfo.SetMaxReportDelayNs(curReportDelayNs); sensorInfo.SetSensorState(true); - SEN_HILOGI("In, sensorId:%{public}d", sensorId); + SEN_HILOGI("Done, sensorId:%{public}d", sensorId); return sensorInfo; } bool SensorManager::IsOtherClientUsingSensor(int32_t sensorId, int32_t clientPid) { - CALL_LOG_ENTER; + SEN_HILOGI("In, sensorId:%{public}d, clientPid:%{public}d", sensorId, clientPid); if (clientInfo_.OnlyCurPidSensorEnabled(sensorId, clientPid)) { SEN_HILOGD("Only current client using this sensor"); return false; @@ -217,5 +217,5 @@ void SensorManager::GetPackageName(AccessTokenID tokenId, std::string &packageNa } } } -} // namespace Sensors -} // namespace OHOS +} // namespace Sensors +} // namespace OHOS diff --git a/services/src/sensor_service.cpp b/services/src/sensor_service.cpp index 24cc9331..408dc84a 100644 --- a/services/src/sensor_service.cpp +++ b/services/src/sensor_service.cpp @@ -296,6 +296,7 @@ ErrCode SensorService::EnableSensor(int32_t sensorId, int64_t samplingPeriodNs, ReportActiveInfo(sensorId, pid); } PrintSensorData::GetInstance().ResetHdiCounter(sensorId); + SEN_HILOGI("Done, sensorId:%{public}d", sensorId); return ERR_OK; } auto ret = SaveSubscriber(sensorId, samplingPeriodNs, maxReportDelayNs); -- Gitee