diff --git a/frameworks/src/bundle_state_common.cpp b/frameworks/src/bundle_state_common.cpp index 12a229201fcaa5175cee9e4cee6ffb587b0c0c32..5c486ca185e80e46d6583f2e8a7eab2308c19ccf 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 3506569558e11d6952d58bfe22a1793649c798ff..4e119aace3ed04015a5429f48c36ddd12ead52b9 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 9847228032634f460311a6992fdb0622dcc778f0..cb7c1f548f3b5dd126153fdf9fda05b9f77b44a9 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 ab56949e1d5e0204e9899e727559292d2d6e6761..56db22bd57b2807d0f118d9645d54fd8f5cfe2c9 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);