ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

SystemUI启动流程

2022-09-05 20:04:18  阅读:299  来源: 互联网

标签:启动 流程 SystemUI public void android com systemui


SystemUI启动流程

  1. frameworks\base\services\java\com\android\server\SystemServer.java

    public final class SystemServer { 
       private static final TimingsTraceLog BOOT_TIMINGS_TRACE_LOG;
       private SystemServiceManager mSystemServiceManager;
       
    public static void main(String[] args) {
          new SystemServer().run();
      }
    private void run() {
          ...
           // Start services.
           try {
          startBootstrapServices();
          }catch(){...}
      }
       
       private void startBootstrapServices() {
          ...
           // TODO: Might need to move after migration to WM.
         ActivityTaskManagerService atm =
           mSystemServiceManager.startService(ActivityTaskManagerService.Lifecycle.class).getService();
           mActivityManagerService = ActivityManagerService.Lifecycle.startService(
                   mSystemServiceManager, atm);
           mActivityManagerService.setSystemServiceManager(mSystemServiceManager);
           mActivityManagerService.setInstaller(installer);
           mWindowManagerGlobalLock = atm.getGlobalLock();
           traceEnd();
      }

    }
    mActivityManagerService.systemReady(() -> {
       traceBeginAndSlog("StartSystemUI");
               try {
                   startSystemUi(context, windowManagerF);
              } catch (Throwable e) {
                   reportWtf("starting System UI", e);
              }
               traceEnd();
    },BOOT_TIMINGS_TRACE_LOG);
                                       
     
    //正式启动SystemUi 入口:com.android.systemui.SystemUIService.java
       private static void startSystemUi(Context context, WindowManagerService windowManager) {
           Intent intent = new Intent();
           intent.setComponent(new ComponentName("com.android.systemui","com.android.systemui.SystemUIService"));
           intent.addFlags(Intent.FLAG_DEBUG_TRIAGED_MISSING);
           //Slog.d(TAG, "Starting service: " + intent);
           context.startServiceAsUser(intent, UserHandle.SYSTEM);
           windowManager.onSystemUiStarted();
      }
     
  1. 启动SystemUIService: com.android.systemui.SystemUIService.java

    public class SystemUIService extends Service {

       @Override
       public void onCreate() {
           super.onCreate();    
          ((SystemUIApplication)getApplication()).startServicesIfNeeded();
          }
    }
           
  2. com.android.systemui.SystemUIApplication.java

    public class SystemUIApplication extends Application implements SysUiServiceProvider {
       private SystemUI[] mServices;
       
        @Override
       public void onCreate() {
           super.onCreate();
            SystemUIFactory.createFromConfig(this);
      }
    public void startServicesIfNeeded() { //系统服务(SystemUiservice启动时执行该方法
           String[] names = getResources().getStringArray(R.array.config_systemUIServiceComponents);
           startServicesIfNeeded(names);
      }
       private void startServicesIfNeeded(String[] services) {
      mServices = new SystemUI[services.length];
           final int N = services.length;
           //反射机制,获取SysUI对象,对象列表所在数组:R.array.config_systemUIServiceComponents

           for (int i = 0; i < N; i++) {
               String clsName = services[i];
               if (DEBUG) Log.d(TAG, "loading: " + clsName);
               log.traceBegin("StartServices" + clsName);
               long ti = System.currentTimeMillis();
               Class cls;
               try {
                   cls = Class.forName(clsName);
                   Object o = cls.newInstance();
                   if (o instanceof SystemUI.Injector) {
                       o = ((SystemUI.Injector) o).apply(this);
                  }
                   mServices[i] = (SystemUI) o;//Dependency$DependencyCreator+NotificationChannels.java
              }catch(){..}
               mServices[i].mContext = this;
               mServices[i].mComponents = mComponents;
               mServices[i].start();//反射结果.start() //SysUI组件extends SystemUI ,通过start()方法启动
             
          }
           //添加插件:OverLayPlugin.java
           Dependency.get(PluginManager.class).addPluginListener(..,OverlayPlugin.class, true)
      }
    }
  3. SystemUI子类,入口:start()

    1. NotificationChannels.java
    public class NotificationChannels extends SystemUI {
       public Context mContext;
       
    @Override
       public void start() {
           createAll(mContext);
      }
    }
    2.KeyguardViewMediator.java
    public class KeyguardViewMediator extends SystemUI {
        @Override
       public void start() {
           synchronized (this) {
               setupLocked();
          }
           putComponent(KeyguardViewMediator.class, this);
      }
    }
    .....    
  4. 通过反射获取的SystemUI子类:xml文件中的数组

    <!-- SystemUI Services: The classes of the stuff to start. -->
    <string-array name="config_systemUIServiceComponents" translatable="false">
    <item>com.android.systemui.Dependency$DependencyCreator</item>  //依赖
           <item>com.android.systemui.util.NotificationChannels</item>  //创建SystemUI的通知Channel
           <item>com.android.systemui.statusbar.CommandQueue$CommandQueueStart</item>
           <item>com.android.systemui.keyguard.KeyguardViewMediator</item>  
           <item>com.android.systemui.recents.Recents</item> //最近任务
           <item>com.android.systemui.volume.VolumeUI</item>  //音量面板
           <item>com.android.systemui.stackdivider.Divider</item> //分屏
           <item>com.android.systemui.SystemBars</item>
            <item>com.android.systemui.usb.StorageNotification</item> //存储设备相关通知
           <item>com.android.systemui.power.PowerUI</item>   //低电量提醒
           <item>com.android.systemui.media.RingtonePlayer</item>   //手机铃声
           <item>com.android.systemui.keyboard.KeyboardUI</item>  //键盘
           <item>com.android.systemui.pip.PipUI</item> //画中画
           <item>com.android.systemui.shortcut.ShortcutKeyDispatcher</item>
           <item>@string/config_systemUIVendorServiceComponent</item>
           <item>com.android.systemui.util.leak.GarbageMonitor$Service</item> //定期检查SystemUI堆内存并报告
           <item>com.android.systemui.LatencyTester</item> // 在DEBUGGABLE版本运行,用于测试系统中的延迟
           <item>com.android.systemui.globalactions.GlobalActionsComponent</item> // 关机菜单
           <item>com.android.systemui.ScreenDecorations</item> //手机屏幕屏切圆角,模拟刘海屏
           <item>com.android.systemui.biometrics.BiometricDialogImpl</item>
           <item>com.android.systemui.SliceBroadcastRelayHandler</item>
           <item>com.android.systemui.SizeCompatModeActivityController</item>
           <item>com.android.systemui.statusbar.notification.InstantAppNotifier</item>  //显示Instant Apps(用户设备不需要安装的应用)的通知
           <item>com.android.systemui.theme.ThemeOverlayController</item>
           
       </string-array>
  5.  

标签:启动,流程,SystemUI,public,void,android,com,systemui
来源: https://www.cnblogs.com/a-n-yan/p/16659357.html

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有