From bf973932590dbac4499593737d1b6a8319c17c47 Mon Sep 17 00:00:00 2001 From: lixiangpeng5 Date: Mon, 24 Apr 2023 12:53:03 +0000 Subject: [PATCH 1/4] fix by code check Signed-off-by: lixiangpeng5 Change-Id: I3641e41c9cf23b9027855a0c3dfe6ee521f2c090 --- .../native/miscdevice/src/light_client.cpp | 3 +- .../light/test/unittest/light_agent_test.cpp | 76 +++++++++---------- .../src/custom_vibration_matcher.cpp | 13 ++-- 3 files changed, 48 insertions(+), 44 deletions(-) diff --git a/frameworks/native/miscdevice/src/light_client.cpp b/frameworks/native/miscdevice/src/light_client.cpp index 026eb8f..8884bf0 100755 --- a/frameworks/native/miscdevice/src/light_client.cpp +++ b/frameworks/native/miscdevice/src/light_client.cpp @@ -62,7 +62,8 @@ int32_t LightClient::InitLightClient() retry++; } HiSysEventWrite(HiviewDFX::HiSysEvent::Domain::MISCDEVICE, "MISC_SERVICE_EXCEPTION", - HiviewDFX::HiSysEvent::EventType::FAULT, "PKG_NAME", "InitLightClient", "ERROR_CODE", MISC_NATIVE_GET_SERVICE_ERR); + HiviewDFX::HiSysEvent::EventType::FAULT, "PKG_NAME", "InitLightClient", "ERROR_CODE", + MISC_NATIVE_GET_SERVICE_ERR); MISC_HILOGE("Get service failed"); return MISC_NATIVE_GET_SERVICE_ERR; } diff --git a/interfaces/native/light/test/unittest/light_agent_test.cpp b/interfaces/native/light/test/unittest/light_agent_test.cpp index bf528a2..7047734 100755 --- a/interfaces/native/light/test/unittest/light_agent_test.cpp +++ b/interfaces/native/light/test/unittest/light_agent_test.cpp @@ -37,10 +37,10 @@ public: void TearDown() {} }; -LightInfo *lightInfo_ = nullptr; -int32_t lightId_ = -1; -int32_t invalidLightId_ = -1; -int32_t lightType_ = -1; +LightInfo *g_lightInfo = nullptr; +int32_t g_lightId = -1; +int32_t g_invalidLightId = -1; +int32_t g_lightType = -1; /** * @tc.name: StartLightTest_001 @@ -52,12 +52,12 @@ HWTEST_F(LightAgentTest, StartLightTest_001, TestSize.Level1) { CALL_LOG_ENTER; int32_t count = -1; - int32_t ret = GetLightList(&lightInfo_, count); + int32_t ret = GetLightList(&g_lightInfo, count); for (int32_t i = 0; i < count; ++i) { MISC_HILOGI("lightId: %{public}d, lightName: %{public}s, lightNumber: %{public}d, lightType: %{public}d", - lightInfo_[i].lightId, lightInfo_[i].lightName, lightInfo_[i].lightNumber, lightInfo_[i].lightType); - lightId_ = lightInfo_[i].lightId; - lightType_ = lightInfo_[i].lightType; + g_lightInfo[i].lightId, g_lightInfo[i].lightName, g_lightInfo[i].lightNumber, g_lightInfo[i].lightType); + g_lightId = g_lightInfo[i].lightId; + g_lightType = g_lightInfo[i].lightType; } ASSERT_EQ(ret, 0); } @@ -119,15 +119,15 @@ HWTEST_F(LightAgentTest, StartLightTest_003, TestSize.Level1) int32_t powerLightId = 1; TurnOff(powerLightId); LightColor color; - bool ret = GetLightColor(color, lightType_); - if (!ret) { - ASSERT_EQ(ret, -1); + bool flag = GetLightColor(color, g_lightType); + if (!flag) { + ASSERT_EQ(flag, -1); } else { LightAnimation animation; animation.mode = LIGHT_MODE_DEFAULT; animation.onTime = 50; animation.offTime = 50; - int32_t ret = TurnOn(lightId_, color, animation); + int32_t ret = TurnOn(g_lightId, color, animation); std::this_thread::sleep_for(std::chrono::milliseconds(TIME_WAIT_FOR_OP)); ASSERT_EQ(ret, 0); } @@ -143,15 +143,15 @@ HWTEST_F(LightAgentTest, StartLightTest_004, TestSize.Level1) { CALL_LOG_ENTER; LightColor color; - bool ret = GetLightColor(color, lightType_); - if (!ret) { - ASSERT_EQ(ret, -1); + bool flag = GetLightColor(color, g_lightType); + if (!flag) { + ASSERT_EQ(flag, -1); } else { LightAnimation animation; animation.mode = LIGHT_MODE_BUTT; animation.onTime = 50; animation.offTime = 50; - int32_t ret = TurnOn(lightId_, color, animation); + int32_t ret = TurnOn(g_lightId, color, animation); ASSERT_EQ(ret, -1); } } @@ -166,15 +166,15 @@ HWTEST_F(LightAgentTest, StartLightTest_005, TestSize.Level1) { CALL_LOG_ENTER; LightColor color; - bool ret = GetLightColor(color, lightType_); - if (!ret) { - ASSERT_EQ(ret, -1); + bool flag = GetLightColor(color, g_lightType); + if (!flag) { + ASSERT_EQ(flag, -1); } else { LightAnimation animation; animation.mode = -1; animation.onTime = 50; animation.offTime = 50; - int32_t ret = TurnOn(lightId_, color, animation); + int32_t ret = TurnOn(g_lightId, color, animation); ASSERT_EQ(ret, -1); } } @@ -189,15 +189,15 @@ HWTEST_F(LightAgentTest, StartLightTest_006, TestSize.Level1) { CALL_LOG_ENTER; LightColor color; - bool ret = GetLightColor(color, lightType_); - if (!ret) { - ASSERT_EQ(ret, -1); + bool flag = GetLightColor(color, g_lightType); + if (!flag) { + ASSERT_EQ(flag, -1); } else { LightAnimation animation; animation.mode = LIGHT_MODE_DEFAULT; animation.onTime = -1; animation.offTime = 50; - int32_t ret = TurnOn(lightId_, color, animation); + int32_t ret = TurnOn(g_lightId, color, animation); ASSERT_EQ(ret, -1); } } @@ -212,15 +212,15 @@ HWTEST_F(LightAgentTest, StartLightTest_007, TestSize.Level1) { CALL_LOG_ENTER; LightColor color; - bool ret = GetLightColor(color, lightType_); - if (!ret) { - ASSERT_EQ(ret, -1); + bool flag = GetLightColor(color, g_lightType); + if (!flag) { + ASSERT_EQ(flag, -1); } else { LightAnimation animation; animation.mode = LIGHT_MODE_DEFAULT; animation.onTime = 50; animation.offTime = -1; - int32_t ret = TurnOn(lightId_, color, animation); + int32_t ret = TurnOn(g_lightId, color, animation); ASSERT_EQ(ret, -1); } } @@ -235,15 +235,15 @@ HWTEST_F(LightAgentTest, StartLightTest_008, TestSize.Level1) { CALL_LOG_ENTER; LightColor color; - bool ret = GetLightColor(color, lightType_); - if (!ret) { - ASSERT_EQ(ret, -1); + bool flag = GetLightColor(color, g_lightType); + if (!flag) { + ASSERT_EQ(flag, -1); } else { LightAnimation animation; animation.mode = LIGHT_MODE_DEFAULT; animation.onTime = 2; animation.offTime = 2; - int32_t ret = TurnOn(lightId_, color, animation); + int32_t ret = TurnOn(g_lightId, color, animation); std::this_thread::sleep_for(std::chrono::milliseconds(TIME_WAIT_FOR_OP)); ASSERT_EQ(ret, 0); } @@ -259,15 +259,15 @@ HWTEST_F(LightAgentTest, StartLightTest_009, TestSize.Level1) { CALL_LOG_ENTER; LightColor color; - bool ret = GetLightColor(color, lightType_); - if (!ret) { - ASSERT_EQ(ret, -1); + bool flag = GetLightColor(color, g_lightType); + if (!flag) { + ASSERT_EQ(flag, -1); } else { LightAnimation animation; animation.mode = LIGHT_MODE_DEFAULT; animation.onTime = 2; animation.offTime = 2; - int32_t ret = TurnOn(invalidLightId_, color, animation); + int32_t ret = TurnOn(g_invalidLightId, color, animation); ASSERT_EQ(ret, -1); } } @@ -281,7 +281,7 @@ HWTEST_F(LightAgentTest, StartLightTest_009, TestSize.Level1) HWTEST_F(LightAgentTest, StartLightTest_010, TestSize.Level1) { CALL_LOG_ENTER; - int32_t ret = TurnOff(lightId_); + int32_t ret = TurnOff(g_lightId); ASSERT_EQ(ret, 0); } @@ -294,7 +294,7 @@ HWTEST_F(LightAgentTest, StartLightTest_010, TestSize.Level1) HWTEST_F(LightAgentTest, StartLightTest_011, TestSize.Level1) { CALL_LOG_ENTER; - int32_t ret = TurnOff(invalidLightId_); + int32_t ret = TurnOff(g_invalidLightId); ASSERT_EQ(ret, -1); } } // namespace Sensors diff --git a/services/miscdevice_service/custom_vibrate_decode/src/custom_vibration_matcher.cpp b/services/miscdevice_service/custom_vibrate_decode/src/custom_vibration_matcher.cpp index 3bbd182..e80cffa 100755 --- a/services/miscdevice_service/custom_vibrate_decode/src/custom_vibration_matcher.cpp +++ b/services/miscdevice_service/custom_vibrate_decode/src/custom_vibration_matcher.cpp @@ -32,6 +32,9 @@ std::map> TRANSIENT_VIBRATION_INFOS = { constexpr int32_t INTENSITY_MAX = 100; constexpr int32_t TRANSIENT_GRADE_NUM = 4; constexpr int32_t CONTINUOUS_GRADE_NUM = 8; +constexpr int32_t CONTINUOUS_GRADE_MASK = 100; +constexpr float ROUND_OFFSET = 0.5; +constexpr float TRANSIENT_GRADE_GAIN = 0.25; constexpr float CONTINUOUS_GRADE_SCALE = 100. / 8; constexpr float INTENSITY_WEIGHT = 0.5; constexpr float FREQUENCY_WEIGHT = 0.5; @@ -78,22 +81,22 @@ void CustomVibrationMatcher::ProcessContinuousEvent(const VibrateEvent &event, i if (event.intensity == INTENSITY_MAX) { grade = CONTINUOUS_GRADE_NUM - 1; } else { - grade = round(event.intensity / CONTINUOUS_GRADE_SCALE + 0.5) - 1; + grade = round(event.intensity / CONTINUOUS_GRADE_SCALE + ROUND_OFFSET) - 1; } if ((!compositeEffects.empty()) && (event.startTime == preStartTime + preDuration)) { PrimitiveEffect& prePrimitiveEffect = compositeEffects.back().primitiveEffect; int32_t preEffectId = prePrimitiveEffect.effectId; - int32_t preGrade = preEffectId % 100; + int32_t preGrade = preEffectId % CONTINUOUS_GRADE_MASK; int32_t mergeDuration = preDuration + event.duration; if (preEffectId > EFFECT_ID_BOUNDARY && preGrade == grade && mergeDuration < DURATION_MAX) { - prePrimitiveEffect.effectId = mergeDuration * 100 + grade; + prePrimitiveEffect.effectId = mergeDuration * CONTINUOUS_GRADE_MASK + grade; preDuration = mergeDuration; return; } } PrimitiveEffect primitiveEffect; primitiveEffect.delay = event.startTime - preStartTime; - primitiveEffect.effectId = event.duration * 100 + grade; + primitiveEffect.effectId = event.duration * CONTINUOUS_GRADE_MASK + grade; CompositeEffect compositeEffect; compositeEffect.primitiveEffect = primitiveEffect; compositeEffects.push_back(compositeEffect); @@ -111,7 +114,7 @@ void CustomVibrationMatcher::ProcessTransientEvent(const VibrateEvent &event, in const std::vector &info = transientInfo.second; float frequencyDistance = std::abs(event.frequency - info[1]); for (int32_t j = 0; j < TRANSIENT_GRADE_NUM; ++j) { - float intensityDistance = std::abs(event.intensity - info[0] * (1 - j * 0.25)); + float intensityDistance = std::abs(event.intensity - info[0] * (1 - j * TRANSIENT_GRADE_GAIN)); float weightSum = INTENSITY_WEIGHT * intensityDistance + FREQUENCY_WEIGHT * frequencyDistance; if (weightSum < minWeightSum) { minWeightSum = weightSum; -- Gitee From 0bd23f7220acf1b062d42dbdb5b474b94a122b33 Mon Sep 17 00:00:00 2001 From: lixiangpeng5 Date: Wed, 26 Apr 2023 09:15:10 +0000 Subject: [PATCH 2/4] fix by code review Signed-off-by: lixiangpeng5 Change-Id: I9360f26e7669341d2471035f97e15f7cd76b10bc --- .../custom_vibrate_decode/src/custom_vibration_matcher.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/services/miscdevice_service/custom_vibrate_decode/src/custom_vibration_matcher.cpp b/services/miscdevice_service/custom_vibrate_decode/src/custom_vibration_matcher.cpp index e80cffa..aea5b9a 100755 --- a/services/miscdevice_service/custom_vibrate_decode/src/custom_vibration_matcher.cpp +++ b/services/miscdevice_service/custom_vibrate_decode/src/custom_vibration_matcher.cpp @@ -23,12 +23,12 @@ namespace OHOS { namespace Sensors { namespace { -std::map> TRANSIENT_VIBRATION_INFOS = { +const std::map> TRANSIENT_VIBRATION_INFOS = { {0x28, {0x4d, 0x4d, 0x0b}}, {0x2c, {0x2a, 0x64, 0x07}}, {0x30, {0x44, 0x52, 0x16}}, {0x3c, {0x45, 0x34, 0x0a}}, {0x40, {0x2e, 0x43, 0x0a}}, {0x48, {0x51, 0x52, 0x0a}}, {0x4c, {0x3a, 0x0c, 0x0f}}, {0x50, {0x64, 0x20, 0x14}}, {0x54, {0x55, 0x34, 0x1c}}, {0x5c, {0x32, 0x0c, 0x13}}, {0x60, {0x12, 0x07, 0x0a}} -}; // {Id, {intensity, frequency, duration}} +}; constexpr int32_t INTENSITY_MAX = 100; constexpr int32_t TRANSIENT_GRADE_NUM = 4; constexpr int32_t CONTINUOUS_GRADE_NUM = 8; -- Gitee From 7c5ae57a8c7a7271c83cb343402383927f9d90a7 Mon Sep 17 00:00:00 2001 From: lixiangpeng5 Date: Fri, 28 Apr 2023 02:38:49 +0000 Subject: [PATCH 3/4] fix by code review 0428 Signed-off-by: lixiangpeng5 Change-Id: I9ebc8f57e0fdeb49fb78a818c7430aac684399b5 --- .../light/test/unittest/light_agent_test.cpp | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/interfaces/native/light/test/unittest/light_agent_test.cpp b/interfaces/native/light/test/unittest/light_agent_test.cpp index 7047734..46f7ce1 100755 --- a/interfaces/native/light/test/unittest/light_agent_test.cpp +++ b/interfaces/native/light/test/unittest/light_agent_test.cpp @@ -121,7 +121,7 @@ HWTEST_F(LightAgentTest, StartLightTest_003, TestSize.Level1) LightColor color; bool flag = GetLightColor(color, g_lightType); if (!flag) { - ASSERT_EQ(flag, -1); + ASSERT_TRUE(flag); } else { LightAnimation animation; animation.mode = LIGHT_MODE_DEFAULT; @@ -145,7 +145,7 @@ HWTEST_F(LightAgentTest, StartLightTest_004, TestSize.Level1) LightColor color; bool flag = GetLightColor(color, g_lightType); if (!flag) { - ASSERT_EQ(flag, -1); + ASSERT_TRUE(flag); } else { LightAnimation animation; animation.mode = LIGHT_MODE_BUTT; @@ -168,7 +168,7 @@ HWTEST_F(LightAgentTest, StartLightTest_005, TestSize.Level1) LightColor color; bool flag = GetLightColor(color, g_lightType); if (!flag) { - ASSERT_EQ(flag, -1); + ASSERT_TRUE(flag); } else { LightAnimation animation; animation.mode = -1; @@ -191,7 +191,7 @@ HWTEST_F(LightAgentTest, StartLightTest_006, TestSize.Level1) LightColor color; bool flag = GetLightColor(color, g_lightType); if (!flag) { - ASSERT_EQ(flag, -1); + ASSERT_TRUE(flag); } else { LightAnimation animation; animation.mode = LIGHT_MODE_DEFAULT; @@ -214,7 +214,7 @@ HWTEST_F(LightAgentTest, StartLightTest_007, TestSize.Level1) LightColor color; bool flag = GetLightColor(color, g_lightType); if (!flag) { - ASSERT_EQ(flag, -1); + ASSERT_TRUE(flag); } else { LightAnimation animation; animation.mode = LIGHT_MODE_DEFAULT; @@ -237,7 +237,7 @@ HWTEST_F(LightAgentTest, StartLightTest_008, TestSize.Level1) LightColor color; bool flag = GetLightColor(color, g_lightType); if (!flag) { - ASSERT_EQ(flag, -1); + ASSERT_TRUE(flag); } else { LightAnimation animation; animation.mode = LIGHT_MODE_DEFAULT; @@ -261,7 +261,7 @@ HWTEST_F(LightAgentTest, StartLightTest_009, TestSize.Level1) LightColor color; bool flag = GetLightColor(color, g_lightType); if (!flag) { - ASSERT_EQ(flag, -1); + ASSERT_TRUE(flag); } else { LightAnimation animation; animation.mode = LIGHT_MODE_DEFAULT; -- Gitee From 1ab533da90579c8d1dfd72d704cbd4daaa1a1fa5 Mon Sep 17 00:00:00 2001 From: lixiangpeng5 Date: Fri, 28 Apr 2023 03:58:39 +0000 Subject: [PATCH 4/4] fix testcase 0428 Signed-off-by: lixiangpeng5 Change-Id: I632ab19fb9199f9370e0587f0f9c9db377568452 --- .../light/test/unittest/light_agent_test.cpp | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/interfaces/native/light/test/unittest/light_agent_test.cpp b/interfaces/native/light/test/unittest/light_agent_test.cpp index 46f7ce1..37492a0 100755 --- a/interfaces/native/light/test/unittest/light_agent_test.cpp +++ b/interfaces/native/light/test/unittest/light_agent_test.cpp @@ -121,7 +121,7 @@ HWTEST_F(LightAgentTest, StartLightTest_003, TestSize.Level1) LightColor color; bool flag = GetLightColor(color, g_lightType); if (!flag) { - ASSERT_TRUE(flag); + ASSERT_FALSE(flag); } else { LightAnimation animation; animation.mode = LIGHT_MODE_DEFAULT; @@ -145,7 +145,7 @@ HWTEST_F(LightAgentTest, StartLightTest_004, TestSize.Level1) LightColor color; bool flag = GetLightColor(color, g_lightType); if (!flag) { - ASSERT_TRUE(flag); + ASSERT_FALSE(flag); } else { LightAnimation animation; animation.mode = LIGHT_MODE_BUTT; @@ -168,7 +168,7 @@ HWTEST_F(LightAgentTest, StartLightTest_005, TestSize.Level1) LightColor color; bool flag = GetLightColor(color, g_lightType); if (!flag) { - ASSERT_TRUE(flag); + ASSERT_FALSE(flag); } else { LightAnimation animation; animation.mode = -1; @@ -191,7 +191,7 @@ HWTEST_F(LightAgentTest, StartLightTest_006, TestSize.Level1) LightColor color; bool flag = GetLightColor(color, g_lightType); if (!flag) { - ASSERT_TRUE(flag); + ASSERT_FALSE(flag); } else { LightAnimation animation; animation.mode = LIGHT_MODE_DEFAULT; @@ -214,7 +214,7 @@ HWTEST_F(LightAgentTest, StartLightTest_007, TestSize.Level1) LightColor color; bool flag = GetLightColor(color, g_lightType); if (!flag) { - ASSERT_TRUE(flag); + ASSERT_FALSE(flag); } else { LightAnimation animation; animation.mode = LIGHT_MODE_DEFAULT; @@ -237,7 +237,7 @@ HWTEST_F(LightAgentTest, StartLightTest_008, TestSize.Level1) LightColor color; bool flag = GetLightColor(color, g_lightType); if (!flag) { - ASSERT_TRUE(flag); + ASSERT_FALSE(flag); } else { LightAnimation animation; animation.mode = LIGHT_MODE_DEFAULT; @@ -261,7 +261,7 @@ HWTEST_F(LightAgentTest, StartLightTest_009, TestSize.Level1) LightColor color; bool flag = GetLightColor(color, g_lightType); if (!flag) { - ASSERT_TRUE(flag); + ASSERT_FALSE(flag); } else { LightAnimation animation; animation.mode = LIGHT_MODE_DEFAULT; -- Gitee