Icon: make Icon's Bitmaps immutable
Because Bitmap mutability is propagated across Parcel and Binder, the following problem can happen when sending an Icon containing a Bitmap as part of a Notification: 1. App creates Icon with a mutable Bitmap (1 alloc) 2. App sends Icon to system_server, often creating ashmem Bitmap (2 allocs) 3. system_server converts ashmem Bitmap back to heap Bitmap (3 allocs) 4. system_server sends heap Bitmap to each NotificationListener individually, converting the heap Bitmap to ashmem each time (3+N allocs) 5. NotificationListener converts ashmem Bitmap to heap Bitmap (3+2N allocs) This is inefficient. This is especially bad because the API to update a Notification involves sending a full Notification object, including Icons, repeatedly, and some apps do that several times per second. Instead, ensure that all Bitmaps transmitted as part of Icons are immutable. Instead, we get: 1. App creates Icon, which may copy to immutable Bitamp (1 or 2 allocs) 2. App sends Icon to system_server over ashmem (still 1 or 2 allocs) 3. system_server uses received ashmem Bitmap directly (still 1 or 2 allocs) 4. system_server sends same ashmem Bitmap to NotificationListeners (1 or 2) 5. Each NotificationListener uses the same ashmem Bitmap (1 or 2) This solves the per-NotificationListener amplification, but it does not solve sending what is likely the same Bitmap N times per second when apps update Notifications. That will require either app changes or Notification API changes to avoid bytewise comparisons for all Bitmaps. Test: boot, notifications work, memory in maps/gearhead remains good Bug: 227920378 Change-Id: If92835f647a76da599f358c7c02888e3e2f59235
Loading
Please register or sign in to comment