源码解析开机systemui启动流程

1.SystemServer.java

找到\frameworks\base\services\java\com\android\server\SystemServer

main方法

public static void main(String[] args) {
    new SystemServer().run();
}

run方法中会调用startBootstrapServices() startCoreServices() startOtherServices(),我们需要看的是startOtherServices()

private void run() {

    ...
    // Start services.
        try {
            traceBeginAndSlog("StartServices");
            startBootstrapServices();
            startCoreServices();
            startOtherServices();
            SystemServerInitThreadPool.shutdown();
        } catch (Throwable ex) {
            Slog.e("System", "******************************************");
            Slog.e("System", "************ Failure starting system services", ex);
            throw ex;
        } finally {
            traceEnd();
        }
    ...
}

startOtherServices()中,mActivityManagerService.systemReady 创建线程去执行startSystemUi(context)

private void startOtherServices() {

    ...
    traceBeginAndSlog("StartSystemUI");
            try {
                startSystemUi(context, windowManagerF);
            } catch (Throwable e) {
                reportWtf("starting System UI", e);
            }
            traceEnd();
    ...
}

startSystemUi中开启服务com.android.systemui.SystemUIService 

static final 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();
}

2.SystemUIService.java

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

3.SystemUIApplication.java

SystemBars、StorageNotification、PowerUI都extends SystemUI,通过for循环调用start()方法,mServices[i].start(),start方法中处理各自的逻辑

private final Class<?>[] SERVICES = new Class[]{
        Dependency.class,
        NotificationChannels.class,
        CommandQueue.CommandQueueStart.class,
        KeyguardViewMediator.class,
        Recents.class,//近期应用管理,以堆叠栈的形式展现
        VolumeUI.class,//来用展示或控制音量的变化:媒体音量、铃声音量与闹钟音量
        Divider.class,//控制管理分屏
        SystemBars.class,//通知消息提示和状态展现
        StorageNotification.class,
        PowerUI.class,//主要处理和Power相关的事件,比如省电模式切换、电池电量变化和开关屏事件等
        RingtonePlayer.class,//铃声播放
        KeyboardUI.class,//锁屏模块可以看做单独的应用,提供基本的手机个人隐私保护
        PipUI.class,//提供对于画中画模式的管理
        ShortcutKeyDispatcher.class,
        VendorServices.class,
        GarbageMonitor.Service.class,
        LatencyTester.class,
        GlobalActionsComponent.class,
};


public void startServicesIfNeeded() {

    ...
    LogUtil.v(TAG, "Starting SystemUI services.");
    final int N = SERVICES.length;
    for (int i = 0; i < N; i++) {
        Class<?> cl = SERVICES[i];
        if (DEBUG)
            LogUtil.d(TAG, "loading: " + cl);
        try {
            mServices[i] = (SystemUI) cl.newInstance();
        } catch (IllegalAccessException ex) {
            throw new RuntimeException(ex);
        } catch (InstantiationException ex) {
            throw new RuntimeException(ex);
        }
        mServices[i].mContext = this;
        mServices[i].mComponents = mComponents;
        if (DEBUG)
            LogUtil.d(TAG, "running: " + mServices[i]);
        mServices[i].start();

        if (mBootCompleted) {
            mServices[i].onBootCompleted();
        }
    }
    ...
}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值