diff --git a/frameworks/native/src/sensor_service_client.cpp b/frameworks/native/src/sensor_service_client.cpp index 42b7211845c1e3c22e4d022732f8845c928da761..b5494cc60bc13f850ee061b62806d64c215962db 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;