Use CopyOnWriteArrayList for listeners.

- We were previously using a list of Listener objects, specifically a
  LinkedList, and synchronizing on the list to maintain thread-safety.
- This cl replaces the LinkedList with a CopyOnWriteArrayList, which is
  specifically made for this kind of situation.

A bit more background:
- During the notify period, we had the classic anti-pattern of holding
  the lock whilst calling foreign methods (the listener
  onServiceCompleted methods).
- It's very evil to call foreign methods with a lock held, since this
  can easily lead to deadlock.  In this case, if any of our Listener
  implementations or any future Listener implementations yet to be
  written were to block until some other thread registers or unregisters
  a listener, we will have deadlock.
- CopyOnWriteArrayList needs no explicit synchronization - see its
  javadoc.

Change-Id: If2251e740a9f266e28956ac5acc52054debb3461
1 file changed