Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit f3dd2901 authored by Thomas Stuart's avatar Thomas Stuart Committed by Android (Google) Code Review
Browse files

Merge "Only inject telecom business extras if the business composer is enabled" into main

parents 90823137 4eba42d5
Loading
Loading
Loading
Loading
+72 −1
Original line number Original line Diff line number Diff line
@@ -157,6 +157,11 @@ public class ImsPhoneConnection extends Connection implements
     */
     */
    private boolean mIsHeldByRemote = false;
    private boolean mIsHeldByRemote = false;


    /**
     * Used to indicate if both the user and carrier config have enabled the business composer.
     */
    private boolean mIsBusinessComposerFeatureEnabled = false;

    //***** Event Constants
    //***** Event Constants
    private static final int EVENT_DTMF_DONE = 1;
    private static final int EVENT_DTMF_DONE = 1;
    private static final int EVENT_PAUSE_DONE = 2;
    private static final int EVENT_PAUSE_DONE = 2;
@@ -230,6 +235,10 @@ public class ImsPhoneConnection extends Connection implements
        mCreateTime = System.currentTimeMillis();
        mCreateTime = System.currentTimeMillis();
        mUusInfo = null;
        mUusInfo = null;


        if (com.android.server.telecom.flags.Flags.businessCallComposer()) {
            setIsBusinessComposerFeatureEnabled(phone);
        }

        // Ensure any extras set on the ImsCallProfile at the start of the call are cached locally
        // Ensure any extras set on the ImsCallProfile at the start of the call are cached locally
        // in the ImsPhoneConnection.  This isn't going to inform any listeners (since the original
        // in the ImsPhoneConnection.  This isn't going to inform any listeners (since the original
        // connection is not likely to be associated with a TelephonyConnection yet).
        // connection is not likely to be associated with a TelephonyConnection yet).
