• 什么是SystemUI


    SystemUI是一个系统级apk,位于frameworks\base\packages\SystemUI\   主要功能有:

    状态栏信息显示,比如电池,wifi信号,3G/4G等icon显示
    通知面板,比如系统消息,第三方应用消息
    近期任务栏显示面板,比如长按近期任务快捷键,显示近期使用的应用
    截图服务
    壁纸服务

    SystemUI的启动流程

    SystemServer启动后,会在Main Thread启动ActivityManagerService,当ActivityManagerService systemReady后,会去启动SystemUIService。

    1. private void startOtherServices(@NonNull TimingsTraceAndSlog t) {
    2. mActivityManagerService.systemReady(() -> {
    3. Slog.i(TAG, "Making services ready");
    4. t.traceBegin("StartActivityManagerReadyPhase");
    5. mSystemServiceManager.startBootPhase(t, SystemService.PHASE_ACTIVITY_MANAGER_READY);
    6. t.traceEnd();
    7. t.traceBegin("StartObservingNativeCrashes");
    8. try {
    9. mActivityManagerService.startObservingNativeCrashes();
    10. } catch (Throwable e) {
    11. reportWtf("observing native crashes", e);
    12. }
    13. t.traceEnd();
    14. // No dependency on Webview preparation in system server. But this should
    15. // be completed before allowing 3rd party
    16. final String WEBVIEW_PREPARATION = "WebViewFactoryPreparation";
    17. Future<?> webviewPrep = null;
    18. if (!mOnlyCore && mWebViewUpdateService != null) {
    19. webviewPrep = SystemServerInitThreadPool.submit(() -> {
    20. Slog.i(TAG, WEBVIEW_PREPARATION);
    21. TimingsTraceAndSlog traceLog = TimingsTraceAndSlog.newAsyncLog();
    22. traceLog.traceBegin(WEBVIEW_PREPARATION);
    23. ConcurrentUtils.waitForFutureNoInterrupt(mZygotePreload, "Zygote preload");
    24. mZygotePreload = null;
    25. mWebViewUpdateService.prepareWebViewInSystemServer();
    26. traceLog.traceEnd();
    27. }, WEBVIEW_PREPARATION);
    28. }
    29. if (mPackageManager.hasSystemFeature(PackageManager.FEATURE_AUTOMOTIVE)) {
    30. t.traceBegin("StartCarServiceHelperService");
    31. mSystemServiceManager.startService(CAR_SERVICE_HELPER_SERVICE_CLASS);
    32. t.traceEnd();
    33. }
    34. t.traceBegin("StartSystemUI");
    35. try {
    36. startSystemUi(context, windowManagerF);
    37. } catch (Throwable e) {
    38. reportWtf("starting System UI", e);
    39. }
    40. }
    1. private static void startSystemUi(Context context, WindowManagerService windowManager) {
    2. PackageManagerInternal pm = LocalServices.getService(PackageManagerInternal.class);
    3. Intent intent = new Intent();
    4. intent.setComponent(pm.getSystemUiServiceComponent());
    5. intent.addFlags(Intent.FLAG_DEBUG_TRIAGED_MISSING);
    6. //Slog.d(TAG, "Starting service: " + intent);
    7. context.startServiceAsUser(intent, UserHandle.SYSTEM);
    8. windowManager.onSystemUiStarted();
    9. }

    frameworks\base\services\core\java\android\content\pm\PackageManagerInternal.java

    1. /**
    2. * @return The SystemUI service component name.
    3. */
    4. public abstract ComponentName getSystemUiServiceComponent();

    抽象方法,具体实现在  PackageManagerService

    mContext 是系统的

    frameworks/base/services/core/java/com/android/server/pm/PackageManagerService.java实现

    1. @Override
    2. public ComponentName getSystemUiServiceComponent() {
    3. return ComponentName.unflattenFromString(mContext.getResources().getString(
    4. com.android.internal.R.string.config_systemUIServiceComponent));
    5. }

    frameworks\base\core\res\res\values\config.xml

    1. <string name="config_systemUIServiceComponent" translatable="false"
    2. >com.android.systemui/com.android.systemui.SystemUIServicestring>

    启动SystemUIService

    frameworks\base\packages\SystemUI\src\com\android\systemui\SystemUIService.java

    调用startServicesIfNeeded启动一系列服务

    1. public void onCreate() {
    2. super.onCreate();
    3. // Start all of SystemUI
    4. ((SystemUIApplication) getApplication()).startServicesIfNeeded();
    5. // Finish initializing dump logic
    6. mLogBufferFreezer.attach(mBroadcastDispatcher);
    7. // For debugging RescueParty
    8. if (Build.IS_DEBUGGABLE && SystemProperties.getBoolean("debug.crash_sysui", false)) {
    9. throw new RuntimeException();
    10. }
    11. if (Build.IS_DEBUGGABLE) {
    12. // b/71353150 - looking for leaked binder proxies
    13. BinderInternal.nSetBinderProxyCountEnabled(true);
    14. BinderInternal.nSetBinderProxyCountWatermarks(1000,900);
    15. BinderInternal.setBinderProxyCountCallback(
    16. new BinderInternal.BinderProxyLimitListener() {
    17. @Override
    18. public void onLimitReached(int uid) {
    19. Slog.w(SystemUIApplication.TAG,
    20. "uid " + uid + " sent too many Binder proxies to uid "
    21. + Process.myUid());
    22. }
    23. }, mMainHandler);
    24. }
    25. // Bind the dump service so we can dump extra info during a bug report
    26. startServiceAsUser(
    27. new Intent(getApplicationContext(), SystemUIAuxiliaryDumpService.class),
    28. UserHandle.SYSTEM);
    29. }

    frameworks\base\packages\SystemUI\src\com\android\systemui\SystemUIApplication.java 

    1. public void startServicesIfNeeded() {
    2. String[] names = SystemUIFactory.getInstance().getSystemUIServiceComponents(getResources());
    3. startServicesIfNeeded(/* metricsPrefix= */ "StartServices", names);
    4. }

    调用 mServices[i].start();启动service

    1. private void startServicesIfNeeded(String metricsPrefix, String[] services) {
    2. if (mServicesStarted) {
    3. return;
    4. }
    5. mServices = new SystemUI[services.length];
    6. if (!mBootCompleteCache.isBootComplete()) {
    7. // check to see if maybe it was already completed long before we began
    8. // see ActivityManagerService.finishBooting()
    9. if ("1".equals(SystemProperties.get("sys.boot_completed"))) {
    10. mBootCompleteCache.setBootComplete();
    11. if (DEBUG) {
    12. Log.v(TAG, "BOOT_COMPLETED was already sent");
    13. }
    14. }
    15. }
    16. final DumpManager dumpManager = mRootComponent.createDumpManager();
    17. Log.v(TAG, "Starting SystemUI services for user " +
    18. Process.myUserHandle().getIdentifier() + ".");
    19. TimingsTraceLog log = new TimingsTraceLog("SystemUIBootTiming",
    20. Trace.TRACE_TAG_APP);
    21. log.traceBegin(metricsPrefix);
    22. final int N = services.length;
    23. for (int i = 0; i < N; i++) {
    24. String clsName = services[i];
    25. if (DEBUG) Log.d(TAG, "loading: " + clsName);
    26. log.traceBegin(metricsPrefix + clsName);
    27. long ti = System.currentTimeMillis();
    28. try {
    29. SystemUI obj = mComponentHelper.resolveSystemUI(clsName);
    30. if (obj == null) {
    31. Constructor constructor = Class.forName(clsName).getConstructor(Context.class);
    32. obj = (SystemUI) constructor.newInstance(this);
    33. }
    34. mServices[i] = obj;
    35. } catch (ClassNotFoundException
    36. | NoSuchMethodException
    37. | IllegalAccessException
    38. | InstantiationException
    39. | InvocationTargetException ex) {
    40. throw new RuntimeException(ex);
    41. }
    42. if (DEBUG) Log.d(TAG, "running: " + mServices[i]);
    43. mServices[i].start();
    44. log.traceEnd();
    45. // Warn if initialization of component takes too long
    46. ti = System.currentTimeMillis() - ti;
    47. if (ti > 1000) {
    48. Log.w(TAG, "Initialization of " + clsName + " took " + ti + " ms");
    49. }
    50. if (mBootCompleteCache.isBootComplete()) {
    51. mServices[i].onBootCompleted();
    52. }
    53. dumpManager.registerDumpable(mServices[i].getClass().getName(), mServices[i]);
    54. }
    55. mRootComponent.getInitController().executePostInitTasks();
    56. log.traceEnd();
    57. mServicesStarted = true;
    58. }

     

    mContext 是SystemUI

    frameworks\base\packages\SystemUI\src\com\android\systemui\SystemUIFactory.java

    1. /** Returns the list of system UI components that should be started. */
    2. public String[] getSystemUIServiceComponents(Resources resources) {
    3. return resources.getStringArray(R.array.config_systemUIServiceComponents);
    4. }

    frameworks\base\packages\SystemUI\res\values\config.xml

    1. <!-- SystemUI Services: The classes of the stuff to start. -->
    2. <string-array name="config_systemUIServiceComponents" translatable="false">
    3. <item>com.android.systemui.util.NotificationChannels</item>
    4. <item>com.android.systemui.keyguard.KeyguardViewMediator</item>
    5. <item>com.android.systemui.recents.Recents</item>
    6. <item>com.android.systemui.volume.VolumeUI</item>
    7. <item>com.android.systemui.stackdivider.Divider</item>
    8. <item>com.android.systemui.statusbar.phone.StatusBar</item>
    9. <item>com.android.systemui.usb.StorageNotification</item>
    10. <item>com.android.systemui.power.PowerUI</item>
    11. <item>com.android.systemui.media.RingtonePlayer</item>
    12. <item>com.android.systemui.keyboard.KeyboardUI</item>
    13. <item>com.android.systemui.pip.PipUI</item>
    14. <item>com.android.systemui.shortcut.ShortcutKeyDispatcher</item>
    15. <item>@string/config_systemUIVendorServiceComponent</item>
    16. <item>com.android.systemui.util.leak.GarbageMonitor$Service</item>
    17. <item>com.android.systemui.LatencyTester</item>
    18. <item>com.android.systemui.globalactions.GlobalActionsComponent</item>
    19. <item>com.android.systemui.ScreenDecorations</item>
    20. <item>com.android.systemui.biometrics.AuthController</item>
    21. <item>com.android.systemui.SliceBroadcastRelayHandler</item>
    22. <item>com.android.systemui.SizeCompatModeActivityController</item>
    23. <item>com.android.systemui.statusbar.notification.InstantAppNotifier</item>
    24. <item>com.android.systemui.theme.ThemeOverlayController</item>
    25. <item>com.android.systemui.accessibility.WindowMagnification</item>
    26. <item>com.android.systemui.accessibility.SystemActions</item>
    27. <item>com.android.systemui.toast.ToastUI</item>
    28. </string-array>

    所有UI均继承自systemUI

    frameworks\base\packages\SystemUI\src\com\android\systemui\SystemUI.java

    public class PowerUI extends SystemUI implements CommandQueue.Callbacks {

  • 相关阅读:
    04-Jenkins构建Maven项目
    基于springboot小型命题系统毕业设计源码011508
    球场输了?卡塔尔背地里可能赢麻了!
    基于DDTBOX,使用线性支持向量回归(SVR)从ERP数据中解码连续变量
    NZ系列工具NZ02:VBA读取PDF使用说明
    企业网络流量分析监控软件
    分享让PPT变高级的两个小技巧
    不露脸的短视频自媒体怎么做?公布这些宝藏领域和工具
    unity Holoens2开发,使用Vuforia识别实体或图片 触发交互
    Linux系统之编译安装python3
  • 原文地址:https://blog.csdn.net/xiaowang_lj/article/details/126424115