From d17f7e83358e6a39672a6338225e4a092c380dea Mon Sep 17 00:00:00 2001 From: rwx1283129 Date: Thu, 2 Nov 2023 04:38:44 +0000 Subject: [PATCH 1/3] Initial quarantine in macro mode Signed-off-by: rwx1283129 Change-Id: I0daad76de6c6d403f9b9de7b96a2232d51bf7638 --- sensor.gni | 10 +++++++ services/BUILD.gn | 14 +++++++-- .../adapter/src/compatible_connection.cpp | 4 +++ .../adapter/src/sensor_event_callback.cpp | 2 ++ .../interface/src/sensor_hdi_connection.cpp | 30 +++++++++++++++++++ services/src/sensor_data_processer.cpp | 2 ++ 6 files changed, 60 insertions(+), 2 deletions(-) diff --git a/sensor.gni b/sensor.gni index 4bf58c1e..2d64ca44 100644 --- a/sensor.gni +++ b/sensor.gni @@ -34,3 +34,13 @@ 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 6513d2d9..4e3ab4e3 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,12 @@ 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 +132,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 +145,12 @@ 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 8a2ef420..88a5833e 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 a67a23c1..4e57fa3a 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 d4337a9c..6741dfc1 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 48258d4e..7572aeeb 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"); -- Gitee From 0c7d63f03314456f742b0e23474a6f07d28185fe Mon Sep 17 00:00:00 2001 From: rwx1283129 Date: Thu, 2 Nov 2023 06:10:33 +0000 Subject: [PATCH 2/3] insulate the dump from sensor Signed-off-by: rwx1283129 Change-Id: I36d6ba0b449793f4324be6131cedd24fb41462d7 --- services/src/sensor_dump.cpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/services/src/sensor_dump.cpp b/services/src/sensor_dump.cpp index caaf94e0..4a7efe17 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) -- Gitee From b66cc64b65076c965162b49353907e5804d49456 Mon Sep 17 00:00:00 2001 From: rwx1283129 Date: Thu, 2 Nov 2023 06:52:10 +0000 Subject: [PATCH 3/3] Modify the format of gn Signed-off-by: rwx1283129 Change-Id: I5e9f3198562af2a85527717c140e38293dd95f6c --- sensor.gni | 7 ++----- services/BUILD.gn | 12 ++++-------- 2 files changed, 6 insertions(+), 13 deletions(-) diff --git a/sensor.gni b/sensor.gni index 2d64ca44..ad3494ff 100644 --- a/sensor.gni +++ b/sensor.gni @@ -35,12 +35,9 @@ if (!defined(global_parts_info) || hdf_drivers_interface_sensor = false } -if(build_variant == "eng") { +if (build_variant == "eng") { sensor_default_defines += [ "BUILD_VARIANT_ENG" ] sensor_build_eng = true -} -else { +} else { sensor_build_eng = false } - - diff --git a/services/BUILD.gn b/services/BUILD.gn index 4e3ab4e3..1db4f457 100644 --- a/services/BUILD.gn +++ b/services/BUILD.gn @@ -72,10 +72,8 @@ ohos_shared_library("libsensor_service") { "$SUBSYSTEM_DIR/services/hdi_connection/hardware/include", ] - if(sensor_build_eng) { - sources += [ - "hdi_connection/adapter/src/compatible_connection.cpp", - ] + if (sensor_build_eng) { + sources += [ "hdi_connection/adapter/src/compatible_connection.cpp" ] } external_deps += [ "drivers_interface_sensor:libsensor_proxy_1.1" ] @@ -145,10 +143,8 @@ 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", - ] + if (sensor_build_eng) { + sources += [ "hdi_connection/adapter/src/compatible_connection.cpp" ] } external_deps += [ "drivers_interface_sensor:libsensor_proxy_1.1" ] -- Gitee