diff --git a/frameworks/native/src/sensor_service_client.cpp b/frameworks/native/src/sensor_service_client.cpp index dc52fa12b250d0fdb138ad1eef8c505aadb250a1..c1af0df23476eada13bbbcc0601c15994c6f6985 100644 --- a/frameworks/native/src/sensor_service_client.cpp +++ b/frameworks/native/src/sensor_service_client.cpp @@ -75,6 +75,10 @@ int32_t SensorServiceClient::InitServiceClient() std::lock_guard clientLock(clientMutex_); if (sensorServer_ != nullptr) { SEN_HILOGD("Already init"); + if (sensorList_.empty()) { + sensorList_ = sensorServer_->GetSensorList(); + SEN_HILOGW("sensorList is %{public}s", sensorList_.empty() ? "empty" : "not empty"); + } return ERR_OK; } if (sensorClientStub_ == nullptr) { @@ -95,6 +99,9 @@ int32_t SensorServiceClient::InitServiceClient() CHKPR(remoteObject, SENSOR_NATIVE_GET_SERVICE_ERR); remoteObject->AddDeathRecipient(serviceDeathObserver_); sensorList_ = sensorServer_->GetSensorList(); + if (sensorList_.empty()) { + SEN_HILOGW("sensorList_ is empty when connecting to the service for the first time"); + } return ERR_OK; } SEN_HILOGW("Get service failed, retry:%{public}d", retry); diff --git a/services/hdi_connection/interface/src/sensor_hdi_connection.cpp b/services/hdi_connection/interface/src/sensor_hdi_connection.cpp index 3990a43b30c91c933c4b52275a2bb7abfeb94a2b..2b2d137fd02035a5b6568149604d9957979ef9e2 100644 --- a/services/hdi_connection/interface/src/sensor_hdi_connection.cpp +++ b/services/hdi_connection/interface/src/sensor_hdi_connection.cpp @@ -203,6 +203,11 @@ int32_t SensorHdiConnection::GetSensorList(std::vector &sensorList) { CHKPR(iSensorHdiConnection_, GET_SENSOR_LIST_ERR); std::lock_guard sensorLock(sensorMutex_); + if (sensorList_.empty()) { + if (iSensorHdiConnection_->GetSensorList(sensorList_) != ERR_OK) { + SEN_HILOGW("Get sensor list failed"); + } + } sensorList.assign(sensorList_.begin(), sensorList_.end()); #ifdef BUILD_VARIANT_ENG if (!hdiConnectionStatus_) {