From 93d81d5be32d42cf24369c32d73680814b4863c3 Mon Sep 17 00:00:00 2001 From: wuzhihuitmac Date: Tue, 2 Sep 2025 20:34:54 +0800 Subject: [PATCH] Add lock for sensorlist Signed-off-by: wuzhihuitmac Change-Id: I0abb8caf40d37701ff8f7ddf6ac381e079c26a5d --- frameworks/native/src/sensor_service_client.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/frameworks/native/src/sensor_service_client.cpp b/frameworks/native/src/sensor_service_client.cpp index 42b72118..b5494cc6 100644 --- a/frameworks/native/src/sensor_service_client.cpp +++ b/frameworks/native/src/sensor_service_client.cpp @@ -45,6 +45,7 @@ extern "C" { } } #endif // OHOS_BUILD_ENABLE_RUST +constexpr int32_t LOCAL_DEVICE = 1; constexpr int32_t LOADSA_TIMEOUT_MS = 10000; } // namespace @@ -292,11 +293,12 @@ std::vector SensorServiceClient::GetSensorListByDevice(int32_t deviceId) int32_t SensorServiceClient::GetLocalDeviceId(int32_t& deviceId) { CALL_LOG_ENTER; + std::lock_guard clientLock(clientMutex_); if (sensorList_.empty()) { std::vector allSensors = GetSensorList(); } for (const auto& sensor : sensorList_) { - if (sensor.GetLocation() == 1) { + if (sensor.GetLocation() == LOCAL_DEVICE) { SEN_HILOGD("local deviceId is:%{public}d", sensor.GetDeviceId()); deviceId = sensor.GetDeviceId(); return ERR_OK; -- Gitee