Merge "Revert "Prevent video calls that down graded to audio calls from merging to"" am: 56017030f0 am: af5a15948e am: 252d2ddb6e

Change-Id: I413968720709b61dba62570f11785d0da1f9881d
diff --git a/src/com/android/services/telephony/TelecomAccountRegistry.java b/src/com/android/services/telephony/TelecomAccountRegistry.java
index 5ab4c88..adfae1b 100644
--- a/src/com/android/services/telephony/TelecomAccountRegistry.java
+++ b/src/com/android/services/telephony/TelecomAccountRegistry.java
@@ -1008,7 +1008,7 @@
      * @param handle The {@link PhoneAccountHandle}.
      * @return {@code True} if merging calls is supported.
      */
-    public boolean isMergeCallSupported(PhoneAccountHandle handle) {
+    boolean isMergeCallSupported(PhoneAccountHandle handle) {
         synchronized (mAccountsLock) {
             for (AccountEntry entry : mAccounts) {
                 if (entry.getPhoneAccountHandle().equals(handle)) {
@@ -1026,7 +1026,7 @@
      * @param handle The {@link PhoneAccountHandle}.
      * @return {@code True} if video conferencing is supported.
      */
-    public boolean isVideoConferencingSupported(PhoneAccountHandle handle) {
+    boolean isVideoConferencingSupported(PhoneAccountHandle handle) {
         synchronized (mAccountsLock) {
             for (AccountEntry entry : mAccounts) {
                 if (entry.getPhoneAccountHandle().equals(handle)) {
@@ -1044,7 +1044,7 @@
      * @param handle The {@link PhoneAccountHandle}.
      * @return {@code True} if merging of wifi calls is allowed when VoWIFI is disabled.
      */
-    public boolean isMergeOfWifiCallsAllowedWhenVoWifiOff(final PhoneAccountHandle handle) {
+    boolean isMergeOfWifiCallsAllowedWhenVoWifiOff(final PhoneAccountHandle handle) {
         synchronized (mAccountsLock) {
             Optional<AccountEntry> result = mAccounts.stream().filter(
                     entry -> entry.getPhoneAccountHandle().equals(handle)).findFirst();
@@ -1064,7 +1064,7 @@
      * @param handle The {@link PhoneAccountHandle}.
      * @return {@code True} if merging IMS calls is supported.
      */
-    public boolean isMergeImsCallSupported(PhoneAccountHandle handle) {
+    boolean isMergeImsCallSupported(PhoneAccountHandle handle) {
         synchronized (mAccountsLock) {
             for (AccountEntry entry : mAccounts) {
                 if (entry.getPhoneAccountHandle().equals(handle)) {
diff --git a/src/com/android/services/telephony/TelephonyConnection.java b/src/com/android/services/telephony/TelephonyConnection.java
index 95f4a04..f2b2244 100644
--- a/src/com/android/services/telephony/TelephonyConnection.java
+++ b/src/com/android/services/telephony/TelephonyConnection.java
@@ -2465,8 +2465,8 @@
         PhoneAccountHandle phoneAccountHandle = isIms ? PhoneUtils
                 .makePstnPhoneAccountHandle(phone.getDefaultPhone())
                 : PhoneUtils.makePstnPhoneAccountHandle(phone);
-        TelecomAccountRegistry telecomAccountRegistry = getTelecomAccountRegistry(
-                getPhone().getContext());
+        TelecomAccountRegistry telecomAccountRegistry = TelecomAccountRegistry
+                .getInstance(getPhone().getContext());
         boolean isConferencingSupported = telecomAccountRegistry
                 .isMergeCallSupported(phoneAccountHandle);
         boolean isImsConferencingSupported = telecomAccountRegistry
@@ -2475,17 +2475,6 @@
                 .isVideoConferencingSupported(phoneAccountHandle);
         boolean isMergeOfWifiCallsAllowedWhenVoWifiOff = telecomAccountRegistry
                 .isMergeOfWifiCallsAllowedWhenVoWifiOff(phoneAccountHandle);
-        ImsCall imsCall = ((ImsPhoneConnection) getOriginalConnection()).getImsCall();
-        CarrierConfigManager configManager = (CarrierConfigManager) phone.getContext()
-                .getSystemService(Context.CARRIER_CONFIG_SERVICE);
-        boolean downGradedVideoCall = false;
-        if (configManager != null) {
-            PersistableBundle config = configManager.getConfigForSubId(phone.getSubId());
-            if (config != null) {
-                downGradedVideoCall = config.getBoolean(
-                        CarrierConfigManager.KEY_TREAT_DOWNGRADED_VIDEO_CALLS_AS_VIDEO_CALLS_BOOL);
-            }
-        }
 
         Log.v(this, "refreshConferenceSupported : isConfSupp=%b, isImsConfSupp=%b, " +
                 "isVidConfSupp=%b, isMergeOfWifiAllowed=%b, " +
@@ -2506,12 +2495,6 @@
         } else if (isVideoCall && !mIsCarrierVideoConferencingSupported) {
             isConferenceSupported = false;
             Log.d(this, "refreshConferenceSupported = false; video conf not supported.");
-        } else if ((imsCall.wasVideoCall() && downGradedVideoCall)
-                && !mIsCarrierVideoConferencingSupported) {
-            isConferenceSupported = false;
-            Log.d(this,
-                    "refreshConferenceSupported = false;"
-                            + " video conf not supported for downgraded audio call.");
         } else if (!isMergeOfWifiCallsAllowedWhenVoWifiOff && isWifi() && !isVoWifiEnabled) {
             isConferenceSupported = false;
             Log.d(this,
@@ -2954,8 +2937,4 @@
             listener.onStatusHintsChanged(this, statusHints);
         }
     }
-
-    public TelecomAccountRegistry getTelecomAccountRegistry(Context context) {
-        return TelecomAccountRegistry.getInstance(context);
-    }
 }
diff --git a/tests/src/com/android/services/telephony/TelephonyConnectionTest.java b/tests/src/com/android/services/telephony/TelephonyConnectionTest.java
index 6f5e5c9..7d15680 100644
--- a/tests/src/com/android/services/telephony/TelephonyConnectionTest.java
+++ b/tests/src/com/android/services/telephony/TelephonyConnectionTest.java
@@ -1,17 +1,15 @@
 package com.android.services.telephony;
 
 import static junit.framework.Assert.assertEquals;
-import static junit.framework.Assert.assertTrue;
-import static junit.framework.TestCase.assertFalse;
 
 import android.os.Bundle;
 import android.telecom.Connection;
 
-import androidx.test.runner.AndroidJUnit4;
-
 import org.junit.Test;
 import org.junit.runner.RunWith;
 
+import androidx.test.runner.AndroidJUnit4;
+
 @RunWith(AndroidJUnit4.class)
 public class TelephonyConnectionTest {
 
@@ -24,17 +22,4 @@
         assertEquals(codec, Connection.AUDIO_CODEC_AMR);
     }
 
-    @Test
-    public void testConferenceNotSupportedForDownGradedVideoCall() {
-        TestTelephonyConnection c = new TestTelephonyConnection();
-        c.setIsImsConnection(true);
-        c.setIsVideoCall(false);
-        c.setWasVideoCall(true);
-        c.setDownGradeVideoCall(true);
-        c.refreshConferenceSupported();
-        assertFalse(c.isConferenceSupported());
-        c.setDownGradeVideoCall(false);
-        c.refreshConferenceSupported();
-        assertTrue(c.isConferenceSupported());
-    }
 }
diff --git a/tests/src/com/android/services/telephony/TestTelephonyConnection.java b/tests/src/com/android/services/telephony/TestTelephonyConnection.java
index d42ef5e..5b31c0f 100644
--- a/tests/src/com/android/services/telephony/TestTelephonyConnection.java
+++ b/tests/src/com/android/services/telephony/TestTelephonyConnection.java
@@ -16,29 +16,24 @@
 
 package com.android.services.telephony;
 
-import static org.mockito.ArgumentMatchers.any;
-import static org.mockito.ArgumentMatchers.anyInt;
-import static org.mockito.ArgumentMatchers.anyString;
-import static org.mockito.ArgumentMatchers.notNull;
-import static org.mockito.Mockito.doNothing;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.when;
-
 import android.content.Context;
 import android.content.res.Resources;
 import android.os.Bundle;
 import android.os.PersistableBundle;
 import android.telecom.PhoneAccountHandle;
-import android.telecom.VideoProfile;
-import android.telephony.CarrierConfigManager;
 
-import com.android.ims.ImsCall;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.ArgumentMatchers.anyInt;
+import static org.mockito.ArgumentMatchers.anyString;
+import static org.mockito.Mockito.doNothing;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
 import com.android.internal.telephony.Call;
 import com.android.internal.telephony.Connection;
 import com.android.internal.telephony.Phone;
 import com.android.internal.telephony.PhoneConstants;
 import com.android.internal.telephony.emergency.EmergencyNumberTracker;
-import com.android.internal.telephony.imsphone.ImsPhoneConnection;
 
 import org.mockito.Mock;
 import org.mockito.MockitoAnnotations;
@@ -67,45 +62,23 @@
     @Mock
     EmergencyNumberTracker mEmergencyNumberTracker;
 
-    @Mock
-    ImsPhoneConnection mImsPhoneConnection;
-
-    @Mock
-    ImsCall mImsCall;
-
-    @Mock
-    TelecomAccountRegistry mTelecomAccountRegistry;
-
-    @Mock
-    CarrierConfigManager mCarrierConfigManager;
-
-    private boolean mIsImsConnection;
-    private boolean mIsConferenceSupported = true;
     private Phone mMockPhone;
     private int mNotifyPhoneAccountChangedCount = 0;
     private List<String> mLastConnectionEvents = new ArrayList<>();
     private List<Bundle> mLastConnectionEventExtras = new ArrayList<>();
-    private Object mLock = new Object();
 
     @Override
     public com.android.internal.telephony.Connection getOriginalConnection() {
-        if (mIsImsConnection) {
-            return mImsPhoneConnection;
-        } else {
-            return mMockRadioConnection;
-        }
+        return mMockRadioConnection;
     }
 
     public TestTelephonyConnection() {
         super(null, null, false);
         MockitoAnnotations.initMocks(this);
 
-        mIsImsConnection = false;
         mMockPhone = mock(Phone.class);
         mMockContext = mock(Context.class);
         mOriginalConnection = mock(Connection.class);
-        mTelecomAccountRegistry = mock(TelecomAccountRegistry.class);
-
         // Set up mMockRadioConnection and mMockPhone to contain an active call
         when(mMockRadioConnection.getState()).thenReturn(Call.State.ACTIVE);
         when(mOriginalConnection.getState()).thenReturn(Call.State.ACTIVE);
@@ -127,17 +100,11 @@
         when(mMockPhone.getPhoneType()).thenReturn(PhoneConstants.PHONE_TYPE_IMS);
         when(mMockCall.getState()).thenReturn(Call.State.ACTIVE);
         when(mMockCall.getPhone()).thenReturn(mMockPhone);
-        when(mMockPhone.getDefaultPhone()).thenReturn(mMockPhone);
-        when(mImsPhoneConnection.getImsCall()).thenReturn(mImsCall);
-        when(mTelecomAccountRegistry.isMergeCallSupported(notNull(PhoneAccountHandle.class)))
-                .thenReturn(mIsConferenceSupported);
-        when(mTelecomAccountRegistry.isMergeImsCallSupported(notNull(PhoneAccountHandle.class)))
-                .thenReturn(mIsImsConnection);
-        when(mTelecomAccountRegistry
-                .isVideoConferencingSupported(notNull(PhoneAccountHandle.class))).thenReturn(false);
-        when(mTelecomAccountRegistry
-                .isMergeOfWifiCallsAllowedWhenVoWifiOff(notNull(PhoneAccountHandle.class)))
-                .thenReturn(false);
+    }
+
+    @Override
+    public boolean isConferenceSupported() {
+        return true;
     }
 
     public void setMockPhone(Phone newPhone) {
@@ -177,13 +144,6 @@
     }
 
     @Override
-    public void refreshConferenceSupported() {
-        if (mIsImsConnection) {
-            super.refreshConferenceSupported();
-        }
-    }
-
-    @Override
     public CharSequence getResourceText(int messageId) {
         return "TEST";
     }
@@ -194,30 +154,8 @@
     }
 
     @Override
-    public void setConferenceSupported(boolean conferenceSupported) {
-        mIsConferenceSupported = conferenceSupported;
-    }
-
-    @Override
-    public boolean isConferenceSupported() {
-        return mIsConferenceSupported;
-    }
-
-    @Override
-    public TelecomAccountRegistry getTelecomAccountRegistry(Context context) {
-        return mTelecomAccountRegistry;
-    }
-
-    public void setIsVideoCall(boolean isVideoCall) {
-        if (isVideoCall) {
-            setVideoState(VideoProfile.STATE_TX_ENABLED);
-        } else {
-            setVideoState(VideoProfile.STATE_AUDIO_ONLY);
-        }
-    }
-
-    public void setWasVideoCall(boolean wasVideoCall) {
-        when(mImsCall.wasVideoCall()).thenReturn(wasVideoCall);
+    void refreshConferenceSupported() {
+        // Requires ImsManager dependencies, do not implement during testing.
     }
 
     public int getNotifyPhoneAccountChangedCount() {
@@ -231,19 +169,4 @@
     public List<Bundle> getLastConnectionEventExtras() {
         return mLastConnectionEventExtras;
     }
-
-    public void setIsImsConnection(boolean isImsConnection) {
-        mIsImsConnection = isImsConnection;
-        when(mTelecomAccountRegistry.isMergeImsCallSupported(notNull(PhoneAccountHandle.class)))
-                .thenReturn(isImsConnection && mIsConferenceSupported);
-    }
-
-    public void setDownGradeVideoCall(boolean downgrade) {
-        PersistableBundle bundle = new PersistableBundle();
-        bundle.putBoolean(CarrierConfigManager.KEY_TREAT_DOWNGRADED_VIDEO_CALLS_AS_VIDEO_CALLS_BOOL,
-                downgrade);
-        when(mMockContext.getSystemService(Context.CARRIER_CONFIG_SERVICE))
-                .thenReturn(mCarrierConfigManager);
-        when(mCarrierConfigManager.getConfigForSubId(anyInt())).thenReturn(bundle);
-    }
 }