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

Commit 0257d64c authored by Tyler Gunn's avatar Tyler Gunn
Browse files

Correct behavior answering incoming call with dialing self-managed call.

When answering an incoming call with a dialing self-managed call in
progress, the incoming call could be answered while the dialing self-mgd
call would remain dialing as well.

Reviewing the logic, dialing calls can't be held, so changing the "canHold"
logic to take that into account.  Now in this scenario the user will be
prompted on the incoming call screen that answering the call will end the
ongoing "X app" call.  If they answer the call, the dialing call is
disconnected.

Test: Reproduced using Telecom test app.  Verified fix corrects issue.
Test: Added unit test for this scenario and ran all existing unit tests.
Bug: 129507552
Change-Id: I80d5ad4875e56df790ad988c01bb7a42a9f0609d
AOSP: aosp/954991
parent 8acd3e21
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -2513,7 +2513,7 @@ public class Call implements CreateConnectionResponse, EventManager.Loggable,
     * networks at least), so we still enable this feature even though
     * SMSes to that number will silently fail.
     */
    boolean isRespondViaSmsCapable() {
    public boolean isRespondViaSmsCapable() {
        if (mState != CallState.RINGING) {
            return false;
        }
+2 −2
Original line number Diff line number Diff line
@@ -1945,7 +1945,7 @@ public class CallsManager extends Call.ListenerBase
        } else {
            // Hold or disconnect the active call and request call focus for the incoming call.
            Call activeCall = (Call) mConnectionSvrFocusMgr.getCurrentFocusCall();
            Log.d(this, "Incoming call = %s Ongoing call %s", call, activeCall);
            Log.d(this, "answerCall: Incoming call = %s Ongoing call %s", call, activeCall);
            holdActiveCallForNewCall(call);
            mConnectionSvrFocusMgr.requestFocus(
                    call,
@@ -4449,7 +4449,7 @@ public class CallsManager extends Call.ListenerBase
    }

    private boolean canHold(Call call) {
        return call.can(Connection.CAPABILITY_HOLD);
        return call.can(Connection.CAPABILITY_HOLD) && call.getState() != CallState.DIALING;
    }

    private boolean supportsHold(Call call) {
+2 −0
Original line number Diff line number Diff line
@@ -104,6 +104,8 @@ public class SelfManagedConnectionService extends ConnectionService {
        if (isIncoming) {
            connection.setIsIncomingCallUiShowing(request.shouldShowIncomingCallUi());
            connection.setRinging();
        } else {
            connection.setDialing();
        }
        Bundle requestExtras = request.getExtras();
        if (requestExtras != null) {
+34 −1
Original line number Diff line number Diff line
@@ -115,7 +115,7 @@ public class CallsManagerTest extends TelecomTestCase {
    private static final PhoneAccountHandle VOIP_1_HANDLE = new PhoneAccountHandle(
            ComponentName.unflattenFromString("com.voip/.Stuff"), "Voip1");
    private static final PhoneAccountHandle SELF_MANAGED_HANDLE = new PhoneAccountHandle(
            ComponentName.unflattenFromString("com.foo/.Self"), "Self");
            ComponentName.unflattenFromString("com.baz/.Self"), "Self");
    private static final PhoneAccount SIM_1_ACCOUNT = new PhoneAccount.Builder(SIM_1_HANDLE, "Sim1")
            .setCapabilities(PhoneAccount.CAPABILITY_SIM_SUBSCRIPTION
                    | PhoneAccount.CAPABILITY_CALL_PROVIDER)
@@ -820,6 +820,39 @@ public class CallsManagerTest extends TelecomTestCase {
        assertEquals(CallState.ACTIVE, newCall.getState());
    }

    @SmallTest
    @Test
    public void testDisconnectDialingCallOnIncoming() {
        // GIVEN a CallsManager with a self-managed call which is dialing, and this call can be held
        Call ongoingCall = addSpyCall(SELF_MANAGED_HANDLE);
        ongoingCall.setState(CallState.DIALING, "test");
        doReturn(true).when(ongoingCall).can(Connection.CAPABILITY_HOLD);
        doReturn(true).when(ongoingCall).can(Connection.CAPABILITY_SUPPORT_HOLD);
        doReturn(true).when(ongoingCall).isSelfManaged();
        doReturn(ongoingCall).when(mConnectionSvrFocusMgr).getCurrentFocusCall();

        // and a new incoming managed call
        Call newCall = addSpyCall();
        doReturn(false).when(newCall).isRespondViaSmsCapable();
        newCall.setState(CallState.RINGING, "test");

        // WHEN answering the new call
        mCallsManager.answerCall(newCall, VideoProfile.STATE_AUDIO_ONLY);

        // THEN the ongoing call is disconnected
        verify(ongoingCall).disconnect();

        // AND focus is requested for the new call
        ArgumentCaptor<CallsManager.RequestCallback> requestCaptor =
                ArgumentCaptor.forClass(CallsManager.RequestCallback.class);
        verify(mConnectionSvrFocusMgr).requestFocus(eq(newCall), requestCaptor.capture());
        // since we're mocking the focus manager, we'll just pretend it did its thing.
        requestCaptor.getValue().onRequestFocusDone(newCall);

        // and the new call is marked answered
        assertEquals(CallState.ANSWERED, newCall.getState());
    }

    @SmallTest
    @Test
    public void testNoFilteringOfSelfManagedCalls() {