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

Commit ee99e09f authored by Hall Liu's avatar Hall Liu
Browse files

Fix BT call state issue

CallAudioManager sets the BT end-of-call tone flag to true after it
calls startTone at the end of a call, no matter whether the call
actually started or not. This causes our call reports to the BT stack to
perpetually be in the disconnecting stack, which apparently is bad.

Fix this so that we only set the flag if the tone actually plays.

Test: unit, manual
Change-Id: I72058667ee6d722fbe5bf87f036a95220cf0a34f
Fixes: 120477414
parent a2e4a7f1
Loading
Loading
Loading
Loading
+5 −3
Original line number Diff line number Diff line
@@ -727,12 +727,14 @@ public class CallAudioManager extends CallsManagerListenerBase {
            Log.d(this, "Found a disconnected call with tone to play %d.", toneToPlay);

            if (toneToPlay != InCallTonePlayer.TONE_INVALID) {
                mPlayerFactory.createPlayer(toneToPlay).startTone();
                boolean didToneStart = mPlayerFactory.createPlayer(toneToPlay).startTone();
                if (didToneStart) {
                    mCallsManager.onDisconnectedTonePlaying(true);
                    mIsDisconnectedTonePlaying = true;
                }
            }
        }
    }

    private void playRingbackForCall(Call call) {
        if (call == mForegroundCall && call.isRingbackRequested()) {
+3 −2
Original line number Diff line number Diff line
@@ -427,11 +427,11 @@ public class InCallTonePlayer extends Thread {
    }

    @VisibleForTesting
    public void startTone() {
    public boolean startTone() {
        // Skip playing the end call tone if the volume is silenced.
        if (mToneId == TONE_CALL_ENDED && !mAudioManagerAdapter.isVolumeOverZero()) {
            Log.i(this, "startTone: skip end-call tone as device is silenced.");
            return;
            return false;
        }

        sTonesPlaying++;
@@ -447,6 +447,7 @@ public class InCallTonePlayer extends Thread {
        }

        super.start();
        return true;
    }

    @Override
+1 −1
Original line number Diff line number Diff line
@@ -77,7 +77,7 @@ public class CallAudioManagerTest extends TelecomTestCase {
            InCallTonePlayer mockInCallTonePlayer = mock(InCallTonePlayer.class);
            doAnswer((invocation2) -> {
                mCallAudioManager.setIsTonePlaying(true);
                return null;
                return true;
            }).when(mockInCallTonePlayer).startTone();
            return mockInCallTonePlayer;
        }).when(mPlayerFactory).createPlayer(anyInt());
+4 −2
Original line number Diff line number Diff line
@@ -16,6 +16,8 @@

package com.android.server.telecom.tests;

import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyInt;
import static org.mockito.ArgumentMatchers.eq;
@@ -114,7 +116,7 @@ public class InCallTonePlayerTest extends TelecomTestCase {
    public void testNoEndCallToneInSilence() {
        when(mAudioManagerAdapter.isVolumeOverZero()).thenReturn(false);
        InCallTonePlayer player = mFactory.createPlayer(InCallTonePlayer.TONE_CALL_ENDED);
        player.startTone();
        assertFalse(player.startTone());

        // Verify we didn't play a tone.
        verify(mCallAudioManager, never()).setIsTonePlaying(eq(true));
@@ -126,7 +128,7 @@ public class InCallTonePlayerTest extends TelecomTestCase {
    public void testEndCallToneWhenNotSilenced() {
        when(mAudioManagerAdapter.isVolumeOverZero()).thenReturn(true);
        InCallTonePlayer player = mFactory.createPlayer(InCallTonePlayer.TONE_CALL_ENDED);
        player.startTone();
        assertTrue(player.startTone());

        // Verify we did play a tone.
        verify(mCallAudioManager).setIsTonePlaying(eq(true));
+1 −0
Original line number Diff line number Diff line
@@ -123,6 +123,7 @@ public class RingerTest extends TelecomTestCase {
        when(mockAudioManager.getRingerModeInternal()).thenReturn(AudioManager.RINGER_MODE_NORMAL);
        NotificationManager notificationManager =
                (NotificationManager) mContext.getSystemService(Context.NOTIFICATION_SERVICE);
        when(mockTonePlayer.startTone()).thenReturn(true);
        when(notificationManager.matchesCallFilter(any(Bundle.class))).thenReturn(true);
        mRingerUnderTest = new Ringer(mockPlayerFactory, mContext, mockSystemSettingsUtil,
                mockRingtonePlayer, mockRingtoneFactory, mockVibrator, spyVibrationEffectProxy,