SystemUI是安卓的一个系统APP,负责的内容有系统通知栏,状态栏,最近应用程序,锁屏,壁纸,屏保,系统对话框,截屏,录屏等功能。

Apk的路径位于/system/priv-app,源码code位于frameworks/base/packages/SystemUI

1.Android.mk

2.AndroidManifest.xml配置文件表明了APP要求的权限,特征以及四大组件。

3.初始化流程

1.SystemUI启动

SystemUI是核心系统应用,需要开机启动,启动SystemUI进程,是通过启动SystemUIService来实现的。
 
 
frameworks\base\services\java\com\android\server\SystemServer.java
 
SystemServer启动后,会在SystemServer Main Thread启动ActivityManagerService,当ActivityManagerService  systemReady后,会去启动SystemUIService。
 
 mActivityManagerService.systemReady(new Runnable() {
            @Override
            public void run() {
           ...
           try {
                    startSystemUi(context);
                } catch (Throwable e) {
                    reportWtf("starting System UI", e);
                }
由如上可以看出,startSystemUi不是在SystemServer Main thread,而是在ActivityManagerService Thread。
 
 static final void startSystemUi(Context context) {
        Intent intent = new Intent();
        intent.setComponent(new ComponentName("com.android.systemui",
                    "com.android.systemui.SystemUIService"));
        //Slog.d(TAG, "Starting service: " + intent);
        context.startServiceAsUser(intent, UserHandle.OWNER);
    }
通过startServiceAsUser,SystemUIService就启动了,即SystemUI进程开机启动。
 
 

2.SystemUI Services启动

SystemServer启动SystemUIService后,会走到SystemUIService的onCreate函数。
public class SystemUIService extends Service {

@Override
    public void onCreate() {
        super.onCreate();
        ((SystemUIApplication) getApplication()).startServicesIfNeeded();
    }

SystemUIService就是一个普通的Service,在onCreate里面,会调用SystemUIApplication的services
 
/**
 * Application class for SystemUI.
 */
public class SystemUIApplication extends Application {

private static final String TAG = "SystemUIService";
    private static final boolean DEBUG = false;

/**
     * The classes of the stuff to start.
     */
    private final Class<?>[] SERVICES = new Class[] {
            com.android.systemui.tuner.TunerService.class,
            com.android.systemui.keyguard.KeyguardViewMediator.class,
            com.android.systemui.recents.Recents.class,
            com.android.systemui.volume.VolumeUI.class,
            com.android.systemui.statusbar.SystemBars.class,
            com.android.systemui.usb.StorageNotification.class,
            com.android.systemui.power.PowerUI.class,
            com.android.systemui.media.RingtonePlayer.class,
    };

 
SystemUIApplication是一个Application实现,重写Application相关函数。
SystemUIApplication定义了很多System Panel,这里叫做SERVICES,但是并非是真正的service.
 
SystemUI应用定义了一个抽象的SystemUI类,根据Java抽象化的特征,可以使开发更加灵活。
 
SystemUI相关的类图关系如下:
从SystemUI继承了很多的Panel,这些Panel有我们很熟悉的,比如Recents(近期任务栏),VolumeUI(音量条),SystemBars(状态栏)等。
 
 
回到SystemUIApplication里的startService函数:
  1. /**
  2. * Makes sure that all the SystemUI services are running. If they are already running, this is a
  3. * no-op. This is needed to conditinally start all the services, as we only need to have it in
  4. * the main process.
  5. *
  6. * <p>This method must only be called from the main thread.</p>
  7. */
  8. public void startServicesIfNeeded() {
  9. if (mServicesStarted) {
  10. return;
  11. }
  12. if (!mBootCompleted) {
  13. // check to see if maybe it was already completed long before we began
  14. // see ActivityManagerService.finishBooting()
  15. if ("1".equals(SystemProperties.get("sys.boot_completed"))) {
  16. mBootCompleted = true;
  17. if (DEBUG) Log.v(TAG, "BOOT_COMPLETED was already sent");
  18. }
  19. }
  20. Log.v(TAG, "Starting SystemUI services.");
  21. final int N = SERVICES.length;
  22. for (int i=0; i<N; i++) {
  23. Class<?> cl = SERVICES[i];
  24. if (DEBUG) Log.d(TAG, "loading: " + cl);
  25. try {
  26. mServices[i] = (SystemUI)cl.newInstance();
  27. } catch (IllegalAccessException ex) {
  28. throw new RuntimeException(ex);
  29. } catch (InstantiationException ex) {
  30. throw new RuntimeException(ex);
  31. }
  32. mServices[i].mContext = this;
  33. mServices[i].mComponents = mComponents;
  34. if (DEBUG) Log.d(TAG, "running: " + mServices[i]);
  35. mServices[i].start();
  36. if (mBootCompleted) {
  37. mServices[i].onBootCompleted();
  38. }
  39. }
  40. mServicesStarted = true;
  41. }
这个函数主要是实例化以及启动SystemUI Services(这里的Service并非是真正的service),这样通过SystemUIService的启动,SystemUI核心的services也启动了。
 
 
在SystemUIApplication类的onCreate里面,会注册开机完成广播,并将开机完成事件,给到SystemUI Services.
  1. @Override
  2. public void onCreate() {
  3. super.onCreate();
  4. // Set the application theme that is inherited by all services. Note that setting the
  5. // application theme in the manifest does only work for activities. Keep this in sync with
  6. // the theme set there.
  7. setTheme(R.style.systemui_theme);
  8. IntentFilter filter = new IntentFilter(Intent.ACTION_BOOT_COMPLETED);
  9. filter.setPriority(IntentFilter.SYSTEM_HIGH_PRIORITY);
  10. registerReceiver(new BroadcastReceiver() {
  11. @Override
  12. public void onReceive(Context context, Intent intent) {
  13. if (mBootCompleted) return;
  14. if (DEBUG) Log.v(TAG, "BOOT_COMPLETED received");
  15. unregisterReceiver(this);
  16. mBootCompleted = true;
  17. if (mServicesStarted) {
  18. final int N = mServices.length;
  19. for (int i = 0; i < N; i++) {
  20. mServices[i].onBootCompleted();
  21. }
  22. }
  23. }
  24. }, filter);
  25. }

SystemUI Services启动后,根据各Services的功能,SystemUI开始各司其职的正常工作起来。

SystemUI分析的更多相关文章

  1. 第三方apk内置因签名导致SystemUI未启动启动问题案例分析

    这个问题是刷完机正常开机后,发现手机无状态栏,下拉通知栏,按音量键也无法出现VolumeDialog,开始看到这个现象感觉是systemUI未编译到版本中去?或者是在systemserver中syst ...

  2. 【转】android SystemUI 流程分析

    android4 SystemUI 流程分析 什么是SystemUI? 对于Phone来说SystemUI指的是:StatusBar(状态栏).NavigationBar(导航栏).而对于Tablet ...

  3. Android之SystemUI载入流程和NavigationBar的分析

    Android之SystemUI载入流程和NavigationBar的分析 本篇仅仅分析SystemUI的载入过程和SystemUI的当中的一个模块StatusBar的小模块NavigationBar ...

  4. Android8.1 MTK平台 SystemUI源码分析之 网络信号栏显示刷新

    SystemUI系列文章 Android8.1 MTK平台 SystemUI源码分析之 Notification流程 Android8.1 MTK平台 SystemUI源码分析之 电池时钟刷新 And ...

  5. Android8.1 SystemUI源码分析之 电池时钟刷新

    SystemUI源码分析相关文章 Android8.1 SystemUI源码分析之 Notification流程 分析之前再贴一下 StatusBar 相关类图 电池图标刷新 从上篇的分析得到电池图标 ...

  6. Android8.1 SystemUI源码分析之 Notification流程

    代码流程 1.先看UI显示,StatuBar加载 CollapsedStatusBarFragment 替换 status_bar_container(状态栏通知显示区域) SystemUI\src\ ...

  7. Android源码分析(十三)----SystemUI下拉状态栏如何添加快捷开关

    一:如何添加快捷开关 源码路径:frameworks/base/packages/SystemUI/res/values/config.xml 添加headset快捷开关,参考如下修改. Index: ...

  8. Android SystemUI源代码分析和修改

    1.在导航栏中添加音量加减button 一些Android音量调节button.或者从保护实体按键的角度考虑,就须要在导航栏的虚拟按键中加入音量加减调节按键. 效果例如以下图所看到的: 实现步骤例如以 ...

  9. Android ANR 分析解决方法

    一:什么是ANR ANR:Application Not Responding,即应用无响应 二:ANR的类型 ANR一般有三种类型: 1. KeyDispatchTimeout(5 seconds) ...

随机推荐

  1. 阶段1 语言基础+高级_1-3-Java语言高级_1-常用API_1_第4节 ArrayList集合_14-ArrayList集合的常用方法和循环

    常用的方法记下来 刚创建好,什么都不放的 add添加方法肯定是成功的. 加了这么多的值都没有用返回值,输出的结果可以看到都是添加成功的 获取索引值 ALT+回车键,推荐使用本地变量去接收 这样左边就会 ...

  2. Dnsmasq 安装配置

    Dnsmasq  官网 http://www.thekelleys.org.uk/dnsmasq/doc.html Unbuntu 安装 Dnsmasq 参见https://help.ubuntu.c ...

  3. python中5个json库的速度对比

    python中json的序列化与反序列化有很多库,具体选择使用哪一个,或者哪一个速度更快呢? 先上结果 json序列化与反序列化速度对比(按总时间排序:测试数据100 * 10000) ujson 序 ...

  4. 刷题——一道全排列的题目(Permutations)

    题目内容: 思路其实很简单,那就是暴力交换顺序,直接迭代出所有可能.先在一个位置固定一个数字,然后对剩下的数字进行排列,用同样的方法对剩下的数字进行排列(因此要用到递归,不用也行,但是会复杂一点,这里 ...

  5. IDEA-包层级结构显示(三)

    IntelliJ IDEA包层级结构显示 如:A.B.C,在项目中希望以如下形式显示: A B C 效果: 再更换为A.B.C形式显示

  6. c#工厂模式

    创建一个抽象类: public abstract class Test {  public abstract void Print();//输出信息} 创建输出123的测试类 public class ...

  7. WebServiceBinding属性

    属性 类型 读 写 说明 ConformsTo Wsiprofiles x x 绑定需要遵守的WS-I标准 EmitConformanceClaims Boolean     如果为true,当WSD ...

  8. [Python3 填坑] 017 实例方法、静态方法、类方法的区别

    目录 1. print( 坑的信息 ) 2. 开始填坑 2.1 先上例子 2.2 分析 1. print( 坑的信息 ) 挖坑时间:2019/04/07 明细 坑的编码 内容 Py024-1 实例方法 ...

  9. FastDFS搭建单机图片服务器(一)

    防丢失转载:https://blog.csdn.net/MissEel/article/details/80856194 根据 分布式文件系统 - FastDFS 在 CentOS 下配置安装部署 和 ...

  10. ASP.NET中Literal控件的使用方法(用于向网页中动态添加内容)

    原文:https://www.jb51.net/article/82855.htm 可以将 Literal 控件用作网页上其他内容的容器.Literal 控件最常用于向网页中动态添加内容.简单的讲,就 ...