多用户应用启动过程#ActivityInfo获取过程#Activ
2019-03-06 本文已影响0人
古风子
过程描述:
在桌面点击一个Profile User用户的应用,分析系统是怎么知道该应用是10用户应用的
主要逻辑代码为
PMS.JAVA
private ActivityInfo getActivityInfoInternal(ComponentName component, int flags,
int filterCallingUid, int userId) {
if (!sUserManager.exists(userId)) return null;
flags = updateFlagsForComponent(flags, userId, component);
if (!isRecentsAccessingChildProfiles(Binder.getCallingUid(), userId)) {
mPermissionManager.enforceCrossUserPermission(Binder.getCallingUid(), userId,
false /* requireFullPermission */, false /* checkShell */, "get activity info");
}
synchronized (mPackages) {
PackageParser.Activity a = mActivities.mActivities.get(component);//获取Activity信息
if (DEBUG_PACKAGE_INFO) Log.v(TAG, "getActivityInfo " + component + ": " + a);
//验证commpont,flag跟获取的PackageUserState是否匹配
if (a != null && mSettings.isEnabledAndMatchLPr(a.info, flags, userId)) {
PackageSetting ps = mSettings.mPackages.get(component.getPackageName());
if (ps == null) return null;
if (filterAppAccessLPr(ps, filterCallingUid, component, TYPE_ACTIVITY, userId)) {
return null;
}
//实例化得到此次启动的ActivityInfo信息
return PackageParser.generateActivityInfo(
a, flags, ps.readUserState(userId), userId);
}
if (mResolveComponentName.equals(component)) {
return PackageParser.generateActivityInfo(
mResolveActivity, flags, new PackageUserState(), userId);
}
}
return null;
}
-
传递的主要参数为component,flags,userid
-
根据component信息,在系统中所有的Activity信息中查询对应的Activity信息,Activity信息每个Activity只有一份,不管有多少个用户
-
根据pkg信息,在系统中所有的package信息中查询该应用对应的包名的PackageSetting信息,然后根据用户id 10查询该用户用户的PackageUserState,PackageUserState是在用户创建的时候创建的
PackageUserState -
然后验证获取的PackageUserState是否跟要查询的{component,flag}相匹配
-
如果相匹配,则根据上述获取的Activity信息,PackageUserState,flags和userid,去实例化ActiivtyInfo,得到对应userId的ActivityInfo信息
PackageParser.java
public static final ActivityInfo generateActivityInfo(Activity a, int flags,
PackageUserState state, int userId) {
if (a == null) return null;
if (!checkUseInstalledOrHidden(flags, state, a.owner.applicationInfo)) {
return null;
}
if (!copyNeeded(flags, a.owner, state, a.metaData, userId)) {
updateApplicationInfo(a.info.applicationInfo, flags, state);
return a.info;
}
// Make shallow copies so we can store the metadata safely
ActivityInfo ai = new ActivityInfo(a.info);
ai.metaData = a.metaData;
ai.applicationInfo = generateApplicationInfo(a.owner, flags, state, userId);//根据传递的参数和用户10,创建ApplicationInfo
return ai;
}