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

Commit 18c46b12 authored by Grant Menke's avatar Grant Menke
Browse files

Update ring stream unmute logic to stop ringtone playback before starting again.

This CL updates ring stream unmute logic to stop ringtone playback before starting again by invoking CallAudioManager#stopRinging before calling tryStartRinging.

Test: atest CallAudioRouteControllerTest
Flag: com.android.server.telecom.flags.ensure_in_car_ringing
Bug: 348708302
Change-Id: If7a177c5690800b1bceae491a17945f1438774e3
parent f5cf4108
Loading
Loading
Loading
Loading
+4 −0
Original line number Diff line number Diff line
@@ -438,6 +438,10 @@ public class CallAudioManager extends CallsManagerListenerBase {

    @VisibleForTesting(visibility = VisibleForTesting.Visibility.PACKAGE)
    public void onRingerModeChange() {
        if (mFeatureFlags.ensureInCarRinging()) {
            // Stop the current ringtone before attempting to start the new ringtone:
            stopRinging();
        }
        mCallAudioModeStateMachine.sendMessageWithArgs(
                CallAudioModeStateMachine.RINGER_MODE_CHANGE, makeArgsForModeStateMachine());
    }
+37 −0
Original line number Diff line number Diff line
@@ -52,12 +52,16 @@ import static org.mockito.Mockito.doNothing;
import static org.mockito.Mockito.eq;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.timeout;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;

import android.bluetooth.BluetoothAdapter;
import android.bluetooth.BluetoothDevice;
import android.bluetooth.BluetoothLeAudio;
import android.content.BroadcastReceiver;
import android.content.Intent;
import android.content.IntentFilter;
import android.media.AudioDeviceInfo;
import android.media.AudioManager;
import android.media.IAudioService;
@@ -86,6 +90,7 @@ import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;
import org.mockito.ArgumentCaptor;
import org.mockito.Mock;

import java.util.HashSet;
@@ -560,6 +565,38 @@ public class CallAudioRouteControllerTest extends TelecomTestCase {
                any(CallAudioState.class), eq(expectedState));
    }

    @SmallTest
    @Test
    public void testStreamRingMuteChange() {
        mController.initialize();

        // Make sure we register a receiver for the STREAM_MUTE_CHANGED_ACTION so we can see if the
        // ring stream unmutes.
        ArgumentCaptor<BroadcastReceiver> brCaptor = ArgumentCaptor.forClass(
                BroadcastReceiver.class);
        ArgumentCaptor<IntentFilter> filterCaptor = ArgumentCaptor.forClass(IntentFilter.class);
        verify(mContext, times(3)).registerReceiver(brCaptor.capture(), filterCaptor.capture());
        boolean foundValid = false;
        for (int ix = 0; ix < brCaptor.getAllValues().size(); ix++) {
            BroadcastReceiver receiver = brCaptor.getAllValues().get(ix);
            IntentFilter filter = filterCaptor.getAllValues().get(ix);
            if (!filter.hasAction(AudioManager.STREAM_MUTE_CHANGED_ACTION)) {
                continue;
            }

            // Fake out a call to the broadcast receiver and make sure we call into audio manager
            // to trigger re-evaluation of ringing.
            Intent intent = new Intent(AudioManager.STREAM_MUTE_CHANGED_ACTION);
            intent.putExtra(AudioManager.EXTRA_STREAM_VOLUME_MUTED, false);
            intent.putExtra(AudioManager.EXTRA_VOLUME_STREAM_TYPE, AudioManager.STREAM_RING);
            receiver.onReceive(mContext, intent);
            verify(mCallAudioManager).onRingerModeChange();
            foundValid = true;
        }
        assertTrue(foundValid);
    }


    @SmallTest
    @Test
    public void testToggleMute() throws Exception {