wmshell/src/com/android/wm/shell/docs/threading.md
Thread boundary
|
WM Shell | SystemUI
|
|
FeatureController <-> FeatureInterface <--|--> WMShell <-> SysUI
| (^post to shell thread) | (^post to main thread)
... |
| |
OtherControllers |
We currently have multiple threads in use in the Shell library depending on the configuration by the product.
ShellMainThread (only used if the resource config_enableShellMainThread is set true
(ie. phones))
THREAD_PRIORITY_DISPLAY priority since so many windowing-critical
components depend on itShellBackgroundThread (for longer running tasks where we don't want to block the shell main
thread)
THREAD_PRIORITY_BACKGROUND priority but can be requested to be boosted
to THREAD_PRIORITY_FOREGROUNDShellAnimationThread (currently only used for Transitions and Splitscreen, but potentially all
animations could be offloaded here)ShellSplashScreenThread (only for use with splashscreens)The threading-related components are provided by the WMShellConcurrencyModule,
for example, the Executors and Handlers for the various threads that are used. You can request
an executor of the necessary type by using the appropriate annotation for each of the threads (ie.
@ShellMainThread Executor) when injecting into your Shell component.
To get the SysUI main thread, you can use the @Main annotation.
synchronize your code (unless you are trying to prevent reentrantcy, but that can also be
done in other ways)@ShellMainThread ShellExecutor instead
@ShellMainThread Handler or use view.getHandler() which should be OK
assuming that the view root was initialized on the main Shell thread@Main ShellExecutor to get the SysUI main threadTestShellExecutor to control the processing of messages