summaryrefslogtreecommitdiff
path: root/hostsidetests/hdmicec/src/android/hdmicec/cts/playback/HdmiCecRemoteControlPassThroughTest.java
blob: 4a64e5c63a0c4da23efeba61de7d8cc5a652454a (plain)
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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
/*
 * Copyright (C) 2019 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.playback;

import static com.google.common.truth.Truth.assertThat;
import static com.google.common.truth.Truth.assertWithMessage;

import android.hdmicec.cts.BaseHdmiCecCtsTest;
import android.hdmicec.cts.CecMessage;
import android.hdmicec.cts.CecOperand;
import android.hdmicec.cts.HdmiCecConstants;
import android.hdmicec.cts.HdmiControlManagerUtility;
import android.hdmicec.cts.LogicalAddress;
import android.hdmicec.cts.RemoteControlPassthrough;

import com.android.tradefed.device.ITestDevice;
import com.android.tradefed.testtype.DeviceJUnit4ClassRunner;

import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.RuleChain;
import org.junit.runner.RunWith;

/**
 * HDMI CEC tests to ensure that the remote control passthrough to TV works as expected (Section
 * 11.2.13)
 */
@RunWith(DeviceJUnit4ClassRunner.class)
public final class HdmiCecRemoteControlPassThroughTest extends BaseHdmiCecCtsTest {

    private static int DUT_DEVICE_TYPE = HdmiCecConstants.CEC_DEVICE_TYPE_PLAYBACK_DEVICE;

    public HdmiCecRemoteControlPassThroughTest() {
        super(DUT_DEVICE_TYPE);
    }

