diff --git a/sensor.gni b/sensor.gni index 4bf58c1eb560a503fb67c076a1dae089c4763877..ad3494ff3a62c68d9525b63b4de9a51e1b9ce60c 100644 --- a/sensor.gni +++ b/sensor.gni @@ -34,3 +34,10 @@ if (!defined(global_parts_info) || } else { hdf_drivers_interface_sensor = false } + +if (build_variant == "eng") { + sensor_default_defines += [ "BUILD_VARIANT_ENG" ] + sensor_build_eng = true +} else { + sensor_build_eng = false +} diff --git a/services/BUILD.gn b/services/BUILD.gn index 6513d2d9964e938c2a95df4027b1901184136624..1db4f457d971df4e4d9910b22f3365d43e41b110 100644 --- a/services/BUILD.gn +++ b/services/BUILD.gn @@ -59,7 +59,6 @@ ohos_shared_library("libsensor_service") { if (hdf_drivers_interface_sensor) { sources += [ - "hdi_connection/adapter/src/compatible_connection.cpp", "hdi_connection/adapter/src/hdi_connection.cpp", "hdi_connection/adapter/src/sensor_event_callback.cpp", "hdi_connection/hardware/src/hdi_service_impl.cpp", @@ -73,6 +72,10 @@ ohos_shared_library("libsensor_service") { "$SUBSYSTEM_DIR/services/hdi_connection/hardware/include", ] + if (sensor_build_eng) { + sources += [ "hdi_connection/adapter/src/compatible_connection.cpp" ] + } + external_deps += [ "drivers_interface_sensor:libsensor_proxy_1.1" ] } @@ -127,7 +130,6 @@ ohos_shared_library("libsensor_service_static") { if (hdf_drivers_interface_sensor) { sources += [ - "hdi_connection/adapter/src/compatible_connection.cpp", "hdi_connection/adapter/src/hdi_connection.cpp", "hdi_connection/adapter/src/sensor_event_callback.cpp", "hdi_connection/hardware/src/hdi_service_impl.cpp", @@ -141,6 +143,10 @@ ohos_shared_library("libsensor_service_static") { "$SUBSYSTEM_DIR/services/hdi_connection/hardware/include", ] + if (sensor_build_eng) { + sources += [ "hdi_connection/adapter/src/compatible_connection.cpp" ] + } + external_deps += [ "drivers_interface_sensor:libsensor_proxy_1.1" ] } diff --git a/services/hdi_connection/adapter/src/compatible_connection.cpp b/services/hdi_connection/adapter/src/compatible_connection.cpp index 8a2ef420c83792bcc1801d1b85acb70b1406be02..88a5833e823c2403a450ebc78a899e9342ac7558 100644 --- a/services/hdi_connection/adapter/src/compatible_connection.cpp +++ b/services/hdi_connection/adapter/src/compatible_connection.cpp @@ -12,7 +12,9 @@ * See the License for the specific language governing permissions and * limitations under the License. */ +#ifdef BUILD_VARIANT_ENG #include "compatible_connection.h" +#endif #include @@ -138,7 +140,9 @@ void CompatibleConnection::ReportSensorDataCallback(SensorEvent *event) } CHKPV(reportDataCallback_); CHKPV(reportDataCb_); +#ifdef BUILD_VARIANT_ENG std::unique_lock lk(ISensorHdiConnection::dataMutex_); +#endif (void)(reportDataCallback_->*reportDataCb_)(&sensorData, reportDataCallback_); ISensorHdiConnection::dataCondition_.notify_one(); } diff --git a/services/hdi_connection/adapter/src/sensor_event_callback.cpp b/services/hdi_connection/adapter/src/sensor_event_callback.cpp index a67a23c118718ec162f9a84af88dd173f0e0f725..4e57fa3af5d49894f6aeb88b48a12b28f899ab14 100644 --- a/services/hdi_connection/adapter/src/sensor_event_callback.cpp +++ b/services/hdi_connection/adapter/src/sensor_event_callback.cpp @@ -53,9 +53,11 @@ int32_t SensorEventCallback::OnDataEvent(const HdfSensorEvents &event) for (int32_t i = 0; i < dataSize; i++) { sensorData.data[i] = event.data[i]; } +#ifdef BUILD_VARIANT_ENG std::unique_lock lk(ISensorHdiConnection::dataMutex_); (void)(reportDataCallback_->*(reportDataCb_))(&sensorData, reportDataCallback_); ISensorHdiConnection::dataCondition_.notify_one(); +#endif return ERR_OK; } } // namespace Sensors diff --git a/services/hdi_connection/interface/src/sensor_hdi_connection.cpp b/services/hdi_connection/interface/src/sensor_hdi_connection.cpp index d4337a9cafef430a848047867e4a298d8769a2bc..6741dfc170cffa0f55b46bb2d33790c4b5701d9b 100644 --- a/services/hdi_connection/interface/src/sensor_hdi_connection.cpp +++ b/services/hdi_connection/interface/src/sensor_hdi_connection.cpp @@ -14,7 +14,11 @@ */ #include "sensor_hdi_connection.h" +#ifdef BUILD_VARIANT_ENG #include "compatible_connection.h" +#endif + +#include "sensor_agent_type.h" #include "hdi_connection.h" #include "hitrace_meter.h" #include "sensor_errors.h" @@ -43,23 +47,29 @@ int32_t SensorHdiConnection::ConnectHdi() int32_t ret = ConnectHdiService(); if (ret != ERR_OK) { SEN_HILOGE("Connect hdi service failed, try to connect compatible connection, ret:%{public}d", ret); +#ifdef BUILD_VARIANT_ENG iSensorHdiConnection_ = std::make_unique(); ret = ConnectHdiService(); if (ret != ERR_OK) { SEN_HILOGE("Connect compatible connection failed, ret:%{public}d", ret); return ret; } +#endif + SEN_HILOGE("Compatible connection have been blocked"); hdiConnectionStatus_ = false; } else { hdiConnectionStatus_ = true; } if (hdiConnectionStatus_ && !FindAllInSensorSet(g_supportMockSensors)) { SEN_HILOGD("SensorList not contain all mock sensors, connect mock sensors compatible connection"); +#ifdef BUILD_VARIANT_ENG ret = ConnectCompatibleHdi(); if (ret != ERR_OK) { SEN_HILOGE("Connect mock sensors compatible connection failed, ret:%{public}d", ret); } return ret; +#endif + SEN_HILOGE("Compatible connection have been blocked"); } return ERR_OK; } @@ -83,6 +93,7 @@ int32_t SensorHdiConnection::ConnectHdiService() return ERR_OK; } +#ifdef BUILD_VARIANT_ENG int32_t SensorHdiConnection::ConnectCompatibleHdi() { if (iSensorCompatibleHdiConnection_ == nullptr) { @@ -95,6 +106,7 @@ int32_t SensorHdiConnection::ConnectCompatibleHdi() } return ERR_OK; } +#endif bool SensorHdiConnection::FindAllInSensorSet(const std::unordered_set &sensors) { @@ -197,6 +209,7 @@ int32_t SensorHdiConnection::EnableSensor(int32_t sensorId) StartTrace(HITRACE_TAG_SENSORS, "EnableSensor"); int32_t ret = ENABLE_SENSOR_ERR; if (FindOneInMockSet(sensorId)) { +#ifdef BUILD_VARIANT_ENG CHKPR(iSensorCompatibleHdiConnection_, ENABLE_SENSOR_ERR); ret = iSensorCompatibleHdiConnection_->EnableSensor(sensorId); FinishTrace(HITRACE_TAG_SENSORS); @@ -205,6 +218,8 @@ int32_t SensorHdiConnection::EnableSensor(int32_t sensorId) return ENABLE_SENSOR_ERR; } return ret; +#endif + SEN_HILOGE("Compatible connection have been blocked"); } CHKPR(iSensorHdiConnection_, ENABLE_SENSOR_ERR); ret = iSensorHdiConnection_->EnableSensor(sensorId); @@ -221,6 +236,7 @@ int32_t SensorHdiConnection::DisableSensor(int32_t sensorId) StartTrace(HITRACE_TAG_SENSORS, "DisableSensor"); int32_t ret = DISABLE_SENSOR_ERR; if (FindOneInMockSet(sensorId)) { +#ifdef BUILD_VARIANT_ENG CHKPR(iSensorCompatibleHdiConnection_, DISABLE_SENSOR_ERR); ret = iSensorCompatibleHdiConnection_->DisableSensor(sensorId); FinishTrace(HITRACE_TAG_SENSORS); @@ -229,6 +245,8 @@ int32_t SensorHdiConnection::DisableSensor(int32_t sensorId) return DISABLE_SENSOR_ERR; } return ret; +#endif + SEN_HILOGE("Compatible connection have been blocked"); } CHKPR(iSensorHdiConnection_, DISABLE_SENSOR_ERR); ret = iSensorHdiConnection_->DisableSensor(sensorId); @@ -245,6 +263,7 @@ int32_t SensorHdiConnection::SetBatch(int32_t sensorId, int64_t samplingInterval StartTrace(HITRACE_TAG_SENSORS, "SetBatch"); int32_t ret = SET_SENSOR_CONFIG_ERR; if (FindOneInMockSet(sensorId)) { +#ifdef BUILD_VARIANT_ENG CHKPR(iSensorCompatibleHdiConnection_, SET_SENSOR_CONFIG_ERR); ret = iSensorCompatibleHdiConnection_->SetBatch(sensorId, samplingInterval, reportInterval); FinishTrace(HITRACE_TAG_SENSORS); @@ -253,6 +272,8 @@ int32_t SensorHdiConnection::SetBatch(int32_t sensorId, int64_t samplingInterval return SET_SENSOR_CONFIG_ERR; } return ret; +#endif + SEN_HILOGE("Compatible connection have been blocked"); } CHKPR(iSensorHdiConnection_, SET_SENSOR_CONFIG_ERR); ret = iSensorHdiConnection_->SetBatch(sensorId, samplingInterval, reportInterval); @@ -269,6 +290,7 @@ int32_t SensorHdiConnection::SetMode(int32_t sensorId, int32_t mode) StartTrace(HITRACE_TAG_SENSORS, "SetMode"); int32_t ret = SET_SENSOR_MODE_ERR; if (FindOneInMockSet(sensorId)) { +#ifdef BUILD_VARIANT_ENG CHKPR(iSensorCompatibleHdiConnection_, SET_SENSOR_MODE_ERR); ret = iSensorCompatibleHdiConnection_->SetMode(sensorId, mode); FinishTrace(HITRACE_TAG_SENSORS); @@ -277,6 +299,8 @@ int32_t SensorHdiConnection::SetMode(int32_t sensorId, int32_t mode) return SET_SENSOR_MODE_ERR; } return ret; +#endif + SEN_HILOGE("Compatible connection have been blocked"); } CHKPR(iSensorHdiConnection_, SET_SENSOR_MODE_ERR); ret = iSensorHdiConnection_->SetMode(sensorId, mode); @@ -297,6 +321,7 @@ int32_t SensorHdiConnection::RegisterDataReport(ReportDataCb cb, sptrRegisterDataReport(cb, reportDataCallback); if (ret != ERR_OK) { @@ -304,6 +329,8 @@ int32_t SensorHdiConnection::RegisterDataReport(ReportDataCb cb, sptrDestroyHdiConnection(); if (ret != ERR_OK) { @@ -323,6 +351,8 @@ int32_t SensorHdiConnection::DestroyHdiConnection() } return DEVICE_ERR; } +#endif + SEN_HILOGE("Compatible connection have been blocked"); return ret; } } // namespace Sensors diff --git a/services/src/sensor_data_processer.cpp b/services/src/sensor_data_processer.cpp index 48258d4ef715eb04ef5d3f68af93a6a8396bc3a6..7572aeeb39c47af0d6f5af2f100076bc4cdd1a99 100644 --- a/services/src/sensor_data_processer.cpp +++ b/services/src/sensor_data_processer.cpp @@ -254,8 +254,10 @@ void SensorDataProcesser::EventFilter(CircularEventBuf &eventsBuf) int32_t SensorDataProcesser::ProcessEvents(sptr dataCallback) { CHKPR(dataCallback, INVALID_POINTER); +#ifdef BUILD_VARIANT_ENG std::unique_lock lk(ISensorHdiConnection::dataMutex_); ISensorHdiConnection::dataCondition_.wait(lk); +#endif auto &eventsBuf = dataCallback->GetEventData(); if (eventsBuf.eventNum <= 0) { SEN_HILOGE("Data cannot be empty"); diff --git a/services/src/sensor_dump.cpp b/services/src/sensor_dump.cpp index caaf94e03c695efc47e79b8a6819531f5f02b9c6..4a7efe17775dec3e54802e1618e0adc53996f33b 100644 --- a/services/src/sensor_dump.cpp +++ b/services/src/sensor_dump.cpp @@ -104,7 +104,9 @@ void SensorDump::ParseCommand(int32_t fd, const std::vector &args, int32_t optionIndex = 0; struct option dumpOptions[] = { {"channel", no_argument, 0, 'c'}, +#ifdef BUILD_VARIANT_ENG {"data", no_argument, 0, 'd'}, +#endif {"open", no_argument, 0, 'o'}, {"help", no_argument, 0, 'h'}, {"list", no_argument, 0, 'l'}, @@ -136,10 +138,12 @@ void SensorDump::ParseCommand(int32_t fd, const std::vector &args, DumpSensorChannel(fd, clientInfo); break; } +#ifdef BUILD_VARIANT_ENG case 'd': { DumpSensorData(fd, clientInfo); break; } +#endif case 'o': { DumpOpeningSensor(fd, sensors, clientInfo); break; @@ -174,7 +178,9 @@ void SensorDump::DumpHelp(int32_t fd) dprintf(fd, " -l, --list: dump the sensor list\n"); dprintf(fd, " -c, --channel: dump the sensor data channel info\n"); dprintf(fd, " -o, --open: dump the opening sensors\n"); +#ifdef BUILD_VARIANT_ENG dprintf(fd, " -d, --data: dump the last 10 packages sensor data\n"); +#endif } bool SensorDump::DumpSensorList(int32_t fd, const std::vector &sensors)