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

Commit 3de102c4 authored by Grant Menke's avatar Grant Menke
Browse files

Remove reference to getDefaultStreamVolume.

This Telecom mainline cleanup CL removes the reference to getDefaultStreamVolume and replaces it with the average of the min and max stream volumes per AudioManager.

Test: atest CallsManagerTest
Bug: 307792317
Flag: com.android.server.telecom.flags.resolve_hidden_dependencies_two
Change-Id: If3dd114890a35735e8a92c20e391cded99341af6
parent a7cb8fa7
Loading
Loading
Loading
Loading
+12 −4
Original line number Diff line number Diff line
@@ -5773,11 +5773,19 @@ public class CallsManager extends Call.ListenerBase
                return;
            }
            if (am.getStreamVolume(AudioManager.STREAM_VOICE_CALL) == 0) {
                Log.i(this,
                        "ensureCallAudible: voice call stream has volume 0. Adjusting to default.");
                if (mFeatureFlags.resolveHiddenDependenciesTwo()) {
                    Log.i(this, "ensureCallAudible: voice call stream has volume 0. "
                            + "Adjusting to average.");
                    int averageStreamVolume = (am.getStreamMaxVolume(AudioManager.STREAM_VOICE_CALL)
                            + am.getStreamMinVolume(AudioManager.STREAM_VOICE_CALL)) / 2;
                    am.setStreamVolume(AudioManager.STREAM_VOICE_CALL, averageStreamVolume, 0);
                } else {
                    Log.i(this, "ensureCallAudible: voice call stream has volume 0. "
                            + "Adjusting to default.");
                    am.setStreamVolume(AudioManager.STREAM_VOICE_CALL,
                            AudioSystem.getDefaultStreamVolume(AudioManager.STREAM_VOICE_CALL), 0);
                }
            }
        });
    }

+21 −0
Original line number Diff line number Diff line
@@ -3429,6 +3429,7 @@ public class CallsManagerTest extends TelecomTestCase {
        verify(mComponentContextFixture.getAudioManager(), times(1)).setStreamVolume(
                eq(AudioManager.STREAM_VOICE_CALL), anyInt(), anyInt());
    }

    @MediumTest
    @Test
    public void testSetCallDialingAndIncreaseVolume() {
@@ -3444,6 +3445,26 @@ public class CallsManagerTest extends TelecomTestCase {
                eq(AudioManager.STREAM_VOICE_CALL), anyInt(), anyInt());
    }

    @MediumTest
    @Test
    public void testSetCallDialingAndCalculateAverageVolume() {
        // This test specificaslly tests the new behavior guarded by this flag:
        when(mFeatureFlags.resolveHiddenDependenciesTwo()).thenReturn(true);

        // Start with a zero volume stream.
        mComponentContextFixture.getAudioManager().setStreamVolume(AudioManager.STREAM_VOICE_CALL,
                0, 0 /* flags */);

        Call call = mock(Call.class);
        mCallsManager.markCallAsDialing(call);

        // Ensure we calculate the new volume using the average of AudioManager min and max volume:
        verify(mComponentContextFixture.getAudioManager(), times(1))
                .getStreamMaxVolume(eq(AudioManager.STREAM_VOICE_CALL));
        verify(mComponentContextFixture.getAudioManager(), times(1))
                .getStreamMinVolume(eq(AudioManager.STREAM_VOICE_CALL));
    }

    @MediumTest
    @Test
    public void testSetCallActiveAndDontIncreaseVolume() {