diff --git a/frameworks/native/include/sensor_agent_proxy.h b/frameworks/native/include/sensor_agent_proxy.h index 76ad11fc4fa7787c07ebd32f94ad952150f3b717..f04d667862ce476683df7b84b09056b8776588f3 100644 --- a/frameworks/native/include/sensor_agent_proxy.h +++ b/frameworks/native/include/sensor_agent_proxy.h @@ -42,6 +42,7 @@ public: int32_t UnsubscribeSensor(int32_t sensorId, const SensorUser *user); int32_t SetMode(int32_t sensorId, const SensorUser *user, int32_t mode); int32_t SetOption(int32_t sensorId, const SensorUser *user, int32_t option); + void SetIsChannelCreated(bool isChannelCreated); int32_t GetAllSensors(SensorInfo **sensorInfo, int32_t *count) const; int32_t SuspendSensors(int32_t pid); int32_t ResumeSensors(int32_t pid); diff --git a/frameworks/native/include/sensor_service_client.h b/frameworks/native/include/sensor_service_client.h index a616d42a9a69413f1104e74f8100d6dea19354ad..9657a1b38dcbcbe889adee9ea7100be446f9dd2a 100755 --- a/frameworks/native/include/sensor_service_client.h +++ b/frameworks/native/include/sensor_service_client.h @@ -60,6 +60,7 @@ private: void UpdateSensorInfoMap(int32_t sensorId, int64_t samplingPeriod, int64_t maxReportDelay); void DeleteSensorInfoItem(int32_t sensorId); int32_t CreateSocketChannel(); + void ReenableSensor(); std::mutex clientMutex_; sptr serviceDeathObserver_ = nullptr; sptr sensorServer_ = nullptr; diff --git a/frameworks/native/src/sensor_agent_proxy.cpp b/frameworks/native/src/sensor_agent_proxy.cpp index 267b3255b0f5d70794ec1fb8e31825fce771f8c0..2e545091a3e42e4be1d367196f165e98a9d278c1 100644 --- a/frameworks/native/src/sensor_agent_proxy.cpp +++ b/frameworks/native/src/sensor_agent_proxy.cpp @@ -82,6 +82,13 @@ void SensorAgentProxy::HandleSensorData(SensorEvent *events, } } +void SensorAgentProxy::SetIsChannelCreated(bool isChannelCreated) +{ + CALL_LOG_ENTER; + std::lock_guard chanelLock(chanelMutex_); + isChannelCreated_ = isChannelCreated; +} + int32_t SensorAgentProxy::CreateSensorDataChannel() { CALL_LOG_ENTER; diff --git a/frameworks/native/src/sensor_service_client.cpp b/frameworks/native/src/sensor_service_client.cpp index 4afdbe6c3c090c3b95026b389cb1f0a24b9aa86a..89fe1b451f8dd6b707d17591eb1acd2eef8826de 100644 --- a/frameworks/native/src/sensor_service_client.cpp +++ b/frameworks/native/src/sensor_service_client.cpp @@ -26,6 +26,7 @@ #endif // HIVIEWDFX_HISYSEVENT_ENABLE #include "hitrace_meter.h" #include "ipc_skeleton.h" +#include "sensor_agent_proxy.h" #include "sensor_errors.h" #include "sensor_service_proxy.h" #include "system_ability_definition.h" @@ -222,6 +223,23 @@ int32_t SensorServiceClient::DestroyDataChannel() return ret; } +void SensorServiceClient::ReenableSensor() +{ + CALL_LOG_ENTER; + std::lock_guard mapLock(mapMutex_); + for (const auto &it : sensorInfoMap_) { + if (sensorServer_ != nullptr) { + sensorServer_->EnableSensor(it.first, it.second.GetSamplingPeriodNs(), it.second.GetMaxReportDelayNs()); + } + } + if (!isConnected_) { + SEN_HILOGD("Previous socket channel status is false, not need retry creat socket channel"); + return; + } + Disconnect(); + CreateSocketChannel(); +} + void SensorServiceClient::ProcessDeathObserver(const wptr &object) { CALL_LOG_ENTER; @@ -250,6 +268,7 @@ void SensorServiceClient::ProcessDeathObserver(const wptr &object if (InitServiceClient() != ERR_OK) { SEN_HILOGE("InitServiceClient failed"); dataChannel_->DestroySensorDataChannel(); + SENSOR_AGENT_IMPL->SetIsChannelCreated(false); return; } if (sensorServer_ != nullptr && sensorClientStub_ != nullptr) { @@ -260,18 +279,7 @@ void SensorServiceClient::ProcessDeathObserver(const wptr &object } } } - std::lock_guard mapLock(mapMutex_); - for (const auto &it : sensorInfoMap_) { - if (sensorServer_ != nullptr) { - sensorServer_->EnableSensor(it.first, it.second.GetSamplingPeriodNs(), it.second.GetMaxReportDelayNs()); - } - } - if (!isConnected_) { - SEN_HILOGD("Previous socket channel status is false, not need retry creat socket channel"); - return; - } - Disconnect(); - CreateSocketChannel(); + ReenableSensor(); } void SensorServiceClient::UpdateSensorInfoMap(int32_t sensorId, int64_t samplingPeriod, int64_t maxReportDelay)