Sort the list by last-use-time, if available. Interleave the
dependencies with the packages.
Clean up the code a bit for better code reuse and ease of writing
filters.
This should help with prioritization under space constraints.
Bug: 31347757
Change-Id: Ia0ec62faf013a379dc4c80b18fd6b2bfbfa470c4
(cherry picked from commit d3e07d46d4)