com.android.systemui.statusbar.policy.clock,Android SystemUI 源码分析

66b52468c121889b900d4956032f1009.png

8种机械键盘轴体对比

本人程序员,要买一个写代码的键盘,请问红轴和茶轴怎么选?

因为项目需要,所以对 Android 源码中的 SystemUI 做了点基本分析。

平台

Android 5.1

源代码路径

/frameworks/base/packages/SystemUI/src/com/android/systemui/

什么是SystemUI

其实就是Android的系统界面,包括状态栏Status Bar,导航栏Navigation Bar,锁屏界面Keyguard,电源界面PowerUI,最近任务管理Recents 等等。

c8ca8d3793425332ce47e3bc1e4fb02b.png

启动流程

SystemServer.java:1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26public static void main(String[] args){

new SystemServer().run()

}

private void (){

startBootstrapServices(); // 启动系统启动所需的关键服务

startCoreServices(); // 启动基本服务

startOtherServices(); // 启动其他服务

}

private void startOtherServices(){

mActivityManagerService.systemReady(new Runnable() {

public void (){

startSystemUi();

}

});

}

static final void startSystemUi(Context context){

Intent intent = new Intent();

intent.setComponent(new ComponentName("com.android.systemui",

"com.android.systemui.SystemUIService"));

context.startServiceAsUser(intent, UserHandle.OWNER);

}

然后我们进入设置启动 systemui 程序的 SystemUIService.java:1

2

3

4

5public void onCreate(){

super.onCreate();

((SystemUIApplication) getApplication()).startServicesIfNeeded();

}

SystemUIApplication.java:1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26private 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

};

// 这里是拿到每个和 SystemUI 相关的类的反射,存到了 service[] 里,然后赋值给cl,紧接着将通过反射将其转化为具体类的对象,存到了mService[i]数组里,最后对象调 start() 方法启动相关类的服务,启动完成后,回调 onBootCompleted( ) 方法

public void startServicesIfNeeded(){

final int N = SERVICES.length;

for (int i=0; i

Class> cl = SERVICES[i];

mServices[i] = (SystemUI)cl.newInstance();

mServices[i].mContext = this;

mServices[i].mComponents = mComponents;

mServices[i].start();

if (mBootCompleted) {

mServices[i].onBootCompleted();

}

}

}

// 以 SystemBars 的 start() 为例,所以mService[i].start() 先认为是 SystemBars.start()

SystemBars.java:1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22public void start(){

mServiceMonitor = new ServiceMonitor(TAG, DEBUG,

mContext, Settings.Secure.BAR_SERVICE_COMPONENT, this);

mServiceMonitor.start(); // will call onNoService if no remote service is found

}

public void onNoService(){

createStatusBarFromConfig(); // fallback to using an in-process implementation

}

private void createStatusBarFromConfig(){

// R.string.config_statusBarComponent: com.android.systemui.statusbar.phone.PhoneStatusBar

final String clsName = mContext.getString(R.string.config_statusBarComponent);

Class> cls = null;

cls = mContext.getClassLoader().loadClass(clsName);

mStatusBar = (BaseStatusBar) cls.newInstance();

mStatusBar.mContext = mContext;

mStatusBar.mComponents = mComponents;

mStatusBar.start();

}

PhoneStatusBar.java:1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19public void start(){

super.start(); // calls createAndAddWindows()

}

@Override

public void createAndAddWindows(){

addStatusBarWindow();

}

private void addStatusBarWindow(){

makeStatusBarView();

}

// Constructing the view

protected PhoneStatusBarView makeStatusBarView(){

mStatusBarWindow = (StatusBarWindowView) View.inflate(context,

R.layout.super_status_bar, null);

}

通过 super_status_bar.xml 的分析 SystemBars 的大致视图构成了:1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

858f05cc72f9033ffecba96ffc67b1ca.png

status_bar

PhoneStatusBarView 即为手机最上方的状态栏,主要用于显示系统状态,通知等,主要包括 notification icons 和 status bar icons。status_bar.xml 即对应状态栏的视图如下:1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

30d416bb3f2d3e633b3722621f4438e1.png

PanelHolder

PanelHolder是用户下拉 status bar 后得到的 view。它主要包含 QuickSettings 和 Notification panel 两个部分。

status_bar_expanded.xml:1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

android:textAppearance="@style/TextAppearance.StatusBar.Expanded.Network.EmergencyOnly" />

c3abd67a91661a3f57c8983da809e63f.png

SystemUI启动流程图

4b6231a2ba90042ae1f326ffcad233c9.png

9b338b7006be26a6a2c0e50425eb8ef4.png

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值