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

Commit 6bc865cc authored by Omata Shou's avatar Omata Shou Committed by Hall Liu
Browse files

To suppress the mute function during an emergency call

During an emergency call, the mute function is suppressed on the call
screen UI, however the user can use mute function below.
- Add an emergency call after the user turns ON mute during
  a normal call
- Doing a long press the function button on the wired headset during
  an emergency call

With this fix, these use cases are suppressed.

Test: manual - Checked that the mute function is suppressed in each
use case
Test: auto - Passed BasicCallTests
Bug: 64102005

Change-Id: I271ef82ce8e96cf45954436f00b844926902d521
parent 996ecdb9
Loading
Loading
Loading
Loading
+7 −1
Original line number Diff line number Diff line
@@ -364,7 +364,13 @@ public class CallAudioManager extends CallsManagerListenerBase {
        return null;
    }

    void toggleMute() {
    @VisibleForTesting
    public void toggleMute() {
        // Don't mute if there are any emergency calls.
        if (mCallsManager.hasEmergencyCall()) {
            Log.v(this, "ignoring toggleMute for emergency call");
            return;
        }
        mCallAudioRouteStateMachine.sendMessageWithSessionInfo(
                CallAudioRouteStateMachine.TOGGLE_MUTE);
    }
+10 −0
Original line number Diff line number Diff line
@@ -1858,6 +1858,7 @@ public class CallsManager extends Call.ListenerBase
    void markCallAsDialing(Call call) {
        setCallState(call, CallState.DIALING, "dialing set explicitly");
        maybeMoveToSpeakerPhone(call);
        maybeTurnOffMute(call);
    }

    void markCallAsPulling(Call call) {
@@ -2852,6 +2853,15 @@ public class CallsManager extends Call.ListenerBase
        }
    }

    /**
     * Checks to see if the call is an emergency call and if so, turn off mute.
     */
    private void maybeTurnOffMute(Call call) {
        if (call.isEmergencyCall()) {
            mute(false);
        }
    }

    /**
     * Creates a new call for an existing connection.
     *
+46 −0
Original line number Diff line number Diff line
@@ -27,6 +27,7 @@ import static org.mockito.Matchers.eq;
import static org.mockito.Matchers.isNull;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.timeout;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.verifyZeroInteractions;
import static org.mockito.Mockito.when;
@@ -68,6 +69,7 @@ import org.junit.runners.JUnit4;
import org.mockito.invocation.InvocationOnMock;
import org.mockito.stubbing.Answer;

import java.util.List;
import java.util.concurrent.BrokenBarrierException;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.CyclicBarrier;
@@ -1068,4 +1070,48 @@ public class BasicCallTests extends TelecomSystemTest {
                .deflect(eq(ids.mConnectionId), eq(deflectAddress), any());
        mInCallServiceFixtureX.mInCallAdapter.disconnectCall(ids.mCallId);
    }

    /**
     * Test to make sure to unmute automatically when making an emergency call and keep unmute
     * during the emergency call.
     * @throws Exception
     */
    @LargeTest
    @Test
    public void testUnmuteDuringEmergencyCall() throws Exception {
        // Make an outgoing call and turn ON mute.
        IdPair outgoingCall = startAndMakeActiveOutgoingCall("650-555-1212",
                mPhoneAccountA0.getAccountHandle(), mConnectionServiceFixtureA);
        assertEquals(Call.STATE_ACTIVE, mInCallServiceFixtureX.getCall(outgoingCall.mCallId)
                .getState());
        mInCallServiceFixtureX.mInCallAdapter.mute(true);
        waitForHandlerAction(mTelecomSystem.getCallsManager().getCallAudioManager()
                .getCallAudioRouteStateMachine().getHandler(), TEST_TIMEOUT);
        assertTrue(mTelecomSystem.getCallsManager().getAudioState().isMuted());

        // Make an emergency call.
        IdPair emergencyCall = startAndMakeDialingEmergencyCall("650-555-1213",
                mPhoneAccountE0.getAccountHandle(), mConnectionServiceFixtureA);
        assertEquals(Call.STATE_DIALING, mInCallServiceFixtureX.getCall(emergencyCall.mCallId)
                .getState());
        waitForHandlerAction(mTelecomSystem.getCallsManager().getCallAudioManager()
                .getCallAudioRouteStateMachine().getHandler(), TEST_TIMEOUT);
        // Should be unmute automatically.
        assertFalse(mTelecomSystem.getCallsManager().getAudioState().isMuted());

        // Toggle mute during an emergency call.
        mTelecomSystem.getCallsManager().getCallAudioManager().toggleMute();
        waitForHandlerAction(mTelecomSystem.getCallsManager().getCallAudioManager()
                .getCallAudioRouteStateMachine().getHandler(), TEST_TIMEOUT);
        // Should keep unmute.
        assertFalse(mTelecomSystem.getCallsManager().getAudioState().isMuted());

        ArgumentCaptor<Boolean> muteValueCaptor = ArgumentCaptor.forClass(Boolean.class);
        verify(mAudioService, times(2)).setMicrophoneMute(muteValueCaptor.capture(),
                any(String.class), any(Integer.class));
        List<Boolean> muteValues = muteValueCaptor.getAllValues();
        // Check mute status was changed twice with true and false.
        assertTrue(muteValues.get(0));
        assertFalse(muteValues.get(1));
    }
}