SystemServer启动流程

SystemServer被zygote启动后会运行到main函数,在这里面直接运行到run方法

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

在run方法中,会做一些初始化,之后启动其他服务,最终进入Loop循环

private void run() {
	Looper.prepareMainLooper();
	nativeInit();
	createSystemContext();
	
	mSystemServiceManager = new SystemServiceManager(mSystemContext);
	LocalServices.addService(SystemServiceManager.class, mSystemServiceManager);

	startBootstrapServices();
	startCoreServices();
	startOtherServices();
	
	Looper.loop();
}

nativeInit函数在com_android_server_SystemServer.cpp中,开启传感器服务

SensorService::instantiate();

createSystemContext函数创建ActivityThread,并创建mSystemContext

    private void createSystemContext() {
        ActivityThread activityThread = ActivityThread.systemMain();
        mSystemContext = activityThread.getSystemContext();
        mSystemContext.setTheme(android.R.style.Theme_DeviceDefault_Light_DarkActionBar);
    }

在startBootstrapServices中通过classloader加载类名并调用他们的start方法开启了一些重要的的系统服务

mActivityManagerService
mPowerManagerService
mDisplayManagerService
mPackageManagerService

在startCoreService中开启了

LightsService
BatteryService
UsageStatsService
UsageStatsManagerInternal
WebViewUpdateService

在startOtherServices中进行了一大堆初始化,最后运行到初始化UI

// 这里启动了launcher
 mActivityManagerService.systemReady()
 
startSystemUi(context)

这里是发送了一个Intent

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);
    }

这里实际是运行到了SystemUIApplication,就是启动一些系统UI

    private final Class<?>[] SERVICES = new Class[] {
            com.android.systemui.keyguard.KeyguardViewMediator.class,
            com.android.systemui.recent.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
    };
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值