SIP: add PEER_NOT_REACHABLE error feedback.

http://b/issue?id=3002033

Change-Id: Ib64b08919d214acbab89945ac19dc113a68e62ad
diff --git a/services/java/com/android/server/sip/SipSessionGroup.java b/services/java/com/android/server/sip/SipSessionGroup.java
index 3d002aa..a3bf3eb 100644
--- a/services/java/com/android/server/sip/SipSessionGroup.java
+++ b/services/java/com/android/server/sip/SipSessionGroup.java
@@ -1036,8 +1036,7 @@
 
         private void onError(Response response) {
             int statusCode = response.getStatusCode();
-            if (!mInCall && ((statusCode == Response.TEMPORARILY_UNAVAILABLE)
-                    || (statusCode == Response.BUSY_HERE))) {
+            if (!mInCall && (statusCode == Response.BUSY_HERE)) {
                 endCallOnBusy();
             } else {
                 onError(getErrorCode(statusCode), createErrorMessage(response));
@@ -1046,11 +1045,22 @@
 
         private SipErrorCode getErrorCode(int responseStatusCode) {
             switch (responseStatusCode) {
+                case Response.TEMPORARILY_UNAVAILABLE:
+                case Response.FORBIDDEN:
+                case Response.GONE:
                 case Response.NOT_FOUND:
+                case Response.NOT_ACCEPTABLE:
+                case Response.NOT_ACCEPTABLE_HERE:
+                    return SipErrorCode.PEER_NOT_REACHABLE;
+
+                case Response.REQUEST_URI_TOO_LONG:
                 case Response.ADDRESS_INCOMPLETE:
+                case Response.AMBIGUOUS:
                     return SipErrorCode.INVALID_REMOTE_URI;
+
                 case Response.REQUEST_TIMEOUT:
                     return SipErrorCode.TIME_OUT;
+
                 default:
                     if (responseStatusCode < 500) {
                         return SipErrorCode.CLIENT_ERROR;
diff --git a/telephony/java/com/android/internal/telephony/Connection.java b/telephony/java/com/android/internal/telephony/Connection.java
index c20c200..72c50fc 100644
--- a/telephony/java/com/android/internal/telephony/Connection.java
+++ b/telephony/java/com/android/internal/telephony/Connection.java
@@ -39,6 +39,7 @@
         CONGESTION,                     /* outgoing call to congested network */
         MMI,                            /* not presently used; dial() returns null */
         INVALID_NUMBER,                 /* invalid dial string */
+        NUMBER_UNREACHABLE,             /* cannot reach the peer */
         INVALID_CREDENTIALS,            /* invalid credentials */
         TIMED_OUT,                      /* client timed out */
         LOST_SIGNAL,
diff --git a/telephony/java/com/android/internal/telephony/sip/SipPhone.java b/telephony/java/com/android/internal/telephony/sip/SipPhone.java
index 943f21c..b009786 100755
--- a/telephony/java/com/android/internal/telephony/sip/SipPhone.java
+++ b/telephony/java/com/android/internal/telephony/sip/SipPhone.java
@@ -606,6 +606,7 @@
                 }
                 synchronized (SipPhone.class) {
                     setState(Call.State.DISCONNECTED);
+                    mSipAudioCall.close();
                     mOwner.onConnectionEnded(SipConnection.this);
                     Log.v(LOG_TAG, "-------- connection ended: "
                             + mPeer.getUriString() + ": "
@@ -822,6 +823,9 @@
         public void onError(SipAudioCall call, SipErrorCode errorCode,
                 String errorMessage) {
             switch (errorCode) {
+                case PEER_NOT_REACHABLE:
+                    onError(Connection.DisconnectCause.NUMBER_UNREACHABLE);
+                    break;
                 case INVALID_REMOTE_URI:
                     onError(Connection.DisconnectCause.INVALID_NUMBER);
                     break;
@@ -839,6 +843,7 @@
                 case SERVER_ERROR:
                 case CLIENT_ERROR:
                 default:
+                    Log.w(LOG_TAG, "error: " + errorCode + ": " + errorMessage);
                     onError(Connection.DisconnectCause.ERROR_UNSPECIFIED);
             }
         }
diff --git a/voip/java/android/net/sip/SipErrorCode.java b/voip/java/android/net/sip/SipErrorCode.java
index 963733e..ee985de 100644
--- a/voip/java/android/net/sip/SipErrorCode.java
+++ b/voip/java/android/net/sip/SipErrorCode.java
@@ -43,6 +43,9 @@
     /** When the remote URI is not valid. */
     INVALID_REMOTE_URI,
 
+    /** When the peer is not reachable. */
+    PEER_NOT_REACHABLE,
+
     /** When invalid credentials are provided. */
     INVALID_CREDENTIALS,