Prevent ConcurrentModificationExceptions

Use sets backed by ConcurrentHashMaps instead of HashSets, and
CopyOnWriteArrayLists instead of ArrayLists, to prevent concurrent
exceptions if listeners try to remove themselves in callbacks while
iterating over the listeners.

Bug:16325026
Change-Id: I55e081eda6ba19fa466bbf019c648bbdaf833c33
diff --git a/telecomm/java/android/telecomm/ConnectionServiceAdapter.java b/telecomm/java/android/telecomm/ConnectionServiceAdapter.java
index bfcb5c3..4144b81 100644
--- a/telecomm/java/android/telecomm/ConnectionServiceAdapter.java
+++ b/telecomm/java/android/telecomm/ConnectionServiceAdapter.java
@@ -36,8 +36,13 @@
  * @hide
  */
 final class ConnectionServiceAdapter implements DeathRecipient {
+    /**
+     * ConcurrentHashMap constructor params: 8 is initial table size, 0.9f is
+     * load factor before resizing, 1 means we only expect a single thread to
+     * access the map so make only a single shard
+     */
     private final Set<IConnectionServiceAdapter> mAdapters = Collections.newSetFromMap(
-            new ConcurrentHashMap<IConnectionServiceAdapter, Boolean>(2));
+            new ConcurrentHashMap<IConnectionServiceAdapter, Boolean>(8, 0.9f, 1));
 
     ConnectionServiceAdapter() {
     }
@@ -53,7 +58,7 @@
     }
 
     void removeAdapter(IConnectionServiceAdapter adapter) {
-        if (mAdapters.remove(adapter)) {
+        if (adapter != null && mAdapters.remove(adapter)) {
             adapter.asBinder().unlinkToDeath(this, 0);
         }
     }