From d85e6aa6ba286f80b9bcdb689dccac6e02a27b4d Mon Sep 17 00:00:00 2001 From: wuzhihuitmac Date: Fri, 2 Aug 2024 11:18:44 +0800 Subject: [PATCH 01/27] Added trigger sensor type filtering Signed-off-by: wuzhihuitmac Change-Id: I536623ea60b6b3818a9ead659921fd9426257a93 --- .../adapter/src/sensor_event_callback.cpp | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/services/hdi_connection/adapter/src/sensor_event_callback.cpp b/services/hdi_connection/adapter/src/sensor_event_callback.cpp index 85b8a466..29449815 100644 --- a/services/hdi_connection/adapter/src/sensor_event_callback.cpp +++ b/services/hdi_connection/adapter/src/sensor_event_callback.cpp @@ -14,6 +14,8 @@ */ #include "sensor_event_callback.h" +#include + #include "hdi_connection.h" #include "sensor_agent_type.h" #include "sensor_errors.h" @@ -35,6 +37,13 @@ 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) @@ -60,6 +69,9 @@ int32_t SensorEventCallback::OnDataEvent(const HdfSensorEvents &event) sensorData.sensorTypeId == SENSOR_TYPE_ID_DROP_DETECTION) { sensorData.mode = SENSOR_ON_CHANGE; } + if (g_sensorTypeTrigger.find(sensorData.sensorTypeId) != g_sensorTypeTrigger.end()) { + sensorData.mode = SENSOR_ON_CHANGE; + } CHKPR(sensorData.data, ERR_NO_INIT); if (sensorData.sensorTypeId == SENSOR_TYPE_ID_HEADPOSTURE) { sensorData.dataLen = HEADPOSTURE_DATA_SIZE; -- Gitee From 169db12224466e8d35729ebcf209da2978aeca8d Mon Sep 17 00:00:00 2001 From: bailu1992 Date: Fri, 2 Aug 2024 09:43:47 +0800 Subject: [PATCH 02/27] Increase tdd use case branch coverage Signed-off-by: bailu1992 --- .../inner_api/sensor_algorithm_test.cpp | 167 +++++++++++++++--- 1 file changed, 140 insertions(+), 27 deletions(-) diff --git a/test/unittest/interfaces/inner_api/sensor_algorithm_test.cpp b/test/unittest/interfaces/inner_api/sensor_algorithm_test.cpp index 9bac6570..7c42af4b 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 -- Gitee From 29f18df1897952783b2860d4ad788f4d0c4ebd3c Mon Sep 17 00:00:00 2001 From: lixiangpeng5 Date: Sat, 3 Aug 2024 09:17:58 +0000 Subject: [PATCH 03/27] fix read pos out of range Signed-off-by: lixiangpeng5 Change-Id: Ibc624eba6242ade9eed1de3b6c18854a60d294db --- services/src/sensor_data_processer.cpp | 3 +-- utils/common/src/report_data_callback.cpp | 8 ++++---- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/services/src/sensor_data_processer.cpp b/services/src/sensor_data_processer.cpp index f6751320..86b6f58f 100644 --- a/services/src/sensor_data_processer.cpp +++ b/services/src/sensor_data_processer.cpp @@ -274,9 +274,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/utils/common/src/report_data_callback.cpp b/utils/common/src/report_data_callback.cpp index 12e882fd..cd4e0d04 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; } -- Gitee From 84adb2dff3d9a89e42a8080168f33dd03d57250c Mon Sep 17 00:00:00 2001 From: bailu1992 Date: Tue, 6 Aug 2024 11:54:02 +0800 Subject: [PATCH 04/27] sensor native file branch overwriting Signed-off-by: bailu1992 --- .../interfaces/kits/sensor_native_test.cpp | 254 +++++++++++++++++- 1 file changed, 253 insertions(+), 1 deletion(-) diff --git a/test/unittest/interfaces/kits/sensor_native_test.cpp b/test/unittest/interfaces/kits/sensor_native_test.cpp index 650165da..89654c2d 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 @@ -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"); @@ -159,6 +180,99 @@ HWTEST_F(SensorAgentTest, OH_Sensor_GetInfos_002, TestSize.Level1) ASSERT_NE(ret, SENSOR_SUCCESS); } +HWTEST_F(SensorAgentTest, OH_Sensor_GetInfos_003, 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); + + Sensor_Info **sensors = OH_Sensor_CreateInfos(count); + ASSERT_NE(sensors, nullptr); + + count = 1; + ret = OH_Sensor_GetInfos(sensors, &count); + ASSERT_EQ(ret, SENSOR_PARAMETER_ERROR); +} + +HWTEST_F(SensorAgentTest, OH_Sensor_GetInfos_004, 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); + + 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); +} + +HWTEST_F(SensorAgentTest, OH_Sensor_GetInfos_005, TestSize.Level1) +{ + SEN_HILOGE("OH_Sensor_GetInfos_005 in"); + uint32_t count = 0; + OH_Sensor_GetInfos(nullptr, &count); + auto sensors = new Sensor_Info *[count]; + + char * sensorName = nullptr; + uint32_t length = SENSOR_NAME_LENGTH_MAX; + int32_t ret = OH_SensorInfo_GetName(sensors[0], sensorName, &length); + ASSERT_EQ(ret, SENSOR_PARAMETER_ERROR); + + char sensorName1[SENSOR_NAME_LENGTH_MAX] = {}; + length = 0; + ret = OH_SensorInfo_GetName(sensors[0], sensorName1, &length); + ASSERT_EQ(ret, SENSOR_PARAMETER_ERROR); +} + +HWTEST_F(SensorAgentTest, OH_Sensor_GetInfos_006, TestSize.Level1) +{ + SEN_HILOGE("OH_Sensor_GetInfos_006 in"); + uint32_t count = 0; + OH_Sensor_GetInfos(nullptr, &count); + auto sensors = new Sensor_Info *[count]; + + char *vendorName = nullptr; + uint32_t length = SENSOR_NAME_LENGTH_MAX; + int32_t ret = OH_SensorInfo_GetVendorName(sensors[0], vendorName, &length); + ASSERT_EQ(ret, SENSOR_PARAMETER_ERROR); + + char vendorName1[SENSOR_NAME_LENGTH_MAX] = {}; + length = 0; + ret = OH_SensorInfo_GetVendorName(sensors[0], vendorName1, &length); + ASSERT_EQ(ret, SENSOR_PARAMETER_ERROR); +} + +HWTEST_F(SensorAgentTest, OH_Sensor_GetInfos_007, TestSize.Level1) +{ + SEN_HILOGE("OH_Sensor_GetInfos_007 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 +373,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 +504,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 +576,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 +604,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 +630,17 @@ HWTEST_F(SensorAgentTest, OH_SensorSubscriber_GetCallback_002, TestSize.Level1) OH_Sensor_DestroySubscriber(g_user); } } + +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 -- Gitee From 6fb2611bd254447cc93b63d9a3a79c346e6ebb0e Mon Sep 17 00:00:00 2001 From: wuzhihuitmac Date: Wed, 7 Aug 2024 18:47:26 +0800 Subject: [PATCH 05/27] add ignore for cfi check Signed-off-by: wuzhihuitmac Change-Id: Ib553865b8e30d7bfb53102b87ea7bbc3d125eb6f --- frameworks/native/src/sensor_agent_proxy.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/frameworks/native/src/sensor_agent_proxy.cpp b/frameworks/native/src/sensor_agent_proxy.cpp index a714a3cb..0cdfbe2d 100644 --- a/frameworks/native/src/sensor_agent_proxy.cpp +++ b/frameworks/native/src/sensor_agent_proxy.cpp @@ -59,7 +59,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) { -- Gitee From e0665b948a3203340d491bd4a0f469a4ba235635 Mon Sep 17 00:00:00 2001 From: bailu1992 Date: Thu, 8 Aug 2024 14:10:43 +0800 Subject: [PATCH 06/27] Example Increase the sensor_basic_data_channel coverage rate Signed-off-by: bailu1992 --- bundle.json | 3 +- .../sensoragent_fuzzer/sensoragent_fuzzer.cpp | 6 +- test/unittest/coverage/BUILD.gn | 48 ++++++ .../sensor_basic_data_channel_test.cpp | 149 ++++++++++++++++++ 4 files changed, 204 insertions(+), 2 deletions(-) create mode 100644 test/unittest/coverage/BUILD.gn create mode 100644 test/unittest/coverage/sensor_basic_data_channel_test.cpp diff --git a/bundle.json b/bundle.json index 72c47298..c331df84 100755 --- a/bundle.json +++ b/bundle.json @@ -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/test/fuzztest/interfaces/sensoragent_fuzzer/sensoragent_fuzzer.cpp b/test/fuzztest/interfaces/sensoragent_fuzzer/sensoragent_fuzzer.cpp index a7300584..f96be5b0 100644 --- a/test/fuzztest/interfaces/sensoragent_fuzzer/sensoragent_fuzzer.cpp +++ b/test/fuzztest/interfaces/sensoragent_fuzzer/sensoragent_fuzzer.cpp @@ -27,6 +27,8 @@ #include "sensor_agent_type.h" #include "sensor_errors.h" +namespace OHOS { +namespace Sensors { using namespace OHOS::HiviewDFX; using namespace OHOS::Security::AccessToken; using OHOS::Security::AccessToken::AccessTokenID; @@ -113,10 +115,12 @@ void SensorAgentFuzzTest(const uint8_t *data, size_t size) DeactivateSensor(sensorTypeId, &user); UnsubscribeSensor(sensorTypeId, &user); } +} // namespace Sensors +} // namespace OHOS extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) { - SensorAgentFuzzTest(data, size); + OHOS::Sensors::SensorAgentFuzzTest(data, size); return 0; } diff --git a/test/unittest/coverage/BUILD.gn b/test/unittest/coverage/BUILD.gn new file mode 100644 index 00000000..458a4c68 --- /dev/null +++ b/test/unittest/coverage/BUILD.gn @@ -0,0 +1,48 @@ +# 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/test.gni") +import("./../../../sensor.gni") + +ohos_unittest("SensorBasicDataChannelTest") { + module_out_path = "sensor/coverage" + + 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", + ] + + deps = [ + "$SUBSYSTEM_DIR/frameworks/native:libsensor_client", + "$SUBSYSTEM_DIR/frameworks/native:ohsensor", + "$SUBSYSTEM_DIR/utils/common:libsensor_utils", + ] + + external_deps = [ + "c_utils:utils", + "googletest:gmock", + "googletest:gtest_main", + "hilog:libhilog", + "ipc:ipc_single", + ] +} +group("unittest") { + testonly = true + deps = [ ":SensorBasicDataChannelTest" ] +} 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 00000000..3001cffe --- /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 -- Gitee From e5f2ccef12250dad94034c6f94c66329c1b742f2 Mon Sep 17 00:00:00 2001 From: bailu1992 Date: Fri, 9 Aug 2024 16:53:39 +0800 Subject: [PATCH 07/27] report_data_callback File coverage rate Signed-off-by: bailu1992 --- test/unittest/coverage/BUILD.gn | 33 ++++- .../coverage/report_data_callback_test.cpp | 122 ++++++++++++++++++ 2 files changed, 154 insertions(+), 1 deletion(-) create mode 100644 test/unittest/coverage/report_data_callback_test.cpp diff --git a/test/unittest/coverage/BUILD.gn b/test/unittest/coverage/BUILD.gn index 458a4c68..e0c6461b 100644 --- a/test/unittest/coverage/BUILD.gn +++ b/test/unittest/coverage/BUILD.gn @@ -42,7 +42,38 @@ ohos_unittest("SensorBasicDataChannelTest") { "ipc:ipc_single", ] } + +ohos_unittest("ReportDataCallbackTest") { + module_out_path = "sensor/coverage" + + 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:libsensor_client", + "$SUBSYSTEM_DIR/frameworks/native:ohsensor", + "$SUBSYSTEM_DIR/utils/common:libsensor_utils", + ] + + external_deps = [ + "c_utils:utils", + "googletest:gmock", + "googletest:gtest_main", + "hilog:libhilog", + ] +} + group("unittest") { testonly = true - deps = [ ":SensorBasicDataChannelTest" ] + deps = [ + ":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 00000000..201bac50 --- /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 -- Gitee From 7a0b3e16533cde9fe235d62d7b5e51cd403b1408 Mon Sep 17 00:00:00 2001 From: bailu1992 Date: Mon, 12 Aug 2024 19:45:48 +0800 Subject: [PATCH 08/27] sensor_native use case optimization Signed-off-by: bailu1992 --- .../interfaces/kits/sensor_native_test.cpp | 122 ++++++++++++++---- 1 file changed, 96 insertions(+), 26 deletions(-) diff --git a/test/unittest/interfaces/kits/sensor_native_test.cpp b/test/unittest/interfaces/kits/sensor_native_test.cpp index 89654c2d..45e3c75e 100644 --- a/test/unittest/interfaces/kits/sensor_native_test.cpp +++ b/test/unittest/interfaces/kits/sensor_native_test.cpp @@ -174,7 +174,7 @@ 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); @@ -182,76 +182,147 @@ HWTEST_F(SensorAgentTest, OH_Sensor_GetInfos_002, TestSize.Level1) HWTEST_F(SensorAgentTest, OH_Sensor_GetInfos_003, TestSize.Level1) { - SEN_HILOGE("OH_Sensor_GetInfos_004 in"); + 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); - Sensor_Info **sensors = OH_Sensor_CreateInfos(count); - ASSERT_NE(sensors, nullptr); - - count = 1; + 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_005 in"); + 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 sensors = new Sensor_Info *[count]; + auto sensors1 = new Sensor_Info *[count]; for (uint32_t i = 0; i < count; ++i) { - if (sensors[i] != nullptr) { - sensors[i] = nullptr; + if (sensors1[i] != nullptr) { + sensors1[i] = nullptr; } } - ret = OH_Sensor_GetInfos(sensors, &count); + 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; - OH_Sensor_GetInfos(nullptr, &count); - auto sensors = new Sensor_Info *[count]; - - char * sensorName = nullptr; + 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; - int32_t ret = OH_SensorInfo_GetName(sensors[0], sensorName, &length); + + ret = OH_SensorInfo_GetName(sensors[0], sensorName, &length); ASSERT_EQ(ret, SENSOR_PARAMETER_ERROR); - char sensorName1[SENSOR_NAME_LENGTH_MAX] = {}; + ret = OH_Sensor_GetInfos(sensors, &count); length = 0; - ret = OH_SensorInfo_GetName(sensors[0], sensorName1, &length); + 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; - OH_Sensor_GetInfos(nullptr, &count); - auto sensors = new Sensor_Info *[count]; + 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; - char *vendorName = nullptr; - uint32_t length = SENSOR_NAME_LENGTH_MAX; - int32_t ret = OH_SensorInfo_GetVendorName(sensors[0], vendorName, &length); + 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[SENSOR_NAME_LENGTH_MAX] = {}; - length = 0; + 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]; @@ -272,7 +343,6 @@ HWTEST_F(SensorAgentTest, OH_Sensor_GetInfos_007, TestSize.Level1) ASSERT_EQ(ret, SENSOR_PARAMETER_ERROR); } - HWTEST_F(SensorAgentTest, OH_Sensor_Subscribe_001, TestSize.Level1) { SEN_HILOGI("OH_Sensor_Subscribe_001 in"); -- Gitee From 32118d12306309f665fe60b32c05759337e15e21 Mon Sep 17 00:00:00 2001 From: wuzhihuitmac Date: Tue, 6 Aug 2024 21:13:01 +0800 Subject: [PATCH 09/27] add log print about sensor data report Signed-off-by: wuzhihuitmac Change-Id: Ibae1b1fd8faab12cab1e9d1d542f80ebf4eec810 --- frameworks/js/napi/BUILD.gn | 5 +- .../js/napi/include/async_callback_info.h | 4 +- frameworks/native/src/sensor_agent_proxy.cpp | 8 + interfaces/inner_api/sensor_agent_type.h | 4 + .../adapter/include/sensor_event_callback.h | 7 - .../adapter/src/sensor_event_callback.cpp | 74 +------ services/src/sensor_service.cpp | 4 + utils/common/BUILD.gn | 1 + utils/common/include/print_sensor_data.h | 59 ++++++ utils/common/src/print_sensor_data.cpp | 185 ++++++++++++++++++ 10 files changed, 269 insertions(+), 82 deletions(-) create mode 100644 utils/common/include/print_sensor_data.h create mode 100644 utils/common/src/print_sensor_data.cpp diff --git a/frameworks/js/napi/BUILD.gn b/frameworks/js/napi/BUILD.gn index 9dd4e8bb..51d5dc43 100644 --- a/frameworks/js/napi/BUILD.gn +++ b/frameworks/js/napi/BUILD.gn @@ -37,7 +37,10 @@ ohos_shared_library("libsensor") { cfi_cross_dso = true debug = false } - deps = [ "$SUBSYSTEM_DIR/frameworks/native:sensor_interface_native" ] + deps = [ + "$SUBSYSTEM_DIR/frameworks/native:sensor_interface_native", + "$SUBSYSTEM_DIR/utils/common:libsensor_utils" + ] external_deps = [ "bundle_framework:appexecfwk_base", "bundle_framework:appexecfwk_core", diff --git a/frameworks/js/napi/include/async_callback_info.h b/frameworks/js/napi/include/async_callback_info.h index fe9b012a..00de4748 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; diff --git a/frameworks/native/src/sensor_agent_proxy.cpp b/frameworks/native/src/sensor_agent_proxy.cpp index a714a3cb..bb2e7fd7 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" @@ -75,6 +76,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 +246,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 +282,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/interfaces/inner_api/sensor_agent_type.h b/interfaces/inner_api/sensor_agent_type.h index 22ceecb4..d7b45cff 100644 --- a/interfaces/inner_api/sensor_agent_type.h +++ b/interfaces/inner_api/sensor_agent_type.h @@ -184,6 +184,10 @@ typedef struct SensorUser { char name[NAME_MAX_LEN]; /**< Name of the sensor data subscriber */ RecordSensorCallback callback; /**< Callback for reporting sensor data */ UserData *userData = nullptr; /**< Reserved field for the sensor data subscriber */ + bool operator==( const SensorUser& user) const + { + return callback == user.callback; + } } SensorUser; /** diff --git a/services/hdi_connection/adapter/include/sensor_event_callback.h b/services/hdi_connection/adapter/include/sensor_event_callback.h index f1c62ff6..2d81cb85 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/sensor_event_callback.cpp b/services/hdi_connection/adapter/src/sensor_event_callback.cpp index 0f90a59f..93a021f8 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" @@ -29,14 +30,6 @@ using namespace OHOS::HiviewDFX; namespace { std::unique_ptr HdiConnection_ = std::make_unique(); constexpr int32_t HEADPOSTURE_DATA_SIZE = 20; -constexpr int64_t LOG_INTERVAL = 60000000000; -enum { - ONE_DIMENSION = 1, - TWO_DIMENSION = 2, - THREE_DIMENSION = 3, - SEVEN_DIMENSION = 7, - DEFAULT_DIMENSION = 16 -}; const std::set g_sensorTypeTrigger = { SENSOR_TYPE_ID_PROXIMITY, SENSOR_TYPE_ID_DROP_DETECTION, @@ -68,9 +61,6 @@ int32_t SensorEventCallback::OnDataEvent(const HdfSensorEvents &event) if (g_sensorTypeTrigger.find(sensorData.sensorTypeId) != g_sensorTypeTrigger.end()) { sensorData.mode = SENSOR_ON_CHANGE; } - if (g_sensorTypeTrigger.find(sensorData.sensorTypeId) != g_sensorTypeTrigger.end()) { - sensorData.mode = SENSOR_ON_CHANGE; - } CHKPR(sensorData.data, ERR_NO_INIT); if (sensorData.sensorTypeId == SENSOR_TYPE_ID_HEADPOSTURE) { sensorData.dataLen = HEADPOSTURE_DATA_SIZE; @@ -90,71 +80,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/src/sensor_service.cpp b/services/src/sensor_service.cpp index eef9a2f3..f72faf6c 100644 --- a/services/src/sensor_service.cpp +++ b/services/src/sensor_service.cpp @@ -27,6 +27,7 @@ #endif // MEMMGR_ENABLE #include "permission_util.h" +#include "print_sensor_data.h" #include "securec.h" #include "sensor.h" #include "sensor_dump.h" @@ -279,6 +280,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 +304,7 @@ ErrCode SensorService::EnableSensor(int32_t sensorId, int64_t samplingPeriodNs, if (isReportActiveInfo_) { ReportActiveInfo(sensorId, pid); } + PrintSensorData::GetInstance().ResetHdiCounter(sensorId); return ret; } @@ -331,6 +334,7 @@ ErrCode SensorService::DisableSensor(int32_t sensorId, int32_t pid) int32_t uid = clientInfo_.GetUidByPid(pid); clientInfo_.DestroyCmd(uid); clientInfo_.ClearDataQueue(sensorId); + PrintSensorData::GetInstance().ResetHdiCounter(sensorId); return sensorManager_.AfterDisableSensor(sensorId); } diff --git a/utils/common/BUILD.gn b/utils/common/BUILD.gn index 48bce26e..0d522496 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", diff --git a/utils/common/include/print_sensor_data.h b/utils/common/include/print_sensor_data.h new file mode 100644 index 00000000..6de8bddc --- /dev/null +++ b/utils/common/include/print_sensor_data.h @@ -0,0 +1,59 @@ +/* + * 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 PRINT_SENSOR_DATA +#define PRINT_SENSOR_DATA + +#include + +#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 }; + }; + LogPrintInfo info_; + std::map hdiLoginfos_ = { + {SENSOR_TYPE_ID_POSTURE, info_}, + {SENSOR_TYPE_ID_AMBIENT_LIGHT, info_}, + {SENSOR_TYPE_ID_MAGNETIC_FIELD, info_}, + }; + std::map clientLoginfos_; +}; +} // 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 00000000..195ace40 --- /dev/null +++ b/utils/common/src/print_sensor_data.cpp @@ -0,0 +1,185 @@ +/* + * 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 = 60000000000; +constexpr int32_t PRINT_TIMES = 20; + +const std::set g_triggerSensorType = { + SENSOR_TYPE_ID_HALL_EXT, + SENSOR_TYPE_ID_PROXIMITY, + SENSOR_TYPE_ID_HALL, +}; +const std::set g_continuousSensorType = { + SENSOR_TYPE_ID_POSTURE, + SENSOR_TYPE_ID_AMBIENT_LIGHT, + SENSOR_TYPE_ID_MAGNETIC_FIELD, +}; +} + +void PrintSensorData::ControlSensorHdiPrint(const SensorData &sensorData) +{ + if (g_triggerSensorType.find(sensorData.sensorTypeId) != g_triggerSensorType.end()) { + PrintHdiData(sensorData); + } + auto it = hdiLoginfos_.find(sensorData.sensorTypeId); + if (it != hdiLoginfos_.end()) { + if (it->second.count < PRINT_TIMES) { + PrintHdiData(sensorData); + if (it->second.count == 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 / 1e9) + ", "; + 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 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) +{ + if (g_triggerSensorType.find(event.sensorTypeId) != g_triggerSensorType.end()) { + PrintClientData(event); + } + if (g_continuousSensorType.find(event.sensorTypeId) != g_continuousSensorType.end()) { + auto it = clientLoginfos_.find(user); + if (it != clientLoginfos_.end()) { + if (it->second.count < PRINT_TIMES) { + PrintClientData(event); + if (it->second.count == 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 / 1e9) + ", "; + int32_t dataDim = GetDataDimension(event.sensorTypeId); + auto data = reinterpret_cast(event.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 g_continuousSensorType.find(sensorId) != g_continuousSensorType.end(); +} + +void PrintSensorData::SavePrintUserInfo(const SensorUser *user) +{ + if (clientLoginfos_.find(user) == clientLoginfos_.end()) { + LogPrintInfo info; + auto status = clientLoginfos_.insert(std::make_pair(user, info)); + if (!status.second) { + SEN_HILOGD("User has been subscribed"); + } + } +} + +void PrintSensorData::RemovePrintUserInfo(const SensorUser *user) +{ + if (clientLoginfos_.find(user) != clientLoginfos_.end()) { + clientLoginfos_.erase(user); + } +} + +void PrintSensorData::ResetHdiCounter(int32_t sensorId) +{ + auto hdiIt = hdiLoginfos_.find(sensorId); + if (hdiIt != hdiLoginfos_.end()) { + SEN_HILOGE("tmac ResetCounter in 111, id:%{public}d", sensorId); + hdiIt->second.count = 0; + hdiIt->second.lastTime = 0; + } +} +} // namespace Sensors +} // namespace OHOS -- Gitee From 2b23b5b93c0b3bbf889a14dc324f37c8698df041 Mon Sep 17 00:00:00 2001 From: bailu1992 Date: Mon, 26 Aug 2024 11:39:17 +0800 Subject: [PATCH 10/27] cherry pick 22c3d15 from https://gitee.com/bailu1992/sensors_sensor/pulls/624 Use case error modification Signed-off-by: bailu1992 --- test/unittest/interfaces/inner_api/sensor_agent_test.cpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/test/unittest/interfaces/inner_api/sensor_agent_test.cpp b/test/unittest/interfaces/inner_api/sensor_agent_test.cpp index 337445f7..fd49e6a5 100644 --- a/test/unittest/interfaces/inner_api/sensor_agent_test.cpp +++ b/test/unittest/interfaces/inner_api/sensor_agent_test.cpp @@ -450,6 +450,12 @@ HWTEST_F(SensorAgentTest, SensorNativeApiTest_002, TestSize.Level1) ret = UnsubscribeSensor(SENSOR_ID, &user2); ASSERT_EQ(ret, OHOS::Sensors::SUCCESS); + + ret = DeactivateSensor(SENSOR_ID, &user); + ASSERT_EQ(ret, OHOS::Sensors::SUCCESS); + + ret = UnsubscribeSensor(SENSOR_ID, &user); + ASSERT_EQ(ret, OHOS::Sensors::SUCCESS); } HWTEST_F(SensorAgentTest, SensorNativeApiTest_003, TestSize.Level1) -- Gitee From 92f7fed30d6755667ffe48a947443ef615576bf7 Mon Sep 17 00:00:00 2001 From: liyaoyao777 Date: Tue, 27 Aug 2024 10:14:26 +0800 Subject: [PATCH 11/27] Rectify namespace irregularities Signed-off-by: liyaoyao777 --- .../createdatachannelstub_fuzzer.cpp | 4 ++-- .../createsocketchannelstub_fuzzer.cpp | 4 ++-- .../destroydatachannelstub_fuzzer.cpp | 4 ++-- .../destroysocketchannelstub_fuzzer.cpp | 4 ++-- .../disableactiveinfocbstub_fuzzer.cpp | 4 ++-- .../enableactiveinfocbstub_fuzzer.cpp | 4 ++-- .../getactiveinfoliststub_fuzzer.cpp | 4 ++-- .../getallsensorsstub_fuzzer/getallsensorsstub_fuzzer.cpp | 4 ++-- .../resetsensorsstub_fuzzer/resetsensorsstub_fuzzer.cpp | 4 ++-- .../resumesensorsstub_fuzzer/resumesensorsstub_fuzzer.cpp | 4 ++-- .../sensordisablestub_fuzzer/sensordisablestub_fuzzer.cpp | 4 ++-- .../sensoronremoterequest_fuzzer.cpp | 4 ++-- .../suspendsensorsstub_fuzzer/suspendsensorsstub_fuzzer.cpp | 4 ++-- 13 files changed, 26 insertions(+), 26 deletions(-) diff --git a/test/fuzztest/services/createdatachannelstub_fuzzer/createdatachannelstub_fuzzer.cpp b/test/fuzztest/services/createdatachannelstub_fuzzer/createdatachannelstub_fuzzer.cpp index 84d56fa1..f3f85d1b 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 456696b9..59717834 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 08ec5740..48284574 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 004f9745..92d43754 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 c5510ddd..21dc7572 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 89920778..a99b9e13 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 3f46761b..c31efbb1 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 9e1c8f2c..ef06d085 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 f17d2dfe..41420633 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 d3ad2968..91c67ddb 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 26ec958d..f5ca6e0d 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 81224c1c..1c0a01ef 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/suspendsensorsstub_fuzzer/suspendsensorsstub_fuzzer.cpp b/test/fuzztest/services/suspendsensorsstub_fuzzer/suspendsensorsstub_fuzzer.cpp index b7fd0647..e72bab07 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) { -- Gitee From f87546031280a262781e6af5219d0e0f68fc3ced Mon Sep 17 00:00:00 2001 From: liyaoyao777 Date: Tue, 27 Aug 2024 10:25:31 +0800 Subject: [PATCH 12/27] Rectify namespace irregularities Signed-off-by: liyaoyao777 --- test/unittest/coverage/report_data_callback_test.cpp | 2 +- test/unittest/coverage/sensor_basic_data_channel_test.cpp | 6 +++--- test/unittest/interfaces/inner_api/sensor_agent_test.cpp | 2 +- test/unittest/interfaces/kits/sensor_native_test.cpp | 6 +++--- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/test/unittest/coverage/report_data_callback_test.cpp b/test/unittest/coverage/report_data_callback_test.cpp index 201bac50..e9320acb 100644 --- a/test/unittest/coverage/report_data_callback_test.cpp +++ b/test/unittest/coverage/report_data_callback_test.cpp @@ -26,7 +26,7 @@ using namespace testing::ext; namespace { SensorData* g_sensorData = new (std::nothrow) SensorData[CIRCULAR_BUF_LEN]; -} // namespace +} // namespace class SensorBasicDataChannelTest : public testing::Test { public: diff --git a/test/unittest/coverage/sensor_basic_data_channel_test.cpp b/test/unittest/coverage/sensor_basic_data_channel_test.cpp index 3001cffe..53cd8ed1 100644 --- a/test/unittest/coverage/sensor_basic_data_channel_test.cpp +++ b/test/unittest/coverage/sensor_basic_data_channel_test.cpp @@ -33,7 +33,7 @@ using namespace OHOS::HiviewDFX; namespace { constexpr int32_t INVALID_FD = 2; -} // namespace +} // namespace class SensorBasicDataChannelTest : public testing::Test { public: @@ -145,5 +145,5 @@ HWTEST_F(SensorBasicDataChannelTest, ReceiveData_001, TestSize.Level1) sensorChannel.DestroySensorBasicChannel(); } -} // namespace Sensors -} // namespace OHOS +} // namespace Sensors +} // namespace OHOS diff --git a/test/unittest/interfaces/inner_api/sensor_agent_test.cpp b/test/unittest/interfaces/inner_api/sensor_agent_test.cpp index 337445f7..b74fa07e 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/kits/sensor_native_test.cpp b/test/unittest/interfaces/kits/sensor_native_test.cpp index 45e3c75e..f2125c7d 100644 --- a/test/unittest/interfaces/kits/sensor_native_test.cpp +++ b/test/unittest/interfaces/kits/sensor_native_test.cpp @@ -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: @@ -712,5 +712,5 @@ HWTEST_F(SensorAgentTest, OH_SensorSubscriber_GetCallback_003, TestSize.Level1) OH_Sensor_DestroySubscriber(g_user); } } -} // namespace Sensors -} // namespace OHOS +} // namespace Sensors +} // namespace OHOS -- Gitee From afeb0d660a1162a569fb7f8d1fdd1d390132a754 Mon Sep 17 00:00:00 2001 From: liyaoyao777 Date: Tue, 27 Aug 2024 11:26:06 +0800 Subject: [PATCH 13/27] Rectify namespace irregularities Signed-off-by: liyaoyao777 --- test/unittest/coverage/report_data_callback_test.cpp | 2 +- test/unittest/coverage/sensor_basic_data_channel_test.cpp | 6 +++--- test/unittest/interfaces/kits/sensor_native_test.cpp | 6 +++--- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/test/unittest/coverage/report_data_callback_test.cpp b/test/unittest/coverage/report_data_callback_test.cpp index 201bac50..e9320acb 100644 --- a/test/unittest/coverage/report_data_callback_test.cpp +++ b/test/unittest/coverage/report_data_callback_test.cpp @@ -26,7 +26,7 @@ using namespace testing::ext; namespace { SensorData* g_sensorData = new (std::nothrow) SensorData[CIRCULAR_BUF_LEN]; -} // namespace +} // namespace class SensorBasicDataChannelTest : public testing::Test { public: diff --git a/test/unittest/coverage/sensor_basic_data_channel_test.cpp b/test/unittest/coverage/sensor_basic_data_channel_test.cpp index 3001cffe..53cd8ed1 100644 --- a/test/unittest/coverage/sensor_basic_data_channel_test.cpp +++ b/test/unittest/coverage/sensor_basic_data_channel_test.cpp @@ -33,7 +33,7 @@ using namespace OHOS::HiviewDFX; namespace { constexpr int32_t INVALID_FD = 2; -} // namespace +} // namespace class SensorBasicDataChannelTest : public testing::Test { public: @@ -145,5 +145,5 @@ HWTEST_F(SensorBasicDataChannelTest, ReceiveData_001, TestSize.Level1) sensorChannel.DestroySensorBasicChannel(); } -} // namespace Sensors -} // namespace OHOS +} // namespace Sensors +} // namespace OHOS diff --git a/test/unittest/interfaces/kits/sensor_native_test.cpp b/test/unittest/interfaces/kits/sensor_native_test.cpp index 45e3c75e..f2125c7d 100644 --- a/test/unittest/interfaces/kits/sensor_native_test.cpp +++ b/test/unittest/interfaces/kits/sensor_native_test.cpp @@ -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: @@ -712,5 +712,5 @@ HWTEST_F(SensorAgentTest, OH_SensorSubscriber_GetCallback_003, TestSize.Level1) OH_Sensor_DestroySubscriber(g_user); } } -} // namespace Sensors -} // namespace OHOS +} // namespace Sensors +} // namespace OHOS -- Gitee From 77702ab5233a05403029141d38584feadf326f7e Mon Sep 17 00:00:00 2001 From: liyaoyao777 Date: Tue, 27 Aug 2024 11:30:45 +0800 Subject: [PATCH 14/27] Rectify namespace irregularities Signed-off-by: liyaoyao777 --- .../intensity_processor/include/intensity_processor.h | 4 ++-- .../intensity_processor/src/intensity_processor.cpp | 6 +++--- vibration_convert/core/algorithm/onset/include/onset.h | 4 ++-- vibration_convert/core/algorithm/onset/src/onset.cpp | 6 +++--- .../core/algorithm/peak_finder/include/peak_finder.h | 4 ++-- .../core/algorithm/peak_finder/src/peak_finder.cpp | 6 +++--- vibration_convert/core/native/include/audio_parsing.h | 4 ++-- .../core/native/include/generate_vibration_json_file.h | 4 ++-- .../core/native/include/vibration_convert_core.h | 4 ++-- vibration_convert/core/native/src/audio_parsing.cpp | 6 +++--- .../core/native/src/generate_vibration_json_file.cpp | 4 ++-- .../core/native/src/vibration_convert_core.cpp | 6 +++--- 12 files changed, 29 insertions(+), 29 deletions(-) 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 3ca73839..1c80979e 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 6bcf8f86..3f457c7b 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 e4ad6ad1..6d0d1aee 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 1d6d07a5..16028363 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 2a317384..c3bf9dc4 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 efa75d0a..a33a004e 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 094ce211..fb837bfc 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 a9a60427..57d4e744 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 2acbd671..11238f62 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 1abf1d8b..4da33cb1 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 3dcc64e8..467290df 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 89d3a0e2..aca84d95 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() { @@ -1196,5 +1196,5 @@ void VibrationConvertCore::AddContinuousEventData(const ContinuousEvent &continu { continuousEvents_.push_back(continuousEvent); } -} // namespace Sensors -} // namespace OHOS +} // namespace Sensors +} // namespace OHOS -- Gitee From 921c1304f4fa68a4deac1c592c2be7b7dd52c78b Mon Sep 17 00:00:00 2001 From: liyaoyao777 Date: Tue, 27 Aug 2024 11:36:20 +0800 Subject: [PATCH 15/27] Rectify namespace irregularities Signed-off-by: liyaoyao777 --- vibration_convert/core/native/test/unittest/data.h | 4 ++-- .../core/native/test/unittest/generate_json_test.cpp | 4 ++-- vibration_convert/core/utils/include/audio_utils.h | 8 ++++---- vibration_convert/core/utils/include/utils.h | 6 +++--- vibration_convert/core/utils/src/audio_utils.cpp | 6 +++--- vibration_convert/core/utils/src/utils.cpp | 6 +++--- .../interfaces/js/include/vibrator_convert_js.h | 4 ++-- .../interfaces/js/include/vibrator_convert_napi_utils.h | 4 ++-- .../interfaces/js/src/vibrator_convert_js.cpp | 6 +++--- .../interfaces/js/src/vibrator_convert_napi_utils.cpp | 6 +++--- 10 files changed, 27 insertions(+), 27 deletions(-) diff --git a/vibration_convert/core/native/test/unittest/data.h b/vibration_convert/core/native/test/unittest/data.h index 40960a2f..e44b7c0a 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 f0e430da..67bdca09 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 57e3f681..808cd821 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 07689309..e51fa056 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 4445058a..890bed1f 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 dded5ba1..12d09759 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 5ee8b6ba..92f4429a 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 81129bc8..a847c903 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 617dec03..8dc769a8 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 3aa211ae..ad158a5c 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 -- Gitee From 82fa5fdcf31abdcef8f39869e85dfec4f32e34c0 Mon Sep 17 00:00:00 2001 From: liyaoyao777 Date: Tue, 27 Aug 2024 11:52:22 +0800 Subject: [PATCH 16/27] Rectify namespace irregularities Signed-off-by: liyaoyao777 --- frameworks/native/include/fd_listener.h | 4 ++-- frameworks/native/include/i_sensor_client.h | 4 ++-- frameworks/native/include/i_sensor_service.h | 4 ++-- frameworks/native/include/sensor_agent_proxy.h | 4 ++-- frameworks/native/include/sensor_client_proxy.h | 4 ++-- frameworks/native/include/sensor_client_stub.h | 4 ++-- frameworks/native/include/sensor_data_channel.h | 4 ++-- frameworks/native/include/sensor_event_handler.h | 4 ++-- frameworks/native/include/sensor_file_descriptor_listener.h | 4 ++-- frameworks/native/include/sensor_service_client.h | 4 ++-- frameworks/native/include/sensor_service_proxy.h | 4 ++-- frameworks/native/include/sensors_ipc_interface_code.h | 4 ++-- 12 files changed, 24 insertions(+), 24 deletions(-) diff --git a/frameworks/native/include/fd_listener.h b/frameworks/native/include/fd_listener.h index a3d97b54..7c4424d8 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 44553870..438a688d 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 7ee56812..6df89586 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 702b43d3..76ad11fc 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 6b895937..ce9b2712 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 2ed785d5..4a8a3d6b 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 ee32f464..167707c9 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 1798f5fa..710d6cd1 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 91a80a0c..bef8b685 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 47033cae..a616d42a 100755 --- a/frameworks/native/include/sensor_service_client.h +++ b/frameworks/native/include/sensor_service_client.h @@ -74,6 +74,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 6712df8f..be7fbea8 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 1cbfc1e3..2fd9df9a 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 -- Gitee From 068e2a9167b0f0e2cc10bbead73018dbf2137527 Mon Sep 17 00:00:00 2001 From: bailu1992 Date: Sat, 17 Aug 2024 09:32:23 +0800 Subject: [PATCH 17/27] Elastic component name changed Signed-off-by: bailu1992 --- bundle.json | 2 +- frameworks/native/BUILD.gn | 2 +- sensor.gni | 4 ++-- services/BUILD.gn | 6 ++++-- utils/ipc/BUILD.gn | 2 +- 5 files changed, 9 insertions(+), 7 deletions(-) diff --git a/bundle.json b/bundle.json index c331df84..197e29b7 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", diff --git a/frameworks/native/BUILD.gn b/frameworks/native/BUILD.gn index f7222ca6..865cd719 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" ] } diff --git a/sensor.gni b/sensor.gni index 4306a824..addc8d52 100644 --- a/sensor.gni +++ b/sensor.gni @@ -14,7 +14,7 @@ import("//build/ohos.gni") declare_args() { - rust_socket_ipc = false + sensor_rust_socket_ipc = false } SUBSYSTEM_DIR = "//base/sensors/sensor" @@ -23,7 +23,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" ] } diff --git a/services/BUILD.gn b/services/BUILD.gn index f8b346c3..e2bca24f 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" ] } @@ -63,6 +63,7 @@ ohos_shared_library("libsensor_service") { "hitrace:hitrace_meter", "ipc:ipc_single", "safwk:system_ability_fwk", + "samgr:samgr_proxy", ] if (sensor_memmgr_enable) { @@ -137,7 +138,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" ] } @@ -151,6 +152,7 @@ ohos_static_library("libsensor_service_static") { "hitrace:hitrace_meter", "ipc:ipc_single", "safwk:system_ability_fwk", + "samgr:samgr_proxy", ] if (sensor_memmgr_enable) { diff --git a/utils/ipc/BUILD.gn b/utils/ipc/BUILD.gn index 9bbc90d6..a37332ae 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" ] } -- Gitee From 0e09c73cfae9d5e113ac5f11ff3996824e87e2c9 Mon Sep 17 00:00:00 2001 From: tujingwei Date: Tue, 27 Aug 2024 16:17:19 +0800 Subject: [PATCH 18/27] =?UTF-8?q?feat:=20sensor=20=E9=9A=94=E7=A6=BBhisyse?= =?UTF-8?q?vent?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: tujingwei --- frameworks/native/BUILD.gn | 5 ++++- .../native/src/sensor_service_client.cpp | 4 ++++ .../native/src/sensor_service_proxy.cpp | 22 +++++++++++++++++++ sensor.gni | 9 ++++++++ services/BUILD.gn | 10 +++++++-- .../adapter/src/hdi_connection.cpp | 18 +++++++++++++++ services/src/sensor_data_processer.cpp | 2 ++ services/src/sensor_service.cpp | 8 +++++++ services/src/sensor_service_stub.cpp | 6 +++++ utils/common/BUILD.gn | 6 ++++- .../common/src/sensor_basic_data_channel.cpp | 4 ++++ 11 files changed, 90 insertions(+), 4 deletions(-) diff --git a/frameworks/native/BUILD.gn b/frameworks/native/BUILD.gn index f7222ca6..1a496e58 100644 --- a/frameworks/native/BUILD.gn +++ b/frameworks/native/BUILD.gn @@ -56,12 +56,15 @@ 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" ] + } + innerapi_tags = [ "platformsdk_indirect" ] part_name = "sensor" subsystem_name = "sensors" diff --git a/frameworks/native/src/sensor_service_client.cpp b/frameworks/native/src/sensor_service_client.cpp index 7d6ceeec..4afdbe6c 100644 --- a/frameworks/native/src/sensor_service_client.cpp +++ b/frameworks/native/src/sensor_service_client.cpp @@ -21,7 +21,9 @@ #include #include "death_recipient_template.h" +#ifdef HIVIEWDFX_HISYSEVENT_ENABLE #include "hisysevent.h" +#endif // HIVIEWDFX_HISYSEVENT_ENABLE #include "hitrace_meter.h" #include "ipc_skeleton.h" #include "sensor_errors.h" @@ -96,8 +98,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; } diff --git a/frameworks/native/src/sensor_service_proxy.cpp b/frameworks/native/src/sensor_service_proxy.cpp index 18790f4a..ea93b680 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/sensor.gni b/sensor.gni index 4306a824..674b98ea 100644 --- a/sensor.gni +++ b/sensor.gni @@ -15,6 +15,7 @@ import("//build/ohos.gni") declare_args() { rust_socket_ipc = false + hiviewdfx_hisysevent_enable = true } SUBSYSTEM_DIR = "//base/sensors/sensor" @@ -48,3 +49,11 @@ 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" ] +} else { + hiviewdfx_hisysevent_enable = false +} diff --git a/services/BUILD.gn b/services/BUILD.gn index f8b346c3..235b2bfe 100644 --- a/services/BUILD.gn +++ b/services/BUILD.gn @@ -59,7 +59,6 @@ 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", @@ -70,6 +69,10 @@ ohos_shared_library("libsensor_service") { external_deps += [ "memmgr:memmgrclient" ] } + if (hiviewdfx_hisysevent_enable) { + external_deps += [ "hisysevent:libhisysevent" ] + } + if (hdf_drivers_interface_sensor) { sources += [ "hdi_connection/adapter/src/hdi_connection.cpp", @@ -147,7 +150,6 @@ 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", @@ -158,6 +160,10 @@ ohos_static_library("libsensor_service_static") { external_deps += [ "memmgr:memmgrclient" ] } + if (hiviewdfx_hisysevent_enable) { + external_deps += [ "hisysevent:libhisysevent" ] + } + if (hdf_drivers_interface_sensor) { sources += [ "hdi_connection/adapter/src/hdi_connection.cpp", diff --git a/services/hdi_connection/adapter/src/hdi_connection.cpp b/services/hdi_connection/adapter/src/hdi_connection.cpp index 977697dd..5cd089ab 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/src/sensor_data_processer.cpp b/services/src/sensor_data_processer.cpp index 86b6f58f..8daa1907 100644 --- a/services/src/sensor_data_processer.cpp +++ b/services/src/sensor_data_processer.cpp @@ -20,7 +20,9 @@ #include #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" diff --git a/services/src/sensor_service.cpp b/services/src/sensor_service.cpp index eef9a2f3..03c04e88 100644 --- a/services/src/sensor_service.cpp +++ b/services/src/sensor_service.cpp @@ -20,7 +20,9 @@ #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" @@ -184,15 +186,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); } } diff --git a/services/src/sensor_service_stub.cpp b/services/src/sensor_service_stub.cpp index 8d07287a..3d08b091 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/utils/common/BUILD.gn b/utils/common/BUILD.gn index 48bce26e..82a1e942 100644 --- a/utils/common/BUILD.gn +++ b/utils/common/BUILD.gn @@ -43,9 +43,13 @@ 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" diff --git a/utils/common/src/sensor_basic_data_channel.cpp b/utils/common/src/sensor_basic_data_channel.cpp index 39c435ad..1851b6c6 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; -- Gitee From 2b91a5b3280fc2e5541931a72599ab1aaa52a465 Mon Sep 17 00:00:00 2001 From: tujingwei Date: Tue, 27 Aug 2024 17:04:04 +0800 Subject: [PATCH 19/27] update Signed-off-by: tujingwei --- utils/common/BUILD.gn | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/utils/common/BUILD.gn b/utils/common/BUILD.gn index 82a1e942..6b84c7ea 100644 --- a/utils/common/BUILD.gn +++ b/utils/common/BUILD.gn @@ -45,7 +45,7 @@ ohos_shared_library("libsensor_utils") { "hilog:libhilog", "ipc:ipc_single", ] - + defines = sensor_default_defines if (hiviewdfx_hisysevent_enable) { external_deps += [ "hisysevent:libhisysevent" ] -- Gitee From a54478d978a3bcb4512e9cb4def71be3dcf2aaa8 Mon Sep 17 00:00:00 2001 From: liyaoyao777 Date: Wed, 28 Aug 2024 10:32:06 +0800 Subject: [PATCH 20/27] Rectify framework namespace irregularities Signed-off-by: liyaoyao777 --- frameworks/js/napi/include/async_callback_info.h | 4 ++-- frameworks/js/napi/include/sensor_js.h | 4 ++-- frameworks/js/napi/include/sensor_napi_error.h | 4 ++-- frameworks/js/napi/include/sensor_napi_utils.h | 4 ++-- frameworks/js/napi/include/sensor_system_js.h | 4 ++-- frameworks/js/napi/src/sensor_js.cpp | 4 ++-- frameworks/js/napi/src/sensor_napi_error.cpp | 4 ++-- frameworks/js/napi/src/sensor_napi_utils.cpp | 4 ++-- frameworks/js/napi/src/sensor_system_js.cpp | 4 ++-- 9 files changed, 18 insertions(+), 18 deletions(-) diff --git a/frameworks/js/napi/include/async_callback_info.h b/frameworks/js/napi/include/async_callback_info.h index fe9b012a..5676d754 100644 --- a/frameworks/js/napi/include/async_callback_info.h +++ b/frameworks/js/napi/include/async_callback_info.h @@ -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 bf75795c..33083199 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 7a8bbb26..1ca9d63d 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 a7ce7588..cbd70ed3 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 e8ba5634..5358a9d1 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 35f75851..9a4ad9de 100644 --- a/frameworks/js/napi/src/sensor_js.cpp +++ b/frameworks/js/napi/src/sensor_js.cpp @@ -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 fa3c948e..b2696e48 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 535d6050..f797e968 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 fd479933..f2a3ed0e 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 -- Gitee From 1a62be2eee84a6ed5efd9c68c3c95479e6208bd5 Mon Sep 17 00:00:00 2001 From: liyaoyao777 Date: Wed, 28 Aug 2024 10:53:41 +0800 Subject: [PATCH 21/27] Rectification log printing is not standard Signed-off-by: liyaoyao777 --- frameworks/js/napi/src/sensor_js.cpp | 2 +- frameworks/native/src/sensor_data_channel.cpp | 2 +- services/src/sensor_dump.cpp | 2 +- utils/ipc/src/stream_socket.cpp | 4 ++-- vibration_convert/core/native/src/vibration_convert_core.cpp | 2 +- 5 files changed, 6 insertions(+), 6 deletions(-) diff --git a/frameworks/js/napi/src/sensor_js.cpp b/frameworks/js/napi/src/sensor_js.cpp index 35f75851..1ddbfe29 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); diff --git a/frameworks/native/src/sensor_data_channel.cpp b/frameworks/native/src/sensor_data_channel.cpp index c5473295..4a2bfc13 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/services/src/sensor_dump.cpp b/services/src/sensor_dump.cpp index 93950201..767222bb 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/utils/ipc/src/stream_socket.cpp b/utils/ipc/src/stream_socket.cpp index 48c3fed9..e77dbb1d 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/native/src/vibration_convert_core.cpp b/vibration_convert/core/native/src/vibration_convert_core.cpp index aca84d95..22b1db4b 100644 --- a/vibration_convert/core/native/src/vibration_convert_core.cpp +++ b/vibration_convert/core/native/src/vibration_convert_core.cpp @@ -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) { -- Gitee From 63ae14040bb1e0e26bac53a36e0bc14ecc8350c7 Mon Sep 17 00:00:00 2001 From: tujingwei Date: Wed, 28 Aug 2024 06:24:51 +0000 Subject: [PATCH 22/27] update sensor.gni. Signed-off-by: tujingwei --- sensor.gni | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/sensor.gni b/sensor.gni index 98afe47b..eed38ee0 100644 --- a/sensor.gni +++ b/sensor.gni @@ -14,7 +14,7 @@ import("//build/ohos.gni") declare_args() { - hiviewdfx_hisysevent_enable = true + hiviewdfx_hisysevent_enable = false sensor_rust_socket_ipc = false } @@ -50,10 +50,9 @@ if (build_variant == "root") { sensor_build_eng = false } -if (!defined(global_parts_info) || +if (defined(global_parts_info) && defined(global_parts_info.hiviewdfx_hisysevent)) { hiviewdfx_hisysevent_enable = true sensor_default_defines += [ "HIVIEWDFX_HISYSEVENT_ENABLE" ] -} else { - hiviewdfx_hisysevent_enable = false } + -- Gitee From 91fe5da1e17847581ad884c3e22f9b129a5a97b4 Mon Sep 17 00:00:00 2001 From: tujingwei Date: Wed, 28 Aug 2024 06:43:30 +0000 Subject: [PATCH 23/27] update sensor.gni. Signed-off-by: tujingwei --- sensor.gni | 1 - 1 file changed, 1 deletion(-) diff --git a/sensor.gni b/sensor.gni index eed38ee0..22c912e2 100644 --- a/sensor.gni +++ b/sensor.gni @@ -55,4 +55,3 @@ if (defined(global_parts_info) && hiviewdfx_hisysevent_enable = true sensor_default_defines += [ "HIVIEWDFX_HISYSEVENT_ENABLE" ] } - -- Gitee From d10108bc14bfe9ffb227c5c681225691e9188836 Mon Sep 17 00:00:00 2001 From: tu-xinxin Date: Wed, 28 Aug 2024 16:44:04 +0800 Subject: [PATCH 24/27] =?UTF-8?q?sensor=E8=A7=A3=E8=80=A6hitrace?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: tu-xinxin --- frameworks/native/BUILD.gn | 5 +- .../native/src/sensor_service_client.cpp | 50 +++++++++++++++++++ sensor.gni | 7 +++ services/BUILD.gn | 10 +++- .../interface/src/sensor_hdi_connection.cpp | 30 +++++++++++ 5 files changed, 99 insertions(+), 3 deletions(-) diff --git a/frameworks/native/BUILD.gn b/frameworks/native/BUILD.gn index dd5176e7..6ee82e32 100644 --- a/frameworks/native/BUILD.gn +++ b/frameworks/native/BUILD.gn @@ -56,7 +56,6 @@ ohos_shared_library("libsensor_client") { "c_utils:utils", "eventhandler:libeventhandler", "hilog:libhilog", - "hitrace:hitrace_meter", "ipc:ipc_single", "samgr:samgr_proxy", ] @@ -65,6 +64,10 @@ ohos_shared_library("libsensor_client") { external_deps += [ "hisysevent:libhisysevent" ] } + if (hiviewdfx_hitrace_enable) { + external_deps += [ "hitrace:hitrace_meter" ] + } + innerapi_tags = [ "platformsdk_indirect" ] part_name = "sensor" subsystem_name = "sensors" diff --git a/frameworks/native/src/sensor_service_client.cpp b/frameworks/native/src/sensor_service_client.cpp index 4afdbe6c..f81f4bd8 100644 --- a/frameworks/native/src/sensor_service_client.cpp +++ b/frameworks/native/src/sensor_service_client.cpp @@ -24,7 +24,9 @@ #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" @@ -136,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); } @@ -155,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); } @@ -194,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; } @@ -213,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; } @@ -307,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; } @@ -323,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; } @@ -339,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; } @@ -382,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; @@ -414,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; } @@ -493,12 +535,16 @@ int32_t SensorServiceClient::CreateSocketChannel() std::lock_guard clientLock(clientMutex_); CHKPR(sensorServer_, ERROR); int32_t clientFd = -1; +#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); ret = sensorServer_->CreateSocketChannel(remoteObject, clientFd); +#ifdef HIVIEWDFX_HITRACE_ENABLE FinishTrace(HITRACE_TAG_SENSORS); +#endif // HIVIEWDFX_HITRACE_ENABLE if (ret != ERR_OK || clientFd < 0) { Close(); SEN_HILOGE("Create socket channel failed, ret:%{public}d", ret); @@ -519,9 +565,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/sensor.gni b/sensor.gni index 22c912e2..0f548ad6 100644 --- a/sensor.gni +++ b/sensor.gni @@ -16,6 +16,7 @@ import("//build/ohos.gni") declare_args() { hiviewdfx_hisysevent_enable = false sensor_rust_socket_ipc = false + hiviewdfx_hitrace_enable = false } SUBSYSTEM_DIR = "//base/sensors/sensor" @@ -55,3 +56,9 @@ if (defined(global_parts_info) && 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 685063ba..31681dd0 100644 --- a/services/BUILD.gn +++ b/services/BUILD.gn @@ -59,7 +59,6 @@ ohos_shared_library("libsensor_service") { "access_token:libtokenid_sdk", "c_utils:utils", "hilog:libhilog", - "hitrace:hitrace_meter", "ipc:ipc_single", "safwk:system_ability_fwk", "samgr:samgr_proxy", @@ -74,6 +73,10 @@ ohos_shared_library("libsensor_service") { 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", @@ -151,7 +154,6 @@ ohos_static_library("libsensor_service_static") { "access_token:libtokenid_sdk", "c_utils:utils", "hilog:libhilog", - "hitrace:hitrace_meter", "ipc:ipc_single", "safwk:system_ability_fwk", "samgr:samgr_proxy", @@ -166,6 +168,10 @@ ohos_static_library("libsensor_service_static") { 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/interface/src/sensor_hdi_connection.cpp b/services/hdi_connection/interface/src/sensor_hdi_connection.cpp index 0f755ac9..65568e33 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 Date: Sat, 31 Aug 2024 07:43:35 +0000 Subject: [PATCH 25/27] fix capi for sensor Signed-off-by: lixiangpeng5 Change-Id: Ib76ad9448021fc7c5f5195b783b8e6bfe8e472e1 --- interfaces/kits/c/oh_sensor.h | 20 +++++++++---- interfaces/kits/c/oh_sensor_type.h | 45 ++++++++++++++++++++---------- 2 files changed, 45 insertions(+), 20 deletions(-) diff --git a/interfaces/kits/c/oh_sensor.h b/interfaces/kits/c/oh_sensor.h index 3c9b54dd..5b2718a9 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 e0ab040e..0641a9c0 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 -- Gitee From 9aede0f384e2512cdb3901d5a400800e0cbd309e Mon Sep 17 00:00:00 2001 From: tu-xinxin Date: Tue, 3 Sep 2024 01:51:19 +0800 Subject: [PATCH 26/27] =?UTF-8?q?sensor=E8=A7=A3=E8=80=A6hitrace=EF=BC=8C?= =?UTF-8?q?=E8=B6=85=E5=A4=A7=E5=87=BD=E6=95=B0=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: tu-xinxin --- .../native/include/sensor_service_client.h | 1 + .../native/src/sensor_service_client.cpp | 26 ++++++++++++------- 2 files changed, 17 insertions(+), 10 deletions(-) diff --git a/frameworks/native/include/sensor_service_client.h b/frameworks/native/include/sensor_service_client.h index a616d42a..1dc3da36 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; diff --git a/frameworks/native/src/sensor_service_client.cpp b/frameworks/native/src/sensor_service_client.cpp index f81f4bd8..f3a329cf 100644 --- a/frameworks/native/src/sensor_service_client.cpp +++ b/frameworks/native/src/sensor_service_client.cpp @@ -524,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; @@ -535,16 +550,7 @@ int32_t SensorServiceClient::CreateSocketChannel() std::lock_guard clientLock(clientMutex_); CHKPR(sensorServer_, ERROR); int32_t clientFd = -1; -#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); - ret = sensorServer_->CreateSocketChannel(remoteObject, clientFd); -#ifdef HIVIEWDFX_HITRACE_ENABLE - FinishTrace(HITRACE_TAG_SENSORS); -#endif // HIVIEWDFX_HITRACE_ENABLE + ret = CreateSocketClientFd(clientFd); if (ret != ERR_OK || clientFd < 0) { Close(); SEN_HILOGE("Create socket channel failed, ret:%{public}d", ret); -- Gitee From 7ed5199bd0529f4f556e8d954877f996da988f97 Mon Sep 17 00:00:00 2001 From: cff-gite Date: Tue, 3 Sep 2024 16:05:19 +0800 Subject: [PATCH 27/27] Code branch difference modification Signed-off-by: cff-gite --- frameworks/js/napi/BUILD.gn | 17 ++- frameworks/native/BUILD.gn | 6 +- interfaces/inner_api/sensor_agent_type.h | 2 +- .../adapter/src/sensor_event_callback.cpp | 16 +-- .../interfaces/sensoragent_fuzzer/BUILD.gn | 9 +- .../sensoragent_fuzzer/sensoragent_fuzzer.cpp | 97 +++++----------- test/fuzztest/services/BUILD.gn | 11 -- .../createsocketchannel_fuzzer/BUILD.gn | 74 ------------ .../createsocketchannel_fuzzer/corpus/init | 14 --- .../createsocketchannel_fuzzer.cpp | 106 ----------------- .../createsocketchannel_fuzzer.h | 22 ---- .../createsocketchannel_fuzzer/project.xml | 25 ---- .../destroysensorchannel_fuzzer/BUILD.gn | 73 ------------ .../destroysensorchannel_fuzzer/corpus/init | 14 --- .../destroysensorchannel_fuzzer.cpp | 104 ----------------- .../destroysensorchannel_fuzzer.h | 22 ---- .../destroysensorchannel_fuzzer/project.xml | 25 ---- .../service/getactiveinfolist_fuzzer/BUILD.gn | 74 ------------ .../getactiveinfolist_fuzzer/corpus/init | 14 --- .../getactiveinfolist_fuzzer.cpp | 105 ----------------- .../getactiveinfolist_fuzzer.h | 22 ---- .../getactiveinfolist_fuzzer/project.xml | 25 ---- .../services/service/onstart_fuzzer/BUILD.gn | 74 ------------ .../service/onstart_fuzzer/corpus/init | 14 --- .../service/onstart_fuzzer/onstart_fuzzer.cpp | 101 ----------------- .../service/onstart_fuzzer/onstart_fuzzer.h | 22 ---- .../service/onstart_fuzzer/project.xml | 25 ---- .../processdeathobserver_fuzzer/BUILD.gn | 73 ------------ .../processdeathobserver_fuzzer/corpus/init | 14 --- .../processdeathobserver_fuzzer.cpp | 90 --------------- .../processdeathobserver_fuzzer.h | 22 ---- .../processdeathobserver_fuzzer/project.xml | 25 ---- .../BUILD.gn | 73 ------------ .../corpus/init | 14 --- .../project.xml | 25 ---- .../registerclientdeathrecipient_fuzzer.cpp | 107 ------------------ .../registerclientdeathrecipient_fuzzer.h | 22 ---- .../registerpermcallback_fuzzer/BUILD.gn | 73 ------------ .../registerpermcallback_fuzzer/corpus/init | 14 --- .../registerpermcallback_fuzzer/project.xml | 25 ---- .../registerpermcallback_fuzzer.cpp | 103 ----------------- .../registerpermcallback_fuzzer.h | 22 ---- .../service/reportactiveinfo_fuzzer/BUILD.gn | 74 ------------ .../reportactiveinfo_fuzzer/corpus/init | 14 --- .../reportactiveinfo_fuzzer/project.xml | 25 ---- .../reportactiveinfo_fuzzer.cpp | 105 ----------------- .../reportactiveinfo_fuzzer.h | 22 ---- .../reportonchangedata_fuzzer/BUILD.gn | 74 ------------ .../reportonchangedata_fuzzer/corpus/init | 14 --- .../reportonchangedata_fuzzer/project.xml | 25 ---- .../reportonchangedata_fuzzer.cpp | 103 ----------------- .../reportonchangedata_fuzzer.h | 22 ---- .../reportsensorsysevent_fuzzer/BUILD.gn | 73 ------------ .../reportsensorsysevent_fuzzer/corpus/init | 14 --- .../reportsensorsysevent_fuzzer/project.xml | 25 ---- .../reportsensorsysevent_fuzzer.cpp | 107 ------------------ .../reportsensorsysevent_fuzzer.h | 22 ---- .../transferdatachannel_fuzzer/BUILD.gn | 74 ------------ .../transferdatachannel_fuzzer/corpus/init | 14 --- .../transferdatachannel_fuzzer/project.xml | 25 ---- .../transferdatachannel_fuzzer.cpp | 91 --------------- .../transferdatachannel_fuzzer.h | 22 ---- .../inner_api/drop_detection_test.cpp | 40 +++---- .../inner_api/sensor_agent_test.cpp | 6 - .../unittest/interfaces/js/sensor/config.json | 3 +- .../conversion/src/conversion_fft.cpp | 14 +-- .../conversion/src/conversion_mfcc.cpp | 8 +- 67 files changed, 80 insertions(+), 2751 deletions(-) delete mode 100644 test/fuzztest/services/service/createsocketchannel_fuzzer/BUILD.gn delete mode 100644 test/fuzztest/services/service/createsocketchannel_fuzzer/corpus/init delete mode 100644 test/fuzztest/services/service/createsocketchannel_fuzzer/createsocketchannel_fuzzer.cpp delete mode 100644 test/fuzztest/services/service/createsocketchannel_fuzzer/createsocketchannel_fuzzer.h delete mode 100644 test/fuzztest/services/service/createsocketchannel_fuzzer/project.xml delete mode 100644 test/fuzztest/services/service/destroysensorchannel_fuzzer/BUILD.gn delete mode 100644 test/fuzztest/services/service/destroysensorchannel_fuzzer/corpus/init delete mode 100644 test/fuzztest/services/service/destroysensorchannel_fuzzer/destroysensorchannel_fuzzer.cpp delete mode 100644 test/fuzztest/services/service/destroysensorchannel_fuzzer/destroysensorchannel_fuzzer.h delete mode 100644 test/fuzztest/services/service/destroysensorchannel_fuzzer/project.xml delete mode 100644 test/fuzztest/services/service/getactiveinfolist_fuzzer/BUILD.gn delete mode 100644 test/fuzztest/services/service/getactiveinfolist_fuzzer/corpus/init delete mode 100644 test/fuzztest/services/service/getactiveinfolist_fuzzer/getactiveinfolist_fuzzer.cpp delete mode 100644 test/fuzztest/services/service/getactiveinfolist_fuzzer/getactiveinfolist_fuzzer.h delete mode 100644 test/fuzztest/services/service/getactiveinfolist_fuzzer/project.xml delete mode 100644 test/fuzztest/services/service/onstart_fuzzer/BUILD.gn delete mode 100644 test/fuzztest/services/service/onstart_fuzzer/corpus/init delete mode 100644 test/fuzztest/services/service/onstart_fuzzer/onstart_fuzzer.cpp delete mode 100644 test/fuzztest/services/service/onstart_fuzzer/onstart_fuzzer.h delete mode 100644 test/fuzztest/services/service/onstart_fuzzer/project.xml delete mode 100644 test/fuzztest/services/service/processdeathobserver_fuzzer/BUILD.gn delete mode 100644 test/fuzztest/services/service/processdeathobserver_fuzzer/corpus/init delete mode 100644 test/fuzztest/services/service/processdeathobserver_fuzzer/processdeathobserver_fuzzer.cpp delete mode 100644 test/fuzztest/services/service/processdeathobserver_fuzzer/processdeathobserver_fuzzer.h delete mode 100644 test/fuzztest/services/service/processdeathobserver_fuzzer/project.xml delete mode 100644 test/fuzztest/services/service/registerclientdeathrecipient_fuzzer/BUILD.gn delete mode 100644 test/fuzztest/services/service/registerclientdeathrecipient_fuzzer/corpus/init delete mode 100644 test/fuzztest/services/service/registerclientdeathrecipient_fuzzer/project.xml delete mode 100644 test/fuzztest/services/service/registerclientdeathrecipient_fuzzer/registerclientdeathrecipient_fuzzer.cpp delete mode 100644 test/fuzztest/services/service/registerclientdeathrecipient_fuzzer/registerclientdeathrecipient_fuzzer.h delete mode 100644 test/fuzztest/services/service/registerpermcallback_fuzzer/BUILD.gn delete mode 100644 test/fuzztest/services/service/registerpermcallback_fuzzer/corpus/init delete mode 100644 test/fuzztest/services/service/registerpermcallback_fuzzer/project.xml delete mode 100644 test/fuzztest/services/service/registerpermcallback_fuzzer/registerpermcallback_fuzzer.cpp delete mode 100644 test/fuzztest/services/service/registerpermcallback_fuzzer/registerpermcallback_fuzzer.h delete mode 100644 test/fuzztest/services/service/reportactiveinfo_fuzzer/BUILD.gn delete mode 100644 test/fuzztest/services/service/reportactiveinfo_fuzzer/corpus/init delete mode 100644 test/fuzztest/services/service/reportactiveinfo_fuzzer/project.xml delete mode 100644 test/fuzztest/services/service/reportactiveinfo_fuzzer/reportactiveinfo_fuzzer.cpp delete mode 100644 test/fuzztest/services/service/reportactiveinfo_fuzzer/reportactiveinfo_fuzzer.h delete mode 100644 test/fuzztest/services/service/reportonchangedata_fuzzer/BUILD.gn delete mode 100644 test/fuzztest/services/service/reportonchangedata_fuzzer/corpus/init delete mode 100644 test/fuzztest/services/service/reportonchangedata_fuzzer/project.xml delete mode 100644 test/fuzztest/services/service/reportonchangedata_fuzzer/reportonchangedata_fuzzer.cpp delete mode 100644 test/fuzztest/services/service/reportonchangedata_fuzzer/reportonchangedata_fuzzer.h delete mode 100644 test/fuzztest/services/service/reportsensorsysevent_fuzzer/BUILD.gn delete mode 100644 test/fuzztest/services/service/reportsensorsysevent_fuzzer/corpus/init delete mode 100644 test/fuzztest/services/service/reportsensorsysevent_fuzzer/project.xml delete mode 100644 test/fuzztest/services/service/reportsensorsysevent_fuzzer/reportsensorsysevent_fuzzer.cpp delete mode 100644 test/fuzztest/services/service/reportsensorsysevent_fuzzer/reportsensorsysevent_fuzzer.h delete mode 100644 test/fuzztest/services/service/transferdatachannel_fuzzer/BUILD.gn delete mode 100644 test/fuzztest/services/service/transferdatachannel_fuzzer/corpus/init delete mode 100644 test/fuzztest/services/service/transferdatachannel_fuzzer/project.xml delete mode 100644 test/fuzztest/services/service/transferdatachannel_fuzzer/transferdatachannel_fuzzer.cpp delete mode 100644 test/fuzztest/services/service/transferdatachannel_fuzzer/transferdatachannel_fuzzer.h diff --git a/frameworks/js/napi/BUILD.gn b/frameworks/js/napi/BUILD.gn index dbbfda13..b6f97fdd 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,16 +37,7 @@ 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", - "$SUBSYSTEM_DIR/utils/common:libsensor_utils", - ] + deps = [ "$SUBSYSTEM_DIR/frameworks/native:sensor_interface_native" ] external_deps = [ "bundle_framework:appexecfwk_base", "bundle_framework:appexecfwk_core", diff --git a/frameworks/native/BUILD.gn b/frameworks/native/BUILD.gn index 6ee82e32..e0ee11db 100644 --- a/frameworks/native/BUILD.gn +++ b/frameworks/native/BUILD.gn @@ -97,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 @@ -110,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/interfaces/inner_api/sensor_agent_type.h b/interfaces/inner_api/sensor_agent_type.h index 22ceecb4..ac5cf63a 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/services/hdi_connection/adapter/src/sensor_event_callback.cpp b/services/hdi_connection/adapter/src/sensor_event_callback.cpp index 93a021f8..d632c5b2 100644 --- a/services/hdi_connection/adapter/src/sensor_event_callback.cpp +++ b/services/hdi_connection/adapter/src/sensor_event_callback.cpp @@ -30,12 +30,13 @@ using namespace OHOS::HiviewDFX; namespace { std::unique_ptr HdiConnection_ = std::make_unique(); constexpr int32_t HEADPOSTURE_DATA_SIZE = 20; -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 +constexpr int64_t LOG_INTERVAL = 60000000000; +enum { + ONE_DIMENSION = 1, + TWO_DIMENSION = 2, + THREE_DIMENSION = 3, + SEVEN_DIMENSION = 7, + DEFAULT_DIMENSION = 16 }; } // namespace @@ -58,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); diff --git a/test/fuzztest/interfaces/sensoragent_fuzzer/BUILD.gn b/test/fuzztest/interfaces/sensoragent_fuzzer/BUILD.gn index c379e577..2528534f 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 f96be5b0..675e90b5 100644 --- a/test/fuzztest/interfaces/sensoragent_fuzzer/sensoragent_fuzzer.cpp +++ b/test/fuzztest/interfaces/sensoragent_fuzzer/sensoragent_fuzzer.cpp @@ -15,63 +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" - -namespace OHOS { -namespace Sensors { -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) { @@ -96,31 +43,39 @@ 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; } -} // namespace Sensors -} // namespace OHOS extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) { - OHOS::Sensors::SensorAgentFuzzTest(data, size); + SensorAgentFuzzTest(data, size); return 0; } diff --git a/test/fuzztest/services/BUILD.gn b/test/fuzztest/services/BUILD.gn index c15f5661..6632a988 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/service/createsocketchannel_fuzzer/BUILD.gn b/test/fuzztest/services/service/createsocketchannel_fuzzer/BUILD.gn deleted file mode 100644 index 26378f39..00000000 --- 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 e7c3fecd..00000000 --- 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 06141b7c..00000000 --- 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 98a294f5..00000000 --- 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 98df56fb..00000000 --- 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 11f710e7..00000000 --- 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 e7c3fecd..00000000 --- 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 eb0b817d..00000000 --- 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 67dc3af3..00000000 --- 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 98df56fb..00000000 --- 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 46dfb718..00000000 --- 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 e7c3fecd..00000000 --- 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 1c07d73c..00000000 --- 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 e5b217b2..00000000 --- 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 98df56fb..00000000 --- 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/BUILD.gn b/test/fuzztest/services/service/onstart_fuzzer/BUILD.gn deleted file mode 100644 index b524a801..00000000 --- a/test/fuzztest/services/service/onstart_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("OnStartFuzzTest") { - module_out_path = FUZZ_MODULE_OUT_PATH - - fuzz_config_file = - "$SUBSYSTEM_DIR/test/fuzztest/services/service/onstart_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/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", - ] - - sources = [ "onstart_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 - ":OnStartFuzzTest", - ] -} 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 e7c3fecd..00000000 --- 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 051ec4f0..00000000 --- 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/onstart_fuzzer.h b/test/fuzztest/services/service/onstart_fuzzer/onstart_fuzzer.h deleted file mode 100644 index 67dc3af3..00000000 --- a/test/fuzztest/services/service/onstart_fuzzer/onstart_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/onstart_fuzzer/project.xml b/test/fuzztest/services/service/onstart_fuzzer/project.xml deleted file mode 100644 index 98df56fb..00000000 --- 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 e9614fc7..00000000 --- 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 e7c3fecd..00000000 --- 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 b72d9c95..00000000 --- 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 ea80ae35..00000000 --- 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 98df56fb..00000000 --- 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 556816d2..00000000 --- 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 e7c3fecd..00000000 --- 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 98df56fb..00000000 --- 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 221ddc9a..00000000 --- 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 0db8d7d7..00000000 --- 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 ab0f298c..00000000 --- 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 e7c3fecd..00000000 --- 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 98df56fb..00000000 --- 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 286f0b51..00000000 --- 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 4a9fcbe7..00000000 --- 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 da2e315b..00000000 --- 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 e7c3fecd..00000000 --- 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 98df56fb..00000000 --- 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 f597b240..00000000 --- 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 5f783f64..00000000 --- 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 2efd1e45..00000000 --- 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 e7c3fecd..00000000 --- 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 98df56fb..00000000 --- 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 556f94dc..00000000 --- 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 e3e1091b..00000000 --- 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 0a1803a6..00000000 --- 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 e7c3fecd..00000000 --- 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 98df56fb..00000000 --- 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 c26f6f18..00000000 --- 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 2472b099..00000000 --- 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 a45b526a..00000000 --- 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 e7c3fecd..00000000 --- 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 98df56fb..00000000 --- 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 3874ebdb..00000000 --- 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 36616538..00000000 --- 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/unittest/interfaces/inner_api/drop_detection_test.cpp b/test/unittest/interfaces/inner_api/drop_detection_test.cpp index 255c8c3f..cfae3d7a 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 a46b9edd..b74fa07e 100644 --- a/test/unittest/interfaces/inner_api/sensor_agent_test.cpp +++ b/test/unittest/interfaces/inner_api/sensor_agent_test.cpp @@ -450,12 +450,6 @@ HWTEST_F(SensorAgentTest, SensorNativeApiTest_002, TestSize.Level1) ret = UnsubscribeSensor(SENSOR_ID, &user2); ASSERT_EQ(ret, OHOS::Sensors::SUCCESS); - - ret = DeactivateSensor(SENSOR_ID, &user); - ASSERT_EQ(ret, OHOS::Sensors::SUCCESS); - - ret = UnsubscribeSensor(SENSOR_ID, &user); - ASSERT_EQ(ret, OHOS::Sensors::SUCCESS); } HWTEST_F(SensorAgentTest, SensorNativeApiTest_003, TestSize.Level1) diff --git a/test/unittest/interfaces/js/sensor/config.json b/test/unittest/interfaces/js/sensor/config.json index aabb3f4b..435079f9 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/vibration_convert/core/algorithm/conversion/src/conversion_fft.cpp b/vibration_convert/core/algorithm/conversion/src/conversion_fft.cpp index e2e135be..0ad28e27 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 126329b8..e1fdadd1 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], -- Gitee