1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
|
/*
* Copyright (C) 2022 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 android.hdmicec.cts.tv;
import static com.google.common.truth.Truth.assertThat;
import static com.google.common.truth.Truth.assertWithMessage;
import android.hdmicec.cts.AudioManagerHelper;
import android.hdmicec.cts.BaseHdmiCecCtsTest;
import android.hdmicec.cts.CecMessage;
import android.hdmicec.cts.CecOperand;
import android.hdmicec.cts.HdmiCecConstants;
import android.hdmicec.cts.LogicalAddress;
import com.android.tradefed.testtype.DeviceJUnit4ClassRunner;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.RuleChain;
import org.junit.runner.RunWith;
/**
* Tests TV behavior when it receives <Set Audio Volume Level>.
*/
@RunWith(DeviceJUnit4ClassRunner.class)
public class HdmiCecAbsoluteVolumeControlFollowerTest extends BaseHdmiCecCtsTest {
public HdmiCecAbsoluteVolumeControlFollowerTest() {
super(HdmiCecConstants.CEC_DEVICE_TYPE_TV, "-t", "p", "-t", "a");
}
@Rule
public RuleChain ruleChain =
RuleChain.outerRule(CecRules.requiresCec(this))
.around(CecRules.requiresLeanback(this))
.around(CecRules.requiresPhysicalDevice(this))
.around(CecRules.requiresDeviceType(this, HdmiCecConstants.CEC_DEVICE_TYPE_TV))
.around(hdmiCecClient);
/**
* Tests that if System Audio Mode is enabled, the TV responds to <Set Audio Volume Level>
* with <Feature Abort>[Not in correct mode to respond]
*/
@Test
public void testSystemAudioModeOn_respondsFeatureAbort() throws Exception {
AudioManagerHelper.unmuteDevice(getDevice());
int initialDeviceVolume = AudioManagerHelper.getDutAudioVolume(getDevice());
getDevice().executeShellCommand("cmd hdmi_control setsam on");
hdmiCecClient.sendCecMessage(LogicalAddress.PLAYBACK_1,
CecOperand.SET_AUDIO_VOLUME_LEVEL,
CecMessage.formatParams((initialDeviceVolume + 50) % 101));
// Check that the DUT sent
// <Feature Abort>[Set Audio Volume Level, Not in correct mode to respond]
String featureAbort = hdmiCecClient.checkExpectedOutput(
LogicalAddress.PLAYBACK_1, CecOperand.FEATURE_ABORT);
assertThat(CecOperand.getOperand(CecMessage.getParams(featureAbort, 0, 2)))
.isEqualTo(CecOperand.SET_AUDIO_VOLUME_LEVEL);
assertThat(CecMessage.getParams(featureAbort, 2, 4)).isEqualTo(1);
// Check that volume did not change
assertThat(AudioManagerHelper.getDutAudioVolume(getDevice()))
.isEqualTo(initialDeviceVolume);
}
/**
* Tests that if System Audio Mode is disabled, the TV updates its volume after receiving
* <Set Audio Volume Level>
*/
@Test
public void testSystemAudioModeOff_updatesVolume() throws Exception {
// Wait for CEC adapter to enable System Audio Mode before turning it off
hdmiCecClient.checkExpectedMessageFromClient(LogicalAddress.AUDIO_SYSTEM,
LogicalAddress.TV, CecOperand.SYSTEM_AUDIO_MODE_STATUS);
getDevice().executeShellCommand("cmd hdmi_control setsam off");
AudioManagerHelper.unmuteDevice(getDevice());
int initialDeviceVolume = AudioManagerHelper.getDutAudioVolume(getDevice());
try {
int volumeToSet = (initialDeviceVolume + 50) % 101;
hdmiCecClient.sendCecMessage(LogicalAddress.PLAYBACK_1,
CecOperand.SET_AUDIO_VOLUME_LEVEL,
CecMessage.formatParams(volumeToSet));
// Check that no <Feature Abort> was sent
hdmiCecClient.checkOutputDoesNotContainMessage(LogicalAddress.PLAYBACK_1,
CecOperand.FEATURE_ABORT);
// Check that device volume is within 5 points of the expected volume.
// This accounts for rounding errors due to volume scale conversions.
int deviceVolume = AudioManagerHelper.getDutAudioVolume(getDevice());
assertWithMessage("Expected DUT to have volume " + volumeToSet
+ " but was actually " + deviceVolume)
.that(Math.abs(volumeToSet - deviceVolume) <= 5)
.isTrue();
} finally {
AudioManagerHelper.setDeviceVolume(getDevice(), initialDeviceVolume);
}
}
}
|