From 7f9e1eb10ad655743fc72dfa33b2185e04861a82 Mon Sep 17 00:00:00 2001 From: l00804143 Date: Wed, 17 May 2023 15:30:10 +0800 Subject: [PATCH 01/17] =?UTF-8?q?=E4=BD=BF=E7=94=A8handle=5Fscope=E7=AE=A1?= =?UTF-8?q?=E7=90=86napi=5Fvalue=E7=9A=84=E7=94=9F=E5=91=BD=E5=91=A8?= =?UTF-8?q?=E6=9C=9F=EF=BC=8C=E9=98=B2=E6=AD=A2=E5=86=85=E5=AD=98=E6=B3=84?= =?UTF-8?q?=E6=BC=8F=20Signed-off-by:=20l00804143=20?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/napi_accessibility_extension.cpp | 21 ++++++++++- .../napi_accessibility_config_observer.cpp | 37 ++++++++++++++++++- 2 files changed, 55 insertions(+), 3 deletions(-) diff --git a/interfaces/kits/napi/accessibility_extension_module_loader/src/napi_accessibility_extension.cpp b/interfaces/kits/napi/accessibility_extension_module_loader/src/napi_accessibility_extension.cpp index 25f8597a..a3cc1e58 100644 --- a/interfaces/kits/napi/accessibility_extension_module_loader/src/napi_accessibility_extension.cpp +++ b/interfaces/kits/napi/accessibility_extension_module_loader/src/napi_accessibility_extension.cpp @@ -275,6 +275,11 @@ void ConvertAccessibilityElementToJS(napi_env env, napi_value objEventInfo, HILOG_ERROR("Failed to create AccessibilityElement."); return; } + napi_handle_scope scope = nullptr; + api_open_handle_scope(env_, &scope); + if (scope == nullptr) { + return; + } napi_value nTargetObject = nullptr; napi_value constructor = nullptr; napi_get_reference_value(env, NAccessibilityElement::consRef_, &constructor); @@ -293,6 +298,7 @@ void ConvertAccessibilityElementToJS(napi_env env, napi_value objEventInfo, nullptr); HILOG_DEBUG("napi_wrap status: %{public}d", (int)sts); NAPI_CALL_RETURN_VOID(env, napi_set_named_property(env, objEventInfo, "target", nTargetObject)); + napi_close_handle_scope(env_, scope); } void NAccessibilityExtension::OnAccessibilityEvent(const AccessibilityEventInfo& eventInfo) @@ -329,6 +335,12 @@ void NAccessibilityExtension::OnAccessibilityEvent(const AccessibilityEventInfo& [](uv_work_t *work) {}, [](uv_work_t *work, int status) { AccessibilityEventInfoCallbackInfo *data = static_cast(work->data); + + napi_handle_scope scope = nullptr; + api_open_handle_scope(env_, &scope); + if (scope == nullptr) { + return; + } napi_value napiEventInfo = nullptr; napi_create_object(reinterpret_cast(data->engine_), &napiEventInfo); @@ -351,7 +363,7 @@ void NAccessibilityExtension::OnAccessibilityEvent(const AccessibilityEventInfo& NativeValue* nativeEventInfo = reinterpret_cast(napiEventInfo); NativeValue* argv[] = {nativeEventInfo}; data->extension_->CallObjectMethod("onAccessibilityEvent", argv, 1); - + napi_close_handle_scope(env_, scope); delete data; data = nullptr; delete work; @@ -394,6 +406,11 @@ bool NAccessibilityExtension::OnKeyPressEvent(const std::shared_ptr(work->data); + napi_handle_scope scope = nullptr; + api_open_handle_scope(env_, &scope); + if (scope == nullptr) { + return; + } napi_value napiEventInfo = nullptr; if (napi_create_object(reinterpret_cast(data->engine_), &napiEventInfo) != napi_ok) { HILOG_ERROR("Create keyEvent object failed."); @@ -422,7 +439,7 @@ bool NAccessibilityExtension::OnKeyPressEvent(const std::shared_ptrsyncPromise_.set_value(result); - + napi_close_handle_scope(env_, scope); delete data; data = nullptr; delete work; diff --git a/interfaces/kits/napi/src/napi_accessibility_config_observer.cpp b/interfaces/kits/napi/src/napi_accessibility_config_observer.cpp index fe2d2ef2..6ac969ec 100644 --- a/interfaces/kits/napi/src/napi_accessibility_config_observer.cpp +++ b/interfaces/kits/napi/src/napi_accessibility_config_observer.cpp @@ -107,6 +107,11 @@ void NAccessibilityConfigObserver::NotifyStateChanged2JS(bool enabled) int ret = uv_queue_work(loop, work, [](uv_work_t *work) {}, [](uv_work_t *work, int status) { StateCallbackInfo *callbackInfo = static_cast(work->data); + napi_handle_scope scope = nullptr; + api_open_handle_scope(env_, &scope); + if (scope == nullptr) { + return; + } napi_value jsEvent; napi_create_object(callbackInfo->env_, &jsEvent); napi_get_boolean(callbackInfo->env_, callbackInfo->state_, &jsEvent); @@ -120,6 +125,7 @@ void NAccessibilityConfigObserver::NotifyStateChanged2JS(bool enabled) int32_t result; napi_get_value_int32(callbackInfo->env_, callResult, &result); HILOG_INFO("NotifyStateChangedJS napi_call_function result[%{public}d]", result); + napi_close_handle_scope(env_, scope); delete callbackInfo; callbackInfo = nullptr; delete work; @@ -160,6 +166,11 @@ void NAccessibilityConfigObserver::NotifyPropertyChanged2JS(const OHOS::Accessib int ret = uv_queue_work(loop, work, [](uv_work_t *work) {}, [](uv_work_t *work, int status) { CaptionCallbackInfo *callbackInfo = static_cast(work->data); + napi_handle_scope scope = nullptr; + api_open_handle_scope(env_, &scope); + if (scope == nullptr) { + return; + } napi_value jsEvent; napi_create_object(callbackInfo->env_, &jsEvent); ConvertCaptionPropertyToJS(callbackInfo->env_, jsEvent, callbackInfo->caption_); @@ -173,6 +184,7 @@ void NAccessibilityConfigObserver::NotifyPropertyChanged2JS(const OHOS::Accessib int32_t result; napi_get_value_int32(callbackInfo->env_, callResult, &result); HILOG_INFO("NotifyPropertyChangedJS napi_call_function result[%{public}d]", result); + napi_close_handle_scope(env_, scope); delete callbackInfo; callbackInfo = nullptr; delete work; @@ -213,6 +225,11 @@ void NAccessibilityConfigObserver::NotifyStringChanged2JS(const std::string& val int ret = uv_queue_work(loop, work, [](uv_work_t *work) {}, [](uv_work_t *work, int status) { StateCallbackInfo *callbackInfo = static_cast(work->data); + napi_handle_scope scope = nullptr; + api_open_handle_scope(env_, &scope); + if (scope == nullptr) { + return; + } napi_value jsEvent; napi_create_string_utf8(callbackInfo->env_, callbackInfo->stringValue_.c_str(), callbackInfo->stringValue_.length(), &jsEvent); @@ -227,6 +244,7 @@ void NAccessibilityConfigObserver::NotifyStringChanged2JS(const std::string& val char buf[BUF_SIZE] = {0}; napi_get_value_string_utf8(callbackInfo->env_, callResult, buf, BUF_SIZE, &result); HILOG_INFO("NotifyStringChanged2JSInner napi_call_function result[%{public}zu]", result); + napi_close_handle_scope(env_, scope); delete callbackInfo; callbackInfo = nullptr; delete work; @@ -270,6 +288,11 @@ void NAccessibilityConfigObserver::NotifyIntChanged2JS(int32_t value) [](uv_work_t *work) {}, [](uv_work_t *work, int status) { StateCallbackInfo *callbackInfo = static_cast(work->data); + napi_handle_scope scope = nullptr; + api_open_handle_scope(env_, &scope); + if (scope == nullptr) { + return; + } napi_value jsEvent; napi_create_int32(callbackInfo->env_, callbackInfo->int32Value_, &jsEvent); @@ -282,6 +305,7 @@ void NAccessibilityConfigObserver::NotifyIntChanged2JS(int32_t value) int32_t result; napi_get_value_int32(callbackInfo->env_, callResult, &result); HILOG_INFO("NotifyIntChanged2JSInner napi_call_function result[%{public}d]", result); + napi_close_handle_scope(env_, scope); delete callbackInfo; callbackInfo = nullptr; delete work; @@ -325,6 +349,11 @@ void NAccessibilityConfigObserver::NotifyUintChanged2JS(uint32_t value) [](uv_work_t *work) {}, [](uv_work_t *work, int status) { StateCallbackInfo *callbackInfo = static_cast(work->data); + napi_handle_scope scope = nullptr; + api_open_handle_scope(env_, &scope); + if (scope == nullptr) { + return; + } napi_value jsEvent; napi_create_uint32(callbackInfo->env_, callbackInfo->uint32Value_, &jsEvent); @@ -337,6 +366,7 @@ void NAccessibilityConfigObserver::NotifyUintChanged2JS(uint32_t value) uint32_t result; napi_get_value_uint32(callbackInfo->env_, callResult, &result); HILOG_INFO("NotifyUintChanged2JSInner napi_call_function result[%{public}d]", result); + napi_close_handle_scope(env_, scope); delete callbackInfo; callbackInfo = nullptr; delete work; @@ -380,9 +410,13 @@ void NAccessibilityConfigObserver::NotifyFloatChanged2JS(float value) [](uv_work_t *work) {}, [](uv_work_t *work, int status) { StateCallbackInfo *callbackInfo = static_cast(work->data); + napi_handle_scope scope = nullptr; + api_open_handle_scope(env_, &scope); + if (scope == nullptr) { + return; + } napi_value jsEvent; napi_create_double(callbackInfo->env_, double(callbackInfo->floatValue_), &jsEvent); - napi_value handler = nullptr; napi_value callResult = nullptr; napi_get_reference_value(callbackInfo->env_, callbackInfo->ref_, &handler); @@ -392,6 +426,7 @@ void NAccessibilityConfigObserver::NotifyFloatChanged2JS(float value) int32_t result; napi_get_value_int32(callbackInfo->env_, callResult, &result); HILOG_INFO("NotifyFloatChanged2JSInner napi_call_function result[%{public}d]", result); + napi_close_handle_scope(env_, scope); delete callbackInfo; callbackInfo = nullptr; delete work; -- Gitee From 81077861f3d6a9f3b08f5a4c4bb727b428332813 Mon Sep 17 00:00:00 2001 From: luocheng Date: Wed, 17 May 2023 08:03:02 +0000 Subject: [PATCH 02/17] update interfaces/kits/napi/src/napi_accessibility_config_observer.cpp. Signed-off-by: luocheng --- .../napi_accessibility_config_observer.cpp | 24 +++++++++---------- 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/interfaces/kits/napi/src/napi_accessibility_config_observer.cpp b/interfaces/kits/napi/src/napi_accessibility_config_observer.cpp index 6ac969ec..6db97163 100644 --- a/interfaces/kits/napi/src/napi_accessibility_config_observer.cpp +++ b/interfaces/kits/napi/src/napi_accessibility_config_observer.cpp @@ -108,7 +108,7 @@ void NAccessibilityConfigObserver::NotifyStateChanged2JS(bool enabled) [](uv_work_t *work, int status) { StateCallbackInfo *callbackInfo = static_cast(work->data); napi_handle_scope scope = nullptr; - api_open_handle_scope(env_, &scope); + api_open_handle_scope(callbackInfo->env_, &scope); if (scope == nullptr) { return; } @@ -125,7 +125,7 @@ void NAccessibilityConfigObserver::NotifyStateChanged2JS(bool enabled) int32_t result; napi_get_value_int32(callbackInfo->env_, callResult, &result); HILOG_INFO("NotifyStateChangedJS napi_call_function result[%{public}d]", result); - napi_close_handle_scope(env_, scope); + napi_close_handle_scope(callbackInfo->env_, scope); delete callbackInfo; callbackInfo = nullptr; delete work; @@ -167,7 +167,7 @@ void NAccessibilityConfigObserver::NotifyPropertyChanged2JS(const OHOS::Accessib [](uv_work_t *work, int status) { CaptionCallbackInfo *callbackInfo = static_cast(work->data); napi_handle_scope scope = nullptr; - api_open_handle_scope(env_, &scope); + api_open_handle_scope(callbackInfo->env_, &scope); if (scope == nullptr) { return; } @@ -184,7 +184,7 @@ void NAccessibilityConfigObserver::NotifyPropertyChanged2JS(const OHOS::Accessib int32_t result; napi_get_value_int32(callbackInfo->env_, callResult, &result); HILOG_INFO("NotifyPropertyChangedJS napi_call_function result[%{public}d]", result); - napi_close_handle_scope(env_, scope); + napi_close_handle_scope(callbackInfo->env_, scope); delete callbackInfo; callbackInfo = nullptr; delete work; @@ -226,7 +226,7 @@ void NAccessibilityConfigObserver::NotifyStringChanged2JS(const std::string& val [](uv_work_t *work, int status) { StateCallbackInfo *callbackInfo = static_cast(work->data); napi_handle_scope scope = nullptr; - api_open_handle_scope(env_, &scope); + api_open_handle_scope(callbackInfo->env_, &scope); if (scope == nullptr) { return; } @@ -244,7 +244,7 @@ void NAccessibilityConfigObserver::NotifyStringChanged2JS(const std::string& val char buf[BUF_SIZE] = {0}; napi_get_value_string_utf8(callbackInfo->env_, callResult, buf, BUF_SIZE, &result); HILOG_INFO("NotifyStringChanged2JSInner napi_call_function result[%{public}zu]", result); - napi_close_handle_scope(env_, scope); + napi_close_handle_scope(callbackInfo->env_, scope); delete callbackInfo; callbackInfo = nullptr; delete work; @@ -289,7 +289,7 @@ void NAccessibilityConfigObserver::NotifyIntChanged2JS(int32_t value) [](uv_work_t *work, int status) { StateCallbackInfo *callbackInfo = static_cast(work->data); napi_handle_scope scope = nullptr; - api_open_handle_scope(env_, &scope); + api_open_handle_scope(callbackInfo->env_, &scope); if (scope == nullptr) { return; } @@ -305,7 +305,7 @@ void NAccessibilityConfigObserver::NotifyIntChanged2JS(int32_t value) int32_t result; napi_get_value_int32(callbackInfo->env_, callResult, &result); HILOG_INFO("NotifyIntChanged2JSInner napi_call_function result[%{public}d]", result); - napi_close_handle_scope(env_, scope); + napi_close_handle_scope(callbackInfo->env_, scope); delete callbackInfo; callbackInfo = nullptr; delete work; @@ -350,7 +350,7 @@ void NAccessibilityConfigObserver::NotifyUintChanged2JS(uint32_t value) [](uv_work_t *work, int status) { StateCallbackInfo *callbackInfo = static_cast(work->data); napi_handle_scope scope = nullptr; - api_open_handle_scope(env_, &scope); + api_open_handle_scope(callbackInfo->env_, &scope); if (scope == nullptr) { return; } @@ -366,7 +366,7 @@ void NAccessibilityConfigObserver::NotifyUintChanged2JS(uint32_t value) uint32_t result; napi_get_value_uint32(callbackInfo->env_, callResult, &result); HILOG_INFO("NotifyUintChanged2JSInner napi_call_function result[%{public}d]", result); - napi_close_handle_scope(env_, scope); + napi_close_handle_scope(callbackInfo->env_, scope); delete callbackInfo; callbackInfo = nullptr; delete work; @@ -411,7 +411,7 @@ void NAccessibilityConfigObserver::NotifyFloatChanged2JS(float value) [](uv_work_t *work, int status) { StateCallbackInfo *callbackInfo = static_cast(work->data); napi_handle_scope scope = nullptr; - api_open_handle_scope(env_, &scope); + api_open_handle_scope(callbackInfo->env_, &scope); if (scope == nullptr) { return; } @@ -426,7 +426,7 @@ void NAccessibilityConfigObserver::NotifyFloatChanged2JS(float value) int32_t result; napi_get_value_int32(callbackInfo->env_, callResult, &result); HILOG_INFO("NotifyFloatChanged2JSInner napi_call_function result[%{public}d]", result); - napi_close_handle_scope(env_, scope); + napi_close_handle_scope(callbackInfo->env_, scope); delete callbackInfo; callbackInfo = nullptr; delete work; -- Gitee From 3713bd20179d6c4863598fd21484b1ef8e5f7370 Mon Sep 17 00:00:00 2001 From: luocheng Date: Wed, 17 May 2023 08:06:50 +0000 Subject: [PATCH 03/17] update src/napi_accessibility_extension.cpp. Signed-off-by: luocheng --- .../src/napi_accessibility_extension.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/interfaces/kits/napi/accessibility_extension_module_loader/src/napi_accessibility_extension.cpp b/interfaces/kits/napi/accessibility_extension_module_loader/src/napi_accessibility_extension.cpp index a3cc1e58..4ef20b15 100644 --- a/interfaces/kits/napi/accessibility_extension_module_loader/src/napi_accessibility_extension.cpp +++ b/interfaces/kits/napi/accessibility_extension_module_loader/src/napi_accessibility_extension.cpp @@ -276,7 +276,7 @@ void ConvertAccessibilityElementToJS(napi_env env, napi_value objEventInfo, return; } napi_handle_scope scope = nullptr; - api_open_handle_scope(env_, &scope); + api_open_handle_scope(env, &scope); if (scope == nullptr) { return; } @@ -298,7 +298,7 @@ void ConvertAccessibilityElementToJS(napi_env env, napi_value objEventInfo, nullptr); HILOG_DEBUG("napi_wrap status: %{public}d", (int)sts); NAPI_CALL_RETURN_VOID(env, napi_set_named_property(env, objEventInfo, "target", nTargetObject)); - napi_close_handle_scope(env_, scope); + napi_close_handle_scope(env, scope); } void NAccessibilityExtension::OnAccessibilityEvent(const AccessibilityEventInfo& eventInfo) -- Gitee From 5c1ec39f02f308019007abab6eedc11e2c4decd3 Mon Sep 17 00:00:00 2001 From: luocheng Date: Wed, 17 May 2023 08:31:29 +0000 Subject: [PATCH 04/17] update interfaces/kits/napi/src/napi_accessibility_config_observer.cpp. Signed-off-by: luocheng --- .../kits/napi/src/napi_accessibility_config_observer.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/interfaces/kits/napi/src/napi_accessibility_config_observer.cpp b/interfaces/kits/napi/src/napi_accessibility_config_observer.cpp index 6db97163..2acda87d 100644 --- a/interfaces/kits/napi/src/napi_accessibility_config_observer.cpp +++ b/interfaces/kits/napi/src/napi_accessibility_config_observer.cpp @@ -350,7 +350,7 @@ void NAccessibilityConfigObserver::NotifyUintChanged2JS(uint32_t value) [](uv_work_t *work, int status) { StateCallbackInfo *callbackInfo = static_cast(work->data); napi_handle_scope scope = nullptr; - api_open_handle_scope(callbackInfo->env_, &scope); + napi_open_handle_scope(callbackInfo->env_, &scope); if (scope == nullptr) { return; } @@ -411,7 +411,7 @@ void NAccessibilityConfigObserver::NotifyFloatChanged2JS(float value) [](uv_work_t *work, int status) { StateCallbackInfo *callbackInfo = static_cast(work->data); napi_handle_scope scope = nullptr; - api_open_handle_scope(callbackInfo->env_, &scope); + napi_open_handle_scope(callbackInfo->env_, &scope); if (scope == nullptr) { return; } -- Gitee From bb434a1f27e41ecb89dd9139820f8b861241c5e5 Mon Sep 17 00:00:00 2001 From: luocheng Date: Wed, 17 May 2023 09:06:33 +0000 Subject: [PATCH 05/17] update interfaces/kits/napi/src/napi_accessibility_config_observer.cpp. Signed-off-by: luocheng --- .../kits/napi/src/napi_accessibility_config_observer.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/interfaces/kits/napi/src/napi_accessibility_config_observer.cpp b/interfaces/kits/napi/src/napi_accessibility_config_observer.cpp index 2acda87d..8b99bd36 100644 --- a/interfaces/kits/napi/src/napi_accessibility_config_observer.cpp +++ b/interfaces/kits/napi/src/napi_accessibility_config_observer.cpp @@ -108,7 +108,7 @@ void NAccessibilityConfigObserver::NotifyStateChanged2JS(bool enabled) [](uv_work_t *work, int status) { StateCallbackInfo *callbackInfo = static_cast(work->data); napi_handle_scope scope = nullptr; - api_open_handle_scope(callbackInfo->env_, &scope); + napi_open_handle_scope(callbackInfo->env_, &scope); if (scope == nullptr) { return; } @@ -226,7 +226,7 @@ void NAccessibilityConfigObserver::NotifyStringChanged2JS(const std::string& val [](uv_work_t *work, int status) { StateCallbackInfo *callbackInfo = static_cast(work->data); napi_handle_scope scope = nullptr; - api_open_handle_scope(callbackInfo->env_, &scope); + napi_open_handle_scope(callbackInfo->env_, &scope); if (scope == nullptr) { return; } @@ -289,7 +289,7 @@ void NAccessibilityConfigObserver::NotifyIntChanged2JS(int32_t value) [](uv_work_t *work, int status) { StateCallbackInfo *callbackInfo = static_cast(work->data); napi_handle_scope scope = nullptr; - api_open_handle_scope(callbackInfo->env_, &scope); + napi_open_handle_scope(callbackInfo->env_, &scope); if (scope == nullptr) { return; } -- Gitee From 0282531a4d93137f8c48bc76926ce321597b3e99 Mon Sep 17 00:00:00 2001 From: luocheng Date: Wed, 17 May 2023 09:07:25 +0000 Subject: [PATCH 06/17] update Signed-off-by: luocheng --- .../src/napi_accessibility_extension.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/interfaces/kits/napi/accessibility_extension_module_loader/src/napi_accessibility_extension.cpp b/interfaces/kits/napi/accessibility_extension_module_loader/src/napi_accessibility_extension.cpp index 4ef20b15..531cd48a 100644 --- a/interfaces/kits/napi/accessibility_extension_module_loader/src/napi_accessibility_extension.cpp +++ b/interfaces/kits/napi/accessibility_extension_module_loader/src/napi_accessibility_extension.cpp @@ -276,7 +276,7 @@ void ConvertAccessibilityElementToJS(napi_env env, napi_value objEventInfo, return; } napi_handle_scope scope = nullptr; - api_open_handle_scope(env, &scope); + napi_open_handle_scope(env, &scope); if (scope == nullptr) { return; } -- Gitee From 53f46960156dc248ff343eee3e6e4db88fc5192b Mon Sep 17 00:00:00 2001 From: luocheng Date: Wed, 17 May 2023 09:09:00 +0000 Subject: [PATCH 07/17] update interfaces/kits/napi/src/napi_accessibility_config_observer.cpp. Signed-off-by: luocheng --- interfaces/kits/napi/src/napi_accessibility_config_observer.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/interfaces/kits/napi/src/napi_accessibility_config_observer.cpp b/interfaces/kits/napi/src/napi_accessibility_config_observer.cpp index 8b99bd36..7ccb03c4 100644 --- a/interfaces/kits/napi/src/napi_accessibility_config_observer.cpp +++ b/interfaces/kits/napi/src/napi_accessibility_config_observer.cpp @@ -167,7 +167,7 @@ void NAccessibilityConfigObserver::NotifyPropertyChanged2JS(const OHOS::Accessib [](uv_work_t *work, int status) { CaptionCallbackInfo *callbackInfo = static_cast(work->data); napi_handle_scope scope = nullptr; - api_open_handle_scope(callbackInfo->env_, &scope); + napi_open_handle_scope(callbackInfo->env_, &scope); if (scope == nullptr) { return; } -- Gitee From 83c089057d8fc389f1058a9fdc6dbe292fe1328b Mon Sep 17 00:00:00 2001 From: luocheng Date: Wed, 17 May 2023 09:09:44 +0000 Subject: [PATCH 08/17] update Signed-off-by: luocheng --- .../src/napi_accessibility_extension.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/interfaces/kits/napi/accessibility_extension_module_loader/src/napi_accessibility_extension.cpp b/interfaces/kits/napi/accessibility_extension_module_loader/src/napi_accessibility_extension.cpp index 531cd48a..4e04f46a 100644 --- a/interfaces/kits/napi/accessibility_extension_module_loader/src/napi_accessibility_extension.cpp +++ b/interfaces/kits/napi/accessibility_extension_module_loader/src/napi_accessibility_extension.cpp @@ -337,7 +337,7 @@ void NAccessibilityExtension::OnAccessibilityEvent(const AccessibilityEventInfo& AccessibilityEventInfoCallbackInfo *data = static_cast(work->data); napi_handle_scope scope = nullptr; - api_open_handle_scope(env_, &scope); + napi_open_handle_scope(env_, &scope); if (scope == nullptr) { return; } -- Gitee From 610670f332502d3afa81df12df2e57e37b6d8253 Mon Sep 17 00:00:00 2001 From: luocheng Date: Wed, 17 May 2023 09:10:34 +0000 Subject: [PATCH 09/17] update Signed-off-by: luocheng --- .../src/napi_accessibility_extension.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/interfaces/kits/napi/accessibility_extension_module_loader/src/napi_accessibility_extension.cpp b/interfaces/kits/napi/accessibility_extension_module_loader/src/napi_accessibility_extension.cpp index 4e04f46a..fa1e2095 100644 --- a/interfaces/kits/napi/accessibility_extension_module_loader/src/napi_accessibility_extension.cpp +++ b/interfaces/kits/napi/accessibility_extension_module_loader/src/napi_accessibility_extension.cpp @@ -407,7 +407,7 @@ bool NAccessibilityExtension::OnKeyPressEvent(const std::shared_ptr(work->data); napi_handle_scope scope = nullptr; - api_open_handle_scope(env_, &scope); + napi_open_handle_scope(env_, &scope); if (scope == nullptr) { return; } -- Gitee From d1fc4d7fcb28b0882c334576990e06a55dce563d Mon Sep 17 00:00:00 2001 From: luocheng Date: Wed, 17 May 2023 10:22:40 +0000 Subject: [PATCH 10/17] update Signed-off-by: luocheng --- .../src/napi_accessibility_extension.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/interfaces/kits/napi/accessibility_extension_module_loader/src/napi_accessibility_extension.cpp b/interfaces/kits/napi/accessibility_extension_module_loader/src/napi_accessibility_extension.cpp index fa1e2095..f1aa89ae 100644 --- a/interfaces/kits/napi/accessibility_extension_module_loader/src/napi_accessibility_extension.cpp +++ b/interfaces/kits/napi/accessibility_extension_module_loader/src/napi_accessibility_extension.cpp @@ -337,7 +337,7 @@ void NAccessibilityExtension::OnAccessibilityEvent(const AccessibilityEventInfo& AccessibilityEventInfoCallbackInfo *data = static_cast(work->data); napi_handle_scope scope = nullptr; - napi_open_handle_scope(env_, &scope); + napi_open_handle_scope(reinterpret_cast(data->engine_), &scope); if (scope == nullptr) { return; } @@ -363,7 +363,7 @@ void NAccessibilityExtension::OnAccessibilityEvent(const AccessibilityEventInfo& NativeValue* nativeEventInfo = reinterpret_cast(napiEventInfo); NativeValue* argv[] = {nativeEventInfo}; data->extension_->CallObjectMethod("onAccessibilityEvent", argv, 1); - napi_close_handle_scope(env_, scope); + napi_close_handle_scope(reinterpret_cast(data->engine_), scope); delete data; data = nullptr; delete work; @@ -407,7 +407,7 @@ bool NAccessibilityExtension::OnKeyPressEvent(const std::shared_ptr(work->data); napi_handle_scope scope = nullptr; - napi_open_handle_scope(env_, &scope); + napi_open_handle_scope(reinterpret_cast(data->engine_), &scope); if (scope == nullptr) { return; } @@ -439,7 +439,7 @@ bool NAccessibilityExtension::OnKeyPressEvent(const std::shared_ptrsyncPromise_.set_value(result); - napi_close_handle_scope(env_, scope); + napi_close_handle_scope(reinterpret_cast(data->engine_), scope); delete data; data = nullptr; delete work; -- Gitee From 6f8be47ddb3f352ce4fcc93581d4248e93da0ded Mon Sep 17 00:00:00 2001 From: luocheng Date: Thu, 18 May 2023 06:12:47 +0000 Subject: [PATCH 11/17] update interfaces/innerkits/acfwk/include/accessibility_config_observer.h. Signed-off-by: luocheng --- .../innerkits/acfwk/include/accessibility_config_observer.h | 1 + 1 file changed, 1 insertion(+) diff --git a/interfaces/innerkits/acfwk/include/accessibility_config_observer.h b/interfaces/innerkits/acfwk/include/accessibility_config_observer.h index f2b220cc..4c062567 100644 --- a/interfaces/innerkits/acfwk/include/accessibility_config_observer.h +++ b/interfaces/innerkits/acfwk/include/accessibility_config_observer.h @@ -32,6 +32,7 @@ public: void NotifyStateChanged2JS(bool enabled); void NotifyPropertyChanged2JS(const OHOS::AccessibilityConfig::CaptionProperty &caption); + int NotifyFloatChanged(uv_work_t *work); void NotifyStringChanged2JS(const std::string& value); void NotifyIntChanged2JS(int32_t value); void NotifyUintChanged2JS(uint32_t value); -- Gitee From 76472ba1262336b883329bba92524355479e3f00 Mon Sep 17 00:00:00 2001 From: luocheng Date: Thu, 18 May 2023 06:29:43 +0000 Subject: [PATCH 12/17] update interfaces/kits/napi/src/napi_accessibility_config_observer.cpp. Signed-off-by: luocheng --- .../napi_accessibility_config_observer.cpp | 206 +++--------------- 1 file changed, 30 insertions(+), 176 deletions(-) diff --git a/interfaces/kits/napi/src/napi_accessibility_config_observer.cpp b/interfaces/kits/napi/src/napi_accessibility_config_observer.cpp index 7ccb03c4..d8c48c6b 100644 --- a/interfaces/kits/napi/src/napi_accessibility_config_observer.cpp +++ b/interfaces/kits/napi/src/napi_accessibility_config_observer.cpp @@ -81,27 +81,8 @@ void NAccessibilityConfigObserver::OnConfigChanged(const ConfigValue &value) } } -void NAccessibilityConfigObserver::NotifyStateChanged2JS(bool enabled) +int NAccessibilityConfigObserver::NotifyFloatChanged(uv_work_t *work) { - HILOG_INFO("id = [%{public}d] enabled = [%{public}s]", static_cast(configId_), enabled ? "true" : "false"); - - StateCallbackInfo *callbackInfo = new(std::nothrow) StateCallbackInfo(); - if (!callbackInfo) { - HILOG_ERROR("Failed to create callbackInfo."); - return; - } - callbackInfo->state_ = enabled; - callbackInfo->env_ = env_; - callbackInfo->ref_ = handlerRef_; - uv_work_t *work = new(std::nothrow) uv_work_t; - if (!work) { - HILOG_ERROR("Failed to create work."); - delete callbackInfo; - callbackInfo = nullptr; - return; - } - work->data = static_cast(callbackInfo); - uv_loop_s *loop = nullptr; napi_get_uv_event_loop(env_, &loop); int ret = uv_queue_work(loop, work, [](uv_work_t *work) {}, @@ -131,6 +112,30 @@ void NAccessibilityConfigObserver::NotifyStateChanged2JS(bool enabled) delete work; work = nullptr; }); + return ret; +} + +void NAccessibilityConfigObserver::NotifyStateChanged2JS(bool enabled) +{ + HILOG_INFO("id = [%{public}d] enabled = [%{public}s]", static_cast(configId_), enabled ? "true" : "false"); + + StateCallbackInfo *callbackInfo = new(std::nothrow) StateCallbackInfo(); + if (!callbackInfo) { + HILOG_ERROR("Failed to create callbackInfo."); + return; + } + callbackInfo->state_ = enabled; + callbackInfo->env_ = env_; + callbackInfo->ref_ = handlerRef_; + uv_work_t *work = new(std::nothrow) uv_work_t; + if (!work) { + HILOG_ERROR("Failed to create work."); + delete callbackInfo; + callbackInfo = nullptr; + return; + } + work->data = static_cast(callbackInfo); + int ret = NotifyFloatChanged(work); if (ret != 0) { HILOG_ERROR("Failed to execute NotifyStateChanged2JS work queue"); delete callbackInfo; @@ -160,36 +165,7 @@ void NAccessibilityConfigObserver::NotifyPropertyChanged2JS(const OHOS::Accessib return; } work->data = static_cast(callbackInfo); - - uv_loop_s *loop = nullptr; - napi_get_uv_event_loop(env_, &loop); - int ret = uv_queue_work(loop, work, [](uv_work_t *work) {}, - [](uv_work_t *work, int status) { - CaptionCallbackInfo *callbackInfo = static_cast(work->data); - napi_handle_scope scope = nullptr; - napi_open_handle_scope(callbackInfo->env_, &scope); - if (scope == nullptr) { - return; - } - napi_value jsEvent; - napi_create_object(callbackInfo->env_, &jsEvent); - ConvertCaptionPropertyToJS(callbackInfo->env_, jsEvent, callbackInfo->caption_); - - napi_value handler = nullptr; - napi_value callResult = nullptr; - napi_get_reference_value(callbackInfo->env_, callbackInfo->ref_, &handler); - napi_value undefined = nullptr; - napi_get_undefined(callbackInfo->env_, &undefined); - napi_call_function(callbackInfo->env_, undefined, handler, 1, &jsEvent, &callResult); - int32_t result; - napi_get_value_int32(callbackInfo->env_, callResult, &result); - HILOG_INFO("NotifyPropertyChangedJS napi_call_function result[%{public}d]", result); - napi_close_handle_scope(callbackInfo->env_, scope); - delete callbackInfo; - callbackInfo = nullptr; - delete work; - work = nullptr; - }); + int ret = NotifyFloatChanged(work); if (ret != 0) { HILOG_ERROR("Failed to execute NotifyPropertyChanged2JS work queue"); delete callbackInfo; @@ -219,37 +195,7 @@ void NAccessibilityConfigObserver::NotifyStringChanged2JS(const std::string& val return; } work->data = static_cast(callbackInfo); - - uv_loop_s *loop = nullptr; - napi_get_uv_event_loop(env_, &loop); - int ret = uv_queue_work(loop, work, [](uv_work_t *work) {}, - [](uv_work_t *work, int status) { - StateCallbackInfo *callbackInfo = static_cast(work->data); - napi_handle_scope scope = nullptr; - napi_open_handle_scope(callbackInfo->env_, &scope); - if (scope == nullptr) { - return; - } - napi_value jsEvent; - napi_create_string_utf8(callbackInfo->env_, callbackInfo->stringValue_.c_str(), - callbackInfo->stringValue_.length(), &jsEvent); - napi_value handler = nullptr; - napi_value callResult = nullptr; - napi_get_reference_value(callbackInfo->env_, callbackInfo->ref_, &handler); - napi_value undefined = nullptr; - napi_get_undefined(callbackInfo->env_, &undefined); - napi_call_function(callbackInfo->env_, undefined, handler, 1, &jsEvent, &callResult); - size_t result; - const uint32_t BUF_SIZE = 1024; - char buf[BUF_SIZE] = {0}; - napi_get_value_string_utf8(callbackInfo->env_, callResult, buf, BUF_SIZE, &result); - HILOG_INFO("NotifyStringChanged2JSInner napi_call_function result[%{public}zu]", result); - napi_close_handle_scope(callbackInfo->env_, scope); - delete callbackInfo; - callbackInfo = nullptr; - delete work; - work = nullptr; - }); + int ret = NotifyFloatChanged(work); if (ret != 0) { HILOG_ERROR("Failed to execute NotifyStringChanged2JS work queue"); delete callbackInfo; @@ -279,38 +225,7 @@ void NAccessibilityConfigObserver::NotifyIntChanged2JS(int32_t value) return; } work->data = static_cast(callbackInfo); - - uv_loop_s *loop = nullptr; - napi_get_uv_event_loop(env_, &loop); - int ret = uv_queue_work( - loop, - work, - [](uv_work_t *work) {}, - [](uv_work_t *work, int status) { - StateCallbackInfo *callbackInfo = static_cast(work->data); - napi_handle_scope scope = nullptr; - napi_open_handle_scope(callbackInfo->env_, &scope); - if (scope == nullptr) { - return; - } - napi_value jsEvent; - napi_create_int32(callbackInfo->env_, callbackInfo->int32Value_, &jsEvent); - - napi_value handler = nullptr; - napi_value callResult = nullptr; - napi_get_reference_value(callbackInfo->env_, callbackInfo->ref_, &handler); - napi_value undefined = nullptr; - napi_get_undefined(callbackInfo->env_, &undefined); - napi_call_function(callbackInfo->env_, undefined, handler, 1, &jsEvent, &callResult); - int32_t result; - napi_get_value_int32(callbackInfo->env_, callResult, &result); - HILOG_INFO("NotifyIntChanged2JSInner napi_call_function result[%{public}d]", result); - napi_close_handle_scope(callbackInfo->env_, scope); - delete callbackInfo; - callbackInfo = nullptr; - delete work; - work = nullptr; - }); + int ret = NotifyFloatChanged(work); if (ret != 0) { HILOG_ERROR("Failed to execute NotifyIntChanged2JS work queue"); delete callbackInfo; @@ -340,38 +255,7 @@ void NAccessibilityConfigObserver::NotifyUintChanged2JS(uint32_t value) return; } work->data = static_cast(callbackInfo); - - uv_loop_s *loop = nullptr; - napi_get_uv_event_loop(env_, &loop); - int ret = uv_queue_work( - loop, - work, - [](uv_work_t *work) {}, - [](uv_work_t *work, int status) { - StateCallbackInfo *callbackInfo = static_cast(work->data); - napi_handle_scope scope = nullptr; - napi_open_handle_scope(callbackInfo->env_, &scope); - if (scope == nullptr) { - return; - } - napi_value jsEvent; - napi_create_uint32(callbackInfo->env_, callbackInfo->uint32Value_, &jsEvent); - - napi_value handler = nullptr; - napi_value callResult = nullptr; - napi_get_reference_value(callbackInfo->env_, callbackInfo->ref_, &handler); - napi_value undefined = nullptr; - napi_get_undefined(callbackInfo->env_, &undefined); - napi_call_function(callbackInfo->env_, undefined, handler, 1, &jsEvent, &callResult); - uint32_t result; - napi_get_value_uint32(callbackInfo->env_, callResult, &result); - HILOG_INFO("NotifyUintChanged2JSInner napi_call_function result[%{public}d]", result); - napi_close_handle_scope(callbackInfo->env_, scope); - delete callbackInfo; - callbackInfo = nullptr; - delete work; - work = nullptr; - }); + int ret = NotifyFloatChanged(work); if (ret != 0) { HILOG_ERROR("Failed to execute NotifyUintChanged2JS work queue"); delete callbackInfo; @@ -401,37 +285,7 @@ void NAccessibilityConfigObserver::NotifyFloatChanged2JS(float value) return; } work->data = static_cast(callbackInfo); - - uv_loop_s *loop = nullptr; - napi_get_uv_event_loop(env_, &loop); - int ret = uv_queue_work( - loop, - work, - [](uv_work_t *work) {}, - [](uv_work_t *work, int status) { - StateCallbackInfo *callbackInfo = static_cast(work->data); - napi_handle_scope scope = nullptr; - napi_open_handle_scope(callbackInfo->env_, &scope); - if (scope == nullptr) { - return; - } - napi_value jsEvent; - napi_create_double(callbackInfo->env_, double(callbackInfo->floatValue_), &jsEvent); - napi_value handler = nullptr; - napi_value callResult = nullptr; - napi_get_reference_value(callbackInfo->env_, callbackInfo->ref_, &handler); - napi_value undefined = nullptr; - napi_get_undefined(callbackInfo->env_, &undefined); - napi_call_function(callbackInfo->env_, undefined, handler, 1, &jsEvent, &callResult); - int32_t result; - napi_get_value_int32(callbackInfo->env_, callResult, &result); - HILOG_INFO("NotifyFloatChanged2JSInner napi_call_function result[%{public}d]", result); - napi_close_handle_scope(callbackInfo->env_, scope); - delete callbackInfo; - callbackInfo = nullptr; - delete work; - work = nullptr; - }); + int ret = NotifyFloatChanged(work); if (ret != 0) { HILOG_ERROR("Failed to execute NotifyFloatChanged2JS work queue"); delete callbackInfo; -- Gitee From 0e790ec6e128ac0b55becd11b4e2521efe6ab79e Mon Sep 17 00:00:00 2001 From: luocheng Date: Thu, 18 May 2023 06:45:20 +0000 Subject: [PATCH 13/17] update interfaces/innerkits/acfwk/include/accessibility_config_observer.h. Signed-off-by: luocheng --- .../innerkits/acfwk/include/accessibility_config_observer.h | 1 + 1 file changed, 1 insertion(+) diff --git a/interfaces/innerkits/acfwk/include/accessibility_config_observer.h b/interfaces/innerkits/acfwk/include/accessibility_config_observer.h index 4c062567..63808a63 100644 --- a/interfaces/innerkits/acfwk/include/accessibility_config_observer.h +++ b/interfaces/innerkits/acfwk/include/accessibility_config_observer.h @@ -18,6 +18,7 @@ #include #include +#include #include "accessibility_config.h" #include "napi/native_api.h" #include "napi/native_node_api.h" -- Gitee From 2a778d1b78d56597cc3accc2258d127a9ce36911 Mon Sep 17 00:00:00 2001 From: luocheng Date: Thu, 18 May 2023 06:45:51 +0000 Subject: [PATCH 14/17] update interfaces/kits/napi/src/napi_accessibility_config_observer.cpp. Signed-off-by: luocheng --- interfaces/kits/napi/src/napi_accessibility_config_observer.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/interfaces/kits/napi/src/napi_accessibility_config_observer.cpp b/interfaces/kits/napi/src/napi_accessibility_config_observer.cpp index d8c48c6b..7503a00a 100644 --- a/interfaces/kits/napi/src/napi_accessibility_config_observer.cpp +++ b/interfaces/kits/napi/src/napi_accessibility_config_observer.cpp @@ -285,7 +285,7 @@ void NAccessibilityConfigObserver::NotifyFloatChanged2JS(float value) return; } work->data = static_cast(callbackInfo); - int ret = NotifyFloatChanged(work); + int ret = NotifyFloatChanged(work); if (ret != 0) { HILOG_ERROR("Failed to execute NotifyFloatChanged2JS work queue"); delete callbackInfo; -- Gitee From 5dee3d63aa7e94a57c9464a0450b81acb08705a5 Mon Sep 17 00:00:00 2001 From: luocheng Date: Thu, 18 May 2023 08:41:04 +0000 Subject: [PATCH 15/17] update interfaces/kits/napi/src/napi_accessibility_config_observer.cpp. Signed-off-by: luocheng --- .../napi_accessibility_config_observer.cpp | 191 +++++++++++++++++- 1 file changed, 184 insertions(+), 7 deletions(-) diff --git a/interfaces/kits/napi/src/napi_accessibility_config_observer.cpp b/interfaces/kits/napi/src/napi_accessibility_config_observer.cpp index 7503a00a..f71ef3f2 100644 --- a/interfaces/kits/napi/src/napi_accessibility_config_observer.cpp +++ b/interfaces/kits/napi/src/napi_accessibility_config_observer.cpp @@ -81,7 +81,7 @@ void NAccessibilityConfigObserver::OnConfigChanged(const ConfigValue &value) } } -int NAccessibilityConfigObserver::NotifyFloatChanged(uv_work_t *work) +int NAccessibilityConfigObserver::NotifyStateChanged(uv_work_t *work) { uv_loop_s *loop = nullptr; napi_get_uv_event_loop(env_, &loop); @@ -112,7 +112,184 @@ int NAccessibilityConfigObserver::NotifyFloatChanged(uv_work_t *work) delete work; work = nullptr; }); - return ret; + return ret; +} + +int NAccessibilityConfigObserver::NotifyPropertyChanged(uv_work_t *work) +{ + uv_loop_s *loop = nullptr; + napi_get_uv_event_loop(env_, &loop); + int ret = uv_queue_work(loop, work, [](uv_work_t *work) {}, + [](uv_work_t *work, int status) { + CaptionCallbackInfo *callbackInfo = static_cast(work->data); + napi_handle_scope scope = nullptr; + napi_open_handle_scope(callbackInfo->env_, &scope); + if (scope == nullptr) { + return; + } + napi_value jsEvent; + napi_create_object(callbackInfo->env_, &jsEvent); + ConvertCaptionPropertyToJS(callbackInfo->env_, jsEvent, callbackInfo->caption_); + + napi_value handler = nullptr; + napi_value callResult = nullptr; + napi_get_reference_value(callbackInfo->env_, callbackInfo->ref_, &handler); + napi_value undefined = nullptr; + napi_get_undefined(callbackInfo->env_, &undefined); + napi_call_function(callbackInfo->env_, undefined, handler, 1, &jsEvent, &callResult); + int32_t result; + napi_get_value_int32(callbackInfo->env_, callResult, &result); + HILOG_INFO("NotifyPropertyChangedJS napi_call_function result[%{public}d]", result); + napi_close_handle_scope(callbackInfo->env_, scope); + delete callbackInfo; + callbackInfo = nullptr; + delete work; + work = nullptr; + }); + return ret; +} + +int NAccessibilityConfigObserver::NotifyStringChanged(uv_work_t *work) +{ + uv_loop_s *loop = nullptr; + napi_get_uv_event_loop(env_, &loop); + int ret = uv_queue_work(loop, work, [](uv_work_t *work) {}, + [](uv_work_t *work, int status) { + StateCallbackInfo *callbackInfo = static_cast(work->data); + napi_handle_scope scope = nullptr; + napi_open_handle_scope(callbackInfo->env_, &scope); + if (scope == nullptr) { + return; + } + napi_value jsEvent; + napi_create_string_utf8(callbackInfo->env_, callbackInfo->stringValue_.c_str(), + callbackInfo->stringValue_.length(), &jsEvent); + napi_value handler = nullptr; + napi_value callResult = nullptr; + napi_get_reference_value(callbackInfo->env_, callbackInfo->ref_, &handler); + napi_value undefined = nullptr; + napi_get_undefined(callbackInfo->env_, &undefined); + napi_call_function(callbackInfo->env_, undefined, handler, 1, &jsEvent, &callResult); + size_t result; + const uint32_t BUF_SIZE = 1024; + char buf[BUF_SIZE] = {0}; + napi_get_value_string_utf8(callbackInfo->env_, callResult, buf, BUF_SIZE, &result); + HILOG_INFO("NotifyStringChanged2JSInner napi_call_function result[%{public}zu]", result); + napi_close_handle_scope(callbackInfo->env_, scope); + delete callbackInfo; + callbackInfo = nullptr; + delete work; + work = nullptr; + }); + return ret; +} + +int NAccessibilityConfigObserver::NotifyIntChanged(uv_work_t *work) +{ + uv_loop_s *loop = nullptr; + napi_get_uv_event_loop(env_, &loop); + int ret = uv_queue_work( + loop, + work, + [](uv_work_t *work) {}, + [](uv_work_t *work, int status) { + StateCallbackInfo *callbackInfo = static_cast(work->data); + napi_handle_scope scope = nullptr; + napi_open_handle_scope(callbackInfo->env_, &scope); + if (scope == nullptr) { + return; + } + napi_value jsEvent; + napi_create_int32(callbackInfo->env_, callbackInfo->int32Value_, &jsEvent); + + napi_value handler = nullptr; + napi_value callResult = nullptr; + napi_get_reference_value(callbackInfo->env_, callbackInfo->ref_, &handler); + napi_value undefined = nullptr; + napi_get_undefined(callbackInfo->env_, &undefined); + napi_call_function(callbackInfo->env_, undefined, handler, 1, &jsEvent, &callResult); + int32_t result; + napi_get_value_int32(callbackInfo->env_, callResult, &result); + HILOG_INFO("NotifyIntChanged2JSInner napi_call_function result[%{public}d]", result); + napi_close_handle_scope(callbackInfo->env_, scope); + delete callbackInfo; + callbackInfo = nullptr; + delete work; + work = nullptr; + }); + return ret; +} + +int NAccessibilityConfigObserver::NotifyUintChanged(uv_work_t *work) +{ + uv_loop_s *loop = nullptr; + napi_get_uv_event_loop(env_, &loop); + int ret = uv_queue_work( + loop, + work, + [](uv_work_t *work) {}, + [](uv_work_t *work, int status) { + StateCallbackInfo *callbackInfo = static_cast(work->data); + napi_handle_scope scope = nullptr; + napi_open_handle_scope(callbackInfo->env_, &scope); + if (scope == nullptr) { + return; + } + napi_value jsEvent; + napi_create_uint32(callbackInfo->env_, callbackInfo->uint32Value_, &jsEvent); + + napi_value handler = nullptr; + napi_value callResult = nullptr; + napi_get_reference_value(callbackInfo->env_, callbackInfo->ref_, &handler); + napi_value undefined = nullptr; + napi_get_undefined(callbackInfo->env_, &undefined); + napi_call_function(callbackInfo->env_, undefined, handler, 1, &jsEvent, &callResult); + uint32_t result; + napi_get_value_uint32(callbackInfo->env_, callResult, &result); + HILOG_INFO("NotifyUintChanged2JSInner napi_call_function result[%{public}d]", result); + napi_close_handle_scope(callbackInfo->env_, scope); + delete callbackInfo; + callbackInfo = nullptr; + delete work; + work = nullptr; + }); + return ret; +} + +int NAccessibilityConfigObserver::NotifyFloatChanged(uv_work_t *work) +{ + uv_loop_s *loop = nullptr; + napi_get_uv_event_loop(env_, &loop); + int ret = uv_queue_work( + loop, + work, + [](uv_work_t *work) {}, + [](uv_work_t *work, int status) { + StateCallbackInfo *callbackInfo = static_cast(work->data); + napi_handle_scope scope = nullptr; + napi_open_handle_scope(callbackInfo->env_, &scope); + if (scope == nullptr) { + return; + } + napi_value jsEvent; + napi_create_double(callbackInfo->env_, double(callbackInfo->floatValue_), &jsEvent); + + napi_value handler = nullptr; + napi_value callResult = nullptr; + napi_get_reference_value(callbackInfo->env_, callbackInfo->ref_, &handler); + napi_value undefined = nullptr; + napi_get_undefined(callbackInfo->env_, &undefined); + napi_call_function(callbackInfo->env_, undefined, handler, 1, &jsEvent, &callResult); + int32_t result; + napi_get_value_int32(callbackInfo->env_, callResult, &result); + HILOG_INFO("NotifyFloatChanged2JSInner napi_call_function result[%{public}d]", result); + napi_close_handle_scope(callbackInfo->env_, scope); + delete callbackInfo; + callbackInfo = nullptr; + delete work; + work = nullptr; + }); + return ret; } void NAccessibilityConfigObserver::NotifyStateChanged2JS(bool enabled) @@ -135,7 +312,7 @@ void NAccessibilityConfigObserver::NotifyStateChanged2JS(bool enabled) return; } work->data = static_cast(callbackInfo); - int ret = NotifyFloatChanged(work); + int ret = NotifyStateChanged(work); if (ret != 0) { HILOG_ERROR("Failed to execute NotifyStateChanged2JS work queue"); delete callbackInfo; @@ -165,7 +342,7 @@ void NAccessibilityConfigObserver::NotifyPropertyChanged2JS(const OHOS::Accessib return; } work->data = static_cast(callbackInfo); - int ret = NotifyFloatChanged(work); + int ret = NotifyPropertyChanged(work); if (ret != 0) { HILOG_ERROR("Failed to execute NotifyPropertyChanged2JS work queue"); delete callbackInfo; @@ -195,7 +372,7 @@ void NAccessibilityConfigObserver::NotifyStringChanged2JS(const std::string& val return; } work->data = static_cast(callbackInfo); - int ret = NotifyFloatChanged(work); + int ret = NotifyStringChanged(work); if (ret != 0) { HILOG_ERROR("Failed to execute NotifyStringChanged2JS work queue"); delete callbackInfo; @@ -225,7 +402,7 @@ void NAccessibilityConfigObserver::NotifyIntChanged2JS(int32_t value) return; } work->data = static_cast(callbackInfo); - int ret = NotifyFloatChanged(work); + int ret = NotifyIntChanged(work); if (ret != 0) { HILOG_ERROR("Failed to execute NotifyIntChanged2JS work queue"); delete callbackInfo; @@ -255,7 +432,7 @@ void NAccessibilityConfigObserver::NotifyUintChanged2JS(uint32_t value) return; } work->data = static_cast(callbackInfo); - int ret = NotifyFloatChanged(work); + int ret = NotifyUintChanged(work); if (ret != 0) { HILOG_ERROR("Failed to execute NotifyUintChanged2JS work queue"); delete callbackInfo; -- Gitee From 9c52c5c32f40af6dfd71877e98a24a5c679a32fd Mon Sep 17 00:00:00 2001 From: luocheng Date: Thu, 18 May 2023 08:42:32 +0000 Subject: [PATCH 16/17] update interfaces/innerkits/acfwk/include/accessibility_config_observer.h. Signed-off-by: luocheng --- .../acfwk/include/accessibility_config_observer.h | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/interfaces/innerkits/acfwk/include/accessibility_config_observer.h b/interfaces/innerkits/acfwk/include/accessibility_config_observer.h index 63808a63..e875f171 100644 --- a/interfaces/innerkits/acfwk/include/accessibility_config_observer.h +++ b/interfaces/innerkits/acfwk/include/accessibility_config_observer.h @@ -32,12 +32,17 @@ public: void OnConfigChanged(const OHOS::AccessibilityConfig::ConfigValue& value); void NotifyStateChanged2JS(bool enabled); + int NotifyStateChanged(uv_work_t *work); void NotifyPropertyChanged2JS(const OHOS::AccessibilityConfig::CaptionProperty &caption); - int NotifyFloatChanged(uv_work_t *work); + int NotifyPropertyChanged(uv_work_t *work); void NotifyStringChanged2JS(const std::string& value); + int NotifyStringChanged(uv_work_t *work); void NotifyIntChanged2JS(int32_t value); + int NotifyIntChanged(uv_work_t *work); void NotifyUintChanged2JS(uint32_t value); + int NotifyUintChanged(uv_work_t *work); void NotifyFloatChanged2JS(float value); + int NotifyFloatChanged(uv_work_t *work); napi_env env_ = nullptr; napi_ref handlerRef_ = nullptr; -- Gitee From fb1b8eeef273b6702274fb3077d969807764f2a5 Mon Sep 17 00:00:00 2001 From: luocheng Date: Thu, 18 May 2023 08:55:05 +0000 Subject: [PATCH 17/17] update interfaces/kits/napi/src/napi_accessibility_config_observer.cpp. Signed-off-by: luocheng --- .../napi/src/napi_accessibility_config_observer.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/interfaces/kits/napi/src/napi_accessibility_config_observer.cpp b/interfaces/kits/napi/src/napi_accessibility_config_observer.cpp index f71ef3f2..9dc6d3ac 100644 --- a/interfaces/kits/napi/src/napi_accessibility_config_observer.cpp +++ b/interfaces/kits/napi/src/napi_accessibility_config_observer.cpp @@ -112,7 +112,7 @@ int NAccessibilityConfigObserver::NotifyStateChanged(uv_work_t *work) delete work; work = nullptr; }); - return ret; + return ret; } int NAccessibilityConfigObserver::NotifyPropertyChanged(uv_work_t *work) @@ -146,7 +146,7 @@ int NAccessibilityConfigObserver::NotifyPropertyChanged(uv_work_t *work) delete work; work = nullptr; }); - return ret; + return ret; } int NAccessibilityConfigObserver::NotifyStringChanged(uv_work_t *work) @@ -181,7 +181,7 @@ int NAccessibilityConfigObserver::NotifyStringChanged(uv_work_t *work) delete work; work = nullptr; }); - return ret; + return ret; } int NAccessibilityConfigObserver::NotifyIntChanged(uv_work_t *work) @@ -217,7 +217,7 @@ int NAccessibilityConfigObserver::NotifyIntChanged(uv_work_t *work) delete work; work = nullptr; }); - return ret; + return ret; } int NAccessibilityConfigObserver::NotifyUintChanged(uv_work_t *work) @@ -253,7 +253,7 @@ int NAccessibilityConfigObserver::NotifyUintChanged(uv_work_t *work) delete work; work = nullptr; }); - return ret; + return ret; } int NAccessibilityConfigObserver::NotifyFloatChanged(uv_work_t *work) @@ -289,7 +289,7 @@ int NAccessibilityConfigObserver::NotifyFloatChanged(uv_work_t *work) delete work; work = nullptr; }); - return ret; + return ret; } void NAccessibilityConfigObserver::NotifyStateChanged2JS(bool enabled) -- Gitee