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

Commit 44bb1fda authored by Yan Han's avatar Yan Han Committed by Android (Google) Code Review
Browse files

Merge "Make volume UI work when using eARC." into main

parents 4933f3e0 8ba6f5bf
Loading
Loading
Loading
Loading
+0 −8
Original line number Diff line number Diff line
@@ -1230,14 +1230,6 @@ public final class HdmiCecLocalDeviceTv extends HdmiCecLocalDevice {
        return mService.getHdmiCecNetwork().getSafeCecDeviceInfo(Constants.ADDR_AUDIO_SYSTEM);
    }

    /**
     * Returns the audio output device used for System Audio Mode.
     */
    AudioDeviceAttributes getSystemAudioOutputDevice() {
        return HdmiControlService.AUDIO_OUTPUT_DEVICE_HDMI_ARC;
    }


    @ServiceThreadOnly
    void handleRemoveActiveRoutingPath(int path) {
        assertRunOnServiceThread();
+81 −52
Original line number Diff line number Diff line
@@ -121,7 +121,6 @@ import java.io.PrintWriter;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
@@ -244,8 +243,27 @@ public class HdmiControlService extends SystemService {

    // Audio output devices used for absolute volume behavior
    private static final List<AudioDeviceAttributes> AVB_AUDIO_OUTPUT_DEVICES =
            Collections.unmodifiableList(Arrays.asList(AUDIO_OUTPUT_DEVICE_HDMI,
                    AUDIO_OUTPUT_DEVICE_HDMI_ARC, AUDIO_OUTPUT_DEVICE_HDMI_EARC));
            List.of(AUDIO_OUTPUT_DEVICE_HDMI,
                    AUDIO_OUTPUT_DEVICE_HDMI_ARC,
                    AUDIO_OUTPUT_DEVICE_HDMI_EARC);

    // Audio output devices used for absolute volume behavior on TV panels
    private static final List<AudioDeviceAttributes> TV_AVB_AUDIO_OUTPUT_DEVICES =
            List.of(AUDIO_OUTPUT_DEVICE_HDMI_ARC,
                    AUDIO_OUTPUT_DEVICE_HDMI_EARC);

    // Audio output devices used for absolute volume behavior on Playback devices
    private static final List<AudioDeviceAttributes> PLAYBACK_AVB_AUDIO_OUTPUT_DEVICES =
            List.of(AUDIO_OUTPUT_DEVICE_HDMI);

    private static final List<Integer> ABSOLUTE_VOLUME_BEHAVIORS =
            List.of(AudioManager.DEVICE_VOLUME_BEHAVIOR_ABSOLUTE,
                    AudioManager.DEVICE_VOLUME_BEHAVIOR_ABSOLUTE_ADJUST_ONLY);

    private static final List<Integer> FULL_AND_ABSOLUTE_VOLUME_BEHAVIORS =
            List.of(AudioManager.DEVICE_VOLUME_BEHAVIOR_FULL,
                    AudioManager.DEVICE_VOLUME_BEHAVIOR_ABSOLUTE,
                    AudioManager.DEVICE_VOLUME_BEHAVIOR_ABSOLUTE_ADJUST_ONLY);

    // AudioAttributes for STREAM_MUSIC
    @VisibleForTesting
@@ -4375,32 +4393,31 @@ public class HdmiControlService extends SystemService {
    }

    /**
     * Returns whether absolute volume behavior is enabled or not. This is determined by the
     * volume behavior of the relevant HDMI audio output device(s) for this device's type.
     * Returns whether absolute volume behavior is enabled or not. This is true if any AVB-capable
     * audio output device is using absolute volume behavior.
     */
    public boolean isAbsoluteVolumeBehaviorEnabled() {
        if (!isTvDevice() && !isPlaybackDevice()) {
            return false;
        }
        AudioDeviceAttributes avbAudioOutputDevice = getAvbAudioOutputDevice();
        if (avbAudioOutputDevice == null) {
            return false;
        for (AudioDeviceAttributes device : getAvbCapableAudioOutputDevices()) {
            if (ABSOLUTE_VOLUME_BEHAVIORS.contains(getDeviceVolumeBehavior(device))) {
                return true;
            }

        @AudioManager.DeviceVolumeBehavior int deviceVolumeBehavior =
                getDeviceVolumeBehavior(avbAudioOutputDevice);

        return deviceVolumeBehavior == AudioManager.DEVICE_VOLUME_BEHAVIOR_ABSOLUTE
                || deviceVolumeBehavior == AudioManager.DEVICE_VOLUME_BEHAVIOR_ABSOLUTE_ADJUST_ONLY;
        }
        return false;
    }

    private AudioDeviceAttributes getAvbAudioOutputDevice() {
    /**
     * Returns a list of audio output devices that may adopt absolute volume behavior.
     */
    private List<AudioDeviceAttributes> getAvbCapableAudioOutputDevices() {
        if (tv() != null) {
            return tv().getSystemAudioOutputDevice();
            return TV_AVB_AUDIO_OUTPUT_DEVICES;
        } else if (playback() != null) {
            return AUDIO_OUTPUT_DEVICE_HDMI;
            return PLAYBACK_AVB_AUDIO_OUTPUT_DEVICES;
        } else {
            return null;
            return Collections.emptyList();
        }
    }

@@ -4415,7 +4432,7 @@ public class HdmiControlService extends SystemService {
     *
     * Absolute volume behavior requires the following conditions:
     * 1. If the System Audio Device is an Audio System: System Audio Mode is active
     * 2. Our HDMI audio output device is using full volume behavior
     * 2. All AVB-capable audio output devices are already using full/absolute volume behavior
     * 3. CEC volume is enabled
     * 4. The System Audio device supports the <Set Audio Volume Level> message
     *
@@ -4452,15 +4469,15 @@ public class HdmiControlService extends SystemService {

        HdmiDeviceInfo systemAudioDeviceInfo = getDeviceInfo(
                localCecDevice.findAudioReceiverAddress());
        @AudioManager.DeviceVolumeBehavior int currentVolumeBehavior =
                        getDeviceVolumeBehavior(getAvbAudioOutputDevice());

        // Condition 2: Already using full or absolute volume behavior
        // Condition 2: All AVB-capable audio outputs already use full/absolute volume behavior
        // We only need to check the first AVB-capable audio output because only TV panels
        // have more than one of them, and they always have the same volume behavior.
        @AudioManager.DeviceVolumeBehavior int currentVolumeBehavior =
                getDeviceVolumeBehavior(getAvbCapableAudioOutputDevices().get(0));
        boolean alreadyUsingFullOrAbsoluteVolume =
                (currentVolumeBehavior == AudioManager.DEVICE_VOLUME_BEHAVIOR_FULL)
                        || (currentVolumeBehavior == AudioManager.DEVICE_VOLUME_BEHAVIOR_ABSOLUTE)
                        || (currentVolumeBehavior
                        == AudioManager.DEVICE_VOLUME_BEHAVIOR_ABSOLUTE_ADJUST_ONLY);
                FULL_AND_ABSOLUTE_VOLUME_BEHAVIORS.contains(currentVolumeBehavior);

        // Condition 3: CEC volume is enabled
        boolean cecVolumeEnabled =
                getHdmiCecVolumeControl() == HdmiControlManager.VOLUME_CONTROL_ENABLED;
@@ -4496,9 +4513,11 @@ public class HdmiControlService extends SystemService {
                        // If we're currently using absolute volume behavior, switch to full volume
                        // behavior until we successfully adopt adjust-only absolute volume behavior
                        if (currentVolumeBehavior == AudioManager.DEVICE_VOLUME_BEHAVIOR_ABSOLUTE) {
                            getAudioManager().setDeviceVolumeBehavior(getAvbAudioOutputDevice(),
                            for (AudioDeviceAttributes device : getAvbCapableAudioOutputDevices()) {
                                getAudioManager().setDeviceVolumeBehavior(device,
                                        AudioManager.DEVICE_VOLUME_BEHAVIOR_FULL);
                            }
                        }
                        // Start an action that will call enableAbsoluteVolumeBehavior
                        // once the System Audio device sends <Report Audio Status>
                        localCecDevice.startNewAvbAudioStatusAction(
@@ -4527,14 +4546,14 @@ public class HdmiControlService extends SystemService {
        } else if (tv() != null) {
            tv().removeAvbAudioStatusAction();
        }
        AudioDeviceAttributes device = getAvbAudioOutputDevice();
        int volumeBehavior = getDeviceVolumeBehavior(device);
        if (volumeBehavior == AudioManager.DEVICE_VOLUME_BEHAVIOR_ABSOLUTE
                || volumeBehavior == AudioManager.DEVICE_VOLUME_BEHAVIOR_ABSOLUTE_ADJUST_ONLY) {

        for (AudioDeviceAttributes device : getAvbCapableAudioOutputDevices()) {
            if (ABSOLUTE_VOLUME_BEHAVIORS.contains(getDeviceVolumeBehavior(device))) {
                getAudioManager().setDeviceVolumeBehavior(device,
                        AudioManager.DEVICE_VOLUME_BEHAVIOR_FULL);
            }
        }
    }

    /**
     * Enables absolute volume behavior or adjust-only absolute volume behavior. Should only be
@@ -4563,14 +4582,18 @@ public class HdmiControlService extends SystemService {
        // Otherwise, enable adjust-only AVB on TVs only.
        if (systemAudioDevice.getDeviceFeatures().getSetAudioVolumeLevelSupport()
                == DeviceFeatures.FEATURE_SUPPORTED) {
            for (AudioDeviceAttributes device : getAvbCapableAudioOutputDevices()) {
                getAudioDeviceVolumeManager().setDeviceAbsoluteVolumeBehavior(
                    getAvbAudioOutputDevice(), volumeInfo, mServiceThreadExecutor,
                        device, volumeInfo, mServiceThreadExecutor,
                        mAbsoluteVolumeChangedListener, true);
            }
        } else if (tv() != null) {
            for (AudioDeviceAttributes device : getAvbCapableAudioOutputDevices()) {
                getAudioDeviceVolumeManager().setDeviceAbsoluteVolumeAdjustOnlyBehavior(
                    getAvbAudioOutputDevice(), volumeInfo, mServiceThreadExecutor,
                        device, volumeInfo, mServiceThreadExecutor,
                        mAbsoluteVolumeChangedListener, true);
            }
        }

    }

@@ -4690,18 +4713,21 @@ public class HdmiControlService extends SystemService {

    /**
     * Notifies AudioService of a change in the volume of the System Audio device. Has no effect if
     * AVB is disabled, or the audio output device for AVB is not playing for STREAM_MUSIC
     * AVB is disabled, or STREAM_MUSIC is not playing on any AVB device.
     */
    void notifyAvbVolumeChange(int volume) {
        if (!isAbsoluteVolumeBehaviorEnabled()) return;
        List<AudioDeviceAttributes> streamMusicDevices =
                getAudioManager().getDevicesForAttributes(STREAM_MUSIC_ATTRIBUTES);
        if (streamMusicDevices.contains(getAvbAudioOutputDevice())) {
        for (AudioDeviceAttributes streamMusicDevice : streamMusicDevices) {
            if (getAvbCapableAudioOutputDevices().contains(streamMusicDevice)) {
                int flags = AudioManager.FLAG_ABSOLUTE_VOLUME;
                if (isTvDevice()) {
                    flags |= AudioManager.FLAG_SHOW_UI;
                }
                setStreamMusicVolume(volume, flags);
                return;
            }
        }
    }

@@ -4713,13 +4739,16 @@ public class HdmiControlService extends SystemService {
        if (!isAbsoluteVolumeBehaviorEnabled()) return;
        List<AudioDeviceAttributes> streamMusicDevices =
                getAudioManager().getDevicesForAttributes(STREAM_MUSIC_ATTRIBUTES);
        if (streamMusicDevices.contains(getAvbAudioOutputDevice())) {
        for (AudioDeviceAttributes streamMusicDevice : streamMusicDevices) {
            if (getAvbCapableAudioOutputDevices().contains(streamMusicDevice)) {
                int direction = mute ? AudioManager.ADJUST_MUTE : AudioManager.ADJUST_UNMUTE;
                int flags = AudioManager.FLAG_ABSOLUTE_VOLUME;
                if (isTvDevice()) {
                    flags |= AudioManager.FLAG_SHOW_UI;
                }
                getAudioManager().adjustStreamVolume(AudioManager.STREAM_MUSIC, direction, flags);
                return;
            }
        }
    }

+26 −21
Original line number Diff line number Diff line
@@ -71,7 +71,7 @@ import java.util.Collections;
 * We test the following pairs of (local device, System Audio device):
 * (Playback, TV): {@link PlaybackDeviceToTvAvbTest}
 * (Playback, Audio System): {@link PlaybackDeviceToAudioSystemAvbTest}
 * (TV, Audio System): {@link TvToAudioSystemAvbTest}
 * (TV, Audio System): {@link TvToAudioSystemArcAvbTest}, {@link TvToAudioSystemEarcAvbTest}
 */
public abstract class BaseAbsoluteVolumeBehaviorTest {
    protected HdmiControlService mHdmiControlService;
@@ -222,6 +222,21 @@ public abstract class BaseAbsoluteVolumeBehaviorTest {
        return mHdmiCecLocalDevice.getDeviceInfo().getLogicalAddress();
    }

    /**
     * Adopts full volume behavior on all of the HDMI audio output devices capable of adopting AVB.
     */
    protected void adoptFullVolumeBehaviorOnAvbCapableAudioOutputDevices() {
        if (getDeviceType() == HdmiDeviceInfo.DEVICE_PLAYBACK) {
            mAudioManager.setDeviceVolumeBehavior(HdmiControlService.AUDIO_OUTPUT_DEVICE_HDMI,
                    AudioManager.DEVICE_VOLUME_BEHAVIOR_FULL);
        } else if (getDeviceType() == HdmiDeviceInfo.DEVICE_TV) {
            mAudioManager.setDeviceVolumeBehavior(HdmiControlService.AUDIO_OUTPUT_DEVICE_HDMI_ARC,
                    AudioManager.DEVICE_VOLUME_BEHAVIOR_FULL);
            mAudioManager.setDeviceVolumeBehavior(HdmiControlService.AUDIO_OUTPUT_DEVICE_HDMI_EARC,
                    AudioManager.DEVICE_VOLUME_BEHAVIOR_FULL);
        }
    }

    /**
     * Changes the setting for CEC volume.
     */
@@ -285,8 +300,7 @@ public abstract class BaseAbsoluteVolumeBehaviorTest {
     * Triggers all the conditions required to enable absolute volume behavior.
     */
    protected void enableAbsoluteVolumeBehavior() {
        mAudioManager.setDeviceVolumeBehavior(getAudioOutputDevice(),
                AudioManager.DEVICE_VOLUME_BEHAVIOR_FULL);
        adoptFullVolumeBehaviorOnAvbCapableAudioOutputDevices();
        setCecVolumeControlSetting(HdmiControlManager.VOLUME_CONTROL_ENABLED);
        receiveSetAudioVolumeLevelSupport(DeviceFeatures.FEATURE_SUPPORTED);
        enableSystemAudioModeIfNeeded();
@@ -299,8 +313,7 @@ public abstract class BaseAbsoluteVolumeBehaviorTest {
    }

    protected void enableAdjustOnlyAbsoluteVolumeBehavior() {
        mAudioManager.setDeviceVolumeBehavior(getAudioOutputDevice(),
                AudioManager.DEVICE_VOLUME_BEHAVIOR_FULL);
        adoptFullVolumeBehaviorOnAvbCapableAudioOutputDevices();
        setCecVolumeControlSetting(HdmiControlManager.VOLUME_CONTROL_ENABLED);
        enableSystemAudioModeIfNeeded();
        receiveSetAudioVolumeLevelSupport(DeviceFeatures.FEATURE_NOT_SUPPORTED);
@@ -326,8 +339,7 @@ public abstract class BaseAbsoluteVolumeBehaviorTest {

    @Test
    public void allConditionsExceptSavlSupportMet_sendsSetAudioVolumeLevelAndGiveFeatures() {
        mAudioManager.setDeviceVolumeBehavior(getAudioOutputDevice(),
                AudioManager.DEVICE_VOLUME_BEHAVIOR_FULL);
        adoptFullVolumeBehaviorOnAvbCapableAudioOutputDevices();
        setCecVolumeControlSetting(HdmiControlManager.VOLUME_CONTROL_ENABLED);
        enableSystemAudioModeIfNeeded();

@@ -342,8 +354,7 @@ public abstract class BaseAbsoluteVolumeBehaviorTest {

    @Test
    public void allConditionsMet_savlSupportLast_reportFeatures_giveAudioStatusSent() {
        mAudioManager.setDeviceVolumeBehavior(getAudioOutputDevice(),
                AudioManager.DEVICE_VOLUME_BEHAVIOR_FULL);
        adoptFullVolumeBehaviorOnAvbCapableAudioOutputDevices();
        setCecVolumeControlSetting(HdmiControlManager.VOLUME_CONTROL_ENABLED);
        enableSystemAudioModeIfNeeded();
        verifyGiveAudioStatusNeverSent();
@@ -354,8 +365,7 @@ public abstract class BaseAbsoluteVolumeBehaviorTest {

    @Test
    public void allConditionsMet_savlSupportLast_noFeatureAbort_giveAudioStatusSent() {
        mAudioManager.setDeviceVolumeBehavior(getAudioOutputDevice(),
                AudioManager.DEVICE_VOLUME_BEHAVIOR_FULL);
        adoptFullVolumeBehaviorOnAvbCapableAudioOutputDevices();
        setCecVolumeControlSetting(HdmiControlManager.VOLUME_CONTROL_ENABLED);
        enableSystemAudioModeIfNeeded();
        verifyGiveAudioStatusNeverSent();
@@ -367,8 +377,7 @@ public abstract class BaseAbsoluteVolumeBehaviorTest {

    @Test
    public void allConditionsMet_cecVolumeEnabledLast_giveAudioStatusSent() {
        mAudioManager.setDeviceVolumeBehavior(getAudioOutputDevice(),
                AudioManager.DEVICE_VOLUME_BEHAVIOR_FULL);
        adoptFullVolumeBehaviorOnAvbCapableAudioOutputDevices();
        enableSystemAudioModeIfNeeded();
        receiveSetAudioVolumeLevelSupport(DeviceFeatures.FEATURE_SUPPORTED);
        verifyGiveAudioStatusNeverSent();
@@ -384,8 +393,7 @@ public abstract class BaseAbsoluteVolumeBehaviorTest {
        receiveSetAudioVolumeLevelSupport(DeviceFeatures.FEATURE_SUPPORTED);
        verifyGiveAudioStatusNeverSent();

        mAudioManager.setDeviceVolumeBehavior(getAudioOutputDevice(),
                AudioManager.DEVICE_VOLUME_BEHAVIOR_FULL);
        adoptFullVolumeBehaviorOnAvbCapableAudioOutputDevices();
        mTestLooper.dispatchAll();
        verifyGiveAudioStatusSent();
    }
@@ -395,8 +403,7 @@ public abstract class BaseAbsoluteVolumeBehaviorTest {
        // Only run when the System Audio device is an Audio System.
        assume().that(getSystemAudioDeviceType()).isEqualTo(HdmiDeviceInfo.DEVICE_AUDIO_SYSTEM);

        mAudioManager.setDeviceVolumeBehavior(getAudioOutputDevice(),
                AudioManager.DEVICE_VOLUME_BEHAVIOR_FULL);
        adoptFullVolumeBehaviorOnAvbCapableAudioOutputDevices();
        setCecVolumeControlSetting(HdmiControlManager.VOLUME_CONTROL_ENABLED);
        receiveSetAudioVolumeLevelSupport(DeviceFeatures.FEATURE_SUPPORTED);
        verifyGiveAudioStatusNeverSent();
@@ -407,8 +414,7 @@ public abstract class BaseAbsoluteVolumeBehaviorTest {

    @Test
    public void giveAudioStatusSent_systemAudioDeviceSendsReportAudioStatus_avbEnabled() {
        mAudioManager.setDeviceVolumeBehavior(getAudioOutputDevice(),
                AudioManager.DEVICE_VOLUME_BEHAVIOR_FULL);
        adoptFullVolumeBehaviorOnAvbCapableAudioOutputDevices();
        setCecVolumeControlSetting(HdmiControlManager.VOLUME_CONTROL_ENABLED);
        enableSystemAudioModeIfNeeded();
        receiveSetAudioVolumeLevelSupport(DeviceFeatures.FEATURE_SUPPORTED);
@@ -437,8 +443,7 @@ public abstract class BaseAbsoluteVolumeBehaviorTest {

    @Test
    public void giveAudioStatusSent_reportAudioStatusVolumeOutOfBounds_avbNotEnabled() {
        mAudioManager.setDeviceVolumeBehavior(getAudioOutputDevice(),
                AudioManager.DEVICE_VOLUME_BEHAVIOR_FULL);
        adoptFullVolumeBehaviorOnAvbCapableAudioOutputDevices();
        setCecVolumeControlSetting(HdmiControlManager.VOLUME_CONTROL_ENABLED);
        enableSystemAudioModeIfNeeded();
        receiveSetAudioVolumeLevelSupport(DeviceFeatures.FEATURE_SUPPORTED);
+9 −21
Original line number Diff line number Diff line
@@ -31,26 +31,21 @@ import static org.mockito.Mockito.verify;
import android.hardware.hdmi.DeviceFeatures;
import android.hardware.hdmi.HdmiControlManager;
import android.hardware.hdmi.HdmiDeviceInfo;
import android.media.AudioDeviceAttributes;
import android.media.AudioDeviceVolumeManager;
import android.media.AudioManager;
import android.media.VolumeInfo;
import android.platform.test.annotations.Presubmit;

import androidx.test.filters.SmallTest;

import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;

/**
 * Tests for absolute volume behavior where the local device is a TV and the System Audio device
 * is an Audio System. Assumes that the TV uses ARC (rather than eARC).
 * Base class for tests for absolute volume behavior on TV panels. Contains tests that are
 * relevant to TV panels but not to Playback devices.
 *
 * Subclasses test the scenarios where ARC and eARC are the audio output devices:
 * ARC: {@link TvToAudioSystemArcAvbTest}
 * eARC: {@link TvToAudioSystemEarcAvbTest}
 */
@SmallTest
@Presubmit
@RunWith(JUnit4.class)
public class TvToAudioSystemAvbTest extends BaseAbsoluteVolumeBehaviorTest {
public abstract class BaseTvToAudioSystemAvbTest extends BaseAbsoluteVolumeBehaviorTest {

    @Override
    protected HdmiCecLocalDevice createLocalDevice(HdmiControlService hdmiControlService) {
@@ -67,11 +62,6 @@ public class TvToAudioSystemAvbTest extends BaseAbsoluteVolumeBehaviorTest {
        return HdmiDeviceInfo.DEVICE_TV;
    }

    @Override
    protected AudioDeviceAttributes getAudioOutputDevice() {
        return HdmiControlService.AUDIO_OUTPUT_DEVICE_HDMI_ARC;
    }

    @Override
    protected int getSystemAudioDeviceLogicalAddress() {
        return Constants.ADDR_AUDIO_SYSTEM;
@@ -88,8 +78,7 @@ public class TvToAudioSystemAvbTest extends BaseAbsoluteVolumeBehaviorTest {
     */
    @Test
    public void savlNotSupported_allOtherConditionsMet_giveAudioStatusSent() {
        mAudioManager.setDeviceVolumeBehavior(getAudioOutputDevice(),
                AudioManager.DEVICE_VOLUME_BEHAVIOR_FULL);
        adoptFullVolumeBehaviorOnAvbCapableAudioOutputDevices();
        setCecVolumeControlSetting(HdmiControlManager.VOLUME_CONTROL_ENABLED);
        enableSystemAudioModeIfNeeded();
        verifyGiveAudioStatusNeverSent();
@@ -100,8 +89,7 @@ public class TvToAudioSystemAvbTest extends BaseAbsoluteVolumeBehaviorTest {

    @Test
    public void savlNotSupported_systemAudioDeviceSendsReportAudioStatus_adjustOnlyAvbEnabled() {
        mAudioManager.setDeviceVolumeBehavior(getAudioOutputDevice(),
                AudioManager.DEVICE_VOLUME_BEHAVIOR_FULL);
        adoptFullVolumeBehaviorOnAvbCapableAudioOutputDevices();
        setCecVolumeControlSetting(HdmiControlManager.VOLUME_CONTROL_ENABLED);
        enableSystemAudioModeIfNeeded();
        receiveSetAudioVolumeLevelSupport(DeviceFeatures.FEATURE_NOT_SUPPORTED);
+63 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2023 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.android.server.hdmi;

import static org.mockito.ArgumentMatchers.anyInt;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.verify;

import android.media.AudioDeviceAttributes;
import android.media.AudioManager;
import android.platform.test.annotations.Presubmit;

import androidx.test.filters.SmallTest;

import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;

import java.util.Collections;

/**
 * Tests for absolute volume behavior where the local device is a TV panel,
 * System Audio device is an Audio System, and they are connected via ARC.
 */
@SmallTest
@Presubmit
@RunWith(JUnit4.class)
public class TvToAudioSystemArcAvbTest extends BaseTvToAudioSystemAvbTest {

    @Override
    protected AudioDeviceAttributes getAudioOutputDevice() {
        return HdmiControlService.AUDIO_OUTPUT_DEVICE_HDMI_ARC;
    }

    @Test
    public void switchAudioOutputDeviceFromArcToEarc_volumeAdjusted_updatesAudioService() {
        enableAbsoluteVolumeBehavior();
        mNativeWrapper.clearResultMessages();

        mAudioFramework.setDevicesForAttributes(HdmiControlService.STREAM_MUSIC_ATTRIBUTES,
                Collections.singletonList(HdmiControlService.AUDIO_OUTPUT_DEVICE_HDMI_EARC));

        receiveReportAudioStatus(20, true);
        verify(mAudioManager).setStreamVolume(eq(AudioManager.STREAM_MUSIC), eq(5),
                anyInt());
        verify(mAudioManager).adjustStreamVolume(eq(AudioManager.STREAM_MUSIC),
                eq(AudioManager.ADJUST_MUTE), anyInt());
    }
}
Loading