From bdee7829dcbbde34fa62bec13e8e85d52bc016ee Mon Sep 17 00:00:00 2001 From: SKY2001 Date: Fri, 17 Jul 2026 14:51:56 +0800 Subject: [PATCH] =?UTF-8?q?AMS=E6=8C=87=E4=BB=A4=E6=95=B0=E9=99=8D?= =?UTF-8?q?=E8=B4=9F=E8=BD=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: SKY2001 🤖 AI[0%] 🔧 Human Fixed[0%] 🧑 Human[100%] 👌 AI Adopted[0%] --- .../src/appmgr/application_state_filter.cpp | 165 +++++++++------- .../appmgr/include/app_mgr_service_inner.h | 5 + services/appmgr/src/app_mgr_service_inner.cpp | 50 ++--- services/appmgr/src/app_preloader.cpp | 3 +- .../appmgr/src/app_state_observer_manager.cpp | 187 +++++++++--------- .../src/exit_resident_process_manager.cpp | 12 +- services/appmgr/src/module_running_record.cpp | 7 +- 7 files changed, 232 insertions(+), 197 deletions(-) diff --git a/interfaces/inner_api/app_manager/src/appmgr/application_state_filter.cpp b/interfaces/inner_api/app_manager/src/appmgr/application_state_filter.cpp index 2dc2e26137..2f94419149 100644 --- a/interfaces/inner_api/app_manager/src/appmgr/application_state_filter.cpp +++ b/interfaces/inner_api/app_manager/src/appmgr/application_state_filter.cpp @@ -96,66 +96,31 @@ bool AppStateFilter::Match(const AppStateFilter& filter) return false; } -std::unordered_map APPLICATION_STATE_TO_FILTER_MAP = { - {ApplicationState::APP_STATE_CREATE, FilterAppStateType::CREATE}, - {ApplicationState::APP_STATE_FOREGROUND, FilterAppStateType::FOREGROUND}, - {ApplicationState::APP_STATE_BACKGROUND, FilterAppStateType::BACKGROUND}, - {ApplicationState::APP_STATE_TERMINATED, FilterAppStateType::DESTROY}, - {ApplicationState::APP_STATE_READY, FilterAppStateType::READY}, - {ApplicationState::APP_STATE_FOCUS, FilterAppStateType::FOCUS}, - {ApplicationState::APP_STATE_END, FilterAppStateType::END}, - {ApplicationState::APP_STATE_SET_COLD_START, FilterAppStateType::SET_COLD_START}, - {ApplicationState::APP_STATE_CACHED, FilterAppStateType::CACHED}, - {ApplicationState::APP_STATE_PRE_FOREGROUND, FilterAppStateType::PRE_FOREGROUND}, -}; - -std::unordered_map APP_PROCESS_STATE_TO_FILTER_MAP = { - {AppProcessState::APP_STATE_CREATE, FilterProcessStateType::CREATE}, - {AppProcessState::APP_STATE_FOREGROUND, FilterProcessStateType::FOREGROUND}, - {AppProcessState::APP_STATE_BACKGROUND, FilterProcessStateType::BACKGROUND}, - {AppProcessState::APP_STATE_TERMINATED, FilterProcessStateType::DESTROY}, - {AppProcessState::APP_STATE_READY, FilterProcessStateType::READY}, - {AppProcessState::APP_STATE_FOCUS, FilterProcessStateType::FOCUS}, - {AppProcessState::APP_STATE_END, FilterProcessStateType::END}, - {AppProcessState::APP_STATE_CACHED, FilterProcessStateType::CACHED}, - {AppProcessState::APP_STATE_PRE_FOREGROUND, FilterProcessStateType::PRE_FOREGROUND}, -}; - -std::unordered_map ABILITY_STATE_TO_FILTER_MAP = { - {AbilityState::ABILITY_STATE_CREATE, FilterAbilityStateType::CREATE}, - {AbilityState::ABILITY_STATE_FOREGROUND, FilterAbilityStateType::FOREGROUND}, - {AbilityState::ABILITY_STATE_BACKGROUND, FilterAbilityStateType::BACKGROUND}, - {AbilityState::ABILITY_STATE_TERMINATED, FilterAbilityStateType::DESTROY}, - {AbilityState::ABILITY_STATE_READY, FilterAbilityStateType::READY}, - {AbilityState::ABILITY_STATE_FOCUS, FilterAbilityStateType::FOCUS}, - {AbilityState::ABILITY_STATE_END, FilterAbilityStateType::END}, - {AbilityState::ABILITY_STATE_CONNECTED, FilterAbilityStateType::CONNECTED}, - {AbilityState::ABILITY_STATE_DISCONNECTED, FilterAbilityStateType::DISCONNECTED}, -}; - -std::unordered_map EXTENSION_STATE_TO_FILTER_MAP = { - {ExtensionState::EXTENSION_STATE_CREATE, FilterAbilityStateType::CREATE}, - {ExtensionState::EXTENSION_STATE_READY, FilterAbilityStateType::READY}, - {ExtensionState::EXTENSION_STATE_CONNECTED, FilterAbilityStateType::CONNECTED}, - {ExtensionState::EXTENSION_STATE_DISCONNECTED, FilterAbilityStateType::DISCONNECTED}, - {ExtensionState::EXTENSION_STATE_TERMINATED, FilterAbilityStateType::DESTROY}, - {ExtensionState::EXTENSION_STATE_FOREGROUND, FilterAbilityStateType::FOREGROUND}, - {ExtensionState::EXTENSION_STATE_BACKGROUND, FilterAbilityStateType::BACKGROUND}, -}; - -std::unordered_map BUNDLE_TYPE_TO_FILTER_MAP = { - {BundleType::APP, FilterBundleType::APP}, - {BundleType::ATOMIC_SERVICE, FilterBundleType::ATOMIC_SERVICE}, - {BundleType::SHARED, FilterBundleType::SHARED}, - {BundleType::APP_SERVICE_FWK, FilterBundleType::APP_SERVICE_FWK}, - {BundleType::APP_PLUGIN, FilterBundleType::APP_PLUGIN}, -}; - FilterAppStateType GetFilterTypeFromApplicationState(ApplicationState state) { - auto it = APPLICATION_STATE_TO_FILTER_MAP.find(state); - if (it != APPLICATION_STATE_TO_FILTER_MAP.end()) { - return it->second; + switch (state) { + case ApplicationState::APP_STATE_CREATE: + return FilterAppStateType::CREATE; + case ApplicationState::APP_STATE_FOREGROUND: + return FilterAppStateType::FOREGROUND; + case ApplicationState::APP_STATE_BACKGROUND: + return FilterAppStateType::BACKGROUND; + case ApplicationState::APP_STATE_TERMINATED: + return FilterAppStateType::DESTROY; + case ApplicationState::APP_STATE_READY: + return FilterAppStateType::READY; + case ApplicationState::APP_STATE_FOCUS: + return FilterAppStateType::FOCUS; + case ApplicationState::APP_STATE_END: + return FilterAppStateType::END; + case ApplicationState::APP_STATE_SET_COLD_START: + return FilterAppStateType::SET_COLD_START; + case ApplicationState::APP_STATE_CACHED: + return FilterAppStateType::CACHED; + case ApplicationState::APP_STATE_PRE_FOREGROUND: + return FilterAppStateType::PRE_FOREGROUND; + default: + break; } TAG_LOGE(AAFwkTag::APPMGR, "get FilterType from ApplicationState failed"); return FilterAppStateType::NONE; @@ -163,9 +128,27 @@ FilterAppStateType GetFilterTypeFromApplicationState(ApplicationState state) FilterProcessStateType GetFilterTypeFromAppProcessState(AppProcessState state) { - auto it = APP_PROCESS_STATE_TO_FILTER_MAP.find(state); - if (it != APP_PROCESS_STATE_TO_FILTER_MAP.end()) { - return it->second; + switch (state) { + case AppProcessState::APP_STATE_CREATE: + return FilterProcessStateType::CREATE; + case AppProcessState::APP_STATE_FOREGROUND: + return FilterProcessStateType::FOREGROUND; + case AppProcessState::APP_STATE_BACKGROUND: + return FilterProcessStateType::BACKGROUND; + case AppProcessState::APP_STATE_TERMINATED: + return FilterProcessStateType::DESTROY; + case AppProcessState::APP_STATE_READY: + return FilterProcessStateType::READY; + case AppProcessState::APP_STATE_FOCUS: + return FilterProcessStateType::FOCUS; + case AppProcessState::APP_STATE_END: + return FilterProcessStateType::END; + case AppProcessState::APP_STATE_CACHED: + return FilterProcessStateType::CACHED; + case AppProcessState::APP_STATE_PRE_FOREGROUND: + return FilterProcessStateType::PRE_FOREGROUND; + default: + break; } TAG_LOGE(AAFwkTag::APPMGR, "get FilterType from AppProcessState failed"); return FilterProcessStateType::NONE; @@ -173,9 +156,27 @@ FilterProcessStateType GetFilterTypeFromAppProcessState(AppProcessState state) FilterAbilityStateType GetFilterTypeFromAbilityState(AbilityState state) { - auto it = ABILITY_STATE_TO_FILTER_MAP.find(state); - if (it != ABILITY_STATE_TO_FILTER_MAP.end()) { - return it->second; + switch (state) { + case AbilityState::ABILITY_STATE_CREATE: + return FilterAbilityStateType::CREATE; + case AbilityState::ABILITY_STATE_FOREGROUND: + return FilterAbilityStateType::FOREGROUND; + case AbilityState::ABILITY_STATE_BACKGROUND: + return FilterAbilityStateType::BACKGROUND; + case AbilityState::ABILITY_STATE_TERMINATED: + return FilterAbilityStateType::DESTROY; + case AbilityState::ABILITY_STATE_READY: + return FilterAbilityStateType::READY; + case AbilityState::ABILITY_STATE_FOCUS: + return FilterAbilityStateType::FOCUS; + case AbilityState::ABILITY_STATE_END: + return FilterAbilityStateType::END; + case AbilityState::ABILITY_STATE_CONNECTED: + return FilterAbilityStateType::CONNECTED; + case AbilityState::ABILITY_STATE_DISCONNECTED: + return FilterAbilityStateType::DISCONNECTED; + default: + break; } TAG_LOGE(AAFwkTag::APPMGR, "get FilterType from AbilityState failed"); return FilterAbilityStateType::NONE; @@ -183,9 +184,23 @@ FilterAbilityStateType GetFilterTypeFromAbilityState(AbilityState state) FilterAbilityStateType GetFilterTypeFromExtensionState(ExtensionState state) { - auto it = EXTENSION_STATE_TO_FILTER_MAP.find(state); - if (it != EXTENSION_STATE_TO_FILTER_MAP.end()) { - return it->second; + switch (state) { + case ExtensionState::EXTENSION_STATE_CREATE: + return FilterAbilityStateType::CREATE; + case ExtensionState::EXTENSION_STATE_READY: + return FilterAbilityStateType::READY; + case ExtensionState::EXTENSION_STATE_CONNECTED: + return FilterAbilityStateType::CONNECTED; + case ExtensionState::EXTENSION_STATE_DISCONNECTED: + return FilterAbilityStateType::DISCONNECTED; + case ExtensionState::EXTENSION_STATE_TERMINATED: + return FilterAbilityStateType::DESTROY; + case ExtensionState::EXTENSION_STATE_FOREGROUND: + return FilterAbilityStateType::FOREGROUND; + case ExtensionState::EXTENSION_STATE_BACKGROUND: + return FilterAbilityStateType::BACKGROUND; + default: + break; } TAG_LOGE(AAFwkTag::APPMGR, "get FilterType from AbilityState failed"); return FilterAbilityStateType::NONE; @@ -193,9 +208,19 @@ FilterAbilityStateType GetFilterTypeFromExtensionState(ExtensionState state) FilterBundleType GetFilterTypeFromBundleType(BundleType state) { - auto it = BUNDLE_TYPE_TO_FILTER_MAP.find(state); - if (it != BUNDLE_TYPE_TO_FILTER_MAP.end()) { - return it->second; + switch (state) { + case BundleType::APP: + return FilterBundleType::APP; + case BundleType::ATOMIC_SERVICE: + return FilterBundleType::ATOMIC_SERVICE; + case BundleType::SHARED: + return FilterBundleType::SHARED; + case BundleType::APP_SERVICE_FWK: + return FilterBundleType::APP_SERVICE_FWK; + case BundleType::APP_PLUGIN: + return FilterBundleType::APP_PLUGIN; + default: + break; } TAG_LOGE(AAFwkTag::APPMGR, "get FilterType from BundleType failed"); return FilterBundleType::NONE; diff --git a/services/appmgr/include/app_mgr_service_inner.h b/services/appmgr/include/app_mgr_service_inner.h index 277d581baa..23fb9107d5 100644 --- a/services/appmgr/include/app_mgr_service_inner.h +++ b/services/appmgr/include/app_mgr_service_inner.h @@ -109,6 +109,11 @@ class WindowPidVisibilityChangedListener; using LoadAbilityTaskFunc = std::function; constexpr int32_t BASE_USER_RANGE = 200000; +inline int32_t GetUserIdByUid(int32_t uid) +{ + return uid / BASE_USER_RANGE; +} + // for child process isolation constexpr int32_t START_ID_FOR_CHILD_PROCESS_ISOLATION = 110000; constexpr int32_t END_ID_FOR_CHILD_PROCESS_ISOLATION = 119999; diff --git a/services/appmgr/src/app_mgr_service_inner.cpp b/services/appmgr/src/app_mgr_service_inner.cpp index 8aba5901bb..9da076df4d 100644 --- a/services/appmgr/src/app_mgr_service_inner.cpp +++ b/services/appmgr/src/app_mgr_service_inner.cpp @@ -381,10 +381,24 @@ constexpr int32_t FORK_ALL_LIVING_END = 1; constexpr const char* TEMPLATE_MONITOR_PATH = "/proc/checkpoint/monitor"; -int32_t GetUserIdByUid(int32_t uid) -{ - return uid / BASE_USER_RANGE; -} +// Precomputed bundle info flag combinations to avoid repeated runtime OR operations. +constexpr int32_t BUNDLE_INFO_FLAG_WITH_APP_EXT_HAP_PERM = + static_cast(GetBundleInfoFlag::GET_BUNDLE_INFO_WITH_APPLICATION) | + static_cast(GetBundleInfoFlag::GET_BUNDLE_INFO_WITH_EXTENSION_ABILITY) | + static_cast(GetBundleInfoFlag::GET_BUNDLE_INFO_WITH_HAP_MODULE) | + static_cast(GetBundleInfoFlag::GET_BUNDLE_INFO_WITH_REQUESTED_PERMISSION); +constexpr int32_t BUNDLE_INFO_FLAG_CLONE_WITH_APP_HAP_ABILITY_EXT = + static_cast(GetBundleInfoFlag::GET_BUNDLE_INFO_WITH_APPLICATION) | + static_cast(GetBundleInfoFlag::GET_BUNDLE_INFO_WITH_HAP_MODULE) | + static_cast(GetBundleInfoFlag::GET_BUNDLE_INFO_WITH_ABILITY) | + static_cast(GetBundleInfoFlag::GET_BUNDLE_INFO_WITH_EXTENSION_ABILITY); +constexpr int32_t BUNDLE_INFO_FLAG_CLONE_WITH_APP_PERM = + static_cast(GetBundleInfoFlag::GET_BUNDLE_INFO_WITH_APPLICATION) | + static_cast(GetBundleInfoFlag::GET_BUNDLE_INFO_WITH_REQUESTED_PERMISSION); +constexpr int32_t BUNDLE_INFO_FLAG_WITH_HAP_APP_METADATA = + static_cast(GetBundleInfoFlag::GET_BUNDLE_INFO_WITH_HAP_MODULE) | + static_cast(GetBundleInfoFlag::GET_BUNDLE_INFO_WITH_APPLICATION) | + static_cast(GetBundleInfoFlag::GET_BUNDLE_INFO_WITH_METADATA); bool IsCjAbility(const std::string& info) { @@ -2707,15 +2721,11 @@ bool AppMgrServiceInner::GetBundleAndHapInfo(const AbilityInfo &abilityInfo, int32_t bundleMgrResult; if (appIndex == 0) { bundleMgrResult = IN_PROCESS_CALL(bundleMgrHelper->GetBundleInfoV9(appInfo->bundleName, - static_cast(GetBundleInfoFlag::GET_BUNDLE_INFO_WITH_APPLICATION) | - static_cast(GetBundleInfoFlag::GET_BUNDLE_INFO_WITH_EXTENSION_ABILITY) | - static_cast(GetBundleInfoFlag::GET_BUNDLE_INFO_WITH_HAP_MODULE) | - static_cast(GetBundleInfoFlag::GET_BUNDLE_INFO_WITH_REQUESTED_PERMISSION), bundleInfo, userId)); + BUNDLE_INFO_FLAG_WITH_APP_EXT_HAP_PERM, bundleInfo, userId)); } else if (AbilityRuntime::GlobalConstant::IsAppCloneIndex(appIndex) || AbilityRuntime::GlobalConstant::IsSandboxCloneIndex(appIndex)) { bundleMgrResult = IN_PROCESS_CALL(bundleMgrHelper->GetCloneBundleInfo(appInfo->bundleName, - static_cast(GetBundleInfoFlag::GET_BUNDLE_INFO_WITH_APPLICATION) | - static_cast(GetBundleInfoFlag::GET_BUNDLE_INFO_WITH_REQUESTED_PERMISSION), + BUNDLE_INFO_FLAG_CLONE_WITH_APP_PERM, appIndex, bundleInfo, userId)); } else { bundleMgrResult = IN_PROCESS_CALL(bundleMgrHelper->GetSandboxBundleInfo(appInfo->bundleName, @@ -6954,11 +6964,8 @@ void AppMgrServiceInner::RestartKeepAliveProcess(std::shared_ptrGetBundleManagerHelper(); BundleInfo bundleInfo; auto userId = GetUserIdByUid(appRecord->GetUid()); - auto flags = static_cast(GetBundleInfoFlag::GET_BUNDLE_INFO_WITH_APPLICATION) - | static_cast(GetBundleInfoFlag::GET_BUNDLE_INFO_WITH_HAP_MODULE) - | static_cast(GetBundleInfoFlag::GET_BUNDLE_INFO_WITH_ABILITY) - | static_cast(GetBundleInfoFlag::GET_BUNDLE_INFO_WITH_EXTENSION_ABILITY); - if (IN_PROCESS_CALL(bundleMgrHelper->GetCloneBundleInfo(appRecord->GetBundleName(), flags, + if (IN_PROCESS_CALL(bundleMgrHelper->GetCloneBundleInfo(appRecord->GetBundleName(), + BUNDLE_INFO_FLAG_CLONE_WITH_APP_HAP_ABILITY_EXT, appRecord->GetAppIndex(), bundleInfo, userId)) != ERR_OK) { TAG_LOGE(AAFwkTag::APPMGR, "getCloneBundleInfo fail"); return; @@ -7003,10 +7010,9 @@ void AppMgrServiceInner::RestartResidentProcess(std::shared_ptrGetBundleManagerHelper(); BundleInfo bundleInfo; auto userId = GetUserIdByUid(appRecord->GetUid()); - auto flags = BundleFlag::GET_BUNDLE_DEFAULT | BundleFlag::GET_BUNDLE_WITH_REQUESTED_PERMISSION; if (!IN_PROCESS_CALL(bundleMgrHelper->GetBundleInfo( appRecord->GetBundleName(), - static_cast(flags), + BundleFlag::GET_BUNDLE_WITH_REQUESTED_PERMISSION, bundleInfo, userId))) { TAG_LOGE(AAFwkTag::APPMGR, "getBundleInfo fail"); return; @@ -9682,10 +9688,7 @@ int32_t AppMgrServiceInner::IsAppRunning(const std::string &bundleName, int32_t int32_t bundleMgrResult; if (appCloneIndex == 0) { bundleMgrResult = IN_PROCESS_CALL(bundleMgrHelper->GetBundleInfoV9(bundleName, - static_cast(GetBundleInfoFlag::GET_BUNDLE_INFO_WITH_APPLICATION) | - static_cast(GetBundleInfoFlag::GET_BUNDLE_INFO_WITH_EXTENSION_ABILITY) | - static_cast(GetBundleInfoFlag::GET_BUNDLE_INFO_WITH_HAP_MODULE) | - static_cast(GetBundleInfoFlag::GET_BUNDLE_INFO_WITH_REQUESTED_PERMISSION), bundleInfo, userId)); + BUNDLE_INFO_FLAG_WITH_APP_EXT_HAP_PERM, bundleInfo, userId)); } else { bundleMgrResult = IN_PROCESS_CALL(bundleMgrHelper->GetCloneBundleInfo(bundleName, static_cast(GetBundleInfoFlag::GET_BUNDLE_INFO_WITH_APPLICATION), @@ -10888,12 +10891,9 @@ int32_t AppMgrServiceInner::GetChildProcessInfoEx(const std::shared_ptr(AppExecFwk::GetBundleInfoFlag::GET_BUNDLE_INFO_WITH_HAP_MODULE) | - static_cast(AppExecFwk::GetBundleInfoFlag::GET_BUNDLE_INFO_WITH_APPLICATION) | - static_cast(AppExecFwk::GetBundleInfoFlag::GET_BUNDLE_INFO_WITH_METADATA); BundleInfo bundleInfo; if (IN_PROCESS_CALL(bundleMgrHelper->GetCloneBundleInfo(appRecord->GetBundleName(), - bundleFlag, appRecord->GetAppIndex(), bundleInfo, userId) != ERR_OK)) { + BUNDLE_INFO_FLAG_WITH_HAP_APP_METADATA, appRecord->GetAppIndex(), bundleInfo, userId) != ERR_OK)) { TAG_LOGE(AAFwkTag::APPMGR, "GetCloneBundleInfo fail"); return ERR_INVALID_VALUE; } diff --git a/services/appmgr/src/app_preloader.cpp b/services/appmgr/src/app_preloader.cpp index 58dd0ae922..939ae7b33a 100644 --- a/services/appmgr/src/app_preloader.cpp +++ b/services/appmgr/src/app_preloader.cpp @@ -211,9 +211,8 @@ bool AppPreloader::GetBundleAndHapInfo(const std::string &bundleName, int32_t us } TAG_LOGD(AAFwkTag::APPMGR, "userId: %{public}d, bundleName: %{public}s", userId, bundleName.c_str()); - auto flags = BundleFlag::GET_BUNDLE_DEFAULT | BundleFlag::GET_BUNDLE_WITH_REQUESTED_PERMISSION; if (!IN_PROCESS_CALL(bundleMgrHelper->GetBundleInfo(bundleName, - static_cast(flags), + BundleFlag::GET_BUNDLE_WITH_REQUESTED_PERMISSION, bundleInfo, userId))) { TAG_LOGE(AAFwkTag::APPMGR, "GetBundleInfo failed"); return false; diff --git a/services/appmgr/src/app_state_observer_manager.cpp b/services/appmgr/src/app_state_observer_manager.cpp index 12ddd6abc8..aea0b3832c 100644 --- a/services/appmgr/src/app_state_observer_manager.cpp +++ b/services/appmgr/src/app_state_observer_manager.cpp @@ -564,16 +564,16 @@ void AppStateObserverManager::HandleOnAppStarted(const std::shared_ptrGetAssignTokenId() > 0 ? true : false; TAG_LOGD(AAFwkTag::APPMGR, "HandleOnAppStarted, bundle:%{public}s, uid:%{public}d, state:%{public}d", data.bundleName.c_str(), data.uid, data.state); + auto applicationInfo = appRecord->GetApplicationInfo(); + BundleType bundleType = applicationInfo != nullptr ? applicationInfo->bundleType : BundleType::APP; + AppStateFilter appStateFilter {FilterCallback::ON_APP_STARTED, + GetFilterTypeFromBundleType(bundleType), + GetFilterTypeFromApplicationState(static_cast(data.state)), + FilterProcessStateType::NONE, FilterAbilityStateType::NONE}; auto appStateObserverMapCopy = GetAppStateObserverMapCopy(); for (auto it = appStateObserverMapCopy.begin(); it != appStateObserverMapCopy.end(); ++it) { const auto &bundleNames = it->second.bundleNames; auto iter = std::find(bundleNames.begin(), bundleNames.end(), data.bundleName); - auto applicationInfo = appRecord->GetApplicationInfo(); - BundleType bundleType = applicationInfo != nullptr ? applicationInfo->bundleType : BundleType::APP; - AppStateFilter appStateFilter {FilterCallback::ON_APP_STARTED, - GetFilterTypeFromBundleType(bundleType), - GetFilterTypeFromApplicationState(static_cast(data.state)), - FilterProcessStateType::NONE, FilterAbilityStateType::NONE}; if ((bundleNames.empty() || iter != bundleNames.end()) && it->first != nullptr && it->second.appStateFilter.Match(appStateFilter)) { it->first->OnAppStarted(data); @@ -592,16 +592,16 @@ void AppStateObserverManager::HandleOnAppStopped(const std::shared_ptrGetApplicationInfo(); + BundleType bundleType = applicationInfo != nullptr ? applicationInfo->bundleType : BundleType::APP; + AppStateFilter appStateFilter {FilterCallback::ON_APP_STOPPED, + GetFilterTypeFromBundleType(bundleType), + GetFilterTypeFromApplicationState(static_cast(data.state)), + FilterProcessStateType::NONE, FilterAbilityStateType::NONE}; auto appStateObserverMapCopy = GetAppStateObserverMapCopy(); for (auto it = appStateObserverMapCopy.begin(); it != appStateObserverMapCopy.end(); ++it) { const auto &bundleNames = it->second.bundleNames; auto iter = std::find(bundleNames.begin(), bundleNames.end(), data.bundleName); - auto applicationInfo = appRecord->GetApplicationInfo(); - BundleType bundleType = applicationInfo != nullptr ? applicationInfo->bundleType : BundleType::APP; - AppStateFilter appStateFilter {FilterCallback::ON_APP_STOPPED, - GetFilterTypeFromBundleType(bundleType), - GetFilterTypeFromApplicationState(static_cast(data.state)), - FilterProcessStateType::NONE, FilterAbilityStateType::NONE}; if ((bundleNames.empty() || iter != bundleNames.end()) && it->first != nullptr && it->second.appStateFilter.Match(appStateFilter)) { it->first->OnAppStopped(data); @@ -635,6 +635,13 @@ void AppStateObserverManager::HandleAppStateChanged(const std::shared_ptr(data.state)); + AppStateFilter foregroundChangedFilter {FilterCallback::ON_FOREGROUND_APPLICATION_CHANGED, + filterBundleType, filterAppStateType, FilterProcessStateType::NONE, FilterAbilityStateType::NONE}; + AppStateFilter appStateChangedFilter {FilterCallback::ON_APP_STATE_CHANGED, + filterBundleType, filterAppStateType, FilterProcessStateType::NONE, FilterAbilityStateType::NONE}; auto appStateObserverMapCopy = GetAppStateObserverMapCopy(); for (auto it = appStateObserverMapCopy.begin(); it != appStateObserverMapCopy.end(); ++it) { const auto &bundleNames = it->second.bundleNames; @@ -642,20 +649,12 @@ void AppStateObserverManager::HandleAppStateChanged(const std::shared_ptrfirst != nullptr; valid = valid && !PreventNotify(state, it->second.uid, isByCall); if (valid) { - AppStateFilter appStateFilter {FilterCallback::ON_FOREGROUND_APPLICATION_CHANGED, - GetFilterTypeFromBundleType(bundleType), - GetFilterTypeFromApplicationState(static_cast(data.state)), - FilterProcessStateType::NONE, FilterAbilityStateType::NONE}; - if (it->second.appStateFilter.Match(appStateFilter)) { + if (it->second.appStateFilter.Match(foregroundChangedFilter)) { it->first->OnForegroundApplicationChanged(data); } } if (valid && needNotifyApp) { - AppStateFilter appStateFilter {FilterCallback::ON_APP_STATE_CHANGED, - GetFilterTypeFromBundleType(bundleType), - GetFilterTypeFromApplicationState(static_cast(data.state)), - FilterProcessStateType::NONE, FilterAbilityStateType::NONE}; - if (it->second.appStateFilter.Match(appStateFilter)) { + if (it->second.appStateFilter.Match(appStateChangedFilter)) { it->first->OnAppStateChanged(data); } } @@ -666,14 +665,14 @@ void AppStateObserverManager::HandleAppStateChanged(const std::shared_ptr(data.state)), + FilterProcessStateType::NONE, FilterAbilityStateType::NONE}; auto appStateObserverMapCopy = GetAppStateObserverMapCopy(); for (auto it = appStateObserverMapCopy.begin(); it != appStateObserverMapCopy.end(); ++it) { const auto &bundleNames = it->second.bundleNames; auto iter = std::find(bundleNames.begin(), bundleNames.end(), data.bundleName); - AppStateFilter appStateFilter {FilterCallback::ON_APPLICATION_STATE_CHANGED, - GetFilterTypeFromBundleType(bundleType), - GetFilterTypeFromApplicationState(static_cast(data.state)), - FilterProcessStateType::NONE, FilterAbilityStateType::NONE}; if ((bundleNames.empty() || iter != bundleNames.end()) && it->first != nullptr && it->second.appStateFilter.Match(appStateFilter)) { it->first->OnApplicationStateChanged(data); @@ -690,12 +689,24 @@ void AppStateObserverManager::HandleStateChangedNotifyObserver( "Handle state change, module:%{public}s, bundle:%{public}s, ability:%{public}s, state:%{public}d, " "pid:%{public}d ,uid:%{public}d, abilityType:%{public}d, isAbility:%{public}d, callerBundleName:%{public}s, " "callerAbilityName:%{public}s, isAtomicService:%{public}d, callerUid:%{public}d, callerPid:%{public}d, " - "preloadMode:%{public}d", - abilityStateData.moduleName.c_str(), abilityStateData.bundleName.c_str(), + "preloadMode:%{public}d", abilityStateData.moduleName.c_str(), abilityStateData.bundleName.c_str(), abilityStateData.abilityName.c_str(), abilityStateData.abilityState, abilityStateData.pid, abilityStateData.uid, abilityStateData.abilityType, isAbility, abilityStateData.callerBundleName.c_str(), abilityStateData.callerAbilityName.c_str(), abilityStateData.isAtomicService, abilityStateData.callerUid, abilityStateData.callerPid, abilityStateData.preloadMode); + FilterBundleType filterBundleType = GetFilterTypeFromBundleType(bundleType); + AppStateFilter appStateFilter; + if (isAbility) { + appStateFilter = {FilterCallback::ON_ABILITY_STATE_CHANGED, + filterBundleType, + FilterAppStateType::NONE, FilterProcessStateType::NONE, + GetFilterTypeFromAbilityState(static_cast(abilityStateData.abilityState))}; + } else { + appStateFilter = {FilterCallback::ON_EXTENSION_STATE_CHANGED, + filterBundleType, + FilterAppStateType::NONE, FilterProcessStateType::NONE, + GetFilterTypeFromExtensionState(static_cast(abilityStateData.abilityState))}; + } auto appStateObserverMapCopy = GetAppStateObserverMapCopy(); for (auto it = appStateObserverMapCopy.begin(); it != appStateObserverMapCopy.end(); ++it) { const auto &bundleNames = it->second.bundleNames; @@ -704,24 +715,15 @@ void AppStateObserverManager::HandleStateChangedNotifyObserver( continue; } if (isAbility) { - AppStateFilter appStateFilter {FilterCallback::ON_ABILITY_STATE_CHANGED, - GetFilterTypeFromBundleType(bundleType), - FilterAppStateType::NONE, FilterProcessStateType::NONE, - GetFilterTypeFromAbilityState(static_cast(abilityStateData.abilityState))}; if (it->second.appStateFilter.Match(appStateFilter)) { it->first->OnAbilityStateChanged(abilityStateData); } } else { - AppStateFilter appStateFilter {FilterCallback::ON_EXTENSION_STATE_CHANGED, - GetFilterTypeFromBundleType(bundleType), - FilterAppStateType::NONE, FilterProcessStateType::NONE, - GetFilterTypeFromExtensionState(static_cast(abilityStateData.abilityState))}; if (it->second.appStateFilter.Match(appStateFilter)) { it->first->OnExtensionStateChanged(abilityStateData); } } } - if ((abilityStateData.abilityState == static_cast(AbilityState::ABILITY_STATE_FOREGROUND) || abilityStateData.abilityState == static_cast(AbilityState::ABILITY_STATE_BACKGROUND)) && isAbility && !isFromWindowFocusChanged) { @@ -773,16 +775,16 @@ void AppStateObserverManager::HandleOnProcessResued(const std::shared_ptrGetApplicationInfo(); + BundleType bundleType = applicationInfo != nullptr ? applicationInfo->bundleType : BundleType::APP; + AppStateFilter appStateFilter {FilterCallback::ON_PROCESS_REUSED, + GetFilterTypeFromBundleType(bundleType), FilterAppStateType::NONE, + GetFilterTypeFromAppProcessState(static_cast(data.state)), + FilterAbilityStateType::NONE}; auto appStateObserverMapCopy = GetAppStateObserverMapCopy(); for (auto it = appStateObserverMapCopy.begin(); it != appStateObserverMapCopy.end(); ++it) { const auto &bundleNames = it->second.bundleNames; auto iter = std::find(bundleNames.begin(), bundleNames.end(), data.bundleName); - auto applicationInfo = appRecord->GetApplicationInfo(); - BundleType bundleType = applicationInfo != nullptr ? applicationInfo->bundleType : BundleType::APP; - AppStateFilter appStateFilter {FilterCallback::ON_PROCESS_REUSED, - GetFilterTypeFromBundleType(bundleType), FilterAppStateType::NONE, - GetFilterTypeFromAppProcessState(static_cast(data.state)), - FilterAbilityStateType::NONE}; if ((bundleNames.empty() || iter != bundleNames.end()) && it->first != nullptr && it->second.appStateFilter.Match(appStateFilter)) { it->first->OnProcessReused(data); @@ -842,14 +844,14 @@ void AppStateObserverManager::HandleOnChildProcessCreated(std::shared_ptr(data.state)), + FilterAbilityStateType::NONE}; auto appStateObserverMapCopy = GetAppStateObserverMapCopy(); for (auto it = appStateObserverMapCopy.begin(); it != appStateObserverMapCopy.end(); ++it) { const auto &bundleNames = it->second.bundleNames; auto iter = std::find(bundleNames.begin(), bundleNames.end(), data.bundleName); - AppStateFilter appStateFilter {FilterCallback::ON_PROCESS_CREATED, - GetFilterTypeFromBundleType(bundleType), FilterAppStateType::NONE, - GetFilterTypeFromAppProcessState(static_cast(data.state)), - FilterAbilityStateType::NONE}; if ((bundleNames.empty() || iter != bundleNames.end()) && it->first != nullptr && it->second.appStateFilter.Match(appStateFilter)) { it->first->OnProcessCreated(data); @@ -876,19 +878,20 @@ void AppStateObserverManager::HandleOnProcessStateChanged( "isContinuousTask:%{public}d, gpuPid:%{public}d, preloadMode:%{public}d, isFromScreenOffBackground:%{public}d", data.bundleName.c_str(), data.pid, data.uid, data.state, data.isContinuousTask, data.gpuPid, data.preloadMode, data.isFromScreenOffBackground); + auto applicationInfo = appRecord->GetApplicationInfo(); + BundleType bundleType = applicationInfo != nullptr ? applicationInfo->bundleType : BundleType::APP; + AppStateFilter appStateFilter {FilterCallback::ON_PROCESS_STATE_CHANGED, + GetFilterTypeFromBundleType(bundleType), FilterAppStateType::NONE, + GetFilterTypeFromAppProcessState(static_cast(data.state)), + FilterAbilityStateType::NONE}; + auto appRecordState = appRecord->GetState(); auto appStateObserverMapCopy = GetAppStateObserverMapCopy(); for (auto it = appStateObserverMapCopy.begin(); it != appStateObserverMapCopy.end(); ++it) { const auto &bundleNames = it->second.bundleNames; auto iter = std::find(bundleNames.begin(), bundleNames.end(), data.bundleName); - auto applicationInfo = appRecord->GetApplicationInfo(); - BundleType bundleType = applicationInfo != nullptr ? applicationInfo->bundleType : BundleType::APP; - AppStateFilter appStateFilter {FilterCallback::ON_PROCESS_STATE_CHANGED, - GetFilterTypeFromBundleType(bundleType), FilterAppStateType::NONE, - GetFilterTypeFromAppProcessState(static_cast(data.state)), - FilterAbilityStateType::NONE}; if ((bundleNames.empty() || iter != bundleNames.end()) && it->first != nullptr && it->second.appStateFilter.Match(appStateFilter) && - !PreventNotify(appRecord->GetState(), it->second.uid, isByCall)) { + !PreventNotify(appRecordState, it->second.uid, isByCall)) { it->first->OnProcessStateChanged(data); } } @@ -906,16 +909,16 @@ void AppStateObserverManager::HandleOnWindowShow(const std::shared_ptrGetApplicationInfo(); + BundleType bundleType = applicationInfo != nullptr ? applicationInfo->bundleType : BundleType::APP; + AppStateFilter appStateFilter {FilterCallback::ON_WINDOW_SHOW, + GetFilterTypeFromBundleType(bundleType), FilterAppStateType::NONE, + GetFilterTypeFromAppProcessState(static_cast(data.state)), + FilterAbilityStateType::NONE}; auto appStateObserverMapCopy = GetAppStateObserverMapCopy(); for (auto it = appStateObserverMapCopy.begin(); it != appStateObserverMapCopy.end(); ++it) { const auto &bundleNames = it->second.bundleNames; auto iter = std::find(bundleNames.begin(), bundleNames.end(), data.bundleName); - auto applicationInfo = appRecord->GetApplicationInfo(); - BundleType bundleType = applicationInfo != nullptr ? applicationInfo->bundleType : BundleType::APP; - AppStateFilter appStateFilter {FilterCallback::ON_WINDOW_SHOW, - GetFilterTypeFromBundleType(bundleType), FilterAppStateType::NONE, - GetFilterTypeFromAppProcessState(static_cast(data.state)), - FilterAbilityStateType::NONE}; if ((bundleNames.empty() || iter != bundleNames.end()) && it->first != nullptr && it->second.appStateFilter.Match(appStateFilter)) { it->first->OnWindowShow(data); @@ -935,16 +938,16 @@ void AppStateObserverManager::HandleOnWindowHidden(const std::shared_ptrGetApplicationInfo(); + BundleType bundleType = applicationInfo != nullptr ? applicationInfo->bundleType : BundleType::APP; + AppStateFilter appStateFilter {FilterCallback::ON_WINDOW_HIDDEN, + GetFilterTypeFromBundleType(bundleType), FilterAppStateType::NONE, + GetFilterTypeFromAppProcessState(static_cast(data.state)), + FilterAbilityStateType::NONE}; auto appStateObserverMapCopy = GetAppStateObserverMapCopy(); for (auto it = appStateObserverMapCopy.begin(); it != appStateObserverMapCopy.end(); ++it) { const auto &bundleNames = it->second.bundleNames; auto iter = std::find(bundleNames.begin(), bundleNames.end(), data.bundleName); - auto applicationInfo = appRecord->GetApplicationInfo(); - BundleType bundleType = applicationInfo != nullptr ? applicationInfo->bundleType : BundleType::APP; - AppStateFilter appStateFilter {FilterCallback::ON_WINDOW_HIDDEN, - GetFilterTypeFromBundleType(bundleType), FilterAppStateType::NONE, - GetFilterTypeFromAppProcessState(static_cast(data.state)), - FilterAbilityStateType::NONE}; if ((bundleNames.empty() || iter != bundleNames.end()) && it->first != nullptr && it->second.appStateFilter.Match(appStateFilter)) { it->first->OnWindowHidden(data); @@ -1018,14 +1021,14 @@ void AppStateObserverManager::HandleOnChildProcessDied(std::shared_ptr(data.state)), + FilterAbilityStateType::NONE}; auto appStateObserverMapCopy = GetAppStateObserverMapCopy(); for (auto it = appStateObserverMapCopy.begin(); it != appStateObserverMapCopy.end(); ++it) { const auto &bundleNames = it->second.bundleNames; auto iter = std::find(bundleNames.begin(), bundleNames.end(), data.bundleName); - AppStateFilter appStateFilter {FilterCallback::ON_PROCESS_DIED, - GetFilterTypeFromBundleType(bundleType), FilterAppStateType::NONE, - GetFilterTypeFromAppProcessState(static_cast(data.state)), - FilterAbilityStateType::NONE}; if ((bundleNames.empty() || iter != bundleNames.end()) && it->first != nullptr && it->second.appStateFilter.Match(appStateFilter)) { it->first->OnProcessDied(data); @@ -1472,16 +1475,16 @@ void AppStateObserverManager::HandleOnAppCacheStateChanged(const std::shared_ptr data.isSpecifyTokenId = appRecord->GetAssignTokenId() > 0 ? true : false; TAG_LOGD(AAFwkTag::APPMGR, "HandleOnAppCacheStateChanged, bundle:%{public}s, uid:%{public}d, state:%{public}d", data.bundleName.c_str(), data.uid, data.state); + auto applicationInfo = appRecord->GetApplicationInfo(); + BundleType bundleType = applicationInfo != nullptr ? applicationInfo->bundleType : BundleType::APP; + AppStateFilter appStateFilter {FilterCallback::ON_APP_CACHE_STATE_CHANGED, + GetFilterTypeFromBundleType(bundleType), + GetFilterTypeFromApplicationState(static_cast(data.state)), + FilterProcessStateType::NONE, FilterAbilityStateType::NONE}; auto appStateObserverMapCopy = GetAppStateObserverMapCopy(); for (auto it = appStateObserverMapCopy.begin(); it != appStateObserverMapCopy.end(); ++it) { const auto &bundleNames = it->second.bundleNames; auto iter = std::find(bundleNames.begin(), bundleNames.end(), data.bundleName); - auto applicationInfo = appRecord->GetApplicationInfo(); - BundleType bundleType = applicationInfo != nullptr ? applicationInfo->bundleType : BundleType::APP; - AppStateFilter appStateFilter {FilterCallback::ON_APP_CACHE_STATE_CHANGED, - GetFilterTypeFromBundleType(bundleType), - GetFilterTypeFromApplicationState(static_cast(data.state)), - FilterProcessStateType::NONE, FilterAbilityStateType::NONE}; if ((bundleNames.empty() || iter != bundleNames.end()) && it->first != nullptr && it->second.appStateFilter.Match(appStateFilter)) { it->first->OnAppCacheStateChanged(data); @@ -1595,16 +1598,16 @@ void AppStateObserverManager::HandleOnKeepAliveStateChanged(const std::shared_pt data.bundleName.c_str(), data.pid, data.uid, data.processType, data.extensionType, data.processName.c_str(), data.renderUid, data.isTestMode, data.callerPid, data.callerUid, data.isKeepAlive); + auto applicationInfo = appRecord->GetApplicationInfo(); + BundleType bundleType = applicationInfo != nullptr ? applicationInfo->bundleType : BundleType::APP; + AppStateFilter appStateFilter {FilterCallback::ON_KEEPALIVE_STATE_CHANGED, + GetFilterTypeFromBundleType(bundleType), FilterAppStateType::NONE, + GetFilterTypeFromAppProcessState(static_cast(data.state)), + FilterAbilityStateType::NONE}; auto appStateObserverMapCopy = GetAppStateObserverMapCopy(); for (auto it = appStateObserverMapCopy.begin(); it != appStateObserverMapCopy.end(); ++it) { const auto &bundleNames = it->second.bundleNames; auto iter = std::find(bundleNames.begin(), bundleNames.end(), data.bundleName); - auto applicationInfo = appRecord->GetApplicationInfo(); - BundleType bundleType = applicationInfo != nullptr ? applicationInfo->bundleType : BundleType::APP; - AppStateFilter appStateFilter {FilterCallback::ON_KEEPALIVE_STATE_CHANGED, - GetFilterTypeFromBundleType(bundleType), FilterAppStateType::NONE, - GetFilterTypeFromAppProcessState(static_cast(data.state)), - FilterAbilityStateType::NONE}; if ((bundleNames.empty() || iter != bundleNames.end()) && it->first != nullptr && it->second.appStateFilter.Match(appStateFilter)) { it->first->OnKeepAliveStateChanged(data); @@ -1655,15 +1658,15 @@ void AppStateObserverManager::HandleOnProcessPreForegroundChanged(std::shared_pt TAG_LOGI(AAFwkTag::APPMGR, "HandleOnProcessPreForegroundChanged, pid:%{public}d, bundle:%{public}s, uid:%{public}d, isPreFore:%{public}d", preloadProcessData.pid, bundleName.c_str(), preloadProcessData.uid, preloadProcessData.isPreForeground); + auto applicationInfo = appRecord->GetApplicationInfo(); + BundleType bundleType = applicationInfo != nullptr ? applicationInfo->bundleType : BundleType::APP; + AppStateFilter appStateFilter {FilterCallback::ON_PROCESS_PREFOREGROUND_CHANGED, + GetFilterTypeFromBundleType(bundleType), FilterAppStateType::ALL, + FilterProcessStateType::ALL, FilterAbilityStateType::ALL}; auto appStateObserverMapCopy = GetAppStateObserverMapCopy(); for (auto it = appStateObserverMapCopy.begin(); it != appStateObserverMapCopy.end(); ++it) { const auto &bundleNames = it->second.bundleNames; auto iter = std::find(bundleNames.begin(), bundleNames.end(), bundleName); - auto applicationInfo = appRecord->GetApplicationInfo(); - BundleType bundleType = applicationInfo != nullptr ? applicationInfo->bundleType : BundleType::APP; - AppStateFilter appStateFilter {FilterCallback::ON_PROCESS_PREFOREGROUND_CHANGED, - GetFilterTypeFromBundleType(bundleType), FilterAppStateType::ALL, - FilterProcessStateType::ALL, FilterAbilityStateType::ALL}; if ((bundleNames.empty() || iter != bundleNames.end()) && it->first != nullptr && it->second.appStateFilter.Match(appStateFilter)) { it->first->OnProcessPreForegroundChanged(preloadProcessData); @@ -1708,15 +1711,15 @@ void AppStateObserverManager::HandleOnProcessTypeChanged(const std::shared_ptrGetApplicationInfo(); + BundleType bundleType = applicationInfo != nullptr ? applicationInfo->bundleType : BundleType::APP; + AppStateFilter appStateFilter {FilterCallback::ON_PROCESS_TYPE_CHANGED, + GetFilterTypeFromBundleType(bundleType), FilterAppStateType::ALL, + FilterProcessStateType::ALL, FilterAbilityStateType::ALL}; auto appStateObserverMapCopy = GetAppStateObserverMapCopy(); for (auto it = appStateObserverMapCopy.begin(); it != appStateObserverMapCopy.end(); ++it) { const auto &bundleNames = it->second.bundleNames; auto iter = std::find(bundleNames.begin(), bundleNames.end(), data.bundleName); - BundleType bundleType = appRecord->GetApplicationInfo() != nullptr ? - appRecord->GetApplicationInfo()->bundleType : BundleType::APP; - AppStateFilter appStateFilter {FilterCallback::ON_PROCESS_TYPE_CHANGED, - GetFilterTypeFromBundleType(bundleType), FilterAppStateType::ALL, - FilterProcessStateType::ALL, FilterAbilityStateType::ALL}; if ((bundleNames.empty() || iter != bundleNames.end()) && it->first != nullptr && it->second.appStateFilter.Match(appStateFilter)) { it->first->OnProcessTypeChanged(data); diff --git a/services/appmgr/src/exit_resident_process_manager.cpp b/services/appmgr/src/exit_resident_process_manager.cpp index 0745955c3d..22b4e521f2 100644 --- a/services/appmgr/src/exit_resident_process_manager.cpp +++ b/services/appmgr/src/exit_resident_process_manager.cpp @@ -26,6 +26,11 @@ namespace AppExecFwk { namespace { constexpr int32_t U0_USER_ID = 0; constexpr int32_t BASE_USER_RANGE = 200000; +constexpr int32_t BUNDLE_INFO_FLAG_CLONE_WITH_APP_HAP_ABILITY_EXT = + static_cast(GetBundleInfoFlag::GET_BUNDLE_INFO_WITH_APPLICATION) | + static_cast(GetBundleInfoFlag::GET_BUNDLE_INFO_WITH_HAP_MODULE) | + static_cast(GetBundleInfoFlag::GET_BUNDLE_INFO_WITH_ABILITY) | + static_cast(GetBundleInfoFlag::GET_BUNDLE_INFO_WITH_EXTENSION_ABILITY); } ExitResidentProcessManager::~ExitResidentProcessManager() {} @@ -156,11 +161,8 @@ void ExitResidentProcessManager::QueryExitBundleInfos(const std::vector(GetBundleInfoFlag::GET_BUNDLE_INFO_WITH_APPLICATION) - | static_cast(GetBundleInfoFlag::GET_BUNDLE_INFO_WITH_HAP_MODULE) - | static_cast(GetBundleInfoFlag::GET_BUNDLE_INFO_WITH_ABILITY) - | static_cast(GetBundleInfoFlag::GET_BUNDLE_INFO_WITH_EXTENSION_ABILITY); - if (IN_PROCESS_CALL(bundleMgrHelper->GetCloneBundleInfo(item.bundleName, flags, appIndex, bundleInfo, + if (IN_PROCESS_CALL(bundleMgrHelper->GetCloneBundleInfo(item.bundleName, + BUNDLE_INFO_FLAG_CLONE_WITH_APP_HAP_ABILITY_EXT, appIndex, bundleInfo, item.uid / BASE_USER_RANGE)) != ERR_OK) { TAG_LOGE(AAFwkTag::ABILITYMGR, "fail from %{public}s", item.bundleName.c_str()); continue; diff --git a/services/appmgr/src/module_running_record.cpp b/services/appmgr/src/module_running_record.cpp index 1df0add498..5b80eea663 100644 --- a/services/appmgr/src/module_running_record.cpp +++ b/services/appmgr/src/module_running_record.cpp @@ -28,6 +28,9 @@ namespace OHOS { namespace AppExecFwk { namespace { const std::string ABILITY_OWNER_USERID = "AbilityMS_Owner_UserId"; +constexpr int32_t BUNDLE_INFO_FLAG_WITH_APP_HAP = + static_cast(GetBundleInfoFlag::GET_BUNDLE_INFO_WITH_APPLICATION) | + static_cast(GetBundleInfoFlag::GET_BUNDLE_INFO_WITH_HAP_MODULE); } ModuleRunningRecord::ModuleRunningRecord( const std::shared_ptr &info, const std::shared_ptr &eventHandler) @@ -384,12 +387,10 @@ void ModuleRunningRecord::GetHapModuleInfo(HapModuleInfo &info) TAG_LOGD(AAFwkTag::APPMGR, "userId: %{public}d, bundleName: %{public}s, appIndex: %{public}d", userId, appInfo_->bundleName.c_str(), appIndex_); int32_t bundleMgrResult; - auto flag = static_cast(GetBundleInfoFlag::GET_BUNDLE_INFO_WITH_APPLICATION) | - static_cast(GetBundleInfoFlag::GET_BUNDLE_INFO_WITH_HAP_MODULE); if (AbilityRuntime::GlobalConstant::IsAppCloneIndex(appIndex_) || AbilityRuntime::GlobalConstant::IsSandboxCloneIndex(appIndex_)) { bundleMgrResult = IN_PROCESS_CALL(bundleMgrHelper->GetCloneBundleInfo(appInfo_->bundleName, - flag, appIndex_, bundleInfo, userId)); + BUNDLE_INFO_FLAG_WITH_APP_HAP, appIndex_, bundleInfo, userId)); } else { bundleMgrResult = IN_PROCESS_CALL(bundleMgrHelper->GetSandboxBundleInfo(appInfo_->bundleName, appIndex_, userId, bundleInfo));