From 8dc6f99e3eb9f23ff6e816edea979d916e39051a Mon Sep 17 00:00:00 2001 From: wuzhihuitmac Date: Mon, 19 Jun 2023 02:12:18 +0000 Subject: [PATCH] add color and sar Signed-off-by: wuzhihuitmac Change-Id: I09de400128b8fccf66f80843503a2f17749c4ea7 --- interfaces/native/include/sensor_agent_type.h | 2 + interfaces/plugin/src/sensor_js.cpp | 4 + interfaces/plugin/src/sensor_napi_utils.cpp | 4 +- .../adapter/include/compatible_connection.h | 2 +- .../adapter/include/hdi_connection.h | 2 +- .../adapter/src/compatible_connection.cpp | 2 +- .../adapter/src/hdi_connection.cpp | 4 +- .../hardware/include/hdi_service_impl.h | 4 +- .../hardware/src/hdi_service_impl.cpp | 62 +++++++--- .../include/i_sensor_hdi_connection.h | 2 +- .../interface/include/sensor_hdi_connection.h | 6 +- .../interface/src/sensor_hdi_connection.cpp | 110 +++++++++++++++++- services/sensor/src/sensor_service.cpp | 2 +- 13 files changed, 171 insertions(+), 35 deletions(-) diff --git a/interfaces/native/include/sensor_agent_type.h b/interfaces/native/include/sensor_agent_type.h index 2e786bf5..cb8113c2 100644 --- a/interfaces/native/include/sensor_agent_type.h +++ b/interfaces/native/include/sensor_agent_type.h @@ -76,6 +76,8 @@ typedef enum SensorTypeId { SENSOR_TYPE_ID_GESTURE = 11, /**< Gesture sensor */ SENSOR_TYPE_ID_PROXIMITY = 12, /**< Proximity sensor */ SENSOR_TYPE_ID_HUMIDITY = 13, /**< Humidity sensor */ + SENSOR_TYPE_ID_COLOR = 14, /**< Color sensor */ + SENSOR_TYPE_ID_SAR = 15, /**< Sar sensor */ SENSOR_TYPE_ID_PHYSICAL_MAX = 0xFF, /**< Maximum type ID of a physical sensor */ SENSOR_TYPE_ID_ORIENTATION = 256, /**< Orientation sensor */ SENSOR_TYPE_ID_GRAVITY = 257, /**< Gravity sensor */ diff --git a/interfaces/plugin/src/sensor_js.cpp b/interfaces/plugin/src/sensor_js.cpp index c2392ca5..7d0a477b 100644 --- a/interfaces/plugin/src/sensor_js.cpp +++ b/interfaces/plugin/src/sensor_js.cpp @@ -1261,6 +1261,8 @@ static napi_value CreateEnumSensorType(napi_env env, napi_value exports) DECLARE_NAPI_STATIC_PROPERTY("SENSOR_TYPE_ID_TEMPERATURE", GetNapiInt32(env, SENSOR_TYPE_ID_TEMPERATURE)), DECLARE_NAPI_STATIC_PROPERTY("SENSOR_TYPE_ID_PROXIMITY", GetNapiInt32(env, SENSOR_TYPE_ID_PROXIMITY)), DECLARE_NAPI_STATIC_PROPERTY("SENSOR_TYPE_ID_HUMIDITY", GetNapiInt32(env, SENSOR_TYPE_ID_HUMIDITY)), + DECLARE_NAPI_STATIC_PROPERTY("SENSOR_TYPE_ID_COLOR", GetNapiInt32(env, SENSOR_TYPE_ID_COLOR)), + DECLARE_NAPI_STATIC_PROPERTY("SENSOR_TYPE_ID_SAR", GetNapiInt32(env, SENSOR_TYPE_ID_SAR)), DECLARE_NAPI_STATIC_PROPERTY("SENSOR_TYPE_ID_ORIENTATION", GetNapiInt32(env, SENSOR_TYPE_ID_ORIENTATION)), DECLARE_NAPI_STATIC_PROPERTY("SENSOR_TYPE_ID_GRAVITY", GetNapiInt32(env, SENSOR_TYPE_ID_GRAVITY)), DECLARE_NAPI_STATIC_PROPERTY("SENSOR_TYPE_ID_LINEAR_ACCELERATION", @@ -1302,6 +1304,8 @@ static napi_value CreateEnumSensorId(napi_env env, napi_value exports) DECLARE_NAPI_STATIC_PROPERTY("TEMPERATURE", GetNapiInt32(env, SENSOR_TYPE_ID_TEMPERATURE)), DECLARE_NAPI_STATIC_PROPERTY("PROXIMITY", GetNapiInt32(env, SENSOR_TYPE_ID_PROXIMITY)), DECLARE_NAPI_STATIC_PROPERTY("HUMIDITY", GetNapiInt32(env, SENSOR_TYPE_ID_HUMIDITY)), + DECLARE_NAPI_STATIC_PROPERTY("COLOR", GetNapiInt32(env, SENSOR_TYPE_ID_COLOR)), + DECLARE_NAPI_STATIC_PROPERTY("SAR", GetNapiInt32(env, SENSOR_TYPE_ID_SAR)), DECLARE_NAPI_STATIC_PROPERTY("ORIENTATION", GetNapiInt32(env, SENSOR_TYPE_ID_ORIENTATION)), DECLARE_NAPI_STATIC_PROPERTY("GRAVITY", GetNapiInt32(env, SENSOR_TYPE_ID_GRAVITY)), DECLARE_NAPI_STATIC_PROPERTY("LINEAR_ACCELEROMETER", GetNapiInt32(env, SENSOR_TYPE_ID_LINEAR_ACCELERATION)), diff --git a/interfaces/plugin/src/sensor_napi_utils.cpp b/interfaces/plugin/src/sensor_napi_utils.cpp index 7d0510f7..4a8b3d23 100644 --- a/interfaces/plugin/src/sensor_napi_utils.cpp +++ b/interfaces/plugin/src/sensor_napi_utils.cpp @@ -179,7 +179,9 @@ std::map> g_sensorAttributeList = { { SENSOR_TYPE_ID_PEDOMETER, { "steps" } }, { SENSOR_TYPE_ID_HEART_RATE, { "heartRate" } }, { SENSOR_TYPE_ID_WEAR_DETECTION, { "value" } }, - { SENSOR_TYPE_ID_ACCELEROMETER_UNCALIBRATED, { "x", "y", "z", "biasX", "biasY", "biasZ" } } + { SENSOR_TYPE_ID_ACCELEROMETER_UNCALIBRATED, { "x", "y", "z", "biasX", "biasY", "biasZ" } }, + { SENSOR_TYPE_ID_COLOR, { "lightIntensity", "colorTemperature" } }, + { SENSOR_TYPE_ID_SAR, { "absorptionRatio" } } }; std::map g_convertfuncList = { diff --git a/services/sensor/hdi_connection/adapter/include/compatible_connection.h b/services/sensor/hdi_connection/adapter/include/compatible_connection.h index c04a1c95..52b04958 100644 --- a/services/sensor/hdi_connection/adapter/include/compatible_connection.h +++ b/services/sensor/hdi_connection/adapter/include/compatible_connection.h @@ -31,7 +31,7 @@ public: int32_t DisableSensor(int32_t sensorId) override; int32_t SetBatch(int32_t sensorId, int64_t samplingInterval, int64_t reportInterval) override; int32_t SetMode(int32_t sensorId, int32_t mode) override; - int32_t RegisteDataReport(ReportDataCb cb, sptr reportDataCallback) override; + int32_t RegisterDataReport(ReportDataCb cb, sptr reportDataCallback) override; int32_t DestroyHdiConnection() override; private: diff --git a/services/sensor/hdi_connection/adapter/include/hdi_connection.h b/services/sensor/hdi_connection/adapter/include/hdi_connection.h index 53436867..cc31f4f3 100644 --- a/services/sensor/hdi_connection/adapter/include/hdi_connection.h +++ b/services/sensor/hdi_connection/adapter/include/hdi_connection.h @@ -32,7 +32,7 @@ public: int32_t DisableSensor(int32_t sensorId) override; int32_t SetBatch(int32_t sensorId, int64_t samplingInterval, int64_t reportInterval) override; int32_t SetMode(int32_t sensorId, int32_t mode) override; - int32_t RegisteDataReport(ReportDataCb cb, sptr reportDataCallback) override; + int32_t RegisterDataReport(ReportDataCb cb, sptr reportDataCallback) override; int32_t DestroyHdiConnection() override; ReportDataCb GetReportDataCb(); sptr GetReportDataCallback(); diff --git a/services/sensor/hdi_connection/adapter/src/compatible_connection.cpp b/services/sensor/hdi_connection/adapter/src/compatible_connection.cpp index fca1e885..c4963fe6 100644 --- a/services/sensor/hdi_connection/adapter/src/compatible_connection.cpp +++ b/services/sensor/hdi_connection/adapter/src/compatible_connection.cpp @@ -143,7 +143,7 @@ void CompatibleConnection::ReportSensorDataCallback(SensorEvent *event) ISensorHdiConnection::dataCondition_.notify_one(); } -int32_t CompatibleConnection::RegisteDataReport(ReportDataCb cb, sptr reportDataCallback) +int32_t CompatibleConnection::RegisterDataReport(ReportDataCb cb, sptr reportDataCallback) { CHKPR(reportDataCallback, ERR_INVALID_VALUE); int32_t ret = hdiServiceImpl_.Register(ReportSensorDataCallback); diff --git a/services/sensor/hdi_connection/adapter/src/hdi_connection.cpp b/services/sensor/hdi_connection/adapter/src/hdi_connection.cpp index 951b5827..819ece28 100755 --- a/services/sensor/hdi_connection/adapter/src/hdi_connection.cpp +++ b/services/sensor/hdi_connection/adapter/src/hdi_connection.cpp @@ -157,7 +157,7 @@ int32_t HdiConnection::SetMode(int32_t sensorId, int32_t mode) return ERR_OK; } -int32_t HdiConnection::RegisteDataReport(ReportDataCb cb, sptr reportDataCallback) +int32_t HdiConnection::RegisterDataReport(ReportDataCb cb, sptr reportDataCallback) { CALL_LOG_ENTER; CHKPR(reportDataCallback, ERR_NO_INIT); @@ -165,7 +165,7 @@ int32_t HdiConnection::RegisteDataReport(ReportDataCb cb, sptrRegister(0, eventCallback_); if (ret != 0) { HiSysEventWrite(HiviewDFX::HiSysEvent::Domain::SENSOR, "HDF_SERVICE_EXCEPTION", - HiSysEvent::EventType::FAULT, "PKG_NAME", "RegisteDataReport", "ERROR_CODE", ret); + HiSysEvent::EventType::FAULT, "PKG_NAME", "RegisterDataReport", "ERROR_CODE", ret); SEN_HILOGE("Register is failed"); return ret; } diff --git a/services/sensor/hdi_connection/hardware/include/hdi_service_impl.h b/services/sensor/hdi_connection/hardware/include/hdi_service_impl.h index 388f2b68..a2b7ebd7 100644 --- a/services/sensor/hdi_connection/hardware/include/hdi_service_impl.h +++ b/services/sensor/hdi_connection/hardware/include/hdi_service_impl.h @@ -39,9 +39,9 @@ public: private: DISALLOW_COPY_AND_MOVE(HdiServiceImpl); static void DataReportThread(); - std::vector g_enableSensors; + static std::vector enableSensors_; std::thread dataReportThread_; - static RecordSensorCallback callback_; + static std::vector callbacks_; static int64_t samplingInterval_; static int64_t reportInterval_; static std::atomic_bool isStop_; diff --git a/services/sensor/hdi_connection/hardware/src/hdi_service_impl.cpp b/services/sensor/hdi_connection/hardware/src/hdi_service_impl.cpp index 3dc108a5..a7167eef 100644 --- a/services/sensor/hdi_connection/hardware/src/hdi_service_impl.cpp +++ b/services/sensor/hdi_connection/hardware/src/hdi_service_impl.cpp @@ -30,15 +30,28 @@ constexpr int32_t CONVERT_MULTIPLES = 1000; std::vector g_sensorInfos = { {"sensor_test", "default", "1.0.0", "1.0.0", 0, 1, 9999.0, 0.000001, 23.0, 100000000, 1000000000}, }; -std::vector supportSensors = {1}; -float g_testData[] = {9.8, 0.0, 0.0}; -SensorEvent testEvent = { - .sensorTypeId = 1, - .data = (uint8_t *)g_testData, +std::vector g_supportSensors = { SENSOR_TYPE_ID_ACCELEROMETER, SENSOR_TYPE_ID_COLOR, SENSOR_TYPE_ID_SAR }; +float g_testData[] = { 9.8, 0.0, 0.0 }; +float g_colorData[] = { 2.2, 3.3 }; +float g_sarData[] = { 8.8 }; +SensorEvent g_testEvent = { + .sensorTypeId = SENSOR_TYPE_ID_ACCELEROMETER, + .data = reinterpret_cast(g_testData), .dataLen = 12 }; +SensorEvent g_colorEvent = { + .sensorTypeId = SENSOR_TYPE_ID_COLOR, + .data = reinterpret_cast(g_colorData), + .dataLen = 8 +}; +SensorEvent g_sarEvent = { + .sensorTypeId = SENSOR_TYPE_ID_SAR, + .data = reinterpret_cast(g_sarData), + .dataLen = 4 +}; } -RecordSensorCallback HdiServiceImpl::callback_; +std::vector HdiServiceImpl::enableSensors_; +std::vector HdiServiceImpl::callbacks_; int64_t HdiServiceImpl::samplingInterval_ = -1; int64_t HdiServiceImpl::reportInterval_ = -1; std::atomic_bool HdiServiceImpl::isStop_ = false; @@ -55,7 +68,21 @@ void HdiServiceImpl::DataReportThread() CALL_LOG_ENTER; while (true) { usleep(samplingInterval_ / CONVERT_MULTIPLES); - callback_(&testEvent); + for (const auto &it : callbacks_) { + if (it == nullptr) { + SEN_HILOGW("RecordSensorCallback is null"); + continue; + } + for (const auto &iter : enableSensors_) { + if (iter == SENSOR_TYPE_ID_COLOR) { + it(&g_colorEvent); + } else if (iter == SENSOR_TYPE_ID_SAR) { + it(&g_sarEvent); + } else { + it(&g_testEvent); + } + } + } if (isStop_) { break; } @@ -67,16 +94,15 @@ void HdiServiceImpl::DataReportThread() int32_t HdiServiceImpl::EnableSensor(int32_t sensorId) { CALL_LOG_ENTER; - CHKPR(callback_, ERROR); - if (std::find(supportSensors.begin(), supportSensors.end(), sensorId) == supportSensors.end()) { + if (std::find(g_supportSensors.begin(), g_supportSensors.end(), sensorId) == g_supportSensors.end()) { SEN_HILOGE("Not support enable sensorId:%{public}d", sensorId); return ERR_NO_INIT; } - if (std::find(g_enableSensors.begin(), g_enableSensors.end(), sensorId) != g_enableSensors.end()) { + if (std::find(enableSensors_.begin(), enableSensors_.end(), sensorId) != enableSensors_.end()) { SEN_HILOGI("sensorId:%{public}d has been enabled", sensorId); return ERR_OK; } - g_enableSensors.push_back(sensorId); + enableSensors_.push_back(sensorId); if (!dataReportThread_.joinable() || isStop_) { if (dataReportThread_.joinable()) { dataReportThread_.join(); @@ -91,22 +117,24 @@ int32_t HdiServiceImpl::EnableSensor(int32_t sensorId) int32_t HdiServiceImpl::DisableSensor(int32_t sensorId) { CALL_LOG_ENTER; - if (std::find(supportSensors.begin(), supportSensors.end(), sensorId) == supportSensors.end()) { + if (std::find(g_supportSensors.begin(), g_supportSensors.end(), sensorId) == g_supportSensors.end()) { SEN_HILOGE("Not support disable sensorId:%{public}d", sensorId); return ERR_NO_INIT; } - if (std::find(g_enableSensors.begin(), g_enableSensors.end(), sensorId) == g_enableSensors.end()) { + if (std::find(enableSensors_.begin(), enableSensors_.end(), sensorId) == enableSensors_.end()) { SEN_HILOGE("sensorId:%{public}d should be enable first", sensorId); return ERR_NO_INIT; } std::vector::iterator iter; - for (iter = g_enableSensors.begin(); iter != g_enableSensors.end(); ++iter) { + for (iter = enableSensors_.begin(); iter != enableSensors_.end();) { if (*iter == sensorId) { - g_enableSensors.erase(iter++); + iter = enableSensors_.erase(iter); break; + } else { + ++iter; } } - if (g_enableSensors.empty()) { + if (enableSensors_.empty()) { isStop_ = true; } return ERR_OK; @@ -132,7 +160,7 @@ int32_t HdiServiceImpl::SetMode(int32_t sensorId, int32_t mode) int32_t HdiServiceImpl::Register(RecordSensorCallback cb) { CHKPR(cb, ERROR); - callback_ = cb; + callbacks_.push_back(cb); return ERR_OK; } diff --git a/services/sensor/hdi_connection/interface/include/i_sensor_hdi_connection.h b/services/sensor/hdi_connection/interface/include/i_sensor_hdi_connection.h index c3b28f15..06323d69 100644 --- a/services/sensor/hdi_connection/interface/include/i_sensor_hdi_connection.h +++ b/services/sensor/hdi_connection/interface/include/i_sensor_hdi_connection.h @@ -33,7 +33,7 @@ public: virtual int32_t DisableSensor(int32_t sensorId) = 0; virtual int32_t SetBatch(int32_t sensorId, int64_t samplingInterval, int64_t reportInterval) = 0; virtual int32_t SetMode(int32_t sensorId, int32_t mode) = 0; - virtual int32_t RegisteDataReport(ReportDataCb cb, sptr reportDataCallback) = 0; + virtual int32_t RegisterDataReport(ReportDataCb cb, sptr reportDataCallback) = 0; virtual int32_t DestroyHdiConnection() = 0; static std::mutex dataMutex_; static std::condition_variable dataCondition_; diff --git a/services/sensor/hdi_connection/interface/include/sensor_hdi_connection.h b/services/sensor/hdi_connection/interface/include/sensor_hdi_connection.h index f027c460..926cc747 100644 --- a/services/sensor/hdi_connection/interface/include/sensor_hdi_connection.h +++ b/services/sensor/hdi_connection/interface/include/sensor_hdi_connection.h @@ -31,14 +31,16 @@ public: int32_t DisableSensor(int32_t sensorId) override; int32_t SetBatch(int32_t sensorId, int64_t samplingInterval, int64_t reportInterval) override; int32_t SetMode(int32_t sensorId, int32_t mode) override; - int32_t RegisteDataReport(ReportDataCb cb, sptr reportDataCallback) override; + int32_t RegisterDataReport(ReportDataCb cb, sptr reportDataCallback) override; int32_t DestroyHdiConnection() override; private: DISALLOW_COPY_AND_MOVE(SensorHdiConnection); - std::unique_ptr iSensorHdiConnection_; + std::unique_ptr iSensorHdiConnection_ { nullptr }; + std::unique_ptr iSensorCompatibleHdiConnection_ { nullptr }; std::vector sensorList_; int32_t ConnectHdiService(); + int32_t ConnectCompatibleHdi(); }; } // namespace Sensors } // namespace OHOS diff --git a/services/sensor/hdi_connection/interface/src/sensor_hdi_connection.cpp b/services/sensor/hdi_connection/interface/src/sensor_hdi_connection.cpp index f4b7c61c..ddf5681a 100644 --- a/services/sensor/hdi_connection/interface/src/sensor_hdi_connection.cpp +++ b/services/sensor/hdi_connection/interface/src/sensor_hdi_connection.cpp @@ -24,6 +24,12 @@ namespace Sensors { using namespace OHOS::HiviewDFX; namespace { constexpr HiLogLabel LABEL = { LOG_CORE, SENSOR_LOG_DOMAIN, "SensorHdiConnection" }; +constexpr float MAX_RANGE = 9999.0; +constexpr float POWER = 20.0; +constexpr float RESOLITION = 0.000001; +constexpr float MIN_SAMPLE_PERIOD_NS = 100000000; +constexpr float MAX_SAMPLE_PERIOD_NS = 1000000000; +const std::string VERSION_NAME = "1.0.1"; } int32_t SensorHdiConnection::ConnectHdi() @@ -38,6 +44,10 @@ int32_t SensorHdiConnection::ConnectHdi() if (ret != ERR_OK) { SEN_HILOGE("Connect hdi failed"); } + ret = ConnectCompatibleHdi(); + if (ret != ERR_OK) { + SEN_HILOGE("Connect compatible hdi failed, ret:%{public}d", ret); + } return ERR_OK; } @@ -56,16 +66,67 @@ int32_t SensorHdiConnection::ConnectHdiService() return ERR_OK; } +int32_t SensorHdiConnection::ConnectCompatibleHdi() +{ + if (iSensorCompatibleHdiConnection_ == nullptr) { + iSensorCompatibleHdiConnection_ = std::make_unique(); + } + int32_t ret = iSensorCompatibleHdiConnection_->ConnectHdi(); + if (ret != ERR_OK) { + SEN_HILOGE("Connect hdi compatible service failed"); + return CONNECT_SENSOR_HDF_ERR; + } + return ERR_OK; +} + int32_t SensorHdiConnection::GetSensorList(std::vector& sensorList) { sensorList.assign(sensorList_.begin(), sensorList_.end()); + Sensor sensorColor; + sensorColor.SetSensorId(SENSOR_TYPE_ID_COLOR); + sensorColor.SetSensorTypeId(SENSOR_TYPE_ID_COLOR); + sensorColor.SetFirmwareVersion(VERSION_NAME); + sensorColor.SetHardwareVersion(VERSION_NAME); + sensorColor.SetMaxRange(MAX_RANGE); + sensorColor.SetSensorName("sensor_color"); + sensorColor.SetVendorName("default_color"); + sensorColor.SetResolution(RESOLITION); + sensorColor.SetPower(POWER); + sensorColor.SetMinSamplePeriodNs(MIN_SAMPLE_PERIOD_NS); + sensorColor.SetMaxSamplePeriodNs(MAX_SAMPLE_PERIOD_NS); + sensorList.push_back(sensorColor); + Sensor sensorSar; + sensorSar.SetSensorId(SENSOR_TYPE_ID_SAR); + sensorSar.SetSensorTypeId(SENSOR_TYPE_ID_SAR); + sensorSar.SetFirmwareVersion(VERSION_NAME); + sensorSar.SetHardwareVersion(VERSION_NAME); + sensorSar.SetMaxRange(MAX_RANGE); + sensorSar.SetSensorName("sensor_sar"); + sensorSar.SetVendorName("default_sar"); + sensorSar.SetResolution(RESOLITION); + sensorSar.SetPower(POWER); + sensorSar.SetMinSamplePeriodNs(MIN_SAMPLE_PERIOD_NS); + sensorSar.SetMaxSamplePeriodNs(MAX_SAMPLE_PERIOD_NS); + sensorList.push_back(sensorSar); return ERR_OK; } int32_t SensorHdiConnection::EnableSensor(int32_t sensorId) { StartTrace(HITRACE_TAG_SENSORS, "EnableSensor"); - int32_t ret = iSensorHdiConnection_->EnableSensor(sensorId); + int32_t ret { ENABLE_SENSOR_ERR }; + if (sensorId == SENSOR_TYPE_ID_COLOR || sensorId == SENSOR_TYPE_ID_SAR) { + CHKPR(iSensorCompatibleHdiConnection_, ENABLE_SENSOR_ERR); + ret = iSensorCompatibleHdiConnection_->EnableSensor(sensorId); + FinishTrace(HITRACE_TAG_SENSORS); + if (ret != ERR_OK) { + SEN_HILOGE("Enable sensor failed in compatible, sensorId:%{public}d", sensorId); + return ENABLE_SENSOR_ERR; + } + return ret; + } + CHKPR(iSensorHdiConnection_, ENABLE_SENSOR_ERR); + ret = iSensorHdiConnection_->EnableSensor(sensorId); FinishTrace(HITRACE_TAG_SENSORS); if (ret != 0) { SEN_HILOGI("Enable sensor failed, sensorId:%{public}d", sensorId); @@ -77,7 +138,19 @@ int32_t SensorHdiConnection::EnableSensor(int32_t sensorId) int32_t SensorHdiConnection::DisableSensor(int32_t sensorId) { StartTrace(HITRACE_TAG_SENSORS, "DisableSensor"); - int32_t ret = iSensorHdiConnection_->DisableSensor(sensorId); + int32_t ret { ENABLE_SENSOR_ERR }; + if (sensorId == SENSOR_TYPE_ID_COLOR || sensorId == SENSOR_TYPE_ID_SAR) { + CHKPR(iSensorCompatibleHdiConnection_, DISABLE_SENSOR_ERR); + ret = iSensorCompatibleHdiConnection_->DisableSensor(sensorId); + FinishTrace(HITRACE_TAG_SENSORS); + if (ret != ERR_OK) { + SEN_HILOGE("Disable sensor failed in compatible, sensorId:%{public}d", sensorId); + return DISABLE_SENSOR_ERR; + } + return ret; + } + CHKPR(iSensorHdiConnection_, DISABLE_SENSOR_ERR); + ret = iSensorHdiConnection_->DisableSensor(sensorId); FinishTrace(HITRACE_TAG_SENSORS); if (ret != 0) { SEN_HILOGI("Disable sensor failed, sensorId:%{public}d", sensorId); @@ -89,7 +162,19 @@ int32_t SensorHdiConnection::DisableSensor(int32_t sensorId) int32_t SensorHdiConnection::SetBatch(int32_t sensorId, int64_t samplingInterval, int64_t reportInterval) { StartTrace(HITRACE_TAG_SENSORS, "SetBatch"); - int32_t ret = iSensorHdiConnection_->SetBatch(sensorId, samplingInterval, reportInterval); + int32_t ret { ENABLE_SENSOR_ERR }; + if (sensorId == SENSOR_TYPE_ID_COLOR || sensorId == SENSOR_TYPE_ID_SAR) { + CHKPR(iSensorCompatibleHdiConnection_, SET_SENSOR_CONFIG_ERR); + ret = iSensorCompatibleHdiConnection_->SetBatch(sensorId, samplingInterval, reportInterval); + FinishTrace(HITRACE_TAG_SENSORS); + if (ret != ERR_OK) { + SEN_HILOGI("Set batch failed in compatible, sensorId:%{public}d", sensorId); + return SET_SENSOR_CONFIG_ERR; + } + return ret; + } + CHKPR(iSensorHdiConnection_, SET_SENSOR_CONFIG_ERR); + ret = iSensorHdiConnection_->SetBatch(sensorId, samplingInterval, reportInterval); FinishTrace(HITRACE_TAG_SENSORS); if (ret != 0) { SEN_HILOGI("Set batch failed, sensorId:%{public}d", sensorId); @@ -101,6 +186,7 @@ int32_t SensorHdiConnection::SetBatch(int32_t sensorId, int64_t samplingInterval int32_t SensorHdiConnection::SetMode(int32_t sensorId, int32_t mode) { StartTrace(HITRACE_TAG_SENSORS, "SetMode"); + CHKPR(iSensorHdiConnection_, SET_SENSOR_MODE_ERR); int32_t ret = iSensorHdiConnection_->SetMode(sensorId, mode); FinishTrace(HITRACE_TAG_SENSORS); if (ret != 0) { @@ -110,10 +196,16 @@ int32_t SensorHdiConnection::SetMode(int32_t sensorId, int32_t mode) return ret; } -int32_t SensorHdiConnection::RegisteDataReport(ReportDataCb cb, sptr reportDataCallback) +int32_t SensorHdiConnection::RegisterDataReport(ReportDataCb cb, sptr reportDataCallback) { - StartTrace(HITRACE_TAG_SENSORS, "RegisteDataReport"); - int32_t ret = iSensorHdiConnection_->RegisteDataReport(cb, reportDataCallback); + StartTrace(HITRACE_TAG_SENSORS, "RegisterDataReport"); + CHKPR(iSensorHdiConnection_, REGIST_CALLBACK_ERR); + int32_t ret = iSensorHdiConnection_->RegisterDataReport(cb, reportDataCallback); + CHKPR(iSensorCompatibleHdiConnection_, REGIST_CALLBACK_ERR); + int32_t compatibleRet = iSensorCompatibleHdiConnection_->RegisterDataReport(cb, reportDataCallback); + if (compatibleRet != ERR_OK) { + SEN_HILOGE("Registe dataReport failed in compatible"); + } FinishTrace(HITRACE_TAG_SENSORS); if (ret != 0) { SEN_HILOGI("Registe dataReport failed"); @@ -124,11 +216,17 @@ int32_t SensorHdiConnection::RegisteDataReport(ReportDataCb cb, sptrDestroyHdiConnection(); if (ret != 0) { SEN_HILOGI("Destroy hdi connection failed"); return DEVICE_ERR; } + CHKPR(iSensorCompatibleHdiConnection_, DEVICE_ERR); + int32_t compatibleRet = iSensorCompatibleHdiConnection_->DestroyHdiConnection(); + if (compatibleRet != ERR_OK) { + SEN_HILOGE("Destroy hdi connection failed in compatible"); + } return ret; } } // namespace Sensors diff --git a/services/sensor/src/sensor_service.cpp b/services/sensor/src/sensor_service.cpp index 6e0f5e86..a911e968 100644 --- a/services/sensor/src/sensor_service.cpp +++ b/services/sensor/src/sensor_service.cpp @@ -97,7 +97,7 @@ bool SensorService::InitDataCallback() reportDataCallback_ = new (std::nothrow) ReportDataCallback(); CHKPF(reportDataCallback_); ReportDataCb cb = &ReportDataCallback::ReportEventCallback; - auto ret = sensorHdiConnection_.RegisteDataReport(cb, reportDataCallback_); + auto ret = sensorHdiConnection_.RegisterDataReport(cb, reportDataCallback_); if (ret != ERR_OK) { SEN_HILOGE("RegisterDataReport failed"); return false; -- Gitee