Ensure bluetooth does not get hangup sound when calling through gvoice

Because Google Voice works by canceling an outgoing call and starting up
its own outgoing call, telecom registers the first call as a
disconnecting call and sends a signal to the bluetooth device that the
call was disconnected. This causes a hangup sound from the bluetooth
device. This fix works by having bluetooth ignore a call until it gets
into the dialing state, which only happens after the google voice call
has connected.

Bug: 17662993
Change-Id: I52c504f615534c59ede8c0de520f755484922730
diff --git a/src/com/android/server/telecom/BluetoothPhoneService.java b/src/com/android/server/telecom/BluetoothPhoneService.java
index a8b71d9..9e02539 100644
--- a/src/com/android/server/telecom/BluetoothPhoneService.java
+++ b/src/com/android/server/telecom/BluetoothPhoneService.java
@@ -498,10 +498,15 @@
      * Sends a single clcc (C* List Current Calls) event for the specified call.
      */
     private void sendClccForCall(Call call) {
-        int index = getIndexForCall(call);
-        int direction = call.isIncoming() ? 1 : 0;
         boolean isForeground = getCallsManager().getForegroundCall() == call;
         int state = convertCallState(call.getState(), isForeground);
+
+        if (state == CALL_STATE_IDLE) {
+            return;
+        }
+
+        int index = getIndexForCall(call);
+        int direction = call.isIncoming() ? 1 : 0;
         boolean isPartOfConference = call.getParentCall() != null;
         Uri addressUri = call.getHandle();
         String address = addressUri == null ? null : addressUri.getSchemeSpecificPart();
@@ -583,6 +588,7 @@
     private int getBluetoothCallStateForUpdate() {
         CallsManager callsManager = getCallsManager();
         Call ringingCall = callsManager.getRingingCall();
+        Call dialingCall = callsManager.getDialingCall();
 
         //
         // !! WARNING !!
@@ -596,7 +602,7 @@
         int bluetoothCallState = CALL_STATE_IDLE;
         if (ringingCall != null) {
             bluetoothCallState = CALL_STATE_INCOMING;
-        } else if (callsManager.getDialingOrConnectingCall() != null) {
+        } else if (dialingCall != null) {
             bluetoothCallState = CALL_STATE_ALERTING;
         }
         return bluetoothCallState;
@@ -607,15 +613,17 @@
             case CallState.NEW:
             case CallState.ABORTED:
             case CallState.DISCONNECTED:
+            case CallState.CONNECTING:
+            case CallState.PRE_DIAL_WAIT:
+                if (callState == CallState.CONNECTING || callState == CallState.PRE_DIAL_WAIT) {
+                    Log.w(this, "convertCallState: unexpected state %s",
+                            CallState.toString(callState));
+                }
                 return CALL_STATE_IDLE;
 
             case CallState.ACTIVE:
                 return CALL_STATE_ACTIVE;
 
-            case CallState.CONNECTING:
-            case CallState.PRE_DIAL_WAIT:
-                return CALL_STATE_DIALING;
-
             case CallState.DIALING:
                 // Yes, this is correctly returning ALERTING.
                 // "Dialing" for BT means that we have sent information to the service provider