I had several users reporting that with the latest AOKP nightlies and my Xposed framework, their SystemUI takes some minutes to show up. Even though I'm not using AOKP myself, I spent some hours investigation this issue. What I found was:
- The reason for the delay are ANRs, which cause a restart of the SystemUI
- I believe the root cause was introduced in this commit:
https://github.com/AOKP/frameworks_base/commit/8432dd523bf51c10e2aa294a9b5494a64ff1f96e
- AppWindow, which is initialized in the start() function of the SystemUI services, loads information about all installed packages
- There are two expensive things in this:
- getting the launch intent results in two queryIntentActivities() calls for each installed package
- retrieving the labels for all launchable packages requires their resources to be loaded
- I injected the package loading functions into the ROM I'm using and they took 10-15 seconds on my S2 at boot time (high load -> more runtime)
- With many installed packages, a slower device or other initializations going on in parallel, the 20 seconds limit for ANRs is easily reached
- Xposed seems be another factor in this, but I have also seen an ANR trace where Xposed was not installed. Even if it slowed down the whole thing by 3 seconds, it couldn't be called the main factor.
- I asked one of the affected users to try an Xposed module that nukes the sortApps() function, which is just one half of the expensive instructions. He reported back that this mostly solves it.
So, here are my suggestions:
- avoid loading the packages during service startup (or at boot time at all - later, the same code just takes about 4 seconds)
- load the information asynchronously if possible to avoid blocking
If you need more information, please let me know.