Fix re-entrant invalidation w/ HUNs + VisStability

Inside of an OnBeforeFinalizeListener, HeadsUpCoordinator processes all
of the notifications in the Shade (up to finalization), and determines
whether or not they should be alerting, and whether or not they are
already alerting. Any differences are then reported to the
HeadsUpManager.

The problem: When HeadsUpManager#removeAlertingNotification is called,
VisualStability can be flipped from enabled->disabled, triggering an
invalidation. In the associated bug, this manifests when the device is
pulsing; removeAltertingNotification internally updates the
StatusBarStateController so that it's no longer pulsing, which notifies
the VisualStabilityManager of this change, which then invalidates.

The solution, in two parts:

1. If we can determine that a notification should stop alerting in the
NotifCollectionListener#onEntryUpdated callback, do so that that time.
This happens before the ShadeListBuilder is run, and so won't cause the
re-entrant call.

2. For group alert transfer, any removal of an alert is because that
alert is being transfered to another notification (via "group alert
transfer" behavior). To work around this, we simply ensure that the
HeadsUpManager is only alerted of removals *after* it is alerted of any
additions.

Fixes: 219684141
Test: Using Notify.apk:
      1. Post a group summary
      2. Post a child, with GROUP_ALERT_SUMMARY flag, while the first
      notification is still HUNNING.
      3. Observe no crash
Change-Id: I6df66af5fb2434815b94659a4da6ade79dd64d69
1 file changed