Audio focus and ring changes (again).

- Went back to using ringtone.  Ringtone class has fallback logic that is
  necessary to keep (without duplicating).
- Moved the ringtone player code into AsyncRingtonePlayer and kept the
  CallsManager listener code inside ringer into CallAudioManager.java
- Consolidated AudioFocus acquisition into CallAudioManager.

bug: 13365906

Change-Id: I8d7b6a999f594b8f81497aa3f5b7ac5916fdd18e
diff --git a/src/com/android/telecomm/CallsManager.java b/src/com/android/telecomm/CallsManager.java
index 452f8e1..106f9af 100644
--- a/src/com/android/telecomm/CallsManager.java
+++ b/src/com/android/telecomm/CallsManager.java
@@ -78,8 +78,6 @@
 
     private final CallsManagerListener mInCallController;
 
-    private final CallsManagerListener mRinger;
-
     private VoicemailManager mVoicemailManager;
 
     private final List<OutgoingCallValidator> mOutgoingCallValidators = Lists.newArrayList();
@@ -95,7 +93,6 @@
         mPhoneStateBroadcaster = new PhoneStateBroadcaster();
         mCallAudioManager = new CallAudioManager();
         mInCallController = new InCallController();
-        mRinger = new Ringer();
     }
 
     static CallsManager getInstance() {
@@ -232,7 +229,6 @@
             mPhoneStateBroadcaster.onIncomingCallAnswered(call);
             mCallAudioManager.onIncomingCallAnswered(call);
             mInCallController.onIncomingCallAnswered(call);
-            mRinger.onIncomingCallAnswered(call);
 
             // We do not update the UI until we get confirmation of the answer() through
             // {@link #markCallAsActive}. However, if we ever change that to look more responsive,
@@ -258,7 +254,6 @@
             mPhoneStateBroadcaster.onIncomingCallRejected(call);
             mCallAudioManager.onIncomingCallRejected(call);
             mInCallController.onIncomingCallRejected(call);
-            mRinger.onIncomingCallRejected(call);
 
             call.reject();
         }
@@ -342,6 +337,21 @@
     }
 
     /**
+     * @return True if there exists a call with the specific state.
+     */
+    boolean hasCallWithState(CallState... states) {
+        for (Call call : mCalls.values()) {
+            for (CallState state : states) {
+                if (call.getState() == state) {
+                    return true;
+                }
+            }
+        }
+
+        return false;
+    }
+
+    /**
      * Adds the specified call to the main list of live calls.
      *
      * @param call The call to add.
@@ -353,7 +363,6 @@
         mPhoneStateBroadcaster.onCallAdded(call);
         mCallAudioManager.onCallAdded(call);
         mInCallController.onCallAdded(call);
-        mRinger.onCallAdded(call);
         updateForegroundCall();
     }
 
@@ -364,13 +373,11 @@
         mPhoneStateBroadcaster.onCallRemoved(call);
         mCallAudioManager.onCallRemoved(call);
         mInCallController.onCallRemoved(call);
-        mRinger.onCallRemoved(call);
         updateForegroundCall();
     }
 
     /**
-     * Sets the specified state on the specified call. Updates the ringer if the call is exiting
-     * the RINGING state.
+     * Sets the specified state on the specified call.
      *
      * @param callId The ID of the call to update.
      * @param newState The new state of the call.
@@ -389,8 +396,7 @@
     }
 
     /**
-     * Sets the specified state on the specified call. Updates the ringer if the call is exiting
-     * the RINGING state.
+     * Sets the specified state on the specified call.
      *
      * @param call The call.
      * @param newState The new state of the call.
@@ -413,7 +419,6 @@
                 mPhoneStateBroadcaster.onCallStateChanged(call, oldState, newState);
                 mCallAudioManager.onCallStateChanged(call, oldState, newState);
                 mInCallController.onCallStateChanged(call, oldState, newState);
-                mRinger.onCallStateChanged(call, oldState, newState);
                 updateForegroundCall();
             }
         }
@@ -444,7 +449,6 @@
             mPhoneStateBroadcaster.onForegroundCallChanged(oldForegroundCall, mForegroundCall);
             mCallAudioManager.onForegroundCallChanged(oldForegroundCall, mForegroundCall);
             mInCallController.onForegroundCallChanged(oldForegroundCall, mForegroundCall);
-            mRinger.onForegroundCallChanged(oldForegroundCall, mForegroundCall);
         }
     }
 }