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

Commit 7de0e5ad authored by Yan Han's avatar Yan Han
Browse files

Always show volume UI on TV after receiving <Report Audio Status>.

Previously, when the AVR reported its audio status, HdmiControlService
would only notify AudioService (and trigger volume UI) if the volume
level or mute state changed from the last time it was reported.

However, this means that the user gets no visual feedback when they
adjust the volume if the change in the AVR is too small for it to
reach a new percentage point (e.g. AVR volume goes from 10.0% to 10.4%). This is because <Report Audio Status> represents volume levels in increments of 1%; 10% and 10.4% would both round to 10%.

With this CL, when a TV panel receives <Report Audio Status> from the
AVR, HdmiControlService will trigger volume UI even if the audio status
didn't change from the previous one.

Bug: 304279125
Test: manual
Test: atest PlaybackDeviceToTvAvbTest PlaybackDeviceToAudioSystemAvbTest
TvToAudioSystemArcAvbTest TvToAudioSystemEarcAvbTest

Change-Id: I1e933b71091e04187fcc8659d7b3a12ed32f166a
parent 7631cf0c
Loading
Loading
Loading
Loading
+10 −11
Original line number Diff line number Diff line
@@ -32,10 +32,6 @@ final class AbsoluteVolumeAudioStatusAction extends HdmiCecFeatureAction {

    private int mInitialAudioStatusRetriesLeft = 2;

    // Flag to notify AudioService of the next audio status reported,
    // regardless of whether the audio status changed.
    private boolean mForceNextAudioStatusUpdate = false;

    private static final int STATE_WAIT_FOR_INITIAL_AUDIO_STATUS = 1;
    private static final int STATE_MONITOR_AUDIO_STATUS = 2;

@@ -74,13 +70,11 @@ final class AbsoluteVolumeAudioStatusAction extends HdmiCecFeatureAction {
        return false;
    }


    /**
     * If AVB has been enabled, send <Give Audio Status> and notify AudioService of the response.
     */
    void requestAndUpdateAudioStatus() {
        if (mState == STATE_MONITOR_AUDIO_STATUS) {
            mForceNextAudioStatusUpdate = true;
            sendGiveAudioStatus();
        }
    }
@@ -104,15 +98,20 @@ final class AbsoluteVolumeAudioStatusAction extends HdmiCecFeatureAction {
            localDevice().getService().enableAbsoluteVolumeBehavior(audioStatus);
            mState = STATE_MONITOR_AUDIO_STATUS;
        } else if (mState == STATE_MONITOR_AUDIO_STATUS) {
            if (mForceNextAudioStatusUpdate
                    || audioStatus.getVolume() != mLastAudioStatus.getVolume()) {
            // On TV panels, we notify AudioService even if neither volume nor mute state changed.
            // This ensures that the user sees volume UI if they tried to adjust the AVR's volume,
            // even if the new volume level is the same as the previous one.
            boolean notifyAvbVolumeToShowUi = localDevice().getService().isTvDevice()
                    && audioStatus.equals(mLastAudioStatus);

            if (audioStatus.getVolume() != mLastAudioStatus.getVolume()
                    || notifyAvbVolumeToShowUi) {
                localDevice().getService().notifyAvbVolumeChange(audioStatus.getVolume());
            }
            if (mForceNextAudioStatusUpdate
                    || audioStatus.getMute() != mLastAudioStatus.getMute()) {

            if (audioStatus.getMute() != mLastAudioStatus.getMute()) {
                localDevice().getService().notifyAvbMuteChange(audioStatus.getMute());
            }
            mForceNextAudioStatusUpdate = false;
        }
        mLastAudioStatus = audioStatus;

+8 −2
Original line number Diff line number Diff line
@@ -528,9 +528,15 @@ public abstract class BaseAbsoluteVolumeBehaviorTest {
        clearInvocations(mAudioManager);

        // Repeat of earlier message: sets neither volume nor mute
        // Exception: On TV, volume is set to ensure that UI is shown
        receiveReportAudioStatus(32, false);
        if (getDeviceType() == HdmiDeviceInfo.DEVICE_TV) {
            verify(mAudioManager).setStreamVolume(eq(AudioManager.STREAM_MUSIC), eq(8),
                    anyInt());
        } else {
            verify(mAudioManager, never()).setStreamVolume(eq(AudioManager.STREAM_MUSIC), eq(8),
                    anyInt());
        }
        verify(mAudioManager, never()).adjustStreamVolume(eq(AudioManager.STREAM_MUSIC),
                eq(AudioManager.ADJUST_UNMUTE), anyInt());
        clearInvocations(mAudioManager);
+7 −4
Original line number Diff line number Diff line
@@ -190,12 +190,13 @@ public abstract class BaseTvToAudioSystemAvbTest extends BaseAbsoluteVolumeBehav
                eq(AudioManager.ADJUST_UNMUTE), anyInt());
        clearInvocations(mAudioManager);

        // Repeat of earlier message: sets neither volume nor mute
        // Repeat of earlier message: sets volume only (to ensure volume UI is shown)
        receiveReportAudioStatus(32, false);
        verify(mAudioManager, never()).setStreamVolume(eq(AudioManager.STREAM_MUSIC), eq(8),
        verify(mAudioManager).setStreamVolume(eq(AudioManager.STREAM_MUSIC), eq(8),
                anyInt());
        verify(mAudioManager, never()).adjustStreamVolume(eq(AudioManager.STREAM_MUSIC),
                eq(AudioManager.ADJUST_UNMUTE), anyInt());
        clearInvocations(mAudioManager);

        // Volume not within range [0, 100]: sets neither volume nor mute
        receiveReportAudioStatus(127, true);
@@ -391,14 +392,16 @@ public abstract class BaseTvToAudioSystemAvbTest extends BaseAbsoluteVolumeBehav
                INITIAL_SYSTEM_AUDIO_DEVICE_STATUS.getMute()));
        mTestLooper.dispatchAll();

        // HdmiControlService calls setStreamVolume and adjustStreamVolume to trigger volume UI
        // HdmiControlService calls setStreamVolume to trigger volume UI
        verify(mAudioManager).setStreamVolume(
                eq(AudioManager.STREAM_MUSIC),
                // Volume level is rescaled to the max volume of STREAM_MUSIC
                eq(INITIAL_SYSTEM_AUDIO_DEVICE_STATUS.getVolume()
                        * STREAM_MUSIC_MAX_VOLUME / AudioStatus.MAX_VOLUME),
                eq(AudioManager.FLAG_ABSOLUTE_VOLUME | AudioManager.FLAG_SHOW_UI));
        verify(mAudioManager).adjustStreamVolume(
        // adjustStreamVolume is not called because mute status didn't change,
        // and setStreamVolume is sufficient to show volume UI
        verify(mAudioManager, never()).adjustStreamVolume(
                eq(AudioManager.STREAM_MUSIC),
                eq(AudioManager.ADJUST_UNMUTE),
                eq(AudioManager.FLAG_ABSOLUTE_VOLUME | AudioManager.FLAG_SHOW_UI));