在Android 5.0中,新增了一个DisplayThread类,源码位置在frameworks/base/services/core/java/com/android/server/DisplayThread.java.
这个类的注释是这么写的,
* Shared singleton foreground thread for the system. This is a thread for
* operations that affect what's on the display, which needs to have a minimum
* of latency. This thread should pretty much only be used by the WindowManager,
* DisplayManager, and InputManager to perform quick operations in real time.
也就是说,从Android 5.0开始,所有跟系统前景相关的操作都集中到这个线程类中。这个类用来处理需要低时延的显示相关的操作。这个线程只能由WindowManager,DisplayManager和InputManager用来实时显示相关的快速操作。
于是WindowManagerService运行的线程再次发生了变化。在Android 4.1的时代,WmS拥有一个自己的主线程WMThread。4.1之后到4.4,SystemServer提供了一个wmHandlerThread来替代它。到了5.0之后,WmS改成运行在DisplayThread的Handler中。
public static WindowManagerService main(final Context context, final InputManagerService im, final boolean haveInputMethods, final boolean showBootMsgs, final boolean onlyCore) { final WindowManagerService[] holder = new WindowManagerService[1]; DisplayThread.getHandler().runWithScissors(new Runnable() { @Override public void run() { holder[0] = new WindowManagerService(context, im, haveInputMethods, showBootMsgs, onlyCore); } }, 0); return holder[0]; }