当前位置: 首页 > news >正文

Android 10.0 SystemUI启动流程

1、手机开机后,Android系统首先会创建一个Zygote(核心进程)。
2、由Zygote启动SystemServer。
3、SystemServer会启动系统运行所需的众多核心服务和普通服务、以及一些应用及数据。例如:SystemUI 启动就是从 SystemServer 里启动的。
4、进入锁屏界面,开机完成。

SystemServer 中有一个 main()方法为系统服务的入口;
frameworks/base/services/java/com/android/server/SystemServer.java

    /*** The main entry point from zygote.*/public static void main(String[] args) {new SystemServer().run();}

在SystemServer 中的 main()方法中,就一句代码生成 SystemServer 对象,执行run 方法。在run()方法里启动了各类服务;
frameworks/base/services/java/com/android/server/SystemServer.java

private void run() {//省略部分代码// Start services.try {traceBeginAndSlog("StartServices");startBootstrapServices();startCoreServices();startOtherServices();    // 在该方法里启动了 SystemUI的服务。SystemServerInitThreadPool.shutdown();} catch (Throwable ex) {Slog.e("System", "******************************************");Slog.e("System", "************ Failure starting system services", ex);throw ex;} finally {traceEnd();}//省略部分代码
}
private void startOtherServices() {//省略部分代码t.traceBegin("StartSystemUI");try {startSystemUi(context, windowManagerF);} catch (Throwable e) {reportWtf("starting System UI", e);}t.traceEnd();//省略部分代码
}
private static void startSystemUi(Context context, WindowManagerService windowManager) {PackageManagerInternal pm = LocalServices.getService(PackageManagerInternal.class);Intent intent = new Intent();intent.setComponent(pm.getSystemUiServiceComponent());intent.addFlags(Intent.FLAG_DEBUG_TRIAGED_MISSING);//Slog.d(TAG, "Starting service: " + intent);context.startServiceAsUser(intent, UserHandle.SYSTEM);windowManager.onSystemUiStarted();}

SystemServer执行流程图:

SystemUi进入到SystemUIService的onCreate()方法里;在onCreate()方法中获得 SystemUIApplication 对象并调用其 startServicesIfNeeded() 方法
frameworks/base/packages/SystemUI/src/com/android/systemui/SystemUIService.java

    @Overridepublic void onCreate() {super.onCreate();// Start all of SystemUI((SystemUIApplication) getApplication()).startServicesIfNeeded();// 省略部分代码...}/*** Makes sure that all the SystemUI services are running. If they are already running, this is a* no-op. This is needed to conditinally start all the services, as we only need to have it in* the main process.* <p>This method must only be called from the main thread.</p>*/public void startServicesIfNeeded() {String[] names = getResources().getStringArray(R.array.config_systemUIServiceComponents);startServicesIfNeeded(names);}

在SystemUIApplication中查看startServicesIfNeeded() 方法,其中其中 config_systemUIServiceComponents 值在frameworks/base/packages/SystemUI/res/values/config.xml 里:
frameworks/base/packages/SystemUI/src/com/android/systemui/SystemUIApplication.java

private void startServicesIfNeeded(String[] services) {if (mServicesStarted) {return;}mServices = new SystemUI[services.length];if (!mBootCompleted) {// check to see if maybe it was already completed long before we began// see ActivityManagerService.finishBooting()if ("1".equals(SystemProperties.get("sys.boot_completed"))) {mBootCompleted = true;if (DEBUG) Log.v(TAG, "BOOT_COMPLETED was already sent");}}Log.v(TAG, "Starting SystemUI services for user " +Process.myUserHandle().getIdentifier() + ".");TimingsTraceLog log = new TimingsTraceLog("SystemUIBootTiming",Trace.TRACE_TAG_APP);log.traceBegin("StartServices");final int N = services.length;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);mServices[i] = (SystemUI) cls.newInstance();} catch(ClassNotFoundException ex){throw new RuntimeException(ex);} catch (IllegalAccessException ex) {throw new RuntimeException(ex);} catch (InstantiationException ex) {throw new RuntimeException(ex);}mServices[i].mContext = this;mServices[i].mComponents = mComponents;if (DEBUG) Log.d(TAG, "running: " + mServices[i]);mServices[i].start();log.traceEnd();//省略其他代码}
}

可以看到 startServicesIfNeeded() 循环 start 了config_systemUIServiceComponents 里的 Service,这些服务不是四大组件之一的 Service, 而是继承自 SystemUI 接口的服务,我们称之为 SystemUI服务。
到此SystemUI 启动流程分析完毕。

http://www.lryc.cn/news/394635.html

相关文章:

  • 洛谷 P1032 [NOIP2002 提高组] 字串变换
  • 网络资源模板--Android Studio 外卖点餐App
  • 【Linux】网络新手村
  • 123123
  • 在pycharm中使用jupyter
  • MongoDB:掌握核心常用命令语句,精通数据操作
  • Redis中测试Stream的例子
  • 28 H3C SecPath F1000 概览(主要功能是总 观看全局)
  • 标准版视频检测终端功能有哪些? 捷顺高清视频车位引导系统怎么样?
  • 说明本文档目录是软件开发梳理需求常见问题QA文档,方便客户看,也方便我们的售前人员,需求分析人员,ui设计师,原型绘图人员,思维导图绘图人员查看。
  • Echarts桑基图
  • wordpress网站添加一个临时维护功能
  • 充电桩开源平台,开发流程有图有工具
  • 数据中台设计书及建设指南(中台及大数据解决技术方案)
  • 合合信息大模型“加速器”重磅上线
  • # Sharding-JDBC 从入门到精通(10)- 综合案例(三)查询商品与测试及统计商品和总结
  • ASRock Creator系列GPU:为AI推理及多GPU系统打造,采用16针电源接口的Radeon RX 7900系列显卡
  • AntV X6 图编辑引擎速通
  • 【若依前后端分离】通过输入用户编号自动带出部门名称(部门树)
  • AIGC时代程序员的跃迁——编程高手的密码武器
  • 园区智慧能源可视化:智能监控与优化能源管理
  • Linux内网端口转公网端口映射
  • 银河麒麟高级服务器操作系统(通用)安装和编译指定的python3版本
  • cs231n 作业3
  • HarmonyOS Next系列之Echarts图表组件(折线图、柱状图、饼图等)实现(八)
  • 网上怎么样可以挣钱,分享几种可以让你在家赚钱的兼职项目
  • 【DevOps】运维过程中经常遇到的Http错误码问题分析(二)
  • 数据结构练习
  • 手动安装Ruby 1.9.3并升级RubyGems
  • go语言day11 错误 defer(),panic(),recover()