description

Signed-off-by: 小发发 <lianghui35@huawei.com>
This commit is contained in:
小发发 2024-08-17 18:02:17 +08:00
parent 7311d06622
commit 06dbb75c48
6 changed files with 187 additions and 41 deletions

View File

@ -218,6 +218,7 @@ bool AccessibilityConfig::Impl::RegisterToService()
}
uint32_t ret = serviceProxy_->RegisterCaptionObserver(captionObserver_);
if (ret != 0) {
captionObserver_ = nullptr;
HILOG_ERROR("Register captionObserver failed.");
return false;
}
@ -240,6 +241,7 @@ bool AccessibilityConfig::Impl::RegisterToService()
}
uint32_t ret = serviceProxy_->RegisterConfigObserver(configObserver_);
if (ret != 0) {
configObserver_ = nullptr;
HILOG_ERROR("Register configObserver failed.");
return false;
}

View File

@ -53,8 +53,14 @@ static napi_value InitHighContrastText(napi_env env)
return nullptr;
}
nativeObj->SetEnv(env);
NAPI_CALL(env, napi_wrap(env, highContrastTextValue, reinterpret_cast<void*>(nativeObj),
NAccessibilityConfigClass::Destructor, nullptr, nullptr));
napi_status sts = napi_wrap(env, highContrastTextValue, reinterpret_cast<void*>(nativeObj),
NAccessibilityConfigClass::Destructor, nullptr, nullptr);
if (sts != napi_ok) {
delete nativeObj;
nativeObj = nullptr;
HILOG_ERROR("failed to wrap JS object");
return nullptr;
}
return highContrastTextValue;
}
@ -76,8 +82,14 @@ static napi_value InitInvertColor(napi_env env)
return nullptr;
}
nativeObj->SetEnv(env);
NAPI_CALL(env, napi_wrap(env, invertColorValue, reinterpret_cast<void*>(nativeObj),
NAccessibilityConfigClass::Destructor, nullptr, nullptr));
napi_status sts = napi_wrap(env, invertColorValue, reinterpret_cast<void*>(nativeObj),
NAccessibilityConfigClass::Destructor, nullptr, nullptr);
if (sts != napi_ok) {
delete nativeObj;
nativeObj = nullptr;
HILOG_ERROR("failed to wrap JS object");
return nullptr;
}
return invertColorValue;
}
@ -99,8 +111,14 @@ static napi_value InitDaltonizationState(napi_env env)
return nullptr;
}
nativeObj->SetEnv(env);
NAPI_CALL(env, napi_wrap(env, daltonizationStateValue, reinterpret_cast<void*>(nativeObj),
NAccessibilityConfigClass::Destructor, nullptr, nullptr));
napi_status sts = napi_wrap(env, daltonizationStateValue, reinterpret_cast<void*>(nativeObj),
NAccessibilityConfigClass::Destructor, nullptr, nullptr);
if (sts != napi_ok) {
delete nativeObj;
nativeObj = nullptr;
HILOG_ERROR("failed to wrap JS object");
return nullptr;
}
return daltonizationStateValue;
}
@ -123,8 +141,14 @@ static napi_value InitDaltonizationColorFilter(napi_env env)
return nullptr;
}
nativeObj->SetEnv(env);
NAPI_CALL(env, napi_wrap(env, daltonizationColorFilterValue, reinterpret_cast<void*>(nativeObj),
NAccessibilityConfigClass::Destructor, nullptr, nullptr));
napi_status sts = napi_wrap(env, daltonizationColorFilterValue, reinterpret_cast<void*>(nativeObj),
NAccessibilityConfigClass::Destructor, nullptr, nullptr);
if (sts != napi_ok) {
delete nativeObj;
nativeObj = nullptr;
HILOG_ERROR("failed to wrap JS object");
return nullptr;
}
return daltonizationColorFilterValue;
}
@ -146,8 +170,14 @@ static napi_value InitContentTimeout(napi_env env)
return nullptr;
}
nativeObj->SetEnv(env);
NAPI_CALL(env, napi_wrap(env, contentTimeoutValue, reinterpret_cast<void*>(nativeObj),
NAccessibilityConfigClass::Destructor, nullptr, nullptr));
napi_status sts = napi_wrap(env, contentTimeoutValue, reinterpret_cast<void*>(nativeObj),
NAccessibilityConfigClass::Destructor, nullptr, nullptr);
if (sts != napi_ok) {
delete nativeObj;
nativeObj = nullptr;
HILOG_ERROR("failed to wrap JS object");
return nullptr;
}
return contentTimeoutValue;
}
@ -169,8 +199,14 @@ static napi_value InitAnimationOff(napi_env env)
return nullptr;
}
nativeObj->SetEnv(env);
NAPI_CALL(env, napi_wrap(env, animationOffValue, reinterpret_cast<void*>(nativeObj),
NAccessibilityConfigClass::Destructor, nullptr, nullptr));
napi_status sts = napi_wrap(env, animationOffValue, reinterpret_cast<void*>(nativeObj),
NAccessibilityConfigClass::Destructor, nullptr, nullptr);
if (sts != napi_ok) {
delete nativeObj;
nativeObj = nullptr;
HILOG_ERROR("failed to wrap JS object");
return nullptr;
}
return animationOffValue;
}
@ -192,8 +228,14 @@ static napi_value InitBrightnessDiscount(napi_env env)
return nullptr;
}
nativeObj->SetEnv(env);
NAPI_CALL(env, napi_wrap(env, brightnessDiscountValue, reinterpret_cast<void*>(nativeObj),
NAccessibilityConfigClass::Destructor, nullptr, nullptr));
napi_status sts = napi_wrap(env, brightnessDiscountValue, reinterpret_cast<void*>(nativeObj),
NAccessibilityConfigClass::Destructor, nullptr, nullptr);
if (sts != napi_ok) {
delete nativeObj;
nativeObj = nullptr;
HILOG_ERROR("failed to wrap JS object");
return nullptr;
}
return brightnessDiscountValue;
}
@ -215,8 +257,14 @@ static napi_value InitScreenMagnifier(napi_env env)
return nullptr;
}
nativeObj->SetEnv(env);
NAPI_CALL(env, napi_wrap(env, screenMagnifierValue, reinterpret_cast<void*>(nativeObj),
NAccessibilityConfigClass::Destructor, nullptr, nullptr));
napi_status sts = napi_wrap(env, screenMagnifierValue, reinterpret_cast<void*>(nativeObj),
NAccessibilityConfigClass::Destructor, nullptr, nullptr);
if (sts != napi_ok) {
delete nativeObj;
nativeObj = nullptr;
HILOG_ERROR("failed to wrap JS object");
return nullptr;
}
return screenMagnifierValue;
}
@ -238,8 +286,14 @@ static napi_value InitAudioMono(napi_env env)
return nullptr;
}
nativeObj->SetEnv(env);
NAPI_CALL(env, napi_wrap(env, audioMonoValue, reinterpret_cast<void*>(nativeObj),
NAccessibilityConfigClass::Destructor, nullptr, nullptr));
napi_status sts = napi_wrap(env, audioMonoValue, reinterpret_cast<void*>(nativeObj),
NAccessibilityConfigClass::Destructor, nullptr, nullptr);
if (sts != napi_ok) {
delete nativeObj;
nativeObj = nullptr;
HILOG_ERROR("failed to wrap JS object");
return nullptr;
}
return audioMonoValue;
}
@ -261,8 +315,14 @@ static napi_value InitAudioBalance(napi_env env)
return nullptr;
}
nativeObj->SetEnv(env);
NAPI_CALL(env, napi_wrap(env, audioBalanceValue, reinterpret_cast<void*>(nativeObj),
NAccessibilityConfigClass::Destructor, nullptr, nullptr));
napi_status sts = napi_wrap(env, audioBalanceValue, reinterpret_cast<void*>(nativeObj),
NAccessibilityConfigClass::Destructor, nullptr, nullptr);
if (sts != napi_ok) {
delete nativeObj;
nativeObj = nullptr;
HILOG_ERROR("failed to wrap JS object");
return nullptr;
}
return audioBalanceValue;
}
@ -284,8 +344,14 @@ static napi_value InitMouseKey(napi_env env)
return nullptr;
}
nativeObj->SetEnv(env);
NAPI_CALL(env, napi_wrap(env, mouseKeyValue, reinterpret_cast<void*>(nativeObj),
NAccessibilityConfigClass::Destructor, nullptr, nullptr));
napi_status sts = napi_wrap(env, mouseKeyValue, reinterpret_cast<void*>(nativeObj),
NAccessibilityConfigClass::Destructor, nullptr, nullptr);
if (sts != napi_ok) {
delete nativeObj;
nativeObj = nullptr;
HILOG_ERROR("failed to wrap JS object");
return nullptr;
}
return mouseKeyValue;
}
@ -307,8 +373,14 @@ static napi_value InitMouseAutoClick(napi_env env)
return nullptr;
}
nativeObj->SetEnv(env);
NAPI_CALL(env, napi_wrap(env, mouseAutoClickValue, reinterpret_cast<void*>(nativeObj),
NAccessibilityConfigClass::Destructor, nullptr, nullptr));
napi_status sts = napi_wrap(env, mouseAutoClickValue, reinterpret_cast<void*>(nativeObj),
NAccessibilityConfigClass::Destructor, nullptr, nullptr);
if (sts != napi_ok) {
delete nativeObj;
nativeObj = nullptr;
HILOG_ERROR("failed to wrap JS object");
return nullptr;
}
return mouseAutoClickValue;
}
@ -330,8 +402,14 @@ static napi_value InitShortKey(napi_env env)
return nullptr;
}
nativeObj->SetEnv(env);
NAPI_CALL(env, napi_wrap(env, shortKeyValue, reinterpret_cast<void*>(nativeObj),
NAccessibilityConfigClass::Destructor, nullptr, nullptr));
napi_status sts = napi_wrap(env, shortKeyValue, reinterpret_cast<void*>(nativeObj),
NAccessibilityConfigClass::Destructor, nullptr, nullptr);
if (sts != napi_ok) {
delete nativeObj;
nativeObj = nullptr;
HILOG_ERROR("failed to wrap JS object");
return nullptr;
}
return shortKeyValue;
}
@ -353,8 +431,14 @@ static napi_value InitShortKeyTarget(napi_env env)
return nullptr;
}
nativeObj->SetEnv(env);
NAPI_CALL(env, napi_wrap(env, shortKeyTargetValue, reinterpret_cast<void*>(nativeObj),
NAccessibilityConfigClass::Destructor, nullptr, nullptr));
napi_status sts = napi_wrap(env, shortKeyTargetValue, reinterpret_cast<void*>(nativeObj),
NAccessibilityConfigClass::Destructor, nullptr, nullptr);
if (sts != napi_ok) {
delete nativeObj;
nativeObj = nullptr;
HILOG_ERROR("failed to wrap JS object");
return nullptr;
}
return shortKeyTargetValue;
}
@ -376,8 +460,14 @@ static napi_value InitShortKeyMultiTarget(napi_env env)
return nullptr;
}
nativeObj->SetEnv(env);
NAPI_CALL(env, napi_wrap(env, shortKeyMultiTargetValue, reinterpret_cast<void*>(nativeObj),
NAccessibilityConfigClass::Destructor, nullptr, nullptr));
napi_status sts = napi_wrap(env, shortKeyMultiTargetValue, reinterpret_cast<void*>(nativeObj),
NAccessibilityConfigClass::Destructor, nullptr, nullptr);
if (sts != napi_ok) {
delete nativeObj;
nativeObj = nullptr;
HILOG_ERROR("failed to wrap JS object");
return nullptr;
}
return shortKeyMultiTargetValue;
}
@ -399,8 +489,14 @@ static napi_value InitCaptionsState(napi_env env)
return nullptr;
}
nativeObj->SetEnv(env);
NAPI_CALL(env, napi_wrap(env, captionsValue, reinterpret_cast<void*>(nativeObj),
NAccessibilityConfigClass::Destructor, nullptr, nullptr));
napi_status sts = napi_wrap(env, captionsValue, reinterpret_cast<void*>(nativeObj),
NAccessibilityConfigClass::Destructor, nullptr, nullptr);
if (sts != napi_ok) {
delete nativeObj;
nativeObj = nullptr;
HILOG_ERROR("failed to wrap JS object");
return nullptr;
}
return captionsValue;
}
@ -422,8 +518,14 @@ static napi_value InitCaptionsStyle(napi_env env)
return nullptr;
}
nativeObj->SetEnv(env);
NAPI_CALL(env, napi_wrap(env, captionsStyleValue, reinterpret_cast<void*>(nativeObj),
NAccessibilityConfigClass::Destructor, nullptr, nullptr));
napi_status sts = napi_wrap(env, captionsStyleValue, reinterpret_cast<void*>(nativeObj),
NAccessibilityConfigClass::Destructor, nullptr, nullptr);
if (sts != napi_ok) {
delete nativeObj;
nativeObj = nullptr;
HILOG_ERROR("failed to wrap JS object");
return nullptr;
}
return captionsStyleValue;
}
@ -445,8 +547,14 @@ static napi_value InitClickResponseTime(napi_env env)
return nullptr;
}
nativeObj->SetEnv(env);
NAPI_CALL(env, napi_wrap(env, clickResponseTimeValue, reinterpret_cast<void*>(nativeObj),
NAccessibilityConfigClass::Destructor, nullptr, nullptr));
napi_status sts = napi_wrap(env, clickResponseTimeValue, reinterpret_cast<void*>(nativeObj),
NAccessibilityConfigClass::Destructor, nullptr, nullptr);
if (sts != napi_ok) {
delete nativeObj;
nativeObj = nullptr;
HILOG_ERROR("failed to wrap JS object");
return nullptr;
}
return clickResponseTimeValue;
}
@ -468,8 +576,14 @@ static napi_value InitIgnoreRepeatClickState(napi_env env)
return nullptr;
}
nativeObj->SetEnv(env);
NAPI_CALL(env, napi_wrap(env, ignoreRepeatClickStateValue, reinterpret_cast<void*>(nativeObj),
NAccessibilityConfigClass::Destructor, nullptr, nullptr));
napi_status sts = napi_wrap(env, ignoreRepeatClickStateValue, reinterpret_cast<void*>(nativeObj),
NAccessibilityConfigClass::Destructor, nullptr, nullptr);
if (sts != napi_ok) {
delete nativeObj;
nativeObj = nullptr;
HILOG_ERROR("failed to wrap JS object");
return nullptr;
}
return ignoreRepeatClickStateValue;
}
@ -491,8 +605,14 @@ static napi_value InitIgnoreRepeatClickTime(napi_env env)
return nullptr;
}
nativeObj->SetEnv(env);
NAPI_CALL(env, napi_wrap(env, ignoreRepeatClickTimeValue, reinterpret_cast<void*>(nativeObj),
NAccessibilityConfigClass::Destructor, nullptr, nullptr));
napi_status sts = napi_wrap(env, ignoreRepeatClickTimeValue, reinterpret_cast<void*>(nativeObj),
NAccessibilityConfigClass::Destructor, nullptr, nullptr);
if (sts != napi_ok) {
delete nativeObj;
nativeObj = nullptr;
HILOG_ERROR("failed to wrap JS object");
return nullptr;
}
return ignoreRepeatClickTimeValue;
}