    @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_PLAYBACK_DEVICE))
                    .around(hdmiCecClient);

    /**
     * Test 11.2.13-1
     *
     * <p>Tests that the device responds correctly to a {@code <USER_CONTROL_PRESSED>} message
     * followed immediately by a {@code <USER_CONTROL_RELEASED>} message.
     */
    @Test
    public void cect_11_2_13_1_UserControlPressAndRelease() throws Exception {
        LogicalAddress dutLogicalAddress = getTargetLogicalAddress(getDevice(), DUT_DEVICE_TYPE);
        RemoteControlPassthrough.checkUserControlPressAndRelease(
                hdmiCecClient, getDevice(), LogicalAddress.TV, dutLogicalAddress);
    }

    /**
     * Test 11.2.13-2
     * Tests that the device responds correctly to a <USER_CONTROL_PRESSED> message for press and
     * hold operations.
     */
    @Test
    public void cect_11_2_13_2_UserControlPressAndHold() throws Exception {
        LogicalAddress dutLogicalAddress = getTargetLogicalAddress(getDevice(), DUT_DEVICE_TYPE);
        RemoteControlPassthrough.checkUserControlPressAndHold(
                hdmiCecClient, getDevice(), LogicalAddress.TV, dutLogicalAddress);
    }

    /**
     * HF 4-8-4
     *
     * <p>Verify that the device that support cec version 2.0 accepts {@code <USER_CONTROL_PRESSED>}
     * messages and maps to appropriate internal action.
     *
     * No Android keycode defined for {@code <CEC_KEYCODE_FAVORITE_MENU>},
     * {@code <CEC_KEYCODE_STOP_RECORD>} and {@code <CEC_KEYCODE_PAUSE_RECORD>}
     *
     * The UI commands Audio Description, internet and 3D mode are introduced in CEC 2.0 devices but
     * they haven't been implemented yet.
     * TODO: Add these UI commands once they are implemented.
     */
    @Test
    public void cect_4_8_4_UserControlPressAndRelease_20() throws Exception {
        setCec20();
        LogicalAddress dutLogicalAddress = getTargetLogicalAddress(getDevice(), DUT_DEVICE_TYPE);
        RemoteControlPassthrough.checkUserControlPressAndRelease_20(
                hdmiCecClient, getDevice(), LogicalAddress.TV, dutLogicalAddress);
    }

    /**
     * Test HF4-8-12
     *
     * <p>Tests that device sends the UCP Commands related to menus (Device Root Menu, Device Setup
     * Menu, Contents Menu, Media Top Menu, Media Context-Sensitive Menu) in the operand [RC Profile
     * Source] that is sent in the <Report Features> message and verifies that device reacts to sent
     * UCP commands.
     */
    @Test
    public void cect_hf4_8_12_UCPForRcProfileSearchOperand() throws Exception {
        setCec20();
        hdmiCecClient.sendCecMessage(LogicalAddress.TV, CecOperand.GIVE_FEATURES);
        String message = hdmiCecClient.checkExpectedOutput(CecOperand.REPORT_FEATURES);
        int remoteControlProfileSource = CecMessage.getParams(message, 4, 6);
        if ((remoteControlProfileSource & 0x01) == 0x01) {
            sendUcpMenuCommand(
                    HdmiCecConstants.CEC_KEYCODE_MEDIA_CONTEXT_SENSITIVE_MENU,
                    "TV_MEDIA_CONTEXT_MENU");
        }
        if ((remoteControlProfileSource & 0x02) == 0x02) {
            sendUcpMenuCommand(HdmiCecConstants.CEC_KEYCODE_MEDIA_TOP_MENU, "MEDIA_TOP_MENU");
        }
        if ((remoteControlProfileSource & 0x04) == 0x04) {
            sendUcpMenuCommand(HdmiCecConstants.CEC_KEYCODE_CONTENTS_MENU, "TV_CONTENTS_MENU");
        }
        if ((remoteControlProfileSource & 0x08) == 0x08) {
            sendUcpMenuCommand(HdmiCecConstants.CEC_KEYCODE_SETUP_MENU, "SETTINGS");
        }
        if ((remoteControlProfileSource & 0x10) == 0x10) {
            sendUcpMenuCommand(HdmiCecConstants.CEC_KEYCODE_ROOT_MENU, "HOME");
        }
    }

    private void sendUcpMenuCommand(int cecKeycode, String androidKeycode) throws Exception {
        LogicalAddress dutLogicalAddress = getTargetLogicalAddress(getDevice(), DUT_DEVICE_TYPE);
        RemoteControlPassthrough.checkUserControlPressAndRelease(
                hdmiCecClient,
                getDevice(),
                LogicalAddress.TV,
                dutLogicalAddress,
                cecKeycode,
                androidKeycode);
    }

    /**
     * Test HF4-8-9 (CEC 2.0)
     *
     * <p>Tests that the DUT sends multiple {@code <USER_CONTROL_PRESSED>[KEYCODE]} when there is a
     * long press keyevent.
     */
    @Test
    public void cect_hf4_8_9_SendLongPress() throws Exception {
        setCec20();
        String message;
        int i;

        HdmiControlManagerUtility.sendLongPressKeyevent(this);
        // The above command should send 5 <UCP>[KEYCODE_UP] messages followed by 1 <UCR> message
        // and finally, a <UCP>[KEYCODE_DOWN].
        for (i = 0; i < 5; i++) {
            message =
                    hdmiCecClient.checkExpectedOutput(
                            LogicalAddress.TV, CecOperand.USER_CONTROL_PRESSED);
            assertThat(CecMessage.getParams(message)).isEqualTo(HdmiCecConstants.CEC_KEYCODE_UP);
        }
        message =
                hdmiCecClient.checkExpectedOutput(
                        LogicalAddress.TV, CecOperand.USER_CONTROL_RELEASED);
        message =
                hdmiCecClient.checkExpectedOutput(
                        LogicalAddress.TV, CecOperand.USER_CONTROL_PRESSED);
        assertThat(CecMessage.getParams(message)).isEqualTo(HdmiCecConstants.CEC_KEYCODE_DOWN);
    }

    /**
     * Test HF4-8-13 (CEC 2.0)
     *
     * <p>Tests that the device responds with a {@code <FEATURE_ABORT>[Not in correct mode]} when it
     * is not in a mode to action the message.
     */
    @Test
    public void cect_hf4_8_13_AbortIncorrectMode() throws Exception {
        setCec20();
        try {
            sendDeviceToSleep();
            hdmiCecClient.sendUserControlPressAndRelease(
                    LogicalAddress.TV, HdmiCecConstants.CEC_KEYCODE_ROOT_MENU, false);
            String message =
                    hdmiCecClient.checkExpectedOutput(LogicalAddress.TV, CecOperand.FEATURE_ABORT);
            int reason = CecMessage.getParams(message) & 0xFF;
            assertThat(reason).isEqualTo(HdmiCecConstants.ABORT_NOT_IN_CORRECT_MODE);
        } finally {
            wakeUpDevice();
        }
    }

    /*
     * Test to check that the DUT sends volume key press events to the TV when system audio mode is
     * not turned on.
     */
    @Test
    public void cect_sendVolumeKeyPressToTv() throws Exception {
        ITestDevice device = getDevice();
        String ucpMessage;
        String command = "cmd hdmi_control setsam ";

        simulateCecSinkConnected(device, getTargetLogicalAddress());
        String volumeControlEnabled =
                getSettingsValue(device, HdmiCecConstants.SETTING_VOLUME_CONTROL_ENABLED);
        setSettingsValue(
                device,
                HdmiCecConstants.SETTING_VOLUME_CONTROL_ENABLED,
                HdmiCecConstants.VOLUME_CONTROL_ENABLED);

        boolean wasSystemAudioModeOn = isSystemAudioModeOn(device);
        if (wasSystemAudioModeOn) {
            device.executeShellCommand(command + "off");
            assertWithMessage("System audio mode is not off")
                    .that(isSystemAudioModeOn(device))
                    .isFalse();
        }
        try {
            device.executeShellCommand("input keyevent KEYCODE_VOLUME_UP");
            ucpMessage =
                    hdmiCecClient.checkExpectedOutput(
                            LogicalAddress.TV, CecOperand.USER_CONTROL_PRESSED);
            assertThat(CecMessage.getParams(ucpMessage))
                    .isEqualTo(HdmiCecConstants.CEC_KEYCODE_VOLUME_UP);
            device.executeShellCommand("input keyevent KEYCODE_VOLUME_DOWN");
            ucpMessage =
                    hdmiCecClient.checkExpectedOutput(
                            LogicalAddress.TV, CecOperand.USER_CONTROL_PRESSED);
            assertThat(CecMessage.getParams(ucpMessage))
                    .isEqualTo(HdmiCecConstants.CEC_KEYCODE_VOLUME_DOWN);
            device.executeShellCommand("input keyevent KEYCODE_VOLUME_MUTE");
            ucpMessage =
                    hdmiCecClient.checkExpectedOutput(
                            LogicalAddress.TV, CecOperand.USER_CONTROL_PRESSED);
            assertThat(CecMessage.getParams(ucpMessage))
                    .isEqualTo(HdmiCecConstants.CEC_KEYCODE_MUTE);
        } finally {
            if (wasSystemAudioModeOn) {
                device.executeShellCommand(command + "on");
            }
            setSettingsValue(
                    device, HdmiCecConstants.SETTING_VOLUME_CONTROL_ENABLED, volumeControlEnabled);
        }
    }
}