在SystemUIApplication onCreate时回调 ContextAvailableCallback, 构建SystemUIFactory,并对它进行初始化
src/com/android/systemui/SystemUIFactory.java
public static void createFromConfig(Context context, boolean fromTest) {
if (mFactory != null) {
return;
}
final String clsName = context.getString(R.string.config_systemUIFactoryComponent);
if (clsName == null || clsName.length() == 0) {
throw new RuntimeException("No SystemUIFactory component configured");
}
try {
Class<?> cls = null;
cls = context.getClassLoader().loadClass(clsName);
// 创建SystemUIFactory实例
mFactory = (SystemUIFactory) cls.newInstance();
// 初始化SystemUIFactory
mFactory.init(context, fromTest);
} catch (Throwable t) {
Log.w(TAG, "Error creating SystemUIFactory component: " + clsName, t);
throw new RuntimeException(t);
}
}
public void init(Context context, boolean fromTest)
throws ExecutionException, InterruptedException {
...
// 获取dagger组件
mRootComponent = buildGlobalRootComponent(context);
...
// 获取systemui的dagger组件
// And finally, retrieve whatever SysUI needs from WMShell and build SysUI.
SysUIComponent.Builder builder = mRootComponent.getSysUIComponent();
mSysUIComponent = builder.build();
...
// 构建Dependency实例并初始化
// Every other part of our codebase currently relies on Dependency, so we
// really need to ensure the Dependency gets initialized early on.
Dependency dependency = mSysUIComponent.createDependency();
dependency.start();
}
protected GlobalRootComponent buildGlobalRootComponent(Context context) {
return DaggerGlobalRootComponent.builder()
.context(context)
.build();
}
Dependency组件使用@Lazy标签懒加载: 首先构建LazyDependencyCreator放入mProviders,然后在真正使用dependency时调用createDep