summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Yan Han <yanha@google.com> 2023-10-25 16:47:16 +0200
committer Yan Han <yanha@google.com> 2023-11-01 10:32:04 +0000
commit7de0e5ade7d63f2e50523b95193034c19e7e6051 (patch)
tree9820d314576b35e8efccb32a7bca5df37e33fc2b
parent7631cf0c9ad60a77b89c25f0b6d70e6f68bc0888 (diff)
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
-rw-r--r--services/core/java/com/android/server/hdmi/AbsoluteVolumeAudioStatusAction.java21
-rw-r--r--services/tests/servicestests/src/com/android/server/hdmi/BaseAbsoluteVolumeBehaviorTest.java10
-rw-r--r--services/tests/servicestests/src/com/android/server/hdmi/BaseTvToAudioSystemAvbTest.java11
3 files changed, 25 insertions, 17 deletions
diff --git a/services/core/java/com/android/server/hdmi/AbsoluteVolumeAudioStatusAction.java b/services/core/java/com/android/server/hdmi/AbsoluteVolumeAudioStatusAction.java
index 9172dc02a4ac..82786001ab68 100644
--- a/services/core/java/com/android/server/hdmi/AbsoluteVolumeAudioStatusAction.java
+++ b/services/core/java/com/android/server/hdmi/AbsoluteVolumeAudioStatusAction.java
@@ -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;
diff --git a/services/tests/servicestests/src/com/android/server/hdmi/BaseAbsoluteVolumeBehaviorTest.java b/services/tests/servicestests/src/com/android/server/hdmi/BaseAbsoluteVolumeBehaviorTest.java
index e7c3cab7f872..a63d01b6225a 100644
--- a/services/tests/servicestests/src/com/android/server/hdmi/BaseAbsoluteVolumeBehaviorTest.java
+++ b/services/tests/servicestests/src/com/android/server/hdmi/BaseAbsoluteVolumeBehaviorTest.java
@@ -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);
- verify(mAudioManager, never()).setStreamVolume(eq(AudioManager.STREAM_MUSIC), eq(8),
- anyInt());
+ 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);
diff --git a/services/tests/servicestests/src/com/android/server/hdmi/BaseTvToAudioSystemAvbTest.java b/services/tests/servicestests/src/com/android/server/hdmi/BaseTvToAudioSystemAvbTest.java
index cb530c0c711c..a410702e202d 100644
--- a/services/tests/servicestests/src/com/android/server/hdmi/BaseTvToAudioSystemAvbTest.java
+++ b/services/tests/servicestests/src/com/android/server/hdmi/BaseTvToAudioSystemAvbTest.java
@@ -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));