Catch SIP exceptions which can crash Phone process on answer.

There are two exceptions which can be raised when answering a call which
can cause the Phone process to crash on answer.
1. IllegalStateException due to answering a call with an incompatible
codec.
2. IllegalArgumentException due to answering a call with a malformed
SDP.
In both of these cases we catch the exception and reject the call to stop
it from ringing (otherwise it will keep ringing and the user will not be
able to stop it).

The existing CallStateException does not require onReject to be called as
it is thrown when the call has already been disconnected before it can be
answered.
Test: Manual (see bug)
Bug: 31752213
Change-Id: I5254fd3a27b86fdc70889ea0a2b5be3b699fd9f5
(cherry picked from commit 06a98183cc79dd112d9d33cf027977a9d5d3418a)

(cherry picked from commit eb72c560946a61853b15cb96bba83957d948b6d4)
diff --git a/sip/src/com/android/services/telephony/sip/SipConnection.java b/sip/src/com/android/services/telephony/sip/SipConnection.java
index b10ae56..2dde5b5 100644
--- a/sip/src/com/android/services/telephony/sip/SipConnection.java
+++ b/sip/src/com/android/services/telephony/sip/SipConnection.java
@@ -24,6 +24,7 @@
 import android.telecom.Connection;
 import android.telecom.PhoneAccount;
 import android.telecom.TelecomManager;
+import android.util.EventLog;
 import android.util.Log;
 
 import com.android.internal.telephony.Call;
@@ -181,6 +182,18 @@
             }
         } catch (CallStateException e) {
             log("onAnswer, exception: " + e);
+        } catch (IllegalStateException e) {
+            // Call could not be answered due to an invalid audio-codec offered by the caller.  We
+            // will reject the call to stop it from ringing.
+            log("onAnswer, IllegalStateException: " + e);
+            EventLog.writeEvent(0x534e4554, "31752213", -1, "Invalid codec.");
+            onReject();
+        } catch (IllegalArgumentException e) {
+            // Call could not be answered due to an error parsing the SDP.  We will reject the call
+            // to stop it from ringing.
+            log("onAnswer, IllegalArgumentException: " + e);
+            EventLog.writeEvent(0x534e4554, "31752213", -1, "Invalid SDP.");
+            onReject();
         }
     }