View File

@ -166,6 +166,11 @@ void NAccessibilityElement::ConvertElementInfoToJS(napi_env env, napi_value resu
},
nullptr,
nullptr);
if (sts != napi_ok) {
delete pAccessibilityElement;
pAccessibilityElement = nullptr;
HILOG_ERROR("failed to wrap JS object");
}
HILOG_DEBUG("napi_wrap status: %{public}d", (int)sts);
}

View File

@ -104,10 +104,16 @@ void NAccessibilityExtension::Init(const std::shared_ptr<AppExecFwk::AbilityLoca
HILOG_ERROR("Failed to get accessibility extension native object");
return;
}
napi_wrap(env_, contextObj, new std::weak_ptr<AbilityRuntime::Context>(context),
auto contextPtr = new std::weak_ptr<AbilityRuntime::Context>(context);
napi_status sts = napi_wrap(env_, contextObj, contextPtr,
[](napi_env env, void* data, void*) {
delete static_cast<std::weak_ptr<AbilityRuntime::Context>*>(data);
}, nullptr, nullptr);
if (sts != napi_ok) {
delete contextPtr;
contextPtr = nullptr;
HILOG_ERROR("failed to wrap JS object");
}
NAccessibilityElement::DefineJSAccessibilityElement(env_);
}
@ -340,6 +346,11 @@ void ConvertAccessibilityElementToJS(napi_env env, napi_value objEventInfo,
},
nullptr,
nullptr);
if (sts != napi_ok) {
delete pAccessibilityElement;
pAccessibilityElement = nullptr;
HILOG_ERROR("failed to wrap JS object");
}
HILOG_DEBUG("napi_wrap status: %{public}d", (int)sts);
NAPI_CALL_RETURN_VOID(env, napi_set_named_property(env, objEventInfo, "target", nTargetObject));
}

View File

@ -54,6 +54,11 @@ static void ConvertAccessibilityWindowInfoToJS(
},
nullptr,
nullptr);
if (sts != napi_ok) {
delete pAccessibilityElement;
pAccessibilityElement = nullptr;
HILOG_ERROR("failed to wrap JS object");
}
HILOG_DEBUG("napi_wrap status: %{public}d", (int)sts);
}

View File

@ -193,6 +193,9 @@ void NAccessibilityClient::Completefunction(napi_env env, std::string type, void
NAPI_CALL_RETURN_VOID(env, napi_get_boolean(env, callbackInfo->touchEnabled_, &result[PARAM1]));
HILOG_INFO("IsOpenTouchExploration completed touchEnabled_[%{public}d]", callbackInfo->touchEnabled_);
} else {
napi_delete_async_work(env, callbackInfo->work_);
delete callbackInfo;
callbackInfo = nullptr;
return;
}
result[PARAM0] = CreateBusinessError(env, callbackInfo->ret_);