用来记录学习wms,后续会一点一点更新。。。。。。
 代码:android14
WMS是在SystemServer进程中启动的
在SystemServer中的main方法中,调用run方法。
 
private void run() {
// Initialize native services.初始化服务,加载android_servers so库
870              System.loadLibrary("android_servers");
// Create the system service manager.创建SystemServiceManager
895              mSystemServiceManager = new SystemServiceManager(mSystemContext);942              startOtherServices(t);//android14在startOtherServices中启动WindowManagerServiceandroid14中,在startOtherServices中启动WindowManagerService
1606              wm = WindowManagerService.main(context, inputManager, !mFirstBoot,
1607                      new PhoneWindowManager(), mActivityManagerService.mActivityTaskManager);
该代码执行了WMS的main方法,会在内部创建一个WMS。其中有一个参数inputManager也是在startOtherServices中创建的,如下。
1589              t.traceBegin("StartInputManagerService");
1590              inputManager = new InputManagerService(context);总结,WMS的main方法在startOtherServices中,而startOtherServices在SystemServer的run方法中,运行在system_server线程中。
1608              ServiceManager.addService(Context.WINDOW_SERVICE, wm, /* allowIsolated= */ false,
1609                      DUMP_FLAG_PRIORITY_CRITICAL | DUMP_FLAG_PROTO);
1610              ServiceManager.addService(Context.INPUT_SERVICE, inputManager,
1611                      /* allowIsolated= */ false, DUMP_FLAG_PRIORITY_CRITICAL);
上述代码将WMS和IMS注册到ServerManager中。
 回到上述的WindowManagerService main中。
 /frameworks/base/services/core/java/com/android/server/wm/WindowManagerService.java
1137      public static WindowManagerService main(final Context context, final InputManagerService im,
1138              final boolean showBootMsgs, WindowManagerPolicy policy, ActivityTaskManagerService atm,
1139              DisplayWindowSettingsProvider displayWindowSettingsProvider,
1140              Supplier<SurfaceControl.Transaction> transactionFactory,
1141              Function<SurfaceSession, SurfaceControl.Builder> surfaceControlFactory) {
1142          final WindowManagerService[] wms = new WindowManagerService[1];
1143          DisplayThread.getHandler().runWithScissors(() ->
1144                  wms[0] = new WindowManagerService(context, im, showBootMsgs, policy, atm,
1145                          displayWindowSettingsProvider, transactionFactory,
1146                          surfaceControlFactory), 0);
1147          return wms[0];
1148      }
DisplayThread.getHandler().runWithScissors调用DisplayThread的getHandler方法,获得DisplayThread的handler实例。
 可以用来处理需要低延时显示的相关操作。

 这张图可以清晰的了解到,不管是applicationWindow,还是SystemWindow都是由WindowManager和WMS处理。