Add compressed bitmaps to be included in `am dumpheap`
Bug: 328443220
`android.graphics.Bitmap` class used to have a field of byte array
`mBuffer` for its content. This allowed the bitmap content to be
included as part of `am dumpheap`. However, this field was removed
when Bitmap was migrated to use native memory.
This CL allows contents of bitmaps to be compressed and included as
part of `am dumpheap`, with added command line switch '-b <format>'.
For example, the command below will include the contents of the
bitmaps compressed in PNG format as part of the heap dump.
`am dumpheap -b png com.google.android.apps.photos`
This is done with a few key changes below:
1. Every bitmap instance created will be tracked by a static
`WeakHashMap`. This is so that 1) the bitmap instances are
used as weak keys and can be garbage collected normally,
and 2) when a bitmap instance is garbage collected, its
entry in `WeakHashMap` will also be removed, so the size
of the map itself is limited
2. A static field `Bitmap.dumpData` is introduced, and will
record every bitmap's `nativePtr` and its compressed
content when bitmap dump is enabled during a heap dump
3. `Bitmap.dumpData` will be cleared after the heap is dumped,
the recorded information as well as buffers with compressed
contents will be garbage collected thereafter.
Change-Id: I37b6ea6b947565d1ac5a6bbc5b462c3ceedebec1
7 files changed