From 01cfaef1f3e79f1b6176357549e6a3454821b75a Mon Sep 17 00:00:00 2001 From: hui1975 Date: Thu, 27 Oct 2022 15:17:09 +0800 Subject: [PATCH 01/22] =?UTF-8?q?freeWork(work)=E6=8F=90=E5=89=8D=EF=BC=8C?= =?UTF-8?q?=E9=81=BF=E5=85=8D=E5=86=85=E5=AD=98=E6=B3=84=E6=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: hui1975 Change-Id: I523c0543082b6b018506369ac303715391d2f176 --- interfaces/plugin/src/sensor_napi_utils.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/interfaces/plugin/src/sensor_napi_utils.cpp b/interfaces/plugin/src/sensor_napi_utils.cpp index 4cfecb68..184edfeb 100644 --- a/interfaces/plugin/src/sensor_napi_utils.cpp +++ b/interfaces/plugin/src/sensor_napi_utils.cpp @@ -492,6 +492,7 @@ void EmitUvEventLoop(sptr asyncCallbackInfo) int32_t ret = uv_queue_work(loop, work, [] (uv_work_t *work) { }, [] (uv_work_t *work, int status) { CHKPV(work); sptr asyncCallbackInfo(static_cast(work->data)); + freeWork(work); /** * After the asynchronous task is created, the asyncCallbackInfo reference count is reduced * to 0 destructions, so you need to add 1 to the asyncCallbackInfo reference count when the @@ -531,7 +532,6 @@ void EmitUvEventLoop(sptr asyncCallbackInfo) } napi_close_handle_scope(asyncCallbackInfo->env, scope); asyncCallbackInfo->work = nullptr; - freeWork(work); }); if (ret != 0) { SEN_HILOGE("uv_queue_work fail"); -- Gitee From 67cbab9d25b74e4fd6069baf91d5085d6ca10f54 Mon Sep 17 00:00:00 2001 From: hui1975 Date: Thu, 27 Oct 2022 15:25:07 +0800 Subject: [PATCH 02/22] =?UTF-8?q?=E5=A2=9E=E5=8A=A0argv[i]=E5=88=A4?= =?UTF-8?q?=E7=A9=BA=EF=BC=8C=E5=8F=AA=E5=9C=A8=E9=9D=9E=E7=A9=BA=E6=97=B6?= =?UTF-8?q?delete[]?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: hui1975 Change-Id: I5b8f50b8001b3324d8760dd17331b1beb4dd644e --- services/sensor/src/sensor_dump.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/services/sensor/src/sensor_dump.cpp b/services/sensor/src/sensor_dump.cpp index d1d298b9..5a1c8a0c 100644 --- a/services/sensor/src/sensor_dump.cpp +++ b/services/sensor/src/sensor_dump.cpp @@ -173,6 +173,9 @@ void SensorDump::ParseCommand(int32_t fd, const std::vector &args, } RELEASE_RES: for (size_t i = 0; i < args.size(); ++i) { + if (argv[i] == nullptr) { + continue; + } delete[] argv[i]; } delete[] argv; -- Gitee From 414fdeac17cc3236663972acf09f81c8fbe8bd16 Mon Sep 17 00:00:00 2001 From: hui1975 Date: Thu, 27 Oct 2022 15:43:24 +0800 Subject: [PATCH 03/22] =?UTF-8?q?=E6=99=BA=E8=83=BD=E6=8C=87=E9=92=88?= =?UTF-8?q?=E5=88=9D=E5=A7=8B=E5=8C=96=E4=B8=BAnullptr?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: hui1975 Change-Id: I2af2fdbefee7000fffd5eac496c57820ce3bb225 --- services/sensor/include/sensor_service.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/services/sensor/include/sensor_service.h b/services/sensor/include/sensor_service.h index a436cf89..62137d5b 100644 --- a/services/sensor/include/sensor_service.h +++ b/services/sensor/include/sensor_service.h @@ -78,11 +78,11 @@ private: ClientInfo &clientInfo_ = ClientInfo::GetInstance(); SensorManager &sensorManager_ = SensorManager::GetInstance(); FlushInfoRecord &flushInfo_ = FlushInfoRecord::GetInstance(); - sptr sensorDataProcesser_; - sptr reportDataCallback_; + sptr sensorDataProcesser_ = nullptr; + sptr reportDataCallback_ = nullptr; std::mutex uidLock_; // death recipient of sensor client - sptr clientDeathObserver_; + sptr clientDeathObserver_ = nullptr; ErrCode SaveSubscriber(uint32_t sensorId, int64_t samplingPeriodNs, int64_t maxReportDelayNs); }; } // namespace Sensors -- Gitee From 89db21e7d477e21e8e9aad52d63c3269967fac46 Mon Sep 17 00:00:00 2001 From: hui1975 Date: Thu, 27 Oct 2022 16:25:13 +0800 Subject: [PATCH 04/22] =?UTF-8?q?=E5=B0=86=E7=BB=93=E6=9E=84=E4=BD=93?= =?UTF-8?q?=E4=B8=AD=E7=9A=84=E6=8C=87=E9=92=88=E5=88=9D=E5=A7=8B=E5=8C=96?= =?UTF-8?q?=E4=B8=BAnullptr?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: hui1975 Change-Id: I429bb16bd81acf8de557f91175494d2056fa0e93 --- interfaces/native/include/sensor_agent_type.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/interfaces/native/include/sensor_agent_type.h b/interfaces/native/include/sensor_agent_type.h index 85531a58..78479e4e 100644 --- a/interfaces/native/include/sensor_agent_type.h +++ b/interfaces/native/include/sensor_agent_type.h @@ -126,7 +126,7 @@ typedef struct SensorEvent { int64_t timestamp; /**< Time when sensor data was reported */ uint32_t option; /**< Sensor data options, including the measurement range and accuracy */ int32_t mode; /**< Sensor data reporting mode (described in {@link SensorMode}) */ - uint8_t *data; /**< Sensor data */ + uint8_t *data = nullptr; /**< Sensor data */ uint32_t dataLen; /**< Sensor data length */ } SensorEvent; @@ -154,7 +154,7 @@ typedef struct UserData { typedef struct SensorUser { char name[NAME_MAX_LEN]; /**< Name of the sensor data subscriber */ RecordSensorCallback callback; /**< Callback for reporting sensor data */ - UserData *userData; /**< Reserved field for the sensor data subscriber */ + UserData *userData = nullptr; /**< Reserved field for the sensor data subscriber */ } SensorUser; /** -- Gitee From e9dc1ae401fb4b2a2b8cef4b5da2410d30f06475 Mon Sep 17 00:00:00 2001 From: wuzhihuitmac Date: Thu, 27 Oct 2022 13:01:57 +0000 Subject: [PATCH 05/22] Modify View Comments Signed-off-by: wuzhihuitmac Change-Id: Ic1df57177c6bbc85fc854a67df488d6686d6b9b2 --- .../native/sensor/src/sensor_agent_proxy.cpp | 24 ++++++++++--------- interfaces/plugin/src/sensor_js.cpp | 5 ++++ 2 files changed, 18 insertions(+), 11 deletions(-) mode change 100644 => 100755 frameworks/native/sensor/src/sensor_agent_proxy.cpp mode change 100644 => 100755 interfaces/plugin/src/sensor_js.cpp diff --git a/frameworks/native/sensor/src/sensor_agent_proxy.cpp b/frameworks/native/sensor/src/sensor_agent_proxy.cpp old mode 100644 new mode 100755 index 7b28161c..5aa48ae2 --- a/frameworks/native/sensor/src/sensor_agent_proxy.cpp +++ b/frameworks/native/sensor/src/sensor_agent_proxy.cpp @@ -300,26 +300,28 @@ int32_t SensorAgentProxy::ConvertSensorInfos() const } sensorInfos_ = (SensorInfo *)malloc(sizeof(SensorInfo) * count); CHKPR(sensorInfos_, ERROR); + SensorInfo *sensorInfo = sensorInfos_; for (size_t i = 0; i < count; ++i) { - errno_t ret = strcpy_s((sensorInfos_ + i)->sensorName, NAME_MAX_LEN, + sensorInfo += i; + errno_t ret = strcpy_s(sensorInfo->sensorName, NAME_MAX_LEN, sensorList[i].GetSensorName().c_str()); CHKCR(ret == EOK, ERROR); - ret = strcpy_s((sensorInfos_ + i)->vendorName, NAME_MAX_LEN, + ret = strcpy_s(sensorInfo->vendorName, NAME_MAX_LEN, sensorList[i].GetVendorName().c_str()); CHKCR(ret == EOK, ERROR); - ret = strcpy_s((sensorInfos_ + i)->hardwareVersion, VERSION_MAX_LEN, + ret = strcpy_s(sensorInfo->hardwareVersion, VERSION_MAX_LEN, sensorList[i].GetHardwareVersion().c_str()); CHKCR(ret == EOK, ERROR); - ret = strcpy_s((sensorInfos_ + i)->firmwareVersion, VERSION_MAX_LEN, + ret = strcpy_s(sensorInfo->firmwareVersion, VERSION_MAX_LEN, sensorList[i].GetFirmwareVersion().c_str()); CHKCR(ret == EOK, ERROR); - (sensorInfos_ + i)->sensorId = static_cast(sensorList[i].GetSensorId()); - (sensorInfos_ + i)->sensorTypeId = static_cast(sensorList[i].GetSensorTypeId()); - (sensorInfos_ + i)->maxRange = sensorList[i].GetMaxRange(); - (sensorInfos_ + i)->precision = sensorList[i].GetResolution(); - (sensorInfos_ + i)->power = sensorList[i].GetPower(); - (sensorInfos_ + i)->minSamplePeriod = sensorList[i].GetMinSamplePeriodNs(); - (sensorInfos_ + i)->maxSamplePeriod = sensorList[i].GetMaxSamplePeriodNs(); + sensorInfo->sensorId = static_cast(sensorList[i].GetSensorId()); + sensorInfo->sensorTypeId = static_cast(sensorList[i].GetSensorTypeId()); + sensorInfo->maxRange = sensorList[i].GetMaxRange(); + sensorInfo->precision = sensorList[i].GetResolution(); + sensorInfo->power = sensorList[i].GetPower(); + sensorInfo->minSamplePeriod = sensorList[i].GetMinSamplePeriodNs(); + sensorInfo->maxSamplePeriod = sensorList[i].GetMaxSamplePeriodNs(); } sensorInfoCount_ = static_cast(count); return SUCCESS; diff --git a/interfaces/plugin/src/sensor_js.cpp b/interfaces/plugin/src/sensor_js.cpp old mode 100644 new mode 100755 index c87bb402..9a062419 --- a/interfaces/plugin/src/sensor_js.cpp +++ b/interfaces/plugin/src/sensor_js.cpp @@ -106,6 +106,7 @@ static void EmitSubscribeCallback(SensorEvent *event) } std::lock_guard subscribeLock(mutex_); auto callback = g_subscribeCallbacks[sensorTypeId]; + CHKPV(callback); CHKCV(copySensorData(callback, event), "Copy sensor data failed"); EmitUvEventLoop(callback); } @@ -120,6 +121,7 @@ static void EmitOnCallback(SensorEvent *event) std::lock_guard onCallbackLock(onMutex_); auto onCallbackInfos = g_onCallbackInfos[sensorTypeId]; for (auto &onCallbackInfo : onCallbackInfos) { + CHKPC(onCallbackInfo); if (!copySensorData(onCallbackInfo, event)) { SEN_HILOGE("Copy sensor data failed"); continue; @@ -138,6 +140,7 @@ static void EmitOnceCallback(SensorEvent *event) return; } for (auto &onceCallbackInfo : iter->second) { + CHKPC(onceCallbackInfo); if (!copySensorData(onceCallbackInfo, event)) { SEN_HILOGE("Copy sensor data failed"); continue; @@ -277,6 +280,7 @@ static bool IsSubscribed(napi_env env, int32_t sensorTypeId, napi_value callback continue; } napi_value sensorCallback = nullptr; + CHKPC(callbackInfo->callback[0]); CHKNRF(env, napi_get_reference_value(env, callbackInfo->callback[0], &sensorCallback), "napi_get_reference_value"); if (IsSameValue(env, callback, sensorCallback)) { @@ -365,6 +369,7 @@ static int32_t RemoveCallback(napi_env env, int32_t sensorTypeId, napi_value cal for (auto iter = callbackInfos.begin(); iter != callbackInfos.end(); ++iter) { CHKPC(*iter); napi_value sensorCallback = nullptr; + CHKPC((*iter)->callback[0]); if (napi_get_reference_value(env, (*iter)->callback[0], &sensorCallback) != napi_ok) { SEN_HILOGE("napi_get_reference_value fail"); continue; -- Gitee From 322db3ccb9f22f91b2a78c67f89785811cbe1052 Mon Sep 17 00:00:00 2001 From: wuzhihuitmac Date: Thu, 27 Oct 2022 13:03:17 +0000 Subject: [PATCH 06/22] Modify View Comments Signed-off-by: wuzhihuitmac Change-Id: I22c2e3cb8fb7f18bcc2912c86bc08a79f078b4ac --- frameworks/native/sensor/src/sensor_agent_proxy.cpp | 0 interfaces/plugin/src/sensor_js.cpp | 0 2 files changed, 0 insertions(+), 0 deletions(-) mode change 100755 => 100644 frameworks/native/sensor/src/sensor_agent_proxy.cpp mode change 100755 => 100644 interfaces/plugin/src/sensor_js.cpp diff --git a/frameworks/native/sensor/src/sensor_agent_proxy.cpp b/frameworks/native/sensor/src/sensor_agent_proxy.cpp old mode 100755 new mode 100644 diff --git a/interfaces/plugin/src/sensor_js.cpp b/interfaces/plugin/src/sensor_js.cpp old mode 100755 new mode 100644 -- Gitee From 6166d795e9e0f2861e9f98562043a4271d753b2f Mon Sep 17 00:00:00 2001 From: wuzhihuitmac Date: Thu, 27 Oct 2022 13:14:17 +0000 Subject: [PATCH 07/22] Modify View Comments Signed-off-by: wuzhihuitmac Change-Id: I3a8c356a0f8734c388e5c308992a95cd8837854e --- services/sensor/src/sensor_dump.cpp | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/services/sensor/src/sensor_dump.cpp b/services/sensor/src/sensor_dump.cpp index d1d298b9..63fa8276 100644 --- a/services/sensor/src/sensor_dump.cpp +++ b/services/sensor/src/sensor_dump.cpp @@ -194,6 +194,9 @@ bool SensorDump::DumpSensorList(int32_t fd, const std::vector &sensors) dprintf(fd, "Total sensor:%d, Sensor list:\n", int32_t { sensors.size() }); for (const auto &sensor : sensors) { auto sensorId = sensor.GetSensorId(); + if (sensorMap_.find(SensorId) == sensorMap_.end()) { + continue; + } dprintf(fd, "sensorId:%8u | sensorType:%s | sensorName:%s | vendorName:%s | maxRange:%f" "| fifoMaxEventCount:%d | minSamplePeriodNs:%" PRId64 " | maxSamplePeriodNs:%" PRId64 "\n", @@ -212,6 +215,9 @@ bool SensorDump::DumpSensorChannel(int32_t fd, ClientInfo &clientInfo) clientInfo.GetSensorChannelInfo(channelInfo); for (const auto &channel : channelInfo) { auto sensorId = channel.GetSensorId(); + if (sensorMap_.find(SensorId) == sensorMap_.end()) { + continue; + } dprintf(fd, "uid:%d | packageName:%s | sensorId:%8u | sensorType:%s | samplingPeriodNs:%" PRId64 "" "| fifoCount:%u\n", @@ -227,6 +233,9 @@ bool SensorDump::DumpOpeningSensor(int32_t fd, const std::vector &sensor dprintf(fd, "Opening sensors:\n"); for (const auto &sensor : sensors) { uint32_t sensorId = sensor.GetSensorId(); + if (sensorMap_.find(SensorId) == sensorMap_.end()) { + continue; + } if (clientInfo.GetSensorState(sensorId)) { dprintf(fd, "sensorId: %8u | sensorType: %s | channelSize: %lu\n", sensorId, sensorMap_[sensorId].c_str(), clientInfo.GetSensorChannel(sensorId).size()); @@ -242,6 +251,9 @@ bool SensorDump::DumpSensorData(int32_t fd, ClientInfo &clientInfo) int32_t j = 0; for (auto &sensorData : dataMap) { uint32_t sensorId = sensorData.first; + if (sensorMap_.find(SensorId) == sensorMap_.end()) { + continue; + } dprintf(fd, "sensorId: %8u | sensorType: %s:\n", sensorId, sensorMap_[sensorId].c_str()); for (uint32_t i = 0; i < MAX_DUMP_DATA_SIZE && (!sensorData.second.empty()); i++) { auto data = sensorData.second.front(); -- Gitee From e49deb17758c14166f29818187c5a6adc9a5ce51 Mon Sep 17 00:00:00 2001 From: lixiangpeng5 Date: Thu, 27 Oct 2022 21:26:47 +0800 Subject: [PATCH 08/22] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E6=9C=8D=E5=8A=A1?= =?UTF-8?q?=E7=AB=AFSensorEvent.data=E5=BC=95=E8=B5=B7=E7=9A=84=E5=86=85?= =?UTF-8?q?=E5=AD=98=E6=B3=84=E9=9C=B2=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: lixiangpeng5 Change-Id: Ie6350876db26be0ac899961fdccf4522150959e9 --- .../sensor/include/sensor_data_channel.h | 1 + .../include/sensor_file_descriptor_listener.h | 2 +- .../src/sensor_file_descriptor_listener.cpp | 8 +- .../adapter/src/compatible_connection.cpp | 10 +- .../adapter/src/sensor_event_callback.cpp | 12 +- services/sensor/include/client_info.h | 14 +-- services/sensor/include/fifo_cache_data.h | 8 +- .../sensor/include/sensor_data_processer.h | 24 ++-- services/sensor/include/sensor_dump.h | 2 +- services/sensor/include/sensor_manager.h | 2 +- services/sensor/include/sensor_service.h | 2 +- services/sensor/src/client_info.cpp | 32 ++--- services/sensor/src/fifo_cache_data.cpp | 4 +- services/sensor/src/sensor_data_processer.cpp | 118 ++++++++---------- services/sensor/src/sensor_dump.cpp | 2 +- services/sensor/src/sensor_manager.cpp | 9 +- services/sensor/src/sensor_service.cpp | 6 +- utils/include/report_data_callback.h | 8 +- utils/include/sensor_basic_data_channel.h | 16 +-- utils/include/sensor_data_event.h | 10 +- utils/src/report_data_callback.cpp | 20 +-- utils/src/sensor_basic_data_channel.cpp | 4 +- 22 files changed, 134 insertions(+), 180 deletions(-) diff --git a/frameworks/native/sensor/include/sensor_data_channel.h b/frameworks/native/sensor/include/sensor_data_channel.h index 8a9bb96d..ecf87bac 100644 --- a/frameworks/native/sensor/include/sensor_data_channel.h +++ b/frameworks/native/sensor/include/sensor_data_channel.h @@ -19,6 +19,7 @@ #include #include +#include "sensor_agent_type.h" #include "sensor_event_handler.h" #include "sensor_basic_data_channel.h" diff --git a/frameworks/native/sensor/include/sensor_file_descriptor_listener.h b/frameworks/native/sensor/include/sensor_file_descriptor_listener.h index 165ba763..770c1dae 100644 --- a/frameworks/native/sensor/include/sensor_file_descriptor_listener.h +++ b/frameworks/native/sensor/include/sensor_file_descriptor_listener.h @@ -35,7 +35,7 @@ public: private: SensorDataChannel* channel_; - TransferSensorEvents *receiveDataBuff_ = nullptr; + SensorData *receiveDataBuff_ = nullptr; }; } // namespace Sensors } // namespace OHOS diff --git a/frameworks/native/sensor/src/sensor_file_descriptor_listener.cpp b/frameworks/native/sensor/src/sensor_file_descriptor_listener.cpp index 8dc13614..e272d1d7 100644 --- a/frameworks/native/sensor/src/sensor_file_descriptor_listener.cpp +++ b/frameworks/native/sensor/src/sensor_file_descriptor_listener.cpp @@ -33,7 +33,7 @@ SensorFileDescriptorListener::SensorFileDescriptorListener() { channel_ = nullptr; receiveDataBuff_ = - new (std::nothrow) TransferSensorEvents[sizeof(TransferSensorEvents) * RECEIVE_DATA_SIZE]; + new (std::nothrow) SensorData[sizeof(SensorData) * RECEIVE_DATA_SIZE]; CHKPL(receiveDataBuff_); } @@ -57,8 +57,8 @@ void SensorFileDescriptorListener::OnReadable(int32_t fileDescriptor) return; } int32_t len = - recv(fileDescriptor, receiveDataBuff_, sizeof(TransferSensorEvents) * RECEIVE_DATA_SIZE, 0); - int32_t eventSize = static_cast(sizeof(TransferSensorEvents)); + recv(fileDescriptor, receiveDataBuff_, sizeof(SensorData) * RECEIVE_DATA_SIZE, 0); + int32_t eventSize = static_cast(sizeof(SensorData)); while (len > 0) { int32_t num = len / eventSize; for (int i = 0; i < num; i++) { @@ -73,7 +73,7 @@ void SensorFileDescriptorListener::OnReadable(int32_t fileDescriptor) }; channel_->dataCB_(&event, 1, channel_->privateData_); } - len = recv(fileDescriptor, receiveDataBuff_, sizeof(TransferSensorEvents) * RECEIVE_DATA_SIZE, 0); + len = recv(fileDescriptor, receiveDataBuff_, sizeof(SensorData) * RECEIVE_DATA_SIZE, 0); } } diff --git a/services/sensor/hdi_connection/adapter/src/compatible_connection.cpp b/services/sensor/hdi_connection/adapter/src/compatible_connection.cpp index 1863ffd6..f57f0b9a 100644 --- a/services/sensor/hdi_connection/adapter/src/compatible_connection.cpp +++ b/services/sensor/hdi_connection/adapter/src/compatible_connection.cpp @@ -132,7 +132,7 @@ int32_t CompatibleConnection::SensorDataCallback(const SensorEvents *event) return ERR_INVALID_VALUE; } - SensorEvent sensorEvent = { + SensorData sensorData = { .sensorTypeId = event->sensorId, .version = event->version, .timestamp = event->timestamp, @@ -140,18 +140,16 @@ int32_t CompatibleConnection::SensorDataCallback(const SensorEvents *event) .mode = event->mode, .dataLen = event->dataLen }; - sensorEvent.data = new (std::nothrow) uint8_t[SENSOR_DATA_LENGHT]; - CHKPR(sensorEvent.data, ERR_INVALID_VALUE); - errno_t ret = memcpy_s(sensorEvent.data, event->dataLen, event->data, event->dataLen); + CHKPR(sensorData.data, ERR_INVALID_VALUE); + errno_t ret = memcpy_s(sensorData.data, event->dataLen, event->data, event->dataLen); if (ret != EOK) { SEN_HILOGE("copy data failed"); - delete[] sensorEvent.data; return COPY_ERR; } CHKPR(reportDataCallback_, ERR_NO_INIT); CHKPR(reportDataCb_, ERR_NO_INIT); std::unique_lock lk(ISensorHdiConnection::dataMutex_); - (void)(reportDataCallback_->*reportDataCb_)(&sensorEvent, reportDataCallback_); + (void)(reportDataCallback_->*reportDataCb_)(&sensorData, reportDataCallback_); ISensorHdiConnection::dataCondition_.notify_one(); return ERR_OK; } 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 a5a9fbf8..75388312 100644 --- a/services/sensor/hdi_connection/adapter/src/sensor_event_callback.cpp +++ b/services/sensor/hdi_connection/adapter/src/sensor_event_callback.cpp @@ -12,11 +12,10 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - #include "sensor_event_callback.h" #include "hdi_connection.h" -#include "sensor_agent_type.h" +#include "sensor_data_event.h" #include "sensors_errors.h" namespace OHOS { @@ -37,7 +36,7 @@ int32_t SensorEventCallback::OnDataEvent(const HdfSensorEvents& event) SEN_HILOGI("data is empty"); return ERR_INVALID_VALUE; } - SensorEvent sensorEvent = { + SensorData sensorData = { .sensorTypeId = event.sensorId, .version = event.version, .timestamp = event.timestamp, @@ -45,13 +44,12 @@ int32_t SensorEventCallback::OnDataEvent(const HdfSensorEvents& event) .mode = event.mode, .dataLen = event.dataLen }; - sensorEvent.data = new (std::nothrow) uint8_t[SENSOR_DATA_LENGHT]; - CHKPR(sensorEvent.data, ERR_NO_INIT); + CHKPR(sensorData.data, ERR_NO_INIT); for (int32_t i = 0; i < static_cast(dataSize); i++) { - sensorEvent.data[i] = event.data[i]; + sensorData.data[i] = event.data[i]; } std::unique_lock lk(ISensorHdiConnection::dataMutex_); - (void)(reportDataCallback_->*(reportDataCb_))(&sensorEvent, reportDataCallback_); + (void)(reportDataCallback_->*(reportDataCb_))(&sensorData, reportDataCallback_); ISensorHdiConnection::dataCondition_.notify_one(); return ERR_OK; } diff --git a/services/sensor/include/client_info.h b/services/sensor/include/client_info.h index f81cd4d9..e4797138 100644 --- a/services/sensor/include/client_info.h +++ b/services/sensor/include/client_info.h @@ -32,7 +32,7 @@ #include "sensor_basic_data_channel.h" #include "sensor_basic_info.h" #include "sensor_channel_info.h" -#include "sensor_agent_type.h" +#include "sensor_data_event.h" namespace OHOS { namespace Sensors { @@ -58,8 +58,8 @@ public: SensorBasicInfo GetCurPidSensorInfo(uint32_t sensorId, int32_t pid); uint64_t ComputeBestPeriodCount(uint32_t sensorId, sptr &channel); uint64_t ComputeBestFifoCount(uint32_t sensorId, sptr &channel); - int32_t GetStoreEvent(int32_t sensorId, SensorEvent &event); - void StoreEvent(const SensorEvent &event); + int32_t GetStoreEvent(int32_t sensorId, SensorData &data); + void StoreEvent(const SensorData &data); void ClearEvent(); AppThreadInfo GetAppInfoByChannel(const sptr &channel); bool SaveClientPid(const sptr &sensorClient, int32_t pid); @@ -69,8 +69,8 @@ public: void GetSensorChannelInfo(std::vector &channelInfo); void UpdateCmd(uint32_t sensorId, int32_t uid, int32_t cmdType); void DestroyCmd(int32_t uid); - void UpdateDataQueue(int32_t sensorId, SensorEvent &event); - std::unordered_map> GetDumpQueue(); + void UpdateDataQueue(int32_t sensorId, SensorData &data); + std::unordered_map> GetDumpQueue(); void ClearDataQueue(int32_t sensorId); int32_t GetUidByPid(int32_t pid); AccessTokenID GetTokenIdByPid(int32_t pid); @@ -87,11 +87,11 @@ private: std::mutex dataQueueMutex_; std::unordered_map> clientMap_; std::unordered_map> channelMap_; - std::unordered_map storedEvent_; + std::unordered_map storedEvent_; std::unordered_map appThreadInfoMap_; std::map, int32_t> clientPidMap_; std::unordered_map>> cmdMap_; - std::unordered_map> dumpQueue_; + std::unordered_map> dumpQueue_; }; } // namespace Sensors } // namespace OHOS diff --git a/services/sensor/include/fifo_cache_data.h b/services/sensor/include/fifo_cache_data.h index 7a1713b5..d6221735 100644 --- a/services/sensor/include/fifo_cache_data.h +++ b/services/sensor/include/fifo_cache_data.h @@ -20,7 +20,7 @@ #include "nocopyable.h" #include "refbase.h" -#include "sensor_agent_type.h" +#include "sensor_data_event.h" #include "sensor_basic_data_channel.h" namespace OHOS { @@ -31,8 +31,8 @@ public: virtual ~FifoCacheData(); void SetPeriodCount(uint64_t periodCount); uint64_t GetPeriodCount() const; - void SetFifoCacheData(const std::vector &fifoCacheData); - std::vector GetFifoCacheData() const; + void SetFifoCacheData(const std::vector &fifoCacheData); + std::vector GetFifoCacheData() const; void SetChannel(const sptr &channel); sptr GetChannel() const; void InitFifoCache(); @@ -41,7 +41,7 @@ private: DISALLOW_COPY_AND_MOVE(FifoCacheData); uint64_t periodCount_; sptr channel_; - std::vector fifoCacheData_; + std::vector fifoCacheData_; }; } // namespace Sensors } // namespace OHOS diff --git a/services/sensor/include/sensor_data_processer.h b/services/sensor/include/sensor_data_processer.h index 8f2ff170..8a9d2125 100644 --- a/services/sensor/include/sensor_data_processer.h +++ b/services/sensor/include/sensor_data_processer.h @@ -29,7 +29,7 @@ #include "report_data_callback.h" #include "sensor.h" #include "sensor_hdi_connection.h" -#include "sensor_agent_type.h" +#include "sensor_data_event.h" namespace OHOS { namespace Sensors { @@ -38,22 +38,22 @@ public: explicit SensorDataProcesser(const std::unordered_map &sensorMap); virtual ~SensorDataProcesser(); int32_t ProcessEvents(sptr dataCallback); - int32_t SendEvents(sptr &channel, SensorEvent &event); + int32_t SendEvents(sptr &channel, SensorData &data); static int DataThread(sptr dataProcesser, sptr dataCallback); - int32_t CacheSensorEvent(const SensorEvent &event, sptr &channel); + int32_t CacheSensorEvent(const SensorData &data, sptr &channel); private: DISALLOW_COPY_AND_MOVE(SensorDataProcesser); - void ReportData(sptr &channel, SensorEvent &event); - bool ReportNotContinuousData(std::unordered_map &cacheBuf, - sptr &channel, SensorEvent &event); - void SendNoneFifoCacheData(std::unordered_map &cacheBuf, - sptr &channel, SensorEvent &event, uint64_t periodCount); - void SendFifoCacheData(std::unordered_map &cacheBuf, - sptr &channel, SensorEvent &event, uint64_t periodCount, + void ReportData(sptr &channel, SensorData &data); + bool ReportNotContinuousData(std::unordered_map &cacheBuf, + sptr &channel, SensorData &data); + void SendNoneFifoCacheData(std::unordered_map &cacheBuf, + sptr &channel, SensorData &data, uint64_t periodCount); + void SendFifoCacheData(std::unordered_map &cacheBuf, + sptr &channel, SensorData &data, uint64_t periodCount, uint64_t fifoCount); - void SendRawData(std::unordered_map &cacheBuf, sptr channel, - std::vector event); + void SendRawData(std::unordered_map &cacheBuf, sptr channel, + std::vector events); void EventFilter(CircularEventBuf &eventsBuf); ClientInfo &clientInfo_ = ClientInfo::GetInstance(); FlushInfoRecord &flushInfo_ = FlushInfoRecord::GetInstance(); diff --git a/services/sensor/include/sensor_dump.h b/services/sensor/include/sensor_dump.h index e636c0e6..8c729114 100644 --- a/services/sensor/include/sensor_dump.h +++ b/services/sensor/include/sensor_dump.h @@ -44,7 +44,7 @@ private: DISALLOW_COPY_AND_MOVE(SensorDump); void DumpCurrentTime(int32_t fd); int32_t DataSizeBySensorId(uint32_t sensorId); - std::string GetDataBySensorId(uint32_t sensorId, TransferSensorEvents &sensorData); + std::string GetDataBySensorId(uint32_t sensorId, SensorData &sensorData); static std::unordered_map sensorMap_; }; } // namespace Sensors diff --git a/services/sensor/include/sensor_manager.h b/services/sensor/include/sensor_manager.h index 2be11364..5bcb35df 100644 --- a/services/sensor/include/sensor_manager.h +++ b/services/sensor/include/sensor_manager.h @@ -24,7 +24,7 @@ #include "flush_info_record.h" #include "sensor_data_processer.h" #include "sensor_hdi_connection.h" -#include "sensor_agent_type.h" + namespace OHOS { namespace Sensors { using namespace Security::AccessToken; diff --git a/services/sensor/include/sensor_service.h b/services/sensor/include/sensor_service.h index a436cf89..35fab928 100644 --- a/services/sensor/include/sensor_service.h +++ b/services/sensor/include/sensor_service.h @@ -25,7 +25,7 @@ #include "client_info.h" #include "death_recipient_template.h" -#include "sensor_agent_type.h" +#include "sensor_data_event.h" #include "sensor_hdi_connection.h" #include "sensor_manager.h" #include "sensor_service_stub.h" diff --git a/services/sensor/src/client_info.cpp b/services/sensor/src/client_info.cpp index 122c727f..15e68601 100644 --- a/services/sensor/src/client_info.cpp +++ b/services/sensor/src/client_info.cpp @@ -427,12 +427,12 @@ uint64_t ClientInfo::ComputeBestFifoCount(uint32_t sensorId, sptr lock(eventMutex_); auto storedEvent = storedEvent_.find(sensorId); if (storedEvent != storedEvent_.end()) { - errno_t ret = memcpy_s(&event, sizeof(SensorEvent), &storedEvent->second, sizeof(SensorEvent)); + errno_t ret = memcpy_s(&data, sizeof(SensorData), &storedEvent->second, sizeof(SensorData)); if (ret != EOK) { SEN_HILOGE("memcpy_s failed, sensorId:%{public}d", sensorId); return ret; @@ -444,10 +444,10 @@ int32_t ClientInfo::GetStoreEvent(int32_t sensorId, SensorEvent &event) return NO_STROE_EVENT; } -void ClientInfo::StoreEvent(const SensorEvent &event) +void ClientInfo::StoreEvent(const SensorData &data) { bool foundSensor = false; - SensorEvent storedEvent; + SensorData storedEvent; auto sensorHdiConnection = &SensorHdiConnection::GetInstance(); if (sensorHdiConnection == nullptr) { SEN_HILOGE("sensorHdiConnection cannot be null"); @@ -459,7 +459,7 @@ void ClientInfo::StoreEvent(const SensorEvent &event) SEN_HILOGE("GetSensorList is failed"); return; } - errno_t retVal = memcpy_s(&storedEvent, sizeof(storedEvent), &event, sizeof(event)); + errno_t retVal = memcpy_s(&storedEvent, sizeof(storedEvent), &data, sizeof(data)); if (retVal != EOK) { SEN_HILOGE("memcpy_s is failed"); return; @@ -653,38 +653,26 @@ std::vector ClientInfo::GetCmdList(uint32_t sensorId, int32_t uid) return uidIt->second; } -void ClientInfo::UpdateDataQueue(int32_t sensorId, SensorEvent &event) +void ClientInfo::UpdateDataQueue(int32_t sensorId, SensorData &data) { if (sensorId == HEART_RATE_SENSOR_ID) { return; } std::lock_guard queueLock(dataQueueMutex_); - TransferSensorEvents transferEvent = { - .sensorTypeId = event.sensorTypeId, - .version = event.version, - .timestamp = event.timestamp, - .option = event.option, - .mode = event.mode, - .dataLen = event.dataLen - }; - if (memcpy_s(transferEvent.data, event.dataLen, event.data, event.dataLen) != EOK) { - SEN_HILOGE("Copy data failed"); - return; - } auto it = dumpQueue_.find(sensorId); if (it == dumpQueue_.end()) { - std::queue q; - q.push(transferEvent); + std::queue q; + q.push(data); dumpQueue_.insert(std::make_pair(sensorId, q)); return; } - it->second.push(transferEvent); + it->second.push(data); if (it->second.size() > MAX_DUMP_DATA_SIZE) { it->second.pop(); } } -std::unordered_map> ClientInfo::GetDumpQueue() +std::unordered_map> ClientInfo::GetDumpQueue() { return dumpQueue_; } diff --git a/services/sensor/src/fifo_cache_data.cpp b/services/sensor/src/fifo_cache_data.cpp index b3aa44c8..db0174f6 100644 --- a/services/sensor/src/fifo_cache_data.cpp +++ b/services/sensor/src/fifo_cache_data.cpp @@ -41,12 +41,12 @@ uint64_t FifoCacheData::GetPeriodCount() const return periodCount_; } -void FifoCacheData::SetFifoCacheData(const std::vector &fifoCacheData) +void FifoCacheData::SetFifoCacheData(const std::vector &fifoCacheData) { fifoCacheData_ = fifoCacheData; } -std::vector FifoCacheData::GetFifoCacheData() const +std::vector FifoCacheData::GetFifoCacheData() const { return fifoCacheData_; } diff --git a/services/sensor/src/sensor_data_processer.cpp b/services/sensor/src/sensor_data_processer.cpp index 5dc6a707..f2c1daaa 100644 --- a/services/sensor/src/sensor_data_processer.cpp +++ b/services/sensor/src/sensor_data_processer.cpp @@ -60,16 +60,16 @@ SensorDataProcesser::~SensorDataProcesser() sensorMap_.clear(); } -void SensorDataProcesser::SendNoneFifoCacheData(std::unordered_map &cacheBuf, - sptr &channel, SensorEvent &event, +void SensorDataProcesser::SendNoneFifoCacheData(std::unordered_map &cacheBuf, + sptr &channel, SensorData &data, uint64_t periodCount) { - std::vector sendEvents; + std::vector sendEvents; std::lock_guard dataCountLock(dataCountMutex_); - sendEvents.push_back(event); - uint32_t sensorId = static_cast(event.sensorTypeId); + sendEvents.push_back(data); + uint32_t sensorId = static_cast(data.sensorTypeId); if (sensorId == FLUSH_COMPLETE_ID) { - sensorId = static_cast(event.sensorTypeId); + sensorId = static_cast(data.sensorTypeId); } auto dataCountIt = dataCountMap_.find(sensorId); if (dataCountIt == dataCountMap_.end()) { @@ -107,13 +107,13 @@ void SensorDataProcesser::SendNoneFifoCacheData(std::unordered_map &cacheBuf, - sptr &channel, SensorEvent &event, +void SensorDataProcesser::SendFifoCacheData(std::unordered_map &cacheBuf, + sptr &channel, SensorData &data, uint64_t periodCount, uint64_t fifoCount) { - uint32_t sensorId = static_cast(event.sensorTypeId); + uint32_t sensorId = static_cast(data.sensorTypeId); if (sensorId == FLUSH_COMPLETE_ID) { - sensorId = static_cast(event.sensorTypeId); + sensorId = static_cast(data.sensorTypeId); } std::lock_guard dataCountLock(dataCountMutex_); auto dataCountIt = dataCountMap_.find(sensorId); @@ -141,8 +141,8 @@ void SensorDataProcesser::SendFifoCacheData(std::unordered_mapSetPeriodCount(0); - std::vector fifoDataList = fifoData->GetFifoCacheData(); - fifoDataList.push_back(event); + std::vector fifoDataList = fifoData->GetFifoCacheData(); + fifoDataList.push_back(data); fifoData->SetFifoCacheData(fifoDataList); if ((fifoData->GetFifoCacheData()).size() != fifoCount) { continue; @@ -160,15 +160,15 @@ void SensorDataProcesser::SendFifoCacheData(std::unordered_map &channel, SensorEvent &event) +void SensorDataProcesser::ReportData(sptr &channel, SensorData &data) { CHKPV(channel); - uint32_t sensorId = static_cast(event.sensorTypeId); + uint32_t sensorId = static_cast(data.sensorTypeId); if (sensorId == FLUSH_COMPLETE_ID) { - sensorId = static_cast(event.sensorTypeId); + sensorId = static_cast(data.sensorTypeId); } - auto &cacheBuf = const_cast &>(channel->GetDataCacheBuf()); - if (ReportNotContinuousData(cacheBuf, channel, event)) { + auto &cacheBuf = const_cast &>(channel->GetDataCacheBuf()); + if (ReportNotContinuousData(cacheBuf, channel, data)) { return; } uint64_t periodCount = clientInfo_.ComputeBestPeriodCount(sensorId, channel); @@ -177,18 +177,18 @@ void SensorDataProcesser::ReportData(sptr &channel, Sens } auto fifoCount = clientInfo_.ComputeBestFifoCount(sensorId, channel); if (fifoCount <= 0) { - SendNoneFifoCacheData(cacheBuf, channel, event, periodCount); + SendNoneFifoCacheData(cacheBuf, channel, data, periodCount); return; } - SendFifoCacheData(cacheBuf, channel, event, periodCount, fifoCount); + SendFifoCacheData(cacheBuf, channel, data, periodCount, fifoCount); } -bool SensorDataProcesser::ReportNotContinuousData(std::unordered_map &cacheBuf, - sptr &channel, SensorEvent &event) +bool SensorDataProcesser::ReportNotContinuousData(std::unordered_map &cacheBuf, + sptr &channel, SensorData &data) { - uint32_t sensorId = static_cast(event.sensorTypeId); + uint32_t sensorId = static_cast(data.sensorTypeId); if (sensorId == FLUSH_COMPLETE_ID) { - sensorId = static_cast(event.sensorTypeId); + sensorId = static_cast(data.sensorTypeId); } std::lock_guard sensorLock(sensorMutex_); auto sensor = sensorMap_.find(sensorId); @@ -196,81 +196,64 @@ bool SensorDataProcesser::ReportNotContinuousData(std::unordered_mapsecond.SetFlags(event.mode); + sensor->second.SetFlags(data.mode); if (((SENSOR_ON_CHANGE & sensor->second.GetFlags()) == SENSOR_ON_CHANGE) || ((SENSOR_ONE_SHOT & sensor->second.GetFlags()) == SENSOR_ONE_SHOT)) { - std::vector sendEvents; - sendEvents.push_back(event); + std::vector sendEvents; + sendEvents.push_back(data); SendRawData(cacheBuf, channel, sendEvents); return true; } return false; } -void SensorDataProcesser::SendRawData(std::unordered_map &cacheBuf, - sptr channel, std::vector event) +void SensorDataProcesser::SendRawData(std::unordered_map &cacheBuf, + sptr channel, std::vector events) { CHKPV(channel); - if (event.empty()) { + if (events.empty()) { return; } - size_t eventSize = event.size(); - std::vector transferEvents; - for (size_t i = 0; i < eventSize; i++) { - TransferSensorEvents transferEvent = { - .sensorTypeId = event[i].sensorTypeId, - .version = event[i].version, - .timestamp = event[i].timestamp, - .option = event[i].option, - .mode = event[i].mode, - .dataLen = event[i].dataLen - }; - errno_t ret = memcpy_s(transferEvent.data, SENSOR_MAX_LENGTH, event[i].data, event[i].dataLen); - if (ret != EOK) { - SEN_HILOGE("copy data failed"); - return; - } - transferEvents.push_back(transferEvent); - } - auto ret = channel->SendData(transferEvents.data(), eventSize * sizeof(TransferSensorEvents)); + size_t eventSize = events.size(); + auto ret = channel->SendData(events.data(), eventSize * sizeof(SensorData)); if (ret != ERR_OK) { SEN_HILOGE("send data failed, ret:%{public}d", ret); - uint32_t sensorId = static_cast(event[eventSize - 1].sensorTypeId); + uint32_t sensorId = static_cast(events[eventSize - 1].sensorTypeId); if (sensorId == FLUSH_COMPLETE_ID) { - sensorId = static_cast(event[eventSize - 1].sensorTypeId); + sensorId = static_cast(events[eventSize - 1].sensorTypeId); } - cacheBuf[sensorId] = event[eventSize - 1]; + cacheBuf[sensorId] = events[eventSize - 1]; } } -int32_t SensorDataProcesser::CacheSensorEvent(const SensorEvent &event, sptr &channel) +int32_t SensorDataProcesser::CacheSensorEvent(const SensorData &data, sptr &channel) { CHKPR(channel, INVALID_POINTER); int32_t ret = ERR_OK; - auto &cacheBuf = const_cast &>(channel->GetDataCacheBuf()); - uint32_t sensorId = static_cast(event.sensorTypeId); + auto &cacheBuf = const_cast &>(channel->GetDataCacheBuf()); + uint32_t sensorId = static_cast(data.sensorTypeId); if (sensorId == FLUSH_COMPLETE_ID) { - sensorId = static_cast(event.sensorTypeId); + sensorId = static_cast(data.sensorTypeId); } auto cacheEvent = cacheBuf.find(sensorId); if (cacheEvent != cacheBuf.end()) { // Try to send the last failed value, if it still fails, replace the previous cache directly - ret = channel->SendData(&cacheEvent->second, sizeof(SensorEvent)); + ret = channel->SendData(&cacheEvent->second, sizeof(SensorData)); if (ret != ERR_OK) { SEN_HILOGE("ret:%{public}d", ret); } - ret = channel->SendData(&event, sizeof(SensorEvent)); + ret = channel->SendData(&data, sizeof(SensorData)); if (ret != ERR_OK) { SEN_HILOGE("ret:%{public}d", ret); - cacheBuf[sensorId] = event; + cacheBuf[sensorId] = data; } else { cacheBuf.erase(cacheEvent); } } else { - ret = channel->SendData(&event, sizeof(SensorEvent)); + ret = channel->SendData(&data, sizeof(SensorData)); if (ret != ERR_OK) { SEN_HILOGE("ret:%{public}d", ret); - cacheBuf[sensorId] = event; + cacheBuf[sensorId] = data; } } return ret; @@ -337,10 +320,7 @@ int32_t SensorDataProcesser::ProcessEvents(sptr dataCallback int32_t eventNum = eventsBuf.eventNum; for (int32_t i = 0; i < eventNum; i++) { EventFilter(eventsBuf); - if (eventsBuf.circularBuf[eventsBuf.readPos].data != nullptr) { - delete[] eventsBuf.circularBuf[eventsBuf.readPos].data; - eventsBuf.circularBuf[eventsBuf.readPos].data = nullptr; - } + eventsBuf.readPos++; if (eventsBuf.readPos == CIRCULAR_BUF_LEN) { eventsBuf.readPos = 0; @@ -350,17 +330,17 @@ int32_t SensorDataProcesser::ProcessEvents(sptr dataCallback return SUCCESS; } -int32_t SensorDataProcesser::SendEvents(sptr &channel, SensorEvent &event) +int32_t SensorDataProcesser::SendEvents(sptr &channel, SensorData &data) { CHKPR(channel, INVALID_POINTER); - clientInfo_.UpdateDataQueue(event.sensorTypeId, event); + clientInfo_.UpdateDataQueue(data.sensorTypeId, data); auto &cacheBuf = channel->GetDataCacheBuf(); if (cacheBuf.empty()) { - ReportData(channel, event); + ReportData(channel, data); } else { - CacheSensorEvent(event, channel); + CacheSensorEvent(data, channel); } - clientInfo_.StoreEvent(event); + clientInfo_.StoreEvent(data); return SUCCESS; } diff --git a/services/sensor/src/sensor_dump.cpp b/services/sensor/src/sensor_dump.cpp index d1d298b9..c5c3ed26 100644 --- a/services/sensor/src/sensor_dump.cpp +++ b/services/sensor/src/sensor_dump.cpp @@ -295,7 +295,7 @@ int32_t SensorDump::DataSizeBySensorId(uint32_t sensorId) } } -std::string SensorDump::GetDataBySensorId(uint32_t sensorId, TransferSensorEvents &sensorData) +std::string SensorDump::GetDataBySensorId(uint32_t sensorId, SensorData &sensorData) { SEN_HILOGD("sensorId:%{public}u", sensorId); std::string str; diff --git a/services/sensor/src/sensor_manager.cpp b/services/sensor/src/sensor_manager.cpp index 5b465e0b..3a8255c8 100644 --- a/services/sensor/src/sensor_manager.cpp +++ b/services/sensor/src/sensor_manager.cpp @@ -19,6 +19,7 @@ #include "iservice_registry.h" #include "sensor.h" +#include "sensor_data_event.h" #include "sensors_errors.h" namespace OHOS { @@ -168,12 +169,12 @@ ErrCode SensorManager::AfterDisableSensor(uint32_t sensorId) CALL_LOG_ENTER; clientInfo_.ClearSensorInfo(sensorId); if (sensorId == PROXIMITY_SENSOR_ID) { - SensorEvent event; - auto ret = clientInfo_.GetStoreEvent(sensorId, event); + SensorData sensorData; + auto ret = clientInfo_.GetStoreEvent(sensorId, sensorData); if (ret == ERR_OK) { SEN_HILOGD("change the default state is far"); - event.data[0] = PROXIMITY_FAR; - clientInfo_.StoreEvent(event); + sensorData.data[0] = PROXIMITY_FAR; + clientInfo_.StoreEvent(sensorData); } } return ERR_OK; diff --git a/services/sensor/src/sensor_service.cpp b/services/sensor/src/sensor_service.cpp index 563427c5..c25ac318 100644 --- a/services/sensor/src/sensor_service.cpp +++ b/services/sensor/src/sensor_service.cpp @@ -178,15 +178,15 @@ void SensorService::ReportOnChangeData(uint32_t sensorId) SEN_HILOGW("it is not onchange data, no need to report"); return; } - SensorEvent event; - auto ret = clientInfo_.GetStoreEvent(sensorId, event); + SensorData sensorData; + auto ret = clientInfo_.GetStoreEvent(sensorId, sensorData); if (ret != ERR_OK) { SEN_HILOGE("there is no data to be reported"); return; } sptr channel = clientInfo_.GetSensorChannelByPid(GetCallingPid()); CHKPV(channel); - auto sendRet = channel->SendData(&event, sizeof(event)); + auto sendRet = channel->SendData(&sensorData, sizeof(sensorData)); if (sendRet != ERR_OK) { SEN_HILOGE("send data failed"); return; diff --git a/utils/include/report_data_callback.h b/utils/include/report_data_callback.h index 4c6acd5d..608e9a7b 100644 --- a/utils/include/report_data_callback.h +++ b/utils/include/report_data_callback.h @@ -17,7 +17,7 @@ #define REPORT_DATA_CALLBACK_H #include "refbase.h" -#include "sensor_agent_type.h" +#include "sensor_data_event.h" namespace OHOS { namespace Sensors { @@ -25,7 +25,7 @@ constexpr int32_t CIRCULAR_BUF_LEN = 1024; constexpr int32_t SENSOR_DATA_LENGHT = 64; struct CircularEventBuf { - struct SensorEvent *circularBuf; + struct SensorData *circularBuf; int32_t readPos; int32_t writePosition; int32_t eventNum; @@ -35,12 +35,12 @@ class ReportDataCallback : public RefBase { public: ReportDataCallback(); ~ReportDataCallback(); - int32_t ReportEventCallback(SensorEvent *event, sptr cb); + int32_t ReportEventCallback(SensorData *sensorData, sptr cb); CircularEventBuf &GetEventData(); CircularEventBuf eventsBuf_; }; -using ReportDataCb = int32_t (ReportDataCallback::*)(SensorEvent *event, sptr cb); +using ReportDataCb = int32_t (ReportDataCallback::*)(SensorData *sensorData, sptr cb); } // namespace Sensors } // namespace OHOS #endif // REPORT_DATA_CALLBACK_H diff --git a/utils/include/sensor_basic_data_channel.h b/utils/include/sensor_basic_data_channel.h index 30147e6b..a98543c2 100644 --- a/utils/include/sensor_basic_data_channel.h +++ b/utils/include/sensor_basic_data_channel.h @@ -22,20 +22,10 @@ #include "message_parcel.h" #include "refbase.h" -#include "sensor_agent_type.h" +#include "sensor_data_event.h" namespace OHOS { namespace Sensors { -constexpr int32_t SENSOR_MAX_LENGTH = 64; -struct TransferSensorEvents { - uint32_t sensorTypeId; - int32_t version; - int64_t timestamp; - int32_t option; - int32_t mode; - uint32_t dataLen; - uint8_t data[SENSOR_MAX_LENGTH]; -}; class SensorBasicDataChannel : public RefBase { public: SensorBasicDataChannel(); @@ -51,14 +41,14 @@ public: int32_t ReceiveData(void *vaddr, size_t size); bool GetSensorStatus() const; void SetSensorStatus(bool isActive); - const std::unordered_map &GetDataCacheBuf() const; + const std::unordered_map &GetDataCacheBuf() const; private: int32_t sendFd_; int32_t receiveFd_; bool isActive_; std::mutex statusLock_; - std::unordered_map dataCacheBuf_; + std::unordered_map dataCacheBuf_; }; } // namespace Sensors } // namespace OHOS diff --git a/utils/include/sensor_data_event.h b/utils/include/sensor_data_event.h index e0e3a349..cf6751ff 100755 --- a/utils/include/sensor_data_event.h +++ b/utils/include/sensor_data_event.h @@ -21,6 +21,7 @@ namespace Sensors { constexpr int32_t RESERVED_DATA_LEN = 3; constexpr int32_t EXTRA_INFO_DATA_LEN = 14; constexpr int32_t DEFAULT_SENSOR_DATA_DIMS = 16; +constexpr int32_t SENSOR_MAX_LENGTH = 64; enum { WAKE_UP_SENSOR = 1u, @@ -30,8 +31,13 @@ enum { }; struct SensorData { - float data[DEFAULT_SENSOR_DATA_DIMS]; - uint32_t reserved[RESERVED_DATA_LEN]; + int32_t sensorTypeId; /**< Sensor type ID */ + int32_t version; /**< Sensor algorithm version */ + int64_t timestamp; /**< Time when sensor data was reported */ + uint32_t option; /**< Sensor data options, including the measurement range and accuracy */ + int32_t mode; /**< Sensor data reporting mode (described in {@link SensorMode}) */ + uint8_t data[SENSOR_MAX_LENGTH]; /**< Sensor data */ + uint32_t dataLen; /**< Sensor data length */ }; struct ExtraInfo { diff --git a/utils/src/report_data_callback.cpp b/utils/src/report_data_callback.cpp index 21231e95..7b71fa2e 100644 --- a/utils/src/report_data_callback.cpp +++ b/utils/src/report_data_callback.cpp @@ -25,7 +25,7 @@ constexpr HiLogLabel LABEL = {LOG_CORE, SENSOR_LOG_DOMAIN, "ReportDataCallback"} } // namespace ReportDataCallback::ReportDataCallback() { - eventsBuf_.circularBuf = new (std::nothrow) SensorEvent[CIRCULAR_BUF_LEN]; + eventsBuf_.circularBuf = new (std::nothrow) SensorData[CIRCULAR_BUF_LEN]; CHKPL(eventsBuf_.circularBuf); eventsBuf_.readPos = 0; eventsBuf_.writePosition = 0; @@ -44,32 +44,24 @@ ReportDataCallback::~ReportDataCallback() eventsBuf_.eventNum = 0; } -int32_t ReportDataCallback::ReportEventCallback(SensorEvent* event, sptr cb) +int32_t ReportDataCallback::ReportEventCallback(SensorData* sensorData, sptr cb) { - CHKPR(event, ERROR); + CHKPR(sensorData, ERROR); if (cb == nullptr || cb->eventsBuf_.circularBuf == nullptr) { SEN_HILOGE("callback or circularBuf or event cannot be null"); - if (event->data != nullptr) { - delete[] event->data; - event->data = nullptr; - } return ERROR; } int32_t leftSize = CIRCULAR_BUF_LEN - cb->eventsBuf_.eventNum; int32_t toEndLen = CIRCULAR_BUF_LEN - cb->eventsBuf_.writePosition; if (leftSize < 0 || toEndLen < 0) { SEN_HILOGE("Leftsize and toendlen cannot be less than zero"); - if (event->data != nullptr) { - delete[] event->data; - event->data = nullptr; - } return ERROR; } if (toEndLen == 0) { - cb->eventsBuf_.circularBuf[0] = *event; - cb->eventsBuf_.writePosition = 1 - toEndLen; + cb->eventsBuf_.circularBuf[0] = *sensorData; + cb->eventsBuf_.writePosition = 1; } else { - cb->eventsBuf_.circularBuf[cb->eventsBuf_.writePosition] = *event; + cb->eventsBuf_.circularBuf[cb->eventsBuf_.writePosition] = *sensorData; cb->eventsBuf_.writePosition += 1; } if (leftSize < 1) { diff --git a/utils/src/sensor_basic_data_channel.cpp b/utils/src/sensor_basic_data_channel.cpp index 0e7ef077..29bfd591 100755 --- a/utils/src/sensor_basic_data_channel.cpp +++ b/utils/src/sensor_basic_data_channel.cpp @@ -28,7 +28,7 @@ using namespace OHOS::HiviewDFX; namespace { constexpr HiLogLabel LABEL = { LOG_CORE, SENSOR_LOG_DOMAIN, "SensorBasicChannel" }; -constexpr int32_t SENSOR_READ_DATA_SIZE = sizeof(SensorEvent) * 100; +constexpr int32_t SENSOR_READ_DATA_SIZE = sizeof(SensorData) * 100; constexpr int32_t DEFAULT_CHANNEL_SIZE = 2 * 1024; constexpr int32_t SOCKET_PAIR_SIZE = 2; } // namespace @@ -202,7 +202,7 @@ int32_t SensorBasicDataChannel::DestroySensorBasicChannel() return ERR_OK; } -const std::unordered_map &SensorBasicDataChannel::GetDataCacheBuf() const +const std::unordered_map &SensorBasicDataChannel::GetDataCacheBuf() const { return dataCacheBuf_; } -- Gitee From 3e973568f646772ec203a3a5a8755627995a5b1a Mon Sep 17 00:00:00 2001 From: hui1975 Date: Fri, 28 Oct 2022 10:21:30 +0800 Subject: [PATCH 09/22] =?UTF-8?q?=E5=88=A0=E9=99=A4=E4=B8=8D=E9=9C=80?= =?UTF-8?q?=E8=A6=81=E7=9A=84delete?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: hui1975 Change-Id: I62f85dfa4c903ab2da48dfc422b7968429e3fdd1 --- interfaces/plugin/include/async_callback_info.h | 4 ---- interfaces/plugin/src/sensor_napi_utils.cpp | 9 +++------ services/sensor/src/sensor_dump.cpp | 5 ++--- 3 files changed, 5 insertions(+), 13 deletions(-) diff --git a/interfaces/plugin/include/async_callback_info.h b/interfaces/plugin/include/async_callback_info.h index 2d515f21..94b3512b 100644 --- a/interfaces/plugin/include/async_callback_info.h +++ b/interfaces/plugin/include/async_callback_info.h @@ -121,10 +121,6 @@ public: napi_delete_reference(env, callback[i]); } } - if (work != nullptr) { - delete work; - work = nullptr; - } } private: diff --git a/interfaces/plugin/src/sensor_napi_utils.cpp b/interfaces/plugin/src/sensor_napi_utils.cpp index 184edfeb..4ee5a4b4 100644 --- a/interfaces/plugin/src/sensor_napi_utils.cpp +++ b/interfaces/plugin/src/sensor_napi_utils.cpp @@ -471,7 +471,7 @@ void EmitAsyncCallbackWork(sptr asyncCallbackInfo) } } -void freeWork(uv_work_t *work) +void DeleteWork(uv_work_t *work) { CHKPV(work); delete work; @@ -486,13 +486,12 @@ void EmitUvEventLoop(sptr asyncCallbackInfo) CHKPV(loop); uv_work_t *work = new(std::nothrow) uv_work_t; CHKPV(work); - asyncCallbackInfo->work = work; asyncCallbackInfo->IncStrongRef(nullptr); work->data = asyncCallbackInfo.GetRefPtr(); int32_t ret = uv_queue_work(loop, work, [] (uv_work_t *work) { }, [] (uv_work_t *work, int status) { CHKPV(work); sptr asyncCallbackInfo(static_cast(work->data)); - freeWork(work); + DeleteWork(work); /** * After the asynchronous task is created, the asyncCallbackInfo reference count is reduced * to 0 destructions, so you need to add 1 to the asyncCallbackInfo reference count when the @@ -531,13 +530,11 @@ void EmitUvEventLoop(sptr asyncCallbackInfo) return; } napi_close_handle_scope(asyncCallbackInfo->env, scope); - asyncCallbackInfo->work = nullptr; }); if (ret != 0) { SEN_HILOGE("uv_queue_work fail"); asyncCallbackInfo->DecStrongRef(nullptr); - asyncCallbackInfo->work = nullptr; - freeWork(work); + DeleteWork(work); } } diff --git a/services/sensor/src/sensor_dump.cpp b/services/sensor/src/sensor_dump.cpp index 5a1c8a0c..51553a02 100644 --- a/services/sensor/src/sensor_dump.cpp +++ b/services/sensor/src/sensor_dump.cpp @@ -173,10 +173,9 @@ void SensorDump::ParseCommand(int32_t fd, const std::vector &args, } RELEASE_RES: for (size_t i = 0; i < args.size(); ++i) { - if (argv[i] == nullptr) { - continue; + if (argv[i] != nullptr) { + delete[] argv[i]; } - delete[] argv[i]; } delete[] argv; } -- Gitee From aacab38cd97ae95fd8755d54f36abd0724b33985 Mon Sep 17 00:00:00 2001 From: lixiangpeng5 Date: Sat, 29 Oct 2022 09:52:52 +0800 Subject: [PATCH 10/22] =?UTF-8?q?=E8=B4=A8=E9=87=8F=E5=8A=A0=E5=9B=BA?= =?UTF-8?q?=E6=A3=80=E8=A7=86=E6=84=8F=E8=A7=81=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: lixiangpeng5 Change-Id: Ibd609be45aaa872576235958f0d0b1e6469a5d55 --- frameworks/native/sensor/src/sensor_agent_proxy.cpp | 3 +-- interfaces/plugin/src/sensor_js.cpp | 5 ----- services/sensor/src/sensor_dump.cpp | 8 ++++---- 3 files changed, 5 insertions(+), 11 deletions(-) diff --git a/frameworks/native/sensor/src/sensor_agent_proxy.cpp b/frameworks/native/sensor/src/sensor_agent_proxy.cpp index 5aa48ae2..5db36d46 100644 --- a/frameworks/native/sensor/src/sensor_agent_proxy.cpp +++ b/frameworks/native/sensor/src/sensor_agent_proxy.cpp @@ -300,9 +300,8 @@ int32_t SensorAgentProxy::ConvertSensorInfos() const } sensorInfos_ = (SensorInfo *)malloc(sizeof(SensorInfo) * count); CHKPR(sensorInfos_, ERROR); - SensorInfo *sensorInfo = sensorInfos_; for (size_t i = 0; i < count; ++i) { - sensorInfo += i; + SensorInfo *sensorInfo = sensorInfos_ + i; errno_t ret = strcpy_s(sensorInfo->sensorName, NAME_MAX_LEN, sensorList[i].GetSensorName().c_str()); CHKCR(ret == EOK, ERROR); diff --git a/interfaces/plugin/src/sensor_js.cpp b/interfaces/plugin/src/sensor_js.cpp index 9a062419..c87bb402 100644 --- a/interfaces/plugin/src/sensor_js.cpp +++ b/interfaces/plugin/src/sensor_js.cpp @@ -106,7 +106,6 @@ static void EmitSubscribeCallback(SensorEvent *event) } std::lock_guard subscribeLock(mutex_); auto callback = g_subscribeCallbacks[sensorTypeId]; - CHKPV(callback); CHKCV(copySensorData(callback, event), "Copy sensor data failed"); EmitUvEventLoop(callback); } @@ -121,7 +120,6 @@ static void EmitOnCallback(SensorEvent *event) std::lock_guard onCallbackLock(onMutex_); auto onCallbackInfos = g_onCallbackInfos[sensorTypeId]; for (auto &onCallbackInfo : onCallbackInfos) { - CHKPC(onCallbackInfo); if (!copySensorData(onCallbackInfo, event)) { SEN_HILOGE("Copy sensor data failed"); continue; @@ -140,7 +138,6 @@ static void EmitOnceCallback(SensorEvent *event) return; } for (auto &onceCallbackInfo : iter->second) { - CHKPC(onceCallbackInfo); if (!copySensorData(onceCallbackInfo, event)) { SEN_HILOGE("Copy sensor data failed"); continue; @@ -280,7 +277,6 @@ static bool IsSubscribed(napi_env env, int32_t sensorTypeId, napi_value callback continue; } napi_value sensorCallback = nullptr; - CHKPC(callbackInfo->callback[0]); CHKNRF(env, napi_get_reference_value(env, callbackInfo->callback[0], &sensorCallback), "napi_get_reference_value"); if (IsSameValue(env, callback, sensorCallback)) { @@ -369,7 +365,6 @@ static int32_t RemoveCallback(napi_env env, int32_t sensorTypeId, napi_value cal for (auto iter = callbackInfos.begin(); iter != callbackInfos.end(); ++iter) { CHKPC(*iter); napi_value sensorCallback = nullptr; - CHKPC((*iter)->callback[0]); if (napi_get_reference_value(env, (*iter)->callback[0], &sensorCallback) != napi_ok) { SEN_HILOGE("napi_get_reference_value fail"); continue; diff --git a/services/sensor/src/sensor_dump.cpp b/services/sensor/src/sensor_dump.cpp index 63fa8276..89efec62 100644 --- a/services/sensor/src/sensor_dump.cpp +++ b/services/sensor/src/sensor_dump.cpp @@ -194,7 +194,7 @@ bool SensorDump::DumpSensorList(int32_t fd, const std::vector &sensors) dprintf(fd, "Total sensor:%d, Sensor list:\n", int32_t { sensors.size() }); for (const auto &sensor : sensors) { auto sensorId = sensor.GetSensorId(); - if (sensorMap_.find(SensorId) == sensorMap_.end()) { + if (sensorMap_.find(sensorId) == sensorMap_.end()) { continue; } dprintf(fd, @@ -215,7 +215,7 @@ bool SensorDump::DumpSensorChannel(int32_t fd, ClientInfo &clientInfo) clientInfo.GetSensorChannelInfo(channelInfo); for (const auto &channel : channelInfo) { auto sensorId = channel.GetSensorId(); - if (sensorMap_.find(SensorId) == sensorMap_.end()) { + if (sensorMap_.find(sensorId) == sensorMap_.end()) { continue; } dprintf(fd, @@ -233,7 +233,7 @@ bool SensorDump::DumpOpeningSensor(int32_t fd, const std::vector &sensor dprintf(fd, "Opening sensors:\n"); for (const auto &sensor : sensors) { uint32_t sensorId = sensor.GetSensorId(); - if (sensorMap_.find(SensorId) == sensorMap_.end()) { + if (sensorMap_.find(sensorId) == sensorMap_.end()) { continue; } if (clientInfo.GetSensorState(sensorId)) { @@ -251,7 +251,7 @@ bool SensorDump::DumpSensorData(int32_t fd, ClientInfo &clientInfo) int32_t j = 0; for (auto &sensorData : dataMap) { uint32_t sensorId = sensorData.first; - if (sensorMap_.find(SensorId) == sensorMap_.end()) { + if (sensorMap_.find(sensorId) == sensorMap_.end()) { continue; } dprintf(fd, "sensorId: %8u | sensorType: %s:\n", sensorId, sensorMap_[sensorId].c_str()); -- Gitee From de334a2d5c08d42f8d6875d7ceec2ed4210eef04 Mon Sep 17 00:00:00 2001 From: wuzhihuitmac Date: Wed, 2 Nov 2022 02:02:53 +0000 Subject: [PATCH 11/22] add check about return value Signed-off-by: wuzhihuitmac Change-Id: I8f1c21287b3a1292c03ed3f872bfc8b628c82113 --- test/unittest/common/include/system_info.h | 2 +- test/unittest/common/src/system_info.cpp | 48 ++++++++-------------- 2 files changed, 17 insertions(+), 33 deletions(-) mode change 100755 => 100644 test/unittest/common/include/system_info.h mode change 100755 => 100644 test/unittest/common/src/system_info.cpp diff --git a/test/unittest/common/include/system_info.h b/test/unittest/common/include/system_info.h old mode 100755 new mode 100644 index a3ad5de7..8b11a249 --- a/test/unittest/common/include/system_info.h +++ b/test/unittest/common/include/system_info.h @@ -57,12 +57,12 @@ private: int32_t cstime { 0 }; }; int32_t GetTaskPidFile(const std::string& process_name); - int32_t GetTaskPidCmd(const std::string& process_name, int32_t flag = 0, std::string user = ""); int32_t GetProcOccupy(int32_t pid); int32_t GetSystemCpuStatInfo(Total_Cpu_Occupy& info); int64_t GetSystemTotalOccupy(); double GetCpuUsage(const Total_Cpu_Occupy& first, const Total_Cpu_Occupy& second); + }; } // namespace SYSTEM_INFO } // namespace Sensors diff --git a/test/unittest/common/src/system_info.cpp b/test/unittest/common/src/system_info.cpp old mode 100755 new mode 100644 index f21a27cc..ca58063e --- a/test/unittest/common/src/system_info.cpp +++ b/test/unittest/common/src/system_info.cpp @@ -65,7 +65,11 @@ int32_t CpuInfo::GetTaskPidFile(const std::string& process_name) continue; } std::string strLine; - std::getline(filePath, strLine); + if (!std::getline(filePath, strLine)) { + SEN_HILOGE("getline fail"); + filePath.close(); + return DEFAULT_PID; + } if (strLine.empty()) { filePath.close(); continue; @@ -76,7 +80,7 @@ int32_t CpuInfo::GetTaskPidFile(const std::string& process_name) } while (std::getline(filePath, strLine)) { if ((strLine.find("Pid")) != std::string::npos) { - if (sscanf_s(strLine.c_str(), "%*s%d", &pid) == -1) { + if (::sscanf_s(strLine.c_str(), "%*s%d", &pid, sizeof(pid)) != 1) { SEN_HILOGE("sscanf_s failed"); } break; @@ -90,34 +94,6 @@ int32_t CpuInfo::GetTaskPidFile(const std::string& process_name) return pid; } -int32_t CpuInfo::GetTaskPidCmd(const std::string& process_name, int32_t flag, std::string user) -{ - std::string command; - if (flag) { - if (user.empty()) { - user = ::getlogin(); - } - command = "pgrep " + process_name + " -u " + user; - } else { - command = "pidof -s " + process_name; - } - ::FILE *fp = nullptr; - if ((fp = ::popen(command.c_str(), "r")) == nullptr) { - SEN_HILOGE("Failed to open, cmd:%{public}s", command.c_str()); - fp = nullptr; - return DEFAULT_PID; - } - char buf[100] = { 0 }; - if (::fgets(buf, sizeof(buf), fp) == nullptr) { - SEN_HILOGE("Failed to read content"); - ::pclose(fp); - fp = nullptr; - return DEFAULT_PID; - } - ::pclose(fp); - return ::atoi(buf); -} - int32_t CpuInfo::GetProcOccupy(int32_t pid) { Proc_Cpu_Occupy info; @@ -129,7 +105,11 @@ int32_t CpuInfo::GetProcOccupy(int32_t pid) } std::string strLine; - std::getline(file, strLine); + if (!std::getline(file, strLine)) { + SEN_HILOGE("getline fail"); + file.close(); + return OHOS::Sensors::ERROR; + } if (strLine.empty()) { SEN_HILOGE("Failed to read content"); file.close(); @@ -170,7 +150,11 @@ int32_t CpuInfo::GetSystemCpuStatInfo(Total_Cpu_Occupy& info) return FILE_OPEN_FAIL; } std::string strLine; - std::getline(statFile, strLine); + if (!std::getline(statFile, strLine)) { + SEN_HILOGE("getline fail"); + statFile.close(); + return STREAM_BUF_READ_FAIL; + } if (strLine.empty()) { SEN_HILOGE("No valid content was read"); statFile.close(); -- Gitee From c11bf14d6c9ae4436fd2f57cf1af2c7f6247459b Mon Sep 17 00:00:00 2001 From: hui1975 Date: Wed, 2 Nov 2022 11:50:37 +0800 Subject: [PATCH 12/22] =?UTF-8?q?=E6=B3=9Bsensor=E8=B4=A8=E9=87=8F?= =?UTF-8?q?=E5=8A=A0=E5=9B=BA=E4=BB=A3=E7=A0=81=E6=A3=80=E8=A7=86=E6=84=8F?= =?UTF-8?q?=E8=A7=81=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: hui1975 Change-Id: I47de3421fc5205b0d3a97a2f03e0295836c590b8 --- services/sensor/src/sensor_service_stub.cpp | 40 +++++++++++++++++---- 1 file changed, 34 insertions(+), 6 deletions(-) diff --git a/services/sensor/src/sensor_service_stub.cpp b/services/sensor/src/sensor_service_stub.cpp index bed7a011..554843f2 100644 --- a/services/sensor/src/sensor_service_stub.cpp +++ b/services/sensor/src/sensor_service_stub.cpp @@ -77,7 +77,11 @@ int32_t SensorServiceStub::OnRemoteRequest(uint32_t code, MessageParcel &data, M ErrCode SensorServiceStub::SensorEnableInner(MessageParcel &data, MessageParcel &reply) { (void)reply; - uint32_t sensorId = data.ReadUint32(); + uint32_t sensorId; + if (!data.ReadUint32(sensorId)) { + SEN_HILOGE("Parcel read failed"); + return ERROR; + } PermissionUtil &permissionUtil = PermissionUtil::GetInstance(); int32_t ret = permissionUtil.CheckSensorPermission(GetCallingTokenID(), sensorId); if (ret != PERMISSION_GRANTED) { @@ -86,13 +90,23 @@ ErrCode SensorServiceStub::SensorEnableInner(MessageParcel &data, MessageParcel SEN_HILOGE("sensorId:%{public}u grant failed,result:%{public}d", sensorId, ret); return PERMISSION_DENIED; } - return EnableSensor(sensorId, data.ReadInt64(), data.ReadInt64()); + int64_t samplingPeriodNs; + int64_t maxReportDelayNs; + if ((!data.ReadInt64(samplingPeriodNs)) || (!data.ReadInt64(maxReportDelayNs))) { + SEN_HILOGE("Parcel read failed"); + return ERROR; + } + return EnableSensor(sensorId, samplingPeriodNs, maxReportDelayNs); } ErrCode SensorServiceStub::SensorDisableInner(MessageParcel &data, MessageParcel &reply) { (void)reply; - uint32_t sensorId = data.ReadUint32(); + uint32_t sensorId; + if (!data.ReadUint32(sensorId)) { + SEN_HILOGE("Parcel read failed"); + return ERROR; + } PermissionUtil &permissionUtil = PermissionUtil::GetInstance(); int32_t ret = permissionUtil.CheckSensorPermission(GetCallingTokenID(), sensorId); if (ret != PERMISSION_GRANTED) { @@ -107,7 +121,11 @@ ErrCode SensorServiceStub::SensorDisableInner(MessageParcel &data, MessageParcel ErrCode SensorServiceStub::GetSensorStateInner(MessageParcel &data, MessageParcel &reply) { (void)reply; - uint32_t sensorId = data.ReadUint32(); + uint32_t sensorId; + if (!data.ReadUint32(sensorId)) { + SEN_HILOGE("Parcel read failed"); + return ERROR; + } PermissionUtil &permissionUtil = PermissionUtil::GetInstance(); int32_t ret = permissionUtil.CheckSensorPermission(GetCallingTokenID(), sensorId); if (ret != PERMISSION_GRANTED) { @@ -122,7 +140,11 @@ ErrCode SensorServiceStub::GetSensorStateInner(MessageParcel &data, MessageParce ErrCode SensorServiceStub::RunCommandInner(MessageParcel &data, MessageParcel &reply) { (void)reply; - uint32_t sensorId = data.ReadUint32(); + uint32_t sensorId; + if (!data.ReadUint32(sensorId)) { + SEN_HILOGE("Parcel read failed"); + return ERROR; + } PermissionUtil &permissionUtil = PermissionUtil::GetInstance(); int32_t ret = permissionUtil.CheckSensorPermission(GetCallingTokenID(), sensorId); if (ret != PERMISSION_GRANTED) { @@ -131,7 +153,13 @@ ErrCode SensorServiceStub::RunCommandInner(MessageParcel &data, MessageParcel &r SEN_HILOGE("sensorId:%{public}u grant failed,result:%{public}d", sensorId, ret); return PERMISSION_DENIED; } - return RunCommand(sensorId, data.ReadUint32(), data.ReadUint32()); + uint32_t cmdType; + uint32_t params; + if ((!data.ReadUint32(cmdType)) || (!data.ReadUint32(params))) { + SEN_HILOGE("Parcel read failed"); + return ERROR; + } + return RunCommand(sensorId, cmdType, params); } ErrCode SensorServiceStub::GetAllSensorsInner(MessageParcel &data, MessageParcel &reply) -- Gitee From 7c27ed92de17e853f808dfb61bd8cc8fb5115b51 Mon Sep 17 00:00:00 2001 From: wuzhihuitmac Date: Wed, 2 Nov 2022 13:14:14 +0000 Subject: [PATCH 13/22] change return to continue Signed-off-by: wuzhihuitmac Change-Id: I316f2dd557761c6912f46ccafb6019bebcc9af1c --- test/unittest/common/src/system_info.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/test/unittest/common/src/system_info.cpp b/test/unittest/common/src/system_info.cpp index ca58063e..9dfff775 100644 --- a/test/unittest/common/src/system_info.cpp +++ b/test/unittest/common/src/system_info.cpp @@ -67,8 +67,7 @@ int32_t CpuInfo::GetTaskPidFile(const std::string& process_name) std::string strLine; if (!std::getline(filePath, strLine)) { SEN_HILOGE("getline fail"); - filePath.close(); - return DEFAULT_PID; + continue; } if (strLine.empty()) { filePath.close(); -- Gitee From 64a8ccff5a0606dbe16e84dd684d59207bb7183f Mon Sep 17 00:00:00 2001 From: lixiangpeng5 Date: Thu, 3 Nov 2022 11:30:47 +0800 Subject: [PATCH 14/22] =?UTF-8?q?system=5Finfo.cpp=E5=AE=89=E5=85=A8?= =?UTF-8?q?=E7=BC=96=E7=A0=81=E6=95=B4=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: lixiangpeng5 Change-Id: I5d279873f9d98e702954795c120c2fbddd80330f --- test/unittest/common/src/system_info.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/test/unittest/common/src/system_info.cpp b/test/unittest/common/src/system_info.cpp index 9dfff775..97784bbb 100644 --- a/test/unittest/common/src/system_info.cpp +++ b/test/unittest/common/src/system_info.cpp @@ -67,6 +67,7 @@ int32_t CpuInfo::GetTaskPidFile(const std::string& process_name) std::string strLine; if (!std::getline(filePath, strLine)) { SEN_HILOGE("getline fail"); + filePath.close(); continue; } if (strLine.empty()) { -- Gitee From 680092b8efaa2abf507b7c332b09409b79c9d48c Mon Sep 17 00:00:00 2001 From: hui1975 Date: Thu, 3 Nov 2022 19:23:54 +0800 Subject: [PATCH 15/22] =?UTF-8?q?sensor=E4=B8=ADread()=E8=BF=94=E5=9B=9E?= =?UTF-8?q?=E5=80=BC=E6=A0=A1=E9=AA=8C=E4=B8=93=E9=A1=B9=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: hui1975 Change-Id: Ia6f8aa216f6978102cc655caf23af38bbea41bc2 --- .../sensor/src/sensor_service_proxy.cpp | 6 +++- utils/src/sensor.cpp | 28 ++++++++++--------- 2 files changed, 20 insertions(+), 14 deletions(-) diff --git a/frameworks/native/sensor/src/sensor_service_proxy.cpp b/frameworks/native/sensor/src/sensor_service_proxy.cpp index b0406b7a..76be0c8c 100755 --- a/frameworks/native/sensor/src/sensor_service_proxy.cpp +++ b/frameworks/native/sensor/src/sensor_service_proxy.cpp @@ -177,7 +177,11 @@ std::vector SensorServiceProxy::GetSensorList() SEN_HILOGE("failed, ret:%{public}d", ret); return sensors; } - int32_t sensorCount = reply.ReadInt32(); + int32_t sensorCount; + if (!reply.ReadInt32(sensorCount)) { + SEN_HILOGE("Parcel read failed"); + return sensors; + } SEN_HILOGD("sensorCount:%{public}d", sensorCount); if (sensorCount > MAX_SENSOR_COUNT) { sensorCount = MAX_SENSOR_COUNT; diff --git a/utils/src/sensor.cpp b/utils/src/sensor.cpp index 3c0c2b7c..69d5a512 100644 --- a/utils/src/sensor.cpp +++ b/utils/src/sensor.cpp @@ -241,19 +241,21 @@ std::unique_ptr Sensor::Unmarshalling(Parcel &parcel) bool Sensor::ReadFromParcel(Parcel &parcel) { - sensorId_ = parcel.ReadUint32(); - sensorTypeId_ = parcel.ReadUint32(); - sensorName_ = parcel.ReadString(); - vendorName_ = parcel.ReadString(); - firmwareVersion_ = parcel.ReadString(); - hardwareVersion_ = parcel.ReadString(); - power_ = parcel.ReadFloat(); - maxRange_ = parcel.ReadFloat(); - resolution_ = parcel.ReadFloat(); - flags_ = parcel.ReadUint32(); - fifoMaxEventCount_ = parcel.ReadInt32(); - minSamplePeriodNs_ = parcel.ReadInt64(); - maxSamplePeriodNs_ = parcel.ReadInt64(); + if ((!parcel.ReadUint32(sensorId_)) || + (!parcel.ReadUint32(sensorTypeId_)) || + (!parcel.ReadString(sensorName_)) || + (!parcel.ReadString(vendorName_)) || + (!parcel.ReadString(firmwareVersion_)) || + (!parcel.ReadString(hardwareVersion_)) || + (!parcel.ReadFloat(power_)) || + (!parcel.ReadFloat(maxRange_)) || + (!parcel.ReadFloat(resolution_)) || + (!parcel.ReadUint32(flags_)) || + (!parcel.ReadInt32(fifoMaxEventCount_)) || + (!parcel.ReadInt64(minSamplePeriodNs_)) || + (!parcel.ReadInt64(maxSamplePeriodNs_))) { + return false; + } return true; } } // namespace Sensors -- Gitee From 66de21e9cbdae104e62dc3db560329062c688d30 Mon Sep 17 00:00:00 2001 From: lixiangpeng5 Date: Thu, 3 Nov 2022 14:06:57 +0800 Subject: [PATCH 16/22] memcpy_s parameter modify Signed-off-by: lixiangpeng5 Change-Id: Ie2e2cd344f09302737ab48859f6e4caecbe6174b --- interfaces/plugin/src/sensor_js.cpp | 3 ++- .../hdi_connection/adapter/src/compatible_connection.cpp | 2 +- services/sensor/src/client_info.cpp | 2 +- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/interfaces/plugin/src/sensor_js.cpp b/interfaces/plugin/src/sensor_js.cpp index c87bb402..349d1ef7 100644 --- a/interfaces/plugin/src/sensor_js.cpp +++ b/interfaces/plugin/src/sensor_js.cpp @@ -80,7 +80,8 @@ static bool copySensorData(sptr callbackInfo, SensorEvent *ev (fabs(g_bodyState - BODY_STATE_EXCEPT) < THREESHOLD) ? true : false; return true; } - if (memcpy_s(callbackInfo->data.sensorData.data, event->dataLen, data, event->dataLen) != EOK) { + if (memcpy_s(callbackInfo->data.sensorData.data, sizeof(callbackInfo->data.sensorData.data), + data, event->dataLen) != EOK) { SEN_HILOGE("Copy data failed"); return false; } diff --git a/services/sensor/hdi_connection/adapter/src/compatible_connection.cpp b/services/sensor/hdi_connection/adapter/src/compatible_connection.cpp index f57f0b9a..7218e86f 100644 --- a/services/sensor/hdi_connection/adapter/src/compatible_connection.cpp +++ b/services/sensor/hdi_connection/adapter/src/compatible_connection.cpp @@ -141,7 +141,7 @@ int32_t CompatibleConnection::SensorDataCallback(const SensorEvents *event) .dataLen = event->dataLen }; CHKPR(sensorData.data, ERR_INVALID_VALUE); - errno_t ret = memcpy_s(sensorData.data, event->dataLen, event->data, event->dataLen); + errno_t ret = memcpy_s(sensorData.data, sizeof(sensorData.data), event->data, event->dataLen); if (ret != EOK) { SEN_HILOGE("copy data failed"); return COPY_ERR; diff --git a/services/sensor/src/client_info.cpp b/services/sensor/src/client_info.cpp index 15e68601..0cf42eeb 100644 --- a/services/sensor/src/client_info.cpp +++ b/services/sensor/src/client_info.cpp @@ -432,7 +432,7 @@ int32_t ClientInfo::GetStoreEvent(int32_t sensorId, SensorData &data) std::lock_guard lock(eventMutex_); auto storedEvent = storedEvent_.find(sensorId); if (storedEvent != storedEvent_.end()) { - errno_t ret = memcpy_s(&data, sizeof(SensorData), &storedEvent->second, sizeof(SensorData)); + errno_t ret = memcpy_s(&data, sizeof(data), &storedEvent->second, sizeof(storedEvent->second)); if (ret != EOK) { SEN_HILOGE("memcpy_s failed, sensorId:%{public}d", sensorId); return ret; -- Gitee From 9a8c71caf729639db364ce6bae6f9e430cf7c0f6 Mon Sep 17 00:00:00 2001 From: lixiangpeng5 Date: Thu, 3 Nov 2022 21:36:03 +0800 Subject: [PATCH 17/22] =?UTF-8?q?=E6=B8=85=E9=99=A4=E5=91=8A=E8=AD=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: lixiangpeng5 Change-Id: I75f62c07f41f7c5814b06e91793ca68e8f3599d2 --- test/unittest/common/include/system_info.h | 1 - 1 file changed, 1 deletion(-) diff --git a/test/unittest/common/include/system_info.h b/test/unittest/common/include/system_info.h index 8b11a249..d9afcfea 100644 --- a/test/unittest/common/include/system_info.h +++ b/test/unittest/common/include/system_info.h @@ -62,7 +62,6 @@ private: int32_t GetSystemCpuStatInfo(Total_Cpu_Occupy& info); int64_t GetSystemTotalOccupy(); double GetCpuUsage(const Total_Cpu_Occupy& first, const Total_Cpu_Occupy& second); - }; } // namespace SYSTEM_INFO } // namespace Sensors -- Gitee From bc82e9e4acb1389cd844da1a866265555758e8fb Mon Sep 17 00:00:00 2001 From: Chao Liu Date: Fri, 4 Nov 2022 11:21:00 +0800 Subject: [PATCH 18/22] Fix typo in sensor repo Signed-off-by: Chao Liu --- README.md | 2 +- .../sensor/src/sensor_service_client.cpp | 2 +- .../sensor/src/sensor_service_proxy.cpp | 2 +- interfaces/native/include/sensor_agent_type.h | 2 +- .../test/unittest/sensor_agent_test.cpp | 6 +- interfaces/plugin/src/sensor_js.cpp | 6 +- interfaces/plugin/src/sensor_napi_utils.cpp | 10 +- .../test/unittest/ExampleJsunit.test.js | 212 +++++++++--------- services/sensor/src/sensor_data_processer.cpp | 4 +- services/sensor/src/sensor_service.cpp | 8 +- services/sensor/src/sensor_suspend_policy.cpp | 8 +- test/unittest/common/include/system_info.h | 2 +- test/unittest/common/src/system_info.cpp | 12 +- utils/include/miscdevice_common.h | 2 +- utils/include/report_data_callback.h | 2 +- utils/include/sensor_catalog.h | 2 +- utils/include/sensors_errors.h | 2 +- 17 files changed, 142 insertions(+), 142 deletions(-) diff --git a/README.md b/README.md index fe90d5a7..cdada016 100755 --- a/README.md +++ b/README.md @@ -145,7 +145,7 @@ The sensor JS APIs listen for sensor data changes. If an API is called multiple 1. Import the sensor package. 2. Subscribe to and listen for data changes of an acceleration sensor. 3. Unsubscribe from data changes of the acceleration sensor. -4. Subscribe to and listen for a data change of a acceleration sensor. +4. Subscribe to and listen for a data change of an acceleration sensor. Example: diff --git a/frameworks/native/sensor/src/sensor_service_client.cpp b/frameworks/native/sensor/src/sensor_service_client.cpp index df26d269..4d41a198 100755 --- a/frameworks/native/sensor/src/sensor_service_client.cpp +++ b/frameworks/native/sensor/src/sensor_service_client.cpp @@ -209,7 +209,7 @@ void SensorServiceClient::ProcessDeathObserver(const wptr &object CALL_LOG_ENTER; (void)object; CHKPV(dataChannel_); - // STEP1 : Destroy revious data channel + // STEP1 : Destroy previous data channel dataChannel_->DestroySensorDataChannel(); // STEP2 : Restore data channel dataChannel_->RestoreSensorDataChannel(); diff --git a/frameworks/native/sensor/src/sensor_service_proxy.cpp b/frameworks/native/sensor/src/sensor_service_proxy.cpp index b0406b7a..e7600b7d 100755 --- a/frameworks/native/sensor/src/sensor_service_proxy.cpp +++ b/frameworks/native/sensor/src/sensor_service_proxy.cpp @@ -65,7 +65,7 @@ ErrCode SensorServiceProxy::EnableSensor(uint32_t sensorId, int64_t samplingPeri int32_t ret = remote->SendRequest(ISensorService::ENABLE_SENSOR, data, reply, option); if (ret != NO_ERROR) { HiSysEvent::Write(HiSysEvent::Domain::SENSOR, "SENSOR_SERVICE_IPC_EXCEPTION", - HiSysEvent::EventType::FAULT, "PKG_NAME", "EnaleSensor", "ERROR_CODE", ret); + HiSysEvent::EventType::FAULT, "PKG_NAME", "EnableSensor", "ERROR_CODE", ret); SEN_HILOGE("failed, ret:%{public}d", ret); } return static_cast(ret); diff --git a/interfaces/native/include/sensor_agent_type.h b/interfaces/native/include/sensor_agent_type.h index 78479e4e..f780e3e5 100644 --- a/interfaces/native/include/sensor_agent_type.h +++ b/interfaces/native/include/sensor_agent_type.h @@ -112,7 +112,7 @@ typedef struct SensorInfo { float precision; /**< Sensor accuracy */ float power; /**< Sensor power */ int64_t minSamplePeriod; /**< Minimum sample period allowed, in ns */ - int64_t maxSamplePeriod; /**< Maxmum sample period allowed, in ns */ + int64_t maxSamplePeriod; /**< Maximum sample period allowed, in ns */ } SensorInfo; /** diff --git a/interfaces/native/test/unittest/sensor_agent_test.cpp b/interfaces/native/test/unittest/sensor_agent_test.cpp index 4dc06b25..412af371 100755 --- a/interfaces/native/test/unittest/sensor_agent_test.cpp +++ b/interfaces/native/test/unittest/sensor_agent_test.cpp @@ -326,7 +326,7 @@ HWTEST_F(SensorAgentTest, SetModeTest_003, TestSize.Level1) * Function: SubscribeSensor * FunctionPoints: Check the interface function * EnvConditions: mobile that can run ohos test framework - * CaseDescription: Verify the senser service framework process. + * CaseDescription: Verify the sensor service framework process. */ HWTEST_F(SensorAgentTest, SensorNativeApiTest_001, TestSize.Level1) { @@ -361,7 +361,7 @@ HWTEST_F(SensorAgentTest, GetProcCpuUsageTest_001, TestSize.Level1) const std::string process_name = "sensors"; auto usage = cpuInfo.GetProcCpuUsage(process_name); SEN_HILOGD("The CPU usage of the %{public}s process is %{public}.2f", process_name.c_str(), usage); - ASSERT_TRUE(usage < SYSTEM_INFO::CPU_USAGE_LOAD && usage != SYSTEM_INFO::CPU_USAGE_UNKONW); + ASSERT_TRUE(usage < SYSTEM_INFO::CPU_USAGE_LOAD && usage != SYSTEM_INFO::CPU_USAGE_UNKNOWN); } /* @@ -369,7 +369,7 @@ HWTEST_F(SensorAgentTest, GetProcCpuUsageTest_001, TestSize.Level1) * Function: GetAllSensors * FunctionPoints: Check the interface function * EnvConditions: mobile that can run ohos test framework - * CaseDescription: Verify the senser service framework process. + * CaseDescription: Verify the sensor service framework process. */ HWTEST_F(SensorAgentTest, SensorListTest_001, TestSize.Level1) { diff --git a/interfaces/plugin/src/sensor_js.cpp b/interfaces/plugin/src/sensor_js.cpp index c87bb402..fd0d3985 100644 --- a/interfaces/plugin/src/sensor_js.cpp +++ b/interfaces/plugin/src/sensor_js.cpp @@ -40,7 +40,7 @@ constexpr int32_t INVALID_SENSOR_ID = -1; constexpr int32_t SENSOR_SUBSCRIBE_FAILURE = 1001; constexpr int32_t INPUT_ERROR = 202; constexpr float BODY_STATE_EXCEPT = 1.0f; -constexpr float THREESHOLD = 0.000001f; +constexpr float THRESHOLD = 0.000001f; } static std::map g_samplingPeriod = { {"normal", 200000000}, @@ -77,7 +77,7 @@ static bool copySensorData(sptr callbackInfo, SensorEvent *ev std::lock_guard onBodyLock(bodyMutex_); g_bodyState = *data; callbackInfo->data.sensorData.data[0] = - (fabs(g_bodyState - BODY_STATE_EXCEPT) < THREESHOLD) ? true : false; + (fabs(g_bodyState - BODY_STATE_EXCEPT) < THRESHOLD) ? true : false; return true; } if (memcpy_s(callbackInfo->data.sensorData.data, event->dataLen, data, event->dataLen) != EOK) { @@ -1212,7 +1212,7 @@ napi_value GetBodyState(napi_env env, napi_callback_info info) "register success callback fail"); std::lock_guard onBodyLock(bodyMutex_); asyncCallbackInfo->data.sensorData.data[0] = - (fabs(g_bodyState - BODY_STATE_EXCEPT) < THREESHOLD) ? true : false; + (fabs(g_bodyState - BODY_STATE_EXCEPT) < THRESHOLD) ? true : false; EmitUvEventLoop(asyncCallbackInfo); return nullptr; } diff --git a/interfaces/plugin/src/sensor_napi_utils.cpp b/interfaces/plugin/src/sensor_napi_utils.cpp index 4ee5a4b4..3a29492b 100644 --- a/interfaces/plugin/src/sensor_napi_utils.cpp +++ b/interfaces/plugin/src/sensor_napi_utils.cpp @@ -318,8 +318,8 @@ bool ConvertToSensorData(const napi_env &env, sptr asyncCallb return ConvertToBodyData(env, asyncCallbackInfo, result); } size_t size = g_sensorAttributeList[sensorTypeId].size(); - uint32_t dataLenth = asyncCallbackInfo->data.sensorData.dataLength / sizeof(float); - CHKNCF(env, (size <= dataLenth), "Data length mismatch"); + uint32_t dataLength = asyncCallbackInfo->data.sensorData.dataLength / sizeof(float); + CHKNCF(env, (size <= dataLength), "Data length mismatch"); CHKNRF(env, napi_create_object(env, &result[1]), "napi_create_object"); napi_value message = nullptr; @@ -434,7 +434,7 @@ void EmitAsyncCallbackWork(sptr asyncCallbackInfo) sptr asyncCallbackInfo(static_cast(data)); /** * After the asynchronous task is created, the asyncCallbackInfo reference count is reduced - * to 0 destructions, so you need to add 1 to the asyncCallbackInfo reference count when the + * to 0 destruction, so you need to add 1 to the asyncCallbackInfo reference count when the * asynchronous task is created, and subtract 1 from the reference count after the naked * pointer is converted to a pointer when the asynchronous task is executed, the reference * count of the smart pointer is guaranteed to be 1. @@ -494,7 +494,7 @@ void EmitUvEventLoop(sptr asyncCallbackInfo) DeleteWork(work); /** * After the asynchronous task is created, the asyncCallbackInfo reference count is reduced - * to 0 destructions, so you need to add 1 to the asyncCallbackInfo reference count when the + * to 0 destruction, so you need to add 1 to the asyncCallbackInfo reference count when the * asynchronous task is created, and subtract 1 from the reference count after the naked * pointer is converted to a pointer when the asynchronous task is executed, the reference * count of the smart pointer is guaranteed to be 1. @@ -554,7 +554,7 @@ void EmitPromiseWork(sptr asyncCallbackInfo) sptr asyncCallbackInfo(static_cast(data)); /** * After the asynchronous task is created, the asyncCallbackInfo reference count is reduced - * to 0 destructions, so you need to add 1 to the asyncCallbackInfo reference count when the + * to 0 destruction, so you need to add 1 to the asyncCallbackInfo reference count when the * asynchronous task is created, and subtract 1 from the reference count after the naked * pointer is converted to a pointer when the asynchronous task is executed, the reference * count of the smart pointer is guaranteed to be 1. diff --git a/interfaces/plugin/test/unittest/ExampleJsunit.test.js b/interfaces/plugin/test/unittest/ExampleJsunit.test.js index 3ab3807c..aa037534 100755 --- a/interfaces/plugin/test/unittest/ExampleJsunit.test.js +++ b/interfaces/plugin/test/unittest/ExampleJsunit.test.js @@ -2052,7 +2052,7 @@ describe("SensorJsTest", function () { ] /* * @tc.name: Sensor_CreateRotationMatrix_012 - * @tc.desc: Verfication results of the incorrect parameters of test interface. + * @tc.desc: Verification results of the incorrect parameters of test interface. * @tc.require: I5SWJI * @tc.author: */ @@ -2076,7 +2076,7 @@ describe("SensorJsTest", function () { /* * tc.name: Sensor_CreateRotationMatrix_013 - * tc.desc: Verfication results of the incorrect parameters of test interface. + * tc.desc: Verification results of the incorrect parameters of test interface. * tc.require: SR000GH2A2 * @tc.author: */ @@ -2098,7 +2098,7 @@ describe("SensorJsTest", function () { /* * tc.name: Sensor_CreateRotationMatrix_014 - * tc.desc: Verfication results of the incorrect parameters of test interface. + * tc.desc: Verification results of the incorrect parameters of test interface. * tc.require: I5SWJI * @tc.author: */ @@ -2758,17 +2758,17 @@ describe("SensorJsTest", function () { ] /* - * @tc.name: Sensor_CreateQuaterniont_001 - * @tc.desc: Verfication results of the incorrect parameters of test interface. + * @tc.name: Sensor_CreateQuaternion_001 + * @tc.desc: Verification results of the incorrect parameters of test interface. * @tc.require: AR000GH2RP * @tc.author: */ - it('Sensor_CreateQuaterniont_001', 0,async function (done) { - console.info('Sensor_CreateQuaterniont_001 start') + it('Sensor_CreateQuaternion_001', 0,async function (done) { + console.info('Sensor_CreateQuaternion_001 start') sensor.getQuaternion([0.52, -0.336, -0.251], (error, data) =>{ - console.info('Sensor_CreateQuaterniont_001' + 'lengh:' + data.length); + console.info('Sensor_CreateQuaternion_001' + 'length:' + data.length); if (error) { - console.info('Sensor_CreateQuaterniont_001 failed'); + console.info('Sensor_CreateQuaternion_001 failed'); expect(false).assertTrue(); } else { for (var i = 0; i < data.length; i++) { @@ -2781,16 +2781,16 @@ describe("SensorJsTest", function () { }) /* - * @tc.name: Sensor_CreateQuaterniont_002 - * @tc.desc: Verfication results of the incorrect parameters of test interface. + * @tc.name: Sensor_CreateQuaternion_002 + * @tc.desc: Verification results of the incorrect parameters of test interface. * @tc.require: AR000GH2RP * @tc.author: */ - it('Sensor_CreateQuaterniont_002', 0,async function (done) { - console.info('Sensor_CreateQuaterniont_002 start') + it('Sensor_CreateQuaternion_002', 0,async function (done) { + console.info('Sensor_CreateQuaternion_002 start') sensor.getQuaternion([3.40282e+38, 3.40282e+38, 3.40282e+38], (error, data) =>{ if (error) { - console.info('Sensor_CreateQuaterniont_002 failed'); + console.info('Sensor_CreateQuaternion_002 failed'); expect(false).assertTrue(); } else { for (var i = 0; i < data.length; i++) { @@ -2803,16 +2803,16 @@ describe("SensorJsTest", function () { }) /* - * @tc.name: Sensor_CreateQuaterniont_003 - * @tc.desc: Verfication results of the incorrect parameters of test interface. + * @tc.name: Sensor_CreateQuaternion_003 + * @tc.desc: Verification results of the incorrect parameters of test interface. * @tc.require: AR000GH2RP * @tc.author: */ - it('Sensor_CreateQuaterniont_003', 0,async function (done) { - console.info('Sensor_CreateQuaterniont_003 start') + it('Sensor_CreateQuaternion_003', 0,async function (done) { + console.info('Sensor_CreateQuaternion_003 start') sensor.getQuaternion([0, 0, 0], (error, data) =>{ if (error) { - console.info('Sensor_CreateQuaterniont_003 failed'); + console.info('Sensor_CreateQuaternion_003 failed'); expect(false).assertTrue(); } else { for (var i = 0; i < data.length; i++) { @@ -2822,20 +2822,20 @@ describe("SensorJsTest", function () { } done() }) - console.info("Sensor_CreateQuaterniont_003 end") + console.info("Sensor_CreateQuaternion_003 end") }) /* - * @tc.name: Sensor_CreateQuaterniont_004 - * @tc.desc: Verfication results of the incorrect parameters of test interface. + * @tc.name: Sensor_CreateQuaternion_004 + * @tc.desc: Verification results of the incorrect parameters of test interface. * @tc.require: AR000GH2RP * @tc.author: */ - it('Sensor_CreateQuaterniont_004', 0,async function (done) { - console.info('Sensor_CreateQuaterniont_004 start') + it('Sensor_CreateQuaternion_004', 0,async function (done) { + console.info('Sensor_CreateQuaternion_004 start') sensor.getQuaternion([-0.325, -0.562, -0.25], (error, data) =>{ if (error) { - console.info('Sensor_CreateQuaterniont_004 failed'); + console.info('Sensor_CreateQuaternion_004 failed'); expect(false).assertTrue(); } else { for (var i = 0; i < data.length; i++) { @@ -2845,17 +2845,17 @@ describe("SensorJsTest", function () { } done() }) - console.info("Sensor_CreateQuaterniont_004 end") + console.info("Sensor_CreateQuaternion_004 end") }) /* - * @tc.name: Sensor_CreateQuaterniont_005 - * @tc.desc: Verfication results of the incorrect parameters of test interface. + * @tc.name: Sensor_CreateQuaternion_005 + * @tc.desc: Verification results of the incorrect parameters of test interface. * @tc.require: AR000GH2RP * @tc.author: */ - it('Sensor_CreateQuaterniont_005', 0,async function (done) { - console.info('Sensor_CreateQuaterniont_005 start') + it('Sensor_CreateQuaternion_005', 0,async function (done) { + console.info('Sensor_CreateQuaternion_005 start') try { sensor.getQuaternion([0.25, 0.14], (error, data) =>{ if (error) { @@ -2870,19 +2870,19 @@ describe("SensorJsTest", function () { expect(err.message).assertEqual(PARAMETER_ERROR_MSG) done() } - console.info("Sensor_CreateQuaterniont_005 end") + console.info("Sensor_CreateQuaternion_005 end") }) /* - * @tc.name: Sensor_CreateQuaterniont_006 - * @tc.desc: Verfication results of the incorrect parameters of test interface. + * @tc.name: Sensor_CreateQuaternion_006 + * @tc.desc: Verification results of the incorrect parameters of test interface. * @tc.require: AR000GH2RP * @tc.author: */ - it('Sensor_CreateQuaterniont_006', 0,async function (done) { - console.info('Sensor_CreateQuaterniont_006 start') + it('Sensor_CreateQuaternion_006', 0,async function (done) { + console.info('Sensor_CreateQuaternion_006 start') sensor.getQuaternion([0.52, -0.336, -0.251]).then((data) => { - console.info('Sensor_CreateQuaterniont_006'); + console.info('Sensor_CreateQuaternion_006'); for (var i = 0; i < data.length; i++) { console.info("data[" + i + "]: " + data[i]); expect(data[i]).assertEqual(result[0][i]) @@ -2893,20 +2893,20 @@ describe("SensorJsTest", function () { console.info('promise failed') done() }) - console.info("Sensor_CreateQuaterniont_006 end") + console.info("Sensor_CreateQuaternion_006 end") }) /* - * @tc.name: Sensor_CreateQuaterniont_007 - * @tc.desc: Verfication results of the incorrect parameters of test interface. + * @tc.name: Sensor_CreateQuaternion_007 + * @tc.desc: Verification results of the incorrect parameters of test interface. * @tc.require: AR000GH2RP * @tc.author: */ - it('Sensor_CreateQuaterniont_007', 0,async function (done) { - console.info('Sensor_CreateQuaterniont_007 start') + it('Sensor_CreateQuaternion_007', 0,async function (done) { + console.info('Sensor_CreateQuaternion_007 start') try { sensor.getQuaternion([0, 0]).then((data) => { - console.info('Sensor_CreateQuaterniont_007'); + console.info('Sensor_CreateQuaternion_007'); expect(false).assertTrue(); done() }, (error) => { @@ -2919,19 +2919,19 @@ describe("SensorJsTest", function () { expect(err.message).assertEqual(PARAMETER_ERROR_MSG) done() } - console.info("Sensor_CreateQuaterniont_007 end") + console.info("Sensor_CreateQuaternion_007 end") }) /* - * @tc.name: Sensor_CreateQuaterniont_008 - * @tc.desc: Verfication results of the incorrect parameters of test interface. + * @tc.name: Sensor_CreateQuaternion_008 + * @tc.desc: Verification results of the incorrect parameters of test interface. * @tc.require: AR000GH2RP * @tc.author: */ - it('Sensor_CreateQuaterniont_008', 0,async function (done) { - console.info('Sensor_CreateQuaterniont_008 start') + it('Sensor_CreateQuaternion_008', 0,async function (done) { + console.info('Sensor_CreateQuaternion_008 start') sensor.getQuaternion([0, 0, 0]).then((data) => { - console.info('Sensor_CreateQuaterniont_008'); + console.info('Sensor_CreateQuaternion_008'); for (var i = 0; i < data.length; i++) { console.info("data[" + i + "]: " + data[i]); expect(data[i]).assertEqual(result[2][i]) @@ -2942,19 +2942,19 @@ describe("SensorJsTest", function () { console.info('promise failed') done() }) - console.info("Sensor_CreateQuaterniont_008 end") + console.info("Sensor_CreateQuaternion_008 end") }) /* - * @tc.name: Sensor_CreateQuaterniont_009 - * @tc.desc: Verfication results of the incorrect parameters of test interface. + * @tc.name: Sensor_CreateQuaternion_009 + * @tc.desc: Verification results of the incorrect parameters of test interface. * @tc.require: AR000GH2RP * @tc.author: */ - it('Sensor_CreateQuaterniont_009', 0,async function (done) { - console.info('Sensor_CreateQuaterniont_009 start') + it('Sensor_CreateQuaternion_009', 0,async function (done) { + console.info('Sensor_CreateQuaternion_009 start') sensor.getQuaternion([-0.325, -0.562, -0.25]).then((data) => { - console.info('Sensor_CreateQuaterniont_009'); + console.info('Sensor_CreateQuaternion_009'); for (var i = 0; i < data.length; i++) { console.info("data[" + i + "]: " + data[i]); expect(data[i]).assertEqual(result[3][i]) @@ -2968,16 +2968,16 @@ describe("SensorJsTest", function () { }) /* - * @tc.name: Sensor_CreateQuaterniont_010 - * @tc.desc: Verfication results of the incorrect parameters of test interface. + * @tc.name: Sensor_CreateQuaternion_010 + * @tc.desc: Verification results of the incorrect parameters of test interface. * @tc.require: AR000GH2RP * @tc.author: */ - it('Sensor_CreateQuaterniont_010', 0,async function (done) { - console.info('Sensor_CreateQuaterniont_010 start') + it('Sensor_CreateQuaternion_010', 0,async function (done) { + console.info('Sensor_CreateQuaternion_010 start') try { sensor.getQuaternion([0.25, 0.14]).then((data) => { - console.info('Sensor_CreateQuaterniont_010'); + console.info('Sensor_CreateQuaternion_010'); expect(false).assertTrue(); done() },(error) => { @@ -2995,12 +2995,12 @@ describe("SensorJsTest", function () { /* * test * - * @tc.name: Sensor_CreateQuaterniont_011 + * @tc.name: Sensor_CreateQuaternion_011 * @tc.desc: Verification results of the incorrect parameters of the test interface. * @tc.require: I5SWJI * @tc.author: */ - it('Sensor_CreateQuaterniont_011', 0, async function (done) { + it('Sensor_CreateQuaternion_011', 0, async function (done) { try { sensor.createQuaternion() } catch (err) { @@ -3013,12 +3013,12 @@ describe("SensorJsTest", function () { /* * test * - * @tc.name: Sensor_CreateQuaterniont_012 + * @tc.name: Sensor_CreateQuaternion_012 * @tc.desc: Verification results of the incorrect parameters of the test interface. * @tc.require: I5SWJI * @tc.author: */ - it('Sensor_CreateQuaterniont_012', 0, async function (done) { + it('Sensor_CreateQuaternion_012', 0, async function (done) { try { sensor.createQuaternion(-1) } catch (err) { @@ -3031,12 +3031,12 @@ describe("SensorJsTest", function () { /* * test * - * @tc.name: Sensor_CreateQuaterniont_013 + * @tc.name: Sensor_CreateQuaternion_013 * @tc.desc: Verification results of the incorrect parameters of the test interface. * @tc.require: I5SWJI * @tc.author: */ - it('Sensor_CreateQuaterniont_013', 0, async function (done) { + it('Sensor_CreateQuaternion_013', 0, async function (done) { try { sensor.createQuaternion([0.52, -0.336, -0.251], -1) } catch (err) { @@ -3049,12 +3049,12 @@ describe("SensorJsTest", function () { /* * test * - * @tc.name: Sensor_CreateQuaterniont_014 + * @tc.name: Sensor_CreateQuaternion_014 * @tc.desc: Verification results of the incorrect parameters of the test interface. * @tc.require: I5SWJI * @tc.author: */ - it('Sensor_CreateQuaterniont_014', 0, async function (done) { + it('Sensor_CreateQuaternion_014', 0, async function (done) { try { sensor.createQuaternion().then((data) => { expect(true).assertfalse() @@ -3073,12 +3073,12 @@ describe("SensorJsTest", function () { /* * test * - * @tc.name: Sensor_CreateQuaterniont_015 + * @tc.name: Sensor_CreateQuaternion_015 * @tc.desc: Verification results of the incorrect parameters of the test interface. * @tc.require: I5SWJI * @tc.author: */ - it('Sensor_CreateQuaterniont_015', 0, async function (done) { + it('Sensor_CreateQuaternion_015', 0, async function (done) { try { sensor.createQuaternion(-1).then((data) => { expect(true).assertfalse() @@ -3097,12 +3097,12 @@ describe("SensorJsTest", function () { /* * test * - * @tc.name: Sensor_CreateQuaterniont_016 + * @tc.name: Sensor_CreateQuaternion_016 * @tc.desc: Verification results of the incorrect parameters of the test interface. * @tc.require: I5SWJI * @tc.author: */ - it('Sensor_CreateQuaterniont_016', 0, async function (done) { + it('Sensor_CreateQuaternion_016', 0, async function (done) { try { sensor.createQuaternion([0.52, -0.336, -0.251], -1).then((data) => { expect(true).assertfalse() @@ -3122,7 +3122,7 @@ describe("SensorJsTest", function () { /* * @tc.name: Sensor_GetGeomagneticDip_001 - * @tc.desc: Verfication results of the incorrect parameters of test interface. + * @tc.desc: Verification results of the incorrect parameters of test interface. * @tc.require: AR000GH2OG * @tc.author: */ @@ -3137,14 +3137,14 @@ describe("SensorJsTest", function () { expect(data).assertEqual(getGeomagneticDipResult[0]) } done() - console.info('Sensor_GetGeomagneticDip_001' + 'lengh:' + data.length); + console.info('Sensor_GetGeomagneticDip_001' + 'length:' + data.length); }) console.info("Sensor_GetGeomagneticDip_001 end") }) /* * @tc.name: Sensor_GetGeomagneticDip_002 - * @tc.desc: Verfication results of the incorrect parameters of test interface. + * @tc.desc: Verification results of the incorrect parameters of test interface. * @tc.require: AR000GH2OG * @tc.author: */ @@ -3169,7 +3169,7 @@ describe("SensorJsTest", function () { /* * @tc.name: Sensor_GetGeomagneticDip_003 - * @tc.desc: Verfication results of the incorrect parameters of test interface. + * @tc.desc: Verification results of the incorrect parameters of test interface. * @tc.require: I5SWJI * @tc.author: */ @@ -3188,7 +3188,7 @@ describe("SensorJsTest", function () { /* * @tc.name: Sensor_GetGeomagneticDip_004 - * @tc.desc: Verfication results of the incorrect parameters of test interface. + * @tc.desc: Verification results of the incorrect parameters of test interface. * @tc.require: I5SWJI * @tc.author: */ @@ -3204,7 +3204,7 @@ describe("SensorJsTest", function () { expect(data).assertEqual(getGeomagneticDipResult[0]) } done() - console.info('Sensor_GetGeomagneticDip_004' + 'lengh:' + data.length); + console.info('Sensor_GetGeomagneticDip_004' + 'length:' + data.length); }) } catch(error) { console.info(error); @@ -3217,7 +3217,7 @@ describe("SensorJsTest", function () { /* * @tc.name: Sensor_GetGeomagneticDip_005 - * @tc.desc: Verfication results of the incorrect parameters of test interface. + * @tc.desc: Verification results of the incorrect parameters of test interface. * @tc.require: I5SWJI * @tc.author: */ @@ -3243,7 +3243,7 @@ describe("SensorJsTest", function () { /* * @tc.name: Sensor_GetGeomagneticDip_006 - * @tc.desc: Verfication results of the incorrect parameters of test interface. + * @tc.desc: Verification results of the incorrect parameters of test interface. * @tc.require: I5SWJI * @tc.author: */ @@ -3269,7 +3269,7 @@ describe("SensorJsTest", function () { /* * @tc.name: Sensor_GetAltitude_001 - * @tc.desc: Verfication results of the incorrect parameters of test interface. + * @tc.desc: Verification results of the incorrect parameters of test interface. * @tc.require: AR000GH2OG * @tc.author: */ @@ -3290,7 +3290,7 @@ describe("SensorJsTest", function () { /* * @tc.name: Sensor_GetAltitude_002 - * @tc.desc: Verfication results of the incorrect parameters of test interface. + * @tc.desc: Verification results of the incorrect parameters of test interface. * @tc.require: AR000GH2OG * @tc.author: */ @@ -3311,7 +3311,7 @@ describe("SensorJsTest", function () { /* * @tc.name: Sensor_GetAltitude_003 - * @tc.desc: Verfication results of the incorrect parameters of test interface. + * @tc.desc: Verification results of the incorrect parameters of test interface. * @tc.require: AR000GH2OG * @tc.author: */ @@ -3329,7 +3329,7 @@ describe("SensorJsTest", function () { /* * @tc.name: Sensor_GetAltitude_004 - * @tc.desc: Verfication results of the incorrect parameters of test interface. + * @tc.desc: Verification results of the incorrect parameters of test interface. * @tc.require: AR000GH2OG * @tc.author: */ @@ -3347,7 +3347,7 @@ describe("SensorJsTest", function () { /* * @tc.name: Sensor_GetAltitude_005 - * @tc.desc: Verfication results of the incorrect parameters of test interface. + * @tc.desc: Verification results of the incorrect parameters of test interface. * @tc.require: I5SWJI * @tc.author: */ @@ -3366,7 +3366,7 @@ describe("SensorJsTest", function () { /* * @tc.name: Sensor_GetAltitude_006 - * @tc.desc: Verfication results of the incorrect parameters of test interface. + * @tc.desc: Verification results of the incorrect parameters of test interface. * @tc.require: I5SWJI * @tc.author: */ @@ -3382,7 +3382,7 @@ describe("SensorJsTest", function () { expect(data).assertEqual(getGeomagneticDipResult[0]) } done() - console.info('Sensor_GetAltitude_006' + 'lengh:' + data.length); + console.info('Sensor_GetAltitude_006' + 'length:' + data.length); }) } catch(error) { console.info(error); @@ -3395,7 +3395,7 @@ describe("SensorJsTest", function () { /* * @tc.name: Sensor_GetAltitude_007 - * @tc.desc: Verfication results of the incorrect parameters of test interface. + * @tc.desc: Verification results of the incorrect parameters of test interface. * @tc.require: I5SWJI * @tc.author: */ @@ -3421,7 +3421,7 @@ describe("SensorJsTest", function () { /* * @tc.name: Sensor_GetAltitude_008 - * @tc.desc: Verfication results of the incorrect parameters of test interface. + * @tc.desc: Verification results of the incorrect parameters of test interface. * @tc.require: I5SWJI * @tc.author: */ @@ -3454,7 +3454,7 @@ describe("SensorJsTest", function () { /* * @tc.name: Sensor_TransformCoordinateSystem_001 - * @tc.desc: Verfication results of the incorrect parameters of test interface. + * @tc.desc: Verification results of the incorrect parameters of test interface. * @tc.require: AR000GH2TR * @tc.author: */ @@ -3474,7 +3474,7 @@ describe("SensorJsTest", function () { /* * @tc.name: Sensor_TransformCoordinateSystem_002 - * @tc.desc: Verfication results of the incorrect parameters of test interface. + * @tc.desc: Verification results of the incorrect parameters of test interface. * @tc.require: AR000GH2TR * @tc.author: */ @@ -3494,7 +3494,7 @@ describe("SensorJsTest", function () { /* * @tc.name: Sensor_TransformCoordinateSystem_003 - * @tc.desc: Verfication results of the incorrect parameters of test interface. + * @tc.desc: Verification results of the incorrect parameters of test interface. * @tc.require: AR000GH2TR * @tc.author: */ @@ -3515,7 +3515,7 @@ describe("SensorJsTest", function () { /* * @tc.name: Sensor_TransformCoordinateSystem_004 - * @tc.desc: Verfication results of the incorrect parameters of test interface. + * @tc.desc: Verification results of the incorrect parameters of test interface. * @tc.require: AR000GH2TR * @tc.author: */ @@ -3536,7 +3536,7 @@ describe("SensorJsTest", function () { /* * @tc.name: Sensor_TransformCoordinateSystem_005 - * @tc.desc: Verfication results of the incorrect parameters of test interface. + * @tc.desc: Verification results of the incorrect parameters of test interface. * @tc.require: I5SWJI * @tc.author: */ @@ -3555,7 +3555,7 @@ describe("SensorJsTest", function () { /* * @tc.name: Sensor_TransformCoordinateSystem_006 - * @tc.desc: Verfication results of the incorrect parameters of test interface. + * @tc.desc: Verification results of the incorrect parameters of test interface. * @tc.require: I5SWJI * @tc.author: */ @@ -3583,7 +3583,7 @@ describe("SensorJsTest", function () { /* * @tc.name: Sensor_TransformCoordinateSystem_007 - * @tc.desc: Verfication results of the incorrect parameters of test interface. + * @tc.desc: Verification results of the incorrect parameters of test interface. * @tc.require: I5SWJI * @tc.author: */ @@ -3609,7 +3609,7 @@ describe("SensorJsTest", function () { /* * @tc.name: Sensor_TransformCoordinateSystem_008 - * @tc.desc: Verfication results of the incorrect parameters of test interface. + * @tc.desc: Verification results of the incorrect parameters of test interface. * @tc.require: I5SWJI * @tc.author: */ @@ -3635,7 +3635,7 @@ describe("SensorJsTest", function () { /* * @tc.name: Sensor_TransformCoordinateSystem_009 - * @tc.desc: Verfication results of the incorrect parameters of test interface. + * @tc.desc: Verification results of the incorrect parameters of test interface. * @tc.require: I5SWJI * @tc.author: */ @@ -3661,7 +3661,7 @@ describe("SensorJsTest", function () { /* * @tc.name: Sensor_TransformCoordinateSystem_010 - * @tc.desc: Verfication results of the incorrect parameters of test interface. + * @tc.desc: Verification results of the incorrect parameters of test interface. * @tc.require: I5SWJI * @tc.author: */ @@ -3689,7 +3689,7 @@ describe("SensorJsTest", function () { /* * @tc.name: Sensor_GetSensorList_001 - * @tc.desc: Verfication results of the incorrect parameters of test interface. + * @tc.desc: Verification results of the incorrect parameters of test interface. * @tc.require: AR000GH2TR * @tc.author: */ @@ -3711,7 +3711,7 @@ describe("SensorJsTest", function () { /* * @tc.name: Sensor_GetSensorList_002 - * @tc.desc: Verfication results of the incorrect parameters of test interface. + * @tc.desc: Verification results of the incorrect parameters of test interface. * @tc.require: AR000GH2TR * @tc.author: */ @@ -3734,7 +3734,7 @@ describe("SensorJsTest", function () { /* * @tc.name: Sensor_GetSensorList_003 - * @tc.desc: Verfication results of the incorrect parameters of test interface. + * @tc.desc: Verification results of the incorrect parameters of test interface. * @tc.require: AR000GH2TR * @tc.author: */ @@ -3752,7 +3752,7 @@ describe("SensorJsTest", function () { /* * @tc.name: Sensor_GetSensorList_004 - * @tc.desc: Verfication results of the incorrect parameters of test interface. + * @tc.desc: Verification results of the incorrect parameters of test interface. * @tc.require: AR000GH2TR * @tc.author: */ @@ -3779,7 +3779,7 @@ describe("SensorJsTest", function () { /* * @tc.name: Sensor_GetSingleSensor_001 - * @tc.desc: Verfication results of the incorrect parameters of test interface. + * @tc.desc: Verification results of the incorrect parameters of test interface. * @tc.require: AR000GH2TR * @tc.author: */ @@ -3800,7 +3800,7 @@ describe("SensorJsTest", function () { /* * @tc.name: Sensor_GetSingleSensor_002 - * @tc.desc: Verfication results of the incorrect parameters of test interface. + * @tc.desc: Verification results of the incorrect parameters of test interface. * @tc.require: AR000GH2TR * @tc.author: */ @@ -3828,7 +3828,7 @@ describe("SensorJsTest", function () { /* * @tc.name: Sensor_GetSingleSensor_003 - * @tc.desc: Verfication results of the incorrect parameters of test interface. + * @tc.desc: Verification results of the incorrect parameters of test interface. * @tc.require: AR000GH2TR * @tc.author: */ @@ -3847,7 +3847,7 @@ describe("SensorJsTest", function () { /* * @tc.name: Sensor_GetSingleSensor_004 - * @tc.desc: Verfication results of the incorrect parameters of test interface. + * @tc.desc: Verification results of the incorrect parameters of test interface. * @tc.require: AR000GH2TR * @tc.author: */ diff --git a/services/sensor/src/sensor_data_processer.cpp b/services/sensor/src/sensor_data_processer.cpp index f2c1daaa..466cd693 100644 --- a/services/sensor/src/sensor_data_processer.cpp +++ b/services/sensor/src/sensor_data_processer.cpp @@ -41,9 +41,9 @@ enum { constexpr uint32_t SENSOR_INDEX_SHIFT = 8; constexpr uint32_t SENSOR_TYPE_SHIFT = 16; -constexpr uint32_t SENSOR_CATAGORY_SHIFT = 24; +constexpr uint32_t SENSOR_CATEGORY_SHIFT = 24; -constexpr uint32_t FLUSH_COMPLETE_ID = ((uint32_t)OTHER << SENSOR_CATAGORY_SHIFT) | +constexpr uint32_t FLUSH_COMPLETE_ID = ((uint32_t)OTHER << SENSOR_CATEGORY_SHIFT) | ((uint32_t)SENSOR_TYPE_FLUSH << SENSOR_TYPE_SHIFT) | ((uint32_t)FIRST_INDEX << SENSOR_INDEX_SHIFT); } // namespace diff --git a/services/sensor/src/sensor_service.cpp b/services/sensor/src/sensor_service.cpp index c25ac318..377e739d 100644 --- a/services/sensor/src/sensor_service.cpp +++ b/services/sensor/src/sensor_service.cpp @@ -366,8 +366,8 @@ ErrCode SensorService::DestroySensorChannel(sptr sensorClient) return CLIENT_PID_INVALID_ERR; } std::lock_guard serviceLock(serviceLock_); - bool destoryRet = clientInfo_.DestroySensorChannel(clientPid); - if (!destoryRet) { + bool destroyRet = clientInfo_.DestroySensorChannel(clientPid); + if (!destroyRet) { SEN_HILOGE("DestroySensorChannel is failed"); return DESTROY_SENSOR_CHANNEL_ERR; } @@ -386,12 +386,12 @@ void SensorService::ProcessDeathObserver(const wptr &object) SEN_HILOGE("pid is -1"); return; } - SEN_HILOGI("pid is %{pubilc}d", pid); + SEN_HILOGI("pid is %{public}d", pid); std::vector activeSensors = clientInfo_.GetSensorIdByPid(pid); for (size_t i = 0; i < activeSensors.size(); ++i) { int32_t ret = DisableSensor(activeSensors[i], pid); if (ret != ERR_OK) { - SEN_HILOGE("disablesensor failed, ret:%{pubilc}d", ret); + SEN_HILOGE("disablesensor failed, ret:%{public}d", ret); } } clientInfo_.DestroySensorChannel(pid); diff --git a/services/sensor/src/sensor_suspend_policy.cpp b/services/sensor/src/sensor_suspend_policy.cpp index 217e2540..1e9f2444 100644 --- a/services/sensor/src/sensor_suspend_policy.cpp +++ b/services/sensor/src/sensor_suspend_policy.cpp @@ -27,10 +27,10 @@ namespace { constexpr HiLogLabel LABEL = { LOG_CORE, SENSOR_LOG_DOMAIN, "SensorSuspendPolicy" }; constexpr uint32_t INVALID_SENSOR_ID = -1; constexpr int64_t MAX_EVENT_COUNT = 1000; -constexpr int64_t DEFAULT_SAMPLEING_RATE = 200000000; +constexpr int64_t DEFAULT_SAMPLING_RATE = 200000000; constexpr int64_t DEFAULT_REPORT_DELAY = 0; constexpr uint32_t STEP_COUNTER_ID = 524544; -constexpr uint32_t STEP_DETECOTR_ID = 590080; +constexpr uint32_t STEP_DETECTOR_ID = 590080; } // namespace SensorSuspendPolicy::~SensorSuspendPolicy() @@ -38,7 +38,7 @@ SensorSuspendPolicy::~SensorSuspendPolicy() bool SensorSuspendPolicy::CheckFreezingSensor(uint32_t sensorId) { - return ((sensorId == STEP_COUNTER_ID) || (sensorId == STEP_DETECOTR_ID)); + return ((sensorId == STEP_COUNTER_ID) || (sensorId == STEP_DETECTOR_ID)); } ErrCode SensorSuspendPolicy::DisableSensor(uint32_t sensorId, int32_t pid) @@ -150,7 +150,7 @@ std::vector SensorSuspendPolicy::GetSensorIdByPid(int32_t pid) void SensorSuspendPolicy::DoActive(const std::shared_ptr &info) { CALL_LOG_ENTER; - int64_t samplePeriod = DEFAULT_SAMPLEING_RATE; + int64_t samplePeriod = DEFAULT_SAMPLING_RATE; int64_t maxReportDelay = DEFAULT_REPORT_DELAY; std::vector sensorIdList; std::lock_guard suspendLock(suspendMutex_); diff --git a/test/unittest/common/include/system_info.h b/test/unittest/common/include/system_info.h index a3ad5de7..a26dd47c 100755 --- a/test/unittest/common/include/system_info.h +++ b/test/unittest/common/include/system_info.h @@ -21,7 +21,7 @@ namespace OHOS { namespace Sensors { namespace SYSTEM_INFO { -static constexpr double CPU_USAGE_UNKONW = -1.0; +static constexpr double CPU_USAGE_UNKNOWN = -1.0; static constexpr double CPU_USAGE_LOAD = 20.0; static constexpr double CPU_USAGE_MAX = 100.0; class SystemInfo { diff --git a/test/unittest/common/src/system_info.cpp b/test/unittest/common/src/system_info.cpp index f21a27cc..0142c928 100755 --- a/test/unittest/common/src/system_info.cpp +++ b/test/unittest/common/src/system_info.cpp @@ -195,14 +195,14 @@ double CpuInfo::GetSystemCpuUsage() int32_t ret = GetSystemCpuStatInfo(first); if (ret != OHOS::Sensors::SUCCESS) { SEN_HILOGE("Failed to obtain CPU information, errcode:%{public}d", ret); - return CPU_USAGE_UNKONW; + return CPU_USAGE_UNKNOWN; } std::this_thread::sleep_for(std::chrono::milliseconds(TIME_WAIT_FOR_OP)); Total_Cpu_Occupy second {}; ret = GetSystemCpuStatInfo(second); if (ret != OHOS::Sensors::SUCCESS) { SEN_HILOGE("Failed to obtain CPU information, errcode:%{public}d", ret); - return CPU_USAGE_UNKONW; + return CPU_USAGE_UNKNOWN; } return GetCpuUsage(first, second); @@ -229,22 +229,22 @@ double CpuInfo::GetProcCpuUsage(const std::string& process_name) if ((totalTime1 = GetSystemTotalOccupy()) == OHOS::Sensors::ERROR) { SEN_HILOGE("Failed to obtain CPU occupy"); - return CPU_USAGE_UNKONW; + return CPU_USAGE_UNKNOWN; } if ((procTime1 = GetProcOccupy(pid)) == OHOS::Sensors::ERROR) { SEN_HILOGE("Failed to obtain process CPU information"); - return CPU_USAGE_UNKONW; + return CPU_USAGE_UNKNOWN; } std::this_thread::sleep_for(std::chrono::milliseconds(TIME_WAIT_FOR_OP)); if ((totalTime2 = GetSystemTotalOccupy()) == OHOS::Sensors::ERROR) { SEN_HILOGE("Failed to obtain CPU occupy"); - return CPU_USAGE_UNKONW; + return CPU_USAGE_UNKNOWN; } if ((procTime2 = GetProcOccupy(pid)) == OHOS::Sensors::ERROR) { SEN_HILOGE("Failed to obtain process CPU information"); - return CPU_USAGE_UNKONW; + return CPU_USAGE_UNKNOWN; } return CHK_RATE(CPU_USAGE_MAX * (procTime2 - procTime1) / (totalTime2 - totalTime1)); diff --git a/utils/include/miscdevice_common.h b/utils/include/miscdevice_common.h index 9932d560..ad742270 100755 --- a/utils/include/miscdevice_common.h +++ b/utils/include/miscdevice_common.h @@ -21,7 +21,7 @@ namespace OHOS { namespace Sensors { -// These LightId correspand to logical lights +// These LightId correspond to logical lights enum LightId { LIGHT_ID_LED = 0, LIGHT_ID_KEYBOARD, diff --git a/utils/include/report_data_callback.h b/utils/include/report_data_callback.h index 608e9a7b..c7c6fa37 100644 --- a/utils/include/report_data_callback.h +++ b/utils/include/report_data_callback.h @@ -22,7 +22,7 @@ namespace OHOS { namespace Sensors { constexpr int32_t CIRCULAR_BUF_LEN = 1024; -constexpr int32_t SENSOR_DATA_LENGHT = 64; +constexpr int32_t SENSOR_DATA_LENGTH = 64; struct CircularEventBuf { struct SensorData *circularBuf; diff --git a/utils/include/sensor_catalog.h b/utils/include/sensor_catalog.h index 5856f6d5..37b70458 100755 --- a/utils/include/sensor_catalog.h +++ b/utils/include/sensor_catalog.h @@ -82,7 +82,7 @@ enum GroupBody { }; struct SensorCombination { - SensorGroup sensorCatagory; + SensorGroup sensorCategory; uint8_t sensorType; uint8_t sensorIndex; }; diff --git a/utils/include/sensors_errors.h b/utils/include/sensors_errors.h index 7c205893..7279ab75 100644 --- a/utils/include/sensors_errors.h +++ b/utils/include/sensors_errors.h @@ -93,7 +93,7 @@ enum { REGIST_CALLBACK_ERR = SET_SENSOR_OPTION_ERR + 1, }; -// Error code for Sensor uitls +// Error code for Sensor utils constexpr ErrCode SENSOR_UTILS_ERR_OFFSET = ErrCodeOffset(SUBSYS_SENSORS, MODULE_SENSORS_UTILS); enum { SENSOR_CHANNEL_SOCKET_CREATE_ERR = SENSOR_UTILS_ERR_OFFSET, -- Gitee From e559283930667a187b40ed612a3afd1002753649 Mon Sep 17 00:00:00 2001 From: Chao Liu Date: Fri, 4 Nov 2022 14:49:17 +0800 Subject: [PATCH 19/22] Fix:'var' is used instead of 'let' or 'const' Signed-off-by: Chao Liu --- .../test/unittest/ExampleJsunit.test.js | 80 +++++++++---------- 1 file changed, 40 insertions(+), 40 deletions(-) diff --git a/interfaces/plugin/test/unittest/ExampleJsunit.test.js b/interfaces/plugin/test/unittest/ExampleJsunit.test.js index aa037534..c235c0f2 100755 --- a/interfaces/plugin/test/unittest/ExampleJsunit.test.js +++ b/interfaces/plugin/test/unittest/ExampleJsunit.test.js @@ -33,21 +33,21 @@ describe("SensorJsTest", function () { */ console.info('beforeAll caled') }) - + afterAll(function() { /* * @tc.teardown: teardown invoked after all testcases */ console.info('afterAll caled') }) - + beforeEach(function() { /* * @tc.setup: setup invoked before each testcases */ console.info('beforeEach caled') }) - + afterEach(function() { /* * @tc.teardown: teardown invoked after each testcases @@ -1078,7 +1078,7 @@ describe("SensorJsTest", function () { */ it("Sensor_GetGeomagneticField_025", 0, async function (done) { console.info("---------------------------Sensor_GetGeomagneticField_025----------------------------------"); - for (var i = 0; i < timeMillis.length; i++) { + for (let i = 0; i < timeMillis.length; i++) { await sensor.getGeomagneticInfo({'latitude':80, 'longitude':0, 'altitude':0}, timeMillis[i]).then((data) => { console.info('Sensor_GetGeomagneticField_025 x: ' + data.x + ',y: ' + data.y + ',z: ' + data.z + ',geomagneticDip: ' + data.geomagneticDip + ',deflectionAngle: ' + data.deflectionAngle + ',levelIntensity: ' + data.levelIntensity + ',totalIntensity: ' + data.totalIntensity); @@ -1343,7 +1343,7 @@ describe("SensorJsTest", function () { * @tc.require: Issue Number */ it('Sensor_GetGeomagneticField_037', 0, async function (done) { - for (var i = 0; i < timeMillis.length; i++) { + for (let i = 0; i < timeMillis.length; i++) { console.info('----------------------Sensor_GetGeomagneticField_037---------------------------'); await sensor.getGeomagneticInfo({'latitude':80, 'longitude':0, 'altitude':0}, timeMillis[i]).then((data) => { console.info('Sensor_GetGeomagneticField_037 x: ' + data.x + ',y: ' + data.y + ',z: ' + data.z + ',geomagneticDip: ' + data.geomagneticDip @@ -1460,7 +1460,7 @@ describe("SensorJsTest", function () { */ it('Sensor_GetGeomagneticField_043', 0, async function (done) { console.info('----------------------Sensor_GetGeomagneticField_043---------------------------'); - for (var i = 0; i < GEOMAGNETIC_COORDINATES.length; i++) { + for (let i = 0; i < GEOMAGNETIC_COORDINATES.length; i++) { await sensor.getGeomagneticInfo({'latitude':GEOMAGNETIC_COORDINATES[i][0], 'longitude':GEOMAGNETIC_COORDINATES[i][1], 'altitude':GEOMAGNETIC_COORDINATES[i][2]}, timeMillis[0]).then((data) => { console.info('Sensor_GetGeomagneticField_043 x: ' + data.x + ',y: ' + data.y + ',z: ' + data.z + ',geomagneticDip: ' + data.geomagneticDip + ',deflectionAngle: ' + data.deflectionAngle + ',levelIntensity: ' + data.levelIntensity + ',totalIntensity: ' + data.totalIntensity) @@ -1762,7 +1762,7 @@ describe("SensorJsTest", function () { } }) - var SENSOR_DATA_MATRIX = [ + const SENSOR_DATA_MATRIX = [ { "rotation": [-0.7980074882507324, 0.5486301183700562, 0.24937734007835388, -0.17277367413043976, -0.6047078967094421, 0.7774815559387207, 0.5773502588272095, 0.5773502588272095,0.5773502588272095], @@ -1786,7 +1786,7 @@ describe("SensorJsTest", function () { "rotation":[null, null, null, null, null, null,0, 0, 0], "inclination":[1, 0, 0, 0, null, 0, 0, 0, null] } - ] + ]; let GET_DIRECTION = [ [ 0.38050639629364014, -0.9783217310905457, -0.6610431671142578], @@ -2064,7 +2064,7 @@ describe("SensorJsTest", function () { console.info('Sensor_CreateRotationMatrix_012 failed'); expect(false).assertTrue(); } else { - for(var i = 0;i < data.length; i++) { + for(let i = 0;i < data.length; i++) { console.info("Sensor_CreateRotationMatrix_012 [" + i + ") = " + data[i]); expect(data[i]).assertEqual(createRotationMatrixResult[0][i]) } @@ -2083,7 +2083,7 @@ describe("SensorJsTest", function () { it('Sensor_CreateRotationMatrix_013', 0,async function (done) { console.info('Sensor_CreateRotationMatrix_013 start') sensor.getRotationMatrix([-0.0245, 0.402, 0.0465]).then((data) => { - for(var i = 0;i < data.length; i++) { + for(let i = 0;i < data.length; i++) { console.info("Sensor_CreateRotationMatrix_013 [" + i + "] : " + data[i]); expect(data[i]).assertEqual(createRotationMatrixResult[0][i]) } @@ -2105,7 +2105,7 @@ describe("SensorJsTest", function () { it('Sensor_CreateRotationMatrix_014', 0,async function (done) { console.info('Sensor_CreateRotationMatrix_014 start') sensor.getRotationMatrix([0, 0, 0]).then((data) => { - for(var i = 0;i < data.length; i++) { + for(let i = 0;i < data.length; i++) { console.info("Sensor_CreateRotationMatrix_014 [" + i + "] : " + data[i]); expect(data[i]).assertEqual(createRotationMatrixResult[1][i]) } @@ -2132,7 +2132,7 @@ describe("SensorJsTest", function () { console.info('Sensor_GetDirection_001 failed'); expect(false).assertTrue(); } else { - for (var i = 1; i < data.length; i++) { + for (let i = 1; i < data.length; i++) { console.info("Sensor_GetDirection_001" + data[i]) expect(data[i]).assertEqual(GET_DIRECTION[0][i]) } @@ -2155,7 +2155,7 @@ describe("SensorJsTest", function () { console.info('Sensor_GetDirection_002 failed'); expect(false).assertTrue(); } else { - for (var i = 1; i < data.length; i++) { + for (let i = 1; i < data.length; i++) { console.info("Sensor_GetDirection_002" + data[i]) expect(data[i]).assertEqual(GET_DIRECTION[1][i]) } @@ -2174,7 +2174,7 @@ describe("SensorJsTest", function () { */ it('Sensor_GetDirection_003', 0, async function (done) { sensor.getOrientation(rotationMatrix[0]).then((data) => { - for (var i = 0; i { - for (var i = 0; i { - for (var i = 0; i { - for(var i = 0; i < data.length; i++) { + for(let i = 0; i < data.length; i++) { console.info("Sensor_GetAngleModify_006 [" + i + "] = " + data[i]); expect(data[0]).assertEqual(ANGLECHANGE_9_RESULT[0][0]) && expect(Number.isNaN(data[1])).assertTrue() && expect(data[2]).assertEqual(ANGLECHANGE_9_RESULT[0][2]); @@ -2534,7 +2534,7 @@ describe("SensorJsTest", function () { console.info("Sensor_GetAngleModify_007 in"); sensor.getAngleVariation([3.40282e+38, 3.40282e+38, 3.40282e+38, 3.40282e+38, 3.40282e+38, 3.40282e+38, 3.40282e+38, 3.40282e+38, 3.40282e+38], [3.40282e+38, 3.40282e+38, 3.40282e+38, 3.40282e+38, 3.40282e+38, 3.40282e+38, 3.40282e+38, 3.40282e+38, 3.40282e+38]).then((data) => { - for(var i = 0; i < data.length; i++) { + for(let i = 0; i < data.length; i++) { console.info("Sensor_GetAngleModify_007 [" + i + "] = " + data[i]); expect(data[0]).assertEqual(ANGLECHANGE_9_RESULT[1][0]) && expect(Number.isNaN(data[1])).assertTrue() && expect(data[2]).assertEqual(ANGLECHANGE_9_RESULT[1][2]); } @@ -2557,7 +2557,7 @@ describe("SensorJsTest", function () { console.info("Sensor_GetAngleModify_008 in"); sensor.getAngleVariation([1.17549e-38, 1.17549e-38, 1.17549e-38, 1.17549e-38, 1.17549e-38, 1.17549e-38, 1.17549e-38, 1.17549e-38, 1.17549e-38], [1.17549e-38, 1.17549e-38, 1.17549e-38, 1.17549e-38, 1.17549e-38, 1.17549e-38, 1.17549e-38, 1.17549e-38, 1.17549e-38]).then((data) => { - for(var i = 0; i < data.length; i++) { + for(let i = 0; i < data.length; i++) { console.info("Sensor_GetAngleModify_008 [" + i + "] = " + data[i]); expect(data[0]).assertEqual(ANGLECHANGE_9_RESULT[2][0]) && expect(data[1]).assertEqual(ANGLECHANGE_9_RESULT[2][1]) @@ -2583,7 +2583,7 @@ describe("SensorJsTest", function () { sensor.getAngleVariation([3.40282e+38 + 1,3.40282e+38 + 1,3.40282e+38 + 1,3.40282e+38+1,3.40282e+38+1,3.40282e+38+1,3.40282e+38+1,3.40282e+38+1,3.40282e+38+1], [3.40282e+38+1,3.40282e+38+1,3.40282e+38+1,3.40282e+38+1,3.40282e+38+1,3.40282e+38+1,3.40282e+38+1,3.40282e+38+1,3.40282e+38+1]) .then((data) => { - for(var i = 0; i < data.length; i++) { + for(let i = 0; i < data.length; i++) { console.info("Sensor_GetAngleModify_009 [" + i + "] = " + data[i]); expect(data[0]).assertEqual(ANGLECHANGE_9_RESULT[3][0]) && expect(Number.isNaN(data[1])).assertTrue() && expect(data[2]).assertEqual(ANGLECHANGE_9_RESULT[3][2]); } @@ -2606,7 +2606,7 @@ describe("SensorJsTest", function () { console.info("Sensor_GetAngleModify_010 in"); sensor.getAngleVariation([0.0 / 0.0, 0.0 / 0.0, 0.0 / 0.0, 0.0 / 0.0, 0.0 / 0.0, 0.0 / 0.0, 0.0 / 0.0, 0.0 / 0.0, 0.0 / 0.0], [0.0 / 0.0, 0.0 / 0.0, 0.0 / 0.0, 0.0 / 0.0, 0.0 / 0.0, 0.0 / 0.0, 0.0 / 0.0, 0.0 / 0.0, 0.0 / 0.0]).then((data) => { - for(var i = 0; i < data.length; i++) { + for(let i = 0; i < data.length; i++) { console.info("Sensor_GetAngleModify_010 [" + i + "] = " + data[i]); expect(Number.isNaN(data[0]) && Number.isNaN(data[1]) && Number.isNaN(data[2])).assertTrue(); } @@ -2749,13 +2749,13 @@ describe("SensorJsTest", function () { } }) - var result = [ + const result = [ [0.7441122531890869, 0.5199999809265137, -0.335999995470047, -0.25099998712539673], [0, 3.402820018375656e+38, 3.402820018375656e+38, 3.402820018375656e+38], [1, 0, 0, 0], [0.7183529734611511, -0.32499998807907104, -0.5619999766349792, -0.25], [0, 0, 0, 0] - ] + ]; /* * @tc.name: Sensor_CreateQuaternion_001 @@ -2771,7 +2771,7 @@ describe("SensorJsTest", function () { console.info('Sensor_CreateQuaternion_001 failed'); expect(false).assertTrue(); } else { - for (var i = 0; i < data.length; i++) { + for (let i = 0; i < data.length; i++) { console.info("data[" + i + "]: " + data[i]) expect(data[i]).assertEqual(result[0][i]) } @@ -2793,7 +2793,7 @@ describe("SensorJsTest", function () { console.info('Sensor_CreateQuaternion_002 failed'); expect(false).assertTrue(); } else { - for (var i = 0; i < data.length; i++) { + for (let i = 0; i < data.length; i++) { console.info("data[" + i + "]: " + data[i]) expect(data[i]).assertEqual(result[1][i]) } @@ -2815,7 +2815,7 @@ describe("SensorJsTest", function () { console.info('Sensor_CreateQuaternion_003 failed'); expect(false).assertTrue(); } else { - for (var i = 0; i < data.length; i++) { + for (let i = 0; i < data.length; i++) { console.info("data[" + i + "]: " + data[i]) expect(data[i]).assertEqual(result[2][i]) } @@ -2838,7 +2838,7 @@ describe("SensorJsTest", function () { console.info('Sensor_CreateQuaternion_004 failed'); expect(false).assertTrue(); } else { - for (var i = 0; i < data.length; i++) { + for (let i = 0; i < data.length; i++) { console.info("data[" + i + "]: " + data[i]) expect(data[i]).assertEqual(result[3][i]) } @@ -2883,7 +2883,7 @@ describe("SensorJsTest", function () { console.info('Sensor_CreateQuaternion_006 start') sensor.getQuaternion([0.52, -0.336, -0.251]).then((data) => { console.info('Sensor_CreateQuaternion_006'); - for (var i = 0; i < data.length; i++) { + for (let i = 0; i < data.length; i++) { console.info("data[" + i + "]: " + data[i]); expect(data[i]).assertEqual(result[0][i]) } @@ -2932,7 +2932,7 @@ describe("SensorJsTest", function () { console.info('Sensor_CreateQuaternion_008 start') sensor.getQuaternion([0, 0, 0]).then((data) => { console.info('Sensor_CreateQuaternion_008'); - for (var i = 0; i < data.length; i++) { + for (let i = 0; i < data.length; i++) { console.info("data[" + i + "]: " + data[i]); expect(data[i]).assertEqual(result[2][i]) } @@ -2955,7 +2955,7 @@ describe("SensorJsTest", function () { console.info('Sensor_CreateQuaternion_009 start') sensor.getQuaternion([-0.325, -0.562, -0.25]).then((data) => { console.info('Sensor_CreateQuaternion_009'); - for (var i = 0; i < data.length; i++) { + for (let i = 0; i < data.length; i++) { console.info("data[" + i + "]: " + data[i]); expect(data[i]).assertEqual(result[3][i]) } @@ -3118,7 +3118,7 @@ describe("SensorJsTest", function () { } }) - var getGeomagneticDipResult = [ 0.8760581016540527, 0.862170, -Infinity, 44330] + const getGeomagneticDipResult = [ 0.8760581016540527, 0.862170, -Infinity, 44330]; /* * @tc.name: Sensor_GetGeomagneticDip_001 @@ -3501,7 +3501,7 @@ describe("SensorJsTest", function () { it("Sensor_TransformCoordinateSystem_003", 0, async function (done) { console.info("---------------------------Sensor_TransformCoordinateSystem_003----------------------------------"); sensor.transformRotationMatrix([1.5, 1.5, 1.5, 1.5, 1.5, 1.5, 1.5, 1.5, 1.5], {'axisX':1, 'axisY':2}).then((data) => { - for (var i = 0; i < data.length; i++) { + for (let i = 0; i < data.length; i++) { console.info("Sensor_TransformCoordinateSystem_003 data[ " + i + "] = " + data[i]); expect(data[i]).assertEqual(transformCoordinateSystemResult[0][i]); } @@ -3522,7 +3522,7 @@ describe("SensorJsTest", function () { it("Sensor_TransformCoordinateSystem_004", 0, async function (done) { console.info("---------------------------Sensor_TransformCoordinateSystem_004----------------------------------"); sensor.transformRotationMatrix([3.40282e+39, 3.40282e+39, 3.40282e+39, 3.40282e+39, 3.40282e+39, 3.40282e+39, 3.40282e+39, 3.40282e+39, 3.40282e+39], {'axisX':1, 'axisY':3}).then((data) => { - for (var i = 0; i < data.length; i++) { + for (let i = 0; i < data.length; i++) { console.info("Sensor_TransformCoordinateSystem_004 data[ " + i + "] = " + data[i]); expect(data[i]).assertEqual(transformCoordinateSystemResult[2][i]); } @@ -3697,7 +3697,7 @@ describe("SensorJsTest", function () { console.info("---------------------------Sensor_GetSensorList_001----------------------------------"); sensor.getSensorList().then((data) => { console.info("---------------------------Sensor_GetSensorList_001 callback in-----------" + data.length); - for (var i = 0; i < data.length; i++) { + for (let i = 0; i < data.length; i++) { console.info("Sensor_GetSensorList_001 " + JSON.stringify(data[i])); } expect(true).assertTrue(); @@ -3723,7 +3723,7 @@ describe("SensorJsTest", function () { expect(false).assertTrue(); } else { console.info("---------------------------Sensor_GetSensorList_002 callback in-----------" + data.length); - for (var i = 0; i < data.length; i++) { + for (let i = 0; i < data.length; i++) { console.info("Sensor_GetSensorList_002 " + JSON.stringify(data[i])); } expect(true).assertTrue(); -- Gitee From 41e02fe663939c291ccba4e93f8b50a8676ff082 Mon Sep 17 00:00:00 2001 From: hui1975 Date: Thu, 3 Nov 2022 21:18:57 +0800 Subject: [PATCH 20/22] =?UTF-8?q?58=E8=A1=8Cset=E5=A4=B1=E8=B4=A5=E5=89=8D?= =?UTF-8?q?=E8=A6=81=E5=85=B3=E9=97=ADfd=EF=BC=8C=E5=88=A0=E9=99=A499?= =?UTF-8?q?=E8=A1=8C=E6=81=92=E6=88=90=E7=AB=8B=E6=9D=A1=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: hui1975 Change-Id: I750feceaa1f7043f0518edad4eb629c5cd086717 --- utils/src/sensor_basic_data_channel.cpp | 54 ++++++++++++------------- 1 file changed, 26 insertions(+), 28 deletions(-) diff --git a/utils/src/sensor_basic_data_channel.cpp b/utils/src/sensor_basic_data_channel.cpp index 29bfd591..3532b9cf 100755 --- a/utils/src/sensor_basic_data_channel.cpp +++ b/utils/src/sensor_basic_data_channel.cpp @@ -55,48 +55,46 @@ int32_t SensorBasicDataChannel::CreateSensorBasicChannel() return SENSOR_CHANNEL_SOCKET_CREATE_ERR; } // set socket attr - int32_t ret = setsockopt(socketPair[0], SOL_SOCKET, SO_SNDBUF, &SENSOR_READ_DATA_SIZE, - sizeof(SENSOR_READ_DATA_SIZE)); - if (ret != 0) { - SEN_HILOGE("setsockopt socketpair 0 failed"); - return SENSOR_CHANNEL_SOCKET_CREATE_ERR; + if (setsockopt(socketPair[0], SOL_SOCKET, SO_SNDBUF, &SENSOR_READ_DATA_SIZE, sizeof(SENSOR_READ_DATA_SIZE)) != 0) { + SEN_HILOGE("setsockopt socketpair 0, SNDBUF failed, errno: %{public}d", errno); + goto CLOSE_SOCK; } - ret = setsockopt(socketPair[1], SOL_SOCKET, SO_RCVBUF, &SENSOR_READ_DATA_SIZE, sizeof(SENSOR_READ_DATA_SIZE)); - if (ret != 0) { - SEN_HILOGE("setsockopt socketpair 1 failed"); - return SENSOR_CHANNEL_SOCKET_CREATE_ERR; + if (setsockopt(socketPair[1], SOL_SOCKET, SO_RCVBUF, &SENSOR_READ_DATA_SIZE, sizeof(SENSOR_READ_DATA_SIZE)) != 0) { + SEN_HILOGE("setsockopt socketpair 1, RCVBUF failed, errno: %{public}d", errno); + goto CLOSE_SOCK; } - int32_t bufferSize = DEFAULT_CHANNEL_SIZE; - ret = setsockopt(socketPair[0], SOL_SOCKET, SO_RCVBUF, &bufferSize, sizeof(bufferSize)); - if (ret != 0) { - SEN_HILOGE("setsockopt socketpair 0 failed"); - return SENSOR_CHANNEL_SOCKET_CREATE_ERR; + if (setsockopt(socketPair[0], SOL_SOCKET, SO_RCVBUF, &DEFAULT_CHANNEL_SIZE, sizeof(DEFAULT_CHANNEL_SIZE)) != 0) { + SEN_HILOGE("setsockopt socketpair 0, RCVBUF failed, errno: %{public}d", errno); + goto CLOSE_SOCK; } - ret = setsockopt(socketPair[1], SOL_SOCKET, SO_SNDBUF, &bufferSize, sizeof(bufferSize)); - if (ret != 0) { - SEN_HILOGE("setsockopt socketpair 1 failed"); - return SENSOR_CHANNEL_SOCKET_CREATE_ERR; + if (setsockopt(socketPair[1], SOL_SOCKET, SO_SNDBUF, &DEFAULT_CHANNEL_SIZE, sizeof(DEFAULT_CHANNEL_SIZE)) != 0) { + SEN_HILOGE("setsockopt socketpair 1, SNDBUF failed, errno: %{public}d", errno); + goto CLOSE_SOCK; } - ret = fcntl(socketPair[0], F_SETFL, O_NONBLOCK); - if (ret != 0) { - SEN_HILOGE("fcntl socketpair 0 failed"); - return SENSOR_CHANNEL_SOCKET_CREATE_ERR; + if (fcntl(socketPair[0], F_SETFL, O_NONBLOCK) != 0) { + SEN_HILOGE("fcntl socketpair 0 failed, errno: %{public}d", errno); + goto CLOSE_SOCK; } - ret = fcntl(socketPair[1], F_SETFL, O_NONBLOCK); - if (ret != 0) { - SEN_HILOGE("fcntl socketpair 1 failed"); - return SENSOR_CHANNEL_SOCKET_CREATE_ERR; + if (fcntl(socketPair[1], F_SETFL, O_NONBLOCK) != 0) { + SEN_HILOGE("fcntl socketpair 1 failed, errno: %{public}d", errno); + goto CLOSE_SOCK; } sendFd_ = socketPair[0]; receiveFd_ = socketPair[1]; - SEN_HILOGD("create socketpair success,receiveFd_:%{public}d,sendFd_:%{public}d", receiveFd_, sendFd_); return ERR_OK; + + CLOSE_SOCK: + close(socketPair[0]); + close(socketPair[1]); + sendFd_ = -1; + receiveFd_ = -1; + return SENSOR_CHANNEL_SOCKET_CREATE_ERR; } int32_t SensorBasicDataChannel::CreateSensorBasicChannel(MessageParcel &data) { CALL_LOG_ENTER; - if ((sendFd_ != -1) || (receiveFd_ != -1)) { + if (sendFd_ != -1) { SEN_HILOGD("already create socketpair"); return ERR_OK; } -- Gitee From 03a0b71774b70cfeee3dce54a0b72d229e32637a Mon Sep 17 00:00:00 2001 From: Chao Liu Date: Mon, 7 Nov 2022 16:11:39 +0800 Subject: [PATCH 21/22] Fix more typo find in review Signed-off-by: Chao Liu --- .../native/sensor/include/sensor_service_client.h | 4 ++-- frameworks/native/sensor/src/sensor_agent_proxy.cpp | 12 ++++++------ interfaces/plugin/BUILD.gn | 2 +- interfaces/plugin/include/async_callback_info.h | 2 +- interfaces/plugin/src/sensor_js.cpp | 2 +- interfaces/plugin/src/sensor_napi_utils.cpp | 2 +- services/sensor/src/client_info.cpp | 4 ++-- 7 files changed, 14 insertions(+), 14 deletions(-) diff --git a/frameworks/native/sensor/include/sensor_service_client.h b/frameworks/native/sensor/include/sensor_service_client.h index 38c29496..e964c03d 100755 --- a/frameworks/native/sensor/include/sensor_service_client.h +++ b/frameworks/native/sensor/include/sensor_service_client.h @@ -36,7 +36,7 @@ namespace Sensors { class SensorServiceClient : public Singleton { public: std::vector GetSensorList(); - int32_t EnableSensor(uint32_t sensorId, int64_t samplingPeroid, int64_t maxReportDelay); + int32_t EnableSensor(uint32_t sensorId, int64_t samplingPeriod, int64_t maxReportDelay); int32_t DisableSensor(uint32_t sensorId); int32_t RunCommand(uint32_t sensorId, int32_t cmdType, int32_t parms); int32_t TransferDataChannel(sptr sensorDataChannel); @@ -46,7 +46,7 @@ public: private: int32_t InitServiceClient(); - void UpdateSensorInfoMap(uint32_t sensorId, int64_t samplingPeroid, int64_t maxReportDelay); + void UpdateSensorInfoMap(uint32_t sensorId, int64_t samplingPeriod, int64_t maxReportDelay); void DeleteSensorInfoItem(uint32_t sensorId); std::mutex clientMutex_; sptr serviceDeathObserver_; diff --git a/frameworks/native/sensor/src/sensor_agent_proxy.cpp b/frameworks/native/sensor/src/sensor_agent_proxy.cpp index 7b28161c..6f83cb5e 100644 --- a/frameworks/native/sensor/src/sensor_agent_proxy.cpp +++ b/frameworks/native/sensor/src/sensor_agent_proxy.cpp @@ -98,8 +98,8 @@ int32_t SensorAgentProxy::CreateSensorDataChannel() const } ret = SenClient.TransferDataChannel(dataChannel_); if (ret != ERR_OK) { - auto destoryRet = dataChannel_->DestroySensorDataChannel(); - SEN_HILOGE("transfer data channel failed, ret:%{public}d,destoryRet:%{public}d", ret, destoryRet); + auto destroyRet = dataChannel_->DestroySensorDataChannel(); + SEN_HILOGE("transfer data channel failed, ret:%{public}d,destroyRet:%{public}d", ret, destroyRet); return ret; } g_isChannelCreated = true; @@ -117,12 +117,12 @@ int32_t SensorAgentProxy::DestroySensorDataChannel() const CHKPR(dataChannel_, INVALID_POINTER); int32_t ret = dataChannel_->DestroySensorDataChannel(); if (ret != ERR_OK) { - SEN_HILOGE("destory data channel failed, ret:%{public}d", ret); + SEN_HILOGE("destroy data channel failed, ret:%{public}d", ret); return ret; } ret = SenClient.DestroyDataChannel(); if (ret != ERR_OK) { - SEN_HILOGE("destory service data channel fail, ret:%{public}d", ret); + SEN_HILOGE("destroy service data channel fail, ret:%{public}d", ret); return ret; } g_isChannelCreated = false; @@ -135,7 +135,7 @@ int32_t SensorAgentProxy::ActivateSensor(int32_t sensorId, const SensorUser *use CHKPR(user->callback, OHOS::Sensors::ERROR); std::lock_guard subscribeLock(subscribeMutex_); if (g_samplingInterval < 0 || g_reportInterval < 0) { - SEN_HILOGE("samplingPeroid or g_reportInterval is invalid"); + SEN_HILOGE("samplingPeriod or g_reportInterval is invalid"); return ERROR; } if (!SenClient.IsValid(sensorId)) { @@ -238,7 +238,7 @@ int32_t SensorAgentProxy::UnsubscribeSensor(int32_t sensorId, const SensorUser * if (g_subscribeMap.empty()) { int32_t ret = DestroySensorDataChannel(); if (ret != ERR_OK) { - SEN_HILOGE("destory data channel fail, ret:%{public}d", ret); + SEN_HILOGE("destroy data channel fail, ret:%{public}d", ret); return ret; } } diff --git a/interfaces/plugin/BUILD.gn b/interfaces/plugin/BUILD.gn index 5b3f3909..d8445259 100644 --- a/interfaces/plugin/BUILD.gn +++ b/interfaces/plugin/BUILD.gn @@ -25,7 +25,7 @@ ohos_shared_library("libsensor") { "//foundation/arkui/napi/interfaces/inner_api/napi", ] defines = [ - "APP_LOG_TAG = \"sensroJs\"", + "APP_LOG_TAG = \"sensorJs\"", "LOG_DOMAIN = 0xD002700", ] sources = [ diff --git a/interfaces/plugin/include/async_callback_info.h b/interfaces/plugin/include/async_callback_info.h index 94b3512b..5119e5cb 100644 --- a/interfaces/plugin/include/async_callback_info.h +++ b/interfaces/plugin/include/async_callback_info.h @@ -41,7 +41,7 @@ enum CallbackDataType { ONCE_CALLBACK = 2, GET_GEOMAGNETIC_FIELD = 3, GET_ALTITUDE = 4, - GET_GEOMAGNITIC_DIP = 5, + GET_GEOMAGNETIC_DIP = 5, GET_ANGLE_MODIFY = 6, CREATE_ROTATION_MATRIX = 7, TRANSFORM_COORDINATE_SYSTEM = 8, diff --git a/interfaces/plugin/src/sensor_js.cpp b/interfaces/plugin/src/sensor_js.cpp index fd0d3985..aa4b761c 100644 --- a/interfaces/plugin/src/sensor_js.cpp +++ b/interfaces/plugin/src/sensor_js.cpp @@ -843,7 +843,7 @@ static napi_value GetGeomagneticDip(napi_env env, napi_callback_info info) return nullptr; } sptr asyncCallbackInfo = - new (std::nothrow) AsyncCallbackInfo(env, GET_GEOMAGNITIC_DIP); + new (std::nothrow) AsyncCallbackInfo(env, GET_GEOMAGNETIC_DIP); CHKPP(asyncCallbackInfo); std::vector inclinationMatrix; if (!GetFloatArray(env, args[0], inclinationMatrix)) { diff --git a/interfaces/plugin/src/sensor_napi_utils.cpp b/interfaces/plugin/src/sensor_napi_utils.cpp index 3a29492b..86f74912 100644 --- a/interfaces/plugin/src/sensor_napi_utils.cpp +++ b/interfaces/plugin/src/sensor_napi_utils.cpp @@ -187,7 +187,7 @@ std::map g_convertfuncList = { {ONCE_CALLBACK, ConvertToSensorData}, {GET_GEOMAGNETIC_FIELD, ConvertToGeomagneticData}, {GET_ALTITUDE, ConvertToNumber}, - {GET_GEOMAGNITIC_DIP, ConvertToNumber}, + {GET_GEOMAGNETIC_DIP, ConvertToNumber}, {GET_ANGLE_MODIFY, ConvertToArray}, {CREATE_ROTATION_MATRIX, ConvertToArray}, {TRANSFORM_COORDINATE_SYSTEM, ConvertToArray}, diff --git a/services/sensor/src/client_info.cpp b/services/sensor/src/client_info.cpp index 15e68601..ef9d7553 100644 --- a/services/sensor/src/client_info.cpp +++ b/services/sensor/src/client_info.cpp @@ -33,7 +33,7 @@ constexpr uint32_t INVALID_SENSOR_ID = -1; constexpr int32_t INVALID_PID = -1; constexpr int32_t INVALID_UID = -1; constexpr int32_t MIN_MAP_SIZE = 0; -constexpr uint32_t NO_STROE_EVENT = -2; +constexpr uint32_t NO_STORE_EVENT = -2; constexpr uint32_t MAX_SUPPORT_CHANNEL = 200; constexpr uint32_t MAX_DUMP_DATA_SIZE = 10; constexpr uint32_t HEART_RATE_SENSOR_ID = 83886336; @@ -441,7 +441,7 @@ int32_t ClientInfo::GetStoreEvent(int32_t sensorId, SensorData &data) } SEN_HILOGE("can't get store event, sensorId:%{public}u", sensorId); - return NO_STROE_EVENT; + return NO_STORE_EVENT; } void ClientInfo::StoreEvent(const SensorData &data) -- Gitee From f380889489d244185ff0f6f913d7529d6f652c97 Mon Sep 17 00:00:00 2001 From: lixiangpeng5 Date: Thu, 17 Nov 2022 20:44:57 +0800 Subject: [PATCH 22/22] =?UTF-8?q?=E4=BF=AE=E5=A4=8Dnative=E5=8F=AF?= =?UTF-8?q?=E8=83=BD=E6=9E=90=E6=9E=84AsyncCallbackInfo=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: lixiangpeng5 Change-Id: I35ae0e9e1620a195db68ad0d7fa7b6359de5cdfb --- interfaces/plugin/src/sensor_js.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/interfaces/plugin/src/sensor_js.cpp b/interfaces/plugin/src/sensor_js.cpp index 5dd0f15a..1f374d97 100644 --- a/interfaces/plugin/src/sensor_js.cpp +++ b/interfaces/plugin/src/sensor_js.cpp @@ -138,14 +138,17 @@ static void EmitOnceCallback(SensorEvent *event) if (iter == g_onceCallbackInfos.end()) { return; } - for (auto &onceCallbackInfo : iter->second) { + auto& onceCallbackInfos = iter->second; + while (!onceCallbackInfos.empty()) { + auto onceCallbackInfo = onceCallbackInfos.front(); + auto beginIter = onceCallbackInfos.begin(); + onceCallbackInfos.erase(beginIter); if (!copySensorData(onceCallbackInfo, event)) { SEN_HILOGE("Copy sensor data failed"); continue; } EmitUvEventLoop(onceCallbackInfo); } - g_onceCallbackInfos[sensorTypeId].clear(); g_onceCallbackInfos.erase(sensorTypeId); CHKCV((!CheckSubscribe(sensorTypeId)), "Has client subscribe, not need cancel subscribe"); -- Gitee