首页 > 其他分享 >Android 10.0 SystemUI启动流程

Android 10.0 SystemUI启动流程

时间:2024-07-08 19:55:59浏览次数:7  
标签:10.0 void ex startServicesIfNeeded services Android SystemUI SystemServer

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

    @Override
    public 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 启动流程分析完毕。

标签:10.0,void,ex,startServicesIfNeeded,services,Android,SystemUI,SystemServer
From: https://blog.csdn.net/u010345983/article/details/134181653

相关文章

  • 晚上定时编译android系统
    1、问题可能偶然想晚上定时编译android系统2、解决at.sh#!/bin/sh#at-fat.shnow+1min#at-lset-eset-xecho$SHELLecho'atbuildbegin'/bin/date>>at_build.log/bin/bash-c'sourcebuild/envsetup.sh>>at_build.log2>&1;lu......
  • Android开发——使用Android Studio封装SDK(二) jar
    前言:什么叫SDK?  软件开发工具包(SoftwareDevelopmentKit,缩写SDK)一般是一些软件工程师为特定的软件包、软件框架、硬件平台、操作系统等建立应用软件时的开发工具的集合。  Android常见的SDK有哪些形式?   (1).so库:是C或C++语言而打包成的库。   (2)......
  • 手机数据恢复:如何在没有root的情况下恢复Android数据?
    您是否不小心从Android设备中删除了重要数据?您是否担心如何取回您的照片、视频和文档?有时,我们不小心删除了重要数据,并使用Androidroot方法取回文件。许多用户不喜欢root他们的Android设备,因为这是一种复杂的方法。在本指南中,我们将告诉您如何使用最好的Android数据恢复软件奇......
  • Android 集成 Unity上的坑
    转载自CSDN1.Unity版本的差异Unity的版本在2019及其以下选择Mono方式打包出Android项目,反之选择IL2CPP方式打包Android项目为什么我会说这个Unity版本上会存在差异呢?因为我在工作时发现,我们项目原本是要升级到2022最新版的,但是发现2022用Mono方式打包出来的Android项目运行到An......
  • Android Studio实战演练-仿网易音乐播放器扩展
    效果图:首先按书里面一样敲出一首歌的播放也可以参考可以参考博主“林林要一直努力”写的,一首歌如下所示:林林要一直努力他写的教程链接AndroidStudio初学者实例:仿网易音乐播放器-CSDN博客https://blog.csdn.net/m0_59558544/article/details/131151435然后更改代码首先,多......
  • android中activity与fragment之间的各种跳转
    我们以音乐播放、视频播放、用户注册与登录为例【Musicfragment(音乐列表页)、Videofragment(视频列表页)、MusicAvtivity(音乐详情页)、VideoFragment(视频详情页)、LoginActivity(用户登录)、RegisterActivity(用户注册)】目录1.activity与activity之间的跳转2.activity与fragment之间......
  • 【计算机毕业设计】springboot基于Android的大学生勤工助学管理系统设计与实现
    大学生勤工助学管理系统设计的目的是为用户提供企业招聘、已投简历等方面的平台。与PC端应用程序相比,大学生勤工助学管理系统的设计主要面向于大学生勤工助学,旨在为管理员和学生、企业提供一个Android的大学生勤工助学管理系统。学生可以通过Android及时查看企业招聘等。......
  • android7.0以上调用系统相机拍照并显示到ImageView上
     /**第一步:新建文件res/xml/file_paths.xml<pathsxmlns:android="http://schemas.android.com/apk/res/android"><external-pathpath="."name="camera_photos"/></paths>*第二步:AndroidManifest.xml文件的a......
  • Android 13.0 mt6771新增分区功能实现一
    1.前言 在13.0的系统ROM定制化开发中,在对某些特殊模块中关于数据的存储方面等需要新增分区来保存,所以就需要在系统分区新增相关的分区,来实现功能,接下来就来实现这个功能,来新增分区功能2.mt6771新增分区功能实现一的核心类build/make/core/Makefilebuild/make/cor......
  • Android面试题自定义View之Window、ViewRootImpl和View的三大流程
    本文首发于公众号“AntDream”,欢迎微信搜索“AntDream”或扫描文章底部二维码关注,和我一起每天进步一点点View的三大流程指的是measure(测量)、layout(布局)、draw(绘制)。下面我们来分别看看这三大流程View的measure(测量)MeasureSpecMeasureSpec是View的一个内部静......