Android5.1 SystemUI 启动流程
16lz
2021-01-26
概述
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 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(); // 启动子服务
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(安卓)launcher3布局和结构
- Android(安卓)6.0 MT流程
- Android之常见图标尺寸
- SwipeRefreshLayout和ListView的EmptyView共存冲突的问题
- Android版本适配(基于 6.0 ~ 9.0)
- Android(安卓)2.0环境下的图标设计原则
- Android中使用Notification并通过点击Notification启动启动通知
- Android(安卓)开发中踩过的坑之一: RemoteView可能造成内存泄露
- Android开发之如何使用通知提醒功能(Notifications)