@@ -1389,10 +1398,18 @@ public class ImsPhoneConnection extends Connection implements
     * ImsCallProfile.EXTRA_ASSERTED_DISPLAY_NAME). This helper notifies Telecom of the business
     * ImsCallProfile.EXTRA_ASSERTED_DISPLAY_NAME). This helper notifies Telecom of the business
     * composer values which will then be injected into the android.telecom.Call object.
     * composer values which will then be injected into the android.telecom.Call object.
     */
     */
    private void maybeInjectBusinessComposerExtras(Bundle extras) {
    @VisibleForTesting
    public void maybeInjectBusinessComposerExtras(Bundle extras) {
        if (extras == null) {
        if (extras == null) {
            return;
            return;
        }
        }
        // Telephony should check that the business composer features is on BEFORE
        // propagating the business call extras.  This prevents the user from getting
        // business call info when they turned the feature off.
        if (!mIsBusinessComposerFeatureEnabled) {
            Rlog.i(LOG_TAG, "mIBCE: business composer feature is NOT enabled");
            return;
        }
        try {
        try {
            if (extras.containsKey(ImsCallProfile.EXTRA_IS_BUSINESS_CALL)
            if (extras.containsKey(ImsCallProfile.EXTRA_IS_BUSINESS_CALL)
                    && !extras.containsKey(android.telecom.Call.EXTRA_IS_BUSINESS_CALL)) {
                    && !extras.containsKey(android.telecom.Call.EXTRA_IS_BUSINESS_CALL)) {
@@ -1413,6 +1430,60 @@ public class ImsPhoneConnection extends Connection implements
        }
        }
    }
    }


    @VisibleForTesting
    public boolean getIsBusinessComposerFeatureEnabled() {
        return mIsBusinessComposerFeatureEnabled;
    }

    @VisibleForTesting
    public void setIsBusinessComposerFeatureEnabled(Phone phone) {
        mIsBusinessComposerFeatureEnabled = isBusinessComposerEnabledByConfig(phone)
                && isBusinessOnlyCallComposerEnabledByUser(phone);
        Rlog.i(LOG_TAG, String.format(
                "setIsBusinessComposerFeatureEnabled:  mIsBusinessComposerFeatureEnabled=[%b], "
                        + "phone=[%s]", mIsBusinessComposerFeatureEnabled, phone));
    }

    /**
     * Returns whether the carrier supports and has enabled the business composer
     */
    @VisibleForTesting
    public boolean isBusinessComposerEnabledByConfig(Phone phone) {
        PersistableBundle b = null;
        CarrierConfigManager configMgr = phone.getContext().getSystemService(
                CarrierConfigManager.class);

        if (configMgr != null) {
            // If an invalid subId is used, this bundle will contain default values.
            b = configMgr.getConfigForSubId(phone.getSubId());
        }
        if (b != null) {
            return b.getBoolean(CarrierConfigManager.KEY_SUPPORTS_BUSINESS_CALL_COMPOSER_BOOL);
        } else {
            // Return static default defined in CarrierConfigManager.
            return CarrierConfigManager.getDefaultConfig()
                    .getBoolean(CarrierConfigManager.KEY_SUPPORTS_BUSINESS_CALL_COMPOSER_BOOL);
        }
    }

    /**
     * Returns whether the user has enabled the business composer
     */
    @VisibleForTesting
    public boolean isBusinessOnlyCallComposerEnabledByUser(Phone phone) {
        if (phone == null || phone.getContext() == null) {
            return false;
        }
        TelephonyManager tm = (TelephonyManager)
                phone.getContext().getSystemService(Context.TELEPHONY_SERVICE);
        if (tm == null) {
            Rlog.e(LOG_TAG, "isBusinessOnlyCallComposerEnabledByUser: TelephonyManager is null");
            return false;
        }
        return tm.getCallComposerStatus() == TelephonyManager.CALL_COMPOSER_STATUS_BUSINESS_ONLY
                || tm.getCallComposerStatus() == TelephonyManager.CALL_COMPOSER_STATUS_ON;
    }

    private static boolean areBundlesEqual(Bundle extras, Bundle newExtras) {
    private static boolean areBundlesEqual(Bundle extras, Bundle newExtras) {
        if (extras == null || newExtras == null) {
        if (extras == null || newExtras == null) {
            return extras == newExtras;
            return extras == newExtras;
+128 −0
Original line number Original line Diff line number Diff line
@@ -40,6 +40,8 @@ import android.os.Bundle;
import android.os.Handler;
import android.os.Handler;
import android.os.Looper;
import android.os.Looper;
import android.os.Message;
import android.os.Message;
import android.os.PersistableBundle;
import android.telephony.CarrierConfigManager;
import android.telephony.DisconnectCause;
import android.telephony.DisconnectCause;
import android.telephony.PhoneNumberUtils;
import android.telephony.PhoneNumberUtils;
import android.telephony.ServiceState;
import android.telephony.ServiceState;
@@ -57,6 +59,7 @@ import com.android.ims.ImsException;
import com.android.internal.telephony.Call;
import com.android.internal.telephony.Call;
import com.android.internal.telephony.Connection;
import com.android.internal.telephony.Connection;
import com.android.internal.telephony.GsmCdmaCall;
import com.android.internal.telephony.GsmCdmaCall;
import com.android.internal.telephony.Phone;
import com.android.internal.telephony.PhoneConstants;
import com.android.internal.telephony.PhoneConstants;
import com.android.internal.telephony.TelephonyTest;
import com.android.internal.telephony.TelephonyTest;
import com.android.internal.telephony.imsphone.ImsPhone.ImsDialArgs;
import com.android.internal.telephony.imsphone.ImsPhone.ImsDialArgs;
@@ -95,6 +98,8 @@ public class ImsPhoneConnectionTest extends TelephonyTest {
        mForeGroundCall = mock(ImsPhoneCall.class);
        mForeGroundCall = mock(ImsPhoneCall.class);
        mBackGroundCall = mock(ImsPhoneCall.class);
        mBackGroundCall = mock(ImsPhoneCall.class);
        mRingGroundCall = mock(ImsPhoneCall.class);
        mRingGroundCall = mock(ImsPhoneCall.class);
        mTelephonyManager = mock(TelephonyManager.class);
        mCarrierConfigManager = mock(CarrierConfigManager.class);
        replaceInstance(Handler.class, "mLooper", mImsCT, Looper.myLooper());
        replaceInstance(Handler.class, "mLooper", mImsCT, Looper.myLooper());
        replaceInstance(ImsPhoneCallTracker.class, "mForegroundCall", mImsCT, mForeGroundCall);
        replaceInstance(ImsPhoneCallTracker.class, "mForegroundCall", mImsCT, mForeGroundCall);
        replaceInstance(ImsPhoneCallTracker.class, "mBackgroundCall", mImsCT, mBackGroundCall);
        replaceInstance(ImsPhoneCallTracker.class, "mBackgroundCall", mImsCT, mBackGroundCall);
@@ -103,6 +108,10 @@ public class ImsPhoneConnectionTest extends TelephonyTest {


        mImsCallProfile.mCallExtras = mBundle;
        mImsCallProfile.mCallExtras = mBundle;
        doReturn(ImsPhoneCall.State.IDLE).when(mForeGroundCall).getState();
        doReturn(ImsPhoneCall.State.IDLE).when(mForeGroundCall).getState();

        // By default, turn off the business composer
        setUserEnabledBusinessComposer(false);
        setCarrierConfigBusinessComposer(false);
    }
    }


    @After
    @After
@@ -431,6 +440,97 @@ public class ImsPhoneConnectionTest extends TelephonyTest {
                ImsPhoneConnection.toTelecomVerificationStatus(90210));
                ImsPhoneConnection.toTelecomVerificationStatus(90210));
    }
    }


    /**
     * Assert the helper method
     * {@link ImsPhoneConnection#isBusinessOnlyCallComposerEnabledByUser(Phone)} is Working As
     * Intended.
     */
    @Test
    @SmallTest
    public void testIsBusinessOnlyCallComposerEnabledByUser() {
        mConnectionUT = new ImsPhoneConnection(mImsPhone, mImsCall, mImsCT, mForeGroundCall, false);
        assertFalse(mConnectionUT.isBusinessOnlyCallComposerEnabledByUser(mImsPhone));
        setUserEnabledBusinessComposer(true);
        assertTrue(mConnectionUT.isBusinessOnlyCallComposerEnabledByUser(mImsPhone));
        setUserEnabledBusinessComposer(false);
        assertFalse(mConnectionUT.isBusinessOnlyCallComposerEnabledByUser(mImsPhone));
    }

    /**
     * Assert the helper method
     * {@link ImsPhoneConnection#isBusinessComposerEnabledByConfig(Phone)} is Working As
     * Intended.
     */
    @Test
    @SmallTest
    public void testBusinessComposerEnabledByCarrierConfig() {
        mConnectionUT = new ImsPhoneConnection(mImsPhone, mImsCall, mImsCT, mForeGroundCall, false);
        assertFalse(mConnectionUT.isBusinessComposerEnabledByConfig(mImsPhone));
        setCarrierConfigBusinessComposer(true);
        assertTrue(mConnectionUT.isBusinessComposerEnabledByConfig(mImsPhone));
        setCarrierConfigBusinessComposer(false);
        assertFalse(mConnectionUT.isBusinessComposerEnabledByConfig(mImsPhone));
    }

    /**
     * Verify that the {@link ImsPhoneConnection#getIsBusinessComposerFeatureEnabled()} only
     * returns true when it is enabled by the CarrierConfigManager and user.
     */
    @Test
    @SmallTest
    public void testIncomingImsCallSetsTheBusinessComposerFeatureStatus() {
        mConnectionUT = new ImsPhoneConnection(mImsPhone, mImsCall, mImsCT, mForeGroundCall, false);
        assertFalse(mConnectionUT.getIsBusinessComposerFeatureEnabled());

        setUserEnabledBusinessComposer(true);
        setCarrierConfigBusinessComposer(false);
        mConnectionUT = new ImsPhoneConnection(mImsPhone, mImsCall, mImsCT, mForeGroundCall, false);
        assertFalse(mConnectionUT.getIsBusinessComposerFeatureEnabled());

        setUserEnabledBusinessComposer(false);
        setCarrierConfigBusinessComposer(true);
        mConnectionUT = new ImsPhoneConnection(mImsPhone, mImsCall, mImsCT, mForeGroundCall, false);
        assertFalse(mConnectionUT.getIsBusinessComposerFeatureEnabled());

        setUserEnabledBusinessComposer(true);
        setCarrierConfigBusinessComposer(true);
        mConnectionUT = new ImsPhoneConnection(mImsPhone, mImsCall, mImsCT, mForeGroundCall, false);
        assertTrue(mConnectionUT.getIsBusinessComposerFeatureEnabled());
    }

    /**
     * If the business composer feature is off but ImsCallProfile extras still injected by the lower
     * layer, Telephony should NOT inject the telecom call extras.
     */
    @Test
    @SmallTest
    public void testMaybeInjectBusinessExtrasWithFeatureOff() {
        setUserEnabledBusinessComposer(false);
        setCarrierConfigBusinessComposer(false);
        mConnectionUT = new ImsPhoneConnection(mImsPhone, mImsCall, mImsCT, mForeGroundCall, false);
        assertFalse(mConnectionUT.getIsBusinessComposerFeatureEnabled());
        Bundle businessExtras = getBusinessExtras();
        mConnectionUT.maybeInjectBusinessComposerExtras(businessExtras);
        assertFalse(businessExtras.containsKey(android.telecom.Call.EXTRA_IS_BUSINESS_CALL));
        assertFalse(businessExtras.containsKey(android.telecom.Call.EXTRA_ASSERTED_DISPLAY_NAME));
    }

    /**
     * Verify if the business composer feature is on, telephony is injecting the telecom call extras
     */
    @Test
    @SmallTest
    public void testMaybeInjectBusinessExtrasWithFeatureOn() {
        setUserEnabledBusinessComposer(true);
        setCarrierConfigBusinessComposer(true);
        mConnectionUT = new ImsPhoneConnection(mImsPhone, mImsCall, mImsCT, mForeGroundCall, false);
        assertTrue(mConnectionUT.getIsBusinessComposerFeatureEnabled());
        Bundle businessExtras = getBusinessExtras();
        mConnectionUT.maybeInjectBusinessComposerExtras(businessExtras);
        assertTrue(businessExtras.containsKey(android.telecom.Call.EXTRA_IS_BUSINESS_CALL));
        assertTrue(businessExtras.containsKey(android.telecom.Call.EXTRA_ASSERTED_DISPLAY_NAME));
    }

    @Test
    @Test
    @SmallTest
    @SmallTest
    public void testSetRedirectingAddress() {
    public void testSetRedirectingAddress() {
@@ -481,4 +581,32 @@ public class ImsPhoneConnectionTest extends TelephonyTest {
        latch.await(TIMEOUT_MILLIS, TimeUnit.MILLISECONDS);
        latch.await(TIMEOUT_MILLIS, TimeUnit.MILLISECONDS);
        assertTrue(receivedCountCallback[0]);
        assertTrue(receivedCountCallback[0]);
    }
    }

    private void setUserEnabledBusinessComposer(boolean isEnabled) {
        when(mPhone.getContext()).thenReturn(mContext);
        when(mContext.getSystemService(TelephonyManager.class)).thenReturn(mTelephonyManager);
        if (isEnabled) {
            when(mTelephonyManager.getCallComposerStatus()).thenReturn(
                    TelephonyManager.CALL_COMPOSER_STATUS_BUSINESS_ONLY);
        } else {
            when(mTelephonyManager.getCallComposerStatus()).thenReturn(
                    TelephonyManager.CALL_COMPOSER_STATUS_OFF);
        }
    }

    private void setCarrierConfigBusinessComposer(boolean isEnabled) {
        when(mPhone.getContext()).thenReturn(mContext);
        when(mContext.getSystemService(CarrierConfigManager.class)).thenReturn(
                mCarrierConfigManager);
        PersistableBundle b = new PersistableBundle();
        b.putBoolean(CarrierConfigManager.KEY_SUPPORTS_BUSINESS_CALL_COMPOSER_BOOL, isEnabled);
        when(mCarrierConfigManager.getConfigForSubId(mPhone.getSubId())).thenReturn(b);
    }

    private Bundle getBusinessExtras() {
        Bundle businessExtras = new Bundle();
        businessExtras.putBoolean(ImsCallProfile.EXTRA_IS_BUSINESS_CALL, true);
        businessExtras.putString(ImsCallProfile.EXTRA_ASSERTED_DISPLAY_NAME, "Google");
        return businessExtras;
    }
}
}