2023年12月24日发(作者:)

SystemServer进程启动的过程.png1、准备主线程Looper

}2、加载nativeService:// Initialize native brary("android_servers");3、创建systemContext1. 创建ActivityThread实例;2. 获取systemContext、systemUiContext;3. 设置系统theme// Initialize the system SystemContext();private void createSystemContext() { //创建ActivityThread ActivityThread activityThread = Main();

//获取systemContext,并设置theme mSystemContext = temContext(); me(DEFAULT_SYSTEM_THEME); //获取systemUiContenx ,设置theme final Context systemUiContext = temUiContext(); me(DEFAULT_SYSTEM_THEME);}3.1 创建ActivityThread

SystemServer创建SystemContext时序图.png

static ContextImpl createAppContext(ActivityThread mainThread, LoadedApk packageInfo, String opPackageName) { if (packageInfo == null) throw new IllegalArgumentException("packageInfo"); //1.2.2.1 ContextImpl context = new ContextImpl(null, mainThread, packageInfo, null, null, null, 0, null, opPackageName); ources(ources()); return context; }}//blic final class LoadedApk { LoadedApk(ActivityThread activityThread) { mActivityThread = activityThread; mApplicationInfo = new ApplicationInfo(); eName = "android"; mPackageName = "android"; mAppDir = null; mResDir = null; mSplitAppDirs = null; mSplitResDirs = null; mSplitClassLoaderNames = null; mOverlayDirs = null; mDataDir = null; mDataDirFile = null; mDeviceProtectedDataDirFile = null; mCredentialProtectedDataDirFile = null; mLibDir = null; mBaseClassLoader = null; mSecurityViolation = false; mIncludeCode = true; mRegisterPackage = false; mResources = tem(); mDefaultClassLoader = temClassLoader(); mAppComponentFactory = createAppFactory(mApplicationInfo, mDefaultClassLoader); mClassLoader = tiateClassLoader(mDefaultClassLoader, new ApplicationInfo(mApplicationInfo)); }

//1.3.1 public Application makeApplication(boolean forceDefaultAppClass, Instrumentation instrumentation) { if (mApplication != null) { return mApplication; } Application app = null; String appClass = ame; if (forceDefaultAppClass || (appClass == null)) { appClass = "ation"; } try { oader cl = getClassLoader(); if (!("android")) { egin(_TAG_ACTIVITY_MANAGER, "initializeJavaContextClassLoader"); initializeJavaContextClassLoader(); nd(_TAG_ACTIVITY_MANAGER); } ContextImpl appContext = AppContext(mActivityThread, this); //1.3.1.1 app = lication( cl, appClass, appContext); erContext(app); } catch (Exception e) { if (!ption(app, e)) {