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

Commit f7fb1da2 authored by Treehugger Robot's avatar Treehugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Ensure disconnecting state is notified to listeners" into main

parents 59d501b9 7868ff22
Loading
Loading
Loading
Loading
+13 −0
Original line number Diff line number Diff line
@@ -3655,6 +3655,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