SystemUI类是SystemUI应用中一些子服务的基类。
public abstract class SystemUI implements SysUiServiceProvider {
public Context mContext;
public Map<Class<?>, Object> mComponents;//根据Class存放共享对象
public abstract void start();//启动方法,进行初始化
protected void onConfigurationChanged(Configuration newConfig) {//状态发生变化
}
public void dump(FileDescriptor fd, PrintWriter pw, String[] args) {//用来将模块的内部状态dump到输出流中,这个方法主要是辅助调试所用。开发者可以在开发过程中,通过adb shell执行dump来了解系统的内部状态。
}
protected void onBootCompleted() {//系统启动完成
}
@SuppressWarnings("unchecked")
public <T> T getComponent(Class<T> interfaceType) {//获取对象
return (T) (mComponents != null ? mComponents.get(interfaceType) : null);
}
public <T, C extends T> void putComponent(Class<T> interfaceType, C component) {//存放对象
if (mComponents != null) {
mComponents.put(interfaceType, component);
}
}
public static void overrideNotificationAppName(Context context, Notification.Builder n,
boolean system) {//设置通知应用名称
final Bundle extras = new Bundle();
String appName = system
? context.getString(com.android.internal.R.string.notification_app_name_system)
: context.getString(com.android.internal.R.string.notification_app_name_settings);
extras.putString(Notification.EXTRA_SUBSTITUTE_APP_NAME, appName);
n.addExtras(extras);
}
public interface Injector extends Function<Context, SystemUI> {//用来创建SystemUI
}
}
SystemUI的创建方式有两种:
直接反射创建SystemUI对象或者
反射创建SystemUI.Injector对象,调用Injector的apply方法创建SystemUI对象。
mComponents在SystemUIApplication中创建,每个SystemUI被创建后都会将mComponents指向SystemUIApplication中创建的mComponents对象,也就是说所有SystemUI共享一个mComponents对象。
每个SystemUI对象在start方法结束时都会将本身或相关对象放入mComponents中,这样一来,mComponents存放了所有SystemUI类或相关对象,每个SystemUI对象可以直接获取其他SystemUI对象,实现跨SystemUI的交互。