Android P SystemUI起動プロセス

25564 ワード

このコードはAndroid 9.0分析に基づいており、個人の理解能力には限界があります.SystemUIは起動中にSystemServerが起動し、SystemServerのstartOtherServices()で
/*frameworks/base/services/java/com/android/server/SystemServer.java*/
private void startOtherServices() {
...
  try {
      startSystemUi(context, windowManagerF);
  } catch (Throwable e) {
      reportWtf("starting System UI", e);
  }
...
}

//startSystemUi  
 static final 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);
        context.startServiceAsUser(intent, UserHandle.SYSTEM);
        windowManager.onSystemUiStarted();
 }


システムUIのシステムUIserviceサービスが開始されることがわかります.windowManager.onSystemUIStarted()メソッドは、最終的には、バインドによってSystemUIのKeyguardServiceサービスを開始します.
SystemUIserviceはサービスを継承し、標準的なandroidサービスであるため、onCreateインタフェースを再ロードする必要があります.
//frameworks/base/packages/SystemUI/src/com/android/systemui/SystemUIService.java
@Override
public void onCreate() {
   super.onCreate();
   ((SystemUIApplication) getApplication()).startServicesIfNeeded();
   ... //       
}

SystemUIserviceのonCreateメソッドでは、SystemUIAPplicationのstartServicesIfNeededメソッドも呼び出されます.
//frameworks/base/packages/SystemUI/src/com/android/systemui/SystemUIApplication.java
public void startServicesIfNeeded() {
    String[] names = getResources().getStringArray(R.array.config_systemUIServiceComponents);
    startServicesIfNeeded(names);
}

まずnamesに何が格納されているか見てみましょう.config_systemUIServiceComponents:
<!-- frameworks/base/packages/SystemUI/res/values/config.xml --!>
<string-array name="config_systemUIServiceComponents" translatable="false">
        <item>com.android.systemui.Dependency</item>
        <item>com.android.systemui.util.NotificationChannels</item>
        <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>
        <item>com.android.systemui.LatencyTester</item>
        <item>com.android.systemui.globalactions.GlobalActionsComponent</item>
        <item>com.android.systemui.ScreenDecorations</item>
        <item>com.android.systemui.fingerprint.FingerprintDialogImpl</item>
        <item>com.android.systemui.SliceBroadcastRelayHandler</item>
    </string-array>

config_SystemUIserviceComponentsは、一連のパッケージ名にクラス名を付けたものです.これらのクラスはすべてSystemUIクラスから継承され、SystemUIは抽象クラスであり、その中に抽象的な方法がある.
public abstract void start();

String配列namesに読み込み、パラメータ付きstartServicesIfNeededメソッドを呼び出します.
private void startServicesIfNeeded(String[] services) {
     ...
     //  SystemUI  ,   names   
     mServices = new SystemUI[services.length];
	...
    //    services  ,      names  
    final int N = services.length;
    for (int i = 0; i < N; i++) {
         String clsName = services[i];
         ...
         long ti = System.currentTimeMillis();
         Class cls;
         try {
              cls = Class.forName(clsName);
              //      class
              mServices[i] = (SystemUI) cls.newInstance();
          } catch(ClassNotFoundException ex){
             throw new RuntimeException(ex);
          } 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]);
          //  start    
          mServices[i].start();
          ...
          if (mBootCompleted) {
              mServices[i].onBootCompleted();
          }
		  ...   
}

各システムui要素(statusBar、PowerUIなどを含む)は、SystemUIという抽象クラスを継承し、startメソッドを再ロードする必要があります.これは、後でシステムUI要素を簡単に拡張または削除できる柔軟なプログラミング方法です.各UI要素の起動は、次の章で分析されます.