diff --git a/bundle.json b/bundle.json index 72c472984d5e350257a7d6436b3154bc2ac14e43..197e29b798741946f4db4fcc149bfb1acef9d238 100755 --- a/bundle.json +++ b/bundle.json @@ -10,7 +10,7 @@ "name": "sensor", "subsystem": "sensors", "syscap": ["SystemCapability.Sensors.Sensor", "SystemCapability.Sensors.Sensor.Lite"], - "features": [], + "features": ["sensor_rust_socket_ipc"], "adapted_system_type": [ "standard" ], "rom": "2048KB", "ram": "~4096KB", @@ -67,7 +67,8 @@ "//base/sensors/sensor/test/unittest/interfaces/kits:unittest", "//base/sensors/sensor/test/fuzztest/interfaces:fuzztest", "//base/sensors/sensor/test/unittest/interfaces/inner_api:unittest", - "//base/sensors/sensor/test/fuzztest/services:fuzztest" + "//base/sensors/sensor/test/fuzztest/services:fuzztest", + "//base/sensors/sensor/test/unittest/coverage:unittest" ] } } diff --git a/frameworks/js/napi/BUILD.gn b/frameworks/js/napi/BUILD.gn index 9dd4e8bb7ffc530b5efc1d3d30aff41b67685760..b6f97fdd62a3c0d30b1bed6d9ccb2d1ea1ae9ced 100644 --- a/frameworks/js/napi/BUILD.gn +++ b/frameworks/js/napi/BUILD.gn @@ -21,6 +21,12 @@ ohos_shared_library("libsensor") { "$SUBSYSTEM_DIR/frameworks/js/napi/include", "$SUBSYSTEM_DIR/utils/common/include", ] + branch_protector_ret = "pac_ret" + sanitize = { + cfi = true + cfi_cross_dso = true + debug = false + } defines = [ "APP_LOG_TAG = \"sensorJs\"", "LOG_DOMAIN = 0xD002700", @@ -31,12 +37,6 @@ ohos_shared_library("libsensor") { "src/sensor_napi_utils.cpp", "src/sensor_system_js.cpp", ] - branch_protector_ret = "pac_ret" - sanitize = { - cfi = true - cfi_cross_dso = true - debug = false - } deps = [ "$SUBSYSTEM_DIR/frameworks/native:sensor_interface_native" ] external_deps = [ "bundle_framework:appexecfwk_base", diff --git a/frameworks/js/napi/include/async_callback_info.h b/frameworks/js/napi/include/async_callback_info.h index fe9b012a30b9b16cc65d1a5acf79805695df7c86..f60bbb9ea5cac582e72009e4e1fd1f525a4425d7 100644 --- a/frameworks/js/napi/include/async_callback_info.h +++ b/frameworks/js/napi/include/async_callback_info.h @@ -72,7 +72,7 @@ struct RationMatrixData { float inclinationMatrix[THREE_DIMENSIONAL_MATRIX_LENGTH]; }; -struct SensorData { +struct CallbackSensorData { int32_t sensorTypeId; uint32_t dataLength; float data[DATA_LENGTH]; @@ -86,7 +86,7 @@ struct ReserveData { }; union CallbackData { - SensorData sensorData; + CallbackSensorData sensorData; GeomagneticData geomagneticData; RationMatrixData rationMatrixData; ReserveData reserveData; @@ -130,6 +130,6 @@ public: private: }; -} // namespace Sensors -} // namespace OHOS +} // namespace Sensors +} // namespace OHOS #endif // ASYNC_CALLBACK_INFO_H \ No newline at end of file diff --git a/frameworks/js/napi/include/sensor_js.h b/frameworks/js/napi/include/sensor_js.h index bf75795c1d49f57ccda81f05ec6d56a0d790a951..33083199620e9d6a038caaa6583dcf017ac97416 100644 --- a/frameworks/js/napi/include/sensor_js.h +++ b/frameworks/js/napi/include/sensor_js.h @@ -29,6 +29,6 @@ int32_t SubscribeSensor(int32_t sensorTypeId, int64_t interval, RecordSensorCall napi_value Subscribe(napi_env env, napi_callback_info info, int32_t sensorTypeId, CallbackDataType type); napi_value Unsubscribe(napi_env env, napi_callback_info info, int32_t sensorTypeId); napi_value GetBodyState(napi_env env, napi_callback_info info); -} // namespace Sensors -} // namespace OHOS +} // namespace Sensors +} // namespace OHOS #endif // SENSOR_JS_H \ No newline at end of file diff --git a/frameworks/js/napi/include/sensor_napi_error.h b/frameworks/js/napi/include/sensor_napi_error.h index 7a8bbb26595973831ac2c7baf3a00b36d7d0331a..1ca9d63d54a4cd7b7e083f991b034428d91de4bf 100755 --- a/frameworks/js/napi/include/sensor_napi_error.h +++ b/frameworks/js/napi/include/sensor_napi_error.h @@ -35,6 +35,6 @@ const std::map ERROR_MESSAGES = { napi_value CreateBusinessError(const napi_env &env, const int32_t errCode, const std::string &errMessage); void ThrowErr(const napi_env &env, const int32_t errCode, const std::string &printMsg); std::optional GetNapiError(int32_t errorCode); -} // namespace Sensors -} // namespace OHOS +} // namespace Sensors +} // namespace OHOS #endif // SENSOR_NAPI_ERROR_H \ No newline at end of file diff --git a/frameworks/js/napi/include/sensor_napi_utils.h b/frameworks/js/napi/include/sensor_napi_utils.h index a7ce75883b27f589a44033b1d97605b7f772fc27..cbd70ed370f51ceeab3f05336e30f9695b4daa95 100644 --- a/frameworks/js/napi/include/sensor_napi_utils.h +++ b/frameworks/js/napi/include/sensor_napi_utils.h @@ -93,6 +93,6 @@ bool GetSelfTargetVersion(uint32_t &targetVersion); return false; \ } \ } while (0) -} // namespace Sensors -} // namespace OHOS +} // namespace Sensors +} // namespace OHOS #endif // SENSOR_NAPI_UTILS_H diff --git a/frameworks/js/napi/include/sensor_system_js.h b/frameworks/js/napi/include/sensor_system_js.h index e8ba56345fd2d03a82a59f5ea362f063a3245cac..5358a9d1bdadec7c3316170193a78c97a646f366 100644 --- a/frameworks/js/napi/include/sensor_system_js.h +++ b/frameworks/js/napi/include/sensor_system_js.h @@ -45,6 +45,6 @@ napi_value SubscribeMagnetic(napi_env env, napi_callback_info info); napi_value UnsubscribeMagnetic(napi_env env, napi_callback_info info); napi_value SubscribeHall(napi_env env, napi_callback_info info); napi_value UnsubscribeHall(napi_env env, napi_callback_info info); -} // namespace Sensors -} // namespace OHOS +} // namespace Sensors +} // namespace OHOS #endif // SENSOR_SYSTEM_JS_H \ No newline at end of file diff --git a/frameworks/js/napi/src/sensor_js.cpp b/frameworks/js/napi/src/sensor_js.cpp index 35f7585180f86bf1344ea31d2e3bac27b5d71965..1d80d11208e841e4506b92b0d91e3c35bc90a17d 100644 --- a/frameworks/js/napi/src/sensor_js.cpp +++ b/frameworks/js/napi/src/sensor_js.cpp @@ -75,7 +75,7 @@ static bool copySensorData(sptr callbackInfo, SensorEvent *ev callbackInfo->data.sensorData.sensorAccuracy = event->option; CHKPF(event->data); if (event->dataLen < sizeof(float)) { - SEN_HILOGE("Event dataLen less than float size."); + SEN_HILOGE("Event dataLen less than float size"); return false; } auto data = reinterpret_cast(event->data); @@ -1438,5 +1438,5 @@ extern "C" __attribute__((constructor)) void RegisterModule(void) { napi_module_register(&_module); } -} // namespace Sensors -} // namespace OHOS \ No newline at end of file +} // namespace Sensors +} // namespace OHOS \ No newline at end of file diff --git a/frameworks/js/napi/src/sensor_napi_error.cpp b/frameworks/js/napi/src/sensor_napi_error.cpp index fa3c948ec489fb7cd8cc8aee93c96668e06312e7..b2696e48dbc4163b35b87f01c1d81af4970b944a 100644 --- a/frameworks/js/napi/src/sensor_napi_error.cpp +++ b/frameworks/js/napi/src/sensor_napi_error.cpp @@ -57,5 +57,5 @@ void ThrowErr(const napi_env &env, const int32_t errCode, const std::string &pri napi_throw(env, error); napi_close_handle_scope(env, scope); } -} // namespace Sensors -} // namespace OHOS \ No newline at end of file +} // namespace Sensors +} // namespace OHOS \ No newline at end of file diff --git a/frameworks/js/napi/src/sensor_napi_utils.cpp b/frameworks/js/napi/src/sensor_napi_utils.cpp index 535d6050d624bd45e8a8295c0a16bdf632b6895b..f797e9686b10e67a3de9512b00741424fa270758 100644 --- a/frameworks/js/napi/src/sensor_napi_utils.cpp +++ b/frameworks/js/napi/src/sensor_napi_utils.cpp @@ -639,5 +639,5 @@ bool GetSelfTargetVersion(uint32_t &targetVersion) targetVersion = bundleInfo.targetVersion; return true; } -} // namespace Sensors -} // namespace OHOS \ No newline at end of file +} // namespace Sensors +} // namespace OHOS \ No newline at end of file diff --git a/frameworks/js/napi/src/sensor_system_js.cpp b/frameworks/js/napi/src/sensor_system_js.cpp index fd479933a1dec5e7bb36189dc264108215c759c5..f2a3ed0e0d64f7854766fbfc2409243c09d1a58f 100644 --- a/frameworks/js/napi/src/sensor_system_js.cpp +++ b/frameworks/js/napi/src/sensor_system_js.cpp @@ -180,5 +180,5 @@ napi_value UnsubscribeHall(napi_env env, napi_callback_info info) CALL_LOG_ENTER; return Unsubscribe(env, info, SENSOR_TYPE_ID_HALL); } -} // namespace Sensors -} // namespace OHOS \ No newline at end of file +} // namespace Sensors +} // namespace OHOS \ No newline at end of file diff --git a/frameworks/native/BUILD.gn b/frameworks/native/BUILD.gn index f7222ca6310c7d7a4d3ff58417dc673fc012a52b..e0ee11db38cbcc1c67262f26f1783320fe32fb26 100644 --- a/frameworks/native/BUILD.gn +++ b/frameworks/native/BUILD.gn @@ -47,7 +47,7 @@ ohos_shared_library("libsensor_client") { "$SUBSYSTEM_DIR/utils/ipc:libsensor_ipc", ] - if (rust_socket_ipc) { + if (sensor_rust_socket_ipc) { deps += [ "$SUBSYSTEM_DIR/rust/utils/socket_ipc_rust_ffi:sensor_rust_util_ffi" ] } @@ -56,12 +56,18 @@ ohos_shared_library("libsensor_client") { "c_utils:utils", "eventhandler:libeventhandler", "hilog:libhilog", - "hisysevent:libhisysevent", - "hitrace:hitrace_meter", "ipc:ipc_single", "samgr:samgr_proxy", ] + if (hiviewdfx_hisysevent_enable) { + external_deps += [ "hisysevent:libhisysevent" ] + } + + if (hiviewdfx_hitrace_enable) { + external_deps += [ "hitrace:hitrace_meter" ] + } + innerapi_tags = [ "platformsdk_indirect" ] part_name = "sensor" subsystem_name = "sensors" @@ -91,9 +97,6 @@ ohos_shared_library("sensor_interface_native") { "src/sensor_algorithm.cpp", ] - configs = [ ":sensor_private_config" ] - public_configs = [ ":sensor_public_config" ] - branch_protector_ret = "pac_ret" sanitize = { cfi = true @@ -104,6 +107,9 @@ ohos_shared_library("sensor_interface_native") { ubsan = true } + configs = [ ":sensor_private_config" ] + public_configs = [ ":sensor_public_config" ] + deps = [ "$SUBSYSTEM_DIR/frameworks/native:libsensor_client", "$SUBSYSTEM_DIR/frameworks/native:libsensor_ndk", diff --git a/frameworks/native/include/fd_listener.h b/frameworks/native/include/fd_listener.h index a3d97b5430bddc2386d07e6ac6fdce22dfb0de66..7c4424d8d9e457e32319c0778b99dee6fe495464 100644 --- a/frameworks/native/include/fd_listener.h +++ b/frameworks/native/include/fd_listener.h @@ -35,6 +35,6 @@ public: private: SensorDataChannel *channel_ = { nullptr }; }; -} // namespace Sensors -} // namespace OHOS +} // namespace Sensors +} // namespace OHOS #endif // FD_LISTENER_H diff --git a/frameworks/native/include/i_sensor_client.h b/frameworks/native/include/i_sensor_client.h index 44553870cd5694a7d34d4f804c9225d820ae0663..438a688dd984ebe4a5116d6399b5bf19966c2c95 100755 --- a/frameworks/native/include/i_sensor_client.h +++ b/frameworks/native/include/i_sensor_client.h @@ -26,6 +26,6 @@ public: virtual ~ISensorClient() = default; DECLARE_INTERFACE_DESCRIPTOR(u"ISensorClient"); }; -} // namespace Sensors -} // namespace OHOS +} // namespace Sensors +} // namespace OHOS #endif // I_SENSOR_CLIENT_H diff --git a/frameworks/native/include/i_sensor_service.h b/frameworks/native/include/i_sensor_service.h index 7ee5681289a76f7ec4c75c3addbf2c1aa616913a..6df8958628da1c7ac8586431ec83a110f14d6e68 100755 --- a/frameworks/native/include/i_sensor_service.h +++ b/frameworks/native/include/i_sensor_service.h @@ -50,6 +50,6 @@ public: virtual ErrCode DisableActiveInfoCB() = 0; virtual ErrCode ResetSensors() = 0; }; -} // namespace Sensors -} // namespace OHOS +} // namespace Sensors +} // namespace OHOS #endif // I_SENSOR_SERVICE_H diff --git a/frameworks/native/include/sensor_agent_proxy.h b/frameworks/native/include/sensor_agent_proxy.h index 702b43d35933f3d11a5b27b90e7b996a69236356..76ad11fc4fa7787c07ebd32f94ad952150f3b717 100644 --- a/frameworks/native/include/sensor_agent_proxy.h +++ b/frameworks/native/include/sensor_agent_proxy.h @@ -68,6 +68,6 @@ private: }; #define SENSOR_AGENT_IMPL OHOS::DelayedSingleton::GetInstance() -} // namespace Sensors -} // namespace OHOS +} // namespace Sensors +} // namespace OHOS #endif // endif SENSOR_PROXY_H \ No newline at end of file diff --git a/frameworks/native/include/sensor_client_proxy.h b/frameworks/native/include/sensor_client_proxy.h index 6b8959377c7f8cc3a390c915687d6fbdd8c80df9..ce9b2712e73fa0b0eb698a03953fb44845e125f4 100755 --- a/frameworks/native/include/sensor_client_proxy.h +++ b/frameworks/native/include/sensor_client_proxy.h @@ -34,6 +34,6 @@ private: DISALLOW_COPY_AND_MOVE(SensorClientProxy); static inline BrokerDelegator delegator_; }; -} // namespace Sensors -} // namespace OHOS +} // namespace Sensors +} // namespace OHOS #endif // SENSOR_CLIENT_PROXY_H diff --git a/frameworks/native/include/sensor_client_stub.h b/frameworks/native/include/sensor_client_stub.h index 2ed785d503120c5676359fa89f0f583896255164..4a8a3d6b96a6e5cb046f6cb08d3d4b039c10e55b 100755 --- a/frameworks/native/include/sensor_client_stub.h +++ b/frameworks/native/include/sensor_client_stub.h @@ -30,6 +30,6 @@ public: virtual int32_t OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) override; }; -} // namespace Sensors -} // namespace OHOS +} // namespace Sensors +} // namespace OHOS #endif // SENSOR_CLIENT_STUB_H diff --git a/frameworks/native/include/sensor_data_channel.h b/frameworks/native/include/sensor_data_channel.h index ee32f46491d1dd69468505725687f1a8d3b85b8c..167707c91fac96457c2a2163e2a681bf1c453198 100644 --- a/frameworks/native/include/sensor_data_channel.h +++ b/frameworks/native/include/sensor_data_channel.h @@ -52,6 +52,6 @@ private: ReceiveMessageFun receiveMessage_; DisconnectFun disconnect_; }; -} // namespace Sensors -} // namespace OHOS +} // namespace Sensors +} // namespace OHOS #endif // SENSOR_DATA_CHANNEL_H diff --git a/frameworks/native/include/sensor_event_handler.h b/frameworks/native/include/sensor_event_handler.h index 1798f5fae851d2c4638b4aa6f15fa934fb153293..710d6cd129498e0c1f8f1946db78b48f698d46bd 100755 --- a/frameworks/native/include/sensor_event_handler.h +++ b/frameworks/native/include/sensor_event_handler.h @@ -31,6 +31,6 @@ public: */ void ProcessEvent(const AppExecFwk::InnerEvent::Pointer &event) override; }; -} // namespace Sensors -} // namespace OHOS +} // namespace Sensors +} // namespace OHOS #endif // SENSOR_EVENT_HANDLER_H \ No newline at end of file diff --git a/frameworks/native/include/sensor_file_descriptor_listener.h b/frameworks/native/include/sensor_file_descriptor_listener.h index 91a80a0c25cf8d347a27c6ab5d11401a95d5d877..bef8b68558cde53dbb0389ec398962af6acc5541 100644 --- a/frameworks/native/include/sensor_file_descriptor_listener.h +++ b/frameworks/native/include/sensor_file_descriptor_listener.h @@ -36,6 +36,6 @@ private: SensorDataChannel *channel_ = nullptr; SensorData *receiveDataBuff_ = nullptr; }; -} // namespace Sensors -} // namespace OHOS +} // namespace Sensors +} // namespace OHOS #endif // SENSOR_FILE_DESCRIPTOR_LISTENER_H diff --git a/frameworks/native/include/sensor_service_client.h b/frameworks/native/include/sensor_service_client.h index 47033caebb36652932ef32f6c69f7c7d414e35f5..1dc3da36b9d783baf2746d8bf6cd407872bed0d8 100755 --- a/frameworks/native/include/sensor_service_client.h +++ b/frameworks/native/include/sensor_service_client.h @@ -59,6 +59,7 @@ private: int32_t InitServiceClient(); void UpdateSensorInfoMap(int32_t sensorId, int64_t samplingPeriod, int64_t maxReportDelay); void DeleteSensorInfoItem(int32_t sensorId); + int32_t CreateSocketClientFd(int32_t &clientFd); int32_t CreateSocketChannel(); std::mutex clientMutex_; sptr serviceDeathObserver_ = nullptr; @@ -74,6 +75,6 @@ private: std::mutex activeInfoCBMutex_; std::set activeInfoCBSet_; }; -} // namespace Sensors -} // namespace OHOS +} // namespace Sensors +} // namespace OHOS #endif // SENSOR_SERVICE_CLIENT_H \ No newline at end of file diff --git a/frameworks/native/include/sensor_service_proxy.h b/frameworks/native/include/sensor_service_proxy.h index 6712df8f47ab58fcb6999464e6d20f8101321538..be7fbea805ac195dc969d88759e6050d58eaf4b0 100755 --- a/frameworks/native/include/sensor_service_proxy.h +++ b/frameworks/native/include/sensor_service_proxy.h @@ -48,6 +48,6 @@ private: DISALLOW_COPY_AND_MOVE(SensorServiceProxy); static inline BrokerDelegator delegator_; }; -} // namespace Sensors -} // namespace OHOS +} // namespace Sensors +} // namespace OHOS #endif // SENSOR_SERVICE_PROXY_H diff --git a/frameworks/native/include/sensors_ipc_interface_code.h b/frameworks/native/include/sensors_ipc_interface_code.h index 1cbfc1e30aa36a3ba1889bb223d098ad5cea3eb1..2fd9df9ac4441be519248b32630f20f7699daa22 100644 --- a/frameworks/native/include/sensors_ipc_interface_code.h +++ b/frameworks/native/include/sensors_ipc_interface_code.h @@ -34,6 +34,6 @@ enum class SensorInterfaceCode { DISABLE_ACTIVE_INFO_CB, RESET_SENSORS, }; -} // namespace Sensors -} // namespace OHOS +} // namespace Sensors +} // namespace OHOS #endif // SENSORS_IPC_INTERFACE_CODE_H diff --git a/frameworks/native/src/sensor_agent_proxy.cpp b/frameworks/native/src/sensor_agent_proxy.cpp index a714a3cb2b87cbd4c89c418373ac75634e93406d..267b3255b0f5d70794ec1fb8e31825fce771f8c0 100644 --- a/frameworks/native/src/sensor_agent_proxy.cpp +++ b/frameworks/native/src/sensor_agent_proxy.cpp @@ -17,6 +17,7 @@ #include +#include "print_sensor_data.h" #include "securec.h" #include "sensor_errors.h" #include "sensor_service_client.h" @@ -59,7 +60,8 @@ std::set SensorAgentProxy::GetSubscribeUser(int32_t sensorId return {iter->second}; } -void SensorAgentProxy::HandleSensorData(SensorEvent *events, int32_t num, void *data) +void SensorAgentProxy::HandleSensorData(SensorEvent *events, + int32_t num, void *data) __attribute__((no_sanitize("cfi"))) { CHKPV(events); if (num <= 0) { @@ -75,6 +77,7 @@ void SensorAgentProxy::HandleSensorData(SensorEvent *events, int32_t num, void * RecordSensorCallback fun = user->callback; CHKPV(fun); fun(&eventStream); + PrintSensorData::GetInstance().ControlSensorClientPrint(user, eventStream); } } } @@ -244,6 +247,9 @@ int32_t SensorAgentProxy::SubscribeSensor(int32_t sensorId, const SensorUser *us if (!status.second) { SEN_HILOGD("User has been subscribed"); } + if (PrintSensorData::GetInstance().IsContinuousType(sensorId)) { + PrintSensorData::GetInstance().SavePrintUserInfo(user); + } return OHOS::Sensors::SUCCESS; } @@ -277,6 +283,9 @@ int32_t SensorAgentProxy::UnsubscribeSensor(int32_t sensorId, const SensorUser * if (unsubscribeSet.empty()) { unsubscribeMap_.erase(sensorId); } + if (PrintSensorData::GetInstance().IsContinuousType(sensorId)) { + PrintSensorData::GetInstance().RemovePrintUserInfo(user); + } return OHOS::Sensors::SUCCESS; } diff --git a/frameworks/native/src/sensor_data_channel.cpp b/frameworks/native/src/sensor_data_channel.cpp index c54732956172a1599a34d6c7a71a8dc480497bfc..4a2bfc1315694e8883248c06dce6b28e6fed3fee 100644 --- a/frameworks/native/src/sensor_data_channel.cpp +++ b/frameworks/native/src/sensor_data_channel.cpp @@ -40,7 +40,7 @@ int32_t SensorDataChannel::RestoreSensorDataChannel() { CHKPR(dataCB_, SENSOR_NATIVE_REGSITER_CB_ERR); if (GetReceiveDataFd() != -1) { - SEN_HILOGW("Restore sensor data channel failed, please destroy sensor data channel first."); + SEN_HILOGW("Restore sensor data channel failed, please destroy sensor data channel first"); return SENSOR_CHANNEL_RESTORE_FD_ERR; } return InnerSensorDataChannel(); diff --git a/frameworks/native/src/sensor_service_client.cpp b/frameworks/native/src/sensor_service_client.cpp index 7d6ceeecaf068f56a755338116f88d5c5b636a71..f3a329cfefca696a36baf01cfefe5fc671efaff2 100644 --- a/frameworks/native/src/sensor_service_client.cpp +++ b/frameworks/native/src/sensor_service_client.cpp @@ -21,8 +21,12 @@ #include #include "death_recipient_template.h" +#ifdef HIVIEWDFX_HISYSEVENT_ENABLE #include "hisysevent.h" +#endif // HIVIEWDFX_HISYSEVENT_ENABLE +#ifdef HIVIEWDFX_HITRACE_ENABLE #include "hitrace_meter.h" +#endif // HIVIEWDFX_HITRACE_ENABLE #include "ipc_skeleton.h" #include "sensor_errors.h" #include "sensor_service_proxy.h" @@ -96,8 +100,10 @@ int32_t SensorServiceClient::InitServiceClient() std::this_thread::sleep_for(std::chrono::milliseconds(WAIT_MS)); retry++; } +#ifdef HIVIEWDFX_HISYSEVENT_ENABLE HiSysEventWrite(HiviewDFX::HiSysEvent::Domain::SENSOR, "SERVICE_EXCEPTION", HiSysEvent::EventType::FAULT, "PKG_NAME", "InitServiceClient", "ERROR_CODE", SENSOR_NATIVE_GET_SERVICE_ERR); +#endif // HIVIEWDFX_HISYSEVENT_ENABLE SEN_HILOGE("Get service failed"); return SENSOR_NATIVE_GET_SERVICE_ERR; } @@ -132,9 +138,13 @@ int32_t SensorServiceClient::EnableSensor(int32_t sensorId, int64_t samplingPeri } std::lock_guard clientLock(clientMutex_); CHKPR(sensorServer_, ERROR); +#ifdef HIVIEWDFX_HITRACE_ENABLE StartTrace(HITRACE_TAG_SENSORS, "EnableSensor"); +#endif // HIVIEWDFX_HITRACE_ENABLE ret = sensorServer_->EnableSensor(sensorId, samplingPeriod, maxReportDelay); +#ifdef HIVIEWDFX_HITRACE_ENABLE FinishTrace(HITRACE_TAG_SENSORS); +#endif // HIVIEWDFX_HITRACE_ENABLE if (ret == ERR_OK) { UpdateSensorInfoMap(sensorId, samplingPeriod, maxReportDelay); } @@ -151,9 +161,13 @@ int32_t SensorServiceClient::DisableSensor(int32_t sensorId) } std::lock_guard clientLock(clientMutex_); CHKPR(sensorServer_, ERROR); +#ifdef HIVIEWDFX_HITRACE_ENABLE StartTrace(HITRACE_TAG_SENSORS, "DisableSensor"); +#endif // HIVIEWDFX_HITRACE_ENABLE ret = sensorServer_->DisableSensor(sensorId); +#ifdef HIVIEWDFX_HITRACE_ENABLE FinishTrace(HITRACE_TAG_SENSORS); +#endif // HIVIEWDFX_HITRACE_ENABLE if (ret == ERR_OK) { DeleteSensorInfoItem(sensorId); } @@ -190,12 +204,16 @@ int32_t SensorServiceClient::TransferDataChannel(sptr sensorD } std::lock_guard clientLock(clientMutex_); CHKPR(sensorServer_, ERROR); +#ifdef HIVIEWDFX_HITRACE_ENABLE StartTrace(HITRACE_TAG_SENSORS, "TransferDataChannel"); +#endif // HIVIEWDFX_HITRACE_ENABLE CHKPR(sensorClientStub_, INVALID_POINTER); auto remoteObject = sensorClientStub_->AsObject(); CHKPR(remoteObject, INVALID_POINTER); ret = sensorServer_->TransferDataChannel(sensorDataChannel, remoteObject); +#ifdef HIVIEWDFX_HITRACE_ENABLE FinishTrace(HITRACE_TAG_SENSORS); +#endif // HIVIEWDFX_HITRACE_ENABLE return ret; } @@ -209,12 +227,16 @@ int32_t SensorServiceClient::DestroyDataChannel() } std::lock_guard clientLock(clientMutex_); CHKPR(sensorServer_, ERROR); +#ifdef HIVIEWDFX_HITRACE_ENABLE StartTrace(HITRACE_TAG_SENSORS, "DestroyDataChannel"); +#endif // HIVIEWDFX_HITRACE_ENABLE CHKPR(sensorClientStub_, INVALID_POINTER); auto remoteObject = sensorClientStub_->AsObject(); CHKPR(remoteObject, INVALID_POINTER); ret = sensorServer_->DestroySensorChannel(remoteObject); +#ifdef HIVIEWDFX_HITRACE_ENABLE FinishTrace(HITRACE_TAG_SENSORS); +#endif // HIVIEWDFX_HITRACE_ENABLE return ret; } @@ -303,9 +325,13 @@ int32_t SensorServiceClient::SuspendSensors(int32_t pid) } std::lock_guard clientLock(clientMutex_); CHKPR(sensorServer_, ERROR); +#ifdef HIVIEWDFX_HITRACE_ENABLE StartTrace(HITRACE_TAG_SENSORS, "SuspendSensors"); +#endif // HIVIEWDFX_HITRACE_ENABLE ret = sensorServer_->SuspendSensors(pid); +#ifdef HIVIEWDFX_HITRACE_ENABLE FinishTrace(HITRACE_TAG_SENSORS); +#endif // HIVIEWDFX_HITRACE_ENABLE return ret; } @@ -319,9 +345,13 @@ int32_t SensorServiceClient::ResumeSensors(int32_t pid) } std::lock_guard clientLock(clientMutex_); CHKPR(sensorServer_, ERROR); +#ifdef HIVIEWDFX_HITRACE_ENABLE StartTrace(HITRACE_TAG_SENSORS, "ResumeSensors"); +#endif // HIVIEWDFX_HITRACE_ENABLE ret = sensorServer_->ResumeSensors(pid); +#ifdef HIVIEWDFX_HITRACE_ENABLE FinishTrace(HITRACE_TAG_SENSORS); +#endif // HIVIEWDFX_HITRACE_ENABLE return ret; } @@ -335,9 +365,13 @@ int32_t SensorServiceClient::GetActiveInfoList(int32_t pid, std::vector clientLock(clientMutex_); CHKPR(sensorServer_, ERROR); +#ifdef HIVIEWDFX_HITRACE_ENABLE StartTrace(HITRACE_TAG_SENSORS, "GetActiveInfoList"); +#endif // HIVIEWDFX_HITRACE_ENABLE ret = sensorServer_->GetActiveInfoList(pid, activeInfoList); +#ifdef HIVIEWDFX_HITRACE_ENABLE FinishTrace(HITRACE_TAG_SENSORS); +#endif // HIVIEWDFX_HITRACE_ENABLE return ret; } @@ -378,20 +412,28 @@ int32_t SensorServiceClient::Unregister(SensorActiveInfoCB callback) } std::lock_guard clientLock(clientMutex_); CHKPR(sensorServer_, ERROR); +#ifdef HIVIEWDFX_HITRACE_ENABLE StartTrace(HITRACE_TAG_SENSORS, "DisableActiveInfoCB"); +#endif // HIVIEWDFX_HITRACE_ENABLE ret = sensorServer_->DisableActiveInfoCB(); +#ifdef HIVIEWDFX_HITRACE_ENABLE FinishTrace(HITRACE_TAG_SENSORS); +#endif // HIVIEWDFX_HITRACE_ENABLE if (ret != ERR_OK) { SEN_HILOGE("Disable active info callback failed, ret:%{public}d", ret); return ret; } Disconnect(); +#ifdef HIVIEWDFX_HITRACE_ENABLE StartTrace(HITRACE_TAG_SENSORS, "DestroySocketChannel"); +#endif // HIVIEWDFX_HITRACE_ENABLE CHKPR(sensorClientStub_, INVALID_POINTER); auto remoteObject = sensorClientStub_->AsObject(); CHKPR(remoteObject, INVALID_POINTER); ret = sensorServer_->DestroySocketChannel(remoteObject); +#ifdef HIVIEWDFX_HITRACE_ENABLE FinishTrace(HITRACE_TAG_SENSORS); +#endif // HIVIEWDFX_HITRACE_ENABLE if (ret != ERR_OK) { SEN_HILOGE("Destroy socket channel failed, ret:%{public}d", ret); return ret; @@ -410,9 +452,13 @@ int32_t SensorServiceClient::ResetSensors() } std::lock_guard clientLock(clientMutex_); CHKPR(sensorServer_, ERROR); +#ifdef HIVIEWDFX_HITRACE_ENABLE StartTrace(HITRACE_TAG_SENSORS, "ResetSensors"); +#endif // HIVIEWDFX_HITRACE_ENABLE ret = sensorServer_->ResetSensors(); +#ifdef HIVIEWDFX_HITRACE_ENABLE FinishTrace(HITRACE_TAG_SENSORS); +#endif // HIVIEWDFX_HITRACE_ENABLE return ret; } @@ -478,6 +524,21 @@ void SensorServiceClient::Disconnect() Close(); } +int32_t SensorServiceClient::CreateSocketClientFd(int32_t &clientFd) +{ +#ifdef HIVIEWDFX_HITRACE_ENABLE + StartTrace(HITRACE_TAG_SENSORS, "CreateSocketChannel"); +#endif // HIVIEWDFX_HITRACE_ENABLE + CHKPR(sensorClientStub_, INVALID_POINTER); + auto remoteObject = sensorClientStub_->AsObject(); + CHKPR(remoteObject, INVALID_POINTER); + int ret = sensorServer_->CreateSocketChannel(remoteObject, clientFd); +#ifdef HIVIEWDFX_HITRACE_ENABLE + FinishTrace(HITRACE_TAG_SENSORS); +#endif // HIVIEWDFX_HITRACE_ENABLE + return ret; +} + int32_t SensorServiceClient::CreateSocketChannel() { CALL_LOG_ENTER; @@ -489,12 +550,7 @@ int32_t SensorServiceClient::CreateSocketChannel() std::lock_guard clientLock(clientMutex_); CHKPR(sensorServer_, ERROR); int32_t clientFd = -1; - StartTrace(HITRACE_TAG_SENSORS, "CreateSocketChannel"); - CHKPR(sensorClientStub_, INVALID_POINTER); - auto remoteObject = sensorClientStub_->AsObject(); - CHKPR(remoteObject, INVALID_POINTER); - ret = sensorServer_->CreateSocketChannel(remoteObject, clientFd); - FinishTrace(HITRACE_TAG_SENSORS); + ret = CreateSocketClientFd(clientFd); if (ret != ERR_OK || clientFd < 0) { Close(); SEN_HILOGE("Create socket channel failed, ret:%{public}d", ret); @@ -515,9 +571,13 @@ int32_t SensorServiceClient::CreateSocketChannel() return ERROR; } } +#ifdef HIVIEWDFX_HITRACE_ENABLE StartTrace(HITRACE_TAG_SENSORS, "EnableActiveInfoCB"); +#endif // HIVIEWDFX_HITRACE_ENABLE ret = sensorServer_->EnableActiveInfoCB(); +#ifdef HIVIEWDFX_HITRACE_ENABLE FinishTrace(HITRACE_TAG_SENSORS); +#endif // HIVIEWDFX_HITRACE_ENABLE if (ret != ERR_OK) { SEN_HILOGE("Enable active info callback failed, ret:%{public}d", ret); Disconnect(); diff --git a/frameworks/native/src/sensor_service_proxy.cpp b/frameworks/native/src/sensor_service_proxy.cpp index 18790f4a973434c300289f4831e89e8bd96b7ddd..ea93b680261cf6784ea05cab8a02d94b0b194ab4 100644 --- a/frameworks/native/src/sensor_service_proxy.cpp +++ b/frameworks/native/src/sensor_service_proxy.cpp @@ -17,7 +17,9 @@ #include +#ifdef HIVIEWDFX_HISYSEVENT_ENABLE #include "hisysevent.h" +#endif // HIVIEWDFX_HISYSEVENT_ENABLE #include "message_parcel.h" #include "sensor_client_proxy.h" #include "sensor_errors.h" @@ -50,8 +52,10 @@ ErrCode SensorServiceProxy::EnableSensor(int32_t sensorId, int64_t samplingPerio int32_t ret = remote->SendRequest(static_cast(SensorInterfaceCode::ENABLE_SENSOR), data, reply, option); if (ret != NO_ERROR) { +#ifdef HIVIEWDFX_HISYSEVENT_ENABLE HiSysEventWrite(HiSysEvent::Domain::SENSOR, "SERVICE_IPC_EXCEPTION", HiSysEvent::EventType::FAULT, "PKG_NAME", "EnableSensor", "ERROR_CODE", ret); +#endif // HIVIEWDFX_HISYSEVENT_ENABLE SEN_HILOGE("Failed, ret:%{public}d", ret); } return static_cast(ret); @@ -72,8 +76,10 @@ ErrCode SensorServiceProxy::DisableSensor(int32_t sensorId) int32_t ret = remote->SendRequest(static_cast(SensorInterfaceCode::DISABLE_SENSOR), data, reply, option); if (ret != NO_ERROR) { +#ifdef HIVIEWDFX_HISYSEVENT_ENABLE HiSysEventWrite(HiSysEvent::Domain::SENSOR, "SERVICE_IPC_EXCEPTION", HiSysEvent::EventType::FAULT, "PKG_NAME", "DisableSensor", "ERROR_CODE", ret); +#endif // HIVIEWDFX_HISYSEVENT_ENABLE SEN_HILOGE("Failed, ret:%{public}d", ret); } return static_cast(ret); @@ -97,8 +103,10 @@ std::vector SensorServiceProxy::GetSensorList() int32_t ret = remote->SendRequest(static_cast(SensorInterfaceCode::GET_SENSOR_LIST), data, reply, option); if (ret != NO_ERROR) { +#ifdef HIVIEWDFX_HISYSEVENT_ENABLE HiSysEventWrite(HiSysEvent::Domain::SENSOR, "SERVICE_IPC_EXCEPTION", HiSysEvent::EventType::FAULT, "PKG_NAME", "GetSensorList", "ERROR_CODE", ret); +#endif // HIVIEWDFX_HISYSEVENT_ENABLE SEN_HILOGE("Failed, ret:%{public}d", ret); return sensors; } @@ -139,8 +147,10 @@ ErrCode SensorServiceProxy::TransferDataChannel(const sptrSendRequest(static_cast(SensorInterfaceCode::TRANSFER_DATA_CHANNEL), data, reply, option); if (ret != NO_ERROR) { +#ifdef HIVIEWDFX_HISYSEVENT_ENABLE HiSysEventWrite(HiSysEvent::Domain::SENSOR, "SERVICE_IPC_EXCEPTION", HiSysEvent::EventType::FAULT, "PKG_NAME", "TransferDataChannel", "ERROR_CODE", ret); +#endif // HIVIEWDFX_HISYSEVENT_ENABLE SEN_HILOGE("Failed, ret:%{public}d", ret); } sensorBasicDataChannel->CloseSendFd(); @@ -163,8 +173,10 @@ ErrCode SensorServiceProxy::DestroySensorChannel(sptr sensorClien int32_t ret = remote->SendRequest(static_cast(SensorInterfaceCode::DESTROY_SENSOR_CHANNEL), data, reply, option); if (ret != NO_ERROR) { +#ifdef HIVIEWDFX_HISYSEVENT_ENABLE HiSysEventWrite(HiSysEvent::Domain::SENSOR, "SERVICE_IPC_EXCEPTION", HiSysEvent::EventType::FAULT, "PKG_NAME", "DestroySensorChannel", "ERROR_CODE", ret); +#endif // HIVIEWDFX_HISYSEVENT_ENABLE SEN_HILOGE("Failed, ret:%{public}d", ret); } return static_cast(ret); @@ -259,8 +271,10 @@ ErrCode SensorServiceProxy::CreateSocketChannel(sptr sensorClient int32_t ret = remote->SendRequest(static_cast(SensorInterfaceCode::CREATE_SOCKET_CHANNEL), data, reply, option); if (ret != NO_ERROR) { +#ifdef HIVIEWDFX_HISYSEVENT_ENABLE HiSysEventWrite(HiSysEvent::Domain::SENSOR, "SERVICE_IPC_EXCEPTION", HiSysEvent::EventType::FAULT, "PKG_NAME", "CreateSocketChannel", "ERROR_CODE", ret); +#endif // HIVIEWDFX_HISYSEVENT_ENABLE SEN_HILOGE("Failed, ret:%{public}d", ret); return ERROR; } @@ -288,8 +302,10 @@ ErrCode SensorServiceProxy::DestroySocketChannel(sptr sensorClien int32_t ret = remote->SendRequest(static_cast(SensorInterfaceCode::DESTROY_SOCKET_CHANNEL), data, reply, option); if (ret != NO_ERROR) { +#ifdef HIVIEWDFX_HISYSEVENT_ENABLE HiSysEventWrite(HiSysEvent::Domain::SENSOR, "SERVICE_IPC_EXCEPTION", HiSysEvent::EventType::FAULT, "PKG_NAME", "DestroySocketChannel", "ERROR_CODE", ret); +#endif // HIVIEWDFX_HISYSEVENT_ENABLE SEN_HILOGE("Failed, ret:%{public}d", ret); } return static_cast(ret); @@ -309,8 +325,10 @@ ErrCode SensorServiceProxy::EnableActiveInfoCB() int32_t ret = remote->SendRequest(static_cast(SensorInterfaceCode::ENABLE_ACTIVE_INFO_CB), data, reply, option); if (ret != NO_ERROR) { +#ifdef HIVIEWDFX_HISYSEVENT_ENABLE HiSysEventWrite(HiSysEvent::Domain::SENSOR, "SERVICE_IPC_EXCEPTION", HiSysEvent::EventType::FAULT, "PKG_NAME", "EnableActiveInfoCB", "ERROR_CODE", ret); +#endif // HIVIEWDFX_HISYSEVENT_ENABLE SEN_HILOGE("Failed, ret:%{public}d", ret); } return static_cast(ret); @@ -330,8 +348,10 @@ ErrCode SensorServiceProxy::DisableActiveInfoCB() int32_t ret = remote->SendRequest(static_cast(SensorInterfaceCode::DISABLE_ACTIVE_INFO_CB), data, reply, option); if (ret != NO_ERROR) { +#ifdef HIVIEWDFX_HISYSEVENT_ENABLE HiSysEventWrite(HiSysEvent::Domain::SENSOR, "SERVICE_IPC_EXCEPTION", HiSysEvent::EventType::FAULT, "PKG_NAME", "DisableActiveInfoCB", "ERROR_CODE", ret); +#endif // HIVIEWDFX_HISYSEVENT_ENABLE SEN_HILOGE("Failed, ret:%{public}d", ret); } return static_cast(ret); @@ -351,8 +371,10 @@ ErrCode SensorServiceProxy::ResetSensors() int32_t ret = remote->SendRequest(static_cast(SensorInterfaceCode::RESET_SENSORS), data, reply, option); if (ret != NO_ERROR) { +#ifdef HIVIEWDFX_HISYSEVENT_ENABLE HiSysEventWrite(HiSysEvent::Domain::SENSOR, "SERVICE_IPC_EXCEPTION", HiSysEvent::EventType::FAULT, "PKG_NAME", "ResetSensors", "ERROR_CODE", ret); +#endif // HIVIEWDFX_HISYSEVENT_ENABLE SEN_HILOGE("Failed, ret:%{public}d", ret); } return static_cast(ret); diff --git a/interfaces/inner_api/sensor_agent_type.h b/interfaces/inner_api/sensor_agent_type.h index 22ceecb4469153ad4c0fcd08d3e1b70cfb6b3159..ac5cf63a51c723e1785ef0c4faedce975ee2790b 100644 --- a/interfaces/inner_api/sensor_agent_type.h +++ b/interfaces/inner_api/sensor_agent_type.h @@ -429,7 +429,7 @@ typedef struct AmbientLightData { * The value 1 means that there is magnet attraction, and 0 means the opposite. */ typedef struct HallData { - float status = 0.0; + float status = 0.0F; } HallData; /** diff --git a/interfaces/kits/c/oh_sensor.h b/interfaces/kits/c/oh_sensor.h index 3c9b54ddf85220bdfe35af49a08ff63b2b3fa8a3..5b2718a99f972c65e7a5b6a363a887acd2fd5124 100644 --- a/interfaces/kits/c/oh_sensor.h +++ b/interfaces/kits/c/oh_sensor.h @@ -45,8 +45,10 @@ extern "C" { * @param infos - Double pointer to the information about all sensors on the device. * For details, see {@link Sensor_Info}. * @param count - Pointer to the number of sensors on the device. - * @return Returns SENSOR_SUCCESS if the operation is successful; - * returns an error code defined in {@link Sensor_Result} otherwise. + * @return Returns SENSOR_SUCCESS if the operation is successful; returns the following error code otherwise. + * {@link SENSOR_PARAMETER_ERROR} Parameter check failed. For example, the parameter is invalid, + * or the parameter type passed in is incorrect.\n + * {@link SENSOR_SERVICE_EXCEPTION} The sensor service is abnormal.\n * * @since 11 */ @@ -65,8 +67,11 @@ Sensor_Result OH_Sensor_GetInfos(Sensor_Info **infos, uint32_t *count); * For details, see {@link Sensor_SubscriptionAttribute}. * @param subscriber - Pointer to the subscriber information, which is used to specify the callback function for * reporting the sensor data. For details, see {@link Sensor_Subscriber}. - * @return Returns SENSOR_SUCCESS if the operation is successful; - * returns an error code defined in {@link Sensor_Result} otherwise. + * @return Returns SENSOR_SUCCESS if the operation is successful; returns the following error code otherwise. + * {@link SENSOR_PERMISSION_DENIED} Permission verification failed.\n + * {@link SENSOR_PARAMETER_ERROR} Parameter check failed. For example, the parameter is invalid, + * or the parameter type passed in is incorrect.\n + * {@link SENSOR_SERVICE_EXCEPTION} The sensor service is abnormal.\n * @permission ohos.permission.ACCELEROMETER or ohos.permission.GYROSCOPE or * ohos.permission.ACTIVITY_MOTION or ohos.permission.READ_HEALTH_DATA * @since 11 @@ -85,8 +90,11 @@ Sensor_Result OH_Sensor_Subscribe(const Sensor_SubscriptionId *id, * @param id - Pointer to the sensor subscription ID. For details, see {@link Sensor_SubscriptionId}. * @param subscriber - Pointer to the subscriber information, which is used to specify the callback function for * reporting the sensor data. For details, see {@link Sensor_Subscriber}. - * @return Returns SENSOR_SUCCESS if the operation is successful; - * returns an error code defined in {@link Sensor_Result} otherwise. + * @return Returns SENSOR_SUCCESS if the operation is successful; returns the following error code otherwise. + * {@link SENSOR_PERMISSION_DENIED} Permission verification failed.\n + * {@link SENSOR_PARAMETER_ERROR} Parameter check failed. For example, the parameter is invalid, + * or the parameter type passed in is incorrect.\n + * {@link SENSOR_SERVICE_EXCEPTION} The sensor service is abnormal.\n * @permission ohos.permission.ACCELEROMETER or ohos.permission.GYROSCOPE or * ohos.permission.ACTIVITY_MOTION or ohos.permission.READ_HEALTH_DATA * diff --git a/interfaces/kits/c/oh_sensor_type.h b/interfaces/kits/c/oh_sensor_type.h index e0ab040e90cae5eb0224b1267f3dbc1b33515cfe..0641a9c0cf414e456dcedd7e972d3df5bb2d8f50 100644 --- a/interfaces/kits/c/oh_sensor_type.h +++ b/interfaces/kits/c/oh_sensor_type.h @@ -91,11 +91,21 @@ typedef enum Sensor_Type { * @since 11 */ SENSOR_TYPE_GRAVITY = 257, + /** + * Linear acceleration sensor. + * @since 13 + */ + SENSOR_TYPE_LINEAR_ACCELERATION = 258, /** * Rotation vector sensor. * @since 11 */ SENSOR_TYPE_ROTATION_VECTOR = 259, + /** + * Game rotation vector sensor. + * @since 13 + */ + SENSOR_TYPE_GAME_ROTATION_VECTOR = 262, /** * Pedometer detection sensor. * @since 11 @@ -120,23 +130,23 @@ typedef enum Sensor_Type { */ typedef enum Sensor_Result { /** - * The operation is successful. + * @error The operation is successful. * @since 11 */ SENSOR_SUCCESS = 0, /** - * Permission verification failed. + * @error Permission verification failed. * @since 11 */ SENSOR_PERMISSION_DENIED = 201, /** - * Parameter check failed. For example, a mandatory parameter is not passed in, + * @error Parameter check failed. For example, a mandatory parameter is not passed in, * or the parameter type passed in is incorrect. * @since 11 */ SENSOR_PARAMETER_ERROR = 401, /** - * The sensor service is abnormal. + * @error The sensor service is abnormal. * @since 11 */ SENSOR_SERVICE_EXCEPTION = 14500101, @@ -277,35 +287,35 @@ typedef struct Sensor_Event Sensor_Event; /** * @brief Obtains the sensor type. * - * @param Sensor_Event - Pointer to the sensor data information. + * @param sensorEvent - Pointer to the sensor data information. * @param sensorType - Pointer to the sensor type. * @return Returns SENSOR_SUCCESS if the operation is successful; * returns an error code defined in {@link Sensor_Result} otherwise. * @since 11 */ -int32_t OH_SensorEvent_GetType(Sensor_Event* Sensor_Event, Sensor_Type *sensorType); +int32_t OH_SensorEvent_GetType(Sensor_Event* sensorEvent, Sensor_Type *sensorType); /** * @brief Obtains the timestamp of sensor data. * - * @param Sensor_Event - Pointer to the sensor data information. + * @param sensorEvent - Pointer to the sensor data information. * @param timestamp - Pointer to the timestamp. * @return Returns SENSOR_SUCCESS if the operation is successful; * returns an error code defined in {@link Sensor_Result} otherwise. * @since 11 */ -int32_t OH_SensorEvent_GetTimestamp(Sensor_Event* Sensor_Event, int64_t *timestamp); +int32_t OH_SensorEvent_GetTimestamp(Sensor_Event* sensorEvent, int64_t *timestamp); /** * @brief Obtains the accuracy of sensor data. * - * @param Sensor_Event - Pointer to the sensor data information. + * @param sensorEvent - Pointer to the sensor data information. * @param accuracy - Pointer to the accuracy. * @return Returns SENSOR_SUCCESS if the operation is successful; * returns an error code defined in {@link Sensor_Result} otherwise. * @since 11 */ -int32_t OH_SensorEvent_GetAccuracy(Sensor_Event* Sensor_Event, Sensor_Accuracy *accuracy); +int32_t OH_SensorEvent_GetAccuracy(Sensor_Event* sensorEvent, Sensor_Accuracy *accuracy); /** * @brief Obtains sensor data. The data length and content depend on the sensor type. @@ -314,7 +324,9 @@ int32_t OH_SensorEvent_GetAccuracy(Sensor_Event* Sensor_Event, Sensor_Accuracy * * the x, y, and z axes of the device, respectively, in m/s2. * SENSOR_TYPE_GYROSCOPE: data[0], data[1], and data[2], indicating the angular velocity of rotation around * the x, y, and z axes of the device, respectively, in rad/s. - * SENSOR_TYPE_AMBIENT_LIGHT: data[0], indicating the ambient light intensity, in lux. + * SENSOR_TYPE_AMBIENT_LIGHT: data[0], indicating the ambient light intensity, in lux. Since api version 12, + * two additional data will be returned, where data[1] indicating the color temperature, in kelvin; data[2] + * indicating the infrared luminance, in cd/m2. * SENSOR_TYPE_MAGNETIC_FIELD: data[0], data[1], and data[2], indicating the magnetic field strength around * the x, y, and z axes of the device, respectively, in μT. * SENSOR_TYPE_BAROMETER: data[0], indicating the atmospheric pressure, in hPa. @@ -332,15 +344,20 @@ int32_t OH_SensorEvent_GetAccuracy(Sensor_Event* Sensor_Event, Sensor_Accuracy * * The value 1 means that the number of detected steps changes. * SENSOR_TYPE_PEDOMETER: data[0], indicating the number of steps a user has walked. * SENSOR_TYPE_HEART_RATE: data[0], indicating the heart rate value. + * SENSOR_TYPE_LINEAR_ACCELERATION: Supported from api version 13. data[0], data[1], and data[2], indicating the + * linear acceleration around the x, y, and z axes of the device, respectively, in m/s2. + * SENSOR_TYPE_GAME_ROTATION_VECTOR: Supported from api version 13. data[0], data[1] and data[2], indicating the + * rotation angles of a device around the x, y, and z axes, respectively, in degree. data[3] indicates the rotation + * vector. * - * @param Sensor_Event - Pointer to the sensor data information. + * @param sensorEvent - Pointer to the sensor data information. * @param data - Double pointer to the sensor data. * @param length - Pointer to the array length. * @return Returns SENSOR_SUCCESS if the operation is successful; * returns an error code defined in {@link Sensor_Result} otherwise. * @since 11 */ -int32_t OH_SensorEvent_GetData(Sensor_Event* Sensor_Event, float **data, uint32_t *length); +int32_t OH_SensorEvent_GetData(Sensor_Event* sensorEvent, float **data, uint32_t *length); /** * @brief Defines the sensor subscription ID, which uniquely identifies a sensor. @@ -371,7 +388,7 @@ int32_t OH_Sensor_DestroySubscriptionId(Sensor_SubscriptionId *id); * @brief Obtains the sensor type. * * @param id - Pointer to the sensor subscription ID. - * @param id - Pointer to the sensor type. + * @param sensorType - Pointer to the sensor type. * @return Returns SENSOR_SUCCESS if the operation is successful; * returns an error code defined in {@link Sensor_Result} otherwise. * @since 11 diff --git a/sensor.gni b/sensor.gni index 4306a82493993915a47e402827d6bb0d3a5e6be7..0f548ad66c61beecf5874fd2033d21671fddba51 100644 --- a/sensor.gni +++ b/sensor.gni @@ -14,7 +14,9 @@ import("//build/ohos.gni") declare_args() { - rust_socket_ipc = false + hiviewdfx_hisysevent_enable = false + sensor_rust_socket_ipc = false + hiviewdfx_hitrace_enable = false } SUBSYSTEM_DIR = "//base/sensors/sensor" @@ -23,7 +25,7 @@ FUZZ_MODULE_OUT_PATH = "sensor/sensor" sensor_default_defines = [] -if (rust_socket_ipc) { +if (sensor_rust_socket_ipc) { sensor_default_defines += [ "OHOS_BUILD_ENABLE_RUST" ] } @@ -48,3 +50,15 @@ if (build_variant == "root") { } else { sensor_build_eng = false } + +if (defined(global_parts_info) && + defined(global_parts_info.hiviewdfx_hisysevent)) { + hiviewdfx_hisysevent_enable = true + sensor_default_defines += [ "HIVIEWDFX_HISYSEVENT_ENABLE" ] +} + +if (defined(global_parts_info) && + defined(global_parts_info.hiviewdfx_hitrace)) { + hiviewdfx_hitrace_enable = true + sensor_default_defines += [ "HIVIEWDFX_HITRACE_ENABLE" ] +} diff --git a/services/BUILD.gn b/services/BUILD.gn index f8b346c3af3103a89be453c46e2d749a19cb9b88..31681dd02c5090dc878a5515ff493f69f6d68b49 100644 --- a/services/BUILD.gn +++ b/services/BUILD.gn @@ -49,7 +49,7 @@ ohos_shared_library("libsensor_service") { "$SUBSYSTEM_DIR/utils/ipc:libsensor_ipc", ] - if (rust_socket_ipc) { + if (sensor_rust_socket_ipc) { deps += [ "$SUBSYSTEM_DIR/rust/utils/socket_ipc_rust_ffi:sensor_rust_util_ffi" ] } @@ -59,10 +59,9 @@ ohos_shared_library("libsensor_service") { "access_token:libtokenid_sdk", "c_utils:utils", "hilog:libhilog", - "hisysevent:libhisysevent", - "hitrace:hitrace_meter", "ipc:ipc_single", "safwk:system_ability_fwk", + "samgr:samgr_proxy", ] if (sensor_memmgr_enable) { @@ -70,6 +69,14 @@ ohos_shared_library("libsensor_service") { external_deps += [ "memmgr:memmgrclient" ] } + if (hiviewdfx_hisysevent_enable) { + external_deps += [ "hisysevent:libhisysevent" ] + } + + if (hiviewdfx_hitrace_enable) { + external_deps += [ "hitrace:hitrace_meter" ] + } + if (hdf_drivers_interface_sensor) { sources += [ "hdi_connection/adapter/src/hdi_connection.cpp", @@ -137,7 +144,7 @@ ohos_static_library("libsensor_service_static") { "$SUBSYSTEM_DIR/utils/ipc:libsensor_ipc", ] - if (rust_socket_ipc) { + if (sensor_rust_socket_ipc) { deps += [ "$SUBSYSTEM_DIR/rust/utils/socket_ipc_rust_ffi:sensor_rust_util_ffi" ] } @@ -147,10 +154,9 @@ ohos_static_library("libsensor_service_static") { "access_token:libtokenid_sdk", "c_utils:utils", "hilog:libhilog", - "hisysevent:libhisysevent", - "hitrace:hitrace_meter", "ipc:ipc_single", "safwk:system_ability_fwk", + "samgr:samgr_proxy", ] if (sensor_memmgr_enable) { @@ -158,6 +164,14 @@ ohos_static_library("libsensor_service_static") { external_deps += [ "memmgr:memmgrclient" ] } + if (hiviewdfx_hisysevent_enable) { + external_deps += [ "hisysevent:libhisysevent" ] + } + + if (hiviewdfx_hitrace_enable) { + external_deps += [ "hitrace:hitrace_meter" ] + } + if (hdf_drivers_interface_sensor) { sources += [ "hdi_connection/adapter/src/hdi_connection.cpp", diff --git a/services/hdi_connection/adapter/include/sensor_event_callback.h b/services/hdi_connection/adapter/include/sensor_event_callback.h index f1c62ff6733f7e42c441f660c70a824c516a8edd..2d81cb858aec85f741810e9361766b1c84ee8a09 100644 --- a/services/hdi_connection/adapter/include/sensor_event_callback.h +++ b/services/hdi_connection/adapter/include/sensor_event_callback.h @@ -30,13 +30,6 @@ class SensorEventCallback : public ISensorCallback { public: virtual ~SensorEventCallback() {} int32_t OnDataEvent(const HdfSensorEvents &event) override; -private: - void ControlSensorPrint(const SensorData &sensorData); - void PrintSensorData(const SensorData &sensorData); - int32_t GetDataDimension(int32_t sensorId); - int64_t postureLastTs_ = 0; - int64_t ambientLightLastTs_ = 0; - int64_t magneticFieldLastTs_ = 0; }; } // namespace Sensors } // namespace OHOS diff --git a/services/hdi_connection/adapter/src/hdi_connection.cpp b/services/hdi_connection/adapter/src/hdi_connection.cpp index 977697dd6ac59848c8cad19142eacfcf46d418d9..5cd089aba48c7bb2175b0fbb7c9169b94846fb44 100644 --- a/services/hdi_connection/adapter/src/hdi_connection.cpp +++ b/services/hdi_connection/adapter/src/hdi_connection.cpp @@ -18,7 +18,9 @@ #include #include +#ifdef HIVIEWDFX_HISYSEVENT_ENABLE #include "hisysevent.h" +#endif // HIVIEWDFX_HISYSEVENT_ENABLE #include "iproxy_broker.h" #include "v2_0/isensor_interface.h" @@ -65,8 +67,10 @@ int32_t HdiConnection::ConnectHdi() SEN_HILOGW("Connect hdi service failed, retry:%{public}d", retry); std::this_thread::sleep_for(std::chrono::milliseconds(WAIT_MS)); } +#ifdef HIVIEWDFX_HISYSEVENT_ENABLE HiSysEventWrite(HiviewDFX::HiSysEvent::Domain::SENSOR, "HDF_SERVICE_EXCEPTION", HiSysEvent::EventType::FAULT, "PKG_NAME", "ConnectHdi", "ERROR_CODE", CONNECT_SENSOR_HDF_ERR); +#endif // HIVIEWDFX_HISYSEVENT_ENABLE SEN_HILOGE("Connect V2_0 hdi failed"); return ERR_NO_INIT; } @@ -78,8 +82,10 @@ int32_t HdiConnection::GetSensorList(std::vector &sensorList) std::vector sensorInfos; int32_t ret = g_sensorInterface->GetAllSensorInfo(sensorInfos); if (ret != 0) { +#ifdef HIVIEWDFX_HISYSEVENT_ENABLE HiSysEventWrite(HiviewDFX::HiSysEvent::Domain::SENSOR, "HDF_SERVICE_EXCEPTION", HiSysEvent::EventType::FAULT, "PKG_NAME", "GetSensorList", "ERROR_CODE", ret); +#endif // HIVIEWDFX_HISYSEVENT_ENABLE SEN_HILOGE("Get sensor list failed"); return ret; } @@ -114,8 +120,10 @@ int32_t HdiConnection::EnableSensor(int32_t sensorId) CHKPR(g_sensorInterface, ERR_NO_INIT); int32_t ret = g_sensorInterface->Enable(sensorId); if (ret != 0) { +#ifdef HIVIEWDFX_HISYSEVENT_ENABLE HiSysEventWrite(HiviewDFX::HiSysEvent::Domain::SENSOR, "HDF_SERVICE_EXCEPTION", HiSysEvent::EventType::FAULT, "PKG_NAME", "EnableSensor", "ERROR_CODE", ret); +#endif // HIVIEWDFX_HISYSEVENT_ENABLE SEN_HILOGE("Connect V2_0 hdi failed"); return ret; } @@ -128,8 +136,10 @@ int32_t HdiConnection::DisableSensor(int32_t sensorId) CHKPR(g_sensorInterface, ERR_NO_INIT); int32_t ret = g_sensorInterface->Disable(sensorId); if (ret != 0) { +#ifdef HIVIEWDFX_HISYSEVENT_ENABLE HiSysEventWrite(HiviewDFX::HiSysEvent::Domain::SENSOR, "HDF_SERVICE_EXCEPTION", HiSysEvent::EventType::FAULT, "PKG_NAME", "DisableSensor", "ERROR_CODE", ret); +#endif // HIVIEWDFX_HISYSEVENT_ENABLE SEN_HILOGE("Disable is failed"); return ret; } @@ -142,8 +152,10 @@ int32_t HdiConnection::SetBatch(int32_t sensorId, int64_t samplingInterval, int6 CHKPR(g_sensorInterface, ERR_NO_INIT); int32_t ret = g_sensorInterface->SetBatch(sensorId, samplingInterval, reportInterval); if (ret != 0) { +#ifdef HIVIEWDFX_HISYSEVENT_ENABLE HiSysEventWrite(HiviewDFX::HiSysEvent::Domain::SENSOR, "HDF_SERVICE_EXCEPTION", HiSysEvent::EventType::FAULT, "PKG_NAME", "SetBatch", "ERROR_CODE", ret); +#endif // HIVIEWDFX_HISYSEVENT_ENABLE SEN_HILOGE("SetBatch is failed"); return ret; } @@ -157,8 +169,10 @@ int32_t HdiConnection::SetMode(int32_t sensorId, int32_t mode) CHKPR(g_sensorInterface, ERR_NO_INIT); int32_t ret = g_sensorInterface->SetMode(sensorId, mode); if (ret != 0) { +#ifdef HIVIEWDFX_HISYSEVENT_ENABLE HiSysEventWrite(HiviewDFX::HiSysEvent::Domain::SENSOR, "HDF_SERVICE_EXCEPTION", HiSysEvent::EventType::FAULT, "PKG_NAME", "SetMode", "ERROR_CODE", ret); +#endif // HIVIEWDFX_HISYSEVENT_ENABLE SEN_HILOGE("SetMode is failed"); return ret; } @@ -172,8 +186,10 @@ int32_t HdiConnection::RegisterDataReport(ReportDataCb cb, sptrRegister(0, g_eventCallback); if (ret != 0) { +#ifdef HIVIEWDFX_HISYSEVENT_ENABLE HiSysEventWrite(HiviewDFX::HiSysEvent::Domain::SENSOR, "HDF_SERVICE_EXCEPTION", HiSysEvent::EventType::FAULT, "PKG_NAME", "RegisterDataReport", "ERROR_CODE", ret); +#endif // HIVIEWDFX_HISYSEVENT_ENABLE SEN_HILOGE("Register is failed"); return ret; } @@ -188,8 +204,10 @@ int32_t HdiConnection::DestroyHdiConnection() CHKPR(g_sensorInterface, ERR_NO_INIT); int32_t ret = g_sensorInterface->Unregister(0, g_eventCallback); if (ret != 0) { +#ifdef HIVIEWDFX_HISYSEVENT_ENABLE HiSysEventWrite(HiviewDFX::HiSysEvent::Domain::SENSOR, "HDF_SERVICE_EXCEPTION", HiSysEvent::EventType::FAULT, "PKG_NAME", "DestroyHdiConnection", "ERROR_CODE", ret); +#endif // HIVIEWDFX_HISYSEVENT_ENABLE SEN_HILOGE("Unregister is failed"); return ret; } diff --git a/services/hdi_connection/adapter/src/sensor_event_callback.cpp b/services/hdi_connection/adapter/src/sensor_event_callback.cpp index 19c830f8c0206f3d5f00877d8be807e7711e785a..d632c5b2a865817728bf8da83039f431a8eaf172 100644 --- a/services/hdi_connection/adapter/src/sensor_event_callback.cpp +++ b/services/hdi_connection/adapter/src/sensor_event_callback.cpp @@ -17,6 +17,7 @@ #include #include "hdi_connection.h" +#include "print_sensor_data.h" #include "sensor_agent_type.h" #include "sensor_errors.h" @@ -37,13 +38,6 @@ enum { SEVEN_DIMENSION = 7, DEFAULT_DIMENSION = 16 }; -const std::set g_sensorTypeTrigger = { - SENSOR_TYPE_ID_PROXIMITY, - SENSOR_TYPE_ID_DROP_DETECTION, - SENSOR_TYPE_ID_HALL, - SENSOR_TYPE_ID_HALL_EXT, - SENSOR_TYPE_ID_PROXIMITY1 -}; } // namespace int32_t SensorEventCallback::OnDataEvent(const HdfSensorEvents &event) @@ -65,7 +59,8 @@ int32_t SensorEventCallback::OnDataEvent(const HdfSensorEvents &event) .mode = event.mode, .dataLen = event.dataLen }; - if (g_sensorTypeTrigger.find(sensorData.sensorTypeId) != g_sensorTypeTrigger.end()) { + if (sensorData.sensorTypeId == SENSOR_TYPE_ID_PROXIMITY || + sensorData.sensorTypeId == SENSOR_TYPE_ID_DROP_DETECTION) { sensorData.mode = SENSOR_ON_CHANGE; } CHKPR(sensorData.data, ERR_NO_INIT); @@ -87,71 +82,11 @@ int32_t SensorEventCallback::OnDataEvent(const HdfSensorEvents &event) sensorData.data[i] = event.data[i]; } } - ControlSensorPrint(sensorData); + PrintSensorData::GetInstance().ControlSensorHdiPrint(sensorData); std::unique_lock lk(ISensorHdiConnection::dataMutex_); (void)(reportDataCallback_->*(reportDataCb_))(&sensorData, reportDataCallback_); ISensorHdiConnection::dataCondition_.notify_one(); return ERR_OK; } - -void SensorEventCallback::ControlSensorPrint(const SensorData &sensorData) -{ - if (sensorData.sensorTypeId == SENSOR_TYPE_ID_HALL_EXT || sensorData.sensorTypeId == SENSOR_TYPE_ID_PROXIMITY - || sensorData.sensorTypeId == SENSOR_TYPE_ID_HALL) { - PrintSensorData(sensorData); - } - if ((sensorData.sensorTypeId == SENSOR_TYPE_ID_POSTURE) - && ((postureLastTs_ == 0) || (sensorData.timestamp - postureLastTs_ >= LOG_INTERVAL))) { - PrintSensorData(sensorData); - postureLastTs_ = sensorData.timestamp; - } - if ((sensorData.sensorTypeId == SENSOR_TYPE_ID_AMBIENT_LIGHT) - && ((ambientLightLastTs_ == 0) || (sensorData.timestamp - ambientLightLastTs_ >= LOG_INTERVAL))) { - PrintSensorData(sensorData); - ambientLightLastTs_ = sensorData.timestamp; - } - if ((sensorData.sensorTypeId == SENSOR_TYPE_ID_MAGNETIC_FIELD) - && ((magneticFieldLastTs_ == 0) || (sensorData.timestamp - magneticFieldLastTs_ >= LOG_INTERVAL))) { - PrintSensorData(sensorData); - magneticFieldLastTs_ = sensorData.timestamp; - } -} - -void SensorEventCallback::PrintSensorData(const SensorData &sensorData) -{ - std::string str; - str += "sensorId: " + std::to_string(sensorData.sensorTypeId) + ", "; - str += "timestamp: " + std::to_string(sensorData.timestamp) + ", "; - int32_t dataDim = GetDataDimension(sensorData.sensorTypeId); - auto data = reinterpret_cast(sensorData.data); - for (int32_t i = 0; i < dataDim; ++i) { - str.append(std::to_string(*data)); - if (i != dataDim - 1) { - str.append(", "); - } - ++data; - } - str.append("\n"); - SEN_HILOGI("SensorData: %{public}s", str.c_str()); -} - -int32_t SensorEventCallback::GetDataDimension(int32_t sensorId) -{ - switch (sensorId) { - case SENSOR_TYPE_ID_HALL: - case SENSOR_TYPE_ID_PROXIMITY: - return ONE_DIMENSION; - case SENSOR_TYPE_ID_HALL_EXT: - return TWO_DIMENSION; - case SENSOR_TYPE_ID_POSTURE: - return SEVEN_DIMENSION; - case SENSOR_TYPE_ID_AMBIENT_LIGHT: - case SENSOR_TYPE_ID_MAGNETIC_FIELD: - return THREE_DIMENSION; - default: - SEN_HILOGW("Unknown sensorId:%{public}d, size:%{public}d", sensorId, DEFAULT_DIMENSION); - return DEFAULT_DIMENSION; - } -} } // namespace Sensors } // namespace OHOS \ No newline at end of file diff --git a/services/hdi_connection/interface/src/sensor_hdi_connection.cpp b/services/hdi_connection/interface/src/sensor_hdi_connection.cpp index 0f755ac9b2e107648309d81c8906864799afcf31..65568e3377af5302aa06c9739a232a1c1b510612 100644 --- a/services/hdi_connection/interface/src/sensor_hdi_connection.cpp +++ b/services/hdi_connection/interface/src/sensor_hdi_connection.cpp @@ -19,7 +19,9 @@ #endif // BUILD_VARIANT_ENG #include "hdi_connection.h" +#ifdef HIVIEWDFX_HITRACE_ENABLE #include "hitrace_meter.h" +#endif // HIVIEWDFX_HITRACE_ENABLE #include "sensor_errors.h" #undef LOG_TAG @@ -230,13 +232,17 @@ int32_t SensorHdiConnection::GetSensorList(std::vector &sensorList) int32_t SensorHdiConnection::EnableSensor(int32_t sensorId) { +#ifdef HIVIEWDFX_HITRACE_ENABLE StartTrace(HITRACE_TAG_SENSORS, "EnableSensor"); +#endif // HIVIEWDFX_HITRACE_ENABLE int32_t ret = ENABLE_SENSOR_ERR; #ifdef BUILD_VARIANT_ENG if (FindOneInMockSet(sensorId)) { CHKPR(iSensorCompatibleHdiConnection_, ENABLE_SENSOR_ERR); ret = iSensorCompatibleHdiConnection_->EnableSensor(sensorId); +#ifdef HIVIEWDFX_HITRACE_ENABLE FinishTrace(HITRACE_TAG_SENSORS); +#endif // HIVIEWDFX_HITRACE_ENABLE if (ret != ERR_OK) { SEN_HILOGE("Enable sensor failed in compatible, sensorId:%{public}d", sensorId); return ENABLE_SENSOR_ERR; @@ -246,7 +252,9 @@ int32_t SensorHdiConnection::EnableSensor(int32_t sensorId) #endif // BUILD_VARIANT_ENG CHKPR(iSensorHdiConnection_, ENABLE_SENSOR_ERR); ret = iSensorHdiConnection_->EnableSensor(sensorId); +#ifdef HIVIEWDFX_HITRACE_ENABLE FinishTrace(HITRACE_TAG_SENSORS); +#endif // HIVIEWDFX_HITRACE_ENABLE if (ret != ERR_OK) { SEN_HILOGI("Enable sensor failed, sensorId:%{public}d", sensorId); return ENABLE_SENSOR_ERR; @@ -256,13 +264,17 @@ int32_t SensorHdiConnection::EnableSensor(int32_t sensorId) int32_t SensorHdiConnection::DisableSensor(int32_t sensorId) { +#ifdef HIVIEWDFX_HITRACE_ENABLE StartTrace(HITRACE_TAG_SENSORS, "DisableSensor"); +#endif // HIVIEWDFX_HITRACE_ENABLE int32_t ret = DISABLE_SENSOR_ERR; #ifdef BUILD_VARIANT_ENG if (FindOneInMockSet(sensorId)) { CHKPR(iSensorCompatibleHdiConnection_, DISABLE_SENSOR_ERR); ret = iSensorCompatibleHdiConnection_->DisableSensor(sensorId); +#ifdef HIVIEWDFX_HITRACE_ENABLE FinishTrace(HITRACE_TAG_SENSORS); +#endif // HIVIEWDFX_HITRACE_ENABLE if (ret != ERR_OK) { SEN_HILOGE("Disable sensor failed in compatible, sensorId:%{public}d", sensorId); return DISABLE_SENSOR_ERR; @@ -272,7 +284,9 @@ int32_t SensorHdiConnection::DisableSensor(int32_t sensorId) #endif // BUILD_VARIANT_ENG CHKPR(iSensorHdiConnection_, DISABLE_SENSOR_ERR); ret = iSensorHdiConnection_->DisableSensor(sensorId); +#ifdef HIVIEWDFX_HITRACE_ENABLE FinishTrace(HITRACE_TAG_SENSORS); +#endif // HIVIEWDFX_HITRACE_ENABLE if (ret != ERR_OK) { SEN_HILOGI("Disable sensor failed, sensorId:%{public}d", sensorId); return DISABLE_SENSOR_ERR; @@ -282,13 +296,17 @@ int32_t SensorHdiConnection::DisableSensor(int32_t sensorId) int32_t SensorHdiConnection::SetBatch(int32_t sensorId, int64_t samplingInterval, int64_t reportInterval) { +#ifdef HIVIEWDFX_HITRACE_ENABLE StartTrace(HITRACE_TAG_SENSORS, "SetBatch"); +#endif // HIVIEWDFX_HITRACE_ENABLE int32_t ret = SET_SENSOR_CONFIG_ERR; #ifdef BUILD_VARIANT_ENG if (FindOneInMockSet(sensorId)) { CHKPR(iSensorCompatibleHdiConnection_, SET_SENSOR_CONFIG_ERR); ret = iSensorCompatibleHdiConnection_->SetBatch(sensorId, samplingInterval, reportInterval); +#ifdef HIVIEWDFX_HITRACE_ENABLE FinishTrace(HITRACE_TAG_SENSORS); +#endif // HIVIEWDFX_HITRACE_ENABLE if (ret != ERR_OK) { SEN_HILOGI("Set batch failed in compatible, sensorId:%{public}d", sensorId); return SET_SENSOR_CONFIG_ERR; @@ -298,7 +316,9 @@ int32_t SensorHdiConnection::SetBatch(int32_t sensorId, int64_t samplingInterval #endif // BUILD_VARIANT_ENG CHKPR(iSensorHdiConnection_, SET_SENSOR_CONFIG_ERR); ret = iSensorHdiConnection_->SetBatch(sensorId, samplingInterval, reportInterval); +#ifdef HIVIEWDFX_HITRACE_ENABLE FinishTrace(HITRACE_TAG_SENSORS); +#endif // HIVIEWDFX_HITRACE_ENABLE if (ret != ERR_OK) { SEN_HILOGI("Set batch failed, sensorId:%{public}d", sensorId); return SET_SENSOR_CONFIG_ERR; @@ -308,13 +328,17 @@ int32_t SensorHdiConnection::SetBatch(int32_t sensorId, int64_t samplingInterval int32_t SensorHdiConnection::SetMode(int32_t sensorId, int32_t mode) { +#ifdef HIVIEWDFX_HITRACE_ENABLE StartTrace(HITRACE_TAG_SENSORS, "SetMode"); +#endif // HIVIEWDFX_HITRACE_ENABLE int32_t ret = SET_SENSOR_MODE_ERR; #ifdef BUILD_VARIANT_ENG if (FindOneInMockSet(sensorId)) { CHKPR(iSensorCompatibleHdiConnection_, SET_SENSOR_MODE_ERR); ret = iSensorCompatibleHdiConnection_->SetMode(sensorId, mode); +#ifdef HIVIEWDFX_HITRACE_ENABLE FinishTrace(HITRACE_TAG_SENSORS); +#endif // HIVIEWDFX_HITRACE_ENABLE if (ret != ERR_OK) { SEN_HILOGI("Set mode failed, sensorId:%{public}d", sensorId); return SET_SENSOR_MODE_ERR; @@ -324,7 +348,9 @@ int32_t SensorHdiConnection::SetMode(int32_t sensorId, int32_t mode) #endif // BUILD_VARIANT_ENG CHKPR(iSensorHdiConnection_, SET_SENSOR_MODE_ERR); ret = iSensorHdiConnection_->SetMode(sensorId, mode); +#ifdef HIVIEWDFX_HITRACE_ENABLE FinishTrace(HITRACE_TAG_SENSORS); +#endif // HIVIEWDFX_HITRACE_ENABLE if (ret != ERR_OK) { SEN_HILOGI("Set mode failed, sensorId:%{public}d", sensorId); return SET_SENSOR_MODE_ERR; @@ -334,7 +360,9 @@ int32_t SensorHdiConnection::SetMode(int32_t sensorId, int32_t mode) int32_t SensorHdiConnection::RegisterDataReport(ReportDataCb cb, sptr reportDataCallback) { +#ifdef HIVIEWDFX_HITRACE_ENABLE StartTrace(HITRACE_TAG_SENSORS, "RegisterDataReport"); +#endif // HIVIEWDFX_HITRACE_ENABLE CHKPR(iSensorHdiConnection_, REGIST_CALLBACK_ERR); int32_t ret = iSensorHdiConnection_->RegisterDataReport(cb, reportDataCallback); if (ret != ERR_OK) { @@ -350,7 +378,9 @@ int32_t SensorHdiConnection::RegisterDataReport(ReportDataCb cb, sptr #include +#ifdef HIVIEWDFX_HISYSEVENT_ENABLE #include "hisysevent.h" +#endif // HIVIEWDFX_HISYSEVENT_ENABLE #include "permission_util.h" #include "securec.h" #include "sensor_basic_data_channel.h" @@ -274,9 +276,8 @@ int32_t SensorDataProcesser::ProcessEvents(sptr dataCallback int32_t eventNum = eventsBuf.eventNum; for (int32_t i = 0; i < eventNum; i++) { EventFilter(eventsBuf); - eventsBuf.readPos++; - if (eventsBuf.readPos == CIRCULAR_BUF_LEN) { + if (eventsBuf.readPos >= CIRCULAR_BUF_LEN) { eventsBuf.readPos = 0; } eventsBuf.eventNum--; diff --git a/services/src/sensor_dump.cpp b/services/src/sensor_dump.cpp index 93950201242d7c6171f7f3fcbc5f6b867598422e..767222bb5b8aaf73f4a3eb03642a0dfa83a40e4b 100644 --- a/services/src/sensor_dump.cpp +++ b/services/src/sensor_dump.cpp @@ -332,7 +332,7 @@ std::string SensorDump::GetDataBySensorId(int32_t sensorId, SensorData &sensorDa std::string str; int32_t dataLen = GetDataDimension(sensorId); if (sensorData.dataLen < sizeof(float)) { - SEN_HILOGE("SensorData dataLen less than float size."); + SEN_HILOGE("SensorData dataLen less than float size"); return str; } auto data = reinterpret_cast(sensorData.data); diff --git a/services/src/sensor_service.cpp b/services/src/sensor_service.cpp index eef9a2f37e133c116e5b7e2fdeb20aa22a8193f0..155c4e12bd621651f005c31d604c9d683b10ac77 100644 --- a/services/src/sensor_service.cpp +++ b/services/src/sensor_service.cpp @@ -20,13 +20,16 @@ #include #include +#ifdef HIVIEWDFX_HISYSEVENT_ENABLE #include "hisysevent.h" +#endif // HIVIEWDFX_HISYSEVENT_ENABLE #include "iservice_registry.h" #ifdef MEMMGR_ENABLE #include "mem_mgr_client.h" #endif // MEMMGR_ENABLE #include "permission_util.h" +#include "print_sensor_data.h" #include "securec.h" #include "sensor.h" #include "sensor_dump.h" @@ -184,15 +187,21 @@ void SensorService::ReportSensorSysEvent(int32_t sensorId, bool enable, int32_t std::string packageName(""); AccessTokenID tokenId = clientInfo_.GetTokenIdByPid(pid); sensorManager_.GetPackageName(tokenId, packageName); +#ifdef HIVIEWDFX_HISYSEVENT_ENABLE const int logLevel = 4; int32_t uid = clientInfo_.GetUidByPid(pid); +#endif // HIVIEWDFX_HISYSEVENT_ENABLE if (enable) { +#ifdef HIVIEWDFX_HISYSEVENT_ENABLE HiSysEventWrite(HiSysEvent::Domain::SENSOR, "ENABLE_SENSOR", HiSysEvent::EventType::STATISTIC, "LEVEL", logLevel, "UID", uid, "PKG_NAME", packageName, "TYPE", sensorId); +#endif // HIVIEWDFX_HISYSEVENT_ENABLE SEN_HILOGI("PackageName:%{public}s open the sensor, sensorId:%{public}d", packageName.c_str(), sensorId); } else { +#ifdef HIVIEWDFX_HISYSEVENT_ENABLE HiSysEventWrite(HiSysEvent::Domain::SENSOR, "DISABLE_SENSOR", HiSysEvent::EventType::STATISTIC, "LEVEL", logLevel, "UID", uid, "PKG_NAME", packageName, "TYPE", sensorId); +#endif // HIVIEWDFX_HISYSEVENT_ENABLE SEN_HILOGI("PackageName:%{public}s close the sensor, sensorId:%{public}d", packageName.c_str(), sensorId); } } @@ -254,12 +263,21 @@ bool SensorService::CheckSensorId(int32_t sensorId) return true; } -ErrCode SensorService::EnableSensor(int32_t sensorId, int64_t samplingPeriodNs, int64_t maxReportDelayNs) +bool SensorService::CheckParameter(int32_t sensorId, int64_t samplingPeriodNs, int64_t maxReportDelayNs) { - CALL_LOG_ENTER; if ((!CheckSensorId(sensorId)) || ((samplingPeriodNs != 0L) && ((maxReportDelayNs / samplingPeriodNs) > MAX_EVENT_COUNT))) { SEN_HILOGE("sensorId is invalid or maxReportDelayNs exceeded the maximum value"); + return false; + } + return true; +} + +ErrCode SensorService::EnableSensor(int32_t sensorId, int64_t samplingPeriodNs, int64_t maxReportDelayNs) +{ + CALL_LOG_ENTER; + if (!CheckParameter(sensorId, samplingPeriodNs, maxReportDelayNs)) { + SEN_HILOGE("sensorId, samplingPeriodNs or maxReportDelayNs is invalid"); return ERR_NO_INIT; } int32_t pid = GetCallingPid(); @@ -279,6 +297,7 @@ ErrCode SensorService::EnableSensor(int32_t sensorId, int64_t samplingPeriodNs, if (isReportActiveInfo_) { ReportActiveInfo(sensorId, pid); } + PrintSensorData::GetInstance().ResetHdiCounter(sensorId); return ERR_OK; } auto ret = SaveSubscriber(sensorId, samplingPeriodNs, maxReportDelayNs); @@ -302,6 +321,7 @@ ErrCode SensorService::EnableSensor(int32_t sensorId, int64_t samplingPeriodNs, if (isReportActiveInfo_) { ReportActiveInfo(sensorId, pid); } + PrintSensorData::GetInstance().ResetHdiCounter(sensorId); return ret; } diff --git a/services/src/sensor_service_stub.cpp b/services/src/sensor_service_stub.cpp index 8d07287ad15624d98f99f4c20fbf0a7568bbeaa2..3d08b091b91743a795fe1c39e9880b5af1325fa2 100644 --- a/services/src/sensor_service_stub.cpp +++ b/services/src/sensor_service_stub.cpp @@ -22,7 +22,9 @@ #include #include "accesstoken_kit.h" +#ifdef HIVIEWDFX_HISYSEVENT_ENABLE #include "hisysevent.h" +#endif // HIVIEWDFX_HISYSEVENT_ENABLE #include "ipc_skeleton.h" #include "message_parcel.h" #include "permission_util.h" @@ -136,8 +138,10 @@ ErrCode SensorServiceStub::SensorEnableInner(MessageParcel &data, MessageParcel PermissionUtil &permissionUtil = PermissionUtil::GetInstance(); int32_t ret = permissionUtil.CheckSensorPermission(GetCallingTokenID(), sensorId); if (ret != PERMISSION_GRANTED) { +#ifdef HIVIEWDFX_HISYSEVENT_ENABLE HiSysEventWrite(HiSysEvent::Domain::SENSOR, "VERIFY_ACCESS_TOKEN_FAIL", HiSysEvent::EventType::SECURITY, "PKG_NAME", "SensorEnableInner", "ERROR_CODE", ret); +#endif // HIVIEWDFX_HISYSEVENT_ENABLE SEN_HILOGE("sensorId:%{public}d grant failed, result:%{public}d", sensorId, ret); return PERMISSION_DENIED; } @@ -160,8 +164,10 @@ ErrCode SensorServiceStub::SensorDisableInner(MessageParcel &data, MessageParcel PermissionUtil &permissionUtil = PermissionUtil::GetInstance(); int32_t ret = permissionUtil.CheckSensorPermission(GetCallingTokenID(), sensorId); if (ret != PERMISSION_GRANTED) { +#ifdef HIVIEWDFX_HISYSEVENT_ENABLE HiSysEventWrite(HiSysEvent::Domain::SENSOR, "VERIFY_ACCESS_TOKEN_FAIL", HiSysEvent::EventType::SECURITY, "PKG_NAME", "SensorDisableInner", "ERROR_CODE", ret); +#endif // HIVIEWDFX_HISYSEVENT_ENABLE SEN_HILOGE("sensorId:%{public}d grant failed, result:%{public}d", sensorId, ret); return PERMISSION_DENIED; } diff --git a/test/fuzztest/interfaces/sensoragent_fuzzer/BUILD.gn b/test/fuzztest/interfaces/sensoragent_fuzzer/BUILD.gn index c379e57756a2e37056481579c152ca5b2bdb37b7..2528534f1e256cecda7c72c1bfebe273a0dd2241 100644 --- a/test/fuzztest/interfaces/sensoragent_fuzzer/BUILD.gn +++ b/test/fuzztest/interfaces/sensoragent_fuzzer/BUILD.gn @@ -26,7 +26,6 @@ ohos_fuzztest("SensorAgentFuzzTest") { "$SUBSYSTEM_DIR/interfaces/inner_api", "$SUBSYSTEM_DIR/frameworks/native/include", "$SUBSYSTEM_DIR/test/fuzztest/interfaces/sensoragent_fuzzer", - "$SUBSYSTEM_DIR/utils/common/include", ] cflags = [ @@ -40,13 +39,7 @@ ohos_fuzztest("SensorAgentFuzzTest") { deps = [ "$SUBSYSTEM_DIR/frameworks/native:sensor_interface_native" ] - external_deps = [ - "access_token:libaccesstoken_sdk", - "access_token:libnativetoken", - "access_token:libtoken_setproc", - "c_utils:utils", - "hilog:libhilog", - ] + external_deps = [ "c_utils:utils" ] } group("fuzztest") { diff --git a/test/fuzztest/interfaces/sensoragent_fuzzer/sensoragent_fuzzer.cpp b/test/fuzztest/interfaces/sensoragent_fuzzer/sensoragent_fuzzer.cpp index a73005845215847f705fd672dccaa33383dde8c5..675e90b5f5838421f88d608d7f02e92282e0e124 100644 --- a/test/fuzztest/interfaces/sensoragent_fuzzer/sensoragent_fuzzer.cpp +++ b/test/fuzztest/interfaces/sensoragent_fuzzer/sensoragent_fuzzer.cpp @@ -15,61 +15,10 @@ #include "sensoragent_fuzzer.h" -#include -#include - -#include "accesstoken_kit.h" -#include "token_setproc.h" -#include "nativetoken_kit.h" -#include "securec.h" - #include "sensor_agent.h" #include "sensor_agent_type.h" -#include "sensor_errors.h" - -using namespace OHOS::HiviewDFX; -using namespace OHOS::Security::AccessToken; -using OHOS::Security::AccessToken::AccessTokenID; -namespace { -constexpr int64_t g_samplingInterval = 200000000; -constexpr int64_t g_reportInterval = 200000000; -} // namespace - -template -size_t GetObject(T &object, const uint8_t *data, size_t size) -{ - size_t objectSize = sizeof(object); - if (objectSize > size) { - return 0; - } - errno_t ret = memcpy_s(&object, objectSize, data, objectSize); - if (ret != EOK) { - return 0; - } - return objectSize; -} - -void SetUpTestCase() -{ - const char **perms = new (std::nothrow) const char *[2]; - CHKPV(perms); - perms[0] = "ohos.permission.ACCELEROMETER"; - perms[1] = "ohos.permission.MANAGE_SENSOR"; - TokenInfoParams infoInstance = { - .dcapsNum = 0, - .permsNum = 2, - .aclsNum = 0, - .dcaps = nullptr, - .perms = perms, - .acls = nullptr, - .processName = "SensorAgentFuzzTest", - .aplStr = "system_core", - }; - uint64_t tokenId = GetAccessTokenId(&infoInstance); - SetSelfTokenID(tokenId); - AccessTokenKit::ReloadNativeTokenInfo(); - delete[] perms; -} +#include +#include void SensorDataCallbackImpl(SensorEvent *event) { @@ -94,24 +43,34 @@ bool CheckSensorTypeId(int32_t sensorTypeId) return false; } -void SensorAgentFuzzTest(const uint8_t *data, size_t size) +bool SensorAgentFuzzTest(const uint8_t *data, size_t size) { - SetUpTestCase(); - size_t startPos = 0; - int32_t sensorTypeId = 0; - GetObject(sensorTypeId, data + startPos, size - startPos); + intptr_t sensorTypeId = reinterpret_cast(data); bool validSensorId = CheckSensorTypeId(sensorTypeId); - if (!validSensorId) { - sensorTypeId = SENSOR_TYPE_ID_ACCELEROMETER; - } SensorUser user; user.callback = SensorDataCallbackImpl; - SubscribeSensor(sensorTypeId, &user); - SetBatch(sensorTypeId, &user, g_samplingInterval, g_reportInterval); - ActivateSensor(sensorTypeId, &user); + int32_t ret = SubscribeSensor(sensorTypeId, &user); + if (ret != 0) { + return validSensorId ? false : true; + } + ret = SetBatch(sensorTypeId, &user, 200000000, 0); + if (ret != 0) { + return validSensorId ? false : true; + } + ret = ActivateSensor(sensorTypeId, &user); + if (ret != 0) { + return validSensorId ? false : true; + } std::this_thread::sleep_for(std::chrono::milliseconds(1000)); - DeactivateSensor(sensorTypeId, &user); - UnsubscribeSensor(sensorTypeId, &user); + ret = DeactivateSensor(sensorTypeId, &user); + if (ret != 0) { + return validSensorId ? false : true; + } + ret = UnsubscribeSensor(sensorTypeId, &user); + if (ret != 0) { + return validSensorId ? false : true; + } + return true; } extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) diff --git a/test/fuzztest/services/BUILD.gn b/test/fuzztest/services/BUILD.gn index c15f56612c0cab4322e63f7acfcac2b2024bb3e0..6632a988c1f2eeb1ca081d39119aa316002fd17a 100644 --- a/test/fuzztest/services/BUILD.gn +++ b/test/fuzztest/services/BUILD.gn @@ -31,17 +31,6 @@ group("fuzztest") { "sensordisablestub_fuzzer:fuzztest", "sensorenablestub_fuzzer:fuzztest", "sensoronremoterequest_fuzzer:fuzztest", - "service/createsocketchannel_fuzzer:fuzztest", - "service/destroysensorchannel_fuzzer:fuzztest", - "service/getactiveinfolist_fuzzer:fuzztest", - "service/onstart_fuzzer:fuzztest", - "service/processdeathobserver_fuzzer:fuzztest", - "service/registerclientdeathrecipient_fuzzer:fuzztest", - "service/registerpermcallback_fuzzer:fuzztest", - "service/reportactiveinfo_fuzzer:fuzztest", - "service/reportonchangedata_fuzzer:fuzztest", - "service/reportsensorsysevent_fuzzer:fuzztest", - "service/transferdatachannel_fuzzer:fuzztest", "suspendsensorsstub_fuzzer:fuzztest", ] } diff --git a/test/fuzztest/services/createdatachannelstub_fuzzer/createdatachannelstub_fuzzer.cpp b/test/fuzztest/services/createdatachannelstub_fuzzer/createdatachannelstub_fuzzer.cpp index 84d56fa1a4216f7198ebafd69986cc0a5eb65c40..f3f85d1b27041dfd8fc9d0785cb5ae1d44037e6d 100644 --- a/test/fuzztest/services/createdatachannelstub_fuzzer/createdatachannelstub_fuzzer.cpp +++ b/test/fuzztest/services/createdatachannelstub_fuzzer/createdatachannelstub_fuzzer.cpp @@ -78,8 +78,8 @@ bool OnRemoteRequestFuzzTest(const uint8_t *data, size_t size) datas, reply, option); return true; } -} // namespace Sensors -} // namespace OHOS +} // namespace Sensors +} // namespace OHOS extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { diff --git a/test/fuzztest/services/createsocketchannelstub_fuzzer/createsocketchannelstub_fuzzer.cpp b/test/fuzztest/services/createsocketchannelstub_fuzzer/createsocketchannelstub_fuzzer.cpp index 456696b99965917410652338e506681505cd7fce..597178347b4edba67d4fff4d5e66ac594a48b16e 100644 --- a/test/fuzztest/services/createsocketchannelstub_fuzzer/createsocketchannelstub_fuzzer.cpp +++ b/test/fuzztest/services/createsocketchannelstub_fuzzer/createsocketchannelstub_fuzzer.cpp @@ -78,8 +78,8 @@ bool OnRemoteRequestFuzzTest(const uint8_t *data, size_t size) datas, reply, option); return true; } -} // namespace Sensors -} // namespace OHOS +} // namespace Sensors +} // namespace OHOS extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { diff --git a/test/fuzztest/services/destroydatachannelstub_fuzzer/destroydatachannelstub_fuzzer.cpp b/test/fuzztest/services/destroydatachannelstub_fuzzer/destroydatachannelstub_fuzzer.cpp index 08ec574003fee91fdc95893fa1917e83e0a2f980..48284574661581782c1ac4c067e4a9ee93532928 100644 --- a/test/fuzztest/services/destroydatachannelstub_fuzzer/destroydatachannelstub_fuzzer.cpp +++ b/test/fuzztest/services/destroydatachannelstub_fuzzer/destroydatachannelstub_fuzzer.cpp @@ -78,8 +78,8 @@ bool OnRemoteRequestFuzzTest(const uint8_t *data, size_t size) datas, reply, option); return true; } -} // namespace Sensors -} // namespace OHOS +} // namespace Sensors +} // namespace OHOS extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { diff --git a/test/fuzztest/services/destroysocketchannelstub_fuzzer/destroysocketchannelstub_fuzzer.cpp b/test/fuzztest/services/destroysocketchannelstub_fuzzer/destroysocketchannelstub_fuzzer.cpp index 004f97456a8bd67ea80f348378534f10baf2a498..92d437548c2df79d01e65b524100fd62530f07b3 100644 --- a/test/fuzztest/services/destroysocketchannelstub_fuzzer/destroysocketchannelstub_fuzzer.cpp +++ b/test/fuzztest/services/destroysocketchannelstub_fuzzer/destroysocketchannelstub_fuzzer.cpp @@ -78,8 +78,8 @@ bool OnRemoteRequestFuzzTest(const uint8_t *data, size_t size) datas, reply, option); return true; } -} // namespace Sensors -} // namespace OHOS +} // namespace Sensors +} // namespace OHOS extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { diff --git a/test/fuzztest/services/disableactiveinfocbstub_fuzzer/disableactiveinfocbstub_fuzzer.cpp b/test/fuzztest/services/disableactiveinfocbstub_fuzzer/disableactiveinfocbstub_fuzzer.cpp index c5510dddd512055711e0c3db63e8cd49f548253b..21dc7572b0bb5c9fd8c62f959999273a1ffea509 100644 --- a/test/fuzztest/services/disableactiveinfocbstub_fuzzer/disableactiveinfocbstub_fuzzer.cpp +++ b/test/fuzztest/services/disableactiveinfocbstub_fuzzer/disableactiveinfocbstub_fuzzer.cpp @@ -74,8 +74,8 @@ bool OnRemoteRequestFuzzTest(const uint8_t *data, size_t size) datas, reply, option); return true; } -} // namespace Sensors -} // namespace OHOS +} // namespace Sensors +} // namespace OHOS extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { diff --git a/test/fuzztest/services/enableactiveinfocbstub_fuzzer/enableactiveinfocbstub_fuzzer.cpp b/test/fuzztest/services/enableactiveinfocbstub_fuzzer/enableactiveinfocbstub_fuzzer.cpp index 89920778b58b1a6d16c9b745f327004ea6d2a456..a99b9e13bdc7ca83f308ec0e92f61dcd79e96e51 100644 --- a/test/fuzztest/services/enableactiveinfocbstub_fuzzer/enableactiveinfocbstub_fuzzer.cpp +++ b/test/fuzztest/services/enableactiveinfocbstub_fuzzer/enableactiveinfocbstub_fuzzer.cpp @@ -74,8 +74,8 @@ bool OnRemoteRequestFuzzTest(const uint8_t *data, size_t size) datas, reply, option); return true; } -} // namespace Sensors -} // namespace OHOS +} // namespace Sensors +} // namespace OHOS extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { diff --git a/test/fuzztest/services/getactiveinfoliststub_fuzzer/getactiveinfoliststub_fuzzer.cpp b/test/fuzztest/services/getactiveinfoliststub_fuzzer/getactiveinfoliststub_fuzzer.cpp index 3f46761baa23cdfc6936d4b7d1e9bbfe8316599b..c31efbb1a9350faa0eeff6995a668e54bc216dd5 100644 --- a/test/fuzztest/services/getactiveinfoliststub_fuzzer/getactiveinfoliststub_fuzzer.cpp +++ b/test/fuzztest/services/getactiveinfoliststub_fuzzer/getactiveinfoliststub_fuzzer.cpp @@ -74,8 +74,8 @@ bool OnRemoteRequestFuzzTest(const uint8_t *data, size_t size) datas, reply, option); return true; } -} // namespace Sensors -} // namespace OHOS +} // namespace Sensors +} // namespace OHOS extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { diff --git a/test/fuzztest/services/getallsensorsstub_fuzzer/getallsensorsstub_fuzzer.cpp b/test/fuzztest/services/getallsensorsstub_fuzzer/getallsensorsstub_fuzzer.cpp index 9e1c8f2c79a527ee369ac4f0165653e1263ede5d..ef06d085a28ddbd3ba9c2792806be1dc17bc2c69 100644 --- a/test/fuzztest/services/getallsensorsstub_fuzzer/getallsensorsstub_fuzzer.cpp +++ b/test/fuzztest/services/getallsensorsstub_fuzzer/getallsensorsstub_fuzzer.cpp @@ -74,8 +74,8 @@ bool OnRemoteRequestFuzzTest(const uint8_t *data, size_t size) datas, reply, option); return true; } -} // namespace Sensors -} // namespace OHOS +} // namespace Sensors +} // namespace OHOS extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { diff --git a/test/fuzztest/services/resetsensorsstub_fuzzer/resetsensorsstub_fuzzer.cpp b/test/fuzztest/services/resetsensorsstub_fuzzer/resetsensorsstub_fuzzer.cpp index f17d2dfefa7a137c951f822e33cb4974d850008e..414206330f0bb0e84656224aa2bd956d7689dcfb 100644 --- a/test/fuzztest/services/resetsensorsstub_fuzzer/resetsensorsstub_fuzzer.cpp +++ b/test/fuzztest/services/resetsensorsstub_fuzzer/resetsensorsstub_fuzzer.cpp @@ -74,8 +74,8 @@ bool OnRemoteRequestFuzzTest(const uint8_t *data, size_t size) datas, reply, option); return true; } -} // namespace Sensors -} // namespace OHOS +} // namespace Sensors +} // namespace OHOS extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { diff --git a/test/fuzztest/services/resumesensorsstub_fuzzer/resumesensorsstub_fuzzer.cpp b/test/fuzztest/services/resumesensorsstub_fuzzer/resumesensorsstub_fuzzer.cpp index d3ad29686c674358a2fae2aba3916a5133e962dc..91c67ddb547dd56350d2dd1f0fbf9082bf8da37b 100644 --- a/test/fuzztest/services/resumesensorsstub_fuzzer/resumesensorsstub_fuzzer.cpp +++ b/test/fuzztest/services/resumesensorsstub_fuzzer/resumesensorsstub_fuzzer.cpp @@ -74,8 +74,8 @@ bool OnRemoteRequestFuzzTest(const uint8_t *data, size_t size) datas, reply, option); return true; } -} // namespace Sensors -} // namespace OHOS +} // namespace Sensors +} // namespace OHOS extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { diff --git a/test/fuzztest/services/sensordisablestub_fuzzer/sensordisablestub_fuzzer.cpp b/test/fuzztest/services/sensordisablestub_fuzzer/sensordisablestub_fuzzer.cpp index 26ec958d5662c6b229420de1867a3d263371a981..f5ca6e0d55116238d4d51f3f3a029b872a3b68d5 100644 --- a/test/fuzztest/services/sensordisablestub_fuzzer/sensordisablestub_fuzzer.cpp +++ b/test/fuzztest/services/sensordisablestub_fuzzer/sensordisablestub_fuzzer.cpp @@ -90,8 +90,8 @@ bool OnRemoteRequestFuzzTest(const uint8_t *data, size_t size) datas, reply, option); return true; } -} // namespace Sensors -} // namespace OHOS +} // namespace Sensors +} // namespace OHOS extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { diff --git a/test/fuzztest/services/sensoronremoterequest_fuzzer/sensoronremoterequest_fuzzer.cpp b/test/fuzztest/services/sensoronremoterequest_fuzzer/sensoronremoterequest_fuzzer.cpp index 81224c1c827b0f8cbb47b5197a6a6329d1808b59..1c0a01efa21498e74d44da4a402ec41e9b8090ff 100644 --- a/test/fuzztest/services/sensoronremoterequest_fuzzer/sensoronremoterequest_fuzzer.cpp +++ b/test/fuzztest/services/sensoronremoterequest_fuzzer/sensoronremoterequest_fuzzer.cpp @@ -81,8 +81,8 @@ bool OnRemoteRequestFuzzTest(const uint8_t *data, size_t size) g_service->OnRemoteRequest(code, datas, reply, option); return true; } -} // namespace Sensors -} // namespace OHOS +} // namespace Sensors +} // namespace OHOS extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) { diff --git a/test/fuzztest/services/service/createsocketchannel_fuzzer/BUILD.gn b/test/fuzztest/services/service/createsocketchannel_fuzzer/BUILD.gn deleted file mode 100644 index 26378f39c0bef12451c1310f573ae03e23226e71..0000000000000000000000000000000000000000 --- a/test/fuzztest/services/service/createsocketchannel_fuzzer/BUILD.gn +++ /dev/null @@ -1,74 +0,0 @@ -# Copyright (c) 2024 Huawei Device Co., Ltd. -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -import("//build/config/features.gni") -import("//build/ohos.gni") -import("//build/test.gni") -import("./../../../../../sensor.gni") - -ohos_fuzztest("CreateSocketChannelFuzzTest") { - module_out_path = FUZZ_MODULE_OUT_PATH - - fuzz_config_file = - "$SUBSYSTEM_DIR/test/fuzztest/services/service/createsocketchannel_fuzzer" - - include_dirs = [ - "$SUBSYSTEM_DIR/frameworks/native/include", - "$SUBSYSTEM_DIR/interfaces/inner_api", - "$SUBSYSTEM_DIR/services/hdi_connection/interface/include", - "$SUBSYSTEM_DIR/services/hdi_connection/adapter/include", - "$SUBSYSTEM_DIR/services/hdi_connection/hardware/include", - "$SUBSYSTEM_DIR/services/include", - "$SUBSYSTEM_DIR/test/fuzztest/services/service/createsocketchannel_fuzzer", - "$SUBSYSTEM_DIR/utils/common/include", - "$SUBSYSTEM_DIR/utils/ipc/include", - ] - - cflags = [ - "-g", - "-O0", - "-Wno-unused-variable", - "-fno-omit-frame-pointer", - "-Dprivate=public", - "-Dprotected=public", - ] - - sources = [ "createsocketchannel_fuzzer.cpp" ] - - defines = sensor_default_defines - - deps = [ - "$SUBSYSTEM_DIR/frameworks/native:sensor_interface_native", - "$SUBSYSTEM_DIR/services:libsensor_service_static", - "$SUBSYSTEM_DIR/utils/common:libsensor_utils", - "$SUBSYSTEM_DIR/utils/ipc:libsensor_ipc", - ] - - external_deps = [ - "access_token:libaccesstoken_sdk", - "access_token:libnativetoken", - "access_token:libtoken_setproc", - "c_utils:utils", - "hilog:libhilog", - "ipc:ipc_single", - "samgr:samgr_proxy", - ] -} - -group("fuzztest") { - testonly = true - deps = [ - # deps file - ":CreateSocketChannelFuzzTest", - ] -} diff --git a/test/fuzztest/services/service/createsocketchannel_fuzzer/corpus/init b/test/fuzztest/services/service/createsocketchannel_fuzzer/corpus/init deleted file mode 100644 index e7c3fecd8d4d4816e40088113a2316bb9eb2e13f..0000000000000000000000000000000000000000 --- a/test/fuzztest/services/service/createsocketchannel_fuzzer/corpus/init +++ /dev/null @@ -1,14 +0,0 @@ -# Copyright (c) 2024 Huawei Device Co., Ltd. -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -FUZZ \ No newline at end of file diff --git a/test/fuzztest/services/service/createsocketchannel_fuzzer/createsocketchannel_fuzzer.cpp b/test/fuzztest/services/service/createsocketchannel_fuzzer/createsocketchannel_fuzzer.cpp deleted file mode 100644 index 06141b7ca9c3052a019c164e6a40dc0f1a5d000e..0000000000000000000000000000000000000000 --- a/test/fuzztest/services/service/createsocketchannel_fuzzer/createsocketchannel_fuzzer.cpp +++ /dev/null @@ -1,106 +0,0 @@ -/* - * Copyright (c) 2024 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "createsocketchannel_fuzzer.h" - -#include -#include - -#include "accesstoken_kit.h" -#include "message_parcel.h" -#include "nativetoken_kit.h" -#include "securec.h" -#include "token_setproc.h" - -#include "sensor.h" -#include "sensor_service.h" - -namespace OHOS { -namespace Sensors { -using namespace Security::AccessToken; -using Security::AccessToken::AccessTokenID; -namespace { -constexpr size_t U32_AT_SIZE = 4; -auto g_service = SensorDelayedSpSingleton::GetInstance(); -static sptr g_remote = new (std::nothrow) IPCObjectStub(); -} // namespace - -template -size_t GetObject(T &object, const uint8_t *data, size_t size) -{ - size_t objectSize = sizeof(object); - if (objectSize > size) { - return 0; - } - errno_t ret = memcpy_s(&object, objectSize, data, objectSize); - if (ret != EOK) { - return 0; - } - return objectSize; -} - -void SetUpTestCase() -{ - const char **perms = new (std::nothrow) const char *[2]; - if (perms == nullptr) { - return; - } - perms[0] = "ohos.permission.ACCELEROMETER"; - perms[1] = "ohos.permission.MANAGE_SENSOR"; - TokenInfoParams infoInstance = { - .dcapsNum = 0, - .permsNum = 2, - .aclsNum = 0, - .dcaps = nullptr, - .perms = perms, - .acls = nullptr, - .processName = "CreateDataChannelStubFuzzTest", - .aplStr = "system_core", - }; - uint64_t tokenId = GetAccessTokenId(&infoInstance); - SetSelfTokenID(tokenId); - AccessTokenKit::ReloadNativeTokenInfo(); - delete[] perms; -} - -bool CreateSocketChannelFuzzTest(const uint8_t *data, size_t size) -{ - SetUpTestCase(); - if (g_remote == nullptr) { - return false; - } - int32_t clientFd = 0; - GetObject(clientFd, data, size); - g_service->CreateSocketChannel(g_remote, clientFd); - return true; -} -} // namespace Sensors -} // namespace OHOS - -extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) -{ - /* Run your code on data */ - if (data == nullptr) { - return 0; - } - - /* Validate the length of size */ - if (size < OHOS::Sensors::U32_AT_SIZE) { - return 0; - } - - OHOS::Sensors::CreateSocketChannelFuzzTest(data, size); - return 0; -} diff --git a/test/fuzztest/services/service/createsocketchannel_fuzzer/createsocketchannel_fuzzer.h b/test/fuzztest/services/service/createsocketchannel_fuzzer/createsocketchannel_fuzzer.h deleted file mode 100644 index 98a294f5076275a6ae7f5b30cd007455c1dfa608..0000000000000000000000000000000000000000 --- a/test/fuzztest/services/service/createsocketchannel_fuzzer/createsocketchannel_fuzzer.h +++ /dev/null @@ -1,22 +0,0 @@ -/* - * Copyright (c) 2024 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef CREATE_SOCKET_CHANNEL_FUZZER_H -#define CREATE_SOCKET_CHANNEL_FUZZER_H - -#define FUZZ_PROJECT_NAME "createsocketchannel_fuzzer" - -#endif // CREATE_SOCKET_CHANNEL_FUZZER_H - diff --git a/test/fuzztest/services/service/createsocketchannel_fuzzer/project.xml b/test/fuzztest/services/service/createsocketchannel_fuzzer/project.xml deleted file mode 100644 index 98df56fb99ddaa5389540f43cd547cbfe959f54d..0000000000000000000000000000000000000000 --- a/test/fuzztest/services/service/createsocketchannel_fuzzer/project.xml +++ /dev/null @@ -1,25 +0,0 @@ - - - - - - 1000 - - 120 - - 2048 - - diff --git a/test/fuzztest/services/service/destroysensorchannel_fuzzer/BUILD.gn b/test/fuzztest/services/service/destroysensorchannel_fuzzer/BUILD.gn deleted file mode 100644 index 11f710e7ce430ae16eddbcaf1377ca7b0e22df7a..0000000000000000000000000000000000000000 --- a/test/fuzztest/services/service/destroysensorchannel_fuzzer/BUILD.gn +++ /dev/null @@ -1,73 +0,0 @@ -# Copyright (c) 2024 Huawei Device Co., Ltd. -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -import("//build/config/features.gni") -import("//build/ohos.gni") -import("//build/test.gni") -import("./../../../../../sensor.gni") - -ohos_fuzztest("DestroySensorChannelFuzzTest") { - module_out_path = FUZZ_MODULE_OUT_PATH - - fuzz_config_file = "$SUBSYSTEM_DIR/test/fuzztest/services/service/destroysensorchannel_fuzzer" - - include_dirs = [ - "$SUBSYSTEM_DIR/frameworks/native/include", - "$SUBSYSTEM_DIR/interfaces/inner_api", - "$SUBSYSTEM_DIR/services/hdi_connection/interface/include", - "$SUBSYSTEM_DIR/services/hdi_connection/adapter/include", - "$SUBSYSTEM_DIR/services/hdi_connection/hardware/include", - "$SUBSYSTEM_DIR/services/include", - "$SUBSYSTEM_DIR/test/fuzztest/services/service/destroysensorchannel_fuzzer", - "$SUBSYSTEM_DIR/utils/common/include", - "$SUBSYSTEM_DIR/utils/ipc/include", - ] - - cflags = [ - "-g", - "-O0", - "-Wno-unused-variable", - "-fno-omit-frame-pointer", - "-Dprivate=public", - "-Dprotected=public", - ] - - sources = [ "destroysensorchannel_fuzzer.cpp" ] - - defines = sensor_default_defines - - deps = [ - "$SUBSYSTEM_DIR/frameworks/native:sensor_interface_native", - "$SUBSYSTEM_DIR/services:libsensor_service_static", - "$SUBSYSTEM_DIR/utils/common:libsensor_utils", - "$SUBSYSTEM_DIR/utils/ipc:libsensor_ipc", - ] - - external_deps = [ - "access_token:libaccesstoken_sdk", - "access_token:libnativetoken", - "access_token:libtoken_setproc", - "c_utils:utils", - "hilog:libhilog", - "ipc:ipc_single", - "samgr:samgr_proxy", - ] -} - -group("fuzztest") { - testonly = true - deps = [ - # deps file - ":DestroySensorChannelFuzzTest", - ] -} diff --git a/test/fuzztest/services/service/destroysensorchannel_fuzzer/corpus/init b/test/fuzztest/services/service/destroysensorchannel_fuzzer/corpus/init deleted file mode 100644 index e7c3fecd8d4d4816e40088113a2316bb9eb2e13f..0000000000000000000000000000000000000000 --- a/test/fuzztest/services/service/destroysensorchannel_fuzzer/corpus/init +++ /dev/null @@ -1,14 +0,0 @@ -# Copyright (c) 2024 Huawei Device Co., Ltd. -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -FUZZ \ No newline at end of file diff --git a/test/fuzztest/services/service/destroysensorchannel_fuzzer/destroysensorchannel_fuzzer.cpp b/test/fuzztest/services/service/destroysensorchannel_fuzzer/destroysensorchannel_fuzzer.cpp deleted file mode 100644 index eb0b817d4a2f53b8b7e0c4b30c5083f14d7abbe0..0000000000000000000000000000000000000000 --- a/test/fuzztest/services/service/destroysensorchannel_fuzzer/destroysensorchannel_fuzzer.cpp +++ /dev/null @@ -1,104 +0,0 @@ -/* - * Copyright (c) 2024 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "destroysensorchannel_fuzzer.h" - -#include -#include - -#include "accesstoken_kit.h" -#include "message_parcel.h" -#include "nativetoken_kit.h" -#include "securec.h" -#include "token_setproc.h" - -#include "sensor.h" -#include "sensor_service.h" - -namespace OHOS { -namespace Sensors { -using namespace Security::AccessToken; -using Security::AccessToken::AccessTokenID; -namespace { -constexpr size_t U32_AT_SIZE = 4; -auto g_service = SensorDelayedSpSingleton::GetInstance(); -static sptr g_remote = new (std::nothrow) IPCObjectStub(); -} // namespace - -template -size_t GetObject(T &object, const uint8_t *data, size_t size) -{ - size_t objectSize = sizeof(object); - if (objectSize > size) { - return 0; - } - errno_t ret = memcpy_s(&object, objectSize, data, objectSize); - if (ret != EOK) { - return 0; - } - return objectSize; -} - -void SetUpTestCase() -{ - const char **perms = new (std::nothrow) const char *[2]; - if (perms == nullptr) { - return; - } - perms[0] = "ohos.permission.ACCELEROMETER"; - perms[1] = "ohos.permission.MANAGE_SENSOR"; - TokenInfoParams infoInstance = { - .dcapsNum = 0, - .permsNum = 2, - .aclsNum = 0, - .dcaps = nullptr, - .perms = perms, - .acls = nullptr, - .processName = "CreateDataChannelStubFuzzTest", - .aplStr = "system_core", - }; - uint64_t tokenId = GetAccessTokenId(&infoInstance); - SetSelfTokenID(tokenId); - AccessTokenKit::ReloadNativeTokenInfo(); - delete[] perms; -} - -bool DestroySensorChannelFuzzTest(const uint8_t *data, size_t size) -{ - SetUpTestCase(); - if (g_remote == nullptr) { - return false; - } - g_service->DestroySensorChannel(g_remote); - return true; -} -} // namespace Sensors -} // namespace OHOS - -extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) -{ - /* Run your code on data */ - if (data == nullptr) { - return 0; - } - - /* Validate the length of size */ - if (size < OHOS::Sensors::U32_AT_SIZE) { - return 0; - } - - OHOS::Sensors::DestroySensorChannelFuzzTest(data, size); - return 0; -} diff --git a/test/fuzztest/services/service/destroysensorchannel_fuzzer/destroysensorchannel_fuzzer.h b/test/fuzztest/services/service/destroysensorchannel_fuzzer/destroysensorchannel_fuzzer.h deleted file mode 100644 index 67dc3af37fdf06e139d430f50ece4937698f77cc..0000000000000000000000000000000000000000 --- a/test/fuzztest/services/service/destroysensorchannel_fuzzer/destroysensorchannel_fuzzer.h +++ /dev/null @@ -1,22 +0,0 @@ -/* - * Copyright (c) 2024 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef ON_START_FUZZER_H -#define ON_START_FUZZER_H - -#define FUZZ_PROJECT_NAME "onstart_fuzzer" - -#endif // ON_START_FUZZER_H - diff --git a/test/fuzztest/services/service/destroysensorchannel_fuzzer/project.xml b/test/fuzztest/services/service/destroysensorchannel_fuzzer/project.xml deleted file mode 100644 index 98df56fb99ddaa5389540f43cd547cbfe959f54d..0000000000000000000000000000000000000000 --- a/test/fuzztest/services/service/destroysensorchannel_fuzzer/project.xml +++ /dev/null @@ -1,25 +0,0 @@ - - - - - - 1000 - - 120 - - 2048 - - diff --git a/test/fuzztest/services/service/getactiveinfolist_fuzzer/BUILD.gn b/test/fuzztest/services/service/getactiveinfolist_fuzzer/BUILD.gn deleted file mode 100644 index 46dfb718eab61d01ae66b85549d3839baea4e7e9..0000000000000000000000000000000000000000 --- a/test/fuzztest/services/service/getactiveinfolist_fuzzer/BUILD.gn +++ /dev/null @@ -1,74 +0,0 @@ -# Copyright (c) 2024 Huawei Device Co., Ltd. -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -import("//build/config/features.gni") -import("//build/ohos.gni") -import("//build/test.gni") -import("./../../../../../sensor.gni") - -ohos_fuzztest("GetActiveInfoListFuzzTest") { - module_out_path = FUZZ_MODULE_OUT_PATH - - fuzz_config_file = - "$SUBSYSTEM_DIR/test/fuzztest/services/service/getactiveinfolist_fuzzer" - - include_dirs = [ - "$SUBSYSTEM_DIR/frameworks/native/include", - "$SUBSYSTEM_DIR/interfaces/inner_api", - "$SUBSYSTEM_DIR/services/hdi_connection/interface/include", - "$SUBSYSTEM_DIR/services/hdi_connection/adapter/include", - "$SUBSYSTEM_DIR/services/hdi_connection/hardware/include", - "$SUBSYSTEM_DIR/services/include", - "$SUBSYSTEM_DIR/test/fuzztest/services/service/getactiveinfolist_fuzzer", - "$SUBSYSTEM_DIR/utils/common/include", - "$SUBSYSTEM_DIR/utils/ipc/include", - ] - - cflags = [ - "-g", - "-O0", - "-Wno-unused-variable", - "-fno-omit-frame-pointer", - "-Dprivate=public", - "-Dprotected=public", - ] - - sources = [ "getactiveinfolist_fuzzer.cpp" ] - - defines = sensor_default_defines - - deps = [ - "$SUBSYSTEM_DIR/frameworks/native:sensor_interface_native", - "$SUBSYSTEM_DIR/services:libsensor_service_static", - "$SUBSYSTEM_DIR/utils/common:libsensor_utils", - "$SUBSYSTEM_DIR/utils/ipc:libsensor_ipc", - ] - - external_deps = [ - "access_token:libaccesstoken_sdk", - "access_token:libnativetoken", - "access_token:libtoken_setproc", - "c_utils:utils", - "hilog:libhilog", - "ipc:ipc_single", - "samgr:samgr_proxy", - ] -} - -group("fuzztest") { - testonly = true - deps = [ - # deps file - ":GetActiveInfoListFuzzTest", - ] -} diff --git a/test/fuzztest/services/service/getactiveinfolist_fuzzer/corpus/init b/test/fuzztest/services/service/getactiveinfolist_fuzzer/corpus/init deleted file mode 100644 index e7c3fecd8d4d4816e40088113a2316bb9eb2e13f..0000000000000000000000000000000000000000 --- a/test/fuzztest/services/service/getactiveinfolist_fuzzer/corpus/init +++ /dev/null @@ -1,14 +0,0 @@ -# Copyright (c) 2024 Huawei Device Co., Ltd. -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -FUZZ \ No newline at end of file diff --git a/test/fuzztest/services/service/getactiveinfolist_fuzzer/getactiveinfolist_fuzzer.cpp b/test/fuzztest/services/service/getactiveinfolist_fuzzer/getactiveinfolist_fuzzer.cpp deleted file mode 100644 index 1c07d73cda828cac780701cb70c4cea859625fc9..0000000000000000000000000000000000000000 --- a/test/fuzztest/services/service/getactiveinfolist_fuzzer/getactiveinfolist_fuzzer.cpp +++ /dev/null @@ -1,105 +0,0 @@ -/* - * Copyright (c) 2024 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "getactiveinfolist_fuzzer.h" - -#include -#include - -#include "accesstoken_kit.h" -#include "message_parcel.h" -#include "nativetoken_kit.h" -#include "securec.h" -#include "token_setproc.h" - -#include "sensor.h" -#include "sensor_service.h" - -namespace OHOS { -namespace Sensors { -using namespace Security::AccessToken; -using Security::AccessToken::AccessTokenID; -namespace { -constexpr size_t U32_AT_SIZE = 4; -auto g_service = SensorDelayedSpSingleton::GetInstance(); -} // namespace - -template -size_t GetObject(T &object, const uint8_t *data, size_t size) -{ - size_t objectSize = sizeof(object); - if (objectSize > size) { - return 0; - } - errno_t ret = memcpy_s(&object, objectSize, data, objectSize); - if (ret != EOK) { - return 0; - } - return objectSize; -} - -void SetUpTestCase() -{ - const char **perms = new (std::nothrow) const char *[2]; - if (perms == nullptr) { - return; - } - perms[0] = "ohos.permission.ACCELEROMETER"; - perms[1] = "ohos.permission.MANAGE_SENSOR"; - TokenInfoParams infoInstance = { - .dcapsNum = 0, - .permsNum = 2, - .aclsNum = 0, - .dcaps = nullptr, - .perms = perms, - .acls = nullptr, - .processName = "CreateDataChannelStubFuzzTest", - .aplStr = "system_core", - }; - uint64_t tokenId = GetAccessTokenId(&infoInstance); - SetSelfTokenID(tokenId); - AccessTokenKit::ReloadNativeTokenInfo(); - delete[] perms; -} - -bool GetActiveInfoListFuzzTest(const uint8_t *data, size_t size) -{ - SetUpTestCase(); - std::vector activeInfoList; - int32_t pid = 0; - GetObject(pid, data, size); - g_service->GetActiveInfoList(pid, activeInfoList); - g_service->SuspendSensors(pid); - g_service->ResumeSensors(pid); - return true; -} -} // namespace Sensors -} // namespace OHOS - -extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) -{ - /* Run your code on data */ - if (data == nullptr) { - return 0; - } - - /* Validate the length of size */ - if (size < OHOS::Sensors::U32_AT_SIZE) { - return 0; - } - - OHOS::Sensors::GetActiveInfoListFuzzTest(data, size); - return 0; -} diff --git a/test/fuzztest/services/service/getactiveinfolist_fuzzer/getactiveinfolist_fuzzer.h b/test/fuzztest/services/service/getactiveinfolist_fuzzer/getactiveinfolist_fuzzer.h deleted file mode 100644 index e5b217b275c4f042c960efc5d646cc3dcb60fd70..0000000000000000000000000000000000000000 --- a/test/fuzztest/services/service/getactiveinfolist_fuzzer/getactiveinfolist_fuzzer.h +++ /dev/null @@ -1,22 +0,0 @@ -/* - * Copyright (c) 2024 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef GET_ACTIVE_INFO_LIST_FUZZER_H -#define GET_ACTIVE_INFO_LIST_FUZZER_H - -#define FUZZ_PROJECT_NAME "getactiveinfolist_fuzzer" - -#endif // GET_ACTIVE_INFO_LIST_FUZZER_H - diff --git a/test/fuzztest/services/service/getactiveinfolist_fuzzer/project.xml b/test/fuzztest/services/service/getactiveinfolist_fuzzer/project.xml deleted file mode 100644 index 98df56fb99ddaa5389540f43cd547cbfe959f54d..0000000000000000000000000000000000000000 --- a/test/fuzztest/services/service/getactiveinfolist_fuzzer/project.xml +++ /dev/null @@ -1,25 +0,0 @@ - - - - - - 1000 - - 120 - - 2048 - - diff --git a/test/fuzztest/services/service/onstart_fuzzer/corpus/init b/test/fuzztest/services/service/onstart_fuzzer/corpus/init deleted file mode 100644 index e7c3fecd8d4d4816e40088113a2316bb9eb2e13f..0000000000000000000000000000000000000000 --- a/test/fuzztest/services/service/onstart_fuzzer/corpus/init +++ /dev/null @@ -1,14 +0,0 @@ -# Copyright (c) 2024 Huawei Device Co., Ltd. -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -FUZZ \ No newline at end of file diff --git a/test/fuzztest/services/service/onstart_fuzzer/onstart_fuzzer.cpp b/test/fuzztest/services/service/onstart_fuzzer/onstart_fuzzer.cpp deleted file mode 100644 index 051ec4f0dbb25c5ac1727aa96e918ba53db20b9f..0000000000000000000000000000000000000000 --- a/test/fuzztest/services/service/onstart_fuzzer/onstart_fuzzer.cpp +++ /dev/null @@ -1,101 +0,0 @@ -/* - * Copyright (c) 2024 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "onstart_fuzzer.h" - -#include -#include - -#include "accesstoken_kit.h" -#include "message_parcel.h" -#include "nativetoken_kit.h" -#include "securec.h" -#include "token_setproc.h" - -#include "sensor.h" -#include "sensor_service.h" - -namespace OHOS { -namespace Sensors { -using namespace Security::AccessToken; -using Security::AccessToken::AccessTokenID; -namespace { -constexpr size_t U32_AT_SIZE = 4; -auto g_service = SensorDelayedSpSingleton::GetInstance(); -} // namespace - -template -size_t GetObject(T &object, const uint8_t *data, size_t size) -{ - size_t objectSize = sizeof(object); - if (objectSize > size) { - return 0; - } - errno_t ret = memcpy_s(&object, objectSize, data, objectSize); - if (ret != EOK) { - return 0; - } - return objectSize; -} - -void SetUpTestCase() -{ - const char **perms = new (std::nothrow) const char *[2]; - if (perms == nullptr) { - return; - } - perms[0] = "ohos.permission.ACCELEROMETER"; - perms[1] = "ohos.permission.MANAGE_SENSOR"; - TokenInfoParams infoInstance = { - .dcapsNum = 0, - .permsNum = 2, - .aclsNum = 0, - .dcaps = nullptr, - .perms = perms, - .acls = nullptr, - .processName = "CreateDataChannelStubFuzzTest", - .aplStr = "system_core", - }; - uint64_t tokenId = GetAccessTokenId(&infoInstance); - SetSelfTokenID(tokenId); - AccessTokenKit::ReloadNativeTokenInfo(); - delete[] perms; -} - -bool OnStartFuzzTest(const uint8_t *data, size_t size) -{ - SetUpTestCase(); - g_service->OnStart(); - g_service->OnStop(); - return true; -} -} // namespace Sensors -} // namespace OHOS - -extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) -{ - /* Run your code on data */ - if (data == nullptr) { - return 0; - } - - /* Validate the length of size */ - if (size < OHOS::Sensors::U32_AT_SIZE) { - return 0; - } - - OHOS::Sensors::OnStartFuzzTest(data, size); - return 0; -} diff --git a/test/fuzztest/services/service/onstart_fuzzer/project.xml b/test/fuzztest/services/service/onstart_fuzzer/project.xml deleted file mode 100644 index 98df56fb99ddaa5389540f43cd547cbfe959f54d..0000000000000000000000000000000000000000 --- a/test/fuzztest/services/service/onstart_fuzzer/project.xml +++ /dev/null @@ -1,25 +0,0 @@ - - - - - - 1000 - - 120 - - 2048 - - diff --git a/test/fuzztest/services/service/processdeathobserver_fuzzer/BUILD.gn b/test/fuzztest/services/service/processdeathobserver_fuzzer/BUILD.gn deleted file mode 100644 index e9614fc719b4903c049715dc5c9fa1d83a4cb146..0000000000000000000000000000000000000000 --- a/test/fuzztest/services/service/processdeathobserver_fuzzer/BUILD.gn +++ /dev/null @@ -1,73 +0,0 @@ -# Copyright (c) 2024 Huawei Device Co., Ltd. -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -import("//build/config/features.gni") -import("//build/ohos.gni") -import("//build/test.gni") -import("./../../../../../sensor.gni") - -ohos_fuzztest("ProcessDeathObserverFuzzTest") { - module_out_path = FUZZ_MODULE_OUT_PATH - - fuzz_config_file = "$SUBSYSTEM_DIR/test/fuzztest/services/service/processdeathobserver_fuzzer" - - include_dirs = [ - "$SUBSYSTEM_DIR/frameworks/native/include", - "$SUBSYSTEM_DIR/interfaces/inner_api", - "$SUBSYSTEM_DIR/services/hdi_connection/interface/include", - "$SUBSYSTEM_DIR/services/hdi_connection/adapter/include", - "$SUBSYSTEM_DIR/services/hdi_connection/hardware/include", - "$SUBSYSTEM_DIR/services/include", - "$SUBSYSTEM_DIR/test/fuzztest/services/service/processdeathobserver_fuzzer", - "$SUBSYSTEM_DIR/utils/common/include", - "$SUBSYSTEM_DIR/utils/ipc/include", - ] - - cflags = [ - "-g", - "-O0", - "-Wno-unused-variable", - "-fno-omit-frame-pointer", - "-Dprivate=public", - "-Dprotected=public", - ] - - sources = [ "processdeathobserver_fuzzer.cpp" ] - - defines = sensor_default_defines - - deps = [ - "$SUBSYSTEM_DIR/frameworks/native:sensor_interface_native", - "$SUBSYSTEM_DIR/services:libsensor_service_static", - "$SUBSYSTEM_DIR/utils/common:libsensor_utils", - "$SUBSYSTEM_DIR/utils/ipc:libsensor_ipc", - ] - - external_deps = [ - "access_token:libaccesstoken_sdk", - "access_token:libnativetoken", - "access_token:libtoken_setproc", - "c_utils:utils", - "hilog:libhilog", - "ipc:ipc_single", - "samgr:samgr_proxy", - ] -} - -group("fuzztest") { - testonly = true - deps = [ - # deps file - ":ProcessDeathObserverFuzzTest", - ] -} diff --git a/test/fuzztest/services/service/processdeathobserver_fuzzer/corpus/init b/test/fuzztest/services/service/processdeathobserver_fuzzer/corpus/init deleted file mode 100644 index e7c3fecd8d4d4816e40088113a2316bb9eb2e13f..0000000000000000000000000000000000000000 --- a/test/fuzztest/services/service/processdeathobserver_fuzzer/corpus/init +++ /dev/null @@ -1,14 +0,0 @@ -# Copyright (c) 2024 Huawei Device Co., Ltd. -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -FUZZ \ No newline at end of file diff --git a/test/fuzztest/services/service/processdeathobserver_fuzzer/processdeathobserver_fuzzer.cpp b/test/fuzztest/services/service/processdeathobserver_fuzzer/processdeathobserver_fuzzer.cpp deleted file mode 100644 index b72d9c95ec418f5c63f0f0802c8dd1fd7f32b47e..0000000000000000000000000000000000000000 --- a/test/fuzztest/services/service/processdeathobserver_fuzzer/processdeathobserver_fuzzer.cpp +++ /dev/null @@ -1,90 +0,0 @@ -/* - * Copyright (c) 2024 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "processdeathobserver_fuzzer.h" - -#include -#include - -#include "accesstoken_kit.h" -#include "message_parcel.h" -#include "nativetoken_kit.h" -#include "securec.h" -#include "token_setproc.h" - -#include "sensor.h" -#include "sensor_service.h" - -namespace OHOS { -namespace Sensors { -using namespace Security::AccessToken; -using Security::AccessToken::AccessTokenID; -namespace { -constexpr size_t U32_AT_SIZE = 4; -auto g_service = SensorDelayedSpSingleton::GetInstance(); -static sptr g_remote = new (std::nothrow) IPCObjectStub(); -} // namespace - -void SetUpTestCase() -{ - const char **perms = new (std::nothrow) const char *[2]; - if (perms == nullptr) { - return; - } - perms[0] = "ohos.permission.ACCELEROMETER"; - perms[1] = "ohos.permission.MANAGE_SENSOR"; - TokenInfoParams infoInstance = { - .dcapsNum = 0, - .permsNum = 2, - .aclsNum = 0, - .dcaps = nullptr, - .perms = perms, - .acls = nullptr, - .processName = "CreateDataChannelStubFuzzTest", - .aplStr = "system_core", - }; - uint64_t tokenId = GetAccessTokenId(&infoInstance); - SetSelfTokenID(tokenId); - AccessTokenKit::ReloadNativeTokenInfo(); - delete[] perms; -} - -bool ProcessDeathObserverFuzzTest(const uint8_t *data, size_t size) -{ - SetUpTestCase(); - if (g_remote == nullptr) { - return false; - } - g_service->ProcessDeathObserver(g_remote); - return true; -} -} // namespace Sensors -} // namespace OHOS - -extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) -{ - /* Run your code on data */ - if (data == nullptr) { - return 0; - } - - /* Validate the length of size */ - if (size < OHOS::Sensors::U32_AT_SIZE) { - return 0; - } - - OHOS::Sensors::ProcessDeathObserverFuzzTest(data, size); - return 0; -} diff --git a/test/fuzztest/services/service/processdeathobserver_fuzzer/processdeathobserver_fuzzer.h b/test/fuzztest/services/service/processdeathobserver_fuzzer/processdeathobserver_fuzzer.h deleted file mode 100644 index ea80ae35d43e42b07fa725168e45877f626b971a..0000000000000000000000000000000000000000 --- a/test/fuzztest/services/service/processdeathobserver_fuzzer/processdeathobserver_fuzzer.h +++ /dev/null @@ -1,22 +0,0 @@ -/* - * Copyright (c) 2024 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef PROCESS_DEATH_OBSERVER_FUZZER_H -#define PROCESS_DEATH_OBSERVER_FUZZER_H - -#define FUZZ_PROJECT_NAME "processdeathobserver_fuzzer" - -#endif // PROCESS_DEATH_OBSERVER_FUZZER_H - diff --git a/test/fuzztest/services/service/processdeathobserver_fuzzer/project.xml b/test/fuzztest/services/service/processdeathobserver_fuzzer/project.xml deleted file mode 100644 index 98df56fb99ddaa5389540f43cd547cbfe959f54d..0000000000000000000000000000000000000000 --- a/test/fuzztest/services/service/processdeathobserver_fuzzer/project.xml +++ /dev/null @@ -1,25 +0,0 @@ - - - - - - 1000 - - 120 - - 2048 - - diff --git a/test/fuzztest/services/service/registerclientdeathrecipient_fuzzer/BUILD.gn b/test/fuzztest/services/service/registerclientdeathrecipient_fuzzer/BUILD.gn deleted file mode 100644 index 556816d208c56d0bd36629c619c09aaa67576000..0000000000000000000000000000000000000000 --- a/test/fuzztest/services/service/registerclientdeathrecipient_fuzzer/BUILD.gn +++ /dev/null @@ -1,73 +0,0 @@ -# Copyright (c) 2024 Huawei Device Co., Ltd. -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -import("//build/config/features.gni") -import("//build/ohos.gni") -import("//build/test.gni") -import("./../../../../../sensor.gni") - -ohos_fuzztest("RegisterClientDeathRecipientFuzzTest") { - module_out_path = FUZZ_MODULE_OUT_PATH - - fuzz_config_file = "$SUBSYSTEM_DIR/test/fuzztest/services/service/registerclientdeathrecipient_fuzzer" - - include_dirs = [ - "$SUBSYSTEM_DIR/frameworks/native/include", - "$SUBSYSTEM_DIR/interfaces/inner_api", - "$SUBSYSTEM_DIR/services/hdi_connection/interface/include", - "$SUBSYSTEM_DIR/services/hdi_connection/adapter/include", - "$SUBSYSTEM_DIR/services/hdi_connection/hardware/include", - "$SUBSYSTEM_DIR/services/include", - "$SUBSYSTEM_DIR/test/fuzztest/services/service/registerclientdeathrecipient_fuzzer", - "$SUBSYSTEM_DIR/utils/common/include", - "$SUBSYSTEM_DIR/utils/ipc/include", - ] - - cflags = [ - "-g", - "-O0", - "-Wno-unused-variable", - "-fno-omit-frame-pointer", - "-Dprivate=public", - "-Dprotected=public", - ] - - sources = [ "registerclientdeathrecipient_fuzzer.cpp" ] - - defines = sensor_default_defines - - deps = [ - "$SUBSYSTEM_DIR/frameworks/native:sensor_interface_native", - "$SUBSYSTEM_DIR/services:libsensor_service_static", - "$SUBSYSTEM_DIR/utils/common:libsensor_utils", - "$SUBSYSTEM_DIR/utils/ipc:libsensor_ipc", - ] - - external_deps = [ - "access_token:libaccesstoken_sdk", - "access_token:libnativetoken", - "access_token:libtoken_setproc", - "c_utils:utils", - "hilog:libhilog", - "ipc:ipc_single", - "samgr:samgr_proxy", - ] -} - -group("fuzztest") { - testonly = true - deps = [ - # deps file - ":RegisterClientDeathRecipientFuzzTest", - ] -} diff --git a/test/fuzztest/services/service/registerclientdeathrecipient_fuzzer/corpus/init b/test/fuzztest/services/service/registerclientdeathrecipient_fuzzer/corpus/init deleted file mode 100644 index e7c3fecd8d4d4816e40088113a2316bb9eb2e13f..0000000000000000000000000000000000000000 --- a/test/fuzztest/services/service/registerclientdeathrecipient_fuzzer/corpus/init +++ /dev/null @@ -1,14 +0,0 @@ -# Copyright (c) 2024 Huawei Device Co., Ltd. -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -FUZZ \ No newline at end of file diff --git a/test/fuzztest/services/service/registerclientdeathrecipient_fuzzer/project.xml b/test/fuzztest/services/service/registerclientdeathrecipient_fuzzer/project.xml deleted file mode 100644 index 98df56fb99ddaa5389540f43cd547cbfe959f54d..0000000000000000000000000000000000000000 --- a/test/fuzztest/services/service/registerclientdeathrecipient_fuzzer/project.xml +++ /dev/null @@ -1,25 +0,0 @@ - - - - - - 1000 - - 120 - - 2048 - - diff --git a/test/fuzztest/services/service/registerclientdeathrecipient_fuzzer/registerclientdeathrecipient_fuzzer.cpp b/test/fuzztest/services/service/registerclientdeathrecipient_fuzzer/registerclientdeathrecipient_fuzzer.cpp deleted file mode 100644 index 221ddc9a333507961bd09a617695aed7cfa25fea..0000000000000000000000000000000000000000 --- a/test/fuzztest/services/service/registerclientdeathrecipient_fuzzer/registerclientdeathrecipient_fuzzer.cpp +++ /dev/null @@ -1,107 +0,0 @@ -/* - * Copyright (c) 2024 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "registerclientdeathrecipient_fuzzer.h" - -#include -#include - -#include "accesstoken_kit.h" -#include "message_parcel.h" -#include "nativetoken_kit.h" -#include "securec.h" -#include "token_setproc.h" - -#include "sensor.h" -#include "sensor_service.h" - -namespace OHOS { -namespace Sensors { -using namespace Security::AccessToken; -using Security::AccessToken::AccessTokenID; -namespace { -constexpr size_t U32_AT_SIZE = 4; -auto g_service = SensorDelayedSpSingleton::GetInstance(); -static sptr g_remote = new (std::nothrow) IPCObjectStub(); -} // namespace - -template -size_t GetObject(T &object, const uint8_t *data, size_t size) -{ - size_t objectSize = sizeof(object); - if (objectSize > size) { - return 0; - } - errno_t ret = memcpy_s(&object, objectSize, data, objectSize); - if (ret != EOK) { - return 0; - } - return objectSize; -} - -void SetUpTestCase() -{ - const char **perms = new (std::nothrow) const char *[2]; - if (perms == nullptr) { - return; - } - perms[0] = "ohos.permission.ACCELEROMETER"; - perms[1] = "ohos.permission.MANAGE_SENSOR"; - TokenInfoParams infoInstance = { - .dcapsNum = 0, - .permsNum = 2, - .aclsNum = 0, - .dcaps = nullptr, - .perms = perms, - .acls = nullptr, - .processName = "CreateDataChannelStubFuzzTest", - .aplStr = "system_core", - }; - uint64_t tokenId = GetAccessTokenId(&infoInstance); - SetSelfTokenID(tokenId); - AccessTokenKit::ReloadNativeTokenInfo(); - delete[] perms; -} - -bool RegisterClientDeathRecipientFuzzTest(const uint8_t *data, size_t size) -{ - SetUpTestCase(); - if (g_remote == nullptr) { - return false; - } - int32_t pid = 0; - GetObject(pid, data, size); - g_service->RegisterClientDeathRecipient(g_remote, pid); - g_service->UnregisterClientDeathRecipient(g_remote); - return true; -} -} // namespace Sensors -} // namespace OHOS - -extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) -{ - /* Run your code on data */ - if (data == nullptr) { - return 0; - } - - /* Validate the length of size */ - if (size < OHOS::Sensors::U32_AT_SIZE) { - return 0; - } - - OHOS::Sensors::RegisterClientDeathRecipientFuzzTest(data, size); - return 0; -} diff --git a/test/fuzztest/services/service/registerclientdeathrecipient_fuzzer/registerclientdeathrecipient_fuzzer.h b/test/fuzztest/services/service/registerclientdeathrecipient_fuzzer/registerclientdeathrecipient_fuzzer.h deleted file mode 100644 index 0db8d7d7c34310fa47a15a486caf3e1472ede18a..0000000000000000000000000000000000000000 --- a/test/fuzztest/services/service/registerclientdeathrecipient_fuzzer/registerclientdeathrecipient_fuzzer.h +++ /dev/null @@ -1,22 +0,0 @@ -/* - * Copyright (c) 2024 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef REGISTER_CLIENT_DEATH_RECIPIENT_FUZZER_H -#define REGISTER_CLIENT_DEATH_RECIPIENT_FUZZER_H - -#define FUZZ_PROJECT_NAME "registerclientdeathrecipient_fuzzer" - -#endif // REGISTER_CLIENT_DEATH_RECIPIENT_FUZZER_H - diff --git a/test/fuzztest/services/service/registerpermcallback_fuzzer/BUILD.gn b/test/fuzztest/services/service/registerpermcallback_fuzzer/BUILD.gn deleted file mode 100644 index ab0f298c78dc639d563d8c5c10383c139068f629..0000000000000000000000000000000000000000 --- a/test/fuzztest/services/service/registerpermcallback_fuzzer/BUILD.gn +++ /dev/null @@ -1,73 +0,0 @@ -# Copyright (c) 2024 Huawei Device Co., Ltd. -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -import("//build/config/features.gni") -import("//build/ohos.gni") -import("//build/test.gni") -import("./../../../../../sensor.gni") - -ohos_fuzztest("RegisterPermCallbackFuzzTest") { - module_out_path = FUZZ_MODULE_OUT_PATH - - fuzz_config_file = "$SUBSYSTEM_DIR/test/fuzztest/services/service/registerpermcallback_fuzzer" - - include_dirs = [ - "$SUBSYSTEM_DIR/frameworks/native/include", - "$SUBSYSTEM_DIR/interfaces/inner_api", - "$SUBSYSTEM_DIR/services/hdi_connection/interface/include", - "$SUBSYSTEM_DIR/services/hdi_connection/adapter/include", - "$SUBSYSTEM_DIR/services/hdi_connection/hardware/include", - "$SUBSYSTEM_DIR/services/include", - "$SUBSYSTEM_DIR/test/fuzztest/services/service/registerpermcallback_fuzzer", - "$SUBSYSTEM_DIR/utils/common/include", - "$SUBSYSTEM_DIR/utils/ipc/include", - ] - - cflags = [ - "-g", - "-O0", - "-Wno-unused-variable", - "-fno-omit-frame-pointer", - "-Dprivate=public", - "-Dprotected=public", - ] - - sources = [ "registerpermcallback_fuzzer.cpp" ] - - defines = sensor_default_defines - - deps = [ - "$SUBSYSTEM_DIR/frameworks/native:sensor_interface_native", - "$SUBSYSTEM_DIR/services:libsensor_service_static", - "$SUBSYSTEM_DIR/utils/common:libsensor_utils", - "$SUBSYSTEM_DIR/utils/ipc:libsensor_ipc", - ] - - external_deps = [ - "access_token:libaccesstoken_sdk", - "access_token:libnativetoken", - "access_token:libtoken_setproc", - "c_utils:utils", - "hilog:libhilog", - "ipc:ipc_single", - "samgr:samgr_proxy", - ] -} - -group("fuzztest") { - testonly = true - deps = [ - # deps file - ":RegisterPermCallbackFuzzTest", - ] -} diff --git a/test/fuzztest/services/service/registerpermcallback_fuzzer/corpus/init b/test/fuzztest/services/service/registerpermcallback_fuzzer/corpus/init deleted file mode 100644 index e7c3fecd8d4d4816e40088113a2316bb9eb2e13f..0000000000000000000000000000000000000000 --- a/test/fuzztest/services/service/registerpermcallback_fuzzer/corpus/init +++ /dev/null @@ -1,14 +0,0 @@ -# Copyright (c) 2024 Huawei Device Co., Ltd. -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -FUZZ \ No newline at end of file diff --git a/test/fuzztest/services/service/registerpermcallback_fuzzer/project.xml b/test/fuzztest/services/service/registerpermcallback_fuzzer/project.xml deleted file mode 100644 index 98df56fb99ddaa5389540f43cd547cbfe959f54d..0000000000000000000000000000000000000000 --- a/test/fuzztest/services/service/registerpermcallback_fuzzer/project.xml +++ /dev/null @@ -1,25 +0,0 @@ - - - - - - 1000 - - 120 - - 2048 - - diff --git a/test/fuzztest/services/service/registerpermcallback_fuzzer/registerpermcallback_fuzzer.cpp b/test/fuzztest/services/service/registerpermcallback_fuzzer/registerpermcallback_fuzzer.cpp deleted file mode 100644 index 286f0b51bc70bdac7c3e481eef9821c9016ca80b..0000000000000000000000000000000000000000 --- a/test/fuzztest/services/service/registerpermcallback_fuzzer/registerpermcallback_fuzzer.cpp +++ /dev/null @@ -1,103 +0,0 @@ -/* - * Copyright (c) 2024 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "registerpermcallback_fuzzer.h" - -#include -#include - -#include "accesstoken_kit.h" -#include "message_parcel.h" -#include "nativetoken_kit.h" -#include "securec.h" -#include "token_setproc.h" - -#include "sensor.h" -#include "sensor_service.h" - -namespace OHOS { -namespace Sensors { -using namespace Security::AccessToken; -using Security::AccessToken::AccessTokenID; -namespace { -constexpr size_t U32_AT_SIZE = 4; -auto g_service = SensorDelayedSpSingleton::GetInstance(); -} // namespace - -template -size_t GetObject(T &object, const uint8_t *data, size_t size) -{ - size_t objectSize = sizeof(object); - if (objectSize > size) { - return 0; - } - errno_t ret = memcpy_s(&object, objectSize, data, objectSize); - if (ret != EOK) { - return 0; - } - return objectSize; -} - -void SetUpTestCase() -{ - const char **perms = new (std::nothrow) const char *[2]; - if (perms == nullptr) { - return; - } - perms[0] = "ohos.permission.ACCELEROMETER"; - perms[1] = "ohos.permission.MANAGE_SENSOR"; - TokenInfoParams infoInstance = { - .dcapsNum = 0, - .permsNum = 2, - .aclsNum = 0, - .dcaps = nullptr, - .perms = perms, - .acls = nullptr, - .processName = "CreateDataChannelStubFuzzTest", - .aplStr = "system_core", - }; - uint64_t tokenId = GetAccessTokenId(&infoInstance); - SetSelfTokenID(tokenId); - AccessTokenKit::ReloadNativeTokenInfo(); - delete[] perms; -} - -bool RegisterPermCallbackFuzzTest(const uint8_t *data, size_t size) -{ - SetUpTestCase(); - int32_t sensorId = 0; - GetObject(sensorId, data, size); - g_service->RegisterPermCallback(sensorId); - g_service->UnregisterPermCallback(); - return true; -} -} // namespace Sensors -} // namespace OHOS - -extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) -{ - /* Run your code on data */ - if (data == nullptr) { - return 0; - } - - /* Validate the length of size */ - if (size < OHOS::Sensors::U32_AT_SIZE) { - return 0; - } - - OHOS::Sensors::RegisterPermCallbackFuzzTest(data, size); - return 0; -} diff --git a/test/fuzztest/services/service/registerpermcallback_fuzzer/registerpermcallback_fuzzer.h b/test/fuzztest/services/service/registerpermcallback_fuzzer/registerpermcallback_fuzzer.h deleted file mode 100644 index 4a9fcbe746c6f06998d1ab72c0ffc82cedb79562..0000000000000000000000000000000000000000 --- a/test/fuzztest/services/service/registerpermcallback_fuzzer/registerpermcallback_fuzzer.h +++ /dev/null @@ -1,22 +0,0 @@ -/* - * Copyright (c) 2024 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef REGISTER_PERM_CALLBACK_FUZZER_H -#define REGISTER_PERM_CALLBACK_FUZZER_H - -#define FUZZ_PROJECT_NAME "registerpermcallback_fuzzer" - -#endif // REGISTER_PERM_CALLBACK_FUZZER_H - diff --git a/test/fuzztest/services/service/reportactiveinfo_fuzzer/BUILD.gn b/test/fuzztest/services/service/reportactiveinfo_fuzzer/BUILD.gn deleted file mode 100644 index da2e315bd07b135ddc1e2f53969cd9be0b3231a2..0000000000000000000000000000000000000000 --- a/test/fuzztest/services/service/reportactiveinfo_fuzzer/BUILD.gn +++ /dev/null @@ -1,74 +0,0 @@ -# Copyright (c) 2024 Huawei Device Co., Ltd. -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -import("//build/config/features.gni") -import("//build/ohos.gni") -import("//build/test.gni") -import("./../../../../../sensor.gni") - -ohos_fuzztest("ReportActiveInfoFuzzTest") { - module_out_path = FUZZ_MODULE_OUT_PATH - - fuzz_config_file = - "$SUBSYSTEM_DIR/test/fuzztest/services/service/reportactiveinfo_fuzzer" - - include_dirs = [ - "$SUBSYSTEM_DIR/frameworks/native/include", - "$SUBSYSTEM_DIR/interfaces/inner_api", - "$SUBSYSTEM_DIR/services/hdi_connection/interface/include", - "$SUBSYSTEM_DIR/services/hdi_connection/adapter/include", - "$SUBSYSTEM_DIR/services/hdi_connection/hardware/include", - "$SUBSYSTEM_DIR/services/include", - "$SUBSYSTEM_DIR/test/fuzztest/services/service/reportactiveinfo_fuzzer", - "$SUBSYSTEM_DIR/utils/common/include", - "$SUBSYSTEM_DIR/utils/ipc/include", - ] - - cflags = [ - "-g", - "-O0", - "-Wno-unused-variable", - "-fno-omit-frame-pointer", - "-Dprivate=public", - "-Dprotected=public", - ] - - sources = [ "reportactiveinfo_fuzzer.cpp" ] - - defines = sensor_default_defines - - deps = [ - "$SUBSYSTEM_DIR/frameworks/native:sensor_interface_native", - "$SUBSYSTEM_DIR/services:libsensor_service_static", - "$SUBSYSTEM_DIR/utils/common:libsensor_utils", - "$SUBSYSTEM_DIR/utils/ipc:libsensor_ipc", - ] - - external_deps = [ - "access_token:libaccesstoken_sdk", - "access_token:libnativetoken", - "access_token:libtoken_setproc", - "c_utils:utils", - "hilog:libhilog", - "ipc:ipc_single", - "samgr:samgr_proxy", - ] -} - -group("fuzztest") { - testonly = true - deps = [ - # deps file - ":ReportActiveInfoFuzzTest", - ] -} diff --git a/test/fuzztest/services/service/reportactiveinfo_fuzzer/corpus/init b/test/fuzztest/services/service/reportactiveinfo_fuzzer/corpus/init deleted file mode 100644 index e7c3fecd8d4d4816e40088113a2316bb9eb2e13f..0000000000000000000000000000000000000000 --- a/test/fuzztest/services/service/reportactiveinfo_fuzzer/corpus/init +++ /dev/null @@ -1,14 +0,0 @@ -# Copyright (c) 2024 Huawei Device Co., Ltd. -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -FUZZ \ No newline at end of file diff --git a/test/fuzztest/services/service/reportactiveinfo_fuzzer/project.xml b/test/fuzztest/services/service/reportactiveinfo_fuzzer/project.xml deleted file mode 100644 index 98df56fb99ddaa5389540f43cd547cbfe959f54d..0000000000000000000000000000000000000000 --- a/test/fuzztest/services/service/reportactiveinfo_fuzzer/project.xml +++ /dev/null @@ -1,25 +0,0 @@ - - - - - - 1000 - - 120 - - 2048 - - diff --git a/test/fuzztest/services/service/reportactiveinfo_fuzzer/reportactiveinfo_fuzzer.cpp b/test/fuzztest/services/service/reportactiveinfo_fuzzer/reportactiveinfo_fuzzer.cpp deleted file mode 100644 index f597b240baae7de5478f11f662c2a024e708d7ee..0000000000000000000000000000000000000000 --- a/test/fuzztest/services/service/reportactiveinfo_fuzzer/reportactiveinfo_fuzzer.cpp +++ /dev/null @@ -1,105 +0,0 @@ -/* - * Copyright (c) 2024 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "reportactiveinfo_fuzzer.h" - -#include -#include - -#include "accesstoken_kit.h" -#include "message_parcel.h" -#include "nativetoken_kit.h" -#include "securec.h" -#include "token_setproc.h" - -#include "sensor.h" -#include "sensor_service.h" - -namespace OHOS { -namespace Sensors { -using namespace Security::AccessToken; -using Security::AccessToken::AccessTokenID; -namespace { -constexpr size_t U32_AT_SIZE = 4; -auto g_service = SensorDelayedSpSingleton::GetInstance(); -} // namespace - -template -size_t GetObject(T &object, const uint8_t *data, size_t size) -{ - size_t objectSize = sizeof(object); - if (objectSize > size) { - return 0; - } - errno_t ret = memcpy_s(&object, objectSize, data, objectSize); - if (ret != EOK) { - return 0; - } - return objectSize; -} - -void SetUpTestCase() -{ - const char **perms = new (std::nothrow) const char *[2]; - if (perms == nullptr) { - return; - } - perms[0] = "ohos.permission.ACCELEROMETER"; - perms[1] = "ohos.permission.MANAGE_SENSOR"; - TokenInfoParams infoInstance = { - .dcapsNum = 0, - .permsNum = 2, - .aclsNum = 0, - .dcaps = nullptr, - .perms = perms, - .acls = nullptr, - .processName = "CreateDataChannelStubFuzzTest", - .aplStr = "system_core", - }; - uint64_t tokenId = GetAccessTokenId(&infoInstance); - SetSelfTokenID(tokenId); - AccessTokenKit::ReloadNativeTokenInfo(); - delete[] perms; -} - -bool ReportActiveInfoFuzzTest(const uint8_t *data, size_t size) -{ - SetUpTestCase(); - size_t startPos = 0; - int32_t sensorId = 0; - startPos += GetObject(sensorId, data + startPos, size - startPos); - int32_t pid = 0; - startPos += GetObject(pid, data + startPos, size - startPos); - g_service->ReportActiveInfo(sensorId, pid); - return true; -} -} // namespace Sensors -} // namespace OHOS - -extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) -{ - /* Run your code on data */ - if (data == nullptr) { - return 0; - } - - /* Validate the length of size */ - if (size < OHOS::Sensors::U32_AT_SIZE) { - return 0; - } - - OHOS::Sensors::ReportActiveInfoFuzzTest(data, size); - return 0; -} diff --git a/test/fuzztest/services/service/reportactiveinfo_fuzzer/reportactiveinfo_fuzzer.h b/test/fuzztest/services/service/reportactiveinfo_fuzzer/reportactiveinfo_fuzzer.h deleted file mode 100644 index 5f783f64e020ecd366b1edc3813c683164a9b0dc..0000000000000000000000000000000000000000 --- a/test/fuzztest/services/service/reportactiveinfo_fuzzer/reportactiveinfo_fuzzer.h +++ /dev/null @@ -1,22 +0,0 @@ -/* - * Copyright (c) 2024 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef REPOR_ACTIVE_INFO_FUZZER_H -#define REPOR_ACTIVE_INFO_FUZZER_H - -#define FUZZ_PROJECT_NAME "reportactiveinfo_fuzzer" - -#endif // REPOR_ACTIVE_INFO_FUZZER_H - diff --git a/test/fuzztest/services/service/reportonchangedata_fuzzer/BUILD.gn b/test/fuzztest/services/service/reportonchangedata_fuzzer/BUILD.gn deleted file mode 100644 index 2efd1e4545293f065aa3a371b2d665926803603e..0000000000000000000000000000000000000000 --- a/test/fuzztest/services/service/reportonchangedata_fuzzer/BUILD.gn +++ /dev/null @@ -1,74 +0,0 @@ -# Copyright (c) 2024 Huawei Device Co., Ltd. -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -import("//build/config/features.gni") -import("//build/ohos.gni") -import("//build/test.gni") -import("./../../../../../sensor.gni") - -ohos_fuzztest("ReportOnChangeDataFuzzTest") { - module_out_path = FUZZ_MODULE_OUT_PATH - - fuzz_config_file = - "$SUBSYSTEM_DIR/test/fuzztest/services/service/reportonchangedata_fuzzer" - - include_dirs = [ - "$SUBSYSTEM_DIR/frameworks/native/include", - "$SUBSYSTEM_DIR/interfaces/inner_api", - "$SUBSYSTEM_DIR/services/hdi_connection/interface/include", - "$SUBSYSTEM_DIR/services/hdi_connection/adapter/include", - "$SUBSYSTEM_DIR/services/hdi_connection/hardware/include", - "$SUBSYSTEM_DIR/services/include", - "$SUBSYSTEM_DIR/test/fuzztest/services/service/reportonchangedata_fuzzer", - "$SUBSYSTEM_DIR/utils/common/include", - "$SUBSYSTEM_DIR/utils/ipc/include", - ] - - cflags = [ - "-g", - "-O0", - "-Wno-unused-variable", - "-fno-omit-frame-pointer", - "-Dprivate=public", - "-Dprotected=public", - ] - - sources = [ "reportonchangedata_fuzzer.cpp" ] - - defines = sensor_default_defines - - deps = [ - "$SUBSYSTEM_DIR/frameworks/native:sensor_interface_native", - "$SUBSYSTEM_DIR/services:libsensor_service_static", - "$SUBSYSTEM_DIR/utils/common:libsensor_utils", - "$SUBSYSTEM_DIR/utils/ipc:libsensor_ipc", - ] - - external_deps = [ - "access_token:libaccesstoken_sdk", - "access_token:libnativetoken", - "access_token:libtoken_setproc", - "c_utils:utils", - "hilog:libhilog", - "ipc:ipc_single", - "samgr:samgr_proxy", - ] -} - -group("fuzztest") { - testonly = true - deps = [ - # deps file - ":ReportOnChangeDataFuzzTest", - ] -} diff --git a/test/fuzztest/services/service/reportonchangedata_fuzzer/corpus/init b/test/fuzztest/services/service/reportonchangedata_fuzzer/corpus/init deleted file mode 100644 index e7c3fecd8d4d4816e40088113a2316bb9eb2e13f..0000000000000000000000000000000000000000 --- a/test/fuzztest/services/service/reportonchangedata_fuzzer/corpus/init +++ /dev/null @@ -1,14 +0,0 @@ -# Copyright (c) 2024 Huawei Device Co., Ltd. -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -FUZZ \ No newline at end of file diff --git a/test/fuzztest/services/service/reportonchangedata_fuzzer/project.xml b/test/fuzztest/services/service/reportonchangedata_fuzzer/project.xml deleted file mode 100644 index 98df56fb99ddaa5389540f43cd547cbfe959f54d..0000000000000000000000000000000000000000 --- a/test/fuzztest/services/service/reportonchangedata_fuzzer/project.xml +++ /dev/null @@ -1,25 +0,0 @@ - - - - - - 1000 - - 120 - - 2048 - - diff --git a/test/fuzztest/services/service/reportonchangedata_fuzzer/reportonchangedata_fuzzer.cpp b/test/fuzztest/services/service/reportonchangedata_fuzzer/reportonchangedata_fuzzer.cpp deleted file mode 100644 index 556f94dcb0627a7f5ce7b70c4ff1baf0963d2be8..0000000000000000000000000000000000000000 --- a/test/fuzztest/services/service/reportonchangedata_fuzzer/reportonchangedata_fuzzer.cpp +++ /dev/null @@ -1,103 +0,0 @@ -/* - * Copyright (c) 2024 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "reportonchangedata_fuzzer.h" - -#include -#include - -#include "accesstoken_kit.h" -#include "message_parcel.h" -#include "nativetoken_kit.h" -#include "securec.h" -#include "token_setproc.h" - -#include "sensor.h" -#include "sensor_service.h" - -namespace OHOS { -namespace Sensors { -using namespace Security::AccessToken; -using Security::AccessToken::AccessTokenID; -namespace { -constexpr size_t U32_AT_SIZE = 4; -auto g_service = SensorDelayedSpSingleton::GetInstance(); -} // namespace - -template -size_t GetObject(T &object, const uint8_t *data, size_t size) -{ - size_t objectSize = sizeof(object); - if (objectSize > size) { - return 0; - } - errno_t ret = memcpy_s(&object, objectSize, data, objectSize); - if (ret != EOK) { - return 0; - } - return objectSize; -} - -void SetUpTestCase() -{ - const char **perms = new (std::nothrow) const char *[2]; - if (perms == nullptr) { - return; - } - perms[0] = "ohos.permission.ACCELEROMETER"; - perms[1] = "ohos.permission.MANAGE_SENSOR"; - TokenInfoParams infoInstance = { - .dcapsNum = 0, - .permsNum = 2, - .aclsNum = 0, - .dcaps = nullptr, - .perms = perms, - .acls = nullptr, - .processName = "CreateDataChannelStubFuzzTest", - .aplStr = "system_core", - }; - uint64_t tokenId = GetAccessTokenId(&infoInstance); - SetSelfTokenID(tokenId); - AccessTokenKit::ReloadNativeTokenInfo(); - delete[] perms; -} - -bool ReportOnChangeDataFuzzTest(const uint8_t *data, size_t size) -{ - SetUpTestCase(); - g_service->OnStart(); - int32_t sensorId = 0; - GetObject(sensorId, data, size); - g_service->ReportOnChangeData(sensorId); - return true; -} -} // namespace Sensors -} // namespace OHOS - -extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) -{ - /* Run your code on data */ - if (data == nullptr) { - return 0; - } - - /* Validate the length of size */ - if (size < OHOS::Sensors::U32_AT_SIZE) { - return 0; - } - - OHOS::Sensors::ReportOnChangeDataFuzzTest(data, size); - return 0; -} diff --git a/test/fuzztest/services/service/reportonchangedata_fuzzer/reportonchangedata_fuzzer.h b/test/fuzztest/services/service/reportonchangedata_fuzzer/reportonchangedata_fuzzer.h deleted file mode 100644 index e3e1091b9afc6b19b0b96b55ee6503e8e3bb2b47..0000000000000000000000000000000000000000 --- a/test/fuzztest/services/service/reportonchangedata_fuzzer/reportonchangedata_fuzzer.h +++ /dev/null @@ -1,22 +0,0 @@ -/* - * Copyright (c) 2024 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef REPORT_ON_CHANGE_DATA_FUZZER_H -#define REPORT_ON_CHANGE_DATA_FUZZER_H - -#define FUZZ_PROJECT_NAME "reportonchangedata_fuzzer" - -#endif // REPORT_ON_CHANGE_DATA_FUZZER_H - diff --git a/test/fuzztest/services/service/reportsensorsysevent_fuzzer/BUILD.gn b/test/fuzztest/services/service/reportsensorsysevent_fuzzer/BUILD.gn deleted file mode 100644 index 0a1803a6ae8d2ef42d013740b72b4744d94206b9..0000000000000000000000000000000000000000 --- a/test/fuzztest/services/service/reportsensorsysevent_fuzzer/BUILD.gn +++ /dev/null @@ -1,73 +0,0 @@ -# Copyright (c) 2024 Huawei Device Co., Ltd. -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -import("//build/config/features.gni") -import("//build/ohos.gni") -import("//build/test.gni") -import("./../../../../../sensor.gni") - -ohos_fuzztest("ReportSensorSysEventFuzzTest") { - module_out_path = FUZZ_MODULE_OUT_PATH - - fuzz_config_file = "$SUBSYSTEM_DIR/test/fuzztest/services/service/reportsensorsysevent_fuzzer" - - include_dirs = [ - "$SUBSYSTEM_DIR/frameworks/native/include", - "$SUBSYSTEM_DIR/interfaces/inner_api", - "$SUBSYSTEM_DIR/services/hdi_connection/interface/include", - "$SUBSYSTEM_DIR/services/hdi_connection/adapter/include", - "$SUBSYSTEM_DIR/services/hdi_connection/hardware/include", - "$SUBSYSTEM_DIR/services/include", - "$SUBSYSTEM_DIR/test/fuzztest/services/service/reportsensorsysevent_fuzzer", - "$SUBSYSTEM_DIR/utils/common/include", - "$SUBSYSTEM_DIR/utils/ipc/include", - ] - - cflags = [ - "-g", - "-O0", - "-Wno-unused-variable", - "-fno-omit-frame-pointer", - "-Dprivate=public", - "-Dprotected=public", - ] - - sources = [ "reportsensorsysevent_fuzzer.cpp" ] - - defines = sensor_default_defines - - deps = [ - "$SUBSYSTEM_DIR/frameworks/native:sensor_interface_native", - "$SUBSYSTEM_DIR/services:libsensor_service_static", - "$SUBSYSTEM_DIR/utils/common:libsensor_utils", - "$SUBSYSTEM_DIR/utils/ipc:libsensor_ipc", - ] - - external_deps = [ - "access_token:libaccesstoken_sdk", - "access_token:libnativetoken", - "access_token:libtoken_setproc", - "c_utils:utils", - "hilog:libhilog", - "ipc:ipc_single", - "samgr:samgr_proxy", - ] -} - -group("fuzztest") { - testonly = true - deps = [ - # deps file - ":ReportSensorSysEventFuzzTest", - ] -} diff --git a/test/fuzztest/services/service/reportsensorsysevent_fuzzer/corpus/init b/test/fuzztest/services/service/reportsensorsysevent_fuzzer/corpus/init deleted file mode 100644 index e7c3fecd8d4d4816e40088113a2316bb9eb2e13f..0000000000000000000000000000000000000000 --- a/test/fuzztest/services/service/reportsensorsysevent_fuzzer/corpus/init +++ /dev/null @@ -1,14 +0,0 @@ -# Copyright (c) 2024 Huawei Device Co., Ltd. -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -FUZZ \ No newline at end of file diff --git a/test/fuzztest/services/service/reportsensorsysevent_fuzzer/project.xml b/test/fuzztest/services/service/reportsensorsysevent_fuzzer/project.xml deleted file mode 100644 index 98df56fb99ddaa5389540f43cd547cbfe959f54d..0000000000000000000000000000000000000000 --- a/test/fuzztest/services/service/reportsensorsysevent_fuzzer/project.xml +++ /dev/null @@ -1,25 +0,0 @@ - - - - - - 1000 - - 120 - - 2048 - - diff --git a/test/fuzztest/services/service/reportsensorsysevent_fuzzer/reportsensorsysevent_fuzzer.cpp b/test/fuzztest/services/service/reportsensorsysevent_fuzzer/reportsensorsysevent_fuzzer.cpp deleted file mode 100644 index c26f6f18001c15bf10ce9e69cac830fc9c2b56f2..0000000000000000000000000000000000000000 --- a/test/fuzztest/services/service/reportsensorsysevent_fuzzer/reportsensorsysevent_fuzzer.cpp +++ /dev/null @@ -1,107 +0,0 @@ -/* - * Copyright (c) 2024 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "reportsensorsysevent_fuzzer.h" - -#include -#include - -#include "accesstoken_kit.h" -#include "message_parcel.h" -#include "nativetoken_kit.h" -#include "securec.h" -#include "token_setproc.h" - -#include "sensor.h" -#include "sensor_service.h" - -namespace OHOS { -namespace Sensors { -using namespace Security::AccessToken; -using Security::AccessToken::AccessTokenID; -namespace { -constexpr size_t U32_AT_SIZE = 4; -auto g_service = SensorDelayedSpSingleton::GetInstance(); -} // namespace - -template -size_t GetObject(T &object, const uint8_t *data, size_t size) -{ - size_t objectSize = sizeof(object); - if (objectSize > size) { - return 0; - } - errno_t ret = memcpy_s(&object, objectSize, data, objectSize); - if (ret != EOK) { - return 0; - } - return objectSize; -} - -void SetUpTestCase() -{ - const char **perms = new (std::nothrow) const char *[2]; - if (perms == nullptr) { - return; - } - perms[0] = "ohos.permission.ACCELEROMETER"; - perms[1] = "ohos.permission.MANAGE_SENSOR"; - TokenInfoParams infoInstance = { - .dcapsNum = 0, - .permsNum = 2, - .aclsNum = 0, - .dcaps = nullptr, - .perms = perms, - .acls = nullptr, - .processName = "CreateDataChannelStubFuzzTest", - .aplStr = "system_core", - }; - uint64_t tokenId = GetAccessTokenId(&infoInstance); - SetSelfTokenID(tokenId); - AccessTokenKit::ReloadNativeTokenInfo(); - delete[] perms; -} - -bool ReportSensorSysEventFuzzTest(const uint8_t *data, size_t size) -{ - SetUpTestCase(); - size_t startPos = 0; - int32_t sensorId = 0; - startPos += GetObject(sensorId, data + startPos, size - startPos); - bool enable = false; - startPos += GetObject(enable, data + startPos, size - startPos); - int32_t pid = 0; - startPos += GetObject(pid, data + startPos, size - startPos); - g_service->ReportSensorSysEvent(sensorId, enable, pid); - return true; -} -} // namespace Sensors -} // namespace OHOS - -extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) -{ - /* Run your code on data */ - if (data == nullptr) { - return 0; - } - - /* Validate the length of size */ - if (size < OHOS::Sensors::U32_AT_SIZE) { - return 0; - } - - OHOS::Sensors::ReportSensorSysEventFuzzTest(data, size); - return 0; -} diff --git a/test/fuzztest/services/service/reportsensorsysevent_fuzzer/reportsensorsysevent_fuzzer.h b/test/fuzztest/services/service/reportsensorsysevent_fuzzer/reportsensorsysevent_fuzzer.h deleted file mode 100644 index 2472b099fca1ea594a484e6821e285d9ffcb843c..0000000000000000000000000000000000000000 --- a/test/fuzztest/services/service/reportsensorsysevent_fuzzer/reportsensorsysevent_fuzzer.h +++ /dev/null @@ -1,22 +0,0 @@ -/* - * Copyright (c) 2024 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef REPORT_SENSOR_SYS_EVENT_FUZZER_H -#define REPORT_SENSOR_SYS_EVENT_FUZZER_H - -#define FUZZ_PROJECT_NAME "reportsensorsysevent_fuzzer" - -#endif // REPORT_SENSOR_SYS_EVENT_FUZZER_H - diff --git a/test/fuzztest/services/service/transferdatachannel_fuzzer/BUILD.gn b/test/fuzztest/services/service/transferdatachannel_fuzzer/BUILD.gn deleted file mode 100644 index a45b526a2fe76e2cf8f1abec496dc302798116a2..0000000000000000000000000000000000000000 --- a/test/fuzztest/services/service/transferdatachannel_fuzzer/BUILD.gn +++ /dev/null @@ -1,74 +0,0 @@ -# Copyright (c) 2024 Huawei Device Co., Ltd. -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -import("//build/config/features.gni") -import("//build/ohos.gni") -import("//build/test.gni") -import("./../../../../../sensor.gni") - -ohos_fuzztest("TransferDataChannelFuzzTest") { - module_out_path = FUZZ_MODULE_OUT_PATH - - fuzz_config_file = - "$SUBSYSTEM_DIR/test/fuzztest/services/service/transferdatachannel_fuzzer" - - include_dirs = [ - "$SUBSYSTEM_DIR/frameworks/native/include", - "$SUBSYSTEM_DIR/interfaces/inner_api", - "$SUBSYSTEM_DIR/services/hdi_connection/interface/include", - "$SUBSYSTEM_DIR/services/hdi_connection/adapter/include", - "$SUBSYSTEM_DIR/services/hdi_connection/hardware/include", - "$SUBSYSTEM_DIR/services/include", - "$SUBSYSTEM_DIR/test/fuzztest/services/service/transferdatachannel_fuzzer", - "$SUBSYSTEM_DIR/utils/common/include", - "$SUBSYSTEM_DIR/utils/ipc/include", - ] - - cflags = [ - "-g", - "-O0", - "-Wno-unused-variable", - "-fno-omit-frame-pointer", - "-Dprivate=public", - "-Dprotected=public", - ] - - sources = [ "transferdatachannel_fuzzer.cpp" ] - - defines = sensor_default_defines - - deps = [ - "$SUBSYSTEM_DIR/frameworks/native:sensor_interface_native", - "$SUBSYSTEM_DIR/services:libsensor_service_static", - "$SUBSYSTEM_DIR/utils/common:libsensor_utils", - "$SUBSYSTEM_DIR/utils/ipc:libsensor_ipc", - ] - - external_deps = [ - "access_token:libaccesstoken_sdk", - "access_token:libnativetoken", - "access_token:libtoken_setproc", - "c_utils:utils", - "hilog:libhilog", - "ipc:ipc_single", - "samgr:samgr_proxy", - ] -} - -group("fuzztest") { - testonly = true - deps = [ - # deps file - ":TransferDataChannelFuzzTest", - ] -} diff --git a/test/fuzztest/services/service/transferdatachannel_fuzzer/corpus/init b/test/fuzztest/services/service/transferdatachannel_fuzzer/corpus/init deleted file mode 100644 index e7c3fecd8d4d4816e40088113a2316bb9eb2e13f..0000000000000000000000000000000000000000 --- a/test/fuzztest/services/service/transferdatachannel_fuzzer/corpus/init +++ /dev/null @@ -1,14 +0,0 @@ -# Copyright (c) 2024 Huawei Device Co., Ltd. -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -FUZZ \ No newline at end of file diff --git a/test/fuzztest/services/service/transferdatachannel_fuzzer/project.xml b/test/fuzztest/services/service/transferdatachannel_fuzzer/project.xml deleted file mode 100644 index 98df56fb99ddaa5389540f43cd547cbfe959f54d..0000000000000000000000000000000000000000 --- a/test/fuzztest/services/service/transferdatachannel_fuzzer/project.xml +++ /dev/null @@ -1,25 +0,0 @@ - - - - - - 1000 - - 120 - - 2048 - - diff --git a/test/fuzztest/services/service/transferdatachannel_fuzzer/transferdatachannel_fuzzer.cpp b/test/fuzztest/services/service/transferdatachannel_fuzzer/transferdatachannel_fuzzer.cpp deleted file mode 100644 index 3874ebdb09e6f9acc6efe889721291f6ddb75e3a..0000000000000000000000000000000000000000 --- a/test/fuzztest/services/service/transferdatachannel_fuzzer/transferdatachannel_fuzzer.cpp +++ /dev/null @@ -1,91 +0,0 @@ -/* - * Copyright (c) 2024 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "transferdatachannel_fuzzer.h" - -#include -#include - -#include "accesstoken_kit.h" -#include "message_parcel.h" -#include "nativetoken_kit.h" -#include "securec.h" -#include "token_setproc.h" - -#include "sensor.h" -#include "sensor_service.h" - -namespace OHOS { -namespace Sensors { -using namespace Security::AccessToken; -using Security::AccessToken::AccessTokenID; -namespace { -constexpr size_t U32_AT_SIZE = 4; -auto g_service = SensorDelayedSpSingleton::GetInstance(); -static sptr g_remote = new (std::nothrow) IPCObjectStub(); -static sptr g_dataChannel = new (std::nothrow) SensorBasicDataChannel(); -} // namespace - -void SetUpTestCase() -{ - const char **perms = new (std::nothrow) const char *[2]; - if (perms == nullptr) { - return; - } - perms[0] = "ohos.permission.ACCELEROMETER"; - perms[1] = "ohos.permission.MANAGE_SENSOR"; - TokenInfoParams infoInstance = { - .dcapsNum = 0, - .permsNum = 2, - .aclsNum = 0, - .dcaps = nullptr, - .perms = perms, - .acls = nullptr, - .processName = "CreateDataChannelStubFuzzTest", - .aplStr = "system_core", - }; - uint64_t tokenId = GetAccessTokenId(&infoInstance); - SetSelfTokenID(tokenId); - AccessTokenKit::ReloadNativeTokenInfo(); - delete[] perms; -} - -bool TransferDataChannelFuzzTest(const uint8_t *data, size_t size) -{ - SetUpTestCase(); - if (g_remote == nullptr || g_dataChannel == nullptr) { - return false; - } - g_service->TransferDataChannel(g_dataChannel, g_remote); - return true; -} -} // namespace Sensors -} // namespace OHOS - -extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) -{ - /* Run your code on data */ - if (data == nullptr) { - return 0; - } - - /* Validate the length of size */ - if (size < OHOS::Sensors::U32_AT_SIZE) { - return 0; - } - - OHOS::Sensors::TransferDataChannelFuzzTest(data, size); - return 0; -} diff --git a/test/fuzztest/services/service/transferdatachannel_fuzzer/transferdatachannel_fuzzer.h b/test/fuzztest/services/service/transferdatachannel_fuzzer/transferdatachannel_fuzzer.h deleted file mode 100644 index 36616538d2d41f0cb5656e32e1e9c0a2403c5613..0000000000000000000000000000000000000000 --- a/test/fuzztest/services/service/transferdatachannel_fuzzer/transferdatachannel_fuzzer.h +++ /dev/null @@ -1,22 +0,0 @@ -/* - * Copyright (c) 2024 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef TRANFER_DATA_CHANNEL_FUZZER_H -#define TRANFER_DATA_CHANNEL_FUZZER_H - -#define FUZZ_PROJECT_NAME "transferdatachannel_fuzzer" - -#endif // TRANFER_DATA_CHANNEL_FUZZER_H - diff --git a/test/fuzztest/services/suspendsensorsstub_fuzzer/suspendsensorsstub_fuzzer.cpp b/test/fuzztest/services/suspendsensorsstub_fuzzer/suspendsensorsstub_fuzzer.cpp index b7fd0647d2290ba6e5b51e5aac711d08801f2196..e72bab07cb63b4b7de34d481b56a8c05ef121cbc 100644 --- a/test/fuzztest/services/suspendsensorsstub_fuzzer/suspendsensorsstub_fuzzer.cpp +++ b/test/fuzztest/services/suspendsensorsstub_fuzzer/suspendsensorsstub_fuzzer.cpp @@ -74,8 +74,8 @@ bool OnRemoteRequestFuzzTest(const uint8_t *data, size_t size) datas, reply, option); return true; } -} // namespace Sensors -} // namespace OHOS +} // namespace Sensors +} // namespace OHOS extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { diff --git a/test/fuzztest/services/service/onstart_fuzzer/BUILD.gn b/test/unittest/coverage/BUILD.gn similarity index 45% rename from test/fuzztest/services/service/onstart_fuzzer/BUILD.gn rename to test/unittest/coverage/BUILD.gn index b524a8015d956fbbce83ff1d35e6868852605920..e0c6461bf733fceaf44a7a33278fd670658f8164 100644 --- a/test/fuzztest/services/service/onstart_fuzzer/BUILD.gn +++ b/test/unittest/coverage/BUILD.gn @@ -11,64 +11,69 @@ # See the License for the specific language governing permissions and # limitations under the License. -import("//build/config/features.gni") -import("//build/ohos.gni") import("//build/test.gni") -import("./../../../../../sensor.gni") +import("./../../../sensor.gni") -ohos_fuzztest("OnStartFuzzTest") { - module_out_path = FUZZ_MODULE_OUT_PATH +ohos_unittest("SensorBasicDataChannelTest") { + module_out_path = "sensor/coverage" - fuzz_config_file = - "$SUBSYSTEM_DIR/test/fuzztest/services/service/onstart_fuzzer" + sources = [ + "$SUBSYSTEM_DIR/test/unittest/coverage/sensor_basic_data_channel_test.cpp", + ] include_dirs = [ + "$SUBSYSTEM_DIR/utils/common/include", + "$SUBSYSTEM_DIR/interfaces/kits/c", "$SUBSYSTEM_DIR/frameworks/native/include", "$SUBSYSTEM_DIR/interfaces/inner_api", - "$SUBSYSTEM_DIR/services/hdi_connection/interface/include", - "$SUBSYSTEM_DIR/services/hdi_connection/adapter/include", - "$SUBSYSTEM_DIR/services/hdi_connection/hardware/include", - "$SUBSYSTEM_DIR/services/include", - "$SUBSYSTEM_DIR/test/fuzztest/services/service/onstart_fuzzer", - "$SUBSYSTEM_DIR/utils/common/include", - "$SUBSYSTEM_DIR/utils/ipc/include", ] - cflags = [ - "-g", - "-O0", - "-Wno-unused-variable", - "-fno-omit-frame-pointer", - "-Dprivate=public", - "-Dprotected=public", + deps = [ + "$SUBSYSTEM_DIR/frameworks/native:libsensor_client", + "$SUBSYSTEM_DIR/frameworks/native:ohsensor", + "$SUBSYSTEM_DIR/utils/common:libsensor_utils", ] - sources = [ "onstart_fuzzer.cpp" ] + external_deps = [ + "c_utils:utils", + "googletest:gmock", + "googletest:gtest_main", + "hilog:libhilog", + "ipc:ipc_single", + ] +} + +ohos_unittest("ReportDataCallbackTest") { + module_out_path = "sensor/coverage" - defines = sensor_default_defines + sources = + [ "$SUBSYSTEM_DIR/test/unittest/coverage/report_data_callback_test.cpp" ] + + include_dirs = [ + "$SUBSYSTEM_DIR/utils/common/include", + "$SUBSYSTEM_DIR/interfaces/kits/c", + "$SUBSYSTEM_DIR/frameworks/native/include", + "$SUBSYSTEM_DIR/interfaces/inner_api", + ] deps = [ - "$SUBSYSTEM_DIR/frameworks/native:sensor_interface_native", - "$SUBSYSTEM_DIR/services:libsensor_service_static", + "$SUBSYSTEM_DIR/frameworks/native:libsensor_client", + "$SUBSYSTEM_DIR/frameworks/native:ohsensor", "$SUBSYSTEM_DIR/utils/common:libsensor_utils", - "$SUBSYSTEM_DIR/utils/ipc:libsensor_ipc", ] external_deps = [ - "access_token:libaccesstoken_sdk", - "access_token:libnativetoken", - "access_token:libtoken_setproc", "c_utils:utils", + "googletest:gmock", + "googletest:gtest_main", "hilog:libhilog", - "ipc:ipc_single", - "samgr:samgr_proxy", ] } -group("fuzztest") { +group("unittest") { testonly = true deps = [ - # deps file - ":OnStartFuzzTest", + ":ReportDataCallbackTest", + ":SensorBasicDataChannelTest", ] } diff --git a/test/unittest/coverage/report_data_callback_test.cpp b/test/unittest/coverage/report_data_callback_test.cpp new file mode 100644 index 0000000000000000000000000000000000000000..e9320acbad5274f8b38eee32ab952ddc25d3c365 --- /dev/null +++ b/test/unittest/coverage/report_data_callback_test.cpp @@ -0,0 +1,122 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#include + +#include "report_data_callback.h" +#include "sensor_errors.h" + +#undef LOG_TAG +#define LOG_TAG "ReportDataCallbackTest" + +namespace OHOS { +namespace Sensors { +using namespace testing::ext; + +namespace { + SensorData* g_sensorData = new (std::nothrow) SensorData[CIRCULAR_BUF_LEN]; +} // namespace + +class SensorBasicDataChannelTest : public testing::Test { +public: + static void SetUpTestCase(); + static void TearDownTestCase(); + void SetUp(); + void TearDown(); +}; + +void SensorBasicDataChannelTest::SetUpTestCase() {} + +void SensorBasicDataChannelTest::TearDownTestCase() +{ + if (g_sensorData != nullptr) { + delete[] g_sensorData; + g_sensorData = nullptr; + } +} + +void SensorBasicDataChannelTest::SetUp() {} + +void SensorBasicDataChannelTest::TearDown() {} + +HWTEST_F(SensorBasicDataChannelTest, ReportDataCallbackTest_001, TestSize.Level1) +{ + SEN_HILOGI("ReportDataCallbackTest_001 in"); + + ReportDataCallback reportDataCallback = ReportDataCallback(); + ReportDataCallback *cb = nullptr; + int32_t ret = reportDataCallback.ReportEventCallback(g_sensorData, cb); + ASSERT_EQ(ret, ERROR); + + sptr callback = new (std::nothrow) ReportDataCallback(); + if (callback->eventsBuf_.circularBuf != nullptr) { + delete[] callback->eventsBuf_.circularBuf; + callback->eventsBuf_.circularBuf = nullptr; + } + callback->eventsBuf_.circularBuf = nullptr; + ret = reportDataCallback.ReportEventCallback(g_sensorData, callback); + ASSERT_EQ(ret, ERROR); +} + +HWTEST_F(SensorBasicDataChannelTest, ReportDataCallbackTest_002, TestSize.Level1) +{ + SEN_HILOGI("ReportDataCallbackTest_002 in"); + + ReportDataCallback reportDataCallback = ReportDataCallback(); + sptr callback = new (std::nothrow) ReportDataCallback(); + callback->eventsBuf_.eventNum = CIRCULAR_BUF_LEN + 1; + callback->eventsBuf_.writePosition = 1; + int32_t ret = reportDataCallback.ReportEventCallback(g_sensorData, callback); + ASSERT_EQ(ret, ERROR); + + callback->eventsBuf_.eventNum = 1; + callback->eventsBuf_.writePosition = CIRCULAR_BUF_LEN + 1; + ret = reportDataCallback.ReportEventCallback(g_sensorData, callback); + ASSERT_EQ(ret, ERROR); +} + +HWTEST_F(SensorBasicDataChannelTest, ReportDataCallbackTest_003, TestSize.Level1) +{ + SEN_HILOGI("ReportDataCallbackTest_003 in"); + ReportDataCallback reportDataCallback = ReportDataCallback(); + sptr callback = new (std::nothrow) ReportDataCallback(); + callback->eventsBuf_.eventNum = CIRCULAR_BUF_LEN; + callback->eventsBuf_.writePosition = CIRCULAR_BUF_LEN; + int32_t ret = reportDataCallback.ReportEventCallback(g_sensorData, callback); + ASSERT_EQ(ret, ERR_OK); +} + +HWTEST_F(SensorBasicDataChannelTest, ReportDataCallbackTest_004, TestSize.Level1) +{ + SEN_HILOGI("ReportDataCallbackTest_004 in"); + ReportDataCallback reportDataCallback = ReportDataCallback(); + sptr callback = new (std::nothrow) ReportDataCallback(); + callback->eventsBuf_.eventNum = CIRCULAR_BUF_LEN; + callback->eventsBuf_.writePosition = 1; + int32_t ret = reportDataCallback.ReportEventCallback(g_sensorData, callback); + ASSERT_EQ(ret, ERR_OK); +} + +HWTEST_F(SensorBasicDataChannelTest, ReportDataCallbackTest_005, TestSize.Level1) +{ + SEN_HILOGI("ReportDataCallbackTest_005 in"); + ReportDataCallback reportDataCallback = ReportDataCallback(); + sptr callback = new (std::nothrow) ReportDataCallback(); + callback->eventsBuf_.eventNum = CIRCULAR_BUF_LEN; + callback->eventsBuf_.writePosition = CIRCULAR_BUF_LEN - 1; + int32_t ret = reportDataCallback.ReportEventCallback(g_sensorData, callback); + ASSERT_EQ(ret, ERR_OK); +} +} // namespace Sensors +} // namespace OHOS \ No newline at end of file diff --git a/test/unittest/coverage/sensor_basic_data_channel_test.cpp b/test/unittest/coverage/sensor_basic_data_channel_test.cpp new file mode 100644 index 0000000000000000000000000000000000000000..53cd8ed1140dec78d5d2027089e972af0e200dc1 --- /dev/null +++ b/test/unittest/coverage/sensor_basic_data_channel_test.cpp @@ -0,0 +1,149 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include + +#include "message_parcel.h" + +#include "sensor_errors.h" +#include "sensor_basic_data_channel.h" + +#undef LOG_TAG +#define LOG_TAG "SensorBasicDataChannelTest" + +namespace OHOS { +namespace Sensors { +using namespace testing::ext; +using namespace OHOS::HiviewDFX; + +namespace { +constexpr int32_t INVALID_FD = 2; +} // namespace + +class SensorBasicDataChannelTest : public testing::Test { +public: + static void SetUpTestCase(); + static void TearDownTestCase(); + void SetUp(); + void TearDown(); +}; + +void SensorBasicDataChannelTest::SetUpTestCase() {} + +void SensorBasicDataChannelTest::TearDownTestCase() {} + +void SensorBasicDataChannelTest::SetUp() {} + +void SensorBasicDataChannelTest::TearDown() {} + +HWTEST_F(SensorBasicDataChannelTest, SensorBasicDataChannelTest_001, TestSize.Level1) +{ + SEN_HILOGI("SensorBasicDataChannelTest_001 in"); + + SensorBasicDataChannel sensorChannel = SensorBasicDataChannel(); + MessageParcel data; + int32_t ret = sensorChannel.CreateSensorBasicChannel(); + ASSERT_EQ(ret, ERR_OK); + ret = sensorChannel.CreateSensorBasicChannel(data); + ASSERT_EQ(ret, ERR_OK); + + ret = sensorChannel.SendToBinder(data); + ASSERT_EQ(ret, ERR_OK); + + char buff[128] = {}; + ret = sensorChannel.SendData(static_cast(buff), sizeof(buff)); + ASSERT_EQ(ret, ERR_OK); + + ret = sensorChannel.ReceiveData(static_cast(buff), sizeof(buff)); + ASSERT_NE(ret, SENSOR_CHANNEL_RECEIVE_ADDR_ERR); + + sensorChannel.DestroySensorBasicChannel(); +} + +HWTEST_F(SensorBasicDataChannelTest, CreateSensorBasicChannel_001, TestSize.Level1) +{ + SEN_HILOGI("CreateSensorBasicChannel_001 in"); + + SensorBasicDataChannel sensorChannel = SensorBasicDataChannel(); + MessageParcel data; + data.WriteFileDescriptor(INVALID_FD); + int32_t ret = sensorChannel.CreateSensorBasicChannel(data); + ASSERT_EQ(ret, ERR_OK); + + ret = sensorChannel.CreateSensorBasicChannel(data); + ASSERT_EQ(ret, ERR_OK); +} + +HWTEST_F(SensorBasicDataChannelTest, CreateSensorBasicChannel_002, TestSize.Level1) +{ + SEN_HILOGI("CreateSensorBasicChannel_002 in"); + SensorBasicDataChannel sensorChannel = SensorBasicDataChannel(); + MessageParcel data; + int32_t ret = sensorChannel.CreateSensorBasicChannel(data); + ASSERT_EQ(ret, SENSOR_CHANNEL_READ_DESCRIPTOR_ERR); +} + +HWTEST_F(SensorBasicDataChannelTest, SendToBinder_001, TestSize.Level1) +{ + SEN_HILOGI("SendToBinder_001 in"); + SensorBasicDataChannel sensorChannel = SensorBasicDataChannel(); + MessageParcel data; + int32_t ret = sensorChannel.SendToBinder(data); + ASSERT_EQ(ret, SENSOR_CHANNEL_SENDFD_ERR); +} + +HWTEST_F(SensorBasicDataChannelTest, SendData_001, TestSize.Level1) +{ + SEN_HILOGI("SendData_001 in"); + SensorBasicDataChannel sensorChannel = SensorBasicDataChannel(); + char buff[128] = {}; + int32_t ret = sensorChannel.SendData(static_cast(buff), sizeof(buff)); + ASSERT_EQ(ret, SENSOR_CHANNEL_SEND_ADDR_ERR); +} + +HWTEST_F(SensorBasicDataChannelTest, SendData_002, TestSize.Level1) +{ + SEN_HILOGI("SendData_002 in"); + SensorBasicDataChannel sensorChannel = SensorBasicDataChannel(); + MessageParcel data; + data.WriteFileDescriptor(INVALID_FD); + int32_t ret = sensorChannel.CreateSensorBasicChannel(data); + ASSERT_EQ(ret, ERR_OK); + char buff[128] = {}; + ret = sensorChannel.SendData(static_cast(buff), sizeof(buff)); + ASSERT_EQ(ret, SENSOR_CHANNEL_SEND_DATA_ERR); +} + +HWTEST_F(SensorBasicDataChannelTest, ReceiveData_001, TestSize.Level1) +{ + SEN_HILOGI("ReceiveData_001 in"); + SensorBasicDataChannel sensorChannel = SensorBasicDataChannel(); + char buff[128] = {}; + int32_t ret = sensorChannel.ReceiveData(static_cast(buff), sizeof(buff)); + ASSERT_EQ(ret, SENSOR_CHANNEL_RECEIVE_ADDR_ERR); + + sensorChannel.CreateSensorBasicChannel(); + char *buff1 = nullptr; + ret = sensorChannel.ReceiveData(static_cast(buff1), sizeof(buff1)); + ASSERT_EQ(ret, SENSOR_CHANNEL_RECEIVE_ADDR_ERR); + + sensorChannel.DestroySensorBasicChannel(); +} + +} // namespace Sensors +} // namespace OHOS diff --git a/test/unittest/interfaces/inner_api/drop_detection_test.cpp b/test/unittest/interfaces/inner_api/drop_detection_test.cpp index 255c8c3f6dbb2b75e9dd6b01576604562b6faae8..cfae3d7a5821e286c7195b00397509f5859d0d8d 100644 --- a/test/unittest/interfaces/inner_api/drop_detection_test.cpp +++ b/test/unittest/interfaces/inner_api/drop_detection_test.cpp @@ -31,7 +31,7 @@ using namespace testing::ext; using namespace OHOS::HiviewDFX; namespace { -std::atomic_bool g_existDropDetection = false; +std::atomic_bool g_hasDropDetection = false; } // namespace class DropDetectionTest : public testing::Test { @@ -54,7 +54,7 @@ void DropDetectionTest::SetUpTestCase() } for (int32_t i = 0; i < count; ++i) { if (sensorInfo[i].sensorId == SENSOR_TYPE_ID_DROP_DETECTION) { - g_existDropDetection = true; + g_hasDropDetection = true; SEN_HILOGD("Exist drop detection sensor"); break; } @@ -117,7 +117,7 @@ void DropDetectionDataCallbackImpl2(SensorEvent *event) HWTEST_F(DropDetectionTest, DropDetectionTest_001, TestSize.Level1) { SEN_HILOGI("DropDetectionTest_001 enter"); - if (g_existDropDetection) { + if (g_hasDropDetection) { ASSERT_NE(ActivateSensor(SENSOR_TYPE_ID_DROP_DETECTION, nullptr), OHOS::Sensors::SUCCESS); } } @@ -125,7 +125,7 @@ HWTEST_F(DropDetectionTest, DropDetectionTest_001, TestSize.Level1) HWTEST_F(DropDetectionTest, DropDetectionTest_002, TestSize.Level1) { SEN_HILOGI("DropDetectionTest_002 enter"); - if (g_existDropDetection) { + if (g_hasDropDetection) { SensorUser user; user.callback = DropDetectionDataCallbackImpl; ASSERT_NE(ActivateSensor(-1, &user), OHOS::Sensors::SUCCESS); @@ -135,7 +135,7 @@ HWTEST_F(DropDetectionTest, DropDetectionTest_002, TestSize.Level1) HWTEST_F(DropDetectionTest, DropDetectionTest_003, TestSize.Level1) { SEN_HILOGI("DropDetectionTest_003 enter"); - if (g_existDropDetection) { + if (g_hasDropDetection) { SensorUser user; user.callback = nullptr; ASSERT_NE(ActivateSensor(SENSOR_TYPE_ID_DROP_DETECTION, &user), OHOS::Sensors::SUCCESS); @@ -145,7 +145,7 @@ HWTEST_F(DropDetectionTest, DropDetectionTest_003, TestSize.Level1) HWTEST_F(DropDetectionTest, DropDetectionTest_004, TestSize.Level1) { SEN_HILOGI("DropDetectionTest_004 enter"); - if (g_existDropDetection) { + if (g_hasDropDetection) { ASSERT_NE(DeactivateSensor(SENSOR_TYPE_ID_DROP_DETECTION, nullptr), OHOS::Sensors::SUCCESS); } } @@ -153,7 +153,7 @@ HWTEST_F(DropDetectionTest, DropDetectionTest_004, TestSize.Level1) HWTEST_F(DropDetectionTest, DropDetectionTest_005, TestSize.Level1) { SEN_HILOGI("DropDetectionTest_005 enter"); - if (g_existDropDetection) { + if (g_hasDropDetection) { SensorUser user; user.callback = DropDetectionDataCallbackImpl; ASSERT_NE(DeactivateSensor(-1, &user), OHOS::Sensors::SUCCESS); @@ -163,7 +163,7 @@ HWTEST_F(DropDetectionTest, DropDetectionTest_005, TestSize.Level1) HWTEST_F(DropDetectionTest, DropDetectionTest_006, TestSize.Level1) { SEN_HILOGI("DropDetectionTest_006 enter"); - if (g_existDropDetection) { + if (g_hasDropDetection) { SensorUser user; user.callback = nullptr; ASSERT_NE(DeactivateSensor(SENSOR_TYPE_ID_DROP_DETECTION, &user), OHOS::Sensors::SUCCESS); @@ -173,7 +173,7 @@ HWTEST_F(DropDetectionTest, DropDetectionTest_006, TestSize.Level1) HWTEST_F(DropDetectionTest, DropDetectionTest_007, TestSize.Level1) { SEN_HILOGI("DropDetectionTest_007 enter"); - if (g_existDropDetection) { + if (g_hasDropDetection) { ASSERT_NE(SetBatch(SENSOR_TYPE_ID_DROP_DETECTION, nullptr, 10000000, 10000000), OHOS::Sensors::SUCCESS); } } @@ -181,7 +181,7 @@ HWTEST_F(DropDetectionTest, DropDetectionTest_007, TestSize.Level1) HWTEST_F(DropDetectionTest, DropDetectionTest_008, TestSize.Level1) { SEN_HILOGI("DropDetectionTest_008 enter"); - if (g_existDropDetection) { + if (g_hasDropDetection) { SensorUser user; user.callback = DropDetectionDataCallbackImpl; ASSERT_NE(SetBatch(-1, &user, 10000000, 10000000), OHOS::Sensors::SUCCESS); @@ -191,7 +191,7 @@ HWTEST_F(DropDetectionTest, DropDetectionTest_008, TestSize.Level1) HWTEST_F(DropDetectionTest, DropDetectionTest_009, TestSize.Level1) { SEN_HILOGI("DropDetectionTest_009 enter"); - if (g_existDropDetection) { + if (g_hasDropDetection) { SensorUser user; user.callback = nullptr; ASSERT_NE(SetBatch(SENSOR_TYPE_ID_DROP_DETECTION, &user, 10000000, 10000000), OHOS::Sensors::SUCCESS); @@ -201,7 +201,7 @@ HWTEST_F(DropDetectionTest, DropDetectionTest_009, TestSize.Level1) HWTEST_F(DropDetectionTest, DropDetectionTest_010, TestSize.Level1) { SEN_HILOGI("DropDetectionTest_010 enter"); - if (g_existDropDetection) { + if (g_hasDropDetection) { SensorUser user; user.callback = DropDetectionDataCallbackImpl; ASSERT_NE(SetBatch(SENSOR_TYPE_ID_DROP_DETECTION, &user, -1, -1), OHOS::Sensors::SUCCESS); @@ -211,7 +211,7 @@ HWTEST_F(DropDetectionTest, DropDetectionTest_010, TestSize.Level1) HWTEST_F(DropDetectionTest, DropDetectionTest_011, TestSize.Level1) { SEN_HILOGI("DropDetectionTest_011 enter"); - if (g_existDropDetection) { + if (g_hasDropDetection) { ASSERT_NE(SubscribeSensor(SENSOR_TYPE_ID_DROP_DETECTION, nullptr), OHOS::Sensors::SUCCESS); } } @@ -219,7 +219,7 @@ HWTEST_F(DropDetectionTest, DropDetectionTest_011, TestSize.Level1) HWTEST_F(DropDetectionTest, DropDetectionTest_012, TestSize.Level1) { SEN_HILOGI("DropDetectionTest_012 enter"); - if (g_existDropDetection) { + if (g_hasDropDetection) { SensorUser user; user.callback = DropDetectionDataCallbackImpl; ASSERT_NE(SubscribeSensor(-1, &user), OHOS::Sensors::SUCCESS); @@ -229,7 +229,7 @@ HWTEST_F(DropDetectionTest, DropDetectionTest_012, TestSize.Level1) HWTEST_F(DropDetectionTest, DropDetectionTest_013, TestSize.Level1) { SEN_HILOGI("DropDetectionTest_013 enter"); - if (g_existDropDetection) { + if (g_hasDropDetection) { SensorUser user; user.callback = nullptr; ASSERT_NE(SubscribeSensor(SENSOR_TYPE_ID_DROP_DETECTION, &user), OHOS::Sensors::SUCCESS); @@ -239,7 +239,7 @@ HWTEST_F(DropDetectionTest, DropDetectionTest_013, TestSize.Level1) HWTEST_F(DropDetectionTest, DropDetectionTest_014, TestSize.Level1) { SEN_HILOGI("DropDetectionTest_014 enter"); - if (g_existDropDetection) { + if (g_hasDropDetection) { ASSERT_NE(UnsubscribeSensor(SENSOR_TYPE_ID_DROP_DETECTION, nullptr), OHOS::Sensors::SUCCESS); } } @@ -247,7 +247,7 @@ HWTEST_F(DropDetectionTest, DropDetectionTest_014, TestSize.Level1) HWTEST_F(DropDetectionTest, DropDetectionTest_015, TestSize.Level1) { SEN_HILOGI("DropDetectionTest_015 enter"); - if (g_existDropDetection) { + if (g_hasDropDetection) { SensorUser user; user.callback = DropDetectionDataCallbackImpl; ASSERT_NE(UnsubscribeSensor(-1, &user), OHOS::Sensors::SUCCESS); @@ -257,7 +257,7 @@ HWTEST_F(DropDetectionTest, DropDetectionTest_015, TestSize.Level1) HWTEST_F(DropDetectionTest, DropDetectionTest_016, TestSize.Level1) { SEN_HILOGI("DropDetectionTest_016 enter"); - if (g_existDropDetection) { + if (g_hasDropDetection) { SensorUser user; user.callback = nullptr; ASSERT_NE(UnsubscribeSensor(SENSOR_TYPE_ID_DROP_DETECTION, &user), OHOS::Sensors::SUCCESS); @@ -267,7 +267,7 @@ HWTEST_F(DropDetectionTest, DropDetectionTest_016, TestSize.Level1) HWTEST_F(DropDetectionTest, DropDetectionTest_017, TestSize.Level1) { SEN_HILOGI("DropDetectionTest_017 enter"); - if (g_existDropDetection) { + if (g_hasDropDetection) { SensorUser user; user.callback = DropDetectionDataCallbackImpl; ASSERT_EQ(SubscribeSensor(SENSOR_TYPE_ID_DROP_DETECTION, &user), OHOS::Sensors::SUCCESS); @@ -282,7 +282,7 @@ HWTEST_F(DropDetectionTest, DropDetectionTest_017, TestSize.Level1) HWTEST_F(DropDetectionTest, DropDetectionTest_018, TestSize.Level1) { SEN_HILOGI("DropDetectionTest_018 enter"); - if (g_existDropDetection) { + if (g_hasDropDetection) { SensorUser user; user.callback = DropDetectionDataCallbackImpl; ASSERT_EQ(SubscribeSensor(SENSOR_TYPE_ID_DROP_DETECTION, &user), OHOS::Sensors::SUCCESS); diff --git a/test/unittest/interfaces/inner_api/sensor_agent_test.cpp b/test/unittest/interfaces/inner_api/sensor_agent_test.cpp index 337445f7c2e89ba91b0795355aa33f3e23edd40f..b74fa07e02e913b6eb9e2c276bb5aa8066ba40d0 100644 --- a/test/unittest/interfaces/inner_api/sensor_agent_test.cpp +++ b/test/unittest/interfaces/inner_api/sensor_agent_test.cpp @@ -60,7 +60,7 @@ HapInfoParams g_infoManagerTestInfoParms = { .instIndex = 0, .appIDDesc = "sensorAgentTest" }; -} // namespace +} // namespace class SensorAgentTest : public testing::Test { public: diff --git a/test/unittest/interfaces/inner_api/sensor_algorithm_test.cpp b/test/unittest/interfaces/inner_api/sensor_algorithm_test.cpp index 9bac6570a82507b54e19c46f6beac0acd4e13177..7c42af4ba4ac64cc3375d0b5eff550ead8377788 100644 --- a/test/unittest/interfaces/inner_api/sensor_algorithm_test.cpp +++ b/test/unittest/interfaces/inner_api/sensor_algorithm_test.cpp @@ -31,6 +31,7 @@ namespace { constexpr int32_t QUATERNION_LENGTH = 4; constexpr int32_t ROTATION_VECTOR_LENGTH = 3; constexpr int32_t THREE_DIMENSIONAL_MATRIX_LENGTH = 9; +constexpr int32_t FOUR_DIMENSIONAL_MATRIX_LENGTH = 16; constexpr float EPS = 0.01; } // namespace @@ -87,6 +88,16 @@ HWTEST_F(SensorAlgorithmTest, SensorAlgorithmTest_003, TestSize.Level1) HWTEST_F(SensorAlgorithmTest, SensorAlgorithmTest_004, TestSize.Level1) { SEN_HILOGI("SensorAlgorithmTest_004 in"); + std::vector rotationVector = {0.52, -0.336, -0.251, 0.1}; + std::vector quaternion(QUATERNION_LENGTH); + int32_t ret = sensorAlgorithm.CreateQuaternion(rotationVector, quaternion); + ASSERT_EQ(ret, OHOS::Sensors::SUCCESS); +} + + +HWTEST_F(SensorAlgorithmTest, SensorAlgorithmTest_005, TestSize.Level1) +{ + SEN_HILOGI("SensorAlgorithmTest_005 in"); std::vector inRotationMatrix = {1.5, 1.5, 1.5, 1.5, 1.5, 1.5, 1.5, 1.5, 1.5}; std::vector outRotationMatrix(THREE_DIMENSIONAL_MATRIX_LENGTH); int32_t ret = sensorAlgorithm.TransformCoordinateSystem(inRotationMatrix, 1, 2, outRotationMatrix); @@ -99,34 +110,74 @@ HWTEST_F(SensorAlgorithmTest, SensorAlgorithmTest_004, TestSize.Level1) } } -HWTEST_F(SensorAlgorithmTest, SensorAlgorithmTest_005, TestSize.Level1) +HWTEST_F(SensorAlgorithmTest, SensorAlgorithmTest_006, TestSize.Level1) { - SEN_HILOGI("SensorAlgorithmTest_005 in"); + SEN_HILOGI("SensorAlgorithmTest_006 in"); std::vector inRotationMatrix(3); std::vector outRotationMatrix(THREE_DIMENSIONAL_MATRIX_LENGTH); int32_t ret = sensorAlgorithm.TransformCoordinateSystem(inRotationMatrix, 1, 2, outRotationMatrix); ASSERT_EQ(ret, OHOS::Sensors::PARAMETER_ERROR); } -HWTEST_F(SensorAlgorithmTest, SensorAlgorithmTest_006, TestSize.Level1) +HWTEST_F(SensorAlgorithmTest, SensorAlgorithmTest_007, TestSize.Level1) { - SEN_HILOGI("SensorAlgorithmTest_006 in"); + SEN_HILOGI("SensorAlgorithmTest_007 in"); std::vector inRotationMatrix = {1.5, 1.5, 1.5, 1.5, 1.5, 1.5, 1.5, 1.5, 1.5}; std::vector outRotationMatrix(THREE_DIMENSIONAL_MATRIX_LENGTH); int32_t ret = sensorAlgorithm.TransformCoordinateSystem(inRotationMatrix, 1, -1, outRotationMatrix); ASSERT_EQ(ret, OHOS::Sensors::PARAMETER_ERROR); } -HWTEST_F(SensorAlgorithmTest, SensorAlgorithmTest_007, TestSize.Level1) +HWTEST_F(SensorAlgorithmTest, SensorAlgorithmTest_008, TestSize.Level1) { - SEN_HILOGI("SensorAlgorithmTest_007 in"); + SEN_HILOGI("SensorAlgorithmTest_008 in"); std::vector inRotationMatrix = {1.5, 1.5, 1.5, 1.5, 1.5, 1.5, 1.5, 1.5, 1.5}; std::vector outRotationMatrix(THREE_DIMENSIONAL_MATRIX_LENGTH); int32_t ret = sensorAlgorithm.TransformCoordinateSystem(inRotationMatrix, -1, 1, outRotationMatrix); ASSERT_EQ(ret, OHOS::Sensors::PARAMETER_ERROR); } -HWTEST_F(SensorAlgorithmTest, SensorAlgorithmTest_008, TestSize.Level1) +HWTEST_F(SensorAlgorithmTest, SensorAlgorithmTest_009, TestSize.Level1) +{ + SEN_HILOGD("SensorAlgorithmTest_009 in"); + std::vector inRotationMatrix = {1.5, 1.5, 1.5, 1.5, 1.5, 1.5, 1.5, 1.5, 1.5}; + std::vector outRotationMatrix(THREE_DIMENSIONAL_MATRIX_LENGTH); + int32_t ret = sensorAlgorithm.TransformCoordinateSystem(inRotationMatrix, 0, 2, outRotationMatrix); + ASSERT_EQ(ret, OHOS::Sensors::PARAMETER_ERROR); + ret = sensorAlgorithm.TransformCoordinateSystem(inRotationMatrix, 3, 3, outRotationMatrix); + ASSERT_EQ(ret, OHOS::Sensors::PARAMETER_ERROR); +} + +HWTEST_F(SensorAlgorithmTest, SensorAlgorithmTest_010, TestSize.Level1) +{ + SEN_HILOGD("SensorAlgorithmTest_010 in"); + std::vector inRotationMatrix = {1.5, 1.5, 1.5, 1.5, 1.5, 1.5, 1.5, 1.5, 1.5}; + std::vector outRotationMatrix(THREE_DIMENSIONAL_MATRIX_LENGTH); + int32_t ret = sensorAlgorithm.TransformCoordinateSystem(inRotationMatrix, 1, 3, outRotationMatrix); + ASSERT_EQ(ret, OHOS::Sensors::SUCCESS); +} + +HWTEST_F(SensorAlgorithmTest, SensorAlgorithmTest_011, TestSize.Level1) +{ + SEN_HILOGD("SensorAlgorithmTest_011 in"); + std::vector inRotationMatrix = {1.5, 1.5, 1.5, 1.5, 1.5, 1.5, 1.5, 1.5, 1.5}; + int32_t ret = sensorAlgorithm.TransformCoordinateSystem(inRotationMatrix, 0, 2, inRotationMatrix); + ASSERT_EQ(ret, OHOS::Sensors::PARAMETER_ERROR); + ret = sensorAlgorithm.TransformCoordinateSystem(inRotationMatrix, 0, 2, inRotationMatrix); + ASSERT_EQ(ret, OHOS::Sensors::PARAMETER_ERROR); +} + +HWTEST_F(SensorAlgorithmTest, SensorAlgorithmTest_012, TestSize.Level1) +{ + SEN_HILOGD("SensorAlgorithmTest_012"); + std::vector inRotationMatrix = {1.5, 1.5, 1.5, 1.5, 1.5, 1.5, 1.5, 1.5, + 1.5, 1.5, 1.5, 1.5, 1.5, 1.5, 1.5, 1.5}; + std::vector outRotationMatrix(FOUR_DIMENSIONAL_MATRIX_LENGTH); + int32_t ret = sensorAlgorithm.TransformCoordinateSystem(inRotationMatrix, 1, 2, outRotationMatrix); + ASSERT_EQ(ret, OHOS::Sensors::SUCCESS); +} + +HWTEST_F(SensorAlgorithmTest, SensorAlgorithmTest_013, TestSize.Level1) { float altitude = -1.0; int32_t ret = sensorAlgorithm.GetAltitude(5.0, 0.0, &altitude); @@ -134,13 +185,13 @@ HWTEST_F(SensorAlgorithmTest, SensorAlgorithmTest_008, TestSize.Level1) ASSERT_EQ(altitude, 44330.0); } -HWTEST_F(SensorAlgorithmTest, SensorAlgorithmTest_009, TestSize.Level1) +HWTEST_F(SensorAlgorithmTest, SensorAlgorithmTest_014, TestSize.Level1) { int32_t ret = sensorAlgorithm.GetAltitude(5.0, 0.0, nullptr); ASSERT_EQ(ret, OHOS::Sensors::PARAMETER_ERROR); } -HWTEST_F(SensorAlgorithmTest, SensorAlgorithmTest_010, TestSize.Level1) +HWTEST_F(SensorAlgorithmTest, SensorAlgorithmTest_015, TestSize.Level1) { float geomagneticDip = -1.0; std::vector inclinationMatrix = {1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0}; @@ -149,14 +200,14 @@ HWTEST_F(SensorAlgorithmTest, SensorAlgorithmTest_010, TestSize.Level1) ASSERT_EQ(geomagneticDip, 0.8760581016540527); } -HWTEST_F(SensorAlgorithmTest, SensorAlgorithmTest_011, TestSize.Level1) +HWTEST_F(SensorAlgorithmTest, SensorAlgorithmTest_016, TestSize.Level1) { std::vector inclinationMatrix = {1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0}; int32_t ret = sensorAlgorithm.GetGeomagneticDip(inclinationMatrix, nullptr); ASSERT_EQ(ret, OHOS::Sensors::PARAMETER_ERROR); } -HWTEST_F(SensorAlgorithmTest, SensorAlgorithmTest_012, TestSize.Level1) +HWTEST_F(SensorAlgorithmTest, SensorAlgorithmTest_017, TestSize.Level1) { std::vector inclinationMatrix(3); float geomagneticDip = -1.0; @@ -164,7 +215,17 @@ HWTEST_F(SensorAlgorithmTest, SensorAlgorithmTest_012, TestSize.Level1) ASSERT_EQ(ret, OHOS::Sensors::PARAMETER_ERROR); } -HWTEST_F(SensorAlgorithmTest, SensorAlgorithmTest_013, TestSize.Level1) +HWTEST_F(SensorAlgorithmTest, SensorAlgorithmTest_018, TestSize.Level1) +{ + SEN_HILOGI("SensorAlgorithmTest_017 in"); + float geomagneticDip = -1.0; + std::vector inclinationMatrix = {1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, + 9.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0}; + int32_t ret = sensorAlgorithm.GetGeomagneticDip(inclinationMatrix, &geomagneticDip); + ASSERT_EQ(ret, OHOS::Sensors::SUCCESS); +} + +HWTEST_F(SensorAlgorithmTest, SensorAlgorithmTest_019, TestSize.Level1) { std::vector currotationMatrix = {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}; @@ -180,7 +241,7 @@ HWTEST_F(SensorAlgorithmTest, SensorAlgorithmTest_013, TestSize.Level1) } } -HWTEST_F(SensorAlgorithmTest, SensorAlgorithmTest_014, TestSize.Level1) +HWTEST_F(SensorAlgorithmTest, SensorAlgorithmTest_020, TestSize.Level1) { std::vector currotationMatrix(3); std::vector preRotationMatrix = {1.17549e-38, 1.17549e-38, 1.17549e-38, @@ -190,7 +251,7 @@ HWTEST_F(SensorAlgorithmTest, SensorAlgorithmTest_014, TestSize.Level1) ASSERT_EQ(ret, OHOS::Sensors::PARAMETER_ERROR); } -HWTEST_F(SensorAlgorithmTest, SensorAlgorithmTest_015, TestSize.Level1) +HWTEST_F(SensorAlgorithmTest, SensorAlgorithmTest_021, TestSize.Level1) { std::vector currotationMatrix = {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}; @@ -200,7 +261,7 @@ HWTEST_F(SensorAlgorithmTest, SensorAlgorithmTest_015, TestSize.Level1) ASSERT_EQ(ret, OHOS::Sensors::PARAMETER_ERROR); } -HWTEST_F(SensorAlgorithmTest, SensorAlgorithmTest_016, TestSize.Level1) +HWTEST_F(SensorAlgorithmTest, SensorAlgorithmTest_022, TestSize.Level1) { std::vector currotationMatrix = {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}; @@ -211,7 +272,7 @@ HWTEST_F(SensorAlgorithmTest, SensorAlgorithmTest_016, TestSize.Level1) ASSERT_EQ(ret, OHOS::Sensors::PARAMETER_ERROR); } -HWTEST_F(SensorAlgorithmTest, SensorAlgorithmTest_017, TestSize.Level1) +HWTEST_F(SensorAlgorithmTest, SensorAlgorithmTest_023, TestSize.Level1) { std::vector rotationMatrix = {1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0}; std::vector rotationAngle(ROTATION_VECTOR_LENGTH); @@ -224,7 +285,7 @@ HWTEST_F(SensorAlgorithmTest, SensorAlgorithmTest_017, TestSize.Level1) } } -HWTEST_F(SensorAlgorithmTest, SensorAlgorithmTest_018, TestSize.Level1) +HWTEST_F(SensorAlgorithmTest, SensorAlgorithmTest_024, TestSize.Level1) { std::vector rotationMatrix(5); std::vector rotationAngle(ROTATION_VECTOR_LENGTH); @@ -232,7 +293,7 @@ HWTEST_F(SensorAlgorithmTest, SensorAlgorithmTest_018, TestSize.Level1) ASSERT_EQ(ret, OHOS::Sensors::PARAMETER_ERROR); } -HWTEST_F(SensorAlgorithmTest, SensorAlgorithmTest_019, TestSize.Level1) +HWTEST_F(SensorAlgorithmTest, SensorAlgorithmTest_025, TestSize.Level1) { std::vector rotationMatrix = {1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0}; std::vector rotationAngle(ROTATION_VECTOR_LENGTH - 1); @@ -240,7 +301,7 @@ HWTEST_F(SensorAlgorithmTest, SensorAlgorithmTest_019, TestSize.Level1) ASSERT_EQ(ret, OHOS::Sensors::PARAMETER_ERROR); } -HWTEST_F(SensorAlgorithmTest, SensorAlgorithmTest_020, TestSize.Level1) +HWTEST_F(SensorAlgorithmTest, SensorAlgorithmTest_026, TestSize.Level1) { std::vector rotationVector = {0.0, 0.0, 0.0}; std::vector rotationMatrix(THREE_DIMENSIONAL_MATRIX_LENGTH); @@ -253,7 +314,7 @@ HWTEST_F(SensorAlgorithmTest, SensorAlgorithmTest_020, TestSize.Level1) } } -HWTEST_F(SensorAlgorithmTest, SensorAlgorithmTest_021, TestSize.Level1) +HWTEST_F(SensorAlgorithmTest, SensorAlgorithmTest_027, TestSize.Level1) { std::vector rotationVector(ROTATION_VECTOR_LENGTH - 1); std::vector rotationMatrix(THREE_DIMENSIONAL_MATRIX_LENGTH); @@ -261,7 +322,7 @@ HWTEST_F(SensorAlgorithmTest, SensorAlgorithmTest_021, TestSize.Level1) ASSERT_EQ(ret, OHOS::Sensors::PARAMETER_ERROR); } -HWTEST_F(SensorAlgorithmTest, SensorAlgorithmTest_022, TestSize.Level1) +HWTEST_F(SensorAlgorithmTest, SensorAlgorithmTest_028, TestSize.Level1) { std::vector rotationVector = {0.0, 0.0, 0.0}; std::vector rotationMatrix(ROTATION_VECTOR_LENGTH - 1); @@ -269,7 +330,25 @@ HWTEST_F(SensorAlgorithmTest, SensorAlgorithmTest_022, TestSize.Level1) ASSERT_EQ(ret, OHOS::Sensors::PARAMETER_ERROR); } -HWTEST_F(SensorAlgorithmTest, SensorAlgorithmTest_023, TestSize.Level1) +HWTEST_F(SensorAlgorithmTest, SensorAlgorithmTest_029, TestSize.Level1) +{ + SEN_HILOGI("SensorAlgorithmTest_028 in"); + std::vector rotationVector = {0.0, 0.0, 0.0, 0.0, 0.0}; + std::vector rotationMatrix(THREE_DIMENSIONAL_MATRIX_LENGTH); + int32_t ret = sensorAlgorithm.CreateRotationMatrix(rotationVector, rotationMatrix); + ASSERT_EQ(ret, OHOS::Sensors::PARAMETER_ERROR); +} + +HWTEST_F(SensorAlgorithmTest, SensorAlgorithmTest_030, TestSize.Level1) +{ + SEN_HILOGI("SensorAlgorithmTest_029 in"); + std::vector rotationVector = {0.0, 0.0, 0.0, 0.0}; + std::vector rotationMatrix(FOUR_DIMENSIONAL_MATRIX_LENGTH); + int32_t ret = sensorAlgorithm.CreateRotationMatrix(rotationVector, rotationMatrix); + ASSERT_EQ(ret, OHOS::Sensors::SUCCESS); +} + +HWTEST_F(SensorAlgorithmTest, SensorAlgorithmTest_031, TestSize.Level1) { std::vector gravity = {9.0, 9.0, 9.0}; std::vector geomagnetic = {30.0, 25.0, 41.0}; @@ -290,7 +369,7 @@ HWTEST_F(SensorAlgorithmTest, SensorAlgorithmTest_023, TestSize.Level1) } } -HWTEST_F(SensorAlgorithmTest, SensorAlgorithmTest_024, TestSize.Level1) +HWTEST_F(SensorAlgorithmTest, SensorAlgorithmTest_032, TestSize.Level1) { std::vector gravity(ROTATION_VECTOR_LENGTH - 1); std::vector geomagnetic = {30.0, 25.0, 41.0}; @@ -300,7 +379,7 @@ HWTEST_F(SensorAlgorithmTest, SensorAlgorithmTest_024, TestSize.Level1) ASSERT_EQ(ret, OHOS::Sensors::PARAMETER_ERROR); } -HWTEST_F(SensorAlgorithmTest, SensorAlgorithmTest_025, TestSize.Level1) +HWTEST_F(SensorAlgorithmTest, SensorAlgorithmTest_033, TestSize.Level1) { std::vector gravity = {9.0, 9.0, 9.0}; std::vector geomagnetic(ROTATION_VECTOR_LENGTH - 1); @@ -310,7 +389,7 @@ HWTEST_F(SensorAlgorithmTest, SensorAlgorithmTest_025, TestSize.Level1) ASSERT_EQ(ret, OHOS::Sensors::PARAMETER_ERROR); } -HWTEST_F(SensorAlgorithmTest, SensorAlgorithmTest_026, TestSize.Level1) +HWTEST_F(SensorAlgorithmTest, SensorAlgorithmTest_034, TestSize.Level1) { std::vector gravity = {9.0, 9.0, 9.0}; std::vector geomagnetic = {30.0, 25.0, 41.0}; @@ -320,7 +399,7 @@ HWTEST_F(SensorAlgorithmTest, SensorAlgorithmTest_026, TestSize.Level1) ASSERT_EQ(ret, OHOS::Sensors::PARAMETER_ERROR); } -HWTEST_F(SensorAlgorithmTest, SensorAlgorithmTest_027, TestSize.Level1) +HWTEST_F(SensorAlgorithmTest, SensorAlgorithmTest_035, TestSize.Level1) { std::vector gravity = {9.0, 9.0, 9.0}; std::vector geomagnetic = {30.0, 25.0, 41.0}; @@ -330,7 +409,7 @@ HWTEST_F(SensorAlgorithmTest, SensorAlgorithmTest_027, TestSize.Level1) ASSERT_EQ(ret, OHOS::Sensors::PARAMETER_ERROR); } -HWTEST_F(SensorAlgorithmTest, SensorAlgorithmTest_028, TestSize.Level1) +HWTEST_F(SensorAlgorithmTest, SensorAlgorithmTest_036, TestSize.Level1) { GeomagneticField geomagneticField(80.0, 0.0, 0.0, 1580486400000); ASSERT_TRUE(fabs(geomagneticField.ObtainX() - 6570.3935546875) < EPS); @@ -341,5 +420,39 @@ HWTEST_F(SensorAlgorithmTest, SensorAlgorithmTest_028, TestSize.Level1) ASSERT_TRUE(fabs(geomagneticField.ObtainLevelIntensity() - 6572.02294921875) < EPS); ASSERT_TRUE(fabs(geomagneticField.ObtainTotalIntensity() - 55000.0703125) < EPS); } + +HWTEST_F(SensorAlgorithmTest, SensorAlgorithmTest_037, TestSize.Level1) +{ + SEN_HILOGI("SensorAlgorithmTest_036 in"); + std::vector gravity = {0.1, 0.1, 0.1}; + std::vector geomagnetic = {30.0, 25.0, 41.0}; + std::vector rotationMatrix(THREE_DIMENSIONAL_MATRIX_LENGTH); + std::vector inclinationMatrix(THREE_DIMENSIONAL_MATRIX_LENGTH); + int32_t ret = sensorAlgorithm.CreateRotationAndInclination(gravity, geomagnetic, rotationMatrix, inclinationMatrix); + ASSERT_EQ(ret, OHOS::Sensors::PARAMETER_ERROR); +} + +HWTEST_F(SensorAlgorithmTest, SensorAlgorithmTest_038, TestSize.Level1) +{ + SEN_HILOGI("SensorAlgorithmTest_037 in"); + std::vector gravity = {9.0, 9.0, 9.0}; + std::vector geomagnetic = {9.0, 9.0, 9.0}; + std::vector rotationMatrix(THREE_DIMENSIONAL_MATRIX_LENGTH); + std::vector inclinationMatrix(THREE_DIMENSIONAL_MATRIX_LENGTH); + int32_t ret = sensorAlgorithm.CreateRotationAndInclination(gravity, geomagnetic, rotationMatrix, inclinationMatrix); + ASSERT_EQ(ret, OHOS::Sensors::PARAMETER_ERROR); +} + +HWTEST_F(SensorAlgorithmTest, SensorAlgorithmTest_039, TestSize.Level1) +{ + SEN_HILOGI("SensorAlgorithmTest_038 in"); + std::vector gravity = {9.0, 9.0, 9.0}; + std::vector geomagnetic = {30.0, 25.0, 41.0}; + std::vector rotationMatrix(FOUR_DIMENSIONAL_MATRIX_LENGTH); + std::vector inclinationMatrix(THREE_DIMENSIONAL_MATRIX_LENGTH); + int32_t ret = sensorAlgorithm.CreateRotationAndInclination(gravity, geomagnetic, rotationMatrix, inclinationMatrix); + ASSERT_EQ(ret, OHOS::Sensors::SUCCESS); +} + } // namespace Sensors } // namespace OHOS diff --git a/test/unittest/interfaces/js/sensor/config.json b/test/unittest/interfaces/js/sensor/config.json index aabb3f4b8a5544b29581e64aedf217387cef1dfd..435079f98c0281c4efd6a1517338ce41b1942a05 100644 --- a/test/unittest/interfaces/js/sensor/config.json +++ b/test/unittest/interfaces/js/sensor/config.json @@ -57,7 +57,8 @@ "name": ".MyApplication", "deviceType": [ "default", - "tablet" + "tablet", + "2inl" ], "distro": { "deliveryWithInstall": true, diff --git a/test/unittest/interfaces/kits/sensor_native_test.cpp b/test/unittest/interfaces/kits/sensor_native_test.cpp index 650165dab01a41b74001ec4bb2202d201ecdf31f..f2125c7d8dba94bdbcd27e973b8748f3d7194d37 100644 --- a/test/unittest/interfaces/kits/sensor_native_test.cpp +++ b/test/unittest/interfaces/kits/sensor_native_test.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2023 Huawei Device Co., Ltd. + * Copyright (c) 2023-2024 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -42,7 +42,7 @@ constexpr int64_t INVALID_VALUE = -1; constexpr float INVALID_RESOLUTION = -1.0F; Sensor_Subscriber *g_user = nullptr; std::atomic_bool g_existAmbientLight = false; -} // namespace +} // namespace class SensorAgentTest : public testing::Test { public: @@ -111,6 +111,27 @@ void SensorDataCallbackImpl(Sensor_Event *event) } } +void SensorDataCallbackImpl1(Sensor_Event *event) +{ + if (event == nullptr) { + SEN_HILOGE("event is null"); + return; + } + int64_t *timestamp = nullptr; + int32_t ret = OH_SensorEvent_GetTimestamp(event, timestamp); + ASSERT_EQ(ret, SENSOR_PARAMETER_ERROR); + Sensor_Type *sensorType = nullptr; + ret = OH_SensorEvent_GetType(event, sensorType); + ASSERT_EQ(ret, SENSOR_PARAMETER_ERROR); + Sensor_Accuracy *accuracy = nullptr; + ret = OH_SensorEvent_GetAccuracy(event, accuracy); + ASSERT_EQ(ret, SENSOR_PARAMETER_ERROR); + float *data = nullptr; + uint32_t *length = nullptr; + ret = OH_SensorEvent_GetData(event, &data, length); + ASSERT_EQ(ret, SENSOR_PARAMETER_ERROR); +} + HWTEST_F(SensorAgentTest, OH_Sensor_GetInfos_001, TestSize.Level1) { SEN_HILOGI("OH_Sensor_GetInfos_001 in"); @@ -153,12 +174,175 @@ HWTEST_F(SensorAgentTest, OH_Sensor_GetInfos_001, TestSize.Level1) HWTEST_F(SensorAgentTest, OH_Sensor_GetInfos_002, TestSize.Level1) { - SEN_HILOGI("OH_Sensor_GetInfos_003 in"); + SEN_HILOGI("OH_Sensor_GetInfos_002 in"); Sensor_Info *sensors { nullptr }; int32_t ret = OH_Sensor_GetInfos(&sensors, nullptr); ASSERT_NE(ret, SENSOR_SUCCESS); } +HWTEST_F(SensorAgentTest, OH_Sensor_GetInfos_003, TestSize.Level1) +{ + SEN_HILOGE("OH_Sensor_GetInfos_003 in"); + uint32_t count = 0; + int32_t ret = OH_Sensor_GetInfos(nullptr, &count); + ASSERT_EQ(ret, SENSOR_SUCCESS); + ASSERT_NE(0, count); + + auto sensors = new Sensor_Info *[count]; + for (uint32_t i = 0; i < count; ++i) { + if (sensors[i] != nullptr) { + sensors[i] = nullptr; + } + } + ret = OH_Sensor_GetInfos(sensors, &count); + ASSERT_EQ(ret, SENSOR_PARAMETER_ERROR); + + ret = OH_Sensor_DestroyInfos(sensors, count); + ASSERT_EQ(ret, SENSOR_SUCCESS); +} + +HWTEST_F(SensorAgentTest, OH_Sensor_GetInfos_004, TestSize.Level1) +{ + SEN_HILOGE("OH_Sensor_GetInfos_004 in"); + uint32_t count = 0; + int32_t ret = OH_Sensor_GetInfos(nullptr, &count); + ASSERT_EQ(ret, SENSOR_SUCCESS); + ASSERT_NE(0, count); + Sensor_Info **sensors = OH_Sensor_CreateInfos(count); + ASSERT_NE(sensors, nullptr); + char sensorName[SENSOR_NAME_LENGTH_MAX] = {}; + uint32_t length = SENSOR_NAME_LENGTH_MAX; + + auto sensors1 = new Sensor_Info *[count]; + for (uint32_t i = 0; i < count; ++i) { + if (sensors1[i] != nullptr) { + sensors1[i] = nullptr; + } + } + ret = OH_SensorInfo_GetName(sensors1[0], sensorName, &length); + ASSERT_EQ(ret, SENSOR_PARAMETER_ERROR); + ret = OH_Sensor_DestroyInfos(sensors1, count); + ASSERT_EQ(ret, SENSOR_SUCCESS); + + char *sensorName1 = nullptr; + ret = OH_SensorInfo_GetName(sensors[0], sensorName1, &length); + ASSERT_EQ(ret, SENSOR_PARAMETER_ERROR); + + uint32_t *length1 = nullptr; + ret = OH_SensorInfo_GetName(sensors[0], sensorName, length1); + ASSERT_EQ(ret, SENSOR_PARAMETER_ERROR); + + ret = OH_Sensor_DestroyInfos(sensors, count); + ASSERT_EQ(ret, SENSOR_SUCCESS); +} + +HWTEST_F(SensorAgentTest, OH_Sensor_GetInfos_005, TestSize.Level1) +{ + SEN_HILOGE("OH_Sensor_GetInfos_005 in"); + uint32_t count = 0; + int32_t ret = OH_Sensor_GetInfos(nullptr, &count); + ASSERT_EQ(ret, SENSOR_SUCCESS); + ASSERT_NE(0, count); + Sensor_Info **sensors = OH_Sensor_CreateInfos(count); + ASSERT_NE(sensors, nullptr); + char sensorName[SENSOR_NAME_LENGTH_MAX] = {}; + uint32_t length = SENSOR_NAME_LENGTH_MAX; + + ret = OH_SensorInfo_GetName(sensors[0], sensorName, &length); + ASSERT_EQ(ret, SENSOR_PARAMETER_ERROR); + + ret = OH_Sensor_GetInfos(sensors, &count); + length = 0; + ret = OH_SensorInfo_GetName(sensors[0], sensorName, &length); + ASSERT_EQ(ret, SENSOR_PARAMETER_ERROR); + + ret = OH_Sensor_DestroyInfos(sensors, count); + ASSERT_EQ(ret, SENSOR_SUCCESS); +} + +HWTEST_F(SensorAgentTest, OH_Sensor_GetInfos_006, TestSize.Level1) +{ + SEN_HILOGE("OH_Sensor_GetInfos_006 in"); + uint32_t count = 0; + int32_t ret = OH_Sensor_GetInfos(nullptr, &count); + ASSERT_EQ(ret, SENSOR_SUCCESS); + ASSERT_NE(0, count); + Sensor_Info **sensors = OH_Sensor_CreateInfos(count); + ASSERT_NE(sensors, nullptr); + char vendorName[SENSOR_NAME_LENGTH_MAX] = {}; + uint32_t length = SENSOR_NAME_LENGTH_MAX; + + auto sensors1 = new Sensor_Info *[count]; + for (uint32_t i = 0; i < count; ++i) { + if (sensors1[i] != nullptr) { + sensors1[i] = nullptr; + } + } + ret = OH_SensorInfo_GetVendorName(sensors1[0], vendorName, &length); + ASSERT_EQ(ret, SENSOR_PARAMETER_ERROR); + ret = OH_Sensor_DestroyInfos(sensors1, count); + ASSERT_EQ(ret, SENSOR_SUCCESS); + + char *vendorName1 = nullptr; + ret = OH_SensorInfo_GetVendorName(sensors[0], vendorName1, &length); + ASSERT_EQ(ret, SENSOR_PARAMETER_ERROR); + + uint32_t *length1 = nullptr; + ret = OH_SensorInfo_GetVendorName(sensors[0], vendorName, length1); + ASSERT_EQ(ret, SENSOR_PARAMETER_ERROR); + + ret = OH_Sensor_DestroyInfos(sensors, count); + ASSERT_EQ(ret, SENSOR_SUCCESS); +} + +HWTEST_F(SensorAgentTest, OH_Sensor_GetInfos_007, TestSize.Level1) +{ + SEN_HILOGE("OH_Sensor_GetInfos_007 in"); + uint32_t count = 0; + int32_t ret = OH_Sensor_GetInfos(nullptr, &count); + ASSERT_EQ(ret, SENSOR_SUCCESS); + ASSERT_NE(0, count); + Sensor_Info **sensors = OH_Sensor_CreateInfos(count); + ASSERT_NE(sensors, nullptr); + char sensorName[SENSOR_NAME_LENGTH_MAX] = {}; + uint32_t length = SENSOR_NAME_LENGTH_MAX; + + ret = OH_SensorInfo_GetVendorName(sensors[0], sensorName, &length); + ASSERT_EQ(ret, SENSOR_PARAMETER_ERROR); + + ret = OH_Sensor_GetInfos(sensors, &count); + length = 0; + ret = OH_SensorInfo_GetVendorName(sensors[0], sensorName, &length); + ASSERT_EQ(ret, SENSOR_PARAMETER_ERROR); + + ret = OH_Sensor_DestroyInfos(sensors, count); + ASSERT_EQ(ret, SENSOR_SUCCESS); +} + +HWTEST_F(SensorAgentTest, OH_Sensor_GetInfos_008, TestSize.Level1) +{ + SEN_HILOGE("OH_Sensor_GetInfos_008 in"); + uint32_t count = 0; + OH_Sensor_GetInfos(nullptr, &count); + auto sensors = new Sensor_Info *[count]; + + Sensor_Type *sensorType = nullptr; + int32_t ret = OH_SensorInfo_GetType(sensors[0], sensorType); + ASSERT_EQ(ret, SENSOR_PARAMETER_ERROR); + + float *resolution = nullptr; + ret = OH_SensorInfo_GetResolution(sensors[0], resolution); + ASSERT_EQ(ret, SENSOR_PARAMETER_ERROR); + + int64_t *minSamplePeriod = nullptr; + ret = OH_SensorInfo_GetMinSamplingInterval(sensors[0], minSamplePeriod); + ASSERT_EQ(ret, SENSOR_PARAMETER_ERROR); + + int64_t *maxSamplePeriod = nullptr; + ret = OH_SensorInfo_GetMaxSamplingInterval(sensors[0], maxSamplePeriod); + ASSERT_EQ(ret, SENSOR_PARAMETER_ERROR); +} + HWTEST_F(SensorAgentTest, OH_Sensor_Subscribe_001, TestSize.Level1) { SEN_HILOGI("OH_Sensor_Subscribe_001 in"); @@ -259,6 +443,82 @@ HWTEST_F(SensorAgentTest, OH_Sensor_Subscribe_004, TestSize.Level1) } } +HWTEST_F(SensorAgentTest, OH_Sensor_Subscribe_005, TestSize.Level1) +{ + SEN_HILOGI("OH_Sensor_Subscribe_005 in"); + g_user = OH_Sensor_CreateSubscriber(); + int32_t ret = OH_SensorSubscriber_SetCallback(g_user, SensorDataCallbackImpl); + ASSERT_EQ(ret, SENSOR_SUCCESS); + Sensor_SubscriptionId *id = OH_Sensor_CreateSubscriptionId(); + Sensor_SubscriptionAttribute *attr = OH_Sensor_CreateSubscriptionAttribute(); + ret = OH_SensorSubscriptionAttribute_SetSamplingInterval(attr, SENSOR_SAMPLE_PERIOD); + ASSERT_EQ(ret, SENSOR_SUCCESS); + ret = OH_Sensor_Subscribe(id, attr, g_user); + ASSERT_EQ(ret, SENSOR_SERVICE_EXCEPTION); +} + +HWTEST_F(SensorAgentTest, OH_Sensor_Subscribe_006, TestSize.Level1) +{ + SEN_HILOGI("OH_Sensor_Subscribe_006 in"); + if (g_existAmbientLight) { + g_user = OH_Sensor_CreateSubscriber(); + int32_t ret = OH_SensorSubscriber_SetCallback(g_user, SensorDataCallbackImpl); + ASSERT_EQ(ret, SENSOR_SUCCESS); + Sensor_SubscriptionId *id = OH_Sensor_CreateSubscriptionId(); + ret = OH_SensorSubscriptionId_SetType(id, SENSOR_ID); + ASSERT_EQ(ret, SENSOR_SUCCESS); + Sensor_SubscriptionAttribute *attr = OH_Sensor_CreateSubscriptionAttribute(); + ret = OH_Sensor_Subscribe(id, attr, g_user); + ASSERT_EQ(ret, SENSOR_SERVICE_EXCEPTION); + } +} + +HWTEST_F(SensorAgentTest, OH_Sensor_Subscribe_007, TestSize.Level1) +{ + SEN_HILOGI("OH_Sensor_Subscribe_007 in"); + g_user = OH_Sensor_CreateSubscriber(); + int32_t ret = OH_SensorSubscriber_SetCallback(g_user, SensorDataCallbackImpl); + ASSERT_EQ(ret, SENSOR_SUCCESS); + Sensor_SubscriptionId *id = OH_Sensor_CreateSubscriptionId(); + ret = OH_Sensor_Unsubscribe(id, g_user); + ASSERT_EQ(ret, SENSOR_SERVICE_EXCEPTION); +} + +HWTEST_F(SensorAgentTest, OH_Sensor_Subscribe_008, TestSize.Level1) +{ + SEN_HILOGI("OH_Sensor_Subscribe_008 in"); + if (g_existAmbientLight) { + g_user = OH_Sensor_CreateSubscriber(); + int32_t ret = OH_SensorSubscriber_SetCallback(g_user, SensorDataCallbackImpl1); + ASSERT_EQ(ret, SENSOR_SUCCESS); + + Sensor_SubscriptionId *id = OH_Sensor_CreateSubscriptionId(); + ret = OH_SensorSubscriptionId_SetType(id, SENSOR_ID); + ASSERT_EQ(ret, SENSOR_SUCCESS); + + Sensor_SubscriptionAttribute *attr = OH_Sensor_CreateSubscriptionAttribute(); + ret = OH_SensorSubscriptionAttribute_SetSamplingInterval(attr, SENSOR_SAMPLE_PERIOD); + ASSERT_EQ(ret, SENSOR_SUCCESS); + + ret = OH_Sensor_Subscribe(id, attr, g_user); + ASSERT_EQ(ret, SENSOR_SUCCESS); + + std::this_thread::sleep_for(std::chrono::milliseconds(SLEEP_TIME_MS)); + ret = OH_Sensor_Unsubscribe(id, g_user); + ASSERT_EQ(ret, SENSOR_SUCCESS); + if (id != nullptr) { + OH_Sensor_DestroySubscriptionId(id); + } + if (attr != nullptr) { + OH_Sensor_DestroySubscriptionAttribute(attr); + } + if (g_user != nullptr) { + OH_Sensor_DestroySubscriber(g_user); + g_user = nullptr; + } + } +} + HWTEST_F(SensorAgentTest, OH_Sensor_Unsubscribe_001, TestSize.Level1) { SEN_HILOGI("OH_Sensor_Unsubscribe_001 in"); @@ -314,6 +574,35 @@ HWTEST_F(SensorAgentTest, OH_SensorSubscriptionId_GetType_002, TestSize.Level1) } } +HWTEST_F(SensorAgentTest, OH_SensorSubscriptionId_GetType_003, TestSize.Level1) +{ + SEN_HILOGI("OH_SensorSubscriptionId_GetType_003 in"); + Sensor_SubscriptionId *id = OH_Sensor_CreateSubscriptionId(); + Sensor_Type type; + int32_t ret = OH_SensorSubscriptionId_GetType(id, &type); + ASSERT_EQ(ret, SENSOR_SUCCESS); + if (id != nullptr) { + OH_Sensor_DestroySubscriptionId(id); + } +} + + +HWTEST_F(SensorAgentTest, OH_SensorSubscriptionId_GetType_004, TestSize.Level1) +{ + SEN_HILOGI("OH_SensorSubscriptionId_GetType_004 in"); + Sensor_SubscriptionId *id = nullptr; + + int32_t ret = OH_Sensor_DestroySubscriptionId(id); + ASSERT_EQ(ret, SENSOR_PARAMETER_ERROR); + + Sensor_SubscriptionAttribute *attr = nullptr; + ret = OH_Sensor_DestroySubscriptionAttribute(attr); + ASSERT_EQ(ret, SENSOR_PARAMETER_ERROR); + + ret = OH_Sensor_DestroySubscriber(g_user); + ASSERT_EQ(ret, SENSOR_PARAMETER_ERROR); +} + HWTEST_F(SensorAgentTest, OH_SensorSubscriptionAttribute_SetSamplingInterval_001, TestSize.Level1) { @@ -357,6 +646,19 @@ HWTEST_F(SensorAgentTest, OH_SensorSubscriptionAttribute_GetSamplingInterval_002 } } +HWTEST_F(SensorAgentTest, OH_SensorSubscriptionAttribute_GetSamplingInterval_003, + TestSize.Level1) +{ + SEN_HILOGI("OH_SensorSubscriptionAttribute_GetSamplingInterval_003 in"); + Sensor_SubscriptionAttribute *attr = OH_Sensor_CreateSubscriptionAttribute(); + int64_t samplingInterval = 0; + int32_t ret = OH_SensorSubscriptionAttribute_GetSamplingInterval(attr, &samplingInterval); + ASSERT_EQ(ret, SENSOR_SUCCESS); + if (attr != nullptr) { + OH_Sensor_DestroySubscriptionAttribute(attr); + } +} + HWTEST_F(SensorAgentTest, OH_SensorSubscriber_SetCallback_001, TestSize.Level1) { SEN_HILOGI("OH_SensorSubscriber_SetCallback_001 in"); @@ -372,6 +674,14 @@ HWTEST_F(SensorAgentTest, OH_SensorSubscriber_SetCallback_002, TestSize.Level1) ASSERT_EQ(ret, SENSOR_PARAMETER_ERROR); } +HWTEST_F(SensorAgentTest, OH_SensorSubscriber_SetCallback_003, TestSize.Level1) +{ + SEN_HILOGI("OH_SensorSubscriber_SetCallback_003 in"); + g_user = OH_Sensor_CreateSubscriber(); + int32_t ret = OH_SensorSubscriber_SetCallback(g_user, SensorDataCallbackImpl); + ASSERT_EQ(ret, SENSOR_SUCCESS); +} + HWTEST_F(SensorAgentTest, OH_SensorSubscriber_GetCallback_001, TestSize.Level1) { SEN_HILOGI("OH_SensorSubscriber_GetCallback_001 in"); @@ -390,5 +700,17 @@ HWTEST_F(SensorAgentTest, OH_SensorSubscriber_GetCallback_002, TestSize.Level1) OH_Sensor_DestroySubscriber(g_user); } } -} // namespace Sensors -} // namespace OHOS + +HWTEST_F(SensorAgentTest, OH_SensorSubscriber_GetCallback_003, TestSize.Level1) +{ + SEN_HILOGI("OH_SensorSubscriber_GetCallback_003 in"); + g_user = OH_Sensor_CreateSubscriber(); + Sensor_EventCallback callback; + int32_t ret = OH_SensorSubscriber_GetCallback(g_user, &callback); + ASSERT_EQ(ret, SENSOR_SUCCESS); + if (g_user != nullptr) { + OH_Sensor_DestroySubscriber(g_user); + } +} +} // namespace Sensors +} // namespace OHOS diff --git a/utils/common/BUILD.gn b/utils/common/BUILD.gn index 48bce26e0b22d0f7f21321a598905ed917336150..093c0f2b9134af96ee2100e6b1911b373bc919cc 100644 --- a/utils/common/BUILD.gn +++ b/utils/common/BUILD.gn @@ -18,6 +18,7 @@ ohos_shared_library("libsensor_utils") { sources = [ "src/active_info.cpp", "src/permission_util.cpp", + "src/print_sensor_data.cpp", "src/report_data_callback.cpp", "src/sensor.cpp", "src/sensor_basic_data_channel.cpp", @@ -43,10 +44,14 @@ ohos_shared_library("libsensor_utils") { "access_token:libprivacy_sdk", "c_utils:utils", "hilog:libhilog", - "hisysevent:libhisysevent", "ipc:ipc_single", ] + defines = sensor_default_defines + if (hiviewdfx_hisysevent_enable) { + external_deps += [ "hisysevent:libhisysevent" ] + } + innerapi_tags = [ "platformsdk_indirect" ] part_name = "sensor" subsystem_name = "sensors" diff --git a/test/fuzztest/services/service/onstart_fuzzer/onstart_fuzzer.h b/utils/common/include/print_sensor_data.h similarity index 31% rename from test/fuzztest/services/service/onstart_fuzzer/onstart_fuzzer.h rename to utils/common/include/print_sensor_data.h index 67dc3af37fdf06e139d430f50ece4937698f77cc..db5d36b6f2da551d05a58e4a361dd721987f5511 100644 --- a/test/fuzztest/services/service/onstart_fuzzer/onstart_fuzzer.h +++ b/utils/common/include/print_sensor_data.h @@ -13,10 +13,49 @@ * limitations under the License. */ -#ifndef ON_START_FUZZER_H -#define ON_START_FUZZER_H +#ifndef PRINT_SENSOR_DATA +#define PRINT_SENSOR_DATA -#define FUZZ_PROJECT_NAME "onstart_fuzzer" +#include -#endif // ON_START_FUZZER_H +#include "singleton.h" +#include "sensor_agent_type.h" +#include "sensor_data_event.h" + +namespace OHOS { +namespace Sensors { + + +class PrintSensorData : public Singleton { +public: + PrintSensorData() = default; + virtual ~PrintSensorData() {}; + void ControlSensorClientPrint(const SensorUser *user, const SensorEvent &event); + void ControlSensorHdiPrint(const SensorData &sensorData); + void ResetHdiCounter(int32_t sensorId); + bool IsContinuousType(int32_t sensorId); + void SavePrintUserInfo(const SensorUser *user); + void RemovePrintUserInfo(const SensorUser *user); + +private: + void PrintClientData(const SensorEvent &event); + void PrintHdiData(const SensorData &sensorData); + int32_t GetDataDimension(int32_t sensorId); + struct LogPrintInfo { + int32_t count { 0 }; + int64_t lastTime { 0 }; + }; + std::mutex hdiLoginfoMutex_; + std::mutex clientLoginfoMutex_; + LogPrintInfo info_; + std::map hdiLoginfo_ = { + {SENSOR_TYPE_ID_POSTURE, info_}, + {SENSOR_TYPE_ID_AMBIENT_LIGHT, info_}, + {SENSOR_TYPE_ID_MAGNETIC_FIELD, info_}, + }; + std::map clientLoginfo_; +}; +} // namespace Sensors +} // namespace OHOS +#endif // PRINT_SENSOR_DATA diff --git a/utils/common/src/print_sensor_data.cpp b/utils/common/src/print_sensor_data.cpp new file mode 100644 index 0000000000000000000000000000000000000000..4f635d7d437320b934bf5bb9ecf186a8c186c18c --- /dev/null +++ b/utils/common/src/print_sensor_data.cpp @@ -0,0 +1,205 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "print_sensor_data.h" + +#include +#include + +#include "sensor_errors.h" + +#undef LOG_TAG +#define LOG_TAG "PrintSensorData" + +namespace OHOS { +namespace Sensors { +namespace { +enum { + ONE_DIMENSION = 1, + TWO_DIMENSION = 2, + THREE_DIMENSION = 3, + SEVEN_DIMENSION = 7, + DEFAULT_DIMENSION = 16 +}; +constexpr int64_t LOG_INTERVAL = 60000000000L; +constexpr int32_t FIRST_PRINT_TIMES = 20; +constexpr float LOG_FORMAT_DIVIDER = 1e9f; + +const std::vector g_triggerSensorType = { + SENSOR_TYPE_ID_HALL_EXT, + SENSOR_TYPE_ID_PROXIMITY, + SENSOR_TYPE_ID_HALL, +}; +const std::vector g_continuousSensorType = { + SENSOR_TYPE_ID_POSTURE, + SENSOR_TYPE_ID_AMBIENT_LIGHT, + SENSOR_TYPE_ID_MAGNETIC_FIELD, +}; +} + +void PrintSensorData::ControlSensorHdiPrint(const SensorData &sensorData) +{ + auto triggerIt = std::find(g_triggerSensorType.begin(), g_triggerSensorType.end(), sensorData.sensorTypeId); + if (triggerIt != g_triggerSensorType.end()) { + PrintHdiData(sensorData); + } + std::lock_guard hdiLoginfoLock(hdiLoginfoMutex_); + auto it = hdiLoginfo_.find(sensorData.sensorTypeId); + if (it == hdiLoginfo_.end()) { + return; + } + if (it->second.count < FIRST_PRINT_TIMES) { + PrintHdiData(sensorData); + if (it->second.count == FIRST_PRINT_TIMES - 1) { + it->second.lastTime = sensorData.timestamp; + } + it->second.count++; + } else { + if (sensorData.timestamp - it->second.lastTime >= LOG_INTERVAL) { + PrintHdiData(sensorData); + it->second.lastTime = sensorData.timestamp; + } + } +} + +void PrintSensorData::PrintHdiData(const SensorData &sensorData) +{ + std::string str; + str += "sensorId: " + std::to_string(sensorData.sensorTypeId) + ", "; + str += "timestamp: " + std::to_string(sensorData.timestamp / LOG_FORMAT_DIVIDER) + ", "; + int32_t dataDim = GetDataDimension(sensorData.sensorTypeId); + auto data = reinterpret_cast(sensorData.data); + CHKPV(data); + for (int32_t i = 0; i < dataDim; ++i) { + str.append(std::to_string(*data)); + if (i != dataDim - 1) { + str.append(", "); + } + ++data; + } + str.append("\n"); + SEN_HILOGI("SensorData: %{public}s", str.c_str()); +} + +int32_t PrintSensorData::GetDataDimension(int32_t sensorId) +{ + switch (sensorId) { + case SENSOR_TYPE_ID_HALL: + case SENSOR_TYPE_ID_PROXIMITY: + return ONE_DIMENSION; + case SENSOR_TYPE_ID_HALL_EXT: + return TWO_DIMENSION; + case SENSOR_TYPE_ID_POSTURE: + return SEVEN_DIMENSION; + case SENSOR_TYPE_ID_AMBIENT_LIGHT: + case SENSOR_TYPE_ID_MAGNETIC_FIELD: + return THREE_DIMENSION; + default: + SEN_HILOGW("Unknown sensorId:%{public}d, size:%{public}d", sensorId, DEFAULT_DIMENSION); + return DEFAULT_DIMENSION; + } +} + +void PrintSensorData::ControlSensorClientPrint(const SensorUser *user, const SensorEvent &event) +{ + auto triggerIt = std::find(g_triggerSensorType.begin(), g_triggerSensorType.end(), event.sensorTypeId); + if (triggerIt != g_triggerSensorType.end()) { + PrintClientData(event); + } + + auto continuosIt = std::find(g_continuousSensorType.begin(), g_continuousSensorType.end(), event.sensorTypeId); + if (continuosIt == g_continuousSensorType.end()) { + return; + } + std::lock_guard clientLoginfoLock(clientLoginfoMutex_); + auto it = clientLoginfo_.find(user); + if (it == clientLoginfo_.end()) { + return; + } + if (it->second.count < FIRST_PRINT_TIMES) { + PrintClientData(event); + if (it->second.count == FIRST_PRINT_TIMES - 1) { + it->second.lastTime = event.timestamp; + } + it->second.count++; + } else { + if (event.timestamp - it->second.lastTime >= LOG_INTERVAL) { + PrintClientData(event); + it->second.lastTime = event.timestamp; + } + } +} + +void PrintSensorData::PrintClientData(const SensorEvent &event) +{ + std::string str; + str += "sensorId: " + std::to_string(event.sensorTypeId) + ", "; + str += "timestamp: " + std::to_string(event.timestamp / LOG_FORMAT_DIVIDER) + ", "; + int32_t dataDim = GetDataDimension(event.sensorTypeId); + auto data = reinterpret_cast(event.data); + CHKPV(data); + for (int32_t i = 0; i < dataDim; ++i) { + str.append(std::to_string(*data)); + if (i != dataDim - 1) { + str.append(", "); + } + ++data; + } + str.append("\n"); + SEN_HILOGI("SensorData: %{public}s", str.c_str()); +} + +bool PrintSensorData::IsContinuousType(int32_t sensorId) +{ + return std::find(g_continuousSensorType.begin(), g_continuousSensorType.end(), + sensorId) != g_continuousSensorType.end(); +} + +void PrintSensorData::SavePrintUserInfo(const SensorUser *user) +{ + CHKPV(user); + std::lock_guard clientLoginfoLock(clientLoginfoMutex_); + if (clientLoginfo_.find(user) != clientLoginfo_.end()) { + return; + } + LogPrintInfo info; + auto status = clientLoginfo_.insert(std::make_pair(user, info)); + if (!status.second) { + SEN_HILOGD("User has been subscribed"); + } +} + +void PrintSensorData::RemovePrintUserInfo(const SensorUser *user) +{ + CHKPV(user); + std::lock_guard clientLoginfoLock(clientLoginfoMutex_); + if (clientLoginfo_.find(user) == clientLoginfo_.end()) { + return; + } + clientLoginfo_.erase(user); +} + +void PrintSensorData::ResetHdiCounter(int32_t sensorId) +{ + std::lock_guard hdiLoginfoLock(hdiLoginfoMutex_); + auto it = hdiLoginfo_.find(sensorId); + if (it == hdiLoginfo_.end()) { + return; + } + it->second.count = 0; + it->second.lastTime = 0; +} +} // namespace Sensors +} // namespace OHOS diff --git a/utils/common/src/report_data_callback.cpp b/utils/common/src/report_data_callback.cpp index 12e882fd526e53dfb271899d810975d362f0de0b..cd4e0d049ef55d3adab657ae35f882036133baec 100644 --- a/utils/common/src/report_data_callback.cpp +++ b/utils/common/src/report_data_callback.cpp @@ -64,16 +64,16 @@ int32_t ReportDataCallback::ReportEventCallback(SensorData *sensorData, sptreventsBuf_.circularBuf[cb->eventsBuf_.writePosition] = *sensorData; cb->eventsBuf_.writePosition += 1; } - if (leftSize < 1) { - cb->eventsBuf_.readPos = cb->eventsBuf_.writePosition; - } cb->eventsBuf_.eventNum += 1; if (cb->eventsBuf_.eventNum >= CIRCULAR_BUF_LEN) { cb->eventsBuf_.eventNum = CIRCULAR_BUF_LEN; } - if (cb->eventsBuf_.writePosition == CIRCULAR_BUF_LEN) { + if (cb->eventsBuf_.writePosition >= CIRCULAR_BUF_LEN) { cb->eventsBuf_.writePosition = 0; } + if (leftSize < 1) { + cb->eventsBuf_.readPos = cb->eventsBuf_.writePosition; + } return ERR_OK; } diff --git a/utils/common/src/sensor_basic_data_channel.cpp b/utils/common/src/sensor_basic_data_channel.cpp index 39c435ad720c43ae517e2b5ddc67deed210e1a37..1851b6c63cb274c4759b8ee03da48a1eedd772b2 100644 --- a/utils/common/src/sensor_basic_data_channel.cpp +++ b/utils/common/src/sensor_basic_data_channel.cpp @@ -19,7 +19,9 @@ #include #include +#ifdef HIVIEWDFX_HISYSEVENT_ENABLE #include "hisysevent.h" +#endif // HIVIEWDFX_HISYSEVENT_ENABLE #include "sensor_errors.h" #undef LOG_TAG @@ -49,8 +51,10 @@ int32_t SensorBasicDataChannel::CreateSensorBasicChannel() int32_t socketPair[SOCKET_PAIR_SIZE] = { 0 }; if (socketpair(AF_UNIX, SOCK_SEQPACKET, 0, socketPair) != 0) { +#ifdef HIVIEWDFX_HISYSEVENT_ENABLE HiSysEventWrite(HiviewDFX::HiSysEvent::Domain::SENSOR, "DATA_CHANNEL_EXCEPTION", HiSysEvent::EventType::FAULT, "PKG_NAME", "CreateSensorBasicChannel", "ERROR_CODE", errno); +#endif // HIVIEWDFX_HISYSEVENT_ENABLE SEN_HILOGE("Create socketpair failed"); sendFd_ = -1; receiveFd_ = -1; diff --git a/utils/ipc/BUILD.gn b/utils/ipc/BUILD.gn index 9bbc90d6e17fdd3fb34c8f19825587857a4f4364..a37332ae66b71c095bf6d6aaef5e4f1ba842a88c 100644 --- a/utils/ipc/BUILD.gn +++ b/utils/ipc/BUILD.gn @@ -37,7 +37,7 @@ ohos_shared_library("libsensor_ipc") { defines = sensor_default_defines - if (rust_socket_ipc) { + if (sensor_rust_socket_ipc) { deps = [ "$SUBSYSTEM_DIR/rust/utils/socket_ipc_rust_ffi:sensor_rust_util_ffi" ] } diff --git a/utils/ipc/src/stream_socket.cpp b/utils/ipc/src/stream_socket.cpp index 48c3fed9f86822f1eac7ac47f63e84ed4c536968..e77dbb1dd4cbc76d79e3db76ee76b889978e5298 100644 --- a/utils/ipc/src/stream_socket.cpp +++ b/utils/ipc/src/stream_socket.cpp @@ -52,7 +52,7 @@ void StreamSocket::OnReadPackets(CircleStreamBuffer &circBuf, StreamSocket::Pack PackHead *head = reinterpret_cast(buf); CHKPB(head); if (head->size < 0 || head->size > MAX_PACKET_BUF_SIZE) { - SEN_HILOGE("Packet header parsing error, and this error cannot be recovered. The buffer will be reset." + SEN_HILOGE("Packet header parsing error, and this error cannot be recovered. The buffer will be reset" " head->size:%{public}zu, unreadSize:%{public}zu", head->size, unreadSize); circBuf.Reset(); break; @@ -67,7 +67,7 @@ void StreamSocket::OnReadPackets(CircleStreamBuffer &circBuf, StreamSocket::Pack break; } if (!circBuf.SeekReadPos(pkt.GetPacketLength())) { - SEN_HILOGW("Set read position error, and this error cannot be recovered, and the buffer will be reset." + SEN_HILOGW("Set read position error, and this error cannot be recovered, and the buffer will be reset" " packetSize:%{public}zu, unreadSize:%{public}zu", pkt.GetPacketLength(), unreadSize); circBuf.Reset(); break; diff --git a/vibration_convert/core/algorithm/conversion/src/conversion_fft.cpp b/vibration_convert/core/algorithm/conversion/src/conversion_fft.cpp index e2e135bed8a4b476fb30e4d6fb3fe88537572f03..0ad28e274ea5c964bf8b1eea87a3318ab5aab6d3 100644 --- a/vibration_convert/core/algorithm/conversion/src/conversion_fft.cpp +++ b/vibration_convert/core/algorithm/conversion/src/conversion_fft.cpp @@ -115,7 +115,7 @@ int32_t ConversionFFT::Process(const std::vector &values, int32_t &frame // reset pos to start of hop pos_ = para_.windowSize - para_.hopSize; /** shift buffer back by one hop size. */ - for (int32_t i = 0; i < pos_; ++i) { + for (int32_t i = 0; i < pos_; i++) { fftResult_.buffer[i] = fftResult_.buffer[i + para_.hopSize]; } isFftCalcFinish_ = true; @@ -142,7 +142,7 @@ float ConversionFFT::GetSpectralFlatness() const } float geometricMean = 0.0F; float arithmaticMean = 0.0F; - for (int32_t i = 0; i < bins_; ++i) { + for (int32_t i = 0; i < bins_; i++) { if (fftResult_.magnitudes[i] != 0) { geometricMean += logf(fftResult_.magnitudes[i]); } @@ -158,7 +158,7 @@ float ConversionFFT::GetSpectralCentroid() const { float x = 0.0F; float y = 0.0F; - for (int32_t i = 0; i < bins_; ++i) { + for (int32_t i = 0; i < bins_; i++) { x += fabs(fftResult_.magnitudes[i]) * i; y += fabs(fftResult_.magnitudes[i]); } @@ -199,15 +199,15 @@ float ConversionIFFT::Process(const std::vector &mags, const std::vector< } // add to output // shift back by one hop - for (int32_t i = 0; i < (para_.fftSize - para_.hopSize); ++i) { + for (int32_t i = 0; i < (para_.fftSize - para_.hopSize); i++) { fftResult_.buffer[i] = fftResult_.buffer[i + para_.hopSize]; } // clear the end chunk - for (int32_t i = 0; i < para_.hopSize; ++i) { + for (int32_t i = 0; i < para_.hopSize; i++) { fftResult_.buffer[i + para_.fftSize - para_.hopSize] = 0.0F; } // merge new output - for (int32_t i = 0; i < para_.fftSize; ++i) { + for (int32_t i = 0; i < para_.fftSize; i++) { fftResult_.buffer[i] += ifftOut_[i]; } } @@ -295,7 +295,7 @@ int32_t ConversionOctave::Calculate(const std::vector &fftData) *(averages_.get() + lastAvgIdx) = sum / count; } // update the peaks separately - for (int32_t i = 0; i < nAverages_; ++i) { + for (int32_t i = 0; i < nAverages_; i++) { if (IsGreatOrEqual(*(averages_.get() + i), *(peaks_.get() + i))) { // save new peak level, also reset the hold timer *(peaks_.get() + i) = *(averages_.get() + i); diff --git a/vibration_convert/core/algorithm/conversion/src/conversion_mfcc.cpp b/vibration_convert/core/algorithm/conversion/src/conversion_mfcc.cpp index 126329b81c9a86b2306334886037535325c6f29d..e1fdadd13c1a542b87f40f794ca085e7838e60a5 100644 --- a/vibration_convert/core/algorithm/conversion/src/conversion_mfcc.cpp +++ b/vibration_convert/core/algorithm/conversion/src/conversion_mfcc.cpp @@ -37,14 +37,14 @@ int32_t ConversionMfcc::HandleMelFilterAndLogSquare(const std::vector &po SEN_HILOGE("Invalid parameter"); return Sensors::PARAMETER_ERROR; } - for (uint32_t i = 0; i < numFilters_; ++i) { + for (uint32_t i = 0; i < numFilters_; i++) { melBands_[i] = 0; for (uint32_t bin = 0; bin < numBins_; ++bin) { uint32_t idx = i + (bin * numFilters_); melBands_[i] += (melFilters_[idx] * powerSpectrum[bin]); } } - for (uint32_t i = 0; i < numFilters_; ++i) { + for (uint32_t i = 0; i < numFilters_; i++) { // log the square melBands_[i] = (melBands_[i] > BANDS_MIN_THRESHOLD) ? log(melBands_[i] * melBands_[i]) : 0; } @@ -155,7 +155,7 @@ int32_t ConversionMfcc::CalcMelFilterBank(double sampleRate) double stepMel = (maxMel - minMel) / (numFilters_ + 1); std::vector filterHzPos(numFilters_ + 2); double nextMel = minMel; - for (uint32_t i = 0; i < (numFilters_ + 2); ++i) { + for (uint32_t i = 0; i < (numFilters_ + 2); i++) { filterHzPos[i] = OHOS::Sensors::ConvertSlaneyHz(nextMel); nextMel += stepMel; } @@ -164,7 +164,7 @@ int32_t ConversionMfcc::CalcMelFilterBank(double sampleRate) for (uint32_t bin = 0; bin < numBins_; ++bin) { binFs[bin] = stepHz * bin; } - for (uint32_t i = 0; i < numFilters_; ++i) { + for (uint32_t i = 0; i < numFilters_; i++) { for (uint32_t j = 0; j < numBins_; ++j) { uint32_t idx = i + (j * numFilters_); if (SetMelFilters(idx, binFs[j], filterHzPos[i], filterHzPos[i + 1], diff --git a/vibration_convert/core/algorithm/intensity_processor/include/intensity_processor.h b/vibration_convert/core/algorithm/intensity_processor/include/intensity_processor.h index 3ca738395f7a08914b1377056061f323da62da0c..1c80979e999239add2f9aa404f830cab4a6b4285 100644 --- a/vibration_convert/core/algorithm/intensity_processor/include/intensity_processor.h +++ b/vibration_convert/core/algorithm/intensity_processor/include/intensity_processor.h @@ -86,6 +86,6 @@ public: */ std::vector VolumeInDB(const std::vector &data, int32_t hopLength); }; -} // namespace Sensors -} // namespace OHOS +} // namespace Sensors +} // namespace OHOS #endif // INTENSITY_PROCESSOR_H \ No newline at end of file diff --git a/vibration_convert/core/algorithm/intensity_processor/src/intensity_processor.cpp b/vibration_convert/core/algorithm/intensity_processor/src/intensity_processor.cpp index 6bcf8f86f81fc2b68bab8032073591620df77861..3f457c7b80d9af8909b9f4a7e08fe3f3537a42cb 100644 --- a/vibration_convert/core/algorithm/intensity_processor/src/intensity_processor.cpp +++ b/vibration_convert/core/algorithm/intensity_processor/src/intensity_processor.cpp @@ -26,7 +26,7 @@ namespace OHOS { namespace Sensors { namespace { constexpr double VOLUME_DB_COEF { 10.0 }; -} // namespace +} // namespace std::vector IntensityProcessor::GetRMS(const std::vector &data, int32_t hopLength, bool centerFlag) { @@ -131,5 +131,5 @@ std::vector IntensityProcessor::VolumeInDB(const std::vector &da } return db; } -} // namespace Sensors -} // namespace OHOS \ No newline at end of file +} // namespace Sensors +} // namespace OHOS \ No newline at end of file diff --git a/vibration_convert/core/algorithm/onset/include/onset.h b/vibration_convert/core/algorithm/onset/include/onset.h index e4ad6ad1213836997b4db7cf6ec9e61139a3b650..6d0d1aeed935859170a5dc4effff96b4abc76f04 100644 --- a/vibration_convert/core/algorithm/onset/include/onset.h +++ b/vibration_convert/core/algorithm/onset/include/onset.h @@ -76,6 +76,6 @@ private: bool htkFlag_ { false }; OnsetInfo onsetInfo_; }; -} // namespace Sensors -} // namespace OHOS +} // namespace Sensors +} // namespace OHOS #endif // ONSET_H \ No newline at end of file diff --git a/vibration_convert/core/algorithm/onset/src/onset.cpp b/vibration_convert/core/algorithm/onset/src/onset.cpp index 1d6d07a5f21037cbb00a5852c24ec8615dcef0fc..1602836359fedc31cf2f1e0e6897be52876d800a 100644 --- a/vibration_convert/core/algorithm/onset/src/onset.cpp +++ b/vibration_convert/core/algorithm/onset/src/onset.cpp @@ -40,7 +40,7 @@ constexpr uint32_t SEMITONE_NUM_COEFFS = 13; constexpr double ONSET_PEAK_THRESHOLD_RATIO = 0.4; constexpr double MIN_FREQ = 0.0; constexpr double MAX_FREQ = SAMPLE_RATE / 2.0; -} // namespace +} // namespace std::vector Onset::MatrixDot(size_t matrixAcols, const std::vector &matrixA, size_t matrixBcols, const std::vector &matrixB) @@ -261,5 +261,5 @@ int32_t Onset::CheckOnset(const std::vector &data, int32_t nFft, int32_t onsetInfo = onsetInfo_; return Sensors::SUCCESS; } -} // namespace Sensors -} // namespace OHOS \ No newline at end of file +} // namespace Sensors +} // namespace OHOS \ No newline at end of file diff --git a/vibration_convert/core/algorithm/peak_finder/include/peak_finder.h b/vibration_convert/core/algorithm/peak_finder/include/peak_finder.h index 2a31738422f5c093e10744b86d07d6e3e2dc8145..c3bf9dc46d79cce5e0b866712b3176233390fc99 100644 --- a/vibration_convert/core/algorithm/peak_finder/include/peak_finder.h +++ b/vibration_convert/core/algorithm/peak_finder/include/peak_finder.h @@ -190,6 +190,6 @@ private: std::vector voiceSegmentFlag_; int32_t hopLength_ { 1024 }; }; -} // namespace Sensors -} // namespace OHOS +} // namespace Sensors +} // namespace OHOS #endif // PEAK_FINDER_H \ No newline at end of file diff --git a/vibration_convert/core/algorithm/peak_finder/src/peak_finder.cpp b/vibration_convert/core/algorithm/peak_finder/src/peak_finder.cpp index efa75d0aec9dafe5d3dcc4deb1ed5edc5e54ff5e..a33a004e5162ce4a0c9102bffd0732f76f4a68f4 100644 --- a/vibration_convert/core/algorithm/peak_finder/src/peak_finder.cpp +++ b/vibration_convert/core/algorithm/peak_finder/src/peak_finder.cpp @@ -46,7 +46,7 @@ constexpr int32_t HUNDRED_POINT_DESCENT_HEIGHT { 100 }; constexpr double DROP_HIGHT { 1.0 }; constexpr int32_t AMPLITUDE_ENVELOPE_HOP_LENGTH { 256 }; constexpr double DROP_HIGHT_THRESHOLD { 0.3 }; // 30% -} // namespace +} // namespace std::vector PeakFinder::ExtractValues(const std::vector &envelope, const std::vector &idxs) { @@ -790,5 +790,5 @@ int32_t PeakFinder::EstimateDesentEnergy(const std::vector &data, double dutyCycle = totalEnergy / virtualWholeEnergy; return Sensors::SUCCESS; } -} // namespace Sensors -} // namespace OHOS +} // namespace Sensors +} // namespace OHOS diff --git a/vibration_convert/core/native/include/audio_parsing.h b/vibration_convert/core/native/include/audio_parsing.h index 094ce2113625313587862e69ca3464e7a5218eee..fb837bfc06414cb847e5ad743fde9847c296992a 100644 --- a/vibration_convert/core/native/include/audio_parsing.h +++ b/vibration_convert/core/native/include/audio_parsing.h @@ -46,6 +46,6 @@ private: AudioData audioData_; AttributeChunk attributeChunk_; }; -} // namespace Sensors -} // namespace OHOS +} // namespace Sensors +} // namespace OHOS #endif // AUDIO_PARSING_H \ No newline at end of file diff --git a/vibration_convert/core/native/include/generate_vibration_json_file.h b/vibration_convert/core/native/include/generate_vibration_json_file.h index a9a60427fe3df0d18dd65fc3339b7eb6437f3b85..57d4e7448eae75a2e193e88721c754e62b9b7860 100644 --- a/vibration_convert/core/native/include/generate_vibration_json_file.h +++ b/vibration_convert/core/native/include/generate_vibration_json_file.h @@ -33,6 +33,6 @@ public: template int32_t DebugJsonFile(const std::string &pathName, const std::vector &srcDatas); }; -} // namespace Sensors -} // namespace OHOS +} // namespace Sensors +} // namespace OHOS #endif // GENERATE_VIBRATION_JSON_FILE_H \ No newline at end of file diff --git a/vibration_convert/core/native/include/vibration_convert_core.h b/vibration_convert/core/native/include/vibration_convert_core.h index 2acbd671482ccf33eea2579ea4fec694a3ef03d0..11238f622370e7813eda30493ad36486feb0987f 100644 --- a/vibration_convert/core/native/include/vibration_convert_core.h +++ b/vibration_convert/core/native/include/vibration_convert_core.h @@ -205,6 +205,6 @@ private: Onset onset_; int32_t onsetMinSkip_ { 0 }; }; -} // namespace Sensors -} // namespace OHOS +} // namespace Sensors +} // namespace OHOS #endif // VIBRATION_CONVERT_CORE_H \ No newline at end of file diff --git a/vibration_convert/core/native/src/audio_parsing.cpp b/vibration_convert/core/native/src/audio_parsing.cpp index 1abf1d8bbaa776ffcd05cd27d8125c6e8dfb0340..4da33cb1ad5ea69ce7b0c3f98c09797033779da7 100644 --- a/vibration_convert/core/native/src/audio_parsing.cpp +++ b/vibration_convert/core/native/src/audio_parsing.cpp @@ -42,7 +42,7 @@ constexpr int32_t AUDIO_DATA_MAX_NUMBER = 100000; constexpr int64_t LSEEK_FAIL = -1; constexpr int32_t TIME_MS = 1000; constexpr int32_t BITS_PER_BYTE = 8; -} // namespace +} // namespace AudioParsing::AudioParsing(const RawFileDescriptor &rawFd) { @@ -210,5 +210,5 @@ void AudioParsing::PrintAttributeChunk() SEN_HILOGD("dataID:%{public}.4s", attributeChunk_.dataID); SEN_HILOGD("dataSize:%{public}u", attributeChunk_.dataSize); } -} // namespace Sensors -} // namespace OHOS +} // namespace Sensors +} // namespace OHOS diff --git a/vibration_convert/core/native/src/generate_vibration_json_file.cpp b/vibration_convert/core/native/src/generate_vibration_json_file.cpp index 3dcc64e872fbd6235d2c00f3eda1784c1817c6c8..467290df7c4d3184246a8c0441e57b4cc83fc51a 100644 --- a/vibration_convert/core/native/src/generate_vibration_json_file.cpp +++ b/vibration_convert/core/native/src/generate_vibration_json_file.cpp @@ -93,5 +93,5 @@ int32_t GenerateVibrationJsonFile::DebugJsonFile(const std::string &pathName, co ofs.close(); return Sensors::SUCCESS; } -} // namespace Sensors -} // namespace OHOS +} // namespace Sensors +} // namespace OHOS diff --git a/vibration_convert/core/native/src/vibration_convert_core.cpp b/vibration_convert/core/native/src/vibration_convert_core.cpp index 89d3a0e2fb11f43700f01a65b982fe88f8967fa9..22b1db4b773b8999998457c7f0fed84b73c23fda 100644 --- a/vibration_convert/core/native/src/vibration_convert_core.cpp +++ b/vibration_convert/core/native/src/vibration_convert_core.cpp @@ -64,7 +64,7 @@ constexpr double AMPLITUDE_DB_MAX { 1.0 }; constexpr int32_t ADSR_BOUNDARY_STATUS_NONE { 0 }; constexpr int32_t ADSR_BOUNDARY_STATUS_ONE { 1 }; constexpr int32_t ADSR_BOUNDARY_STATUS_BOTH { 2 }; -} // namespace +} // namespace int32_t VibrationConvertCore::GetAudioData() { @@ -545,7 +545,7 @@ int32_t VibrationConvertCore::ConvertTransientEvent(const std::vector &d IsolatedEnvelopeInfo isolatedEnvelopeInfo; int32_t ret = peakFinder_.ObtainTransientByAmplitude(datas, isolatedEnvelopeInfo); if (ret != Sensors::SUCCESS) { - SEN_HILOGE("ObtainTransientByAmplitude failed."); + SEN_HILOGE("ObtainTransientByAmplitude failed"); return ret; } if (!isolatedEnvelopeInfo.isHaveContinuousEvent) { @@ -1196,5 +1196,5 @@ void VibrationConvertCore::AddContinuousEventData(const ContinuousEvent &continu { continuousEvents_.push_back(continuousEvent); } -} // namespace Sensors -} // namespace OHOS +} // namespace Sensors +} // namespace OHOS diff --git a/vibration_convert/core/native/test/unittest/data.h b/vibration_convert/core/native/test/unittest/data.h index 40960a2f9f1fc422e2dce0ea43a861c587314498..e44b7c0a72c57f20d6605b7030c319f8fb1dab58 100644 --- a/vibration_convert/core/native/test/unittest/data.h +++ b/vibration_convert/core/native/test/unittest/data.h @@ -38,6 +38,6 @@ std::vector AudioSrcDatas = { 0.00393714383244514, 0.0 }; -} // namespace Sensors -} // namespace OHOS +} // namespace Sensors +} // namespace OHOS #endif // UT_TEST_DATA_H \ No newline at end of file diff --git a/vibration_convert/core/native/test/unittest/generate_json_test.cpp b/vibration_convert/core/native/test/unittest/generate_json_test.cpp index f0e430da9f6f95eea9173214b8b3e638209b10c5..67bdca0981a4f0b2471b9717654f9177f01b36e7 100644 --- a/vibration_convert/core/native/test/unittest/generate_json_test.cpp +++ b/vibration_convert/core/native/test/unittest/generate_json_test.cpp @@ -103,5 +103,5 @@ HWTEST_F(GenerateJsonFileTest, GenerateJsonFileTest_002, TestSize.Level1) int32_t ret = vibrationConvertCore.ConvertAudioToHaptic(audioSetting, data, vtEvents); EXPECT_EQ(ret, 0); } -} // namespace Sensors -} // namespace OHOS \ No newline at end of file +} // namespace Sensors +} // namespace OHOS \ No newline at end of file diff --git a/vibration_convert/core/utils/include/audio_utils.h b/vibration_convert/core/utils/include/audio_utils.h index 57e3f681c4ad8e15530cf86bf7d387f3edc39e25..808cd8215f975ec5222fc250f830f7a3a8f1023d 100644 --- a/vibration_convert/core/utils/include/audio_utils.h +++ b/vibration_convert/core/utils/include/audio_utils.h @@ -34,7 +34,7 @@ namespace Sensors { namespace { constexpr double DB_TO_AMP_COEF { 0.05 }; constexpr double AMP_TO_DB_COEF { 20.0 }; -} // namespace +} // namespace /** *@brief Basic processing of audio, called by other modules. @@ -102,6 +102,6 @@ public: */ std::vector PadData(const std::vector &data, int32_t hopLength); }; -} // namespace Sensors -} // namespace OHOS -#endif \ No newline at end of file +} // namespace Sensors +} // namespace OHOS +#endif // AUDIO_UTILS_H \ No newline at end of file diff --git a/vibration_convert/core/utils/include/utils.h b/vibration_convert/core/utils/include/utils.h index 07689309dbbdb69263aa8f7964c13fa343b1778b..e51fa0562198c90700dbbebf7401e6103d75d2b9 100644 --- a/vibration_convert/core/utils/include/utils.h +++ b/vibration_convert/core/utils/include/utils.h @@ -47,7 +47,7 @@ constexpr double F_THREE = 3.0; constexpr double SAMPLE_IN_MS = 1000.0; constexpr double INTERSITY_BOUNDARY_POINT = 0.25; constexpr double INTERSITY_NUMBER_BOUNDARY_POINT = 0.75; -} // namespace +} // namespace enum WindowType { WND_TYPE_BARTLETT = 1, @@ -205,6 +205,6 @@ inline double ConvertHtkHz(double mels) } return freqs; } -} // namespace Sensors -} // namespace OHOS +} // namespace Sensors +} // namespace OHOS #endif // CONVERSION_UTILS_H \ No newline at end of file diff --git a/vibration_convert/core/utils/src/audio_utils.cpp b/vibration_convert/core/utils/src/audio_utils.cpp index 4445058a03300a663af5d6f204150e574a20141c..890bed1fe6a659ad5b650cd354822fb602a85b07 100644 --- a/vibration_convert/core/utils/src/audio_utils.cpp +++ b/vibration_convert/core/utils/src/audio_utils.cpp @@ -39,7 +39,7 @@ constexpr double MTOF_ARRAY[MTOF_ARRAY_SIZE + 1] = { 3729.31, 3951.066406, 4186.009277, 4434.921875, 4698.63623, 4978.031738, 5274.041016, 5587.651855, 5919.910645, 6271.926758, 6644.875, 7040., 7458.620117, 7902.132812, 8372.018555, 8869.84375, 9397.272461, 9956.063477, 10548.082031, 11175.303711, 11839.821289, 12543.853516, 13289.75 }; -} // namespace +} // namespace double AudioUtils::ConvertMtof(int32_t midinote) { @@ -61,5 +61,5 @@ std::vector AudioUtils::PadData(const std::vector &data, int32_t paddingData.insert(paddingData.end(), hopLength / 2, 0); return paddingData; } -} // namespace Sensors -} // namespace OHOS \ No newline at end of file +} // namespace Sensors +} // namespace OHOS \ No newline at end of file diff --git a/vibration_convert/core/utils/src/utils.cpp b/vibration_convert/core/utils/src/utils.cpp index dded5ba1424c0f3cedb649f70048fce2c2dcccfc..12d09759642e8ba5724efd9b4ef88c9cd89b72e7 100644 --- a/vibration_convert/core/utils/src/utils.cpp +++ b/vibration_convert/core/utils/src/utils.cpp @@ -37,7 +37,7 @@ namespace{ constexpr double PERCENTAGE_RANGE = 100.0; constexpr int32_t VOICE_MIN_INTENSITY_NORM = 25; constexpr size_t MAX_SIZE = 26460000; -} // namespace +} // namespace bool IsPowerOfTwo(uint32_t x) { @@ -259,5 +259,5 @@ std::vector ObtainAmplitudeEnvelop(const std::vector &data, size } return enery; } -} // namespace Sensors -} // namespace OHOS \ No newline at end of file +} // namespace Sensors +} // namespace OHOS \ No newline at end of file diff --git a/vibration_convert/interfaces/js/include/vibrator_convert_js.h b/vibration_convert/interfaces/js/include/vibrator_convert_js.h index 5ee8b6ba9583731835f13f46b5c8b2f858dfa7ee..92f4429a7338d56acd5045f0611fae315670eedd 100644 --- a/vibration_convert/interfaces/js/include/vibrator_convert_js.h +++ b/vibration_convert/interfaces/js/include/vibrator_convert_js.h @@ -45,6 +45,6 @@ private: std::mutex mutex_; napi_ref contextRef_ { nullptr }; }; -} // namespace Sensors -} // namespace OHOS +} // namespace Sensors +} // namespace OHOS #endif // VIBRATOR_CONVERT_JS_H \ No newline at end of file diff --git a/vibration_convert/interfaces/js/include/vibrator_convert_napi_utils.h b/vibration_convert/interfaces/js/include/vibrator_convert_napi_utils.h index 81129bc81b068cbef4dadc960c35f605323304f1..a847c903b04d5767af044748ec70e8285e547a82 100644 --- a/vibration_convert/interfaces/js/include/vibrator_convert_napi_utils.h +++ b/vibration_convert/interfaces/js/include/vibrator_convert_napi_utils.h @@ -82,6 +82,6 @@ napi_value GetAudioToHapticInfo(sptr asyncCallbackInfo); void EmitHapticAsyncCallbackWork(sptr async_callback_info); void EmitHapticPromiseWork(sptr asyncCallbackInfo); int64_t GetFileSize(int32_t fd); -} // namespace Sensors -} // namespace OHOS +} // namespace Sensors +} // namespace OHOS #endif // VIBRATOR_CONVERT_NAPI_UTILS_H \ No newline at end of file diff --git a/vibration_convert/interfaces/js/src/vibrator_convert_js.cpp b/vibration_convert/interfaces/js/src/vibrator_convert_js.cpp index 617dec03aa0d9e5e34a7bc296f00716a9f975025..8dc769a8c2a6f812054d85f9ddeda458d1ceddee 100644 --- a/vibration_convert/interfaces/js/src/vibrator_convert_js.cpp +++ b/vibration_convert/interfaces/js/src/vibrator_convert_js.cpp @@ -30,7 +30,7 @@ namespace Sensors { namespace { const char* CONVERT = "convert"; const char* CONVERT_CLASS = "convert_class"; -} // namespace +} // namespace std::shared_ptr VibratorConvert::GetInterfaces() { @@ -295,5 +295,5 @@ napi_value VibratorConvert::ConvertAudioToHaptic(napi_env env, napi_callback_inf EmitHapticPromiseWork(asyncCallbackInfo); return promise; } -} // namespace Sensors -} // namespace OHOS +} // namespace Sensors +} // namespace OHOS diff --git a/vibration_convert/interfaces/js/src/vibrator_convert_napi_utils.cpp b/vibration_convert/interfaces/js/src/vibrator_convert_napi_utils.cpp index 3aa211aedd585d8ec5769326fb1fb493d4a6f3f3..ad158a5caf05616b3cfea3836f127cbbdbd6febd 100644 --- a/vibration_convert/interfaces/js/src/vibrator_convert_napi_utils.cpp +++ b/vibration_convert/interfaces/js/src/vibrator_convert_napi_utils.cpp @@ -33,7 +33,7 @@ namespace Sensors { namespace { constexpr int32_t RESULT_LENGTH = 2; constexpr int64_t INVALID_FILE_SIZE = -1; -} // namespace +} // namespace AsyncCallbackInfo::~AsyncCallbackInfo() { @@ -385,5 +385,5 @@ void EmitHapticPromiseWork(sptr asyncCallbackInfo) asyncCallbackInfo->DecStrongRef(nullptr); } } -} // namespace Sensors -} // namespace OHOS +} // namespace Sensors +} // namespace OHOS