AMS指令数降负载

Signed-off-by: SKY2001 <songtianyu10@huawei.com>

🤖 AI[0%] 🔧 Human Fixed[0%] 🧑 Human[100%] 👌 AI Adopted[0%]
This commit is contained in:
SKY2001
2026-07-17 14:51:56 +08:00
parent cdd7b14cde
commit bdee7829dc
7 changed files with 232 additions and 197 deletions
@@ -96,66 +96,31 @@ bool AppStateFilter::Match(const AppStateFilter& filter)
return false;
}
std::unordered_map<ApplicationState, FilterAppStateType> 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<AppProcessState, FilterProcessStateType> 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<AbilityState, FilterAbilityStateType> 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<ExtensionState, FilterAbilityStateType> 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<BundleType, FilterBundleType> 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;
@@ -109,6 +109,11 @@ class WindowPidVisibilityChangedListener;
using LoadAbilityTaskFunc = std::function<void()>;
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;
+25 -25
View File
@@ -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<int32_t>(GetBundleInfoFlag::GET_BUNDLE_INFO_WITH_APPLICATION) |
static_cast<int32_t>(GetBundleInfoFlag::GET_BUNDLE_INFO_WITH_EXTENSION_ABILITY) |
static_cast<int32_t>(GetBundleInfoFlag::GET_BUNDLE_INFO_WITH_HAP_MODULE) |
static_cast<int32_t>(GetBundleInfoFlag::GET_BUNDLE_INFO_WITH_REQUESTED_PERMISSION);
constexpr int32_t BUNDLE_INFO_FLAG_CLONE_WITH_APP_HAP_ABILITY_EXT =
static_cast<int32_t>(GetBundleInfoFlag::GET_BUNDLE_INFO_WITH_APPLICATION) |
static_cast<int32_t>(GetBundleInfoFlag::GET_BUNDLE_INFO_WITH_HAP_MODULE) |
static_cast<int32_t>(GetBundleInfoFlag::GET_BUNDLE_INFO_WITH_ABILITY) |
static_cast<int32_t>(GetBundleInfoFlag::GET_BUNDLE_INFO_WITH_EXTENSION_ABILITY);
constexpr int32_t BUNDLE_INFO_FLAG_CLONE_WITH_APP_PERM =
static_cast<int32_t>(GetBundleInfoFlag::GET_BUNDLE_INFO_WITH_APPLICATION) |
static_cast<int32_t>(GetBundleInfoFlag::GET_BUNDLE_INFO_WITH_REQUESTED_PERMISSION);
constexpr int32_t BUNDLE_INFO_FLAG_WITH_HAP_APP_METADATA =
static_cast<int32_t>(GetBundleInfoFlag::GET_BUNDLE_INFO_WITH_HAP_MODULE) |
static_cast<int32_t>(GetBundleInfoFlag::GET_BUNDLE_INFO_WITH_APPLICATION) |
static_cast<int32_t>(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<int32_t>(GetBundleInfoFlag::GET_BUNDLE_INFO_WITH_APPLICATION) |
static_cast<int32_t>(GetBundleInfoFlag::GET_BUNDLE_INFO_WITH_EXTENSION_ABILITY) |
static_cast<int32_t>(GetBundleInfoFlag::GET_BUNDLE_INFO_WITH_HAP_MODULE) |
static_cast<int32_t>(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<int32_t>(GetBundleInfoFlag::GET_BUNDLE_INFO_WITH_APPLICATION) |
static_cast<int32_t>(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_ptr<AppRunningRecor
auto bundleMgrHelper = remoteClientManager_->GetBundleManagerHelper();
BundleInfo bundleInfo;
auto userId = GetUserIdByUid(appRecord->GetUid());
auto flags = static_cast<int32_t>(GetBundleInfoFlag::GET_BUNDLE_INFO_WITH_APPLICATION)
| static_cast<int32_t>(GetBundleInfoFlag::GET_BUNDLE_INFO_WITH_HAP_MODULE)
| static_cast<int32_t>(GetBundleInfoFlag::GET_BUNDLE_INFO_WITH_ABILITY)
| static_cast<int32_t>(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_ptr<AppRunningRecord
auto bundleMgrHelper = remoteClientManager_->GetBundleManagerHelper();
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<BundleFlag>(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<int32_t>(GetBundleInfoFlag::GET_BUNDLE_INFO_WITH_APPLICATION) |
static_cast<int32_t>(GetBundleInfoFlag::GET_BUNDLE_INFO_WITH_EXTENSION_ABILITY) |
static_cast<int32_t>(GetBundleInfoFlag::GET_BUNDLE_INFO_WITH_HAP_MODULE) |
static_cast<int32_t>(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<int32_t>(GetBundleInfoFlag::GET_BUNDLE_INFO_WITH_APPLICATION),
@@ -10888,12 +10891,9 @@ int32_t AppMgrServiceInner::GetChildProcessInfoEx(const std::shared_ptr<ChildPro
TAG_LOGE(AAFwkTag::APPMGR, "GetOsAccountLocalIdFromUid failed,errcode=%{public}d", errCode);
return errCode;
}
auto bundleFlag = static_cast<int32_t>(AppExecFwk::GetBundleInfoFlag::GET_BUNDLE_INFO_WITH_HAP_MODULE) |
static_cast<int32_t>(AppExecFwk::GetBundleInfoFlag::GET_BUNDLE_INFO_WITH_APPLICATION) |
static_cast<int32_t>(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;
}
+1 -2
View File
@@ -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<BundleFlag>(flags),
BundleFlag::GET_BUNDLE_WITH_REQUESTED_PERMISSION,
bundleInfo, userId))) {
TAG_LOGE(AAFwkTag::APPMGR, "GetBundleInfo failed");
return false;
@@ -564,16 +564,16 @@ void AppStateObserverManager::HandleOnAppStarted(const std::shared_ptr<AppRunnin
data.isSpecifyTokenId = appRecord->GetAssignTokenId() > 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<ApplicationState>(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<ApplicationState>(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_ptr<AppRunnin
AppStateData data = WrapAppStateData(appRecord, ApplicationState::APP_STATE_TERMINATED);
TAG_LOGD(AAFwkTag::APPMGR, "HandleOnAppStopped, 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_STOPPED,
GetFilterTypeFromBundleType(bundleType),
GetFilterTypeFromApplicationState(static_cast<ApplicationState>(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<ApplicationState>(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<AppRun
TAG_LOGD(AAFwkTag::APPMGR, "name:%{public}s, uid:%{public}d, state:%{public}d, notify:%{public}d, "
"preloadMode:%{public}d",
data.bundleName.c_str(), data.uid, data.state, needNotifyApp, data.preloadMode);
FilterBundleType filterBundleType = GetFilterTypeFromBundleType(bundleType);
FilterAppStateType filterAppStateType =
GetFilterTypeFromApplicationState(static_cast<ApplicationState>(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_ptr<AppRun
bool valid = (bundleNames.empty() || iter != bundleNames.end()) && it->first != nullptr;
valid = valid && !PreventNotify(state, it->second.uid, isByCall);
if (valid) {
AppStateFilter appStateFilter {FilterCallback::ON_FOREGROUND_APPLICATION_CHANGED,
GetFilterTypeFromBundleType(bundleType),
GetFilterTypeFromApplicationState(static_cast<ApplicationState>(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<ApplicationState>(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<AppRun
AppStateData data = WrapAppStateData(appRecord, state, isFromWindowFocusChanged);
TAG_LOGD(AAFwkTag::APPMGR, "OnApplicationStateChanged, name:%{public}s, uid:%{public}d, state:%{public}d, "
"preloadMode:%{public}d", data.bundleName.c_str(), data.uid, data.state, data.preloadMode);
AppStateFilter appStateFilter {FilterCallback::ON_APPLICATION_STATE_CHANGED,
GetFilterTypeFromBundleType(bundleType),
GetFilterTypeFromApplicationState(static_cast<ApplicationState>(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<ApplicationState>(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<AbilityState>(abilityStateData.abilityState))};
} else {
appStateFilter = {FilterCallback::ON_EXTENSION_STATE_CHANGED,
filterBundleType,
FilterAppStateType::NONE, FilterProcessStateType::NONE,
GetFilterTypeFromExtensionState(static_cast<ExtensionState>(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<AbilityState>(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<ExtensionState>(abilityStateData.abilityState))};
if (it->second.appStateFilter.Match(appStateFilter)) {
it->first->OnExtensionStateChanged(abilityStateData);
}
}
}
if ((abilityStateData.abilityState == static_cast<int32_t>(AbilityState::ABILITY_STATE_FOREGROUND) ||
abilityStateData.abilityState == static_cast<int32_t>(AbilityState::ABILITY_STATE_BACKGROUND)) &&
isAbility && !isFromWindowFocusChanged) {
@@ -773,16 +775,16 @@ void AppStateObserverManager::HandleOnProcessResued(const std::shared_ptr<AppRun
TAG_LOGD(AAFwkTag::APPMGR, "Process Resued, bundle:%{public}s, pid:%{public}d, uid:%{public}d",
data.bundleName.c_str(), data.pid, data.uid);
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<AppProcessState>(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<AppProcessState>(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<ChildP
void AppStateObserverManager::HandleOnProcessCreated(const ProcessData &data, BundleType bundleType)
{
AppStateFilter appStateFilter {FilterCallback::ON_PROCESS_CREATED,
GetFilterTypeFromBundleType(bundleType), FilterAppStateType::NONE,
GetFilterTypeFromAppProcessState(static_cast<AppProcessState>(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<AppProcessState>(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<AppProcessState>(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<AppProcessState>(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_ptr<AppRunnin
"bundle:%{public}s, pid:%{public}d, uid:%{public}d, state:%{public}d, "
"isContinuousTask:%{public}d, gpuPid:%{public}d",
data.bundleName.c_str(), data.pid, data.uid, data.state, data.isContinuousTask, data.gpuPid);
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<AppProcessState>(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<AppProcessState>(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_ptr<AppRunn
"bundle:%{public}s, pid:%{public}d, uid:%{public}d, state:%{public}d, "
"isContinuousTask:%{public}d, gpuPid:%{public}d",
data.bundleName.c_str(), data.pid, data.uid, data.state, data.isContinuousTask, data.gpuPid);
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<AppProcessState>(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<AppProcessState>(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<ChildProc
void AppStateObserverManager::HandleOnProcessDied(const ProcessData &data, BundleType bundleType)
{
AppStateFilter appStateFilter {FilterCallback::ON_PROCESS_DIED,
GetFilterTypeFromBundleType(bundleType), FilterAppStateType::NONE,
GetFilterTypeFromAppProcessState(static_cast<AppProcessState>(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<AppProcessState>(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<ApplicationState>(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<ApplicationState>(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<AppProcessState>(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<AppProcessState>(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_ptr<A
"bundle:%{public}s, pid:%{public}d, uid:%{public}d, state:%{public}d, "
"isContinuousTask:%{public}d, gpuPid:%{public}d, processType:%{public}d",
data.bundleName.c_str(), data.pid, data.uid, data.state, data.isContinuousTask, data.gpuPid, data.processType);
auto applicationInfo = appRecord->GetApplicationInfo();
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);
@@ -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<int32_t>(GetBundleInfoFlag::GET_BUNDLE_INFO_WITH_APPLICATION) |
static_cast<int32_t>(GetBundleInfoFlag::GET_BUNDLE_INFO_WITH_HAP_MODULE) |
static_cast<int32_t>(GetBundleInfoFlag::GET_BUNDLE_INFO_WITH_ABILITY) |
static_cast<int32_t>(GetBundleInfoFlag::GET_BUNDLE_INFO_WITH_EXTENSION_ABILITY);
}
ExitResidentProcessManager::~ExitResidentProcessManager() {}
@@ -156,11 +161,8 @@ void ExitResidentProcessManager::QueryExitBundleInfos(const std::vector<ExitResi
TAG_LOGE(AAFwkTag::ABILITYMGR, "fail to get appIndex for %{public}s", item.bundleName.c_str());
continue;
}
auto flags = static_cast<int32_t>(GetBundleInfoFlag::GET_BUNDLE_INFO_WITH_APPLICATION)
| static_cast<int32_t>(GetBundleInfoFlag::GET_BUNDLE_INFO_WITH_HAP_MODULE)
| static_cast<int32_t>(GetBundleInfoFlag::GET_BUNDLE_INFO_WITH_ABILITY)
| static_cast<int32_t>(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;
@@ -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<int32_t>(GetBundleInfoFlag::GET_BUNDLE_INFO_WITH_APPLICATION) |
static_cast<int32_t>(GetBundleInfoFlag::GET_BUNDLE_INFO_WITH_HAP_MODULE);
}
ModuleRunningRecord::ModuleRunningRecord(
const std::shared_ptr<ApplicationInfo> &info, const std::shared_ptr<AMSEventHandler> &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<int32_t>(GetBundleInfoFlag::GET_BUNDLE_INFO_WITH_APPLICATION) |
static_cast<int32_t>(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));