当前位置:操作系统 > 安卓/Android >>

Android 4.0 ICS SystemUI浅析——SystemUI启动流程

阅读Android 4.0源码也有一段时间了,这次是针对SystemUI的一个学习过程。本文只是对SystemUI分析的一个开始——启动流程的分析,网上有很多关于2.3的SystemUI的分析,可4.0与2.3的差别还是很大的,为了给自己留下笔记同时也方便大家学习和探讨,遂写此文,后续将有更多关于SystemUI的分析,敬请关注。


       1.初始SystemUI

       什么是SystemUI?你或许会觉得这个问题很幼稚,界面上的布局UI显示?系统的UI?如果你是这么想的,那么就大错特错了。我们知道Android 4.0 ICS同时适用于Phone和Tablet(TV),因此,对于Phone来说SystemUI指的是:StatusBar(状态栏)、NavigationBar(导航栏)。而对于Tablet或者是TV来说SystemUI指的是:CombinedBar(包括了StatusBar和NavigationBar)。注:关于Android 4.0的UI介绍请参考这篇文章http://developer.android.com/design/get-started/ui-overview.html#home-all-apps-recents。

       根据上面的介绍,我想大家应该知道SystemUI的具体作用了吧!也就是说我们的Phone的信号,蓝牙标志,Wifi标志等等这些状态显示标志都会在StatusBar上显示。当我们的设备开机后,首先需要给用户呈现的就是各种界面同时也包括了我们的SystemUI,因此对于整个Android系统来说,SystemUI都有举足轻重的作用,那接下来就来看看它的启动流程吧!

       2.启动流程

       这里只是单单的分析启动流程,实际上SystemUI启动过程中涉及到很多东西的调用,这里暂时不分支去介绍,后续会有相关文章的详细分析。那么对于这种分析我还是将自己的分析思路写出来,而不是直接展现已经分析好的结果,当然结果会在最后展示出来。这样做一方面有利于锻炼自己的分析能力,另一方面各位看官也可以找出分析中的利与弊从而更好的取舍。

       首先来看看SystemUI的代码位置,路径:SourceCode/frameworks/base/packages/SystemUI;其次看看它的代码梗概:

 \

图 2.1

      在Android 4.0中,Google整合了Phone和Tablet(TV)的SystemUI,也就说可以根据设备的类型自动匹配相应的SystemUI。这一点是在Android 2.3中是没有的。那么接下来怎么分析呢?打开AndroidManifest.xml可以看到:

[html]
<manifest xmlns:android="http://schemas.android.com/apk/res/android" 
        package="com.android.systemui" 
        coreApp="true" 
        android:sharedUserId="android.uid.system" 
        android:process="system" 
        > 
 
    <uses-permission android:name="android.permission.STATUS_BAR_SERVICE" /> 
    <uses-permission android:name="android.permission.BLUETOOTH" /> 
    <uses-permission android:name="android.permission.BLUETOOTH_ADMIN" /> 
    <uses-permission android:name="android.permission.GET_TASKS" /> 
    <uses-permission android:name="android.permission.MANAGE_USB" /> 
 
    <application 
        android:persistent="true" 
        android:allowClearUserData="false" 
        android:allowBackup="false" 
        android:hardwareAccelerated="true" 
        android:label="@string/app_label" 
        android:icon="@drawable/ic_launcher_settings"> 
 
        <!-- Broadcast receiver that gets the broadcast at boot time and starts 
             up everything else. 
             TODO: Should have an android:permission attribute 
             --> 
        <service android:name="SystemUIService" 
            android:exported="true" 
            /> 
 
        <!-- started from PhoneWindowManager 
             TODO: Should have an android:permission attribute --> 
        <service android:name=".screenshot.TakeScreenshotService" 
            android:process=":screenshot" 
            android:exported="false" /> 
 
        <service android:name=".LoadAverageService" 
                android:exported="true" /> 
 
        <service android:name=".ImageWallpaper" 
                android:permission="android.permission.BIND_WALLPAPER" 
                android:exported="true" /> 
 
        <receiver android:name=".BootReceiver" > 
            <intent-filter> 
                <action android:name="android.intent.action.BOOT_COMPLETED" /> 
            </intent-filter> 
        </receiver> 
        ... ... 
    </application> 
</manifest> 

 

       根据以上代码我们可以发现这其中注册了很多Service,同时也包括了广播。但这里我们只关注SystemUIService,这才是本文的主旨啊。那么首先要找到SystemUIService是如何启动的。对于Service的启动,在我以前的博文中已有提到,这里就不多说了,不外乎startService(intent)和bindService(intent),它们都是以intent为对象,那intent的声明也需要SystemUIService啊,因此我们可以据此搜索关键词"SystemUIService"。

       经过漫长的搜索和比对之后发现,原来,SystemUIService是在SystemServer.java中被启动的,如下所示:


[java]
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.startService(intent); 

这里的startSystemUi()方法则在ServerThread的run()方法中被调用。这里提到SystemServer就不得不提及Android的启动流

补充:移动开发 , Android ,
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,