From 39a1588c94a63b61892cc039d66a493bc951b23e Mon Sep 17 00:00:00 2001 From: shenpeixing Date: Mon, 7 Apr 2025 19:39:30 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=A2=E6=88=B7=E7=AB=AF=E7=8E=AF=E5=A2=83?= =?UTF-8?q?=E5=85=89=E4=B8=8A=E6=8A=A5=E6=97=B6=E6=AF=8F=E5=88=86=E9=92=9F?= =?UTF-8?q?=E6=89=93=E5=8D=B0=E4=B8=80=E6=AC=A1=E4=B8=8A=E6=8A=A5=E6=AC=A1?= =?UTF-8?q?=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: shenpeixing --- .../native/include/sensor_agent_proxy.h | 2 ++ frameworks/native/src/sensor_agent_proxy.cpp | 25 ++++++++++++++++++- 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/frameworks/native/include/sensor_agent_proxy.h b/frameworks/native/include/sensor_agent_proxy.h index 58e8bd1f..707e6e81 100644 --- a/frameworks/native/include/sensor_agent_proxy.h +++ b/frameworks/native/include/sensor_agent_proxy.h @@ -55,6 +55,7 @@ private: void ClearSensorInfos() const; std::set GetSubscribeUserCallback(int32_t sensorId); bool IsSubscribeMapEmpty() const; + void PrintAmbientLightReportCount(); static std::recursive_mutex subscribeMutex_; static std::mutex chanelMutex_; OHOS::sptr dataChannel_ = nullptr; @@ -63,6 +64,7 @@ private: int64_t reportInterval_ = -1; std::map> subscribeMap_; std::map> unsubscribeMap_; + std::thread ambientLightCountThread_; static std::mutex createChannelMutex_; }; diff --git a/frameworks/native/src/sensor_agent_proxy.cpp b/frameworks/native/src/sensor_agent_proxy.cpp index 2d023b4d..2e5f25ce 100644 --- a/frameworks/native/src/sensor_agent_proxy.cpp +++ b/frameworks/native/src/sensor_agent_proxy.cpp @@ -30,6 +30,9 @@ SensorInfo *sensorInfos_ = nullptr; std::mutex sensorActiveInfoMutex_; SensorActiveInfo *sensorActiveInfos_ = nullptr; int32_t sensorInfoCount_ = 0; +std::mutex ambientLightCallBackCountMutex_; +int32_t ambientLightCallBackCount_ = 0; +bool stop_ = false; } // namespace #define SEN_CLIENT SensorServiceClient::GetInstance() @@ -38,13 +41,22 @@ std::mutex SensorAgentProxy::chanelMutex_; std::mutex SensorAgentProxy::createChannelMutex_; SensorAgentProxy::SensorAgentProxy() - : dataChannel_(new (std::nothrow) SensorDataChannel()) + : dataChannel_(new (std::nothrow) SensorDataChannel()), ambientLightCountThread_([this]() { + while (!stop_) { + this->PrintAmbientLightReportCount(); + std::this_thread::sleep_for(std::chrono::minutes(1)); + } + }) {} SensorAgentProxy::~SensorAgentProxy() { CALL_LOG_ENTER; ClearSensorInfos(); + if (ambientLightCountThread_.joinable()) { + stop_ = true; + ambientLightCountThread_.join(); + } } std::set SensorAgentProxy::GetSubscribeUserCallback(int32_t sensorId) @@ -82,6 +94,10 @@ void SensorAgentProxy::HandleSensorData(SensorEvent *events, if (eventStream.sensorTypeId == SENSOR_TYPE_ID_HALL_EXT) { PrintSensorData::GetInstance().ControlSensorClientPrint(callback, eventStream); } + if (eventStream.sensorTypeId == SENSOR_TYPE_ID_AMBIENT_LIGHT) { + std::lock_guard ambientLightCallBackCountLock(ambientLightCallBackCountMutex_); + ambientLightCallBackCount_++; + } callback(&eventStream); PrintSensorData::GetInstance().ControlSensorClientPrint(callback, eventStream); } @@ -297,6 +313,13 @@ bool SensorAgentProxy::IsSubscribeMapEmpty() const return subscribeMap_.empty(); } +void SensorAgentProxy::PrintAmbientLightReportCount() +{ + std::lock_guard ambientLightCallBackCountLock(ambientLightCallBackCountMutex_); + SEN_HILOGI("Number of reports per minuts for ambient light, count:%{public}d", ambientLightCallBackCount_); + ambientLightCallBackCount_ = 0; +} + int32_t SensorAgentProxy::UnsubscribeSensor(int32_t sensorId, const SensorUser *user) { SEN_HILOGI("In, sensorId:%{public}d", sensorId); -- Gitee