From f9fcd6efd9a452d52d679e160f86765edce2b6c8 Mon Sep 17 00:00:00 2001 From: "yupeng74@huawei.com" Date: Fri, 16 Sep 2022 11:17:04 +0800 Subject: [PATCH] =?UTF-8?q?cppCheck=20=E4=BF=AE=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: yupeng74@huawei.com --- .../src/bundle_active_group_observer.cpp | 4 ++-- frameworks/src/bundle_state_query.cpp | 21 +++++++------------ .../common/include/bundle_active_service.h | 2 +- .../src/bundle_active_app_state_obsever.cpp | 4 ++-- ...bundle_active_continuous_task_observer.cpp | 4 ++-- services/common/src/bundle_active_core.cpp | 8 ++----- services/common/src/bundle_active_service.cpp | 6 ++---- 7 files changed, 19 insertions(+), 30 deletions(-) diff --git a/frameworks/src/bundle_active_group_observer.cpp b/frameworks/src/bundle_active_group_observer.cpp index f1e3d51..59594f2 100644 --- a/frameworks/src/bundle_active_group_observer.cpp +++ b/frameworks/src/bundle_active_group_observer.cpp @@ -171,8 +171,8 @@ void BundleActiveGroupObserver::OnBundleGroupChanged(const BundleActiveGroupCall delete callbackReceiveDataWorker; callbackReceiveDataWorker = nullptr; delete work; - work = nullptr; } + work = nullptr; } napi_value GetBundleGroupChangeCallback(const napi_env &env, const napi_value &value) @@ -213,7 +213,7 @@ napi_value ParseRegisterGroupCallBackParameters(const napi_env &env, const napi_ // argv[1]: asyncCallback if (argc == REGISTER_GROUP_CALLBACK_PARAMS) { - napi_valuetype valuetype = napi_undefined; + valuetype = napi_undefined; NAPI_CALL(env, napi_typeof(env, argv[1], &valuetype)); NAPI_ASSERT(env, valuetype == napi_function, "ParseStatesParameters invalid parameter type. Function expected"); napi_create_reference(env, argv[1], 1, ¶ms.callback); diff --git a/frameworks/src/bundle_state_query.cpp b/frameworks/src/bundle_state_query.cpp index e4984e5..3127127 100644 --- a/frameworks/src/bundle_state_query.cpp +++ b/frameworks/src/bundle_state_query.cpp @@ -180,7 +180,7 @@ napi_value ParseIsIdleStateParameters(const napi_env &env, const napi_callback_i // argv[1]: callback if (argc == IS_IDLE_STATE_PARAMS) { - napi_valuetype valuetype = napi_undefined; + valuetype = napi_undefined; NAPI_CALL(env, napi_typeof(env, argv[1], &valuetype)); NAPI_ASSERT(env, valuetype == napi_function, "ParseIsIdleStateParameters invalid parameter type, function expected."); @@ -260,10 +260,6 @@ napi_value ParsePriorityGroupParameters(const napi_env &env, const napi_callback napi_valuetype valuetype = napi_undefined; NAPI_CALL(env, napi_typeof(env, argv[0], &valuetype)); if (valuetype == napi_function) { - napi_valuetype valuetype = napi_undefined; - NAPI_CALL(env, napi_typeof(env, argv[0], &valuetype)); - NAPI_ASSERT(env, valuetype == napi_function, "ParsePriorityGroupParameters invalid parameter type. " - "Function expected."); napi_create_reference(env, argv[0], 1, ¶ms.callback); } else { params.bundleName = BundleStateCommon::GetTypeStringValue(env, argv[0], result); @@ -279,14 +275,13 @@ napi_value ParsePriorityGroupParameters(const napi_env &env, const napi_callback BUNDLE_ACTIVE_LOGE("ParsePriorityGroupParameters failed, bundleName is empty."); params.errorCode = ERR_USAGE_STATS_BUNDLENAME_EMPTY; } + // argv[1]: callback - if (argc == PRIORITY_GROUP_PARAMS) { - napi_valuetype valuetype = napi_undefined; - NAPI_CALL(env, napi_typeof(env, argv[1], &valuetype)); - NAPI_ASSERT(env, valuetype == napi_function, "ParsePriorityGroupParameters invalid parameter type. " - "Function expected."); - napi_create_reference(env, argv[1], 1, ¶ms.callback); - } + napi_valuetype valuetype = napi_undefined; + NAPI_CALL(env, napi_typeof(env, argv[1], &valuetype)); + NAPI_ASSERT(env, valuetype == napi_function, "ParsePriorityGroupParameters invalid parameter type. " + "Function expected."); + napi_create_reference(env, argv[1], 1, ¶ms.callback); } BundleStateCommon::AsyncInit(env, params, asyncCallbackInfo); return BundleStateCommon::NapiGetNull(env); @@ -799,7 +794,7 @@ napi_value ParseAppUsageBundleGroupInfoParameters(const napi_env &env, const nap } // argv[SECOND_ARG]: callback if (argc == APP_USAGE_PARAMS_BUNDLE_GROUP) { - napi_valuetype valuetype = napi_undefined; + valuetype = napi_undefined; NAPI_CALL(env, napi_typeof(env, argv[SECOND_ARG], &valuetype)); NAPI_ASSERT(env, valuetype == napi_function, "ParseAppUsageBundleGroupInfoParameters invalid parameter type. " "Function expected."); diff --git a/services/common/include/bundle_active_service.h b/services/common/include/bundle_active_service.h index bd49a3f..1e529b1 100644 --- a/services/common/include/bundle_active_service.h +++ b/services/common/include/bundle_active_service.h @@ -166,7 +166,7 @@ private: void InitService(); bool GetBundleMgrProxy(); bool CheckBundleIsSystemAppAndHasPermission(const int32_t uid, OHOS::Security::AccessToken::AccessTokenID tokenId, - int32_t& errCode); + int32_t errCode); void InitAppStateSubscriber(const std::shared_ptr& reportHandler); void InitContinuousSubscriber(const std::shared_ptr& reportHandler); bool SubscribeAppState(); diff --git a/services/common/src/bundle_active_app_state_obsever.cpp b/services/common/src/bundle_active_app_state_obsever.cpp index f33f121..cb62343 100644 --- a/services/common/src/bundle_active_app_state_obsever.cpp +++ b/services/common/src/bundle_active_app_state_obsever.cpp @@ -75,8 +75,8 @@ void BundleActiveAppStateObserver::OnAbilityStateChanged(const AbilityStateData "send report event msg"); std::shared_ptr handlerobjToPtr = std::make_shared(tmpHandlerObject); - auto event = AppExecFwk::InnerEvent::Get(BundleActiveReportHandler::MSG_REPORT_EVENT, handlerobjToPtr); - reportHandler_->SendEvent(event); + auto handlerEvent = AppExecFwk::InnerEvent::Get(BundleActiveReportHandler::MSG_REPORT_EVENT, handlerobjToPtr); + reportHandler_->SendEvent(handlerEvent); } } return; diff --git a/services/common/src/bundle_active_continuous_task_observer.cpp b/services/common/src/bundle_active_continuous_task_observer.cpp index b2fb713..80e4f7e 100644 --- a/services/common/src/bundle_active_continuous_task_observer.cpp +++ b/services/common/src/bundle_active_continuous_task_observer.cpp @@ -108,8 +108,8 @@ void BundleActiveContinuousTaskObserver::ReportContinuousTaskEvent( BUNDLE_ACTIVE_LOGI("BundleActiveAppStateObserver::OnAbilityStateChanged handler not null, SEND"); std::shared_ptr handlerobjToPtr = std::make_shared(tmpHandlerObject); - auto event = AppExecFwk::InnerEvent::Get(BundleActiveReportHandler::MSG_REPORT_EVENT, handlerobjToPtr); - reportHandler_->SendEvent(event); + auto handlerEvent = AppExecFwk::InnerEvent::Get(BundleActiveReportHandler::MSG_REPORT_EVENT, handlerobjToPtr); + reportHandler_->SendEvent(handlerEvent); } } } diff --git a/services/common/src/bundle_active_core.cpp b/services/common/src/bundle_active_core.cpp index e97e0db..f9b08a7 100644 --- a/services/common/src/bundle_active_core.cpp +++ b/services/common/src/bundle_active_core.cpp @@ -269,8 +269,7 @@ void BundleActiveCore::OnStatsChanged(const int32_t userId) void BundleActiveCore::RestoreAllData() { - for (std::map>::iterator it = userStatServices_.begin(); - it != userStatServices_.end(); it++) { + for (auto it = userStatServices_.begin(); it != userStatServices_.end(); ++it) { std::shared_ptr service = it->second; if (service == nullptr) { BUNDLE_ACTIVE_LOGI("service in BundleActiveCore::RestoreToDatabaseLocked() is null"); @@ -294,7 +293,6 @@ void BundleActiveCore::RestoreAllData() void BundleActiveCore::RestoreToDatabase(const int32_t userId) { BUNDLE_ACTIVE_LOGD("RestoreToDatabase called"); - sptr timer = MiscServices::TimeServiceClient::GetInstance(); BundleActiveEvent event; event.eventId_ = BundleActiveEvent::FLUSH; event.timeStamp_ = GetSystemTimeMs(); @@ -535,8 +533,7 @@ int32_t BundleActiveCore::ReportEventToAllUserId(BundleActiveEvent& event) if (userStatServices_.empty()) { return DEFAULT_USER_ID; } - for (std::map>::iterator it = userStatServices_.begin(); - it != userStatServices_.end(); it++) { + for (auto it = userStatServices_.begin(); it != userStatServices_.end(); ++it) { ConvertToSystemTimeLocked(event); std::shared_ptr service = GetUserDataAndInitializeIfNeeded(it->first, timeNow, debugCore_); @@ -762,7 +759,6 @@ void BundleActiveCore::AddObserverDeathRecipient(const sptrAsObject(); auto it = recipientMap_.find(observer->AsObject()); if (it != recipientMap_.end()) { BUNDLE_ACTIVE_LOGI("This death recipient has been added."); diff --git a/services/common/src/bundle_active_service.cpp b/services/common/src/bundle_active_service.cpp index 4d1b088..26a94a9 100644 --- a/services/common/src/bundle_active_service.cpp +++ b/services/common/src/bundle_active_service.cpp @@ -314,7 +314,6 @@ std::vector BundleActiveService::QueryPackageStats(con if (userId != -1) { BUNDLE_ACTIVE_LOGI("QueryPackageStats user id is %{public}d", userId); bool isSystemAppAndHasPermission = CheckBundleIsSystemAppAndHasPermission(callingUid, tokenId, errCode); - AccessToken::AccessTokenID tokenId = OHOS::IPCSkeleton::GetCallingTokenID(); auto tokenFlag = AccessToken::AccessTokenKit::GetTokenTypeFlag(tokenId); if (isSystemAppAndHasPermission == true || tokenFlag == AccessToken::TypeATokenTypeEnum::TOKEN_NATIVE || @@ -346,7 +345,6 @@ std::vector BundleActiveService::QueryEvents(const int64_t be if (userId != -1) { BUNDLE_ACTIVE_LOGI("QueryEvents userid is %{public}d", userId); bool isSystemAppAndHasPermission = CheckBundleIsSystemAppAndHasPermission(callingUid, tokenId, errCode); - AccessToken::AccessTokenID tokenId = OHOS::IPCSkeleton::GetCallingTokenID(); auto tokenFlag = AccessToken::AccessTokenKit::GetTokenTypeFlag(tokenId); if (isSystemAppAndHasPermission == true || tokenFlag == AccessToken::TypeATokenTypeEnum::TOKEN_NATIVE || @@ -458,7 +456,6 @@ int32_t BundleActiveService::QueryPackageGroup(std::string& bundleName, int32_t // get uid int32_t callingUid = OHOS::IPCSkeleton::GetCallingUid(); BUNDLE_ACTIVE_LOGD("QueryPackageGroup UID is %{public}d", callingUid); - int32_t errCode = 0; int32_t result = -1; if (userId == -1) { OHOS::ErrCode ret = BundleActiveAccountHelper::GetUserId(callingUid, userId); @@ -479,6 +476,7 @@ int32_t BundleActiveService::QueryPackageGroup(std::string& bundleName, int32_t } else { AccessToken::AccessTokenID tokenId = OHOS::IPCSkeleton::GetCallingTokenID(); auto tokenFlag = AccessToken::AccessTokenKit::GetTokenTypeFlag(tokenId); + int32_t errCode = 0; if (CheckBundleIsSystemAppAndHasPermission(callingUid, tokenId, errCode) || tokenFlag == AccessToken::TypeATokenTypeEnum::TOKEN_NATIVE || tokenFlag == AccessToken::TypeATokenTypeEnum::TOKEN_SHELL) { @@ -560,7 +558,7 @@ int32_t BundleActiveService::ConvertIntervalType(const int32_t intervalType) } bool BundleActiveService::CheckBundleIsSystemAppAndHasPermission(const int32_t uid, - OHOS::Security::AccessToken::AccessTokenID tokenId, int32_t& errCode) + OHOS::Security::AccessToken::AccessTokenID tokenId, int32_t errCode) { if (!GetBundleMgrProxy()) { BUNDLE_ACTIVE_LOGE("RegisterGroupCallBack Get bundle manager proxy failed!"); -- Gitee