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

Commit 7868ff22 authored by Pranav Madapurmath's avatar Pranav Madapurmath
Browse files

Ensure disconnecting state is notified to listeners

I had originally removed this in the call sequencing code path as I
thought it was a redundant update because we were already sending the
disconnected state onCallStateChanged. This, however, prevented the
intermediate disconnecting state to be notified to the registered
listeners which were causing some test failures.

In the case of a failure, ensure that we reset the disconnecting call
state and notify the listeners as well.

Bug: 417327935
Flag: EXEMPT bug fix
Test: Manual
Change-Id: I9617d4a1924bde04374c6ac29603d5ff168b9686
parent 2d16482b
Loading
Loading
Loading
Loading
+13 −0
Original line number Diff line number Diff line
@@ -3659,6 +3659,19 @@ public class CallsManager extends Call.ListenerBase
        }
        mPendingAccountSelection.remove(callId);
    }

    /**
     * Derived from the disconnectCallOld logic to ensure that the registered listeners are notified
     * of the disconnecting state once the call is disconnected. This is used for call sequencing.
     * @param call The call to notify the state change for.
     * @param previousState The previous call state before the disconnect.
     */
    public void notifyCallStateChangeForDisconnect(Call call, int previousState) {
        for (CallsManagerListener listener : mListeners) {
            listener.onCallStateChanged(call, previousState, call.getState());
        }
    }

    /**
     * Disconnects calls for any other {@link PhoneAccountHandle} but the one specified.
     * Note: As a protective measure, will NEVER disconnect an emergency call.  Although that
+7 −0
Original line number Diff line number Diff line
@@ -863,12 +863,19 @@ public class CallSequencingController {
     */
    public void disconnectCall(Call call, int previousState) {
        CompletableFuture<Boolean> disconnectFuture = call.disconnect();
        int newState = call.getState();
        mCallsManager.notifyCallStateChangeForDisconnect(call, previousState);
        disconnectFuture.thenComposeAsync((result) -> {
            if (result) {
                Log.i(this, "disconnectCall: Disconnect call transaction succeeded. "
                        + "Processing associated cleanup.");
                mCallsManager.processDisconnectCallAndCleanup(call, previousState);
            } else {
                // Revert the disconnecting state that was set as a result of invoking
                // Call#disconnect and make sure the reverted state is notified to the registered
                // listeners.
                call.setLocallyDisconnecting(false);
                mCallsManager.notifyCallStateChangeForDisconnect(call, newState);
                Log.i(this, "disconnectCall: Disconnect call transaction failed. "
                        + "Aborting associated cleanup.");
            }
+5 −0
Original line number Diff line number Diff line
@@ -620,6 +620,7 @@ public class CallSequencingTests extends TelecomTestCase {
        when(mActiveCall.disconnect()).thenReturn(CompletableFuture.completedFuture(true));
        int previousState = CallState.ACTIVE;
        mController.disconnectCall(mActiveCall, previousState);
        verify(mCallsManager).notifyCallStateChangeForDisconnect(any(Call.class), anyInt());
        verify(mCallsManager, timeout(SEQUENCING_TIMEOUT_MS))
                .processDisconnectCallAndCleanup(eq(mActiveCall), eq(previousState));
    }
@@ -630,8 +631,12 @@ public class CallSequencingTests extends TelecomTestCase {
        when(mActiveCall.disconnect()).thenReturn(CompletableFuture.completedFuture(false));
        int previousState = CallState.ACTIVE;
        mController.disconnectCall(mActiveCall, previousState);
        verify(mCallsManager).notifyCallStateChangeForDisconnect(any(Call.class), anyInt());
        verify(mCallsManager, timeout(SEQUENCING_TIMEOUT_MS).times(0))
                .processDisconnectCallAndCleanup(eq(mActiveCall), eq(previousState));
        verify(mCallsManager, timeout(SEQUENCING_TIMEOUT_MS).times(2))
                .notifyCallStateChangeForDisconnect(any(Call.class), anyInt());
        verify(mActiveCall, timeout(SEQUENCING_TIMEOUT_MS)).setLocallyDisconnecting(eq(false));
    }

    @Test