blob: 6effc0d7b07c2855a65f9a7dd187285c99f55775 [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;
Yuncheol Heo2b0da5c2014-10-22 14:32:27 +090024import android.util.ArrayMap;
25import android.util.Log;
Jinsuk Kim78d695d2014-05-13 16:36:15 +090026
Jinsuk Kim91120c52014-05-08 17:12:51 +090027/**
28 * The {@link HdmiControlManager} class is used to send HDMI control messages
29 * to attached CEC devices.
30 *
31 * <p>Provides various HDMI client instances that represent HDMI-CEC logical devices
32 * hosted in the system. {@link #getTvClient()}, for instance will return an
33 * {@link HdmiTvClient} object if the system is configured to host one. Android system
34 * can host more than one logical CEC devices. If multiple types are configured they
35 * all work as if they were independent logical devices running in the system.
Jinsuk Kim66d1eb22014-06-06 16:12:18 +090036 *
37 * @hide
Jinsuk Kim91120c52014-05-08 17:12:51 +090038 */
Jinsuk Kim66d1eb22014-06-06 16:12:18 +090039@SystemApi
Jinsuk Kim91120c52014-05-08 17:12:51 +090040public final class HdmiControlManager {
Yuncheol Heo2b0da5c2014-10-22 14:32:27 +090041 private static final String TAG = "HdmiControlManager";
42
Jinsuk Kim91120c52014-05-08 17:12:51 +090043 @Nullable private final IHdmiControlService mService;
44
Jinsuk Kimc7eba0f2014-07-07 14:18:02 +090045 /**
46 * Broadcast Action: Display OSD message.
47 * <p>Send when the service has a message to display on screen for events
48 * that need user's attention such as ARC status change.
Jungshik Jange5a93372014-07-25 13:41:14 +090049 * <p>Always contains the extra fields {@link #EXTRA_MESSAGE_ID}.
Jinsuk Kimc7eba0f2014-07-07 14:18:02 +090050 * <p>Requires {@link android.Manifest.permission#HDMI_CEC} to receive.
51 */
52 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
53 public static final String ACTION_OSD_MESSAGE = "android.hardware.hdmi.action.OSD_MESSAGE";
54
Jungshik Jang339227d2014-08-25 15:37:20 +090055 // --- Messages for ACTION_OSD_MESSAGE ---
56 /**
57 * Message that ARC enabled device is connected to invalid port (non-ARC port).
58 */
59 public static final int OSD_MESSAGE_ARC_CONNECTED_INVALID_PORT = 1;
60
Jinsuk Kimc7eba0f2014-07-07 14:18:02 +090061 /**
Jungshik Jang2e8f1b62014-09-03 08:28:02 +090062 * Message used by TV to receive volume status from Audio Receiver. It should check volume value
Yuncheol Heo2b0da5c2014-10-22 14:32:27 +090063 * that is retrieved from extra value with the key {@link #EXTRA_MESSAGE_EXTRA_PARAM1}. If the
Jungshik Jang2e8f1b62014-09-03 08:28:02 +090064 * value is in range of [0,100], it is current volume of Audio Receiver. And there is another
65 * value, {@link #AVR_VOLUME_MUTED}, which is used to inform volume mute.
66 */
67 public static final int OSD_MESSAGE_AVR_VOLUME_CHANGED = 2;
68
69 /**
Jinsuk Kimc7eba0f2014-07-07 14:18:02 +090070 * Used as an extra field in the intent {@link #ACTION_OSD_MESSAGE}. Contains the ID of
71 * the message to display on screen.
72 */
73 public static final String EXTRA_MESSAGE_ID = "android.hardware.hdmi.extra.MESSAGE_ID";
Jungshik Jang2e8f1b62014-09-03 08:28:02 +090074 /**
75 * Used as an extra field in the intent {@link #ACTION_OSD_MESSAGE}. Contains the extra value
76 * of the message.
77 */
Yuncheol Heo2b0da5c2014-10-22 14:32:27 +090078 public static final String EXTRA_MESSAGE_EXTRA_PARAM1 =
Jungshik Jang2e8f1b62014-09-03 08:28:02 +090079 "android.hardware.hdmi.extra.MESSAGE_EXTRA_PARAM1";
80
81 /**
82 * Volume value for mute state.
83 */
84 public static final int AVR_VOLUME_MUTED = 101;
Jinsuk Kimc7eba0f2014-07-07 14:18:02 +090085
Jinsuk Kimc0c20d02014-07-04 14:34:31 +090086 public static final int POWER_STATUS_UNKNOWN = -1;
87 public static final int POWER_STATUS_ON = 0;
88 public static final int POWER_STATUS_STANDBY = 1;
89 public static final int POWER_STATUS_TRANSIENT_TO_ON = 2;
90 public static final int POWER_STATUS_TRANSIENT_TO_STANDBY = 3;
91
92 public static final int RESULT_SUCCESS = 0;
93 public static final int RESULT_TIMEOUT = 1;
94 public static final int RESULT_SOURCE_NOT_AVAILABLE = 2;
95 public static final int RESULT_TARGET_NOT_AVAILABLE = 3;
Jinsuk Kimcb802872015-10-13 08:22:09 +090096
97 @Deprecated public static final int RESULT_ALREADY_IN_PROGRESS = 4;
Jinsuk Kimc0c20d02014-07-04 14:34:31 +090098 public static final int RESULT_EXCEPTION = 5;
99 public static final int RESULT_INCORRECT_MODE = 6;
Jinsuk Kimb38cd682014-07-07 08:05:03 +0900100 public static final int RESULT_COMMUNICATION_FAILED = 7;
Jinsuk Kimc0c20d02014-07-04 14:34:31 +0900101
Jungshik Jang61daf6b2014-08-08 11:38:28 +0900102 public static final int DEVICE_EVENT_ADD_DEVICE = 1;
103 public static final int DEVICE_EVENT_REMOVE_DEVICE = 2;
104 public static final int DEVICE_EVENT_UPDATE_DEVICE = 3;
105
Jungshik Jang12e5dce2014-07-24 15:27:44 +0900106 // --- One Touch Recording success result
Jungshik Jangb6591b82014-07-23 16:10:23 +0900107 /** Recording currently selected source. Indicates the status of a recording. */
Jungshik Jang12e5dce2014-07-24 15:27:44 +0900108 public static final int ONE_TOUCH_RECORD_RECORDING_CURRENTLY_SELECTED_SOURCE = 0x01;
Jungshik Jangb6591b82014-07-23 16:10:23 +0900109 /** Recording Digital Service. Indicates the status of a recording. */
Jungshik Jang12e5dce2014-07-24 15:27:44 +0900110 public static final int ONE_TOUCH_RECORD_RECORDING_DIGITAL_SERVICE = 0x02;
Jungshik Jangb6591b82014-07-23 16:10:23 +0900111 /** Recording Analogue Service. Indicates the status of a recording. */
Jungshik Jang12e5dce2014-07-24 15:27:44 +0900112 public static final int ONE_TOUCH_RECORD_RECORDING_ANALOGUE_SERVICE = 0x03;
Jungshik Jangb6591b82014-07-23 16:10:23 +0900113 /** Recording External input. Indicates the status of a recording. */
Jungshik Jang12e5dce2014-07-24 15:27:44 +0900114 public static final int ONE_TOUCH_RECORD_RECORDING_EXTERNAL_INPUT = 0x04;
115
116 // --- One Touch Record failure result
Jungshik Jangb6591b82014-07-23 16:10:23 +0900117 /** No recording – unable to record Digital Service. No suitable tuner. */
Jungshik Jang12e5dce2014-07-24 15:27:44 +0900118 public static final int ONE_TOUCH_RECORD_UNABLE_DIGITAL_SERVICE = 0x05;
Jungshik Jangb6591b82014-07-23 16:10:23 +0900119 /** No recording – unable to record Analogue Service. No suitable tuner. */
Jungshik Jang12e5dce2014-07-24 15:27:44 +0900120 public static final int ONE_TOUCH_RECORD_UNABLE_ANALOGUE_SERVICE = 0x06;
Jungshik Jangb6591b82014-07-23 16:10:23 +0900121 /**
122 * No recording – unable to select required service. as suitable tuner, but the requested
123 * parameters are invalid or out of range for that tuner.
124 */
Jungshik Jang12e5dce2014-07-24 15:27:44 +0900125 public static final int ONE_TOUCH_RECORD_UNABLE_SELECTED_SERVICE = 0x07;
Jungshik Jangb6591b82014-07-23 16:10:23 +0900126 /** No recording – invalid External plug number */
Jungshik Jang12e5dce2014-07-24 15:27:44 +0900127 public static final int ONE_TOUCH_RECORD_INVALID_EXTERNAL_PLUG_NUMBER = 0x09;
Jungshik Jangb6591b82014-07-23 16:10:23 +0900128 /** No recording – invalid External Physical Address */
Jungshik Jang12e5dce2014-07-24 15:27:44 +0900129 public static final int ONE_TOUCH_RECORD_INVALID_EXTERNAL_PHYSICAL_ADDRESS = 0x0A;
Jungshik Jangb6591b82014-07-23 16:10:23 +0900130 /** No recording – CA system not supported */
Jungshik Jang12e5dce2014-07-24 15:27:44 +0900131 public static final int ONE_TOUCH_RECORD_UNSUPPORTED_CA = 0x0B;
Jungshik Jangb6591b82014-07-23 16:10:23 +0900132 /** No Recording – No or Insufficient CA Entitlements” */
Jungshik Jang12e5dce2014-07-24 15:27:44 +0900133 public static final int ONE_TOUCH_RECORD_NO_OR_INSUFFICIENT_CA_ENTITLEMENTS = 0x0C;
Jungshik Jangb6591b82014-07-23 16:10:23 +0900134 /** No recording – Not allowed to copy source. Source is “copy never”. */
Jungshik Jang12e5dce2014-07-24 15:27:44 +0900135 public static final int ONE_TOUCH_RECORD_DISALLOW_TO_COPY = 0x0D;
Jungshik Jangb6591b82014-07-23 16:10:23 +0900136 /** No recording – No further copies allowed */
Jungshik Jang12e5dce2014-07-24 15:27:44 +0900137 public static final int ONE_TOUCH_RECORD_DISALLOW_TO_FUTHER_COPIES = 0x0E;
Jungshik Jangb6591b82014-07-23 16:10:23 +0900138 /** No recording – No media */
Jungshik Jang12e5dce2014-07-24 15:27:44 +0900139 public static final int ONE_TOUCH_RECORD_NO_MEDIA = 0x10;
Jungshik Jangb6591b82014-07-23 16:10:23 +0900140 /** No recording – playing */
Jungshik Jang12e5dce2014-07-24 15:27:44 +0900141 public static final int ONE_TOUCH_RECORD_PLAYING = 0x11;
Jungshik Jangb6591b82014-07-23 16:10:23 +0900142 /** No recording – already recording */
Jungshik Jang12e5dce2014-07-24 15:27:44 +0900143 public static final int ONE_TOUCH_RECORD_ALREADY_RECORDING = 0x12;
Jungshik Jangb6591b82014-07-23 16:10:23 +0900144 /** No recording – media protected */
Jungshik Jang12e5dce2014-07-24 15:27:44 +0900145 public static final int ONE_TOUCH_RECORD_MEDIA_PROTECTED = 0x13;
Jungshik Jangb6591b82014-07-23 16:10:23 +0900146 /** No recording – no source signal */
Jungshik Jang12e5dce2014-07-24 15:27:44 +0900147 public static final int ONE_TOUCH_RECORD_NO_SOURCE_SIGNAL = 0x14;
Jungshik Jangb6591b82014-07-23 16:10:23 +0900148 /** No recording – media problem */
Jungshik Jang12e5dce2014-07-24 15:27:44 +0900149 public static final int ONE_TOUCH_RECORD_MEDIA_PROBLEM = 0x15;
Jungshik Jangb6591b82014-07-23 16:10:23 +0900150 /** No recording – not enough space available */
Jungshik Jang12e5dce2014-07-24 15:27:44 +0900151 public static final int ONE_TOUCH_RECORD_NOT_ENOUGH_SPACE = 0x16;
Jungshik Jangb6591b82014-07-23 16:10:23 +0900152 /** No recording – Parental Lock On */
Jungshik Jang12e5dce2014-07-24 15:27:44 +0900153 public static final int ONE_TOUCH_RECORD_PARENT_LOCK_ON = 0x17;
Jungshik Jangb6591b82014-07-23 16:10:23 +0900154 /** Recording terminated normally */
Jungshik Jang12e5dce2014-07-24 15:27:44 +0900155 public static final int ONE_TOUCH_RECORD_RECORDING_TERMINATED_NORMALLY = 0x1A;
Jungshik Jangb6591b82014-07-23 16:10:23 +0900156 /** Recording has already terminated */
Jungshik Jang12e5dce2014-07-24 15:27:44 +0900157 public static final int ONE_TOUCH_RECORD_RECORDING_ALREADY_TERMINATED = 0x1B;
Jungshik Jangb6591b82014-07-23 16:10:23 +0900158 /** No recording – other reason */
Jungshik Jang12e5dce2014-07-24 15:27:44 +0900159 public static final int ONE_TOUCH_RECORD_OTHER_REASON = 0x1F;
Jungshik Jangb6591b82014-07-23 16:10:23 +0900160 // From here extra message for recording that is not mentioned in CEC spec
161 /** No recording. Previous recording request in progress. */
Jungshik Jang12e5dce2014-07-24 15:27:44 +0900162 public static final int ONE_TOUCH_RECORD_PREVIOUS_RECORDING_IN_PROGRESS = 0x30;
Jungshik Jangb6591b82014-07-23 16:10:23 +0900163 /** No recording. Please check recorder and connection. */
Jungshik Jang12e5dce2014-07-24 15:27:44 +0900164 public static final int ONE_TOUCH_RECORD_CHECK_RECORDER_CONNECTION = 0x31;
Jungshik Jangb6591b82014-07-23 16:10:23 +0900165 /** Cannot record currently displayed source. */
Jungshik Jang12e5dce2014-07-24 15:27:44 +0900166 public static final int ONE_TOUCH_RECORD_FAIL_TO_RECORD_DISPLAYED_SCREEN = 0x32;
167 /** CEC is disabled. */
168 public static final int ONE_TOUCH_RECORD_CEC_DISABLED = 0x33;
Jungshik Jangb6591b82014-07-23 16:10:23 +0900169
Jungshik Jang12e5dce2014-07-24 15:27:44 +0900170 // --- Types for timer recording
Jungshik Jangb6591b82014-07-23 16:10:23 +0900171 /** Timer recording type for digital service source. */
172 public static final int TIMER_RECORDING_TYPE_DIGITAL = 1;
173 /** Timer recording type for analogue service source. */
174 public static final int TIMER_RECORDING_TYPE_ANALOGUE = 2;
175 /** Timer recording type for external source. */
176 public static final int TIMER_RECORDING_TYPE_EXTERNAL = 3;
177
Jungshik Jange5a93372014-07-25 13:41:14 +0900178 // --- Timer Status Data
179 /** [Timer Status Data/Media Info] - Media present and not protected. */
180 public static final int TIMER_STATUS_MEDIA_INFO_PRESENT_NOT_PROTECTED = 0x0;
181 /** [Timer Status Data/Media Info] - Media present, but protected. */
182 public static final int TIMER_STATUS_MEDIA_INFO_PRESENT_PROTECTED = 0x1;
183 /** [Timer Status Data/Media Info] - Media not present. */
184 public static final int TIMER_STATUS_MEDIA_INFO_NOT_PRESENT = 0x2;
185
186 /** [Timer Status Data/Programmed Info] - Enough space available for recording. */
187 public static final int TIMER_STATUS_PROGRAMMED_INFO_ENOUGH_SPACE = 0x8;
188 /** [Timer Status Data/Programmed Info] - Not enough space available for recording. */
189 public static final int TIMER_STATUS_PROGRAMMED_INFO_NOT_ENOUGH_SPACE = 0x9;
190 /** [Timer Status Data/Programmed Info] - Might not enough space available for recording. */
191 public static final int TIMER_STATUS_PROGRAMMED_INFO_MIGHT_NOT_ENOUGH_SPACE = 0xB;
192 /** [Timer Status Data/Programmed Info] - No media info available. */
193 public static final int TIMER_STATUS_PROGRAMMED_INFO_NO_MEDIA_INFO = 0xA;
194
195 /** [Timer Status Data/Not Programmed Error Info] - No free timer available. */
196 public static final int TIMER_STATUS_NOT_PROGRAMMED_NO_FREE_TIME = 0x1;
197 /** [Timer Status Data/Not Programmed Error Info] - Date out of range. */
198 public static final int TIMER_STATUS_NOT_PROGRAMMED_DATE_OUT_OF_RANGE = 0x2;
199 /** [Timer Status Data/Not Programmed Error Info] - Recording Sequence error. */
200 public static final int TIMER_STATUS_NOT_PROGRAMMED_INVALID_SEQUENCE = 0x3;
201 /** [Timer Status Data/Not Programmed Error Info] - Invalid External Plug Number. */
202 public static final int TIMER_STATUS_NOT_PROGRAMMED_INVALID_EXTERNAL_PLUG_NUMBER = 0x4;
203 /** [Timer Status Data/Not Programmed Error Info] - Invalid External Physical Address. */
204 public static final int TIMER_STATUS_NOT_PROGRAMMED_INVALID_EXTERNAL_PHYSICAL_NUMBER = 0x5;
205 /** [Timer Status Data/Not Programmed Error Info] - CA system not supported. */
206 public static final int TIMER_STATUS_NOT_PROGRAMMED_CA_NOT_SUPPORTED = 0x6;
207 /** [Timer Status Data/Not Programmed Error Info] - No or insufficient CA Entitlements. */
208 public static final int TIMER_STATUS_NOT_PROGRAMMED_NO_CA_ENTITLEMENTS = 0x7;
209 /** [Timer Status Data/Not Programmed Error Info] - Does not support resolution. */
210 public static final int TIMER_STATUS_NOT_PROGRAMMED_UNSUPPORTED_RESOLUTION = 0x8;
211 /** [Timer Status Data/Not Programmed Error Info] - Parental Lock On. */
212 public static final int TIMER_STATUS_NOT_PROGRAMMED_PARENTAL_LOCK_ON= 0x9;
213 /** [Timer Status Data/Not Programmed Error Info] - Clock Failure. */
214 public static final int TIMER_STATUS_NOT_PROGRAMMED_CLOCK_FAILURE = 0xA;
215 /** [Timer Status Data/Not Programmed Error Info] - Duplicate: already programmed. */
216 public static final int TIMER_STATUS_NOT_PROGRAMMED_DUPLICATED = 0xE;
217
Jungshik Jang12e5dce2014-07-24 15:27:44 +0900218 // --- Extra result value for timer recording.
Jungshik Jange5a93372014-07-25 13:41:14 +0900219 /** No extra error. */
220 public static final int TIMER_RECORDING_RESULT_EXTRA_NO_ERROR = 0x00;
Jungshik Jang12e5dce2014-07-24 15:27:44 +0900221 /** No timer recording - check recorder and connection. */
Jungshik Jange5a93372014-07-25 13:41:14 +0900222 public static final int TIMER_RECORDING_RESULT_EXTRA_CHECK_RECORDER_CONNECTION = 0x01;
Jungshik Jang12e5dce2014-07-24 15:27:44 +0900223 /** No timer recording - cannot record selected source. */
Jungshik Jange5a93372014-07-25 13:41:14 +0900224 public static final int TIMER_RECORDING_RESULT_EXTRA_FAIL_TO_RECORD_SELECTED_SOURCE = 0x02;
Jungshik Jang12e5dce2014-07-24 15:27:44 +0900225 /** CEC is disabled. */
Jungshik Jange5a93372014-07-25 13:41:14 +0900226 public static final int TIMER_RECORDING_RESULT_EXTRA_CEC_DISABLED = 0x03;
227
228 // -- Timer cleared status data code used for result of onClearTimerRecordingResult.
229 /** Timer not cleared – recording. */
230 public static final int CLEAR_TIMER_STATUS_TIMER_NOT_CLEARED_RECORDING = 0x00;
231 /** Timer not cleared – no matching. */
232 public static final int CLEAR_TIMER_STATUS_TIMER_NOT_CLEARED_NO_MATCHING = 0x01;
233 /** Timer not cleared – no info available. */
234 public static final int CLEAR_TIMER_STATUS_TIMER_NOT_CLEARED_NO_INFO_AVAILABLE = 0x02;
235 /** Timer cleared. */
236 public static final int CLEAR_TIMER_STATUS_TIMER_CLEARED = 0x80;
237 /** Clear timer error - check recorder and connection. */
238 public static final int CLEAR_TIMER_STATUS_CHECK_RECORDER_CONNECTION = 0xA0;
239 /** Clear timer error - cannot clear timer for selected source. */
240 public static final int CLEAR_TIMER_STATUS_FAIL_TO_CLEAR_SELECTED_SOURCE = 0xA1;
241 /** Clear timer error - CEC is disabled. */
242 public static final int CLEAR_TIMER_STATUS_CEC_DISABLE = 0xA2;
Jungshik Jang12e5dce2014-07-24 15:27:44 +0900243
Yuncheol Heo0608b932014-10-13 16:39:18 +0900244 /** The HdmiControlService is started. */
245 public static final int CONTROL_STATE_CHANGED_REASON_START = 0;
246 /** The state of HdmiControlService is changed by changing of settings. */
247 public static final int CONTROL_STATE_CHANGED_REASON_SETTING = 1;
248 /** The HdmiControlService is enabled to wake up. */
249 public static final int CONTROL_STATE_CHANGED_REASON_WAKEUP = 2;
250 /** The HdmiControlService will be disabled to standby. */
251 public static final int CONTROL_STATE_CHANGED_REASON_STANDBY = 3;
252
Jinsuk Kim78d695d2014-05-13 16:36:15 +0900253 // True if we have a logical device of type playback hosted in the system.
254 private final boolean mHasPlaybackDevice;
255 // True if we have a logical device of type TV hosted in the system.
256 private final boolean mHasTvDevice;
257
Jinsuk Kim91120c52014-05-08 17:12:51 +0900258 /**
Yuncheol Heo2b0da5c2014-10-22 14:32:27 +0900259 * {@hide} - hide this constructor because it has a parameter of type IHdmiControlService,
260 * which is a system private class. The right way to create an instance of this class is
261 * using the factory Context.getSystemService.
Jinsuk Kim91120c52014-05-08 17:12:51 +0900262 */
263 public HdmiControlManager(IHdmiControlService service) {
264 mService = service;
Jinsuk Kim78d695d2014-05-13 16:36:15 +0900265 int[] types = null;
266 if (mService != null) {
267 try {
268 types = mService.getSupportedTypes();
269 } catch (RemoteException e) {
270 // Do nothing.
271 }
272 }
Jungshik Jang61f4fbd2014-08-06 19:21:12 +0900273 mHasTvDevice = hasDeviceType(types, HdmiDeviceInfo.DEVICE_TV);
274 mHasPlaybackDevice = hasDeviceType(types, HdmiDeviceInfo.DEVICE_PLAYBACK);
Jinsuk Kim78d695d2014-05-13 16:36:15 +0900275 }
276
277 private static boolean hasDeviceType(int[] types, int type) {
278 if (types == null) {
279 return false;
280 }
281 for (int t : types) {
282 if (t == type) {
283 return true;
284 }
285 }
286 return false;
Jinsuk Kim91120c52014-05-08 17:12:51 +0900287 }
288
289 /**
Jinsuk Kim6ffb0382014-08-01 19:13:53 +0900290 * Gets an object that represents an HDMI-CEC logical device of a specified type.
291 *
292 * @param type CEC device type
293 * @return {@link HdmiClient} instance. {@code null} on failure.
Jungshik Jang61f4fbd2014-08-06 19:21:12 +0900294 * See {@link HdmiDeviceInfo#DEVICE_PLAYBACK}
295 * See {@link HdmiDeviceInfo#DEVICE_TV}
Jinsuk Kim6ffb0382014-08-01 19:13:53 +0900296 */
297 @Nullable
298 public HdmiClient getClient(int type) {
299 if (mService == null) {
300 return null;
301 }
302 switch (type) {
Jungshik Jang61f4fbd2014-08-06 19:21:12 +0900303 case HdmiDeviceInfo.DEVICE_TV:
Jinsuk Kim6ffb0382014-08-01 19:13:53 +0900304 return mHasTvDevice ? new HdmiTvClient(mService) : null;
Jungshik Jang61f4fbd2014-08-06 19:21:12 +0900305 case HdmiDeviceInfo.DEVICE_PLAYBACK:
Jinsuk Kim6ffb0382014-08-01 19:13:53 +0900306 return mHasPlaybackDevice ? new HdmiPlaybackClient(mService) : null;
307 default:
308 return null;
309 }
310 }
311
312 /**
313 * Gets an object that represents an HDMI-CEC logical device of type playback on the system.
Jinsuk Kim91120c52014-05-08 17:12:51 +0900314 *
315 * <p>Used to send HDMI control messages to other devices like TV or audio amplifier through
316 * HDMI bus. It is also possible to communicate with other logical devices hosted in the same
317 * system if the system is configured to host more than one type of HDMI-CEC logical devices.
318 *
319 * @return {@link HdmiPlaybackClient} instance. {@code null} on failure.
320 */
321 @Nullable
322 public HdmiPlaybackClient getPlaybackClient() {
Jungshik Jang61f4fbd2014-08-06 19:21:12 +0900323 return (HdmiPlaybackClient) getClient(HdmiDeviceInfo.DEVICE_PLAYBACK);
Jinsuk Kim91120c52014-05-08 17:12:51 +0900324 }
325
326 /**
Jinsuk Kim6ffb0382014-08-01 19:13:53 +0900327 * Gets an object that represents an HDMI-CEC logical device of type TV on the system.
Jinsuk Kim91120c52014-05-08 17:12:51 +0900328 *
329 * <p>Used to send HDMI control messages to other devices and manage them through
330 * HDMI bus. It is also possible to communicate with other logical devices hosted in the same
331 * system if the system is configured to host more than one type of HDMI-CEC logical devices.
332 *
333 * @return {@link HdmiTvClient} instance. {@code null} on failure.
334 */
335 @Nullable
336 public HdmiTvClient getTvClient() {
Jungshik Jang61f4fbd2014-08-06 19:21:12 +0900337 return (HdmiTvClient) getClient(HdmiDeviceInfo.DEVICE_TV);
Jinsuk Kim91120c52014-05-08 17:12:51 +0900338 }
Jinsuk Kim78d695d2014-05-13 16:36:15 +0900339
340 /**
341 * Listener used to get hotplug event from HDMI port.
342 */
343 public interface HotplugEventListener {
344 void onReceived(HdmiHotplugEvent event);
345 }
346
Yuncheol Heo2b0da5c2014-10-22 14:32:27 +0900347 private final ArrayMap<HotplugEventListener, IHdmiHotplugEventListener>
348 mHotplugEventListeners = new ArrayMap<>();
349
Jinsuk Kim78d695d2014-05-13 16:36:15 +0900350 /**
Jinsuk Kim119160a2014-07-07 18:48:10 +0900351 * Listener used to get vendor-specific commands.
352 */
353 public interface VendorCommandListener {
354 /**
355 * Called when a vendor command is received.
356 *
357 * @param srcAddress source logical address
Yuncheol Heo0608b932014-10-13 16:39:18 +0900358 * @param destAddress destination logical address
Jinsuk Kim119160a2014-07-07 18:48:10 +0900359 * @param params vendor-specific parameters
360 * @param hasVendorId {@code true} if the command is &lt;Vendor Command
361 * With ID&gt;. The first 3 bytes of params is vendor id.
362 */
Yuncheol Heo0608b932014-10-13 16:39:18 +0900363 void onReceived(int srcAddress, int destAddress, byte[] params, boolean hasVendorId);
364
365 /**
366 * The callback is called:
367 * <ul>
368 * <li> before HdmiControlService is disabled.
369 * <li> after HdmiControlService is enabled and the local address is assigned.
370 * </ul>
371 * The client shouldn't hold the thread too long since this is a blocking call.
372 *
373 * @param enabled {@code true} if HdmiControlService is enabled.
374 * @param reason the reason code why the state of HdmiControlService is changed.
375 * @see #CONTROL_STATE_CHANGED_REASON_START
376 * @see #CONTROL_STATE_CHANGED_REASON_SETTING
377 * @see #CONTROL_STATE_CHANGED_REASON_WAKEUP
378 * @see #CONTROL_STATE_CHANGED_REASON_STANDBY
379 */
380 void onControlStateChanged(boolean enabled, int reason);
Jinsuk Kim119160a2014-07-07 18:48:10 +0900381 }
382
383 /**
Jinsuk Kim78d695d2014-05-13 16:36:15 +0900384 * Adds a listener to get informed of {@link HdmiHotplugEvent}.
385 *
386 * <p>To stop getting the notification,
Jinsuk Kim9302a732014-05-22 13:24:55 +0900387 * use {@link #removeHotplugEventListener(HotplugEventListener)}.
Jinsuk Kim78d695d2014-05-13 16:36:15 +0900388 *
389 * @param listener {@link HotplugEventListener} instance
Jinsuk Kim9302a732014-05-22 13:24:55 +0900390 * @see HdmiControlManager#removeHotplugEventListener(HotplugEventListener)
Jinsuk Kim78d695d2014-05-13 16:36:15 +0900391 */
392 public void addHotplugEventListener(HotplugEventListener listener) {
393 if (mService == null) {
Yuncheol Heo2b0da5c2014-10-22 14:32:27 +0900394 Log.e(TAG, "HdmiControlService is not available");
Jinsuk Kim78d695d2014-05-13 16:36:15 +0900395 return;
396 }
Yuncheol Heo2b0da5c2014-10-22 14:32:27 +0900397 if (mHotplugEventListeners.containsKey(listener)) {
398 Log.e(TAG, "listener is already registered");
399 return;
400 }
401 IHdmiHotplugEventListener wrappedListener = getHotplugEventListenerWrapper(listener);
402 mHotplugEventListeners.put(listener, wrappedListener);
Jinsuk Kim78d695d2014-05-13 16:36:15 +0900403 try {
Yuncheol Heo2b0da5c2014-10-22 14:32:27 +0900404 mService.addHotplugEventListener(wrappedListener);
Jinsuk Kim78d695d2014-05-13 16:36:15 +0900405 } catch (RemoteException e) {
Yuncheol Heo2b0da5c2014-10-22 14:32:27 +0900406 Log.e(TAG, "failed to add hotplug event listener: ", e);
Jinsuk Kim78d695d2014-05-13 16:36:15 +0900407 }
408 }
409
410 /**
411 * Removes a listener to stop getting informed of {@link HdmiHotplugEvent}.
412 *
413 * @param listener {@link HotplugEventListener} instance to be removed
414 */
Jinsuk Kim9302a732014-05-22 13:24:55 +0900415 public void removeHotplugEventListener(HotplugEventListener listener) {
Jinsuk Kim78d695d2014-05-13 16:36:15 +0900416 if (mService == null) {
Yuncheol Heo2b0da5c2014-10-22 14:32:27 +0900417 Log.e(TAG, "HdmiControlService is not available");
418 return;
419 }
420 IHdmiHotplugEventListener wrappedListener = mHotplugEventListeners.remove(listener);
421 if (wrappedListener == null) {
422 Log.e(TAG, "tried to remove not-registered listener");
Jinsuk Kim78d695d2014-05-13 16:36:15 +0900423 return;
424 }
425 try {
Yuncheol Heo2b0da5c2014-10-22 14:32:27 +0900426 mService.removeHotplugEventListener(wrappedListener);
Jinsuk Kim78d695d2014-05-13 16:36:15 +0900427 } catch (RemoteException e) {
Yuncheol Heo2b0da5c2014-10-22 14:32:27 +0900428 Log.e(TAG, "failed to remove hotplug event listener: ", e);
Jinsuk Kim78d695d2014-05-13 16:36:15 +0900429 }
430 }
431
432 private IHdmiHotplugEventListener getHotplugEventListenerWrapper(
433 final HotplugEventListener listener) {
434 return new IHdmiHotplugEventListener.Stub() {
Jungshik Jange5a93372014-07-25 13:41:14 +0900435 @Override
Jinsuk Kim78d695d2014-05-13 16:36:15 +0900436 public void onReceived(HdmiHotplugEvent event) {
437 listener.onReceived(event);;
438 }
439 };
440 }
Jinsuk Kim91120c52014-05-08 17:12:51 +0900441}