BroadcastQueue: more robust edge-case handling.

When a caller provides a null receivers list, simply swap in an
immutable empty list so we get stronger @NonNull behavior.  Fix bug
when an ordered broadcast is sent to an empty list by sending the
final "resultTo" immediately.

Verify that we handle unexpected finishReceiverLocked() calls coming
in from apps, likely due to them racing with an ANR that finished
the active broadcast on their behalf.

Bug: 249997101
Test: atest FrameworksMockingServicesTests:BroadcastQueueTest
Test: atest FrameworksMockingServicesTests:BroadcastQueueModernImplTest
Change-Id: I50e6bb5878ef028c73352ccf04d8d57c113a6310
3 files changed