Android上所有的系统Service都是通过SystemServer进程启动的,并且驻留在SystemServer进程中。
SystemServer进程在启动时,通过创建一个ServerThread线程来启动所有服务.
安装, 卸载app都是通过PackageManagerService来完成的. 除此之外, 系统启动时, 也要通过PackageManagerService对系统app和第三方app进行扫描, 解析所有app里面的AndroidManifest.xml, 目的是当app通过隐式intent启动Activity或Service时, 可以通过PackageManagerService来找到真正要启动的目标组件.
public class PackageManagerService extends IPackageManager.Stub {
final ActivityIntentResolver mActivities =
new ActivityIntentResolver();
final ActivityIntentResolver mReceivers =
new ActivityIntentResolver();
final ServiceIntentResolver mServices = new ServiceIntentResolver();
//通过PackageParser解析所有app中的AndroidManifest.xml文件.
//最终目的是对mActivities, mReceivers和mServices进行赋值, 记录各组件的信息,
//主要是记录各组件和intent匹配关系的信息.
private PackageParser.Package scanPackageLI(File scanFile, int parseFlags) {
parseFlags |= mDefParseFlags;
PackageParser pp = new PackageParser();
final PackageParser.Package pkg;
pkg = pp.parsePackage(scanFile, parseFlags);
}
//查询符合intent匹配规则的所有目标Activity的list.
@Override
public List<ResolveInfo> queryIntentActivities(Intent intent, String resolvedType) {
return mActivities.queryIntentForPackage(intent, resolvedType, flags, pkg.activities, userId);
}
}
---DONE.----