From 49d4970ff4393d5ba6c3af43070dccd014101e78 Mon Sep 17 00:00:00 2001 From: liuzongze Date: Tue, 24 Jun 2025 21:02:19 +0800 Subject: [PATCH] =?UTF-8?q?entry=E9=94=99=E8=AF=AF=E7=A0=81=E8=BF=94?= =?UTF-8?q?=E5=9B=9E=E9=97=AE=E9=A2=98=E4=BF=AE=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: liuzongze Change-Id: Ibc4bb4028c26f168de568a76587d35ef1fbf2185 --- .../js_insight_intent_entry.cpp | 38 ++++++++++++++++++- .../js_insight_intent_entry.h | 4 ++ .../insight_intent_utils_test.cpp | 1 + 3 files changed, 42 insertions(+), 1 deletion(-) diff --git a/frameworks/native/ability/native/insight_intent_executor/js_insight_intent_entry.cpp b/frameworks/native/ability/native/insight_intent_executor/js_insight_intent_entry.cpp index c3e585856b9..4b9f84ba4f0 100644 --- a/frameworks/native/ability/native/insight_intent_executor/js_insight_intent_entry.cpp +++ b/frameworks/native/ability/native/insight_intent_executor/js_insight_intent_entry.cpp @@ -28,6 +28,7 @@ #include "napi_common_util.h" #include "napi_common_want.h" #include "native_reference.h" +#include "string_wrapper.h" #undef STATE_PATTERN_NAIVE_H #define STATE_PATTERN_NAIVE_STATE state_ @@ -213,6 +214,41 @@ void JsInsightIntentEntry::ReplySucceededInner(std::shared_ptr(data); + napi_value resultJs = argv[0]; + if (resultJs == nullptr) { + TAG_LOGE(AAFwkTag::INTENT, "callback invalid"); + JsInsightIntentUtils::ReplyFailed(callback); + return nullptr; + } + + auto resultCpp = GetResultFromJs(env, resultJs); + JsInsightIntentUtils::ReplySucceeded(callback, resultCpp); + return nullptr; +} + +std::shared_ptr JsInsightIntentEntry::GetResultFromJs( + napi_env env, napi_value resultJs) +{ + TAG_LOGD(AAFwkTag::INTENT, "Get result for intent func"); + auto resultCpp = std::make_shared(); + auto resultStr = JsInsightIntentUtils::StringifyObject(env, resultJs); + auto wantParams = std::make_shared(); + wantParams->SetParam("methodResult", AAFwk::String::Box(resultStr)); + resultCpp->result = wantParams; + resultCpp->code = InsightIntentInnerErr::INSIGHT_INTENT_ERR_OK; + return resultCpp; +} + bool JsInsightIntentEntry::HandleResultReturnedFromJsFunc(napi_value resultJs) { TAG_LOGD(AAFwkTag::INTENT, "handle result returned"); @@ -238,7 +274,7 @@ bool JsInsightIntentEntry::HandleResultReturnedFromJsFunc(napi_value resultJs) NAPI_CALL_BASE(env, napi_get_named_property(env, resultJs, "then", &then), ExecuteIntentCheckError()); napi_value resolveCbJs = nullptr; NAPI_CALL_BASE(env, napi_create_function(env, TMP_NAPI_ANONYMOUS_FUNC, strlen(TMP_NAPI_ANONYMOUS_FUNC), - JsInsightIntentUtils::ResolveCbCpp, callback, &resolveCbJs), ExecuteIntentCheckError()); + ResolveCbCpp, callback, &resolveCbJs), ExecuteIntentCheckError()); constexpr size_t argcThen = 1; napi_value argvThen[argcThen] = { resolveCbJs }; NAPI_CALL_BASE(env, napi_call_function(env, resultJs, then, argcThen, argvThen, nullptr), diff --git a/interfaces/kits/native/ability/native/insight_intent_executor/js_insight_intent_entry.h b/interfaces/kits/native/ability/native/insight_intent_executor/js_insight_intent_entry.h index 98762d84697..87721ca89f5 100644 --- a/interfaces/kits/native/ability/native/insight_intent_executor/js_insight_intent_entry.h +++ b/interfaces/kits/native/ability/native/insight_intent_executor/js_insight_intent_entry.h @@ -96,6 +96,10 @@ private: bool PrepareParametersUIExtension(napi_env env, const std::shared_ptr& pageLoader); bool PrepareParametersServiceExtension(napi_env env); + static std::shared_ptr GetResultFromJs(napi_env env, napi_value resultJs); + + static napi_value ResolveCbCpp(napi_env env, napi_callback_info info); + bool AssignObject(napi_env env, const AAFwk::WantParams &wantParams); JsRuntime& runtime_; diff --git a/test/unittest/insight_intent/insight_intent_utils_test/insight_intent_utils_test.cpp b/test/unittest/insight_intent/insight_intent_utils_test/insight_intent_utils_test.cpp index cfb1429e9a7..7f65a1cbaf2 100644 --- a/test/unittest/insight_intent/insight_intent_utils_test/insight_intent_utils_test.cpp +++ b/test/unittest/insight_intent/insight_intent_utils_test/insight_intent_utils_test.cpp @@ -307,6 +307,7 @@ HWTEST_F(InsightIntentUtilsTest, ConvertExtractInsightIntentGenericInfo_0100, Te TEST_INSIGHT_INTENT_GENERIC_INFO.decoratorType = "@InsightIntentLink"; auto result = utils.ConvertExtractInsightIntentGenericInfo(TEST_INSIGHT_INTENT_GENERIC_INFO, insightIntentInfoForQuery); EXPECT_EQ(result, ERR_OK); + EXPECT_EQ(insightIntentInfoForQuery.intentType, "@InsightIntentLink"); Mock::VerifyAndClear(mockBundleMgr); testing::Mock::AllowLeak(mockBundleMgr); TAG_LOGI(AAFwkTag::TEST, "InsightIntentUtilsTest ConvertExtractInsightIntentGenericInfo_0100 end."); -- Gitee