systemUI启动流程
-
frameworks\base\services\java\com\android\server\SystemServer.java
public final class SystemServer {
private static final TimingsTraceLog BOOT_TIMINGS_TRACE_LOG;
private SystemServiceManager mSystemServiceManager;
public static void main(String[] args) {
new SystemServer().run();
}
private void run() {
...
// Start services.
try {
startBootstrapServices();
}catch(){...}
}
private void startBootstrapServices() {
...
// Todo: Might need to move after migration to WM.
ActivityTaskManagerService atm =
mSystemServiceManager.startService(ActivityTaskManagerService.Lifecycle.class).getService();
mActivityManagerService = ActivityManagerService.Lifecycle.startService(
mSystemServiceManager, atm);
mActivityManagerService.setSystemServiceManager(mSystemServiceManager);
mActivityManagerService.setInstaller(installer);
mWindowManagerGlobalLock = atm.getGlobalLock();
traceEnd();
}
}
mActivityManagerService.systemReady(() -> {
traceBeginAndSlog("StartsystemUI");
try {
startsystemUI(context, windowManagerF);
} catch (Throwable e) {
reportWtf("starting System UI", e);
}
traceEnd();
},BOOT_TIMINGS_TRACE_LOG);
//正式启动systemUI 入口:com.android.systemUI.systemUIService.java
private static void startsystemUI(Context context, WindowManagerService windowManager) {
Intent intent = new Intent();
intent.setComponent(new ComponentName("com.android.systemUI","com.android.systemUI.systemUIService"));
intent.addFlags(Intent.FLAG_DEBUG_TRIAGED_MISSING);
//Slog.d(TAG, "Starting service: " + intent);
context.startServiceAsUser(intent, UserHandle.SYstem);
windowManager.onsystemUIStarted();
}
-
启动systemUIService: com.android.systemUI.systemUIService.java
public class systemUIService extends Service {
@Override
public void onCreate() {
super.onCreate();
((systemUIApplication)getApplication()).startServicesIfNeeded();
}
}
-
com.android.systemUI.systemUIApplication.java
public class systemUIApplication extends Application implements SysUiServiceProvider {
private systemUI[] mServices;
@Override
public void onCreate() {
super.onCreate();
systemUIFactory.createFromConfig(this);
}
public void startServicesIfNeeded() { //系统服务(systemUIservice启动时执行该方法
String[] names = getResources().getStringArray(R.array.config_systemUIServiceComponents);
startServicesIfNeeded(names);
}
private void startServicesIfNeeded(String[] services) {
mServices = new systemUI[services.length];
final int N = services.length;
//反射机制,获取SysUI对象,对象列表所在数组:R.array.config_systemUIServiceComponents
for (int i = 0; i < N; i++) {
String clsName = services[i];
if (DEBUG) Log.d(TAG, "loading: " + clsName);
log.traceBegin("StartServices" + clsName);
long ti = System.currentTimeMillis();
Class cls;
try {
cls = Class.forName(clsName);
Object o = cls.newInstance();
if (o instanceof systemUI.Injector) {
o = ((systemUI.Injector) o).apply(this);
}
mServices[i] = (systemUI) o;//Dependency$DependencyCreator+NotificationChannels.java
}catch(){..}
mServices[i].mContext = this;
mServices[i].mComponents = mComponents;
mServices[i].start();//反射结果.start() //SysUI组件extends systemUI ,通过start()方法启动
}
//添加插件:OverLayPlugin.java
Dependency.get(PluginManager.class).addpluginListener(..,OverlayPlugin.class, true)
}
} -
systemUI子类,入口:start()
1. NotificationChannels.java
public class NotificationChannels extends systemUI {
public Context mContext;
@Override
public void start() {
createall(mContext);
}
}
2.KeyguardViewMediator.java
public class KeyguardViewMediator extends systemUI {
@Override
public void start() {
synchronized (this) {
setupLocked();
}
putComponent(KeyguardViewMediator.class, this);
}
}
.....
-
<!-- systemUI Services: The classes of the stuff to start. -->
<string-array name="config_systemUIServiceComponents" translatable="false">
<item>com.android.systemUI.Dependency$DependencyCreator</item> //依赖
<item>com.android.systemUI.util.NotificationChannels</item> //创建systemUI的通知Channel
<item>com.android.systemUI.statusbar.CommandQueue$CommandQueueStart</item>
<item>com.android.systemUI.keyguard.KeyguardViewMediator</item>
<item>com.android.systemUI.recents.Recents</item> //最近任务
<item>com.android.systemUI.volume.VolumeUI</item> //音量面板
<item>com.android.systemUI.stackdivider.Divider</item> //分屏
<item>com.android.systemUI.SystemBars</item>
<item>com.android.systemUI.usb.StorageNotification</item> //存储设备相关通知
<item>com.android.systemUI.power.PowerUI</item> //低电量提醒
<item>com.android.systemUI.media.ringtonePlayer</item> //手机铃声
<item>com.android.systemUI.keyboard.KeyboardUI</item> //键盘
<item>com.android.systemUI.pip.PipUI</item> //画中画
<item>com.android.systemUI.shortcut.ShortcutKeydispatcher</item>
<item>@string/config_systemUIvendorServiceComponent</item>
<item>com.android.systemUI.util.leak.GarbageMonitor$Service</item> //定期检查systemUI堆内存并报告
<item>com.android.systemUI.LatencyTester</item> // 在DEBUGGABLE版本运行,用于测试系统中的延迟
<item>com.android.systemUI.globalactions.GlobalActionsComponent</item> // 关机菜单
<item>com.android.systemUI.Screendecorations</item> //手机屏幕屏切圆角,模拟刘海屏
<item>com.android.systemUI.biometrics.BiometricDialogImpl</item>
<item>com.android.systemUI.SlicebroadcastRelayHandler</item>
<item>com.android.systemUI.SizeCompatModeActivityController</item>
<item>com.android.systemUI.statusbar.notification.InstantAppNotifier</item> //显示Instant Apps(用户设备不需要安装的应用)的通知
<item>com.android.systemUI.theme.ThemeOverlayController</item>
</string-array>
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。