1 /*
2  * Copyright (C) 2022 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 package com.android.server.hdmi;
18 
19 import static com.google.common.truth.Truth.assertThat;
20 
21 import android.hardware.hdmi.DeviceFeatures;
22 import android.hardware.hdmi.HdmiControlManager;
23 import android.hardware.hdmi.HdmiDeviceInfo;
24 import android.media.AudioManager;
25 import android.platform.test.annotations.Presubmit;
26 
27 import androidx.test.filters.SmallTest;
28 
29 import com.google.android.collect.Lists;
30 
31 import org.junit.Test;
32 import org.junit.runner.RunWith;
33 import org.junit.runners.JUnit4;
34 
35 import java.util.Arrays;
36 
37 /**
38  * Tests for absolute volume behavior where the local device is a Playback device and the
39  * System Audio device is an Audio System.
40  */
41 @SmallTest
42 @Presubmit
43 @RunWith(JUnit4.class)
44 public class PlaybackDeviceToAudioSystemAvbTest extends BasePlaybackDeviceAvbTest {
45 
46     @Override
getSystemAudioDeviceLogicalAddress()47     protected int getSystemAudioDeviceLogicalAddress() {
48         return Constants.ADDR_AUDIO_SYSTEM;
49     }
50 
51     @Override
getSystemAudioDeviceType()52     protected int getSystemAudioDeviceType() {
53         return HdmiDeviceInfo.DEVICE_AUDIO_SYSTEM;
54     }
55 
56     /**
57      * AVB is disabled if the Audio System disables System Audio mode, and the TV has unknown
58      * support for <Set Audio Volume Level>. It is enabled once the TV confirms support for
59      * <Set Audio Volume Level> and sends <Report Audio Status>.
60      */
61     @Test
switchToTv_absoluteVolumeControlDisabledUntilAllConditionsMet()62     public void switchToTv_absoluteVolumeControlDisabledUntilAllConditionsMet() {
63         enableAbsoluteVolumeBehavior();
64 
65         // Audio System disables System Audio Mode. AVB should be disabled.
66         receiveSetSystemAudioMode(false);
67         assertThat(mAudioManager.getDeviceVolumeBehavior(getAudioOutputDevice())).isEqualTo(
68                 AudioManager.DEVICE_VOLUME_BEHAVIOR_FULL);
69 
70         // TV reports support for <Set Audio Volume Level>
71         mNativeWrapper.onCecMessage(ReportFeaturesMessage.build(
72                 Constants.ADDR_TV, HdmiControlManager.HDMI_CEC_VERSION_2_0,
73                 Arrays.asList(HdmiDeviceInfo.DEVICE_TV), Constants.RC_PROFILE_TV,
74                 Lists.newArrayList(Constants.RC_PROFILE_TV_NONE),
75                 DeviceFeatures.NO_FEATURES_SUPPORTED.toBuilder()
76                         .setSetAudioVolumeLevelSupport(DeviceFeatures.FEATURE_SUPPORTED)
77                         .build()));
78         mTestLooper.dispatchAll();
79 
80         // TV reports its initial audio status
81         mNativeWrapper.onCecMessage(HdmiCecMessageBuilder.buildReportAudioStatus(
82                 Constants.ADDR_TV,
83                 getLogicalAddress(),
84                 30,
85                 false));
86         mTestLooper.dispatchAll();
87 
88         assertThat(mAudioManager.getDeviceVolumeBehavior(getAudioOutputDevice())).isEqualTo(
89                 AudioManager.DEVICE_VOLUME_BEHAVIOR_ABSOLUTE);
90     }
91 }
92