diff --git a/frameworks/js/napi/vibrator/src/vibrator_js.cpp b/frameworks/js/napi/vibrator/src/vibrator_js.cpp index 470c1f96df21a67801241655a3e2ad063164fa02..bcec8e5fb619c7c9f353e0be1304fb3d373ef6af 100644 --- a/frameworks/js/napi/vibrator/src/vibrator_js.cpp +++ b/frameworks/js/napi/vibrator/src/vibrator_js.cpp @@ -775,14 +775,23 @@ static napi_value CreateEnumHapticFeedback(const napi_env env, napi_value export napi_value effectSoft = nullptr; napi_value effectHard = nullptr; napi_value effectSharp = nullptr; + napi_value effectNoticeSuccess = nullptr; + napi_value effectNoticeFail = nullptr; + napi_value effectNoticeWarning = nullptr; NAPI_CALL(env, napi_create_string_utf8(env, "haptic.effect.soft", NAPI_AUTO_LENGTH, &effectSoft)); NAPI_CALL(env, napi_create_string_utf8(env, "haptic.effect.hard", NAPI_AUTO_LENGTH, &effectHard)); NAPI_CALL(env, napi_create_string_utf8(env, "haptic.effect.sharp", NAPI_AUTO_LENGTH, &effectSharp)); + NAPI_CALL(env, napi_create_string_utf8(env, "haptic.notice.success", NAPI_AUTO_LENGTH, &effectNoticeSuccess)); + NAPI_CALL(env, napi_create_string_utf8(env, "haptic.notice.fail", NAPI_AUTO_LENGTH, &effectNoticeFail)); + NAPI_CALL(env, napi_create_string_utf8(env, "haptic.notice.warning", NAPI_AUTO_LENGTH, &effectNoticeWarning)); napi_property_descriptor desc[] = { DECLARE_NAPI_STATIC_PROPERTY("EFFECT_SOFT", effectSoft), DECLARE_NAPI_STATIC_PROPERTY("EFFECT_HARD", effectHard), DECLARE_NAPI_STATIC_PROPERTY("EFFECT_SHARP", effectSharp), + DECLARE_NAPI_STATIC_PROPERTY("EFFECT_NOTICE_SUCCESS", effectNoticeSuccess), + DECLARE_NAPI_STATIC_PROPERTY("EFFECT_NOTICE_FAILURE", effectNoticeFail), + DECLARE_NAPI_STATIC_PROPERTY("EFFECT_NOTICE_WARNING", effectNoticeWarning), }; napi_value result = nullptr; NAPI_CALL(env, napi_define_class(env, "HapticFeedback", NAPI_AUTO_LENGTH, EnumClassConstructor, nullptr, diff --git a/interfaces/inner_api/vibrator/vibrator_agent_type.h b/interfaces/inner_api/vibrator/vibrator_agent_type.h index 91c1c48a0a1ac02df3f533109b86cfea9ef91117..9c336720cb03112e7bda11fd801e92466d24c4fd 100644 --- a/interfaces/inner_api/vibrator/vibrator_agent_type.h +++ b/interfaces/inner_api/vibrator/vibrator_agent_type.h @@ -104,6 +104,27 @@ inline const char *VIBRATOR_TYPE_SHARP = "haptic.effect.sharp"; */ inline const char *VIBRATOR_TYPE_SLIDE = "haptic.slide"; +/** + * @brief Describes the vibration effect of the succeed notice. + * + * @since 16 + */ +inline const char *VIBRATOR_TYPE_NOTICE_SUCCESS = "haptic.notice.success"; + +/** + * @brief Describes the vibration effect of the failed notice. + * + * @since 16 + */ +inline const char *VIBRATOR_TYPE_NOTICE_FAILURE = "haptic.notice.fail"; + +/** + * @brief Describes the vibration effect of the warning notice. + * + * @since 16 + */ +inline const char *VIBRATOR_TYPE_NOTICE_WARNING = "haptic.notice.warning"; + /** * @brief Enumerates vibration usages. * diff --git a/services/miscdevice_service/hdi_connection/adapter/src/compatible_connection.cpp b/services/miscdevice_service/hdi_connection/adapter/src/compatible_connection.cpp index 5090b1330bfc01e6a6dbc5c39132ba48803825f8..eb4d1ef560ede1d68dd561d3283c8bea39d5e5b3 100644 --- a/services/miscdevice_service/hdi_connection/adapter/src/compatible_connection.cpp +++ b/services/miscdevice_service/hdi_connection/adapter/src/compatible_connection.cpp @@ -41,7 +41,10 @@ std::unordered_map g_vibratorEffect = { {"haptic.long_press.heavy", 80}, {"haptic.effect.hard", 50}, {"haptic.effect.soft", 30}, - {"haptic.effect.sharp", 20} + {"haptic.effect.sharp", 20}, + {"haptic.notice.success", 139}, + {"haptic.notice.fail", 277}, + {"haptic.notice.warning", 2200} }; #ifdef HDF_DRIVERS_INTERFACE_VIBRATOR HdfVibratorModeV1_2 g_vibrateMode; diff --git a/test/unittest/vibrator/js/ExampleJsunit.test.js b/test/unittest/vibrator/js/ExampleJsunit.test.js index 3c59f01c39ed487a96a1dac53e32f6b1034c610b..8b0ec5d92ab40bc36fdd788393c09290a80882c3 100644 --- a/test/unittest/vibrator/js/ExampleJsunit.test.js +++ b/test/unittest/vibrator/js/ExampleJsunit.test.js @@ -1212,7 +1212,7 @@ describe("VibratorJsTest", function () { if (ret) { vibrator.startVibration({ type: "preset", - effectId: "haptic.effect.soft", + effectId: "haptic.effect.hard", count: 1, intensity: 50, }, { @@ -3308,4 +3308,112 @@ describe("VibratorJsTest", function () { } console.info("VibrateTest051 end"); }) + + /* + * @tc.name:VibrateJsTest052 + * @tc.desc:verify app info is not null + * @tc.type: FUNC + * @tc.require: I53SGE + * @tc.number: VibrateJsTest052 + */ + it("VibrateJsTest052", 0, async function () { + let ret = vibrator.isSupportEffectSync("haptic.notice.success"); + if (ret) { + vibrator.startVibration({ + type: "preset", + effectId: "haptic.notice.success", + count: 1, + intensity: 50, + }, { + usage: "unknown" + }, (error) => { + if (error) { + console.info('VibrateJsTest052 vibrator error'); + expect(false).assertTrue(); + } else { + console.info('VibrateJsTest052 vibrator success'); + expect(true).assertTrue(); + } + setTimeout(() => { + done(); + }, 139); + }); + } else { + console.info('This device is not supportEffect'); + expect(true).assertTrue(); + done(); + } + }) + + /* + * @tc.name:VibrateJsTest053 + * @tc.desc:verify app info is not null + * @tc.type: FUNC + * @tc.require: I53SGE + * @tc.number: VibrateJsTest053 + */ + it("VibrateJsTest053", 0, async function () { + let ret = vibrator.isSupportEffectSync("haptic.notice.fail"); + if (ret) { + vibrator.startVibration({ + type: "preset", + effectId: "haptic.notice.fail", + count: 1, + intensity: 50, + }, { + usage: "unknown" + }, (error) => { + if (error) { + console.info('VibrateJsTest053 vibrator error'); + expect(false).assertTrue(); + } else { + console.info('VibrateJsTest053 vibrator success'); + expect(true).assertTrue(); + } + setTimeout(() => { + done(); + }, 277); + }); + } else { + console.info('This device is not supportEffect'); + expect(true).assertTrue(); + done(); + } + }) + + /* + * @tc.name:VibrateJsTest054 + * @tc.desc:verify app info is not null + * @tc.type: FUNC + * @tc.require: I53SGE + * @tc.number: VibrateJsTest054 + */ + it("VibrateJsTest054", 0, async function () { + let ret = vibrator.isSupportEffectSync("haptic.notice.warning"); + if (ret) { + vibrator.startVibration({ + type: "preset", + effectId: "haptic.notice.warning", + count: 1, + intensity: 50, + }, { + usage: "unknown" + }, (error) => { + if (error) { + console.info('VibrateJsTest054 vibrator error'); + expect(false).assertTrue(); + } else { + console.info('VibrateJsTest054 vibrator success'); + expect(true).assertTrue(); + } + setTimeout(() => { + done(); + }, 2200); + }); + } else { + console.info('This device is not supportEffect'); + expect(true).assertTrue(); + done(); + } + }) })