SIP: add the check for expiry time in Contact header.

There can be three expiry times in the same message header. We
choose the smaller value in Expires header and Contact header,
and then we obey the value defined in Min-Expires header. If
none of them is set, the default value is used.

Bug: 5178284

Change-Id: Ie9d4a48c93863e82e5197bb4a0db3f4fec56857c
diff --git a/java/com/android/server/sip/SipSessionGroup.java b/java/com/android/server/sip/SipSessionGroup.java
index 3b3cbf3..49effa8 100644
--- a/java/com/android/server/sip/SipSessionGroup.java
+++ b/java/com/android/server/sip/SipSessionGroup.java
@@ -72,6 +72,7 @@
 import javax.sip.address.Address;
 import javax.sip.address.SipURI;
 import javax.sip.header.CSeqHeader;
+import javax.sip.header.ContactHeader;
 import javax.sip.header.ExpiresHeader;
 import javax.sip.header.FromHeader;
 import javax.sip.header.HeaderAddress;
@@ -873,16 +874,21 @@
         }
 
         private int getExpiryTime(Response response) {
-            int expires = EXPIRY_TIME;
-            ExpiresHeader expiresHeader = (ExpiresHeader)
-                    response.getHeader(ExpiresHeader.NAME);
-            if (expiresHeader != null) expires = expiresHeader.getExpires();
-            expiresHeader = (ExpiresHeader)
-                    response.getHeader(MinExpiresHeader.NAME);
-            if (expiresHeader != null) {
-                expires = Math.max(expires, expiresHeader.getExpires());
+            int time = -1;
+            ContactHeader contact = (ContactHeader) response.getHeader(ContactHeader.NAME);
+            if (contact != null) {
+                time = contact.getExpires();
             }
-            return expires;
+            ExpiresHeader expires = (ExpiresHeader) response.getHeader(ExpiresHeader.NAME);
+            if (expires != null && (time < 0 || time > expires.getExpires())) {
+                time = expires.getExpires();
+            }
+            expires = (ExpiresHeader) response.getHeader(MinExpiresHeader.NAME);
+            if (expires != null && time < expires.getExpires()) {
+                time = expires.getExpires();
+            }
+            Log.v(TAG, "Expiry time = " + time);
+            return (time > 0) ? time : EXPIRY_TIME;
         }
 
         private boolean registeringToReady(EventObject evt)