Android5.1 SystemUI 启动流程

概述

SystemUI作为android系统自带的默认的系统操作界面,通常包含状态栏,下拉栏。状态栏主要包含一些蓝牙,wifi,信号强度,SD等模块的信息状态,平台深度定制时,
会修改这部分的文件。可以参见一篇米柚的文章:http://www.miui.com/thread-513527-1-1.html , 包含systemui.apk, framework-res.apk的内容。

find android_top_dir  -name "*.mk" |xargs -i  grep -rwnH "SystemUI" {}  // 查找systemui所在目录,android迭代后,很多功能位置发生变化.

启动流程分析

SystemServer.java启动其它服务时startOtherServices会call  startSystemUi来启动SystemUIService服务
    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);
    }

context.startServiceAsUser会调用ContextImpl.java中
    public ComponentName startServiceAsUser(Intent service, UserHandle user) {
        return startServiceCommon(service, user);
    }
startServiceAsUser直接转调startServiceCommon

    private ComponentName startServiceCommon(Intent service, UserHandle user) {
        try {
            validateServiceIntent(service);
            service.prepareToLeaveProcess();
            ComponentName cn = ActivityManagerNative.getDefault().startService(
                mMainThread.getApplicationThread(), service,
                service.resolveTypeIfNeeded(getContentResolver()), user.getIdentifier());
            if (cn != null) {
                if (cn.getPackageName().equals("!")) {
                    throw new SecurityException(
                            "Not allowed to start service " + service
                            + " without permission " + cn.getClassName());
                } else if (cn.getPackageName().equals("!!")) {
                    throw new SecurityException(
                            "Unable to start service " + service
                            + ": " + cn.getClassName());
                }
            }
            return cn;
        } catch (RemoteException e) {
            return null;
        }
    }
startServiceCommon通过ActivityManager.startService 到ActivityManagerService.startService,完成SystemUIService服务的启动。

SystemUIApplication分析

启动SystemUIService服务之后,SystemUIService.onCreate会被调用
    public void onCreate() {
        super.onCreate();
        ((SystemUIApplication) getApplication()).startServicesIfNeeded();
    }
接着SystemUIApplication.startServicesIfNeeded判断是否需要启动,先判断sys.boot_completed属性值
    public void startServicesIfNeeded() {
        if (mServicesStarted) {
            return;
        }

        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.");
        final int N = SERVICES.length;
        for (int i=0; i<N; i++) {
            Class<?> cl = SERVICES[i]; // 所有子服务
            if (DEBUG) Log.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) Log.d(TAG, "running: " + mServices[i]);
            mServices[i].start(); // 启动子服务
</pre></div><pre name="code" class="java">            if (mBootCompleted) {
				mServices[i].onBootCompleted(); // 启动所有子服务 
			} 
		} mServicesStarted = true; 
	}


 
    sys.boot_completed属性值,在系统的boot启动完成时,ActivityManagerService中会进行设置,下面看一下所有的子服务 
   
    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
    };
子服务有KeyguardViewMediator,Recents,VolumeUI,SystemBars,StorageNotification,PowerUI,RingtonePlayer,
KeyguardViewMediator为锁屏模块, 包含 锁屏机制; 
Recents 为 近期任务列表;
VolumeUI为全局音量控制UI;
SystemBars为系统栏;
StorageNotification 为存储信息通知栏;
PowerUI 为电源界面;
RingtonePlayer 为铃声播放;

frameworks\base\packages\SystemUI\src\com\android\systemui\usb 为系统USB挂载,卸载处理的 框架。
遍历调用这些子服务的 start , onBootCompleted函数。

SystemUI  图片定制

systemui使用的图片都在frameworks/base/packages/SystemUI/res/drawable-xxx/ ,根据不同分辨率替换对应图片,注意尺寸即可。

图片信息说明:
battery_low_battery  充电提示
stat_2g3g  下拉通知栏2G/3G切换图标
stat_airplane_on/off  下拉通知栏飞行模式开启/关闭图标
stat_bluetooth_on/off  下拉通知栏蓝牙开启/关闭图标
stat_brightness_auto/mid/on/off  自动调节/适中/开启/关闭下拉通知栏屏幕亮度图标
stat_data_on/off  下拉通知栏数据控制开启/关闭图标
stat_flashlight_on/off  下拉通知栏电筒开启/关闭图标
stat_gps_on/off  下拉通知栏GPS开启/关闭图标
stat_lock_screen_on/off  下拉通知栏锁屏开启/关闭图标
stat_media_xxx  下拉通知栏播放器控制图标
stat_ing_xxx  下拉通知栏声音模式控制图标
stat_orientation_on/off  下拉通知栏转屏控制图标
stat_screen_timeout_on/off  下拉通知栏屏幕超时控制图标
stat_sync_on/off  下拉通知栏同步开启/关闭图标
stat_sys_data_xxx  数据通信图标
stat_sys_no_sim  无sim卡通知图标
stat_sys_signal_x  信号图标
stat_sys_wifi_xwifi  信号图标
stat_vibrate_XXX  震动提示图标
shade_bg  下拉菜单背景
statusbar_background  状态栏背景图片


你可能感兴趣的:(android,SystemUI)