From 9ad9a93f3d531e400b143b5c931044d73b1f7752 Mon Sep 17 00:00:00 2001 From: li-yaoyao777 Date: Fri, 1 Apr 2022 17:25:57 +0800 Subject: [PATCH 1/9] =?UTF-8?q?=E6=97=A0=E4=B8=9A=E5=8A=A1=E9=80=BB?= =?UTF-8?q?=E8=BE=91=E7=9A=84=E7=A9=BA=E6=8C=87=E9=92=88=E5=88=A4=E6=96=AD?= =?UTF-8?q?=E7=94=A8=E4=B8=93=E9=97=A8=E7=9A=84=E5=AE=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: li-yaoyao777 --- .../src/my_file_descriptor_listener.cpp | 1 + .../native/sensor/src/sensor_agent_proxy.cpp | 40 ++++++----- .../native/sensor/src/sensor_data_channel.cpp | 26 ++----- .../sensor/src/sensor_service_client.cpp | 10 +-- .../sensor/src/sensor_service_proxy.cpp | 11 +-- .../adapter/src/compatible_connection.cpp | 14 ++-- .../adapter/src/hdi_connection.cpp | 67 +++++-------------- .../adapter/src/sensor_event_callback.cpp | 6 +- .../hardware/src/hdi_service_impl.cpp | 10 +-- .../interface/src/sensor_hdi_connection.cpp | 5 +- services/sensor/src/client_info.cpp | 18 ++--- services/sensor/src/flush_info_record.cpp | 10 +-- services/sensor/src/sensor_data_processer.cpp | 43 +++--------- services/sensor/src/sensor_dump.cpp | 10 +-- services/sensor/src/sensor_service.cpp | 35 ++-------- services/sensor/src/sensor_service_stub.cpp | 15 +---- utils/src/report_data_callback.cpp | 5 +- utils/src/sensor.cpp | 5 +- utils/src/sensor_basic_data_channel.cpp | 6 +- 19 files changed, 96 insertions(+), 241 deletions(-) diff --git a/frameworks/native/sensor/src/my_file_descriptor_listener.cpp b/frameworks/native/sensor/src/my_file_descriptor_listener.cpp index 06c44431..98c4d51b 100644 --- a/frameworks/native/sensor/src/my_file_descriptor_listener.cpp +++ b/frameworks/native/sensor/src/my_file_descriptor_listener.cpp @@ -35,6 +35,7 @@ MyFileDescriptorListener::MyFileDescriptorListener() if (receiveDataBuff_ == nullptr) { SEN_HILOGE("receiveDataBuff_ memory request failed"); } + CHKPL(receiveDataBuff_); } MyFileDescriptorListener::~MyFileDescriptorListener() diff --git a/frameworks/native/sensor/src/sensor_agent_proxy.cpp b/frameworks/native/sensor/src/sensor_agent_proxy.cpp index afb5bafc..93addeeb 100644 --- a/frameworks/native/sensor/src/sensor_agent_proxy.cpp +++ b/frameworks/native/sensor/src/sensor_agent_proxy.cpp @@ -92,7 +92,8 @@ const SensorAgentProxy *SensorAgentProxy::GetSensorsObj() void SensorAgentProxy::HandleSensorData(struct SensorEvent *events, int32_t num, void *data) { - if (events == nullptr || num <= 0) { + CHKPV(events); + if (num <= 0) { SEN_HILOGE("events is null or num is invalid"); return; } @@ -104,10 +105,6 @@ void SensorAgentProxy::HandleSensorData(struct SensorEvent *events, int32_t num, SEN_HILOGE("sensorTypeId not in g_subscribeMap"); return; } - if (g_subscribeMap[eventStream.sensorTypeId] == nullptr) { - SEN_HILOGE("sensor user is null"); - return; - } g_subscribeMap[eventStream.sensorTypeId]->callback(&eventStream); } } @@ -163,7 +160,9 @@ int32_t SensorAgentProxy::DestroySensorDataChannel() const int32_t SensorAgentProxy::ActivateSensor(int32_t sensorId, const SensorUser *user) const { - if (user == nullptr || sensorId < 0 || user->callback == nullptr) { + CHKPR(user, OHOS::Sensors::ERROR); + CHKPR(user->callback, OHOS::Sensors::ERROR); + if (sensorId < 0) { SEN_HILOGE("user is null or sensorId is invalid"); return OHOS::Sensors::ERROR; } @@ -191,7 +190,9 @@ int32_t SensorAgentProxy::ActivateSensor(int32_t sensorId, const SensorUser *use int32_t SensorAgentProxy::DeactivateSensor(int32_t sensorId, const SensorUser *user) const { - if (user == nullptr || sensorId < 0 || user->callback == nullptr) { + CHKPR(user, OHOS::Sensors::ERROR); + CHKPR(user->callback, OHOS::Sensors::ERROR); + if (sensorId < 0) { SEN_HILOGE("user is null or sensorId is invalid"); return OHOS::Sensors::ERROR; } @@ -214,7 +215,8 @@ int32_t SensorAgentProxy::DeactivateSensor(int32_t sensorId, const SensorUser *u int32_t SensorAgentProxy::SetBatch(int32_t sensorId, const SensorUser *user, int64_t samplingInterval, int64_t reportInterval) const { - if (user == nullptr || sensorId < 0) { + CHKPR(user, OHOS::Sensors::ERROR); + if (sensorId < 0) { SEN_HILOGE("user is null or sensorId is invalid"); return OHOS::Sensors::ERROR; } @@ -235,7 +237,9 @@ int32_t SensorAgentProxy::SetBatch(int32_t sensorId, const SensorUser *user, int int32_t SensorAgentProxy::SubscribeSensor(int32_t sensorId, const SensorUser *user) const { SEN_HILOGI("in, sensorId: %{public}d", sensorId); - if (user == nullptr || sensorId < 0 || user->callback == nullptr) { + CHKPR(user, OHOS::Sensors::ERROR); + CHKPR(user->callback, OHOS::Sensors::ERROR); + if (sensorId < 0) { SEN_HILOGE("user or sensorId is invalid"); return OHOS::Sensors::ERROR; } @@ -252,7 +256,9 @@ int32_t SensorAgentProxy::SubscribeSensor(int32_t sensorId, const SensorUser *us int32_t SensorAgentProxy::UnsubscribeSensor(int32_t sensorId, const SensorUser *user) const { SEN_HILOGI("in, sensorId: %{public}d", sensorId); - if (user == nullptr || sensorId < 0 || user->callback == nullptr) { + CHKPR(user, OHOS::Sensors::ERROR); + CHKPR(user->callback, OHOS::Sensors::ERROR); + if (sensorId < 0) { SEN_HILOGE("user is null or sensorId is invalid"); return OHOS::Sensors::ERROR; } @@ -274,7 +280,9 @@ int32_t SensorAgentProxy::UnsubscribeSensor(int32_t sensorId, const SensorUser * int32_t SensorAgentProxy::SetMode(int32_t sensorId, const SensorUser *user, int32_t mode) const { - if (user == nullptr || sensorId < 0 || user->callback == nullptr) { + CHKPR(user, OHOS::Sensors::ERROR); + CHKPR(user->callback, OHOS::Sensors::ERROR); + if (sensorId < 0) { SEN_HILOGE("user is null or sensorId is invalid"); return OHOS::Sensors::ERROR; } @@ -288,7 +296,9 @@ int32_t SensorAgentProxy::SetMode(int32_t sensorId, const SensorUser *user, int3 int32_t SensorAgentProxy::SetOption(int32_t sensorId, const SensorUser *user, int32_t option) const { - if (user == nullptr || sensorId < 0 || user->callback == nullptr) { + CHKPR(user, OHOS::Sensors::ERROR); + CHKPR(user->callback, OHOS::Sensors::ERROR); + if (sensorId < 0) { SEN_HILOGE("user is null or sensorId is invalid"); return OHOS::Sensors::ERROR; } @@ -302,10 +312,8 @@ int32_t SensorAgentProxy::SetOption(int32_t sensorId, const SensorUser *user, in int32_t SensorAgentProxy::GetAllSensors(SensorInfo **sensorInfo, int32_t *count) const { - if (sensorInfo == nullptr || count == nullptr) { - SEN_HILOGE("sensorInfo or count is null"); - return OHOS::Sensors::ERROR; - } + CHKPR(sensorInfo, OHOS::Sensors::ERROR); + CHKPR(count, OHOS::Sensors::ERROR); SensorServiceClient &client = SensorServiceClient::GetInstance(); std::vector sensorList_ = client.GetSensorList(); if (sensorList_.empty()) { diff --git a/frameworks/native/sensor/src/sensor_data_channel.cpp b/frameworks/native/sensor/src/sensor_data_channel.cpp index ccbd8bfc..fc96e209 100755 --- a/frameworks/native/sensor/src/sensor_data_channel.cpp +++ b/frameworks/native/sensor/src/sensor_data_channel.cpp @@ -45,10 +45,7 @@ constexpr uint32_t STOP_EVENT_ID = 0; int32_t SensorDataChannel::CreateSensorDataChannel(DataChannelCB callBack, void *data) { - if (callBack == nullptr) { - SEN_HILOGE("callBack cannot be null"); - return SENSOR_NATIVE_REGSITER_CB_ERR; - } + CHKPR(callBack, SENSOR_NATIVE_REGSITER_CB_ERR); dataCB_ = callBack; privateData_ = data; return InnerSensorDataChannel(); @@ -56,10 +53,7 @@ int32_t SensorDataChannel::CreateSensorDataChannel(DataChannelCB callBack, void int32_t SensorDataChannel::RestoreSensorDataChannel() { - if (dataCB_ == nullptr) { - SEN_HILOGE("dataCB_ cannot be null"); - return SENSOR_CHANNEL_RESTORE_CB_ERR; - } + CHKPR(dataCB_, SENSOR_NATIVE_REGSITER_CB_ERR); if (GetReceiveDataFd() != -1) { SEN_HILOGE("fd not close"); return SENSOR_CHANNEL_RESTORE_FD_ERR; @@ -79,15 +73,9 @@ int32_t SensorDataChannel::InnerSensorDataChannel() auto listener = std::make_shared(); listener->SetChannel(this); auto myRunner = AppExecFwk::EventRunner::Create(true); - if (myRunner == nullptr) { - SEN_HILOGE("myRunner is null"); - return ERROR; - } + CHKPR(myRunner, ERROR); auto handler = std::make_shared(myRunner); - if (handler == nullptr) { - SEN_HILOGE("handler is null"); - return ERROR; - } + CHKPR(handler, ERROR); int32_t receiveFd = GetReceiveDataFd(); auto inResult = handler->AddFileDescriptorListener(receiveFd, AppExecFwk::FILE_DESCRIPTOR_INPUT_EVENT, listener); if (inResult != 0) { @@ -114,10 +102,8 @@ int32_t SensorDataChannel::InnerSensorDataChannel() int32_t SensorDataChannel::DestroySensorDataChannel() { std::lock_guard eventRunnerLock(eventRunnerMutex_); - if (eventHandler_ == nullptr || eventRunner_ == nullptr) { - SEN_HILOGE("handler or eventRunner is null"); - return ERROR; - } + CHKPR(eventHandler_, ERROR); + CHKPR(eventRunner_, ERROR); int32_t receiveFd = GetReceiveDataFd(); eventHandler_->RemoveFileDescriptorListener(receiveFd); eventHandler_ = nullptr; diff --git a/frameworks/native/sensor/src/sensor_service_client.cpp b/frameworks/native/sensor/src/sensor_service_client.cpp index dbc90460..92fbb2ba 100755 --- a/frameworks/native/sensor/src/sensor_service_client.cpp +++ b/frameworks/native/sensor/src/sensor_service_client.cpp @@ -50,10 +50,7 @@ int32_t SensorServiceClient::InitServiceClient() sensorClientStub_ = new (std::nothrow) SensorClientStub(); } auto systemAbilityManager = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager(); - if (systemAbilityManager == nullptr) { - SEN_HILOGE("systemAbilityManager cannot be null"); - return SENSOR_NATIVE_SAM_ERR; - } + CHKPR(systemAbilityManager, SENSOR_NATIVE_SAM_ERR); int32_t retry = 0; while (retry < GET_SERVICE_MAX_COUNT) { sensorServer_ = iface_cast(systemAbilityManager->GetSystemAbility(SENSOR_SERVICE_ABILITY_ID)); @@ -188,10 +185,7 @@ void SensorServiceClient::ProcessDeathObserver(const wptr &object { CALL_LOG_ENTER; (void)object; - if (dataChannel_ == nullptr) { - SEN_HILOGE("dataChannel_ cannot be null"); - return; - } + CHKPL(dataChannel_); // STEP1 : Destroy revious data channel dataChannel_->DestroySensorDataChannel(); diff --git a/frameworks/native/sensor/src/sensor_service_proxy.cpp b/frameworks/native/sensor/src/sensor_service_proxy.cpp index b6dad630..459cca58 100755 --- a/frameworks/native/sensor/src/sensor_service_proxy.cpp +++ b/frameworks/native/sensor/src/sensor_service_proxy.cpp @@ -180,10 +180,8 @@ std::vector SensorServiceProxy::GetSensorList() ErrCode SensorServiceProxy::TransferDataChannel(const sptr &sensorBasicDataChannel, const sptr &sensorClient) { - if (sensorBasicDataChannel == nullptr || sensorClient == nullptr) { - SEN_HILOGE("sensorBasicDataChannel or sensorClient cannot be null"); - return OBJECT_NULL; - } + CHKPR(sensorBasicDataChannel, OBJECT_NULL); + CHKPR(sensorClient, OBJECT_NULL); MessageParcel data; MessageParcel reply; MessageOption option; @@ -207,10 +205,7 @@ ErrCode SensorServiceProxy::TransferDataChannel(const sptr sensorClient) { - if (sensorClient == nullptr) { - SEN_HILOGE("sensorClient cannot be null"); - return OBJECT_NULL; - } + CHKPR(sensorClient, OBJECT_NULL); MessageParcel data; MessageParcel reply; MessageOption option; diff --git a/services/sensor/hdi_connection/adapter/src/compatible_connection.cpp b/services/sensor/hdi_connection/adapter/src/compatible_connection.cpp index a0a9aa4b..b4e0b798 100644 --- a/services/sensor/hdi_connection/adapter/src/compatible_connection.cpp +++ b/services/sensor/hdi_connection/adapter/src/compatible_connection.cpp @@ -124,14 +124,13 @@ int32_t CompatibleConnection::SetOption(int32_t sensorId, int32_t option) int32_t CompatibleConnection::SensorDataCallback(const struct SensorEvents *event) { - if ((event == nullptr) || (event->dataLen == 0)) { + CHKPR(event, ERR_INVALID_VALUE); + if ((event->dataLen == 0)) { SEN_HILOGE("event is NULL"); return ERR_INVALID_VALUE; } - if (reportDataCb_ == nullptr || reportDataCallback_ == nullptr) { - SEN_HILOGE("reportDataCb_ cannot be null"); - return ERR_NO_INIT; - } + CHKPR(reportDataCallback_, ERR_NO_INIT); + CHKPR(reportDataCb_, ERR_NO_INIT); struct SensorEvent sensorEvent = { .sensorTypeId = event->sensorId, @@ -155,10 +154,7 @@ int32_t CompatibleConnection::SensorDataCallback(const struct SensorEvents *even int32_t CompatibleConnection::RegisteDataReport(ZReportDataCb cb, sptr reportDataCallback) { - if (reportDataCallback == nullptr) { - SEN_HILOGE("failed, reportDataCallback cannot be null"); - return ERR_INVALID_VALUE; - } + CHKPR(reportDataCallback, ERR_INVALID_VALUE); int32_t ret = hdiServiceImpl_.Register(SensorDataCallback); if (ret < 0) { SEN_HILOGE("Register is failed"); diff --git a/services/sensor/hdi_connection/adapter/src/hdi_connection.cpp b/services/sensor/hdi_connection/adapter/src/hdi_connection.cpp index 31b844ae..8c07da00 100644 --- a/services/sensor/hdi_connection/adapter/src/hdi_connection.cpp +++ b/services/sensor/hdi_connection/adapter/src/hdi_connection.cpp @@ -51,10 +51,7 @@ int32_t HdiConnection::ConnectHdi() if (sensorInterface_ != nullptr) { SEN_HILOGI("connect v1_0 hdi success"); eventCallback_ = new (std::nothrow) SensorEventCallback(); - if (eventCallback_ == nullptr) { - SEN_HILOGE("failed to initialize eventCallback"); - return ERR_NO_INIT; - } + CHKPR(eventCallback_, ERR_NO_INIT); RegisterHdiDeathRecipient(); return ERR_OK; } @@ -69,10 +66,7 @@ int32_t HdiConnection::ConnectHdi() int32_t HdiConnection::GetSensorList(std::vector& sensorList) { CALL_LOG_ENTER; - if (sensorInterface_ == nullptr) { - SEN_HILOGE("connect v1_0 hdi failed"); - return ERR_NO_INIT; - } + CHKPR(sensorInterface_, ERR_NO_INIT); std::vector sensorInfos; int32_t ret = sensorInterface_->GetAllSensorInfo(sensorInfos); if (ret != 0) { @@ -97,10 +91,7 @@ int32_t HdiConnection::GetSensorList(std::vector& sensorList) int32_t HdiConnection::EnableSensor(int32_t sensorId) { - if (sensorInterface_ == nullptr) { - SEN_HILOGE("connect v1_0 hdi failed"); - return ERR_NO_INIT; - } + CHKPR(sensorInterface_, ERR_NO_INIT); int32_t ret = sensorInterface_->Enable(sensorId); if (ret < 0) { SEN_HILOGE("connect v1_0 hdi failed"); @@ -112,10 +103,7 @@ int32_t HdiConnection::EnableSensor(int32_t sensorId) int32_t HdiConnection::DisableSensor(int32_t sensorId) { - if (sensorInterface_ == nullptr) { - SEN_HILOGE("connect v1_0 hdi failed"); - return ERR_NO_INIT; - } + CHKPR(sensorInterface_, ERR_NO_INIT); int32_t ret = sensorInterface_->Disable(sensorId); if (ret < 0) { SEN_HILOGE("Disable is failed"); @@ -127,10 +115,7 @@ int32_t HdiConnection::DisableSensor(int32_t sensorId) int32_t HdiConnection::SetBatch(int32_t sensorId, int64_t samplingInterval, int64_t reportInterval) { - if (sensorInterface_ == nullptr) { - SEN_HILOGE("connect v1_0 hdi failed"); - return ERR_NO_INIT; - } + CHKPR(sensorInterface_, ERR_NO_INIT); int32_t ret = sensorInterface_->SetBatch(sensorId, samplingInterval, reportInterval); if (ret < 0) { SEN_HILOGE("SetBatch is failed"); @@ -143,10 +128,7 @@ int32_t HdiConnection::SetBatch(int32_t sensorId, int64_t samplingInterval, int6 int32_t HdiConnection::SetMode(int32_t sensorId, int32_t mode) { CALL_LOG_ENTER; - if (sensorInterface_ == nullptr) { - SEN_HILOGE("connect v1_0 hdi failed"); - return ERR_NO_INIT; - } + CHKPR(sensorInterface_, ERR_NO_INIT); int32_t ret = sensorInterface_->SetMode(sensorId, mode); if (ret < 0) { SEN_HILOGE("SetMode is failed"); @@ -158,10 +140,7 @@ int32_t HdiConnection::SetMode(int32_t sensorId, int32_t mode) int32_t HdiConnection::SetOption(int32_t sensorId, int32_t option) { CALL_LOG_ENTER; - if (sensorInterface_ == nullptr) { - SEN_HILOGE("connect v1_0 hdi failed"); - return ERR_NO_INIT; - } + CHKPR(sensorInterface_, ERR_NO_INIT); int32_t ret = sensorInterface_->SetOption(sensorId, option); if (ret < 0) { SEN_HILOGE("SetOption is failed"); @@ -173,10 +152,8 @@ int32_t HdiConnection::SetOption(int32_t sensorId, int32_t option) int32_t HdiConnection::RegisteDataReport(ZReportDataCb cb, sptr reportDataCallback) { CALL_LOG_ENTER; - if (reportDataCallback == nullptr || sensorInterface_ == nullptr) { - SEN_HILOGE("failed, reportDataCallback or sensorInterface_ cannot be null"); - return ERR_NO_INIT; - } + CHKPR(reportDataCallback, ERR_NO_INIT); + CHKPR(sensorInterface_, ERR_NO_INIT); int32_t ret = sensorInterface_->Register(0, eventCallback_); if (ret < 0) { SEN_HILOGE("Register is failed"); @@ -190,10 +167,7 @@ int32_t HdiConnection::RegisteDataReport(ZReportDataCb cb, sptrUnregister(0, eventCallback_); if (ret < 0) { SEN_HILOGE("Unregister is failed"); @@ -259,25 +233,17 @@ void HdiConnection::deleteSensorBasicInfoState(int32_t sensorId) void HdiConnection::RegisterHdiDeathRecipient() { CALL_LOG_ENTER; - if (sensorInterface_ == nullptr) { - SEN_HILOGE("connect v1_0 hdi failed"); - return; - } + CHKPV(sensorInterface_); hdiDeathObserver_ = new (std::nothrow) DeathRecipientTemplate(*const_cast(this)); - if (hdiDeathObserver_ == nullptr) { - SEN_HILOGE("hdiDeathObserver_ cannot be null"); - return; - } + CHKPV(hdiDeathObserver_); sensorInterface_->AsObject()->AddDeathRecipient(hdiDeathObserver_); } void HdiConnection::UnregisterHdiDeathRecipient() { CALL_LOG_ENTER; - if (sensorInterface_ == nullptr || hdiDeathObserver_ == nullptr) { - SEN_HILOGE("sensorInterface_ or hdiDeathObserver_ is null"); - return; - } + CHKPV(sensorInterface_); + CHKPV(hdiDeathObserver_); sensorInterface_->AsObject()->RemoveDeathRecipient(hdiDeathObserver_); } @@ -285,10 +251,7 @@ void HdiConnection::ProcessDeathObserver(const wptr &object) { CALL_LOG_ENTER; sptr hdiService = object.promote(); - if (hdiService == nullptr) { - SEN_HILOGE("invalid remote object"); - return; - } + CHKPV(hdiService); hdiService->RemoveDeathRecipient(hdiDeathObserver_); eventCallback_ = nullptr; reconnect(); diff --git a/services/sensor/hdi_connection/adapter/src/sensor_event_callback.cpp b/services/sensor/hdi_connection/adapter/src/sensor_event_callback.cpp index 719c7973..587331fb 100644 --- a/services/sensor/hdi_connection/adapter/src/sensor_event_callback.cpp +++ b/services/sensor/hdi_connection/adapter/src/sensor_event_callback.cpp @@ -29,10 +29,8 @@ int32_t SensorEventCallback::OnDataEvent(const HdfSensorEvents& event) { ZReportDataCb reportDataCb_ = HdiConnection_->getReportDataCb(); sptr reportDataCallback_ = HdiConnection_->getReportDataCallback(); - if (reportDataCb_ == nullptr || reportDataCallback_ == nullptr) { - SEN_HILOGE("reportDataCb_ or reportDataCallback_ cannot be null"); - return ERR_NO_INIT; - } + CHKPR(reportDataCb_, ERR_NO_INIT); + CHKPR(reportDataCallback_, ERR_NO_INIT); int32_t dataSize = static_cast(event.data.size()); if (dataSize == 0) { SEN_HILOGI("data is empty"); 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 7a2bb7eb..1c70fdca 100644 --- a/services/sensor/hdi_connection/hardware/src/hdi_service_impl.cpp +++ b/services/sensor/hdi_connection/hardware/src/hdi_service_impl.cpp @@ -66,10 +66,7 @@ void HdiServiceImpl::DataReportThread() int32_t HdiServiceImpl::EnableSensor(uint32_t sensorId) { CALL_LOG_ENTER; - if (g_callback == nullptr) { - SEN_HILOGE("enable sensor failed"); - return -1; - } + CHKPR(g_callback, -1); if (std::find(supportSensors.begin(), supportSensors.end(), sensorId) == supportSensors.end()) { SEN_HILOGE("not support enable sensorId: %{public}d", sensorId); return ERR_NO_INIT; @@ -143,10 +140,7 @@ int32_t HdiServiceImpl::SetOption(int32_t sensorId, uint32_t option) int32_t HdiServiceImpl::Register(RecordDataCallback cb) { - if (cb == nullptr) { - SEN_HILOGE("cb cannot be null"); - return -1; - } + CHKPR(cb, -1); g_callback = cb; return ERR_OK; } 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 f3fda294..43306461 100644 --- a/services/sensor/hdi_connection/interface/src/sensor_hdi_connection.cpp +++ b/services/sensor/hdi_connection/interface/src/sensor_hdi_connection.cpp @@ -29,10 +29,7 @@ constexpr HiLogLabel LABEL = { LOG_CORE, SensorsLogDomain::SENSOR_SERVICE, "Sens int32_t SensorHdiConnection::ConnectHdi() { iSensorHdiConnection_ = std::make_unique(); - if (iSensorHdiConnection_ == nullptr) { - SEN_HILOGE("failed, iSensorHdiConnection_ cannot be null"); - return ERROR; - } + CHKPR(iSensorHdiConnection_, ERROR); int32_t ret = connectHdiService(); if (ret != ERR_OK) { SEN_HILOGE("connect hdi service failed, try to connect compatible connection"); diff --git a/services/sensor/src/client_info.cpp b/services/sensor/src/client_info.cpp index 3576e3c6..3b99d873 100644 --- a/services/sensor/src/client_info.cpp +++ b/services/sensor/src/client_info.cpp @@ -264,7 +264,8 @@ void ClientInfo::RemoveSubscriber(uint32_t sensorId, uint32_t pid) bool ClientInfo::UpdateSensorChannel(int32_t pid, const sptr &channel) { CALL_LOG_ENTER; - if (pid <= INVALID_PID || channel == nullptr) { + CHKPR(channel, false); + if (pid <= INVALID_PID) { SEN_HILOGE("pid or channel is invalid or channel cannot be null"); return false; } @@ -488,10 +489,7 @@ void ClientInfo::StoreEvent(const struct SensorEvent &event) bool ClientInfo::SaveClientPid(const sptr &sensorClient, int32_t pid) { CALL_LOG_ENTER; - if (sensorClient == nullptr) { - SEN_HILOGE("sensorClient cannot be null"); - return false; - } + CHKPF(sensorClient); std::lock_guard lock(clientPidMutex_); auto it = clientPidMap_.find(sensorClient); if (it == clientPidMap_.end()) { @@ -505,10 +503,7 @@ bool ClientInfo::SaveClientPid(const sptr &sensorClient, int32_t int32_t ClientInfo::FindClientPid(const sptr &sensorClient) { CALL_LOG_ENTER; - if (sensorClient == nullptr) { - SEN_HILOGE("sensorClient cannot be null"); - return INVALID_PID; - } + CHKPR(sensorClient, INVALID_PID); std::lock_guard lock(clientPidMutex_); auto it = clientPidMap_.find(sensorClient); if (it == clientPidMap_.end()) { @@ -521,10 +516,7 @@ int32_t ClientInfo::FindClientPid(const sptr &sensorClient) void ClientInfo::DestroyClientPid(const sptr &sensorClient) { CALL_LOG_ENTER; - if (sensorClient == nullptr) { - SEN_HILOGE("sensorClient cannot be null"); - return; - } + CHKPV(sensorClient); std::lock_guard lock(clientPidMutex_); auto it = clientPidMap_.find(sensorClient); if (it == clientPidMap_.end()) { diff --git a/services/sensor/src/flush_info_record.cpp b/services/sensor/src/flush_info_record.cpp index f76987ff..54f7ea1b 100644 --- a/services/sensor/src/flush_info_record.cpp +++ b/services/sensor/src/flush_info_record.cpp @@ -51,10 +51,7 @@ void FlushInfoRecord::ClearFlushInfoItem(uint32_t sensorId) ErrCode FlushInfoRecord::SetFlushInfo(uint32_t sensorId, const sptr &channel, bool isFirstFlush) { SEN_HILOGD("sensorId : %{public}u", sensorId); - if (channel == nullptr) { - SEN_HILOGE("failed, channel cannot be null"); - return INVALID_POINTER; - } + CHKPR(channel, INVALID_POINTER); struct FlushInfo flush(channel, isFirstFlush); std::lock_guard flushLock(flushInfoMutex_); /* If the sensorId can be found, it indicates that other processes have flushed on this sensor, @@ -103,10 +100,7 @@ ErrCode FlushInfoRecord::FlushProcess(const uint32_t sensorId, const uint32_t fl return ret; } sptr channel = clientInfo_.GetSensorChannelByPid(pid); - if (channel == nullptr) { - SEN_HILOGE("channel cannot be null"); - return ERROR; - } + CHKPR(channel, ERROR); ret = SetFlushInfo(sensorId, channel, false); if (ret != ERR_OK) { SEN_HILOGE("set flush info failed"); diff --git a/services/sensor/src/sensor_data_processer.cpp b/services/sensor/src/sensor_data_processer.cpp index 0a543ffc..a08f67ec 100644 --- a/services/sensor/src/sensor_data_processer.cpp +++ b/services/sensor/src/sensor_data_processer.cpp @@ -74,10 +74,7 @@ void SensorDataProcesser::SendNoneFifoCacheData(std::unordered_map> channelFifoList; sptr fifoCacheData = new (std::nothrow) FifoCacheData(); - if (fifoCacheData == nullptr) { - SEN_HILOGE("fifoCacheData cannot be null"); - return; - } + CHKPV(fifoCacheData); fifoCacheData->SetChannel(channel); channelFifoList.push_back(fifoCacheData); dataCountMap_.insert(std::make_pair(sensorId, channelFifoList)); @@ -102,10 +99,7 @@ void SensorDataProcesser::SendNoneFifoCacheData(std::unordered_map fifoCacheData = new (std::nothrow) FifoCacheData(); - if (fifoCacheData == nullptr) { - SEN_HILOGE("failed, fifoCacheData cannot be null"); - return; - } + CHKPV(fifoCacheData); fifoCacheData->SetChannel(channel); dataCountIt->second.push_back(fifoCacheData); SendRawData(cacheBuf, channel, sendEvents); @@ -126,10 +120,7 @@ void SensorDataProcesser::SendFifoCacheData(std::unordered_map> channelFifoList; sptr fifoCacheData = new (std::nothrow) FifoCacheData(); - if (fifoCacheData == nullptr) { - SEN_HILOGE("fifoCacheData cannot be null"); - return; - } + CHKPV(fifoCacheData); fifoCacheData->SetChannel(channel); channelFifoList.push_back(fifoCacheData); dataCountMap_.insert(std::make_pair(sensorId, channelFifoList)); @@ -162,10 +153,7 @@ void SensorDataProcesser::SendFifoCacheData(std::unordered_map fifoCacheData = new (std::nothrow) FifoCacheData(); - if (fifoCacheData == nullptr) { - SEN_HILOGE("failed, fifoCacheData cannot be null"); - return; - } + CHKPV(fifoCacheData); fifoCacheData->SetChannel(channel); dataCountIt->second.push_back(fifoCacheData); } @@ -173,10 +161,7 @@ void SensorDataProcesser::SendFifoCacheData(std::unordered_map &channel, struct SensorEvent &event) { - if (channel == nullptr) { - SEN_HILOGE("channel cannot be null"); - return; - } + CHKPV(channel); uint32_t sensorId = static_cast(event.sensorTypeId); if (sensorId == FLUSH_COMPLETE_ID) { sensorId = static_cast(event.sensorTypeId); @@ -231,7 +216,8 @@ bool SensorDataProcesser::CheckSendDataPermission(sptr c void SensorDataProcesser::SendRawData(std::unordered_map &cacheBuf, sptr channel, std::vector event) { - if (channel == nullptr || event.empty()) { + CHKPV(channel); + if (event.empty()) { SEN_HILOGE("channel cannot be null or event cannot be empty"); return; } @@ -271,10 +257,7 @@ void SensorDataProcesser::SendRawData(std::unordered_map &channel) { - if (channel == nullptr) { - SEN_HILOGE("channel cannot be null"); - return INVALID_POINTER; - } + CHKPR(channel, INVALID_POINTER); int32_t ret = ERR_OK; auto &cacheBuf = const_cast &>(channel->GetDataCacheBuf()); uint32_t sensorId = static_cast(event.sensorTypeId); @@ -355,10 +338,7 @@ void SensorDataProcesser::EventFilter(struct CircularEventBuf &eventsBuf) int32_t SensorDataProcesser::ProcessEvents(sptr dataCallback) { - if (dataCallback == nullptr) { - SEN_HILOGE("dataCallback cannot be null"); - return INVALID_POINTER; - } + CHKPR(dataCallback, INVALID_POINTER); std::unique_lock lk(ISensorHdiConnection::dataMutex_); ISensorHdiConnection::dataCondition_.wait(lk); auto &eventsBuf = dataCallback->GetEventData(); @@ -381,10 +361,7 @@ int32_t SensorDataProcesser::ProcessEvents(sptr dataCallback int32_t SensorDataProcesser::SendEvents(sptr &channel, struct SensorEvent &event) { - if (channel == nullptr) { - SEN_HILOGE("channel cannot be null"); - return INVALID_POINTER; - } + CHKPR(channel, INVALID_POINTER); clientInfo_.UpdateDataQueue(event.sensorTypeId, event); auto &cacheBuf = channel->GetDataCacheBuf(); if (cacheBuf.empty()) { diff --git a/services/sensor/src/sensor_dump.cpp b/services/sensor/src/sensor_dump.cpp index a3ac9a78..df09f2d9 100644 --- a/services/sensor/src/sensor_dump.cpp +++ b/services/sensor/src/sensor_dump.cpp @@ -214,10 +214,7 @@ bool SensorDump::DumpSensorData(int32_t fd, ClientInfo &clientInfo, const std::v sensorData.second.pop(); timespec time = { 0, 0 }; struct tm *timeinfo = localtime(&(time.tv_sec)); - if (timeinfo == nullptr) { - SEN_HILOGE("timeinfo cannot be null"); - return false; - } + CHKPF(timeinfo); dprintf(fd, " %2d (ts=%.9f, time=%02d:%02d:%02d.%03d) | data:%s", ++j, data.timestamp / 1e9, timeinfo->tm_hour, timeinfo->tm_min, timeinfo->tm_sec, int32_t { (time.tv_nsec / MS_NS) }, GetDataBySensorId(sensorId, data).c_str()); @@ -231,10 +228,7 @@ void SensorDump::DumpCurrentTime(int32_t fd) timespec curTime = { 0, 0 }; clock_gettime(CLOCK_REALTIME, &curTime); struct tm *timeinfo = localtime(&(curTime.tv_sec)); - if (timeinfo == nullptr) { - SEN_HILOGE("timeinfo cannot be null"); - return; - } + CHKPV(timeinfo); dprintf(fd, "Current time: %02d:%02d:%02d.%03d\n", timeinfo->tm_hour, timeinfo->tm_min, timeinfo->tm_sec, int32_t { (curTime.tv_nsec / MS_NS) }); } diff --git a/services/sensor/src/sensor_service.cpp b/services/sensor/src/sensor_service.cpp index 333b008c..2d5c0f16 100644 --- a/services/sensor/src/sensor_service.cpp +++ b/services/sensor/src/sensor_service.cpp @@ -78,10 +78,7 @@ void SensorService::OnStart() return; } sensorDataProcesser_ = new (std::nothrow) SensorDataProcesser(sensorMap_); - if (sensorDataProcesser_ == nullptr) { - SEN_HILOGE("failed, sensorDataProcesser_ cannot be null"); - return; - } + CHKPV(sensorDataProcesser_); if (!InitSensorPolicy()) { SEN_HILOGE("Init sensor policy error"); } @@ -107,10 +104,7 @@ bool SensorService::InitInterface() bool SensorService::InitDataCallback() { reportDataCallback_ = new (std::nothrow) ReportDataCallback(); - if (reportDataCallback_ == nullptr) { - SEN_HILOGE("failed, reportDataCallback_ cannot be null"); - return false; - } + CHKPF(reportDataCallback_); ZReportDataCb cb = &ReportDataCallback::ReportEventCallback; auto ret = sensorHdiConnection_.RegisteDataReport(cb, reportDataCallback_); if (ret != ERR_OK) { @@ -208,10 +202,7 @@ void SensorService::ReportOnChangeData(uint32_t sensorId) return; } sptr channel = clientInfo_.GetSensorChannelByPid(this->GetCallingPid()); - if (channel == nullptr) { - SEN_HILOGE("there is no channel to be reported"); - return; - } + CHKPV(channel); auto sendRet = channel->SendData(&event, sizeof(event)); if (sendRet != ERR_OK) { SEN_HILOGE("send data failed"); @@ -365,10 +356,7 @@ std::vector SensorService::GetSensorList() ErrCode SensorService::TransferDataChannel(const sptr &sensorBasicDataChannel, const sptr &sensorClient) { - if ((sensorBasicDataChannel == nullptr)) { - SEN_HILOGE("sensorBasicDataChannel cannot be null"); - return ERR_NO_INIT; - } + CHKPR(sensorBasicDataChannel, ERR_NO_INIT); auto pid = this->GetCallingPid(); auto uid = this->GetCallingUid(); auto callerToken = this->GetCallingTokenID(); @@ -409,10 +397,7 @@ void SensorService::ProcessDeathObserver(const wptr &object) { CALL_LOG_ENTER; sptr client = object.promote(); - if (client == nullptr) { - SEN_HILOGE("client cannot be null"); - return; - } + CHKPV(client); int32_t pid = clientInfo_.FindClientPid(client); if (pid == INVALID_PID) { SEN_HILOGE("pid is -1"); @@ -429,10 +414,7 @@ void SensorService::RegisterClientDeathRecipient(sptr sensorClien CALL_LOG_ENTER; sptr client = iface_cast(sensorClient); clientDeathObserver_ = new (std::nothrow) DeathRecipientTemplate(*const_cast(this)); - if (clientDeathObserver_ == nullptr) { - SEN_HILOGE("clientDeathObserver_ cannot be null"); - return; - } + CHKPV(clientDeathObserver_); client->AsObject()->AddDeathRecipient(clientDeathObserver_); clientInfo_.SaveClientPid(sensorClient, pid); } @@ -442,10 +424,7 @@ void SensorService::UnregisterClientDeathRecipient(sptr sensorCli CALL_LOG_ENTER; sptr client = iface_cast(sensorClient); clientDeathObserver_ = new (std::nothrow) DeathRecipientTemplate(*const_cast(this)); - if (clientDeathObserver_ == nullptr) { - SEN_HILOGE("clientDeathObserver_ cannot be null"); - return; - } + CHKPV(clientDeathObserver_); client->AsObject()->RemoveDeathRecipient(clientDeathObserver_); clientInfo_.DestroyClientPid(sensorClient); } diff --git a/services/sensor/src/sensor_service_stub.cpp b/services/sensor/src/sensor_service_stub.cpp index a1265430..d401e797 100644 --- a/services/sensor/src/sensor_service_stub.cpp +++ b/services/sensor/src/sensor_service_stub.cpp @@ -142,30 +142,21 @@ ErrCode SensorServiceStub::CreateDataChannelInner(MessageParcel &data, MessagePa { (void)reply; sptr sensorChannel = new (std::nothrow) SensorBasicDataChannel(); - if (sensorChannel == nullptr) { - SEN_HILOGE("sensorChannel cannot be null"); - return OBJECT_NULL; - } + CHKPR(sensorChannel, OBJECT_NULL); auto ret = sensorChannel->CreateSensorBasicChannel(data); if (ret != ERR_OK) { SEN_HILOGE("CreateSensorBasicChannel ret : %{public}d", ret); return OBJECT_NULL; } sptr sensorClient = data.ReadRemoteObject(); - if (sensorClient == nullptr) { - SEN_HILOGE("sensorClient cannot be null"); - return OBJECT_NULL; - } + CHKPR(sensorClient, OBJECT_NULL); return TransferDataChannel(sensorChannel, sensorClient); } ErrCode SensorServiceStub::DestroyDataChannelInner(MessageParcel &data, MessageParcel &reply) { sptr sensorClient = data.ReadRemoteObject(); - if (sensorClient == nullptr) { - SEN_HILOGE("sensorClient cannot be null"); - return OBJECT_NULL; - } + CHKPR(sensorClient, OBJECT_NULL); return DestroySensorChannel(sensorClient); } } // namespace Sensors diff --git a/utils/src/report_data_callback.cpp b/utils/src/report_data_callback.cpp index 3f00ae35..82dc130d 100644 --- a/utils/src/report_data_callback.cpp +++ b/utils/src/report_data_callback.cpp @@ -53,10 +53,7 @@ ReportDataCallback::~ReportDataCallback() int32_t ReportDataCallback::ReportEventCallback(const struct SensorEvent* event, sptr cb) { - if (event == nullptr) { - SEN_HILOGE("sensor data is null"); - return ERROR; - } + CHKPR(event, ERROR); if (cb == nullptr || cb->eventsBuf_.circularBuf == nullptr) { SEN_HILOGE("callback or circularBuf or event cannot be null"); if (event->data != nullptr) { diff --git a/utils/src/sensor.cpp b/utils/src/sensor.cpp index 76f72481..7fa75910 100644 --- a/utils/src/sensor.cpp +++ b/utils/src/sensor.cpp @@ -231,10 +231,7 @@ bool Sensor::Marshalling(Parcel &parcel) const std::unique_ptr Sensor::Unmarshalling(Parcel &parcel) { auto sensor = std::make_unique(); - if (sensor == nullptr) { - SEN_HILOGE("sensor cannot be null"); - return nullptr; - } + CHKPP(sensor); if (!sensor->ReadFromParcel(parcel)) { SEN_HILOGE("ReadFromParcel is failed"); diff --git a/utils/src/sensor_basic_data_channel.cpp b/utils/src/sensor_basic_data_channel.cpp index 2b513af9..9ff7b6f1 100755 --- a/utils/src/sensor_basic_data_channel.cpp +++ b/utils/src/sensor_basic_data_channel.cpp @@ -148,7 +148,8 @@ void SensorBasicDataChannel::CloseSendFd() int32_t SensorBasicDataChannel::SendData(const void *vaddr, size_t size) { - if (vaddr == nullptr || sendFd_ < 0) { + CHKPR(vaddr, SENSOR_CHANNEL_SEND_ADDR_ERR); + if (sendFd_ < 0) { SEN_HILOGE("failed, param is invalid"); return SENSOR_CHANNEL_SEND_ADDR_ERR; } @@ -165,7 +166,8 @@ int32_t SensorBasicDataChannel::SendData(const void *vaddr, size_t size) int32_t SensorBasicDataChannel::ReceiveData(void *vaddr, size_t size) { - if (vaddr == nullptr || (receiveFd_ == -1)) { + CHKPR(vaddr, SENSOR_CHANNEL_SEND_ADDR_ERR); + if (receiveFd_ == -1) { SEN_HILOGE("failed, vaddr is null or receiveFd_ invalid"); return SENSOR_CHANNEL_RECEIVE_ADDR_ERR; } -- Gitee From b133bbea334bf3567a4e2e0900a88404d873c5b0 Mon Sep 17 00:00:00 2001 From: li-yaoyao777 Date: Sat, 2 Apr 2022 09:14:58 +0800 Subject: [PATCH 2/9] my_file_descriptor_listener.cpp Signed-off-by: li-yaoyao777 --- frameworks/native/sensor/src/my_file_descriptor_listener.cpp | 3 --- 1 file changed, 3 deletions(-) diff --git a/frameworks/native/sensor/src/my_file_descriptor_listener.cpp b/frameworks/native/sensor/src/my_file_descriptor_listener.cpp index 98c4d51b..b24a95a6 100644 --- a/frameworks/native/sensor/src/my_file_descriptor_listener.cpp +++ b/frameworks/native/sensor/src/my_file_descriptor_listener.cpp @@ -32,9 +32,6 @@ MyFileDescriptorListener::MyFileDescriptorListener() channel_ = nullptr; receiveDataBuff_ = new (std::nothrow) TransferSensorEvents[sizeof(struct TransferSensorEvents) * RECEIVE_DATA_SIZE]; - if (receiveDataBuff_ == nullptr) { - SEN_HILOGE("receiveDataBuff_ memory request failed"); - } CHKPL(receiveDataBuff_); } -- Gitee From 31937c5d1d0c0b45e525aaf5ab85ee695cb9b638 Mon Sep 17 00:00:00 2001 From: li-yaoyao777 Date: Sat, 2 Apr 2022 09:16:26 +0800 Subject: [PATCH 3/9] sensor_agent_proxy.cpp Signed-off-by: li-yaoyao777 --- frameworks/native/sensor/src/sensor_agent_proxy.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frameworks/native/sensor/src/sensor_agent_proxy.cpp b/frameworks/native/sensor/src/sensor_agent_proxy.cpp index 93addeeb..94903302 100644 --- a/frameworks/native/sensor/src/sensor_agent_proxy.cpp +++ b/frameworks/native/sensor/src/sensor_agent_proxy.cpp @@ -101,7 +101,7 @@ void SensorAgentProxy::HandleSensorData(struct SensorEvent *events, int32_t num, for (int32_t i = 0; i < num; ++i) { eventStream = events[i]; CHKPV(eventStream.data); - if (g_subscribeMap.find(eventStream.sensorTypeId) == g_subscribeMap.end()) { + if (g_subscribeMap[eventStream.sensorTypeId] == nullptr) { SEN_HILOGE("sensorTypeId not in g_subscribeMap"); return; } -- Gitee From 0a9e58ae47fbf6f7e8f2041abbedc15d6c11f02e Mon Sep 17 00:00:00 2001 From: li-yaoyao777 Date: Sat, 2 Apr 2022 09:16:57 +0800 Subject: [PATCH 4/9] sensor_agent_proxy.cpp Signed-off-by: li-yaoyao777 --- frameworks/native/sensor/src/sensor_agent_proxy.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frameworks/native/sensor/src/sensor_agent_proxy.cpp b/frameworks/native/sensor/src/sensor_agent_proxy.cpp index 94903302..93addeeb 100644 --- a/frameworks/native/sensor/src/sensor_agent_proxy.cpp +++ b/frameworks/native/sensor/src/sensor_agent_proxy.cpp @@ -101,7 +101,7 @@ void SensorAgentProxy::HandleSensorData(struct SensorEvent *events, int32_t num, for (int32_t i = 0; i < num; ++i) { eventStream = events[i]; CHKPV(eventStream.data); - if (g_subscribeMap[eventStream.sensorTypeId] == nullptr) { + if (g_subscribeMap.find(eventStream.sensorTypeId) == g_subscribeMap.end()) { SEN_HILOGE("sensorTypeId not in g_subscribeMap"); return; } -- Gitee From a5fba484eaa65ca93b8923fb3d44b72838be2e06 Mon Sep 17 00:00:00 2001 From: li-yaoyao777 Date: Sat, 2 Apr 2022 09:19:40 +0800 Subject: [PATCH 5/9] sensor_agent_proxy.cpp Signed-off-by: li-yaoyao777 --- frameworks/native/sensor/src/sensor_agent_proxy.cpp | 3 --- 1 file changed, 3 deletions(-) diff --git a/frameworks/native/sensor/src/sensor_agent_proxy.cpp b/frameworks/native/sensor/src/sensor_agent_proxy.cpp index 93addeeb..4283ad2b 100644 --- a/frameworks/native/sensor/src/sensor_agent_proxy.cpp +++ b/frameworks/native/sensor/src/sensor_agent_proxy.cpp @@ -102,9 +102,6 @@ void SensorAgentProxy::HandleSensorData(struct SensorEvent *events, int32_t num, eventStream = events[i]; CHKPV(eventStream.data); if (g_subscribeMap.find(eventStream.sensorTypeId) == g_subscribeMap.end()) { - SEN_HILOGE("sensorTypeId not in g_subscribeMap"); - return; - } g_subscribeMap[eventStream.sensorTypeId]->callback(&eventStream); } } -- Gitee From 7739a85370ac883afa1caa42f4fa5e919be888e0 Mon Sep 17 00:00:00 2001 From: li-yaoyao777 Date: Sat, 2 Apr 2022 09:20:17 +0800 Subject: [PATCH 6/9] sensor_agent_proxy.cpp Signed-off-by: li-yaoyao777 --- frameworks/native/sensor/src/sensor_agent_proxy.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/frameworks/native/sensor/src/sensor_agent_proxy.cpp b/frameworks/native/sensor/src/sensor_agent_proxy.cpp index 4283ad2b..93addeeb 100644 --- a/frameworks/native/sensor/src/sensor_agent_proxy.cpp +++ b/frameworks/native/sensor/src/sensor_agent_proxy.cpp @@ -102,6 +102,9 @@ void SensorAgentProxy::HandleSensorData(struct SensorEvent *events, int32_t num, eventStream = events[i]; CHKPV(eventStream.data); if (g_subscribeMap.find(eventStream.sensorTypeId) == g_subscribeMap.end()) { + SEN_HILOGE("sensorTypeId not in g_subscribeMap"); + return; + } g_subscribeMap[eventStream.sensorTypeId]->callback(&eventStream); } } -- Gitee From 782affe21aac329a90c8c15ffe4f45f55d25d73d Mon Sep 17 00:00:00 2001 From: li-yaoyao777 Date: Sat, 2 Apr 2022 09:25:29 +0800 Subject: [PATCH 7/9] sensor_agent_proxy.cpp Signed-off-by: li-yaoyao777 --- frameworks/native/sensor/src/sensor_agent_proxy.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frameworks/native/sensor/src/sensor_agent_proxy.cpp b/frameworks/native/sensor/src/sensor_agent_proxy.cpp index 93addeeb..dc3cb809 100644 --- a/frameworks/native/sensor/src/sensor_agent_proxy.cpp +++ b/frameworks/native/sensor/src/sensor_agent_proxy.cpp @@ -100,11 +100,11 @@ void SensorAgentProxy::HandleSensorData(struct SensorEvent *events, int32_t num, struct SensorEvent eventStream; for (int32_t i = 0; i < num; ++i) { eventStream = events[i]; - CHKPV(eventStream.data); if (g_subscribeMap.find(eventStream.sensorTypeId) == g_subscribeMap.end()) { SEN_HILOGE("sensorTypeId not in g_subscribeMap"); return; } + CHKPV(g_subscribeMap[eventStream.sensorTypeId]); g_subscribeMap[eventStream.sensorTypeId]->callback(&eventStream); } } -- Gitee From a0a283c032507c9bb353e96627b87ce13ec18a94 Mon Sep 17 00:00:00 2001 From: li-yaoyao777 Date: Sat, 2 Apr 2022 16:56:07 +0800 Subject: [PATCH 8/9] =?UTF-8?q?=E4=BF=AE=E6=94=B9sensor=E5=91=8A=E8=AD=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: li-yaoyao777 --- frameworks/native/sensor/src/sensor_agent_proxy.cpp | 6 +++--- .../sensor/hdi_connection/hardware/src/hdi_service_impl.cpp | 4 ++-- services/sensor/src/sensor_data_processer.cpp | 1 - 3 files changed, 5 insertions(+), 6 deletions(-) diff --git a/frameworks/native/sensor/src/sensor_agent_proxy.cpp b/frameworks/native/sensor/src/sensor_agent_proxy.cpp index dc3cb809..a87511f4 100644 --- a/frameworks/native/sensor/src/sensor_agent_proxy.cpp +++ b/frameworks/native/sensor/src/sensor_agent_proxy.cpp @@ -164,16 +164,16 @@ int32_t SensorAgentProxy::ActivateSensor(int32_t sensorId, const SensorUser *use CHKPR(user->callback, OHOS::Sensors::ERROR); if (sensorId < 0) { SEN_HILOGE("user is null or sensorId is invalid"); - return OHOS::Sensors::ERROR; + return ERROR; } if (g_samplingInterval < 0 || g_reportInterval < 0) { SEN_HILOGE("samplingPeroid or g_reportInterval is invalid"); - return OHOS::Sensors::ERROR; + return ERROR; } std::lock_guard subscribeLock(subscribeMutex_); if ((g_subscribeMap.find(sensorId) == g_subscribeMap.end()) || (g_subscribeMap[sensorId] != user)) { SEN_HILOGE("subscribe sensorId first"); - return OHOS::Sensors::ERROR; + return ERROR; } SensorServiceClient &client = SensorServiceClient::GetInstance(); int32_t ret = client.EnableSensor(sensorId, g_samplingInterval, g_reportInterval); 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 1c70fdca..3916dc76 100644 --- a/services/sensor/hdi_connection/hardware/src/hdi_service_impl.cpp +++ b/services/sensor/hdi_connection/hardware/src/hdi_service_impl.cpp @@ -66,7 +66,7 @@ void HdiServiceImpl::DataReportThread() int32_t HdiServiceImpl::EnableSensor(uint32_t sensorId) { CALL_LOG_ENTER; - CHKPR(g_callback, -1); + CHKPR(g_callback, ERROR); if (std::find(supportSensors.begin(), supportSensors.end(), sensorId) == supportSensors.end()) { SEN_HILOGE("not support enable sensorId: %{public}d", sensorId); return ERR_NO_INIT; @@ -140,7 +140,7 @@ int32_t HdiServiceImpl::SetOption(int32_t sensorId, uint32_t option) int32_t HdiServiceImpl::Register(RecordDataCallback cb) { - CHKPR(cb, -1); + CHKPR(cb, ERROR); g_callback = cb; return ERR_OK; } diff --git a/services/sensor/src/sensor_data_processer.cpp b/services/sensor/src/sensor_data_processer.cpp index a08f67ec..86e75338 100644 --- a/services/sensor/src/sensor_data_processer.cpp +++ b/services/sensor/src/sensor_data_processer.cpp @@ -218,7 +218,6 @@ void SensorDataProcesser::SendRawData(std::unordered_map Date: Sat, 2 Apr 2022 16:58:12 +0800 Subject: [PATCH 9/9] =?UTF-8?q?=E4=BF=AE=E6=94=B9sensor=E5=91=8A=E8=AD=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: li-yaoyao777 --- utils/src/sensor_basic_data_channel.cpp | 2 -- 1 file changed, 2 deletions(-) diff --git a/utils/src/sensor_basic_data_channel.cpp b/utils/src/sensor_basic_data_channel.cpp index 9ff7b6f1..c26b4e54 100755 --- a/utils/src/sensor_basic_data_channel.cpp +++ b/utils/src/sensor_basic_data_channel.cpp @@ -167,10 +167,8 @@ int32_t SensorBasicDataChannel::SendData(const void *vaddr, size_t size) int32_t SensorBasicDataChannel::ReceiveData(void *vaddr, size_t size) { CHKPR(vaddr, SENSOR_CHANNEL_SEND_ADDR_ERR); - if (receiveFd_ == -1) { SEN_HILOGE("failed, vaddr is null or receiveFd_ invalid"); return SENSOR_CHANNEL_RECEIVE_ADDR_ERR; - } ssize_t length; do { length = recv(receiveFd_, vaddr, size, MSG_DONTWAIT); -- Gitee