Merge "Allow timeouts to be configurable" into master-nova
diff --git a/src/com/android/telecomm/BinderDeallocator.java b/src/com/android/telecomm/BinderDeallocator.java
index ab7db25..fc57158 100644
--- a/src/com/android/telecomm/BinderDeallocator.java
+++ b/src/com/android/telecomm/BinderDeallocator.java
@@ -65,7 +65,7 @@
      * The set of all known binders, either in use or potentially about to be used.
      */
     @SuppressWarnings("rawtypes")
-    private Set<ServiceBinder> mBinders = Sets.newHashSet();
+    private final Set<ServiceBinder> mBinders = Sets.newHashSet();
 
     /**
      * Accounts for the action entering a critical section (i.e. potentially needing access to
@@ -87,7 +87,9 @@
     void updateBinders(Set<? extends ServiceBinder> binders) {
         ThreadUtil.checkOnMainThread();
 
-        mBinders.addAll(binders);
+        if (binders != null) {
+            mBinders.addAll(binders);
+        }
     }
 
     /**
diff --git a/src/com/android/telecomm/CallServiceRepository.java b/src/com/android/telecomm/CallServiceRepository.java
index 6cd7a9d..6dad6eb 100644
--- a/src/com/android/telecomm/CallServiceRepository.java
+++ b/src/com/android/telecomm/CallServiceRepository.java
@@ -91,7 +91,7 @@
      * responses are received, the partial (potentially empty) set gets passed (to the switchboard)
      * instead. Entries are removed from this set as providers are processed.
      */
-    private Set<ComponentName> mOutstandingProviders;
+    private final Set<ComponentName> mOutstandingProviders = Sets.newHashSet();
 
     /**
      * The map of call-service wrappers keyed by their ComponentName.  Used to ensure at most one
@@ -100,7 +100,7 @@
      * include only active call services (ones that are associated with one or more active calls)
      * upon {@link #purgeInactiveCallServices()} invocations.
      */
