Disconnect calls which were canceled via NEW_OUTGOING_CALL intent.

Bug: 17067923
Change-Id: Ida72b045f07e335bfa8c5542bdf40102e0a7a5de
diff --git a/src/com/android/telecomm/Call.java b/src/com/android/telecomm/Call.java
index 203aa84..e2dbb79 100644
--- a/src/com/android/telecomm/Call.java
+++ b/src/com/android/telecomm/Call.java
@@ -680,6 +680,7 @@
 
     @Override
     public void handleCreateConnectionCancelled() {
+        Log.v(this, "handleCreateConnectionCancelled");
         mCreateConnectionProcessor = null;
         if (mIsIncoming) {
             clearConnectionService();
@@ -746,8 +747,11 @@
     void abort() {
         if (mCreateConnectionProcessor != null) {
             mCreateConnectionProcessor.abort();
-        } else if (mState == CallState.PRE_DIAL_WAIT) {
-            handleCreateConnectionFailed(DisconnectCause.LOCAL, null);
+        } else if (mState == CallState.NEW || mState == CallState.PRE_DIAL_WAIT ||
+                mState == CallState.CONNECTING) {
+            handleCreateConnectionCancelled();
+        } else {
+            Log.v(this, "Cannot abort a call which isn't either PRE_DIAL_WAIT or CONNECTING");
         }
     }
 
diff --git a/src/com/android/telecomm/CallsManager.java b/src/com/android/telecomm/CallsManager.java
index aff1885..314020d 100644
--- a/src/com/android/telecomm/CallsManager.java
+++ b/src/com/android/telecomm/CallsManager.java
@@ -159,8 +159,7 @@
     @Override
     public void onCancelledOutgoingCall(Call call) {
         Log.v(this, "onCancelledOutgoingCall, call: %s", call);
-        setCallState(call, CallState.ABORTED);
-        removeCall(call);
+        markCallAsDisconnected(call, DisconnectCause.OUTGOING_CANCELED, null);
     }
 
     @Override
@@ -407,7 +406,7 @@
             call.startCreateConnection();
         } else {
             // This is the state where the user is expected to select an account
-            call.setState(CallState.PRE_DIAL_WAIT);
+            setCallState(call, CallState.PRE_DIAL_WAIT);
         }
     }
 
diff --git a/src/com/android/telecomm/NewOutgoingCallIntentBroadcaster.java b/src/com/android/telecomm/NewOutgoingCallIntentBroadcaster.java
index a3aa740..65c1309 100644
--- a/src/com/android/telecomm/NewOutgoingCallIntentBroadcaster.java
+++ b/src/com/android/telecomm/NewOutgoingCallIntentBroadcaster.java
@@ -100,11 +100,19 @@
             String resultHandle = getResultData();
             Log.v(this, "- got number from resultData: %s", Log.pii(resultHandle));
 
+            boolean endEarly = false;
             if (resultHandle == null) {
                 Log.v(this, "Call cancelled (null number), returning...");
-                return;
+                endEarly = true;
             } else if (PhoneNumberUtils.isPotentialLocalEmergencyNumber(context, resultHandle)) {
                 Log.w(this, "Cannot modify outgoing call to emergency number %s.", resultHandle);
+                endEarly = true;
+            }
+
+            if (endEarly) {
+                if (mCall != null) {
+                    mCall.disconnect();
+                }
                 return;
             }