diff --git a/frameworks/native/src/sensor_service_client.cpp b/frameworks/native/src/sensor_service_client.cpp index 42b7211845c1e3c22e4d022732f8845c928da761..f746f32d3d6019d7298dc75584f40a1ebd34ad43 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,14 @@ std::vector SensorServiceClient::GetSensorListByDevice(int32_t deviceId) int32_t SensorServiceClient::GetLocalDeviceId(int32_t& deviceId) { CALL_LOG_ENTER; - if (sensorList_.empty()) { - std::vector allSensors = GetSensorList(); + int32_t ret = InitServiceClient(); + if (ret != ERR_OK) { + SEN_HILOGE("InitServiceClient failed, ret:%{public}d", ret); + return ret; } + std::lock_guard clientLock(clientMutex_); 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;