From 99f3bba4646e220e1550c3e952ebae591208d3e0 Mon Sep 17 00:00:00 2001 From: fengyang Date: Thu, 10 Apr 2025 15:35:35 +0800 Subject: [PATCH 1/5] =?UTF-8?q?=E5=91=8A=E8=AD=A6=E6=B8=85=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: fengyang --- frameworks/src/app_group_observer_napi.cpp | 7 +++++-- .../src/bundle_active_app_group_napi.cpp | 10 ++++++++- frameworks/src/bundle_state_query_napi.cpp | 21 +++++++++++++++++++ .../src/bundle_active_module_record.cpp | 1 + .../common/include/bundle_active_constant.h | 1 + .../src/bundle_active_usage_database.cpp | 6 +++++- 6 files changed, 42 insertions(+), 4 deletions(-) diff --git a/frameworks/src/app_group_observer_napi.cpp b/frameworks/src/app_group_observer_napi.cpp index a722582..2a7f231 100644 --- a/frameworks/src/app_group_observer_napi.cpp +++ b/frameworks/src/app_group_observer_napi.cpp @@ -116,8 +116,11 @@ void UvQueueWorkOnAppGroupChanged(uv_work_t *work) napi_value results[ARGS_ONE] = {nullptr}; results[PARAM_FIRST] = result; - NAPI_CALL_RETURN_VOID(callbackReceiveDataWorkerData->env, napi_call_function(callbackReceiveDataWorkerData->env, - undefined, callback, ARGS_ONE, &results[PARAM_FIRST], &resultout)); + napi_status status = napi_call_function(callbackReceiveDataWorkerData->env, + undefined, callback, ARGS_ONE, &results[PARAM_FIRST], &resultout); + if (status != napi_ok) { + GET_AND_THROW_LAST_ERROR(callbackReceiveDataWorkerData->env); + } napi_close_handle_scope(callbackReceiveDataWorkerData->env, scope); delete callbackReceiveDataWorkerData; diff --git a/frameworks/src/bundle_active_app_group_napi.cpp b/frameworks/src/bundle_active_app_group_napi.cpp index 5b16dbb..9405a14 100644 --- a/frameworks/src/bundle_active_app_group_napi.cpp +++ b/frameworks/src/bundle_active_app_group_napi.cpp @@ -140,6 +140,9 @@ napi_value QueryAppGroup(napi_env env, napi_callback_info info) AsyncQueryAppGroupCallbackInfo *asyncCallbackInfo = nullptr; ParseQueryAppGroupParameters(env, info, params, asyncCallbackInfo); if (params.errorCode != ERR_OK && !asyncCallbackInfo) { + if (params.callback != nullptr) { + napi_delete_reference(params.callback); + } return BundleStateCommon::NapiGetNull(env); } std::unique_ptr callbackPtr {asyncCallbackInfo}; @@ -314,6 +317,9 @@ napi_value SetAppGroup(napi_env env, napi_callback_info info) AsyncCallbackInfoSetAppGroup *asyncCallbackInfo = nullptr; ParseSetAppGroupParameters(env, info, params, asyncCallbackInfo); if (params.errorCode != ERR_OK && !asyncCallbackInfo) { + if (params.callback != nullptr) { + napi_delete_reference(params.callback); + } return BundleStateCommon::NapiGetNull(env); } std::unique_ptr callbackPtr {asyncCallbackInfo}; @@ -422,7 +428,9 @@ napi_value RegisterAppGroupCallBack(napi_env env, napi_callback_info info) AsyncRegisterCallbackInfo *asyncCallbackInfo = nullptr; ParseRegisterAppGroupCallBackParameters(env, info, params, asyncCallbackInfo); if (params.errorCode != ERR_OK && !asyncCallbackInfo) { - // return BundleStateCommon::JSParaError(env, params.callback, params.errorCode); + if (params.callback != nullptr) { + napi_delete_reference(params.callback); + } return BundleStateCommon::NapiGetNull(env); } std::unique_ptr callbackPtr {asyncCallbackInfo}; diff --git a/frameworks/src/bundle_state_query_napi.cpp b/frameworks/src/bundle_state_query_napi.cpp index a4935d2..fd4299b 100644 --- a/frameworks/src/bundle_state_query_napi.cpp +++ b/frameworks/src/bundle_state_query_napi.cpp @@ -134,6 +134,9 @@ napi_value QueryModuleUsageRecords(napi_env env, napi_callback_info info) AsyncCallbackInfoModuleRecord *asyncCallbackInfo = nullptr; ParseQueryModuleUsageRecords(env, info, params, asyncCallbackInfo); if (params.errorCode != ERR_OK) { + if (params.callback != nullptr) { + napi_delete_reference(params.callback); + } return BundleStateCommon::NapiGetNull(env); } napi_value promise = nullptr; @@ -225,6 +228,9 @@ napi_value IsIdleState(napi_env env, napi_callback_info info) AsyncCallbackInfoIsIdleState *asyncCallbackInfo = nullptr; ParseIsIdleStateParameters(env, info, params, asyncCallbackInfo); if (params.errorCode != ERR_OK && !asyncCallbackInfo) { + if (params.callback != nullptr) { + napi_delete_reference(params.callback); + } return BundleStateCommon::NapiGetNull(env); } napi_value promise = nullptr; @@ -368,6 +374,9 @@ napi_value QueryCurrentBundleEvents(napi_env env, napi_callback_info info) AsyncCallbackInfoStates *asyncCallbackInfo = nullptr; ParseQueryCurrentBundleEventsParameters(env, info, params, asyncCallbackInfo); if (params.errorCode != ERR_OK && !asyncCallbackInfo) { + if (params.callback != nullptr) { + napi_delete_reference(params.callback); + } return BundleStateCommon::NapiGetNull(env); } napi_value promise = nullptr; @@ -424,6 +433,9 @@ napi_value QueryBundleEvents(napi_env env, napi_callback_info info) AsyncCallbackInfoStates *asyncCallbackInfo = nullptr; ParseQueryCurrentBundleEventsParameters(env, info, params, asyncCallbackInfo); if (params.errorCode != ERR_OK && !asyncCallbackInfo) { + if (params.callback != nullptr) { + napi_delete_reference(params.callback); + } return BundleStateCommon::NapiGetNull(env); } napi_value promise = nullptr; @@ -552,6 +564,9 @@ napi_value QueryBundleStatsInfoByInterval(napi_env env, napi_callback_info info) AsyncCallbackInfoAppUsageByInterval *asyncCallbackInfo = nullptr; ParseQueryBundleStatsInfoByInterval(env, info, params, asyncCallbackInfo); if (params.errorCode != ERR_OK && !asyncCallbackInfo) { + if (params.callback != nullptr) { + napi_delete_reference(params.callback); + } return BundleStateCommon::NapiGetNull(env); } napi_value promise = nullptr; @@ -649,6 +664,9 @@ napi_value QueryBundleStatsInfos(napi_env env, napi_callback_info info) AsyncCallbackInfoAppUsage *asyncCallbackInfo = nullptr; ParseQueryBundleStatsInfos(env, info, params, asyncCallbackInfo); if (params.errorCode != ERR_OK && !asyncCallbackInfo) { + if (params.callback != nullptr) { + napi_delete_reference(params.callback); + } return BundleStateCommon::NapiGetNull(env); } napi_value promise = nullptr; @@ -748,6 +766,9 @@ napi_value QueryAppStatsInfos(napi_env env, napi_callback_info info) AsyncCallbackInfoAppStats *asyncCallbackInfo = nullptr; ParseAppStatsInfos(env, info, params, asyncCallbackInfo); if (params.errorCode != ERR_OK && !asyncCallbackInfo) { + if (params.callback != nullptr) { + napi_delete_reference(params.callback); + } return BundleStateCommon::NapiGetNull(env); } napi_value promise = nullptr; diff --git a/interfaces/innerkits/src/bundle_active_module_record.cpp b/interfaces/innerkits/src/bundle_active_module_record.cpp index 5326560..b4e6051 100644 --- a/interfaces/innerkits/src/bundle_active_module_record.cpp +++ b/interfaces/innerkits/src/bundle_active_module_record.cpp @@ -117,6 +117,7 @@ BundleActiveModuleRecord *BundleActiveModuleRecord::Unmarshalling(Parcel &parcel uint32_t size = parcel.ReadUint32(); result->uid_ = parcel.ReadInt32(); if (size > MAX_FORM_NUM) { + delete result; return nullptr; } diff --git a/services/common/include/bundle_active_constant.h b/services/common/include/bundle_active_constant.h index be48f45..f4ee663 100644 --- a/services/common/include/bundle_active_constant.h +++ b/services/common/include/bundle_active_constant.h @@ -78,6 +78,7 @@ const int32_t FORM_LAST_TIME_COLUMN_INDEX = 7; const int32_t FORM_UID_COLUMN_INDEX = 8; const int32_t QUERY_CONDITION_VALID = 0; const int32_t QUERY_CONDITION_INVALID = -1; +const uint32_t BUNDLE_ACTIVE_DB_NAME_MAX_LENGTH = 100; const int64_t TWO_SECONDS = 2 * 1000LL; const int64_t THIRTY_MINUTE = 30 * 60 * 1000LL; const int64_t SIX_DAY_IN_MILLIS_MAX_DEBUG = 6 * 1 * 10 * 60 * 1000LL; diff --git a/services/common/src/bundle_active_usage_database.cpp b/services/common/src/bundle_active_usage_database.cpp index 52842ee..cf03ac8 100644 --- a/services/common/src/bundle_active_usage_database.cpp +++ b/services/common/src/bundle_active_usage_database.cpp @@ -424,6 +424,10 @@ int64_t BundleActiveUsageDatabase::ParseStartTime(const string &tableName) return invalidStartTime; } string tableTime = tableName; + if (tableTime.length() > BUNDLE_ACTIVE_DB_NAME_MAX_LENGTH) { + int64_t invalidStartTime(BUNDLE_ACTIVE_FAIL); + return invalidStartTime; + } for (uint32_t i = 0; i < tableTime.length(); i++) { if (tableTime[i] >= '0' && tableTime[i] <= '9') { tableTime = tableTime.substr(i); @@ -1377,7 +1381,7 @@ void BundleActiveUsageDatabase::UpdateBundleUsageData(int32_t databaseType, Bund int32_t bundleStatsSize = 0; vector bundleActivePackageStats = QueryDatabaseUsageStats(databaseType, 0, MAX_END_TIME, stats.userId_, ""); - for (int32_t i = 0; i < bundleActivePackageStats.size(); i++) { + for (uint32_t i = 0; i < bundleActivePackageStats.size(); i++) { std::map>::iterator iter = stats.bundleStats_.find(bundleActivePackageStats[i].bundleName_ + to_string( bundleActivePackageStats[i].uid_)); -- Gitee From b7ecd5a659b9d578a825801fd63c21187794e51a Mon Sep 17 00:00:00 2001 From: fengyang Date: Thu, 10 Apr 2025 20:07:14 +0800 Subject: [PATCH 2/5] =?UTF-8?q?=E5=91=8A=E8=AD=A6=E6=B8=85=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: fengyang --- frameworks/src/bundle_active_app_group_napi.cpp | 6 +++--- frameworks/src/bundle_state_query_napi.cpp | 14 +++++++------- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/frameworks/src/bundle_active_app_group_napi.cpp b/frameworks/src/bundle_active_app_group_napi.cpp index 9405a14..6fda8bc 100644 --- a/frameworks/src/bundle_active_app_group_napi.cpp +++ b/frameworks/src/bundle_active_app_group_napi.cpp @@ -141,7 +141,7 @@ napi_value QueryAppGroup(napi_env env, napi_callback_info info) ParseQueryAppGroupParameters(env, info, params, asyncCallbackInfo); if (params.errorCode != ERR_OK && !asyncCallbackInfo) { if (params.callback != nullptr) { - napi_delete_reference(params.callback); + napi_delete_reference(env, params.callback); } return BundleStateCommon::NapiGetNull(env); } @@ -318,7 +318,7 @@ napi_value SetAppGroup(napi_env env, napi_callback_info info) ParseSetAppGroupParameters(env, info, params, asyncCallbackInfo); if (params.errorCode != ERR_OK && !asyncCallbackInfo) { if (params.callback != nullptr) { - napi_delete_reference(params.callback); + napi_delete_reference(env, params.callback); } return BundleStateCommon::NapiGetNull(env); } @@ -429,7 +429,7 @@ napi_value RegisterAppGroupCallBack(napi_env env, napi_callback_info info) ParseRegisterAppGroupCallBackParameters(env, info, params, asyncCallbackInfo); if (params.errorCode != ERR_OK && !asyncCallbackInfo) { if (params.callback != nullptr) { - napi_delete_reference(params.callback); + napi_delete_reference(env, params.callback); } return BundleStateCommon::NapiGetNull(env); } diff --git a/frameworks/src/bundle_state_query_napi.cpp b/frameworks/src/bundle_state_query_napi.cpp index fd4299b..770286d 100644 --- a/frameworks/src/bundle_state_query_napi.cpp +++ b/frameworks/src/bundle_state_query_napi.cpp @@ -135,7 +135,7 @@ napi_value QueryModuleUsageRecords(napi_env env, napi_callback_info info) ParseQueryModuleUsageRecords(env, info, params, asyncCallbackInfo); if (params.errorCode != ERR_OK) { if (params.callback != nullptr) { - napi_delete_reference(params.callback); + napi_delete_reference(env, params.callback); } return BundleStateCommon::NapiGetNull(env); } @@ -229,7 +229,7 @@ napi_value IsIdleState(napi_env env, napi_callback_info info) ParseIsIdleStateParameters(env, info, params, asyncCallbackInfo); if (params.errorCode != ERR_OK && !asyncCallbackInfo) { if (params.callback != nullptr) { - napi_delete_reference(params.callback); + napi_delete_reference(env, params.callback); } return BundleStateCommon::NapiGetNull(env); } @@ -375,7 +375,7 @@ napi_value QueryCurrentBundleEvents(napi_env env, napi_callback_info info) ParseQueryCurrentBundleEventsParameters(env, info, params, asyncCallbackInfo); if (params.errorCode != ERR_OK && !asyncCallbackInfo) { if (params.callback != nullptr) { - napi_delete_reference(params.callback); + napi_delete_reference(env, params.callback); } return BundleStateCommon::NapiGetNull(env); } @@ -434,7 +434,7 @@ napi_value QueryBundleEvents(napi_env env, napi_callback_info info) ParseQueryCurrentBundleEventsParameters(env, info, params, asyncCallbackInfo); if (params.errorCode != ERR_OK && !asyncCallbackInfo) { if (params.callback != nullptr) { - napi_delete_reference(params.callback); + napi_delete_reference(env, params.callback); } return BundleStateCommon::NapiGetNull(env); } @@ -565,7 +565,7 @@ napi_value QueryBundleStatsInfoByInterval(napi_env env, napi_callback_info info) ParseQueryBundleStatsInfoByInterval(env, info, params, asyncCallbackInfo); if (params.errorCode != ERR_OK && !asyncCallbackInfo) { if (params.callback != nullptr) { - napi_delete_reference(params.callback); + napi_delete_reference(env, params.callback); } return BundleStateCommon::NapiGetNull(env); } @@ -665,7 +665,7 @@ napi_value QueryBundleStatsInfos(napi_env env, napi_callback_info info) ParseQueryBundleStatsInfos(env, info, params, asyncCallbackInfo); if (params.errorCode != ERR_OK && !asyncCallbackInfo) { if (params.callback != nullptr) { - napi_delete_reference(params.callback); + napi_delete_reference(env, params.callback); } return BundleStateCommon::NapiGetNull(env); } @@ -767,7 +767,7 @@ napi_value QueryAppStatsInfos(napi_env env, napi_callback_info info) ParseAppStatsInfos(env, info, params, asyncCallbackInfo); if (params.errorCode != ERR_OK && !asyncCallbackInfo) { if (params.callback != nullptr) { - napi_delete_reference(params.callback); + napi_delete_reference(env, params.callback); } return BundleStateCommon::NapiGetNull(env); } -- Gitee From e1622118165c4f87b77140354582031e73017678 Mon Sep 17 00:00:00 2001 From: fengyang Date: Fri, 11 Apr 2025 10:13:12 +0800 Subject: [PATCH 3/5] =?UTF-8?q?=E5=91=8A=E8=AD=A6=E6=B8=85=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: fengyang --- .../src/bundle_active_app_group_napi.cpp | 12 ++------ frameworks/src/bundle_state_common.cpp | 7 +++++ frameworks/src/bundle_state_query_napi.cpp | 28 +++++-------------- .../napi/include/bundle_state_common.h | 1 + 4 files changed, 18 insertions(+), 30 deletions(-) diff --git a/frameworks/src/bundle_active_app_group_napi.cpp b/frameworks/src/bundle_active_app_group_napi.cpp index 6fda8bc..e10fc80 100644 --- a/frameworks/src/bundle_active_app_group_napi.cpp +++ b/frameworks/src/bundle_active_app_group_napi.cpp @@ -140,9 +140,7 @@ napi_value QueryAppGroup(napi_env env, napi_callback_info info) AsyncQueryAppGroupCallbackInfo *asyncCallbackInfo = nullptr; ParseQueryAppGroupParameters(env, info, params, asyncCallbackInfo); if (params.errorCode != ERR_OK && !asyncCallbackInfo) { - if (params.callback != nullptr) { - napi_delete_reference(env, params.callback); - } + BundleStateCommon::DeleteNapiReference(env, params); return BundleStateCommon::NapiGetNull(env); } std::unique_ptr callbackPtr {asyncCallbackInfo}; @@ -317,9 +315,7 @@ napi_value SetAppGroup(napi_env env, napi_callback_info info) AsyncCallbackInfoSetAppGroup *asyncCallbackInfo = nullptr; ParseSetAppGroupParameters(env, info, params, asyncCallbackInfo); if (params.errorCode != ERR_OK && !asyncCallbackInfo) { - if (params.callback != nullptr) { - napi_delete_reference(env, params.callback); - } + BundleStateCommon::DeleteNapiReference(env, params); return BundleStateCommon::NapiGetNull(env); } std::unique_ptr callbackPtr {asyncCallbackInfo}; @@ -428,9 +424,7 @@ napi_value RegisterAppGroupCallBack(napi_env env, napi_callback_info info) AsyncRegisterCallbackInfo *asyncCallbackInfo = nullptr; ParseRegisterAppGroupCallBackParameters(env, info, params, asyncCallbackInfo); if (params.errorCode != ERR_OK && !asyncCallbackInfo) { - if (params.callback != nullptr) { - napi_delete_reference(env, params.callback); - } + BundleStateCommon::DeleteNapiReference(env, params); return BundleStateCommon::NapiGetNull(env); } std::unique_ptr callbackPtr {asyncCallbackInfo}; diff --git a/frameworks/src/bundle_state_common.cpp b/frameworks/src/bundle_state_common.cpp index 03c240a..93dd589 100644 --- a/frameworks/src/bundle_state_common.cpp +++ b/frameworks/src/bundle_state_common.cpp @@ -733,6 +733,13 @@ std::unique_ptr BundleStateCommon::HandleEventStats (long long)callbackPtr->beginTime, (long long)callbackPtr->endTime); return callbackPtr; } + +void BundleStateCommon::DeleteNapiReference(const napi_env &env, QueryAppGroupParamsInfo ¶ms) +{ + if (params.callback != nullptr) { + napi_delete_reference(env, params.callback); + } +} } // namespace DeviceUsageStats } // namespace OHOS diff --git a/frameworks/src/bundle_state_query_napi.cpp b/frameworks/src/bundle_state_query_napi.cpp index 770286d..f3ff7e8 100644 --- a/frameworks/src/bundle_state_query_napi.cpp +++ b/frameworks/src/bundle_state_query_napi.cpp @@ -134,9 +134,7 @@ napi_value QueryModuleUsageRecords(napi_env env, napi_callback_info info) AsyncCallbackInfoModuleRecord *asyncCallbackInfo = nullptr; ParseQueryModuleUsageRecords(env, info, params, asyncCallbackInfo); if (params.errorCode != ERR_OK) { - if (params.callback != nullptr) { - napi_delete_reference(env, params.callback); - } + BundleStateCommon::DeleteNapiReference(env, params); return BundleStateCommon::NapiGetNull(env); } napi_value promise = nullptr; @@ -228,9 +226,7 @@ napi_value IsIdleState(napi_env env, napi_callback_info info) AsyncCallbackInfoIsIdleState *asyncCallbackInfo = nullptr; ParseIsIdleStateParameters(env, info, params, asyncCallbackInfo); if (params.errorCode != ERR_OK && !asyncCallbackInfo) { - if (params.callback != nullptr) { - napi_delete_reference(env, params.callback); - } + BundleStateCommon::DeleteNapiReference(env, params); return BundleStateCommon::NapiGetNull(env); } napi_value promise = nullptr; @@ -374,9 +370,7 @@ napi_value QueryCurrentBundleEvents(napi_env env, napi_callback_info info) AsyncCallbackInfoStates *asyncCallbackInfo = nullptr; ParseQueryCurrentBundleEventsParameters(env, info, params, asyncCallbackInfo); if (params.errorCode != ERR_OK && !asyncCallbackInfo) { - if (params.callback != nullptr) { - napi_delete_reference(env, params.callback); - } + BundleStateCommon::DeleteNapiReference(env, params); return BundleStateCommon::NapiGetNull(env); } napi_value promise = nullptr; @@ -433,9 +427,7 @@ napi_value QueryBundleEvents(napi_env env, napi_callback_info info) AsyncCallbackInfoStates *asyncCallbackInfo = nullptr; ParseQueryCurrentBundleEventsParameters(env, info, params, asyncCallbackInfo); if (params.errorCode != ERR_OK && !asyncCallbackInfo) { - if (params.callback != nullptr) { - napi_delete_reference(env, params.callback); - } + BundleStateCommon::DeleteNapiReference(env, params); return BundleStateCommon::NapiGetNull(env); } napi_value promise = nullptr; @@ -564,9 +556,7 @@ napi_value QueryBundleStatsInfoByInterval(napi_env env, napi_callback_info info) AsyncCallbackInfoAppUsageByInterval *asyncCallbackInfo = nullptr; ParseQueryBundleStatsInfoByInterval(env, info, params, asyncCallbackInfo); if (params.errorCode != ERR_OK && !asyncCallbackInfo) { - if (params.callback != nullptr) { - napi_delete_reference(env, params.callback); - } + BundleStateCommon::DeleteNapiReference(env, params); return BundleStateCommon::NapiGetNull(env); } napi_value promise = nullptr; @@ -664,9 +654,7 @@ napi_value QueryBundleStatsInfos(napi_env env, napi_callback_info info) AsyncCallbackInfoAppUsage *asyncCallbackInfo = nullptr; ParseQueryBundleStatsInfos(env, info, params, asyncCallbackInfo); if (params.errorCode != ERR_OK && !asyncCallbackInfo) { - if (params.callback != nullptr) { - napi_delete_reference(env, params.callback); - } + BundleStateCommon::DeleteNapiReference(env, params); return BundleStateCommon::NapiGetNull(env); } napi_value promise = nullptr; @@ -766,9 +754,7 @@ napi_value QueryAppStatsInfos(napi_env env, napi_callback_info info) AsyncCallbackInfoAppStats *asyncCallbackInfo = nullptr; ParseAppStatsInfos(env, info, params, asyncCallbackInfo); if (params.errorCode != ERR_OK && !asyncCallbackInfo) { - if (params.callback != nullptr) { - napi_delete_reference(env, params.callback); - } + BundleStateCommon::DeleteNapiReference(env, params); return BundleStateCommon::NapiGetNull(env); } napi_value promise = nullptr; diff --git a/interfaces/kits/bundlestats/napi/include/bundle_state_common.h b/interfaces/kits/bundlestats/napi/include/bundle_state_common.h index cd106c5..79b724c 100644 --- a/interfaces/kits/bundlestats/napi/include/bundle_state_common.h +++ b/interfaces/kits/bundlestats/napi/include/bundle_state_common.h @@ -110,6 +110,7 @@ public: template static void AsyncInit(napi_env env, PARAMT ¶ms, ASYNCT* &asyncCallbackInfo); + static void DeleteNapiReference(const napi_env &env, QueryAppGroupParamsInfo ¶ms); }; template -- Gitee From 157fee495bce2a3105716c5667deca5c2558460e Mon Sep 17 00:00:00 2001 From: fengyang Date: Fri, 11 Apr 2025 10:47:51 +0800 Subject: [PATCH 4/5] =?UTF-8?q?=E5=91=8A=E8=AD=A6=E6=B8=85=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: fengyang --- frameworks/src/bundle_state_common.cpp | 3 ++- interfaces/kits/bundlestats/napi/include/bundle_state_common.h | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/frameworks/src/bundle_state_common.cpp b/frameworks/src/bundle_state_common.cpp index 93dd589..6ed4a4c 100644 --- a/frameworks/src/bundle_state_common.cpp +++ b/frameworks/src/bundle_state_common.cpp @@ -734,7 +734,8 @@ std::unique_ptr BundleStateCommon::HandleEventStats return callbackPtr; } -void BundleStateCommon::DeleteNapiReference(const napi_env &env, QueryAppGroupParamsInfo ¶ms) +template +void BundleStateCommon::DeleteNapiReference(const napi_env &env, T ¶ms) { if (params.callback != nullptr) { napi_delete_reference(env, params.callback); diff --git a/interfaces/kits/bundlestats/napi/include/bundle_state_common.h b/interfaces/kits/bundlestats/napi/include/bundle_state_common.h index 79b724c..1d8ab6d 100644 --- a/interfaces/kits/bundlestats/napi/include/bundle_state_common.h +++ b/interfaces/kits/bundlestats/napi/include/bundle_state_common.h @@ -110,7 +110,8 @@ public: template static void AsyncInit(napi_env env, PARAMT ¶ms, ASYNCT* &asyncCallbackInfo); - static void DeleteNapiReference(const napi_env &env, QueryAppGroupParamsInfo ¶ms); + template + static void DeleteNapiReference(const napi_env &env, T ¶ms); }; template -- Gitee From 1fc835a20d4b6b4d4062dc4f05345f2432d7c541 Mon Sep 17 00:00:00 2001 From: fengyang Date: Fri, 11 Apr 2025 11:08:41 +0800 Subject: [PATCH 5/5] =?UTF-8?q?=E5=91=8A=E8=AD=A6=E6=B8=85=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: fengyang --- frameworks/src/bundle_active_app_group_napi.cpp | 6 +++--- frameworks/src/bundle_state_common.cpp | 7 +++---- frameworks/src/bundle_state_query_napi.cpp | 14 +++++++------- .../bundlestats/napi/include/bundle_state_common.h | 3 +-- 4 files changed, 14 insertions(+), 16 deletions(-) diff --git a/frameworks/src/bundle_active_app_group_napi.cpp b/frameworks/src/bundle_active_app_group_napi.cpp index e10fc80..620b936 100644 --- a/frameworks/src/bundle_active_app_group_napi.cpp +++ b/frameworks/src/bundle_active_app_group_napi.cpp @@ -140,7 +140,7 @@ napi_value QueryAppGroup(napi_env env, napi_callback_info info) AsyncQueryAppGroupCallbackInfo *asyncCallbackInfo = nullptr; ParseQueryAppGroupParameters(env, info, params, asyncCallbackInfo); if (params.errorCode != ERR_OK && !asyncCallbackInfo) { - BundleStateCommon::DeleteNapiReference(env, params); + BundleStateCommon::DeleteNapiReference(env, params.callback); return BundleStateCommon::NapiGetNull(env); } std::unique_ptr callbackPtr {asyncCallbackInfo}; @@ -315,7 +315,7 @@ napi_value SetAppGroup(napi_env env, napi_callback_info info) AsyncCallbackInfoSetAppGroup *asyncCallbackInfo = nullptr; ParseSetAppGroupParameters(env, info, params, asyncCallbackInfo); if (params.errorCode != ERR_OK && !asyncCallbackInfo) { - BundleStateCommon::DeleteNapiReference(env, params); + BundleStateCommon::DeleteNapiReference(env, params.callback); return BundleStateCommon::NapiGetNull(env); } std::unique_ptr callbackPtr {asyncCallbackInfo}; @@ -424,7 +424,7 @@ napi_value RegisterAppGroupCallBack(napi_env env, napi_callback_info info) AsyncRegisterCallbackInfo *asyncCallbackInfo = nullptr; ParseRegisterAppGroupCallBackParameters(env, info, params, asyncCallbackInfo); if (params.errorCode != ERR_OK && !asyncCallbackInfo) { - BundleStateCommon::DeleteNapiReference(env, params); + BundleStateCommon::DeleteNapiReference(env, params.callback); return BundleStateCommon::NapiGetNull(env); } std::unique_ptr callbackPtr {asyncCallbackInfo}; diff --git a/frameworks/src/bundle_state_common.cpp b/frameworks/src/bundle_state_common.cpp index 6ed4a4c..d69dacd 100644 --- a/frameworks/src/bundle_state_common.cpp +++ b/frameworks/src/bundle_state_common.cpp @@ -734,11 +734,10 @@ std::unique_ptr BundleStateCommon::HandleEventStats return callbackPtr; } -template -void BundleStateCommon::DeleteNapiReference(const napi_env &env, T ¶ms) +void BundleStateCommon::DeleteNapiReference(napi_env &env, napi_ref ref) { - if (params.callback != nullptr) { - napi_delete_reference(env, params.callback); + if (ref != nullptr) { + napi_delete_reference(env, ref); } } } // namespace DeviceUsageStats diff --git a/frameworks/src/bundle_state_query_napi.cpp b/frameworks/src/bundle_state_query_napi.cpp index f3ff7e8..434a099 100644 --- a/frameworks/src/bundle_state_query_napi.cpp +++ b/frameworks/src/bundle_state_query_napi.cpp @@ -134,7 +134,7 @@ napi_value QueryModuleUsageRecords(napi_env env, napi_callback_info info) AsyncCallbackInfoModuleRecord *asyncCallbackInfo = nullptr; ParseQueryModuleUsageRecords(env, info, params, asyncCallbackInfo); if (params.errorCode != ERR_OK) { - BundleStateCommon::DeleteNapiReference(env, params); + BundleStateCommon::DeleteNapiReference(env, params.callback); return BundleStateCommon::NapiGetNull(env); } napi_value promise = nullptr; @@ -226,7 +226,7 @@ napi_value IsIdleState(napi_env env, napi_callback_info info) AsyncCallbackInfoIsIdleState *asyncCallbackInfo = nullptr; ParseIsIdleStateParameters(env, info, params, asyncCallbackInfo); if (params.errorCode != ERR_OK && !asyncCallbackInfo) { - BundleStateCommon::DeleteNapiReference(env, params); + BundleStateCommon::DeleteNapiReference(env, params.callback); return BundleStateCommon::NapiGetNull(env); } napi_value promise = nullptr; @@ -370,7 +370,7 @@ napi_value QueryCurrentBundleEvents(napi_env env, napi_callback_info info) AsyncCallbackInfoStates *asyncCallbackInfo = nullptr; ParseQueryCurrentBundleEventsParameters(env, info, params, asyncCallbackInfo); if (params.errorCode != ERR_OK && !asyncCallbackInfo) { - BundleStateCommon::DeleteNapiReference(env, params); + BundleStateCommon::DeleteNapiReference(env, params.callback); return BundleStateCommon::NapiGetNull(env); } napi_value promise = nullptr; @@ -427,7 +427,7 @@ napi_value QueryBundleEvents(napi_env env, napi_callback_info info) AsyncCallbackInfoStates *asyncCallbackInfo = nullptr; ParseQueryCurrentBundleEventsParameters(env, info, params, asyncCallbackInfo); if (params.errorCode != ERR_OK && !asyncCallbackInfo) { - BundleStateCommon::DeleteNapiReference(env, params); + BundleStateCommon::DeleteNapiReference(env, params.callback); return BundleStateCommon::NapiGetNull(env); } napi_value promise = nullptr; @@ -556,7 +556,7 @@ napi_value QueryBundleStatsInfoByInterval(napi_env env, napi_callback_info info) AsyncCallbackInfoAppUsageByInterval *asyncCallbackInfo = nullptr; ParseQueryBundleStatsInfoByInterval(env, info, params, asyncCallbackInfo); if (params.errorCode != ERR_OK && !asyncCallbackInfo) { - BundleStateCommon::DeleteNapiReference(env, params); + BundleStateCommon::DeleteNapiReference(env, params.callback); return BundleStateCommon::NapiGetNull(env); } napi_value promise = nullptr; @@ -654,7 +654,7 @@ napi_value QueryBundleStatsInfos(napi_env env, napi_callback_info info) AsyncCallbackInfoAppUsage *asyncCallbackInfo = nullptr; ParseQueryBundleStatsInfos(env, info, params, asyncCallbackInfo); if (params.errorCode != ERR_OK && !asyncCallbackInfo) { - BundleStateCommon::DeleteNapiReference(env, params); + BundleStateCommon::DeleteNapiReference(env, params.callback); return BundleStateCommon::NapiGetNull(env); } napi_value promise = nullptr; @@ -754,7 +754,7 @@ napi_value QueryAppStatsInfos(napi_env env, napi_callback_info info) AsyncCallbackInfoAppStats *asyncCallbackInfo = nullptr; ParseAppStatsInfos(env, info, params, asyncCallbackInfo); if (params.errorCode != ERR_OK && !asyncCallbackInfo) { - BundleStateCommon::DeleteNapiReference(env, params); + BundleStateCommon::DeleteNapiReference(env, params.callback); return BundleStateCommon::NapiGetNull(env); } napi_value promise = nullptr; diff --git a/interfaces/kits/bundlestats/napi/include/bundle_state_common.h b/interfaces/kits/bundlestats/napi/include/bundle_state_common.h index 1d8ab6d..df9815d 100644 --- a/interfaces/kits/bundlestats/napi/include/bundle_state_common.h +++ b/interfaces/kits/bundlestats/napi/include/bundle_state_common.h @@ -110,8 +110,7 @@ public: template static void AsyncInit(napi_env env, PARAMT ¶ms, ASYNCT* &asyncCallbackInfo); - template - static void DeleteNapiReference(const napi_env &env, T ¶ms); + static void DeleteNapiReference(napi_env &env, napi_ref ref); }; template -- Gitee