Fix Runnable/View leak from posting to detached views in FragmentManager
The old Animation framework runs callbacks during View.draw(). During
this, it's unsafe to change the layer type of that view, therefore an
older bug fix began posting layer type changes as runnables to the
view in question.
This doesn't work well either, since that means it's too late to start
using a hardware layer for animation (the first frame has been drawn
and we'll likely jank the next in layer creation) and if the view is
detached and we're on a non-Looper thread, prior to Android N we will
post the runnable to a thread-local run queue that never gets flushed,
leaking anything we've closed over like the view, its context, etc.
Change FragmentManager to set layers for alpha animations before
starting the animation rather than in the animation callback
itself. Only post the change back to LAYER_TYPE_NONE if we're attached
to a window or if we're running on at least N to avoid the
bug. Otherwise, make the layer type change immediately since we're
assured not to be running in a hwui drawing operation on the UI
thread.
Bug 28142337
Change-Id: I8819f55555cfb2b0b44a1f8a22c651429d4382fd
1 file changed