blob: f8b39627f2360a6a319d4b731af65441f3f32d99 [file] [log] [blame]
Jinsuk Kim4f512fb2014-02-28 17:41:17 +09001/*
2 * Copyright (C) 2014 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
Jinsuk Kimc0c20d02014-07-04 14:34:31 +090017package com.android.server.hdmi;
Jinsuk Kim4f512fb2014-02-28 17:41:17 +090018
Amy2a6c3dc2018-06-05 17:31:55 -070019import android.annotation.Nullable;
Nick Chalko420df882018-10-23 13:40:41 -070020
Jinsuk Kimc70d2292014-04-30 15:43:16 +090021import libcore.util.EmptyArray;
22
Jinsuk Kim4f512fb2014-02-28 17:41:17 +090023import java.util.Arrays;
Amy2a6c3dc2018-06-05 17:31:55 -070024import java.util.Objects;
Jinsuk Kim4f512fb2014-02-28 17:41:17 +090025
26/**
27 * A class to encapsulate HDMI-CEC message used for the devices connected via
28 * HDMI cable to communicate with one another. A message is defined by its
29 * source and destination address, command (or opcode), and optional parameters.
30 */
Jungshik Jang8e93c842014-08-06 15:48:33 +090031public final class HdmiCecMessage {
Jinsuk Kimc70d2292014-04-30 15:43:16 +090032 public static final byte[] EMPTY_PARAM = EmptyArray.BYTE;
33
Jinsuk Kim4f512fb2014-02-28 17:41:17 +090034 private final int mSource;
35 private final int mDestination;
36
37 private final int mOpcode;
38 private final byte[] mParams;
39
40 /**
41 * Constructor.
42 */
43 public HdmiCecMessage(int source, int destination, int opcode, byte[] params) {
44 mSource = source;
45 mDestination = destination;
Jinsuk Kima8fd44b2014-05-28 17:42:56 +090046 mOpcode = opcode & 0xFF;
Jinsuk Kim4f512fb2014-02-28 17:41:17 +090047 mParams = Arrays.copyOf(params, params.length);
48 }
49
Amy2a6c3dc2018-06-05 17:31:55 -070050 @Override
51 public boolean equals(@Nullable Object message) {
52 if (message instanceof HdmiCecMessage) {
53 HdmiCecMessage that = (HdmiCecMessage) message;
54 return this.mSource == that.getSource() &&
55 this.mDestination == that.getDestination() &&
56 this.mOpcode == that.getOpcode() &&
57 Arrays.equals(this.mParams, that.getParams());
58 }
59 return false;
60 }
61
62 @Override
63 public int hashCode() {
64 return Objects.hash(
65 mSource,
66 mDestination,
67 mOpcode,
68 Arrays.hashCode(mParams));
69 }
70
Jinsuk Kim4f512fb2014-02-28 17:41:17 +090071 /**
72 * Return the source address field of the message. It is the logical address
73 * of the device which generated the message.
74 *
75 * @return source address
76 */
77 public int getSource() {
78 return mSource;
79 }
80
81 /**
82 * Return the destination address field of the message. It is the logical address
83 * of the device to which the message is sent.
84 *
85 * @return destination address
86 */
87 public int getDestination() {
88 return mDestination;
89 }
90
91 /**
92 * Return the opcode field of the message. It is the type of the message that
93 * tells the destination device what to do.
94 *
95 * @return opcode
96 */
97 public int getOpcode() {
98 return mOpcode;
99 }
100
101 /**
102 * Return the parameter field of the message. The contents of parameter varies
103 * from opcode to opcode, and is used together with opcode to describe
104 * the action for the destination device to take.
105 *
106 * @return parameter
107 */
108 public byte[] getParams() {
109 return mParams;
110 }
111
Jinsuk Kim4f512fb2014-02-28 17:41:17 +0900112 @Override
113 public String toString() {
114 StringBuffer s = new StringBuffer();
Nick Chalko476e5462018-10-23 13:36:04 -0700115 s.append(String.format("<%s> %X%X:%02X",
116 opcodeToString(mOpcode), mSource, mDestination, mOpcode));
Yuncheol Heo61ced382014-05-23 20:10:19 +0900117 if (mParams.length > 0) {
Yuncheol Heo61ced382014-05-23 20:10:19 +0900118 for (byte data : mParams) {
Nick Chalko476e5462018-10-23 13:36:04 -0700119 s.append(String.format(":%02X", data));
Yuncheol Heo61ced382014-05-23 20:10:19 +0900120 }
Jinsuk Kim4f512fb2014-02-28 17:41:17 +0900121 }
122 return s.toString();
123 }
Yuncheol Heo61ced382014-05-23 20:10:19 +0900124
125 private static String opcodeToString(int opcode) {
126 switch (opcode) {
Jinsuk Kimc0c20d02014-07-04 14:34:31 +0900127 case Constants.MESSAGE_FEATURE_ABORT:
Yuncheol Heo61ced382014-05-23 20:10:19 +0900128 return "Feature Abort";
Jungshik Jangc94ac5c2014-08-27 13:48:37 +0900129 case Constants.MESSAGE_IMAGE_VIEW_ON:
130 return "Image View On";
131 case Constants.MESSAGE_TUNER_STEP_INCREMENT:
132 return "Tuner Step Increment";
133 case Constants.MESSAGE_TUNER_STEP_DECREMENT:
134 return "Tuner Step Decrement";
135 case Constants.MESSAGE_TUNER_DEVICE_STATUS:
Nick Chalko420df882018-10-23 13:40:41 -0700136 return "Tuner Device Status";
Jungshik Jangc94ac5c2014-08-27 13:48:37 +0900137 case Constants.MESSAGE_GIVE_TUNER_DEVICE_STATUS:
138 return "Give Tuner Device Status";
139 case Constants.MESSAGE_RECORD_ON:
140 return "Record On";
141 case Constants.MESSAGE_RECORD_STATUS:
142 return "Record Status";
143 case Constants.MESSAGE_RECORD_OFF:
144 return "Record Off";
145 case Constants.MESSAGE_TEXT_VIEW_ON:
146 return "Text View On";
147 case Constants.MESSAGE_RECORD_TV_SCREEN:
148 return "Record Tv Screen";
149 case Constants.MESSAGE_GIVE_DECK_STATUS:
150 return "Give Deck Status";
151 case Constants.MESSAGE_DECK_STATUS:
152 return "Deck Status";
153 case Constants.MESSAGE_SET_MENU_LANGUAGE:
154 return "Set Menu Language";
155 case Constants.MESSAGE_CLEAR_ANALOG_TIMER:
156 return "Clear Analog Timer";
157 case Constants.MESSAGE_SET_ANALOG_TIMER:
158 return "Set Analog Timer";
159 case Constants.MESSAGE_TIMER_STATUS:
160 return "Timer Status";
161 case Constants.MESSAGE_STANDBY:
162 return "Standby";
163 case Constants.MESSAGE_PLAY:
164 return "Play";
165 case Constants.MESSAGE_DECK_CONTROL:
166 return "Deck Control";
167 case Constants.MESSAGE_TIMER_CLEARED_STATUS:
168 return "Timer Cleared Status";
169 case Constants.MESSAGE_USER_CONTROL_PRESSED:
170 return "User Control Pressed";
171 case Constants.MESSAGE_USER_CONTROL_RELEASED:
172 return "User Control Release";
173 case Constants.MESSAGE_GIVE_OSD_NAME:
174 return "Give Osd Name";
175 case Constants.MESSAGE_SET_OSD_NAME:
176 return "Set Osd Name";
177 case Constants.MESSAGE_SET_OSD_STRING:
178 return "Set Osd String";
179 case Constants.MESSAGE_SET_TIMER_PROGRAM_TITLE:
180 return "Set Timer Program Title";
181 case Constants.MESSAGE_SYSTEM_AUDIO_MODE_REQUEST:
182 return "System Audio Mode Request";
183 case Constants.MESSAGE_GIVE_AUDIO_STATUS:
184 return "Give Audio Status";
185 case Constants.MESSAGE_SET_SYSTEM_AUDIO_MODE:
Jungshik Jang473119f2014-08-27 16:43:22 +0900186 return "Set System Audio Mode";
Jungshik Jangc94ac5c2014-08-27 13:48:37 +0900187 case Constants.MESSAGE_REPORT_AUDIO_STATUS:
188 return "Report Audio Status";
189 case Constants.MESSAGE_GIVE_SYSTEM_AUDIO_MODE_STATUS:
190 return "Give System Audio Mode Status";
191 case Constants.MESSAGE_SYSTEM_AUDIO_MODE_STATUS:
192 return "System Audio Mode Status";
193 case Constants.MESSAGE_ROUTING_CHANGE:
194 return "Routing Change";
195 case Constants.MESSAGE_ROUTING_INFORMATION:
196 return "Routing Information";
197 case Constants.MESSAGE_ACTIVE_SOURCE:
198 return "Active Source";
199 case Constants.MESSAGE_GIVE_PHYSICAL_ADDRESS:
200 return "Give Physical Address";
201 case Constants.MESSAGE_REPORT_PHYSICAL_ADDRESS:
202 return "Report Physical Address";
203 case Constants.MESSAGE_REQUEST_ACTIVE_SOURCE:
204 return "Request Active Source";
205 case Constants.MESSAGE_SET_STREAM_PATH:
206 return "Set Stream Path";
207 case Constants.MESSAGE_DEVICE_VENDOR_ID:
208 return "Device Vendor Id";
209 case Constants.MESSAGE_VENDOR_COMMAND:
Nick Chalko420df882018-10-23 13:40:41 -0700210 return "Vendor Command";
Jungshik Jangc94ac5c2014-08-27 13:48:37 +0900211 case Constants.MESSAGE_VENDOR_REMOTE_BUTTON_DOWN:
212 return "Vendor Remote Button Down";
213 case Constants.MESSAGE_VENDOR_REMOTE_BUTTON_UP:
214 return "Vendor Remote Button Up";
215 case Constants.MESSAGE_GIVE_DEVICE_VENDOR_ID:
216 return "Give Device Vendor Id";
217 case Constants.MESSAGE_MENU_REQUEST:
Nick Chalko420df882018-10-23 13:40:41 -0700218 return "Menu Request";
Jungshik Jangc94ac5c2014-08-27 13:48:37 +0900219 case Constants.MESSAGE_MENU_STATUS:
220 return "Menu Status";
221 case Constants.MESSAGE_GIVE_DEVICE_POWER_STATUS:
222 return "Give Device Power Status";
223 case Constants.MESSAGE_REPORT_POWER_STATUS:
224 return "Report Power Status";
225 case Constants.MESSAGE_GET_MENU_LANGUAGE:
226 return "Get Menu Language";
227 case Constants.MESSAGE_SELECT_ANALOG_SERVICE:
228 return "Select Analog Service";
229 case Constants.MESSAGE_SELECT_DIGITAL_SERVICE:
230 return "Select Digital Service";
231 case Constants.MESSAGE_SET_DIGITAL_TIMER:
232 return "Set Digital Timer";
233 case Constants.MESSAGE_CLEAR_DIGITAL_TIMER:
234 return "Clear Digital Timer";
235 case Constants.MESSAGE_SET_AUDIO_RATE:
236 return "Set Audio Rate";
237 case Constants.MESSAGE_INACTIVE_SOURCE:
238 return "InActive Source";
Jinsuk Kimc0c20d02014-07-04 14:34:31 +0900239 case Constants.MESSAGE_CEC_VERSION:
Jungshik Jangc94ac5c2014-08-27 13:48:37 +0900240 return "Cec Version";
241 case Constants.MESSAGE_GET_CEC_VERSION:
242 return "Get Cec Version";
243 case Constants.MESSAGE_VENDOR_COMMAND_WITH_ID:
244 return "Vendor Command With Id";
245 case Constants.MESSAGE_CLEAR_EXTERNAL_TIMER:
246 return "Clear External Timer";
247 case Constants.MESSAGE_SET_EXTERNAL_TIMER:
248 return "Set External Timer";
249 case Constants.MESSAGE_REPORT_SHORT_AUDIO_DESCRIPTOR:
Nick Chalko420df882018-10-23 13:40:41 -0700250 return "Report Short Audio Descriptor";
Jungshik Jangc94ac5c2014-08-27 13:48:37 +0900251 case Constants.MESSAGE_REQUEST_SHORT_AUDIO_DESCRIPTOR:
252 return "Request Short Audio Descriptor";
253 case Constants.MESSAGE_INITIATE_ARC:
254 return "Initiate ARC";
Jinsuk Kimc0c20d02014-07-04 14:34:31 +0900255 case Constants.MESSAGE_REPORT_ARC_INITIATED:
Yuncheol Heo61ced382014-05-23 20:10:19 +0900256 return "Report ARC Initiated";
Jinsuk Kimc0c20d02014-07-04 14:34:31 +0900257 case Constants.MESSAGE_REPORT_ARC_TERMINATED:
Yuncheol Heo61ced382014-05-23 20:10:19 +0900258 return "Report ARC Terminated";
Jungshik Jangc94ac5c2014-08-27 13:48:37 +0900259 case Constants.MESSAGE_REQUEST_ARC_INITIATION:
260 return "Request ARC Initiation";
261 case Constants.MESSAGE_REQUEST_ARC_TERMINATION:
262 return "Request ARC Termination";
263 case Constants.MESSAGE_TERMINATE_ARC:
264 return "Terminate ARC";
265 case Constants.MESSAGE_CDC_MESSAGE:
266 return "Cdc Message";
267 case Constants.MESSAGE_ABORT:
268 return "Abort";
Yuncheol Heo61ced382014-05-23 20:10:19 +0900269 default:
270 return String.format("Opcode: %02X", opcode);
271 }
272 }
Jinsuk Kim4f512fb2014-02-28 17:41:17 +0900273}
274