Fix drawable-state cache expired issue
Context:
The list of Preloaded drawables is defined in
/system/framework/framework-res.apk. It describes a set of
drawables to be loaded as the cache. The cache includes the
drawables states for each preloaded drawable.
For example: we have preloadSet(
res/drawable/a.png
res/drawable/b.png
res/drawable/c_vector_drawable.xml).
Because both of loading png and decoding xml to be a vector
drawable take I/O and parsing time, in order to prevent app
processes from doing again, the drawable state describes where is
the decoded image of Bitmap in memory and the data structure of
VectorDrawable.
When some process wants to load R.drawable.a, it intends to load
res/drawable/a.png, it's already in the cache because Zygote has
preloaded as the drawable state for res/drawable/a.png. The
Resources clones another drawable state and creates a new Drawable
instance back to the app.
Solution:
ResourcesPerfWorkloads sets a special version of the framework
resources package but it doesn't rebuild the drawable state cache
according to the special framework resources package.
When the drawable state cache belonging to the old framework
resources package doesn't match the new framework resources
package, accessing the preloaded drawables may trigger this kind
of issue.
The solution is to clear the static caches in ResourcesImpl and
load the cache defined in the specified framework resources
package.
This patch also moves the preload resources tasks from ZygoteInit.java
to Resources.java.
Bug: 193826688
Test: atest ResourcesPerfWorkloads
Change-Id: I0fa25612bf82dd810d1d9443068a9a302a61d53d
3 files changed