Add optimizations to keep TaskPersister queue small.

CTS tests cause the TaskPersister queue to fill faster than it can
drain. Since it contains screenshots this can consume massive
memory. Monkey may also cause the queue to back up.

Several optimizations are added to drain the queue when it gets
large:
- High water mark to recognize when queue gets too deep. Queue is
completely drained at this point so that obsolete files can be
removed from storage.
- Use Thread.yield() to give the TaskPersister write thread some cpu
cycles.
- Remove images from write queue when TaskRecord is removed from
recents.

May fix bug 17177273.
May fix bug 17381033.

Change-Id: If21c03c8f380e5f6816cf4701a40fcfe34ace3f1
1 file changed