diff --git a/frameworks/js/napi/vibrator/src/vibrator_js.cpp b/frameworks/js/napi/vibrator/src/vibrator_js.cpp index 63972c08e1fa7b5d51d2157f5f207769e3012b57..474a1200d83a184cdff9b8a9bef1e92d7b4b7116 100644 --- a/frameworks/js/napi/vibrator/src/vibrator_js.cpp +++ b/frameworks/js/napi/vibrator/src/vibrator_js.cpp @@ -337,6 +337,42 @@ static napi_value Stop(napi_env env, napi_callback_info info) } } +static napi_value StopVibrationSync(napi_env env, napi_callback_info info) +{ + napi_value result = nullptr; + napi_get_undefined(env, &result); + napi_value thisArg = nullptr; + size_t argc = 0; + napi_status status = napi_get_cb_info(env, info, &argc, nullptr, &thisArg, nullptr); + if (status != napi_ok) { + ThrowErr(env, PARAMETER_ERROR, "Get the parameter info fail"); + return result; + } + int32_t ret = Cancel(); + if (ret != SUCCESS) { + MISC_HILOGE("Cancel execution failed"); + } + return result; +} + +static napi_value IsHdHapticSupported(napi_env env, napi_callback_info info) +{ + napi_value result = nullptr; + napi_get_undefined(env, &result); + napi_value thisArg = nullptr; + size_t argc = 0; + napi_status status = napi_get_cb_info(env, info, &argc, nullptr, &thisArg, nullptr); + if (status != napi_ok) { + ThrowErr(env, PARAMETER_ERROR, "Get the parameter info fail"); + return result; + } + status= napi_get_boolean(env, IsHdHapticSupported(), &result); + if (status != napi_ok) { + ThrowErr(env, PARAMETER_ERROR, "Get the value of boolean fail"); + } + return result; +} + static napi_value IsSupportEffect(napi_env env, napi_callback_info info) { size_t argc = 2; @@ -362,18 +398,29 @@ static napi_value IsSupportEffect(napi_env env, napi_callback_info info) return EmitAsyncWork(nullptr, asyncCallbackInfo); } -static napi_value IsHdHapticSupportedSync(napi_env env, napi_callback_info info) +static napi_value IsSupportEffectSync(napi_env env, napi_callback_info info) { + size_t argc = 1; + napi_value args[1] = {}; napi_value result = nullptr; napi_get_undefined(env, &result); napi_value thisArg = nullptr; - size_t argc = 0; - napi_status status = napi_get_cb_info(env, info, &argc, nullptr, &thisArg, nullptr); - if (status != napi_ok) { - ThrowErr(env, PARAMETER_ERROR, "Get the parameter info fail"); + napi_status status = napi_get_cb_info(env, info, &argc, args, &thisArg, nullptr); + if ((status != napi_ok) || (argc == 0)) { + ThrowErr(env, PARAMETER_ERROR, "Get the parameter info fail or number of parameter invalid"); return result; } - status= napi_get_boolean(env, IsHdHapticSupported(), &result); + string effectId; + if (!GetStringValue(env, args[0], effectId)) { + ThrowErr(env, PARAMETER_ERROR, "Get the value of string fail"); + return result; + } + bool isSupportEffect = false; + if (IsSupportEffect(effectId.c_str(), &isSupportEffect) != SUCCESS) { + MISC_HILOGE("IsSupportEffect execution failed"); + return result; + } + status= napi_get_boolean(env, isSupportEffect, &result); if (status != napi_ok) { ThrowErr(env, PARAMETER_ERROR, "Get the value of boolean fail"); } @@ -429,8 +476,10 @@ static napi_value Init(napi_env env, napi_value exports) DECLARE_NAPI_FUNCTION("stop", Stop), DECLARE_NAPI_FUNCTION("startVibration", StartVibrate), DECLARE_NAPI_FUNCTION("stopVibration", Stop), - DECLARE_NAPI_FUNCTION("isHdHapticSupportedSync", IsHdHapticSupportedSync), + DECLARE_NAPI_FUNCTION("stopVibrationSync", StopVibrationSync), + DECLARE_NAPI_FUNCTION("isHdHapticSupported", IsHdHapticSupported), DECLARE_NAPI_FUNCTION("isSupportEffect", IsSupportEffect), + DECLARE_NAPI_FUNCTION("isSupportEffectSync", IsSupportEffectSync), }; NAPI_CALL(env, napi_define_properties(env, exports, sizeof(desc) / sizeof(napi_property_descriptor), desc)); NAPI_ASSERT_BASE(env, CreateEnumStopMode(env, exports) != nullptr, "Create enum stop mode fail", exports); diff --git a/test/unittest/vibrator/js/ExampleJsunit.test.js b/test/unittest/vibrator/js/ExampleJsunit.test.js index 2aed64c623c132308281101a96aa9f6e61344936..1607bcf529030e6696587bbb93ccdd64ad84735d 100644 --- a/test/unittest/vibrator/js/ExampleJsunit.test.js +++ b/test/unittest/vibrator/js/ExampleJsunit.test.js @@ -3147,14 +3147,14 @@ describe("VibratorJsTest", function () { /* * @tc.name:VibrateTest037 - * @tc.desc:verify the isHdHapticSupportedSync interface + * @tc.desc:verify the isHdHapticSupported interface * @tc.type: FUNC * @tc.require: I6HLLL * @tc.number: VibrateTest037 */ it("VibrateTest037", 0, function () { try { - expect(typeof(vibrator.isHdHapticSupportedSync())).assertEqual("boolean"); + expect(typeof(vibrator.isHdHapticSupported())).assertEqual("boolean"); } catch (error) { console.info("VibrateTest037 exception in, err:" + error); expect(true).assertEqual(false);