From ad509ea9cabfc868b94a263853cac26fc0bf2518 Mon Sep 17 00:00:00 2001 From: maan4 Date: Wed, 2 Jul 2025 09:08:47 +0800 Subject: [PATCH] change the crash of dump Signed-off-by: maan4 --- services/src/sensor_service.cpp | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/services/src/sensor_service.cpp b/services/src/sensor_service.cpp index e751179a..e9e91b24 100644 --- a/services/src/sensor_service.cpp +++ b/services/src/sensor_service.cpp @@ -577,12 +577,16 @@ ErrCode SensorService::GetSensorList(std::vector &sensorList) ErrCode SensorService::GetSensorListByDevice(int32_t deviceId, std::vector &singleDevSensors) { CALL_LOG_ENTER; - for (const auto& sensor : sensors_) { - if (sensor.GetDeviceId() == deviceId) { - SEN_HILOGD("Sensor found: GetDeviceId: %{public}d, deviceId: %{public}d", sensor.GetDeviceId(), deviceId); - singleDevSensors.push_back(sensor); + { + std::lock_guard sensorLock(sensorsMutex_); + for (const auto& sensor : sensors_) { + if (sensor.GetDeviceId() == deviceId) { + SEN_HILOGD("Sensor found: id is %{public}d", deviceId); + singleDevSensors.push_back(sensor); + } } } + if (singleDevSensors.empty()) { std::vector sensors = GetSensorListByDevice(deviceId); int32_t sensorCount = static_cast(sensors.size()); @@ -784,6 +788,7 @@ int32_t SensorService::Dump(int32_t fd, const std::vector &args) [](const std::u16string &arg) { return Str16ToStr8(arg); }); + std::lock_guard sensorLock(sensorsMutex_); sensorDump.ParseCommand(fd, argList, sensors_, clientInfo_); return ERR_OK; } -- Gitee