Do not use Map.Entry outside of lock
Map.Entry returned from Map#entrySet are tied to the backing map.
A change to the map is reflected to the Map.Entry. This causes
undefined behavior (including NPE) if we try to use them outside of
the lock. If a client removes their callback after we exit the lock
but before we invoke the client callbacks, we run into NPE. Instead,
lets copy the callback and executor into a separate data structure.
Fixes: 286512746
Test: atest DeviceStateControllerTests
Change-Id: I8ed29cf6e27f5c8020f120c3968896f627573a35
2 files changed