diff --git a/frameworks/src/bundle_active_group_observer.cpp b/frameworks/src/bundle_active_group_observer.cpp index f1e3d51220731c2002e77a97467c69c95e35fad7..59594f2f4621e4f7db576a8a18d8c3f69883a627 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 e4984e5bf6fcba3a122a813ea387bb28bd505cc3..31271275452e06c954385dfc782bbd8151be0bcd 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 bd49a3f65fa1e5c912c0c4e101f62ae13f232405..1e529b19a3c42a2e20107740cd3e8b38d8c8cbdb 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 f33f1214744a9ef8ebe7c316aa1b23ffd5b40227..cb6234333b5a157ffc5d50bcccd7d5142fdbe6c1 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 b2fb713ac3c246e46bc3e531666ec468e2c10ba2..80e4f7e7182dce2cc0fd26c4b98f0b2febdc827c 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 e97e0db68ee9ef741e42a55f4480062dc5901a58..f9b08a78df128db9b2e8e976f5ca6c179c81cb6b 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 4d1b088cda602635868f6478b81d8b1f3c2f72e7..26a94a9f6e6fc151b16f98682a1a0c4f60f9ae16 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!");