From 0bb1cc473c005a07b7f6c60606789a3f1377c376 Mon Sep 17 00:00:00 2001 From: "yupeng74@huawei.com" Date: Sat, 22 Oct 2022 18:26:52 +0800 Subject: [PATCH] =?UTF-8?q?=E7=89=88=E6=9C=AC=E5=85=BC=E5=AE=B9bugfix?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: yupeng74@huawei.com --- frameworks/src/bundle_state_common.cpp | 19 +++++++++++++------ frameworks/src/bundle_state_query.cpp | 6 ++++-- frameworks/src/bundle_state_query_napi.cpp | 6 ++++-- .../napi/include/bundle_state_common.h | 2 +- 4 files changed, 22 insertions(+), 11 deletions(-) diff --git a/frameworks/src/bundle_state_common.cpp b/frameworks/src/bundle_state_common.cpp index 12a2292..5c486ca 100644 --- a/frameworks/src/bundle_state_common.cpp +++ b/frameworks/src/bundle_state_common.cpp @@ -102,7 +102,7 @@ void BundleStateCommon::SetCallbackInfo( } void BundleStateCommon::GetBundleActiveEventForResult( - napi_env env, const std::vector &bundleActiveStates, napi_value result) + napi_env env, const std::vector &bundleActiveStates, napi_value result, bool isNewVersion) { int32_t index = 0; for (const auto &item : bundleActiveStates) { @@ -116,12 +116,19 @@ void BundleStateCommon::GetBundleActiveEventForResult( napi_value eventId = nullptr; NAPI_CALL_RETURN_VOID(env, napi_create_int32(env, item.eventId_, &eventId)); - NAPI_CALL_RETURN_VOID(env, napi_set_named_property(env, bundleActiveState, "eventId", eventId)); napi_value eventOccurredTime = nullptr; NAPI_CALL_RETURN_VOID(env, napi_create_int64(env, item.timeStamp_, &eventOccurredTime)); - NAPI_CALL_RETURN_VOID(env, napi_set_named_property(env, bundleActiveState, "eventOccurredTime", - eventOccurredTime)); + + if (isNewVersion) { + NAPI_CALL_RETURN_VOID(env, napi_set_named_property(env, bundleActiveState, "eventId", eventId)); + NAPI_CALL_RETURN_VOID(env, napi_set_named_property(env, bundleActiveState, "eventOccurredTime", + eventOccurredTime)); + } else { + NAPI_CALL_RETURN_VOID(env, napi_set_named_property(env, bundleActiveState, "stateType", eventId)); + NAPI_CALL_RETURN_VOID(env, napi_set_named_property(env, bundleActiveState, "stateOccurredTime", + eventOccurredTime)); + } NAPI_CALL_RETURN_VOID(env, napi_set_element(env, result, index, bundleActiveState)); index++; @@ -359,8 +366,8 @@ napi_value BundleStateCommon::GetErrorValue(napi_env env, int32_t errCode) NAPI_CALL(env, napi_create_int32(env, reflectCode, &eCode)); NAPI_CALL(env, napi_create_string_utf8(env, errMsg.c_str(), errMsg.length(), &eMsg)); NAPI_CALL(env, napi_create_object(env, &result)); - NAPI_CALL(env, napi_set_named_property(env, result, "errCode", eCode)); - NAPI_CALL(env, napi_set_named_property(env, result, "errMessage", eMsg)); + NAPI_CALL(env, napi_set_named_property(env, result, "code", eCode)); + NAPI_CALL(env, napi_set_named_property(env, result, "message", eMsg)); return result; } diff --git a/frameworks/src/bundle_state_query.cpp b/frameworks/src/bundle_state_query.cpp index 3506569..4e119aa 100644 --- a/frameworks/src/bundle_state_query.cpp +++ b/frameworks/src/bundle_state_query.cpp @@ -317,7 +317,8 @@ napi_value QueryCurrentBundleActiveStates(napi_env env, napi_callback_info info) if (asyncCallbackInfo != nullptr) { napi_value result = nullptr; napi_create_array(env, &result); - BundleStateCommon::GetBundleActiveEventForResult(env, asyncCallbackInfo->BundleActiveState, result); + BundleStateCommon::GetBundleActiveEventForResult( + env, asyncCallbackInfo->BundleActiveState, result, false); BundleStateCommon::GetCallbackPromiseResult(env, *asyncCallbackInfo, result); } }, @@ -383,7 +384,8 @@ napi_value QueryBundleActiveStates(napi_env env, napi_callback_info info) if (asyncCallbackInfo != nullptr) { napi_value result = nullptr; napi_create_array(env, &result); - BundleStateCommon::GetBundleActiveEventForResult(env, asyncCallbackInfo->BundleActiveState, result); + BundleStateCommon::GetBundleActiveEventForResult( + env, asyncCallbackInfo->BundleActiveState, result, false); BundleStateCommon::GetCallbackPromiseResult(env, *asyncCallbackInfo, result); } }, diff --git a/frameworks/src/bundle_state_query_napi.cpp b/frameworks/src/bundle_state_query_napi.cpp index 9847228..cb7c1f5 100644 --- a/frameworks/src/bundle_state_query_napi.cpp +++ b/frameworks/src/bundle_state_query_napi.cpp @@ -331,7 +331,8 @@ napi_value QueryCurrentBundleEvents(napi_env env, napi_callback_info info) if (asyncCallbackInfo != nullptr) { napi_value result = nullptr; napi_create_array(env, &result); - BundleStateCommon::GetBundleActiveEventForResult(env, asyncCallbackInfo->BundleActiveState, result); + BundleStateCommon::GetBundleActiveEventForResult( + env, asyncCallbackInfo->BundleActiveState, result, true); BundleStateCommon::GetCallbackPromiseResult(env, *asyncCallbackInfo, result); } }, @@ -386,7 +387,8 @@ napi_value QueryBundleEvents(napi_env env, napi_callback_info info) if (asyncCallbackInfo != nullptr) { napi_value result = nullptr; napi_create_array(env, &result); - BundleStateCommon::GetBundleActiveEventForResult(env, asyncCallbackInfo->BundleActiveState, result); + BundleStateCommon::GetBundleActiveEventForResult( + env, asyncCallbackInfo->BundleActiveState, result, true); BundleStateCommon::GetCallbackPromiseResult(env, *asyncCallbackInfo, result); } }, diff --git a/interfaces/kits/bundlestats/napi/include/bundle_state_common.h b/interfaces/kits/bundlestats/napi/include/bundle_state_common.h index ab56949..56db22b 100644 --- a/interfaces/kits/bundlestats/napi/include/bundle_state_common.h +++ b/interfaces/kits/bundlestats/napi/include/bundle_state_common.h @@ -51,7 +51,7 @@ public: const napi_env &env, const napi_ref &callbackIn, const int32_t &errorCode, const napi_value &result); static void GetBundleActiveEventForResult( - napi_env env, const std::vector &BundleActiveState, napi_value result); + napi_env env, const std::vector &BundleActiveState, napi_value result, bool isNewVersion); static void GetBundleStateInfoByIntervalForResult( napi_env env, const std::vector &packageStats, napi_value result); -- Gitee