blob: 4b5ced99a250458f5abbea18794c13fcd9d272fe [file] [log] [blame]
Jinsuk Kim91120c52014-05-08 17:12:51 +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
17package android.hardware.hdmi;
18
19import android.annotation.Nullable;
Jinsuk Kimc7eba0f2014-07-07 14:18:02 +090020import android.annotation.SdkConstant;
21import android.annotation.SdkConstant.SdkConstantType;
Jinsuk Kim66d1eb22014-06-06 16:12:18 +090022import android.annotation.SystemApi;
Jinsuk Kim78d695d2014-05-13 16:36:15 +090023import android.os.RemoteException;
24
Jinsuk Kim91120c52014-05-08 17:12:51 +090025/**
26 * The {@link HdmiControlManager} class is used to send HDMI control messages
27 * to attached CEC devices.
28 *
29 * <p>Provides various HDMI client instances that represent HDMI-CEC logical devices
30 * hosted in the system. {@link #getTvClient()}, for instance will return an
31 * {@link HdmiTvClient} object if the system is configured to host one. Android system
32 * can host more than one logical CEC devices. If multiple types are configured they
33 * all work as if they were independent logical devices running in the system.
Jinsuk Kim66d1eb22014-06-06 16:12:18 +090034 *
35 * @hide
Jinsuk Kim91120c52014-05-08 17:12:51 +090036 */
Jinsuk Kim66d1eb22014-06-06 16:12:18 +090037@SystemApi
Jinsuk Kim91120c52014-05-08 17:12:51 +090038public final class HdmiControlManager {
39 @Nullable private final IHdmiControlService mService;
40
Jinsuk Kimc7eba0f2014-07-07 14:18:02 +090041 /**
42 * Broadcast Action: Display OSD message.
43 * <p>Send when the service has a message to display on screen for events
44 * that need user's attention such as ARC status change.
Jungshik Jange5a93372014-07-25 13:41:14 +090045 * <p>Always contains the extra fields {@link #EXTRA_MESSAGE_ID}.
Jinsuk Kimc7eba0f2014-07-07 14:18:02 +090046 * <p>Requires {@link android.Manifest.permission#HDMI_CEC} to receive.
47 */
48 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
49 public static final String ACTION_OSD_MESSAGE = "android.hardware.hdmi.action.OSD_MESSAGE";
50
Jungshik Jang339227d2014-08-25 15:37:20 +090051 // --- Messages for ACTION_OSD_MESSAGE ---
52 /**
53 * Message that ARC enabled device is connected to invalid port (non-ARC port).
54 */
55 public static final int OSD_MESSAGE_ARC_CONNECTED_INVALID_PORT = 1;
56
Jinsuk Kimc7eba0f2014-07-07 14:18:02 +090057 /**
58 * Used as an extra field in the intent {@link #ACTION_OSD_MESSAGE}. Contains the ID of
59 * the message to display on screen.
60 */
61 public static final String EXTRA_MESSAGE_ID = "android.hardware.hdmi.extra.MESSAGE_ID";
62
Jinsuk Kimc0c20d02014-07-04 14:34:31 +090063 public static final int POWER_STATUS_UNKNOWN = -1;
64 public static final int POWER_STATUS_ON = 0;
65 public static final int POWER_STATUS_STANDBY = 1;
66 public static final int POWER_STATUS_TRANSIENT_TO_ON = 2;
67 public static final int POWER_STATUS_TRANSIENT_TO_STANDBY = 3;
68
69 public static final int RESULT_SUCCESS = 0;
70 public static final int RESULT_TIMEOUT = 1;
71 public static final int RESULT_SOURCE_NOT_AVAILABLE = 2;
72 public static final int RESULT_TARGET_NOT_AVAILABLE = 3;
73 public static final int RESULT_ALREADY_IN_PROGRESS = 4;
74 public static final int RESULT_EXCEPTION = 5;
75 public static final int RESULT_INCORRECT_MODE = 6;
Jinsuk Kimb38cd682014-07-07 08:05:03 +090076 public static final int RESULT_COMMUNICATION_FAILED = 7;
Jinsuk Kimc0c20d02014-07-04 14:34:31 +090077
Jungshik Jang61daf6b2014-08-08 11:38:28 +090078 public static final int DEVICE_EVENT_ADD_DEVICE = 1;
79 public static final int DEVICE_EVENT_REMOVE_DEVICE = 2;
80 public static final int DEVICE_EVENT_UPDATE_DEVICE = 3;
81
Jungshik Jang12e5dce2014-07-24 15:27:44 +090082 // --- One Touch Recording success result
Jungshik Jangb6591b82014-07-23 16:10:23 +090083 /** Recording currently selected source. Indicates the status of a recording. */
Jungshik Jang12e5dce2014-07-24 15:27:44 +090084 public static final int ONE_TOUCH_RECORD_RECORDING_CURRENTLY_SELECTED_SOURCE = 0x01;
Jungshik Jangb6591b82014-07-23 16:10:23 +090085 /** Recording Digital Service. Indicates the status of a recording. */
Jungshik Jang12e5dce2014-07-24 15:27:44 +090086 public static final int ONE_TOUCH_RECORD_RECORDING_DIGITAL_SERVICE = 0x02;
Jungshik Jangb6591b82014-07-23 16:10:23 +090087 /** Recording Analogue Service. Indicates the status of a recording. */
Jungshik Jang12e5dce2014-07-24 15:27:44 +090088 public static final int ONE_TOUCH_RECORD_RECORDING_ANALOGUE_SERVICE = 0x03;
Jungshik Jangb6591b82014-07-23 16:10:23 +090089 /** Recording External input. Indicates the status of a recording. */
Jungshik Jang12e5dce2014-07-24 15:27:44 +090090 public static final int ONE_TOUCH_RECORD_RECORDING_EXTERNAL_INPUT = 0x04;
91
92 // --- One Touch Record failure result
Jungshik Jangb6591b82014-07-23 16:10:23 +090093 /** No recording – unable to record Digital Service. No suitable tuner. */
Jungshik Jang12e5dce2014-07-24 15:27:44 +090094 public static final int ONE_TOUCH_RECORD_UNABLE_DIGITAL_SERVICE = 0x05;
Jungshik Jangb6591b82014-07-23 16:10:23 +090095 /** No recording – unable to record Analogue Service. No suitable tuner. */
Jungshik Jang12e5dce2014-07-24 15:27:44 +090096 public static final int ONE_TOUCH_RECORD_UNABLE_ANALOGUE_SERVICE = 0x06;
Jungshik Jangb6591b82014-07-23 16:10:23 +090097 /**
98 * No recording – unable to select required service. as suitable tuner, but the requested
99 * parameters are invalid or out of range for that tuner.
100 */
Jungshik Jang12e5dce2014-07-24 15:27:44 +0900101 public static final int ONE_TOUCH_RECORD_UNABLE_SELECTED_SERVICE = 0x07;
Jungshik Jangb6591b82014-07-23 16:10:23 +0900102 /** No recording – invalid External plug number */
Jungshik Jang12e5dce2014-07-24 15:27:44 +0900103 public static final int ONE_TOUCH_RECORD_INVALID_EXTERNAL_PLUG_NUMBER = 0x09;
Jungshik Jangb6591b82014-07-23 16:10:23 +0900104 /** No recording – invalid External Physical Address */
Jungshik Jang12e5dce2014-07-24 15:27:44 +0900105 public static final int ONE_TOUCH_RECORD_INVALID_EXTERNAL_PHYSICAL_ADDRESS = 0x0A;
Jungshik Jangb6591b82014-07-23 16:10:23 +0900106 /** No recording – CA system not supported */
Jungshik Jang12e5dce2014-07-24 15:27:44 +0900107 public static final int ONE_TOUCH_RECORD_UNSUPPORTED_CA = 0x0B;
Jungshik Jangb6591b82014-07-23 16:10:23 +0900108 /** No Recording – No or Insufficient CA Entitlements” */
Jungshik Jang12e5dce2014-07-24 15:27:44 +0900109 public static final int ONE_TOUCH_RECORD_NO_OR_INSUFFICIENT_CA_ENTITLEMENTS = 0x0C;
Jungshik Jangb6591b82014-07-23 16:10:23 +0900110 /** No recording – Not allowed to copy source. Source is “copy never”. */
Jungshik Jang12e5dce2014-07-24 15:27:44 +0900111 public static final int ONE_TOUCH_RECORD_DISALLOW_TO_COPY = 0x0D;
Jungshik Jangb6591b82014-07-23 16:10:23 +0900112 /** No recording – No further copies allowed */
Jungshik Jang12e5dce2014-07-24 15:27:44 +0900113 public static final int ONE_TOUCH_RECORD_DISALLOW_TO_FUTHER_COPIES = 0x0E;
Jungshik Jangb6591b82014-07-23 16:10:23 +0900114 /** No recording – No media */
Jungshik Jang12e5dce2014-07-24 15:27:44 +0900115 public static final int ONE_TOUCH_RECORD_NO_MEDIA = 0x10;
Jungshik Jangb6591b82014-07-23 16:10:23 +0900116 /** No recording – playing */
Jungshik Jang12e5dce2014-07-24 15:27:44 +0900117 public static final int ONE_TOUCH_RECORD_PLAYING = 0x11;
Jungshik Jangb6591b82014-07-23 16:10:23 +0900118 /** No recording – already recording */
Jungshik Jang12e5dce2014-07-24 15:27:44 +0900119 public static final int ONE_TOUCH_RECORD_ALREADY_RECORDING = 0x12;
Jungshik Jangb6591b82014-07-23 16:10:23 +0900120 /** No recording – media protected */
Jungshik Jang12e5dce2014-07-24 15:27:44 +0900121 public static final int ONE_TOUCH_RECORD_MEDIA_PROTECTED = 0x13;
Jungshik Jangb6591b82014-07-23 16:10:23 +0900122 /** No recording – no source signal */
Jungshik Jang12e5dce2014-07-24 15:27:44 +0900123 public static final int ONE_TOUCH_RECORD_NO_SOURCE_SIGNAL = 0x14;
Jungshik Jangb6591b82014-07-23 16:10:23 +0900124 /** No recording – media problem */
Jungshik Jang12e5dce2014-07-24 15:27:44 +0900125 public static final int ONE_TOUCH_RECORD_MEDIA_PROBLEM = 0x15;
Jungshik Jangb6591b82014-07-23 16:10:23 +0900126 /** No recording – not enough space available */
Jungshik Jang12e5dce2014-07-24 15:27:44 +0900127 public static final int ONE_TOUCH_RECORD_NOT_ENOUGH_SPACE = 0x16;
Jungshik Jangb6591b82014-07-23 16:10:23 +0900128 /** No recording – Parental Lock On */
Jungshik Jang12e5dce2014-07-24 15:27:44 +0900129 public static final int ONE_TOUCH_RECORD_PARENT_LOCK_ON = 0x17;
Jungshik Jangb6591b82014-07-23 16:10:23 +0900130 /** Recording terminated normally */
Jungshik Jang12e5dce2014-07-24 15:27:44 +0900131 public static final int ONE_TOUCH_RECORD_RECORDING_TERMINATED_NORMALLY = 0x1A;
Jungshik Jangb6591b82014-07-23 16:10:23 +0900132 /** Recording has already terminated */
Jungshik Jang12e5dce2014-07-24 15:27:44 +0900133 public static final int ONE_TOUCH_RECORD_RECORDING_ALREADY_TERMINATED = 0x1B;
Jungshik Jangb6591b82014-07-23 16:10:23 +0900134 /** No recording – other reason */
Jungshik Jang12e5dce2014-07-24 15:27:44 +0900135 public static final int ONE_TOUCH_RECORD_OTHER_REASON = 0x1F;
Jungshik Jangb6591b82014-07-23 16:10:23 +0900136 // From here extra message for recording that is not mentioned in CEC spec
137 /** No recording. Previous recording request in progress. */
Jungshik Jang12e5dce2014-07-24 15:27:44 +0900138 public static final int ONE_TOUCH_RECORD_PREVIOUS_RECORDING_IN_PROGRESS = 0x30;
Jungshik Jangb6591b82014-07-23 16:10:23 +0900139 /** No recording. Please check recorder and connection. */
Jungshik Jang12e5dce2014-07-24 15:27:44 +0900140 public static final int ONE_TOUCH_RECORD_CHECK_RECORDER_CONNECTION = 0x31;
Jungshik Jangb6591b82014-07-23 16:10:23 +0900141 /** Cannot record currently displayed source. */
Jungshik Jang12e5dce2014-07-24 15:27:44 +0900142 public static final int ONE_TOUCH_RECORD_FAIL_TO_RECORD_DISPLAYED_SCREEN = 0x32;
143 /** CEC is disabled. */
144 public static final int ONE_TOUCH_RECORD_CEC_DISABLED = 0x33;
Jungshik Jangb6591b82014-07-23 16:10:23 +0900145
Jungshik Jang12e5dce2014-07-24 15:27:44 +0900146 // --- Types for timer recording
Jungshik Jangb6591b82014-07-23 16:10:23 +0900147 /** Timer recording type for digital service source. */
148 public static final int TIMER_RECORDING_TYPE_DIGITAL = 1;
149 /** Timer recording type for analogue service source. */
150 public static final int TIMER_RECORDING_TYPE_ANALOGUE = 2;
151 /** Timer recording type for external source. */
152 public static final int TIMER_RECORDING_TYPE_EXTERNAL = 3;
153
Jungshik Jange5a93372014-07-25 13:41:14 +0900154 // --- Timer Status Data
155 /** [Timer Status Data/Media Info] - Media present and not protected. */
156 public static final int TIMER_STATUS_MEDIA_INFO_PRESENT_NOT_PROTECTED = 0x0;
157 /** [Timer Status Data/Media Info] - Media present, but protected. */
158 public static final int TIMER_STATUS_MEDIA_INFO_PRESENT_PROTECTED = 0x1;
159 /** [Timer Status Data/Media Info] - Media not present. */
160 public static final int TIMER_STATUS_MEDIA_INFO_NOT_PRESENT = 0x2;
161
162 /** [Timer Status Data/Programmed Info] - Enough space available for recording. */
163 public static final int TIMER_STATUS_PROGRAMMED_INFO_ENOUGH_SPACE = 0x8;
164 /** [Timer Status Data/Programmed Info] - Not enough space available for recording. */
165 public static final int TIMER_STATUS_PROGRAMMED_INFO_NOT_ENOUGH_SPACE = 0x9;
166 /** [Timer Status Data/Programmed Info] - Might not enough space available for recording. */
167 public static final int TIMER_STATUS_PROGRAMMED_INFO_MIGHT_NOT_ENOUGH_SPACE = 0xB;
168 /** [Timer Status Data/Programmed Info] - No media info available. */
169 public static final int TIMER_STATUS_PROGRAMMED_INFO_NO_MEDIA_INFO = 0xA;
170
171 /** [Timer Status Data/Not Programmed Error Info] - No free timer available. */
172 public static final int TIMER_STATUS_NOT_PROGRAMMED_NO_FREE_TIME = 0x1;
173 /** [Timer Status Data/Not Programmed Error Info] - Date out of range. */
174 public static final int TIMER_STATUS_NOT_PROGRAMMED_DATE_OUT_OF_RANGE = 0x2;
175 /** [Timer Status Data/Not Programmed Error Info] - Recording Sequence error. */
176 public static final int TIMER_STATUS_NOT_PROGRAMMED_INVALID_SEQUENCE = 0x3;
177 /** [Timer Status Data/Not Programmed Error Info] - Invalid External Plug Number. */
178 public static final int TIMER_STATUS_NOT_PROGRAMMED_INVALID_EXTERNAL_PLUG_NUMBER = 0x4;
179 /** [Timer Status Data/Not Programmed Error Info] - Invalid External Physical Address. */
180 public static final int TIMER_STATUS_NOT_PROGRAMMED_INVALID_EXTERNAL_PHYSICAL_NUMBER = 0x5;
181 /** [Timer Status Data/Not Programmed Error Info] - CA system not supported. */
182 public static final int TIMER_STATUS_NOT_PROGRAMMED_CA_NOT_SUPPORTED = 0x6;
183 /** [Timer Status Data/Not Programmed Error Info] - No or insufficient CA Entitlements. */
184 public static final int TIMER_STATUS_NOT_PROGRAMMED_NO_CA_ENTITLEMENTS = 0x7;
185 /** [Timer Status Data/Not Programmed Error Info] - Does not support resolution. */
186 public static final int TIMER_STATUS_NOT_PROGRAMMED_UNSUPPORTED_RESOLUTION = 0x8;
187 /** [Timer Status Data/Not Programmed Error Info] - Parental Lock On. */
188 public static final int TIMER_STATUS_NOT_PROGRAMMED_PARENTAL_LOCK_ON= 0x9;
189 /** [Timer Status Data/Not Programmed Error Info] - Clock Failure. */
190 public static final int TIMER_STATUS_NOT_PROGRAMMED_CLOCK_FAILURE = 0xA;
191 /** [Timer Status Data/Not Programmed Error Info] - Duplicate: already programmed. */
192 public static final int TIMER_STATUS_NOT_PROGRAMMED_DUPLICATED = 0xE;
193
Jungshik Jang12e5dce2014-07-24 15:27:44 +0900194 // --- Extra result value for timer recording.
Jungshik Jange5a93372014-07-25 13:41:14 +0900195 /** No extra error. */
196 public static final int TIMER_RECORDING_RESULT_EXTRA_NO_ERROR = 0x00;
Jungshik Jang12e5dce2014-07-24 15:27:44 +0900197 /** No timer recording - check recorder and connection. */
Jungshik Jange5a93372014-07-25 13:41:14 +0900198 public static final int TIMER_RECORDING_RESULT_EXTRA_CHECK_RECORDER_CONNECTION = 0x01;
Jungshik Jang12e5dce2014-07-24 15:27:44 +0900199 /** No timer recording - cannot record selected source. */
Jungshik Jange5a93372014-07-25 13:41:14 +0900200 public static final int TIMER_RECORDING_RESULT_EXTRA_FAIL_TO_RECORD_SELECTED_SOURCE = 0x02;
Jungshik Jang12e5dce2014-07-24 15:27:44 +0900201 /** CEC is disabled. */
Jungshik Jange5a93372014-07-25 13:41:14 +0900202 public static final int TIMER_RECORDING_RESULT_EXTRA_CEC_DISABLED = 0x03;
203
204 // -- Timer cleared status data code used for result of onClearTimerRecordingResult.
205 /** Timer not cleared – recording. */
206 public static final int CLEAR_TIMER_STATUS_TIMER_NOT_CLEARED_RECORDING = 0x00;
207 /** Timer not cleared – no matching. */
208 public static final int CLEAR_TIMER_STATUS_TIMER_NOT_CLEARED_NO_MATCHING = 0x01;
209 /** Timer not cleared – no info available. */
210 public static final int CLEAR_TIMER_STATUS_TIMER_NOT_CLEARED_NO_INFO_AVAILABLE = 0x02;
211 /** Timer cleared. */
212 public static final int CLEAR_TIMER_STATUS_TIMER_CLEARED = 0x80;
213 /** Clear timer error - check recorder and connection. */
214 public static final int CLEAR_TIMER_STATUS_CHECK_RECORDER_CONNECTION = 0xA0;
215 /** Clear timer error - cannot clear timer for selected source. */
216 public static final int CLEAR_TIMER_STATUS_FAIL_TO_CLEAR_SELECTED_SOURCE = 0xA1;
217 /** Clear timer error - CEC is disabled. */
218 public static final int CLEAR_TIMER_STATUS_CEC_DISABLE = 0xA2;
Jungshik Jang12e5dce2014-07-24 15:27:44 +0900219
Jinsuk Kim78d695d2014-05-13 16:36:15 +0900220 // True if we have a logical device of type playback hosted in the system.
221 private final boolean mHasPlaybackDevice;
222 // True if we have a logical device of type TV hosted in the system.
223 private final boolean mHasTvDevice;
224
Jinsuk Kim91120c52014-05-08 17:12:51 +0900225 /**
226 * @hide - hide this constructor because it has a parameter of type
227 * IHdmiControlService, which is a system private class. The right way
228 * to create an instance of this class is using the factory
229 * Context.getSystemService.
230 */
231 public HdmiControlManager(IHdmiControlService service) {
232 mService = service;
Jinsuk Kim78d695d2014-05-13 16:36:15 +0900233 int[] types = null;
234 if (mService != null) {
235 try {
236 types = mService.getSupportedTypes();
237 } catch (RemoteException e) {
238 // Do nothing.
239 }
240 }
Jungshik Jang61f4fbd2014-08-06 19:21:12 +0900241 mHasTvDevice = hasDeviceType(types, HdmiDeviceInfo.DEVICE_TV);
242 mHasPlaybackDevice = hasDeviceType(types, HdmiDeviceInfo.DEVICE_PLAYBACK);
Jinsuk Kim78d695d2014-05-13 16:36:15 +0900243 }
244
245 private static boolean hasDeviceType(int[] types, int type) {
246 if (types == null) {
247 return false;
248 }
249 for (int t : types) {
250 if (t == type) {
251 return true;
252 }
253 }
254 return false;
Jinsuk Kim91120c52014-05-08 17:12:51 +0900255 }
256
257 /**
Jinsuk Kim6ffb0382014-08-01 19:13:53 +0900258 * Gets an object that represents an HDMI-CEC logical device of a specified type.
259 *
260 * @param type CEC device type
261 * @return {@link HdmiClient} instance. {@code null} on failure.
Jungshik Jang61f4fbd2014-08-06 19:21:12 +0900262 * See {@link HdmiDeviceInfo#DEVICE_PLAYBACK}
263 * See {@link HdmiDeviceInfo#DEVICE_TV}
Jinsuk Kim6ffb0382014-08-01 19:13:53 +0900264 */
265 @Nullable
266 public HdmiClient getClient(int type) {
267 if (mService == null) {
268 return null;
269 }
270 switch (type) {
Jungshik Jang61f4fbd2014-08-06 19:21:12 +0900271 case HdmiDeviceInfo.DEVICE_TV:
Jinsuk Kim6ffb0382014-08-01 19:13:53 +0900272 return mHasTvDevice ? new HdmiTvClient(mService) : null;
Jungshik Jang61f4fbd2014-08-06 19:21:12 +0900273 case HdmiDeviceInfo.DEVICE_PLAYBACK:
Jinsuk Kim6ffb0382014-08-01 19:13:53 +0900274 return mHasPlaybackDevice ? new HdmiPlaybackClient(mService) : null;
275 default:
276 return null;
277 }
278 }
279
280 /**
281 * Gets an object that represents an HDMI-CEC logical device of type playback on the system.
Jinsuk Kim91120c52014-05-08 17:12:51 +0900282 *
283 * <p>Used to send HDMI control messages to other devices like TV or audio amplifier through
284 * HDMI bus. It is also possible to communicate with other logical devices hosted in the same
285 * system if the system is configured to host more than one type of HDMI-CEC logical devices.
286 *
287 * @return {@link HdmiPlaybackClient} instance. {@code null} on failure.
288 */
289 @Nullable
290 public HdmiPlaybackClient getPlaybackClient() {
Jungshik Jang61f4fbd2014-08-06 19:21:12 +0900291 return (HdmiPlaybackClient) getClient(HdmiDeviceInfo.DEVICE_PLAYBACK);
Jinsuk Kim91120c52014-05-08 17:12:51 +0900292 }
293
294 /**
Jinsuk Kim6ffb0382014-08-01 19:13:53 +0900295 * Gets an object that represents an HDMI-CEC logical device of type TV on the system.
Jinsuk Kim91120c52014-05-08 17:12:51 +0900296 *
297 * <p>Used to send HDMI control messages to other devices and manage them through
298 * HDMI bus. It is also possible to communicate with other logical devices hosted in the same
299 * system if the system is configured to host more than one type of HDMI-CEC logical devices.
300 *
301 * @return {@link HdmiTvClient} instance. {@code null} on failure.
302 */
303 @Nullable
304 public HdmiTvClient getTvClient() {
Jungshik Jang61f4fbd2014-08-06 19:21:12 +0900305 return (HdmiTvClient) getClient(HdmiDeviceInfo.DEVICE_TV);
Jinsuk Kim91120c52014-05-08 17:12:51 +0900306 }
Jinsuk Kim78d695d2014-05-13 16:36:15 +0900307
308 /**
309 * Listener used to get hotplug event from HDMI port.
310 */
311 public interface HotplugEventListener {
312 void onReceived(HdmiHotplugEvent event);
313 }
314
315 /**
Jinsuk Kim119160a2014-07-07 18:48:10 +0900316 * Listener used to get vendor-specific commands.
317 */
318 public interface VendorCommandListener {
319 /**
320 * Called when a vendor command is received.
321 *
322 * @param srcAddress source logical address
323 * @param params vendor-specific parameters
324 * @param hasVendorId {@code true} if the command is &lt;Vendor Command
325 * With ID&gt;. The first 3 bytes of params is vendor id.
326 */
327 void onReceived(int srcAddress, byte[] params, boolean hasVendorId);
328 }
329
330 /**
Jinsuk Kim78d695d2014-05-13 16:36:15 +0900331 * Adds a listener to get informed of {@link HdmiHotplugEvent}.
332 *
333 * <p>To stop getting the notification,
Jinsuk Kim9302a732014-05-22 13:24:55 +0900334 * use {@link #removeHotplugEventListener(HotplugEventListener)}.
Jinsuk Kim78d695d2014-05-13 16:36:15 +0900335 *
336 * @param listener {@link HotplugEventListener} instance
Jinsuk Kim9302a732014-05-22 13:24:55 +0900337 * @see HdmiControlManager#removeHotplugEventListener(HotplugEventListener)
Jinsuk Kim78d695d2014-05-13 16:36:15 +0900338 */
339 public void addHotplugEventListener(HotplugEventListener listener) {
340 if (mService == null) {
341 return;
342 }
343 try {
344 mService.addHotplugEventListener(getHotplugEventListenerWrapper(listener));
345 } catch (RemoteException e) {
346 // Do nothing.
347 }
348 }
349
350 /**
351 * Removes a listener to stop getting informed of {@link HdmiHotplugEvent}.
352 *
353 * @param listener {@link HotplugEventListener} instance to be removed
354 */
Jinsuk Kim9302a732014-05-22 13:24:55 +0900355 public void removeHotplugEventListener(HotplugEventListener listener) {
Jinsuk Kim78d695d2014-05-13 16:36:15 +0900356 if (mService == null) {
357 return;
358 }
359 try {
360 mService.removeHotplugEventListener(getHotplugEventListenerWrapper(listener));
361 } catch (RemoteException e) {
362 // Do nothing.
363 }
364 }
365
366 private IHdmiHotplugEventListener getHotplugEventListenerWrapper(
367 final HotplugEventListener listener) {
368 return new IHdmiHotplugEventListener.Stub() {
Jungshik Jange5a93372014-07-25 13:41:14 +0900369 @Override
Jinsuk Kim78d695d2014-05-13 16:36:15 +0900370 public void onReceived(HdmiHotplugEvent event) {
371 listener.onReceived(event);;
372 }
373 };
374 }
Jinsuk Kim91120c52014-05-08 17:12:51 +0900375}