Implement extra logic for disabling add call

This change sets the disable add call extra if:
The carrier forbids adding calls during video calls AND
(The call is currently a video call OR
 (The call used to be a video call AND it is on wifi AND voice over wifi
  is disabled)
)

Bug: 29047863
Change-Id: I1356e15cf65cb64534b92e159b3ad4f67ebc7b19
diff --git a/src/com/android/services/telephony/TelephonyConnection.java b/src/com/android/services/telephony/TelephonyConnection.java
index 07cd7b5..8481320 100644
--- a/src/com/android/services/telephony/TelephonyConnection.java
+++ b/src/com/android/services/telephony/TelephonyConnection.java
@@ -34,6 +34,7 @@
 import android.telephony.PhoneNumberUtils;
 import android.util.Pair;
 
+import com.android.ims.ImsCall;
 import com.android.ims.ImsCallProfile;
 import com.android.internal.telephony.Call;
 import com.android.internal.telephony.CallStateException;
@@ -44,6 +45,7 @@
 
 import com.android.internal.telephony.Phone;
 import com.android.internal.telephony.imsphone.ImsPhone;
+import com.android.internal.telephony.imsphone.ImsPhoneCallTracker;
 import com.android.phone.PhoneUtils;
 import com.android.phone.R;
 
@@ -164,8 +166,9 @@
                     setVideoState(videoState);
 
                     // A change to the video state of the call can influence whether or not it
-                    // can be part of a conference.
+                    // can be part of a conference and whether another call can be added.
                     refreshConferenceSupported();
+                    refreshDisableAddCall();
                     break;
 
                 case MSG_SET_VIDEO_PROVIDER:
@@ -779,10 +782,10 @@
             extrasToRemove.add(Connection.EXTRA_ANSWERING_DROPS_FG_CALL);
         }
 
-        if (!mOriginalConnection.shouldAllowAddCallDuringVideoCall()) {
-            extrasToPut.putBoolean(Connection.EXTRA_DISABLE_ADD_CALL_DURING_VIDEO_CALL, true);
+        if (shouldSetDisableAddCallExtra()) {
+            extrasToPut.putBoolean(Connection.EXTRA_DISABLE_ADD_CALL, true);
         } else {
-            extrasToRemove.add(Connection.EXTRA_DISABLE_ADD_CALL_DURING_VIDEO_CALL);
+            extrasToRemove.add(Connection.EXTRA_DISABLE_ADD_CALL);
         }
         putExtras(extrasToPut);
         removeExtras(extrasToRemove);
@@ -807,6 +810,48 @@
         }
     }
 
+    private void refreshDisableAddCall() {
+        if (shouldSetDisableAddCallExtra()) {
+            putExtra(Connection.EXTRA_DISABLE_ADD_CALL, true);
+        } else {
+            removeExtras(Connection.EXTRA_DISABLE_ADD_CALL);
+        }
+    }
+
+    private boolean shouldSetDisableAddCallExtra() {
+        boolean carrierShouldAllowAddCall = mOriginalConnection.shouldAllowAddCallDuringVideoCall();
+        if (carrierShouldAllowAddCall) {
+            return false;
+        }
+        Phone phone = getPhone();
+        if (phone == null) {
+            return false;
+        }
+        boolean isCurrentVideoCall = false;
+        boolean wasVideoCall = false;
+        boolean isWifiCall = false;
+        boolean isVowifiEnabled = false;
+        if (phone instanceof ImsPhone) {
+            ImsPhone imsPhone = (ImsPhone) phone;
+            if (imsPhone.getForegroundCall() != null
+                    && imsPhone.getForegroundCall().getImsCall() != null) {
+                ImsCall call = imsPhone.getForegroundCall().getImsCall();
+                isCurrentVideoCall = call.isVideoCall();
+                wasVideoCall = call.wasVideoCall();
+                isWifiCall = call.isWifiCall();
+            }
+
+            isVowifiEnabled = ((ImsPhoneCallTracker) imsPhone.getCallTracker()).isVowifiEnabled();
+        }
+
+        if (isCurrentVideoCall) {
+            return true;
+        } else if (wasVideoCall && isWifiCall && !isVowifiEnabled) {
+            return true;
+        }
+        return false;
+    }
+
     /**
      * Whether the connection should be treated as an emergency.
      * @return {@code true} if the connection should be treated as an emergency call based