-    private Map<ComponentName, CallServiceWrapper> mCallServices = Maps.newHashMap();
+    private final Map<ComponentName, CallServiceWrapper> mCallServices = Maps.newHashMap();
 
     /**
      * Persists the specified parameters.
@@ -142,7 +142,7 @@
         mLookupId = lookupId;
         mIsLookupInProgress = true;
 
-        mOutstandingProviders = Sets.newHashSet();
+        mOutstandingProviders.clear();
         for (ComponentName name : providerNames) {
             mOutstandingProviders.add(name);
             bindProvider(name);
@@ -340,7 +340,7 @@
      */
     private void terminateLookup() {
         mHandler.removeCallbacks(mLookupTerminator);
-        mOutstandingProviders = null;
+        mOutstandingProviders.clear();
 
         updateSwitchboard();
         mIsLookupInProgress = false;
diff --git a/src/com/android/telecomm/CallServiceSelectorRepository.java b/src/com/android/telecomm/CallServiceSelectorRepository.java
index 1935e25..4186a5d 100644
--- a/src/com/android/telecomm/CallServiceSelectorRepository.java
+++ b/src/com/android/telecomm/CallServiceSelectorRepository.java
@@ -84,7 +84,7 @@
      * The set of bound call-service selectors.  Only populated via initiateLookup scenarios.
      * Selectors should only be removed upon unbinding.
      */
-    private Set<ICallServiceSelector> mSelectorRegistry = Sets.newHashSet();
+    private final Set<ICallServiceSelector> mSelectorRegistry = Sets.newHashSet();
 
     /**
      * Stores the names of the selectors to bind to in one lookup cycle.  The set size represents
@@ -96,7 +96,7 @@
      * selectors do not require finding and hence are excluded from this set.  Also note that
      * selectors are removed from this set as they register.
      */
-    private Set<ComponentName> mUnregisteredSelectors;
+    private final Set<ComponentName> mUnregisteredSelectors = Sets.newHashSet();
 
     /**
      * Persists the specified parameters and initializes the new instance.
@@ -129,7 +129,7 @@
 
         mLookupId = lookupId;
         mIsLookupInProgress = true;
-        mUnregisteredSelectors = Sets.newHashSet();
+        mUnregisteredSelectors.clear();
 
         for (ComponentName name : selectorNames) {
             if (!mSelectorRegistry.contains(name)) {
diff --git a/src/com/android/telecomm/CallServiceWrapper.java b/src/com/android/telecomm/CallServiceWrapper.java
index 72e1041..067b715 100644
--- a/src/com/android/telecomm/CallServiceWrapper.java
+++ b/src/com/android/telecomm/CallServiceWrapper.java
@@ -26,8 +26,6 @@
 import android.telecomm.ICallServiceAdapter;
 import android.util.Log;
 
-import com.android.telecomm.ServiceBinder.BindCallback;
-
 /**
  * Wrapper for {@link ICallService}s, handles binding to {@link ICallService} and keeps track of
  * when the object can safely be unbound. Other classes should not use {@link ICallService} directly
diff --git a/src/com/android/telecomm/CallsManager.java b/src/com/android/telecomm/CallsManager.java
index 7381bdc..7102cf4 100644
--- a/src/com/android/telecomm/CallsManager.java
+++ b/src/com/android/telecomm/CallsManager.java
@@ -79,9 +79,9 @@
 
     private VoicemailManager mVoicemailManager;
 
-    private List<OutgoingCallValidator> mOutgoingCallValidators = Lists.newArrayList();
+    private final List<OutgoingCallValidator> mOutgoingCallValidators = Lists.newArrayList();
 
-    private List<IncomingCallValidator> mIncomingCallValidators = Lists.newArrayList();
+    private final List<IncomingCallValidator> mIncomingCallValidators = Lists.newArrayList();
 
     /**
      * Initializes the required Telecomm components.
diff --git a/src/com/android/telecomm/InCallAdapter.java b/src/com/android/telecomm/InCallAdapter.java
index 9faa472..170f66b 100644
--- a/src/com/android/telecomm/InCallAdapter.java
+++ b/src/com/android/telecomm/InCallAdapter.java
@@ -18,7 +18,6 @@
 
 import android.os.Handler;
 import android.os.Looper;
-import android.os.RemoteException;
 import android.telecomm.IInCallAdapter;
 import android.util.Log;
 
@@ -42,7 +41,7 @@
 
     /** {@inheritDoc} */
     @Override
-    public void answerCall(final String callId) throws RemoteException {
+    public void answerCall(final String callId) {
         Log.d(TAG, "answerCall(" + callId + ")");
         mHandler.post(new Runnable() {
             @Override public void run() {
@@ -53,7 +52,7 @@
 
     /** {@inheritDoc} */
     @Override
-    public void rejectCall(final String callId) throws RemoteException {
+    public void rejectCall(final String callId) {
         Log.d(TAG, "rejectCall(" + callId + ")");
         mHandler.post(new Runnable() {
             @Override public void run() {
@@ -64,12 +63,11 @@
 
     /** {@inheritDoc} */
     @Override
-    public void disconnectCall(final String callId) throws RemoteException {
+    public void disconnectCall(final String callId) {
         mHandler.post(new Runnable() {
             @Override public void run() {
                 mCallsManager.disconnectCall(callId);
             }
         });
     }
-
 }
diff --git a/src/com/android/telecomm/OutgoingCallProcessor.java b/src/com/android/telecomm/OutgoingCallProcessor.java
index a0875c9..42a16c6 100644
--- a/src/com/android/telecomm/OutgoingCallProcessor.java
+++ b/src/com/android/telecomm/OutgoingCallProcessor.java
@@ -175,10 +175,6 @@
         }
 
         mCall.setState(CallState.DIALING);
-
-        // TODO(gilad): Seems better/clearer not to invoke "abort" on successfully-connected calls.
-        abort();
-
         mSwitchboard.handleSuccessfulOutgoingCall(mCall);
     }
 
@@ -269,7 +265,7 @@
             return;
         }
 
-        if (mCallServiceDescriptorIterator.hasNext()) {
+        if (mCallServiceDescriptorIterator != null && mCallServiceDescriptorIterator.hasNext()) {
             CallServiceDescriptor descriptor = mCallServiceDescriptorIterator.next();
             final CallServiceWrapper callService =
                     mCallServicesById.get(descriptor.getCallServiceId());
diff --git a/src/com/android/telecomm/Switchboard.java b/src/com/android/telecomm/Switchboard.java
index bb40ef6..077e605 100644
--- a/src/com/android/telecomm/Switchboard.java
+++ b/src/com/android/telecomm/Switchboard.java
@@ -16,7 +16,6 @@
 
 package com.android.telecomm;
 
-import com.google.common.base.Preconditions;
 import com.google.common.collect.Lists;
 import com.google.common.collect.Sets;
 
@@ -28,7 +27,6 @@
 import android.telecomm.TelecommConstants;
 import android.util.Log;
 
-import java.util.Collection;
 import java.util.Iterator;
 import java.util.List;
 import java.util.Set;
@@ -83,14 +81,14 @@
      * {@link CallServiceRepository}.  Populated during call-service lookup cycles as part of the
      * {@link #placeOutgoingCall} flow and cleared upon zero-remaining new/pending outgoing calls.
      */
-    private Set<CallServiceWrapper> mCallServices;
+    private final Set<CallServiceWrapper> mCallServices = Sets.newHashSet();
 
     /**
      * The set of currently available call-service-selector implementations,
      * see {@link CallServiceSelectorRepository}.
-     * TODO(gilad): Null out once the active-call count goes to zero.
+     * TODO(gilad): Clear once the active-call count goes to zero.
      */
-    private Set<ICallServiceSelector> mSelectors;
+    private final Set<ICallServiceSelector> mSelectors = Sets.newHashSet();
 
     /**
      * The current lookup-cycle ID used with the repositories. Incremented with each invocation
@@ -128,8 +126,8 @@
         // reset, (5) the selector lookup completes but the call-services are missing.  This should
         // be okay since the call-service lookup completed. Specifically the already-available call
         // services are cached and will be provided in response to the second lookup cycle.
-        mCallServices = null;
-        mSelectors = null;
+        mCallServices.clear();
+        mSelectors.clear();
 
         mNewOutgoingCalls.add(call);
 
@@ -169,7 +167,8 @@
     void setCallServices(Set<CallServiceWrapper> callServices) {
         mBinderDeallocator.updateBinders(mCallServices);
 
-        mCallServices = callServices;
+        mCallServices.clear();
+        mCallServices.addAll(callServices);
         processNewOutgoingCalls();
     }
 
@@ -191,7 +190,8 @@
         // emergency calls) and order the entire set prior to the assignment below. If the
         // built-in selectors can be implemented in a manner that does not require binding,
         // that's probably preferred.  May want to use a LinkedHashSet for the sorted set.
-        mSelectors = selectors;
+        mSelectors.clear();
+        mSelectors.addAll(selectors);
         processNewOutgoingCalls();
     }
 
@@ -272,7 +272,7 @@
      * Attempts to process the next new outgoing calls that have not yet been expired.
      */
     private void processNewOutgoingCalls() {
-        if (isNullOrEmpty(mCallServices) || isNullOrEmpty(mSelectors)) {
+        if (mCallServices.isEmpty() || mSelectors.isEmpty()) {
             // At least one call service and one selector are required to process outgoing calls.
             return;
         }
@@ -294,9 +294,6 @@
      * @param call The call to place.
      */
     private void processNewOutgoingCall(Call call) {
-        Preconditions.checkNotNull(mCallServices);
-        Preconditions.checkNotNull(mSelectors);
-
         // Convert to (duplicate-free) list to aid index-based iteration, see the comment under
         // setSelectors regarding using LinkedHashSet instead.
         List<ICallServiceSelector> selectors = Lists.newArrayList();
@@ -355,15 +352,4 @@
             }
         }
     }
-
-    /**
-     * Determines whether or not the specified collection is either null or empty.
-     *
-     * @param collection Either null or the collection object to be evaluated.
-     * @return True if the collection is null or empty.
-     */
-    @SuppressWarnings("rawtypes")
-    private boolean isNullOrEmpty(Collection collection) {
-        return collection == null || collection.isEmpty();
-    }
 }
diff --git a/tests/src/com/android/telecomm/testcallservice/TestCallService.java b/tests/src/com/android/telecomm/testcallservice/TestCallService.java
index 2b0f421..8fa1303 100644
--- a/tests/src/com/android/telecomm/testcallservice/TestCallService.java
+++ b/tests/src/com/android/telecomm/testcallservice/TestCallService.java
@@ -118,15 +118,9 @@
 
     /** {@inheritDoc} */
     @Override
-    public void disconnect(String callId) {
-        Log.i(TAG, "disconnect(" + callId + ")");
-
-        try {
-            destroyCall(callId);
-            mCallsManagerAdapter.setDisconnected(callId);
-        } catch (RemoteException e) {
-            Log.e(TAG, "Failed to setDisconnected().", e);
-        }
+    public void abort(String callId) {
+        Log.i(TAG, "abort(" + callId + ")");
+        destroyCall(callId);
     }
 
     /** {@inheritDoc} */
@@ -167,6 +161,19 @@
 
     /** {@inheritDoc} */
     @Override
+    public void disconnect(String callId) {
+        Log.i(TAG, "disconnect(" + callId + ")");
+
+        destroyCall(callId);
+        try {
+            mCallsManagerAdapter.setDisconnected(callId);
+        } catch (RemoteException e) {
+            Log.e(TAG, "Failed to setDisconnected().", e);
+        }
+    }
+
+    /** {@inheritDoc} */
+    @Override
     public boolean onUnbind(Intent intent) {
         mMediaPlayer = null;