diff --git a/frameworks/js/napi/vibrator/src/vibrator_js.cpp b/frameworks/js/napi/vibrator/src/vibrator_js.cpp index bb5aed30436adbd122d303fefc1e5060ded97df0..b2eecf7d50ea46e2cce18788297d6222d98d9157 100644 --- a/frameworks/js/napi/vibrator/src/vibrator_js.cpp +++ b/frameworks/js/napi/vibrator/src/vibrator_js.cpp @@ -336,6 +336,14 @@ static napi_value Stop(napi_env env, napi_callback_info info) return Cancel(env, info); } } +static napi_value StopVibrationSync(napi_env env, napi_callback_info info) +{ + int32_t ret = Cancel(); + if (ret != SUCCESS) { + ThrowErr(env, ret, "Cancel execution failed"); + } + return nullptr; +} static napi_value IsSupportEffect(napi_env env, napi_callback_info info) { @@ -362,6 +370,31 @@ static napi_value IsSupportEffect(napi_env env, napi_callback_info info) return EmitAsyncWork(nullptr, asyncCallbackInfo); } +static napi_value IsSupportEffectSync(napi_env env, napi_callback_info info) +{ + size_t argc = 1; + napi_value args[1] = {}; + napi_value thisArg = nullptr; + napi_status status = napi_get_cb_info(env, info, &argc, args, &thisArg, nullptr); + if (status != napi_ok) { + ThrowErr(env, PARAMETER_ERROR, "napi_get_cb_info fail or number of parameter invalid"); + return nullptr; + } + string effectId; + if (!GetStringValue(env, args[0], effectId)) { + ThrowErr(env, PARAMETER_ERROR, "GetStringValue fail"); + return nullptr; + } + bool isSupportEffect = false; + if(IsSupportEffect(effectId.c_str(), &isSupportEffect) != SUCCESS){ + ThrowErr(env, PARAMETER_ERROR, "GetStringValue fail"); + return nullptr; + } + napi_value isSupport = nullptr; + napi_get_boolean(env, isSupportEffect, &isSupport); + return isSupport; +} + static napi_value EnumClassConstructor(const napi_env env, const napi_callback_info info) { size_t argc = 0; @@ -409,9 +442,11 @@ static napi_value Init(napi_env env, napi_value exports) napi_property_descriptor desc[] = { DECLARE_NAPI_FUNCTION("vibrate", Vibrate), DECLARE_NAPI_FUNCTION("stop", Stop), + DECLARE_NAPI_FUNCTION("stopVibrationSync", StopVibrationSync), DECLARE_NAPI_FUNCTION("startVibration", StartVibrate), DECLARE_NAPI_FUNCTION("stopVibration", Stop), 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/utils/common/include/sensors_errors.h b/utils/common/include/sensors_errors.h index 25b1d3a39a6391ef4cfc2681a0d250e54693be0a..1486fccca370fcce8e8550e1be760a3697269d4b 100644 --- a/utils/common/include/sensors_errors.h +++ b/utils/common/include/sensors_errors.h @@ -29,7 +29,7 @@ enum ErrorCode : int32_t { PERMISSION_DENIED = 201, // Use this error code when permission is denied. PARAMETER_ERROR = 401, // Use this error code when the input parameter type or range does not match. IS_NOT_SUPPORTED = 801, // Use this error code when capability not supported. - DEVICE_OPERATION_FAILED = 14600101, // Use this error code when operating the device fail. + DEVICE_OPERATION_FAILED = 14600101 // Use this error code when operating the device fail. }; enum {