Debian Codegraph @

core/java/android/hardware/hdmi/HdmiControlManager.java

raw symbols SCIP
1 /*
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
17 package android.hardware.hdmi;
18
19 import android.annotation.CallbackExecutor;
20 import android.annotation.IntDef;
21 import android.annotation.NonNull;
22 import android.annotation.Nullable;
23 import android.annotation.RequiresFeature;
24 import android.annotation.RequiresPermission;
25 import android.annotation.SdkConstant;
26 import android.annotation.SdkConstant.SdkConstantType;
27 import android.annotation.StringDef;
28 import android.annotation.SuppressLint;
29 import android.annotation.SystemApi;
30 import android.annotation.SystemService;
31 import android.content.Context;
32 import android.content.pm.PackageManager;
33 import android.os.Binder;
34 import android.os.RemoteException;
35 import android.sysprop.HdmiProperties;
36 import android.util.ArrayMap;
37 import android.util.Log;
38
39 import com.android.internal.annotations.GuardedBy;
40 import com.android.internal.util.ConcurrentUtils;
41
42 import java.lang.annotation.Retention;
43 import java.lang.annotation.RetentionPolicy;
44 import java.util.ArrayList;
45 import java.util.Arrays;
46 import java.util.List;
47 import java.util.Objects;
48 import java.util.concurrent.Executor;
49 import java.util.stream.Collectors;
50
51 /**
52 * The {@link HdmiControlManager} class is used to send HDMI control messages
53 * to attached CEC devices.
54 *
55 * <p>Provides various HDMI client instances that represent HDMI-CEC logical devices
56 * hosted in the system. {@link #getTvClient()}, for instance will return an
57 * {@link HdmiTvClient} object if the system is configured to host one. Android system
58 * can host more than one logical CEC devices. If multiple types are configured they
59 * all work as if they were independent logical devices running in the system.
60 *
61 * @hide
62 */
63 @SystemApi
64 @SystemService(Context.HDMI_CONTROL_SERVICE)
65 @RequiresFeature(PackageManager.FEATURE_HDMI_CEC)
66 public final class HdmiControlManager {
67 private static final String TAG = "HdmiControlManager";
68
69 @Nullable private final IHdmiControlService mService;
70
71 private static final int INVALID_PHYSICAL_ADDRESS = 0xFFFF;
72
73 /**
74 * A cache of the current device's physical address. When device's HDMI out port
75 * is not connected to any device, it is set to {@link #INVALID_PHYSICAL_ADDRESS}.
76 *
77 * <p>Otherwise it is updated by the {@link ClientHotplugEventListener} registered
78 * with {@link com.android.server.hdmi.HdmiControlService} by the
79 * {@link #addHotplugEventListener(HotplugEventListener)} and the address is from
80 * {@link com.android.server.hdmi.HdmiControlService#getPortInfo()}
81 */
82 @GuardedBy("mLock")
83 private int mLocalPhysicalAddress = INVALID_PHYSICAL_ADDRESS;
84
85 private void setLocalPhysicalAddress(int physicalAddress) {
86 synchronized (mLock) {
87 mLocalPhysicalAddress = physicalAddress;
88 }
89 }
90
91 private int getLocalPhysicalAddress() {
92 synchronized (mLock) {
93 return mLocalPhysicalAddress;
94 }
95 }
96
97 private final Object mLock = new Object();
98
99 /**
100 * Broadcast Action: Display OSD message.
101 * <p>Send when the service has a message to display on screen for events
102 * that need user's attention such as ARC status change.
103 * <p>Always contains the extra fields {@link #EXTRA_MESSAGE_ID}.
104 * <p>Requires {@link android.Manifest.permission#HDMI_CEC} to receive.
105 */
106 @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION)
107 public static final String ACTION_OSD_MESSAGE = "android.hardware.hdmi.action.OSD_MESSAGE";
108
109 // --- Messages for ACTION_OSD_MESSAGE ---
110 /**
111 * Message that ARC enabled device is connected to invalid port (non-ARC port).
112 */
113 public static final int OSD_MESSAGE_ARC_CONNECTED_INVALID_PORT = 1;
114
115 /**
116 * Message used by TV to receive volume status from Audio Receiver. It should check volume value
117 * that is retrieved from extra value with the key {@link #EXTRA_MESSAGE_EXTRA_PARAM1}. If the
118 * value is in range of [0,100], it is current volume of Audio Receiver. And there is another
119 * value, {@link #AVR_VOLUME_MUTED}, which is used to inform volume mute.
120 */
121 public static final int OSD_MESSAGE_AVR_VOLUME_CHANGED = 2;
122
123 /**
124 * Used as an extra field in the intent {@link #ACTION_OSD_MESSAGE}. Contains the ID of
125 * the message to display on screen.
126 */
127 public static final String EXTRA_MESSAGE_ID = "android.hardware.hdmi.extra.MESSAGE_ID";
128 /**
129 * Used as an extra field in the intent {@link #ACTION_OSD_MESSAGE}. Contains the extra value
130 * of the message.
131 */
132 public static final String EXTRA_MESSAGE_EXTRA_PARAM1 =
133 "android.hardware.hdmi.extra.MESSAGE_EXTRA_PARAM1";
134
135 /**
136 * Used as an extra field in the Set Menu Language intent. Contains the requested locale.
137 * @hide
138 */
139 public static final String EXTRA_LOCALE = "android.hardware.hdmi.extra.LOCALE";
140
141 /**
142 * Volume value for mute state.
143 */
144 public static final int AVR_VOLUME_MUTED = 101;
145
146 public static final int POWER_STATUS_UNKNOWN = -1;
147 public static final int POWER_STATUS_ON = 0;
148 public static final int POWER_STATUS_STANDBY = 1;
149 public static final int POWER_STATUS_TRANSIENT_TO_ON = 2;
150 public static final int POWER_STATUS_TRANSIENT_TO_STANDBY = 3;
151
152 @IntDef ({
153 RESULT_SUCCESS,
154 RESULT_TIMEOUT,
155 RESULT_SOURCE_NOT_AVAILABLE,
156 RESULT_TARGET_NOT_AVAILABLE,
157 RESULT_ALREADY_IN_PROGRESS,
158 RESULT_EXCEPTION,
159 RESULT_INCORRECT_MODE,
160 RESULT_COMMUNICATION_FAILED,
161 })
162 public @interface ControlCallbackResult {}
163
164 /** Control operation is successfully handled by the framework. */
165 public static final int RESULT_SUCCESS = 0;
166 public static final int RESULT_TIMEOUT = 1;
167 /** Source device that the application is using is not available. */
168 public static final int RESULT_SOURCE_NOT_AVAILABLE = 2;
169 /** Target device that the application is controlling is not available. */
170 public static final int RESULT_TARGET_NOT_AVAILABLE = 3;
171
172 @Deprecated public static final int RESULT_ALREADY_IN_PROGRESS = 4;
173 public static final int RESULT_EXCEPTION = 5;
174 public static final int RESULT_INCORRECT_MODE = 6;
175 public static final int RESULT_COMMUNICATION_FAILED = 7;
176
177 public static final int DEVICE_EVENT_ADD_DEVICE = 1;
178 public static final int DEVICE_EVENT_REMOVE_DEVICE = 2;
179 public static final int DEVICE_EVENT_UPDATE_DEVICE = 3;
180
181 // --- One Touch Recording success result
182 /** Recording currently selected source. Indicates the status of a recording. */
183 public static final int ONE_TOUCH_RECORD_RECORDING_CURRENTLY_SELECTED_SOURCE = 0x01;
184 /** Recording Digital Service. Indicates the status of a recording. */
185 public static final int ONE_TOUCH_RECORD_RECORDING_DIGITAL_SERVICE = 0x02;
186 /** Recording Analogue Service. Indicates the status of a recording. */
187 public static final int ONE_TOUCH_RECORD_RECORDING_ANALOGUE_SERVICE = 0x03;
188 /** Recording External input. Indicates the status of a recording. */
189 public static final int ONE_TOUCH_RECORD_RECORDING_EXTERNAL_INPUT = 0x04;
190
191 // --- One Touch Record failure result
192 /** No recording – unable to record Digital Service. No suitable tuner. */
193 public static final int ONE_TOUCH_RECORD_UNABLE_DIGITAL_SERVICE = 0x05;
194 /** No recording – unable to record Analogue Service. No suitable tuner. */
195 public static final int ONE_TOUCH_RECORD_UNABLE_ANALOGUE_SERVICE = 0x06;
196 /**
197 * No recording – unable to select required service. as suitable tuner, but the requested
198 * parameters are invalid or out of range for that tuner.
199 */
200 public static final int ONE_TOUCH_RECORD_UNABLE_SELECTED_SERVICE = 0x07;
201 /** No recording – invalid External plug number */
202 public static final int ONE_TOUCH_RECORD_INVALID_EXTERNAL_PLUG_NUMBER = 0x09;
203 /** No recording – invalid External Physical Address */
204 public static final int ONE_TOUCH_RECORD_INVALID_EXTERNAL_PHYSICAL_ADDRESS = 0x0A;
205 /** No recording – CA system not supported */
206 public static final int ONE_TOUCH_RECORD_UNSUPPORTED_CA = 0x0B;
207 /** No Recording – No or Insufficient CA Entitlements” */
208 public static final int ONE_TOUCH_RECORD_NO_OR_INSUFFICIENT_CA_ENTITLEMENTS = 0x0C;
209 /** No recording – Not allowed to copy source. Source is “copy never”. */
210 public static final int ONE_TOUCH_RECORD_DISALLOW_TO_COPY = 0x0D;
211 /** No recording – No further copies allowed */
212 public static final int ONE_TOUCH_RECORD_DISALLOW_TO_FUTHER_COPIES = 0x0E;
213 /** No recording – No media */
214 public static final int ONE_TOUCH_RECORD_NO_MEDIA = 0x10;
215 /** No recording – playing */
216 public static final int ONE_TOUCH_RECORD_PLAYING = 0x11;
217 /** No recording – already recording */
218 public static final int ONE_TOUCH_RECORD_ALREADY_RECORDING = 0x12;
219 /** No recording – media protected */
220 public static final int ONE_TOUCH_RECORD_MEDIA_PROTECTED = 0x13;
221 /** No recording – no source signal */
222 public static final int ONE_TOUCH_RECORD_NO_SOURCE_SIGNAL = 0x14;
223 /** No recording – media problem */
224 public static final int ONE_TOUCH_RECORD_MEDIA_PROBLEM = 0x15;
225 /** No recording – not enough space available */
226 public static final int ONE_TOUCH_RECORD_NOT_ENOUGH_SPACE = 0x16;
227 /** No recording – Parental Lock On */
228 public static final int ONE_TOUCH_RECORD_PARENT_LOCK_ON = 0x17;
229 /** Recording terminated normally */
230 public static final int ONE_TOUCH_RECORD_RECORDING_TERMINATED_NORMALLY = 0x1A;
231 /** Recording has already terminated */
232 public static final int ONE_TOUCH_RECORD_RECORDING_ALREADY_TERMINATED = 0x1B;
233 /** No recording – other reason */
234 public static final int ONE_TOUCH_RECORD_OTHER_REASON = 0x1F;
235 // From here extra message for recording that is not mentioned in CEC spec
236 /** No recording. Previous recording request in progress. */
237 public static final int ONE_TOUCH_RECORD_PREVIOUS_RECORDING_IN_PROGRESS = 0x30;
238 /** No recording. Please check recorder and connection. */
239 public static final int ONE_TOUCH_RECORD_CHECK_RECORDER_CONNECTION = 0x31;
240 /** Cannot record currently displayed source. */
241 public static final int ONE_TOUCH_RECORD_FAIL_TO_RECORD_DISPLAYED_SCREEN = 0x32;
242 /** CEC is disabled. */
243 public static final int ONE_TOUCH_RECORD_CEC_DISABLED = 0x33;
244
245 // --- Types for timer recording
246 /** Timer recording type for digital service source. */
247 public static final int TIMER_RECORDING_TYPE_DIGITAL = 1;
248 /** Timer recording type for analogue service source. */
249 public static final int TIMER_RECORDING_TYPE_ANALOGUE = 2;
250 /** Timer recording type for external source. */
251 public static final int TIMER_RECORDING_TYPE_EXTERNAL = 3;
252
253 // --- Timer Status Data
254 /** [Timer Status Data/Media Info] - Media present and not protected. */
255 public static final int TIMER_STATUS_MEDIA_INFO_PRESENT_NOT_PROTECTED = 0x0;
256 /** [Timer Status Data/Media Info] - Media present, but protected. */
257 public static final int TIMER_STATUS_MEDIA_INFO_PRESENT_PROTECTED = 0x1;
258 /** [Timer Status Data/Media Info] - Media not present. */
259 public static final int TIMER_STATUS_MEDIA_INFO_NOT_PRESENT = 0x2;
260
261 /** [Timer Status Data/Programmed Info] - Enough space available for recording. */
262 public static final int TIMER_STATUS_PROGRAMMED_INFO_ENOUGH_SPACE = 0x8;
263 /** [Timer Status Data/Programmed Info] - Not enough space available for recording. */
264 public static final int TIMER_STATUS_PROGRAMMED_INFO_NOT_ENOUGH_SPACE = 0x9;
265 /** [Timer Status Data/Programmed Info] - Might not enough space available for recording. */
266 public static final int TIMER_STATUS_PROGRAMMED_INFO_MIGHT_NOT_ENOUGH_SPACE = 0xB;
267 /** [Timer Status Data/Programmed Info] - No media info available. */
268 public static final int TIMER_STATUS_PROGRAMMED_INFO_NO_MEDIA_INFO = 0xA;
269
270 /** [Timer Status Data/Not Programmed Error Info] - No free timer available. */
271 public static final int TIMER_STATUS_NOT_PROGRAMMED_NO_FREE_TIME = 0x1;
272 /** [Timer Status Data/Not Programmed Error Info] - Date out of range. */
273 public static final int TIMER_STATUS_NOT_PROGRAMMED_DATE_OUT_OF_RANGE = 0x2;
274 /** [Timer Status Data/Not Programmed Error Info] - Recording Sequence error. */
275 public static final int TIMER_STATUS_NOT_PROGRAMMED_INVALID_SEQUENCE = 0x3;
276 /** [Timer Status Data/Not Programmed Error Info] - Invalid External Plug Number. */
277 public static final int TIMER_STATUS_NOT_PROGRAMMED_INVALID_EXTERNAL_PLUG_NUMBER = 0x4;
278 /** [Timer Status Data/Not Programmed Error Info] - Invalid External Physical Address. */
279 public static final int TIMER_STATUS_NOT_PROGRAMMED_INVALID_EXTERNAL_PHYSICAL_NUMBER = 0x5;
280 /** [Timer Status Data/Not Programmed Error Info] - CA system not supported. */
281 public static final int TIMER_STATUS_NOT_PROGRAMMED_CA_NOT_SUPPORTED = 0x6;
282 /** [Timer Status Data/Not Programmed Error Info] - No or insufficient CA Entitlements. */
283 public static final int TIMER_STATUS_NOT_PROGRAMMED_NO_CA_ENTITLEMENTS = 0x7;
284 /** [Timer Status Data/Not Programmed Error Info] - Does not support resolution. */
285 public static final int TIMER_STATUS_NOT_PROGRAMMED_UNSUPPORTED_RESOLUTION = 0x8;
286 /** [Timer Status Data/Not Programmed Error Info] - Parental Lock On. */
287 public static final int TIMER_STATUS_NOT_PROGRAMMED_PARENTAL_LOCK_ON= 0x9;
288 /** [Timer Status Data/Not Programmed Error Info] - Clock Failure. */
289 public static final int TIMER_STATUS_NOT_PROGRAMMED_CLOCK_FAILURE = 0xA;
290 /** [Timer Status Data/Not Programmed Error Info] - Duplicate: already programmed. */
291 public static final int TIMER_STATUS_NOT_PROGRAMMED_DUPLICATED = 0xE;
292
293 // --- Extra result value for timer recording.
294 /** No extra error. */
295 public static final int TIMER_RECORDING_RESULT_EXTRA_NO_ERROR = 0x00;
296 /** No timer recording - check recorder and connection. */
297 public static final int TIMER_RECORDING_RESULT_EXTRA_CHECK_RECORDER_CONNECTION = 0x01;
298 /** No timer recording - cannot record selected source. */
299 public static final int TIMER_RECORDING_RESULT_EXTRA_FAIL_TO_RECORD_SELECTED_SOURCE = 0x02;
300 /** CEC is disabled. */
301 public static final int TIMER_RECORDING_RESULT_EXTRA_CEC_DISABLED = 0x03;
302
303 // -- Timer cleared status data code used for result of onClearTimerRecordingResult.
304 /** Timer not cleared – recording. */
305 public static final int CLEAR_TIMER_STATUS_TIMER_NOT_CLEARED_RECORDING = 0x00;
306 /** Timer not cleared – no matching. */
307 public static final int CLEAR_TIMER_STATUS_TIMER_NOT_CLEARED_NO_MATCHING = 0x01;
308 /** Timer not cleared – no info available. */
309 public static final int CLEAR_TIMER_STATUS_TIMER_NOT_CLEARED_NO_INFO_AVAILABLE = 0x02;
310 /** Timer cleared. */
311 public static final int CLEAR_TIMER_STATUS_TIMER_CLEARED = 0x80;
312 /** Clear timer error - check recorder and connection. */
313 public static final int CLEAR_TIMER_STATUS_CHECK_RECORDER_CONNECTION = 0xA0;
314 /** Clear timer error - cannot clear timer for selected source. */
315 public static final int CLEAR_TIMER_STATUS_FAIL_TO_CLEAR_SELECTED_SOURCE = 0xA1;
316 /** Clear timer error - CEC is disabled. */
317 public static final int CLEAR_TIMER_STATUS_CEC_DISABLE = 0xA2;
318
319 /** The HdmiControlService is started. */
320 public static final int CONTROL_STATE_CHANGED_REASON_START = 0;
321 /** The state of HdmiControlService is changed by changing of settings. */
322 public static final int CONTROL_STATE_CHANGED_REASON_SETTING = 1;
323 /** The HdmiControlService is enabled to wake up. */
324 public static final int CONTROL_STATE_CHANGED_REASON_WAKEUP = 2;
325 /** The HdmiControlService will be disabled to standby. */
326 public static final int CONTROL_STATE_CHANGED_REASON_STANDBY = 3;
327
328 // -- Whether the HDMI CEC is enabled or disabled.
329 /**
330 * HDMI CEC enabled.
331 *
332 * @see HdmiControlManager#CEC_SETTING_NAME_HDMI_CEC_ENABLED
333 */
334 public static final int HDMI_CEC_CONTROL_ENABLED = 1;
335 /**
336 * HDMI CEC disabled.
337 *
338 * @see HdmiControlManager#CEC_SETTING_NAME_HDMI_CEC_ENABLED
339 */
340 public static final int HDMI_CEC_CONTROL_DISABLED = 0;
341 /**
342 * @hide
343 *
344 * @see HdmiControlManager#CEC_SETTING_NAME_HDMI_CEC_ENABLED
345 */
346 @IntDef(prefix = { "HDMI_CEC_CONTROL_" }, value = {
347 HDMI_CEC_CONTROL_ENABLED,
348 HDMI_CEC_CONTROL_DISABLED
349 })
350 @Retention(RetentionPolicy.SOURCE)
351 public @interface HdmiCecControl {}
352
353 // -- Supported HDMI-CEC versions.
354 /**
355 * Version constant for HDMI-CEC v1.4b.
356 *
357 * @see HdmiControlManager#CEC_SETTING_NAME_HDMI_CEC_VERSION
358 */
359 public static final int HDMI_CEC_VERSION_1_4_B = 0x05;
360 /**
361 * Version constant for HDMI-CEC v2.0.
362 *
363 * @see HdmiControlManager#CEC_SETTING_NAME_HDMI_CEC_VERSION
364 */
365 public static final int HDMI_CEC_VERSION_2_0 = 0x06;
366 /**
367 * @see HdmiControlManager#CEC_SETTING_NAME_HDMI_CEC_VERSION
368 * @hide
369 */
370 @IntDef(prefix = { "HDMI_CEC_VERSION_" }, value = {
371 HDMI_CEC_VERSION_1_4_B,
372 HDMI_CEC_VERSION_2_0
373 })
374 @Retention(RetentionPolicy.SOURCE)
375 public @interface HdmiCecVersion {}
376
377 // -- Whether the Routing Control feature is enabled or disabled.
378 /**
379 * Routing Control feature enabled.
380 *
381 * @see HdmiControlManager#CEC_SETTING_NAME_ROUTING_CONTROL
382 */
383 public static final int ROUTING_CONTROL_ENABLED = 1;
384 /**
385 * Routing Control feature disabled.
386 *
387 * @see HdmiControlManager#CEC_SETTING_NAME_ROUTING_CONTROL
388 */
389 public static final int ROUTING_CONTROL_DISABLED = 0;
390 /**
391 * @see HdmiControlManager#CEC_SETTING_NAME_ROUTING_CONTROL
392 * @hide
393 */
394 @IntDef(prefix = { "ROUTING_CONTROL_" }, value = {
395 ROUTING_CONTROL_ENABLED,
396 ROUTING_CONTROL_DISABLED
397 })
398 @Retention(RetentionPolicy.SOURCE)
399 public @interface RoutingControl {}
400
401 // -- Scope of CEC power control messages sent by a playback device.
402 /**
403 * Send CEC power control messages to TV only:
404 * Upon going to sleep, send {@code <Standby>} to TV only.
405 * Upon waking up, attempt to turn on the TV via {@code <One Touch Play>} but do not turn on the
406 * Audio system via {@code <System Audio Mode Request>}.
407 *
408 * @see HdmiControlManager#CEC_SETTING_NAME_POWER_CONTROL_MODE
409 */
410 public static final String POWER_CONTROL_MODE_TV = "to_tv";
411 /**
412 * Send CEC power control messages to TV and Audio System:
413 * Upon going to sleep, send {@code <Standby>} to TV and Audio system.
414 * Upon waking up, attempt to turn on the TV via {@code <One Touch Play>} and attempt to turn on
415 * the Audio system via {@code <System Audio Mode Request>}.
416 *
417 * @see HdmiControlManager#CEC_SETTING_NAME_POWER_CONTROL_MODE
418 */
419 public static final String POWER_CONTROL_MODE_TV_AND_AUDIO_SYSTEM = "to_tv_and_audio_system";
420 /**
421 * Broadcast CEC power control messages to all devices in the network:
422 * Upon going to sleep, send {@code <Standby>} to all devices in the network.
423 * Upon waking up, attempt to turn on the TV via {@code <One Touch Play>} and attempt to turn on
424 * the Audio system via {@code <System Audio Mode Request>}.
425 *
426 * @see HdmiControlManager#CEC_SETTING_NAME_POWER_CONTROL_MODE
427 */
428 public static final String POWER_CONTROL_MODE_BROADCAST = "broadcast";
429 /**
430 * Don't send any CEC power control messages:
431 * Upon going to sleep, do not send any {@code <Standby>} message.
432 * Upon waking up, do not turn on the TV via {@code <One Touch Play>} and do not turn on the
433 * Audio system via {@code <System Audio Mode Request>}.
434 *
435 * @see HdmiControlManager#CEC_SETTING_NAME_POWER_CONTROL_MODE
436 */
437 public static final String POWER_CONTROL_MODE_NONE = "none";
438 /**
439 * @see HdmiControlManager#CEC_SETTING_NAME_POWER_CONTROL_MODE
440 * @hide
441 */
442 @StringDef(prefix = { "POWER_CONTROL_MODE_" }, value = {
443 POWER_CONTROL_MODE_TV,
444 POWER_CONTROL_MODE_TV_AND_AUDIO_SYSTEM,
445 POWER_CONTROL_MODE_BROADCAST,
446 POWER_CONTROL_MODE_NONE
447 })
448 @Retention(RetentionPolicy.SOURCE)
449 public @interface PowerControlMode {}
450
451 // -- Which power state action should be taken when Active Source is lost.
452 /**
453 * No action to be taken.
454 *
455 * @see HdmiControlManager#CEC_SETTING_NAME_POWER_STATE_CHANGE_ON_ACTIVE_SOURCE_LOST
456 */
457 public static final String POWER_STATE_CHANGE_ON_ACTIVE_SOURCE_LOST_NONE = "none";
458 /**
459 * Go to standby immediately.
460 *
461 * @see HdmiControlManager#CEC_SETTING_NAME_POWER_STATE_CHANGE_ON_ACTIVE_SOURCE_LOST
462 */
463 public static final String POWER_STATE_CHANGE_ON_ACTIVE_SOURCE_LOST_STANDBY_NOW = "standby_now";
464 /**
465 * @see HdmiControlManager#CEC_SETTING_NAME_POWER_STATE_CHANGE_ON_ACTIVE_SOURCE_LOST
466 * @hide
467 */
468 @StringDef(prefix = { "POWER_STATE_CHANGE_ON_ACTIVE_SOURCE_LOST_" }, value = {
469 POWER_STATE_CHANGE_ON_ACTIVE_SOURCE_LOST_NONE,
470 POWER_STATE_CHANGE_ON_ACTIVE_SOURCE_LOST_STANDBY_NOW
471 })
472 @Retention(RetentionPolicy.SOURCE)
473 public @interface ActiveSourceLostBehavior {}
474
475 // -- Whether System Audio Control is enabled or disabled.
476 /**
477 * System Audio Control enabled.
478 *
479 * @see HdmiControlManager#CEC_SETTING_NAME_SYSTEM_AUDIO_CONTROL
480 */
481 public static final int SYSTEM_AUDIO_CONTROL_ENABLED = 1;
482 /**
483 * System Audio Control disabled.
484 *
485 * @see HdmiControlManager#CEC_SETTING_NAME_SYSTEM_AUDIO_CONTROL
486 */
487 public static final int SYSTEM_AUDIO_CONTROL_DISABLED = 0;
488 /**
489 * @see HdmiControlManager#CEC_SETTING_NAME_SYSTEM_AUDIO_CONTROL
490 * @hide
491 */
492 @IntDef(prefix = { "SYSTEM_AUDIO_CONTROL_" }, value = {
493 SYSTEM_AUDIO_CONTROL_ENABLED,
494 SYSTEM_AUDIO_CONTROL_DISABLED
495 })
496 @Retention(RetentionPolicy.SOURCE)
497 public @interface SystemAudioControl {}
498
499 // -- Whether System Audio Mode muting is enabled or disabled.
500 /**
501 * System Audio Mode muting enabled.
502 *
503 * @see HdmiControlManager#CEC_SETTING_NAME_SYSTEM_AUDIO_MODE_MUTING
504 */
505 public static final int SYSTEM_AUDIO_MODE_MUTING_ENABLED = 1;
506 /**
507 * System Audio Mode muting disabled.
508 *
509 * @see HdmiControlManager#CEC_SETTING_NAME_SYSTEM_AUDIO_MODE_MUTING
510 */
511 public static final int SYSTEM_AUDIO_MODE_MUTING_DISABLED = 0;
512 /**
513 * @see HdmiControlManager#CEC_SETTING_NAME_SYSTEM_AUDIO_MODE_MUTING
514 * @hide
515 */
516 @IntDef(prefix = { "SYSTEM_AUDIO_MODE_MUTING_" }, value = {
517 SYSTEM_AUDIO_MODE_MUTING_ENABLED,
518 SYSTEM_AUDIO_MODE_MUTING_DISABLED
519 })
520 @Retention(RetentionPolicy.SOURCE)
521 public @interface SystemAudioModeMuting {}
522
523 // -- Whether the HDMI CEC volume control is enabled or disabled.
524 /**
525 * HDMI CEC enabled.
526 *
527 * @see HdmiControlManager#CEC_SETTING_NAME_VOLUME_CONTROL_MODE
528 */
529 public static final int VOLUME_CONTROL_ENABLED = 1;
530 /**
531 * HDMI CEC disabled.
532 *
533 * @see HdmiControlManager#CEC_SETTING_NAME_VOLUME_CONTROL_MODE
534 */
535 public static final int VOLUME_CONTROL_DISABLED = 0;
536 /**
537 * @see HdmiControlManager#CEC_SETTING_NAME_VOLUME_CONTROL_MODE
538 * @hide
539 */
540 @IntDef(prefix = { "VOLUME_CONTROL_" }, value = {
541 VOLUME_CONTROL_ENABLED,
542 VOLUME_CONTROL_DISABLED
543 })
544 @Retention(RetentionPolicy.SOURCE)
545 public @interface VolumeControl {}
546
547 // -- Whether TV Wake on One Touch Play is enabled or disabled.
548 /**
549 * TV Wake on One Touch Play enabled.
550 *
551 * @see HdmiControlManager#CEC_SETTING_NAME_TV_WAKE_ON_ONE_TOUCH_PLAY
552 */
553 public static final int TV_WAKE_ON_ONE_TOUCH_PLAY_ENABLED = 1;
554 /**
555 * TV Wake on One Touch Play disabled.
556 *
557 * @see HdmiControlManager#CEC_SETTING_NAME_TV_WAKE_ON_ONE_TOUCH_PLAY
558 */
559 public static final int TV_WAKE_ON_ONE_TOUCH_PLAY_DISABLED = 0;
560 /**
561 * @see HdmiControlManager#CEC_SETTING_NAME_TV_WAKE_ON_ONE_TOUCH_PLAY
562 * @hide
563 */
564 @IntDef(prefix = { "TV_WAKE_ON_ONE_TOUCH_PLAY_" }, value = {
565 TV_WAKE_ON_ONE_TOUCH_PLAY_ENABLED,
566 TV_WAKE_ON_ONE_TOUCH_PLAY_DISABLED
567 })
568 @Retention(RetentionPolicy.SOURCE)
569 public @interface TvWakeOnOneTouchPlay {}
570
571 // -- Whether TV should send &lt;Standby&gt; on sleep.
572 /**
573 * Sending &lt;Standby&gt; on sleep.
574 *
575 * @see HdmiControlManager#CEC_SETTING_NAME_TV_SEND_STANDBY_ON_SLEEP
576 */
577 public static final int TV_SEND_STANDBY_ON_SLEEP_ENABLED = 1;
578 /**
579 * Not sending &lt;Standby&gt; on sleep.
580 *
581 * @see HdmiControlManager#CEC_SETTING_NAME_TV_SEND_STANDBY_ON_SLEEP
582 */
583 public static final int TV_SEND_STANDBY_ON_SLEEP_DISABLED = 0;
584 /**
585 * @see HdmiControlManager#CEC_SETTING_NAME_TV_SEND_STANDBY_ON_SLEEP
586 * @hide
587 */
588 @IntDef(prefix = { "TV_SEND_STANDBY_ON_SLEEP_" }, value = {
589 TV_SEND_STANDBY_ON_SLEEP_ENABLED,
590 TV_SEND_STANDBY_ON_SLEEP_DISABLED
591 })
592 @Retention(RetentionPolicy.SOURCE)
593 public @interface TvSendStandbyOnSleep {}
594
595 // -- Whether a playback device should act on an incoming {@code <Set Menu Language>} message.
596 /**
597 * Confirmation dialog should be shown upon receiving the CEC message.
598 *
599 * @see HdmiControlManager#CEC_SETTING_NAME_SET_MENU_LANGUAGE
600 * @hide
601 */
602 public static final int SET_MENU_LANGUAGE_ENABLED = 1;
603 /**
604 * The message should be ignored.
605 *
606 * @see HdmiControlManager#CEC_SETTING_NAME_SET_MENU_LANGUAGE
607 * @hide
608 */
609 public static final int SET_MENU_LANGUAGE_DISABLED = 0;
610 /**
611 * @see HdmiControlManager#CEC_SETTING_NAME_SET_MENU_LANGUAGE
612 * @hide
613 */
614 @IntDef(prefix = { "SET_MENU_LANGUAGE_" }, value = {
615 SET_MENU_LANGUAGE_ENABLED,
616 SET_MENU_LANGUAGE_DISABLED
617 })
618 @Retention(RetentionPolicy.SOURCE)
619 public @interface SetMenuLanguage {}
620
621 // -- The RC profile of a TV panel.
622 /**
623 * RC profile none.
624 *
625 * @see HdmiControlManager#CEC_SETTING_NAME_RC_PROFILE_TV
626 * @hide
627 */
628 public static final int RC_PROFILE_TV_NONE = 0x0;
629 /**
630 * RC profile 1.
631 *
632 * @see HdmiControlManager#CEC_SETTING_NAME_RC_PROFILE_TV
633 * @hide
634 */
635 public static final int RC_PROFILE_TV_ONE = 0x2;
636 /**
637 * RC profile 2.
638 *
639 * @see HdmiControlManager#CEC_SETTING_NAME_RC_PROFILE_TV
640 * @hide
641 */
642 public static final int RC_PROFILE_TV_TWO = 0x6;
643 /**
644 * RC profile 3.
645 *
646 * @see HdmiControlManager#CEC_SETTING_NAME_RC_PROFILE_TV
647 * @hide
648 */
649 public static final int RC_PROFILE_TV_THREE = 0xA;
650 /**
651 * RC profile 4.
652 *
653 * @see HdmiControlManager#CEC_SETTING_NAME_RC_PROFILE_TV
654 * @hide
655 */
656 public static final int RC_PROFILE_TV_FOUR = 0xE;
657 /**
658 * @see HdmiControlManager#CEC_SETTING_NAME_RC_PROFILE_TV
659 * @hide
660 */
661 @IntDef(prefix = { "RC_PROFILE_TV_" }, value = {
662 RC_PROFILE_TV_NONE,
663 RC_PROFILE_TV_ONE,
664 RC_PROFILE_TV_TWO,
665 RC_PROFILE_TV_THREE,
666 RC_PROFILE_TV_FOUR
667 })
668 @Retention(RetentionPolicy.SOURCE)
669 public @interface RcProfileTv {}
670
671 // -- RC profile parameter defining if a source handles a specific menu.
672 /**
673 * Handles the menu.
674 *
675 * @see HdmiControlManager#CEC_SETTING_NAME_RC_PROFILE_SOURCE_HANDLES_ROOT_MENU
676 * @see HdmiControlManager#CEC_SETTING_NAME_RC_PROFILE_SOURCE_HANDLES_SETUP_MENU
677 * @see HdmiControlManager#CEC_SETTING_NAME_RC_PROFILE_SOURCE_HANDLES_CONTENTS_MENU
678 * @see HdmiControlManager#CEC_SETTING_NAME_RC_PROFILE_SOURCE_HANDLES_TOP_MENU
679 * @see HdmiControlManager#
680 * CEC_SETTING_NAME_RC_PROFILE_SOURCE_HANDLES_MEDIA_CONTEXT_SENSITIVE_MENU
681 * @hide
682 */
683 public static final int RC_PROFILE_SOURCE_MENU_HANDLED = 1;
684 /**
685 * Doesn't handle the menu.
686 *
687 * @see HdmiControlManager#CEC_SETTING_NAME_RC_PROFILE_SOURCE_HANDLES_ROOT_MENU
688 * @see HdmiControlManager#CEC_SETTING_NAME_RC_PROFILE_SOURCE_HANDLES_SETUP_MENU
689 * @see HdmiControlManager#CEC_SETTING_NAME_RC_PROFILE_SOURCE_HANDLES_CONTENTS_MENU
690 * @see HdmiControlManager#CEC_SETTING_NAME_RC_PROFILE_SOURCE_HANDLES_TOP_MENU
691 * @see HdmiControlManager#
692 * CEC_SETTING_NAME_RC_PROFILE_SOURCE_HANDLES_MEDIA_CONTEXT_SENSITIVE_MENU
693 * @hide
694 */
695 public static final int RC_PROFILE_SOURCE_MENU_NOT_HANDLED = 0;
696 /**
697 * @see HdmiControlManager#CEC_SETTING_NAME_RC_PROFILE_SOURCE_HANDLES_ROOT_MENU
698 * @see HdmiControlManager#CEC_SETTING_NAME_RC_PROFILE_SOURCE_HANDLES_SETUP_MENU
699 * @see HdmiControlManager#CEC_SETTING_NAME_RC_PROFILE_SOURCE_HANDLES_CONTENTS_MENU
700 * @see HdmiControlManager#CEC_SETTING_NAME_RC_PROFILE_SOURCE_HANDLES_TOP_MENU
701 * @see HdmiControlManager#
702 * CEC_SETTING_NAME_RC_PROFILE_SOURCE_HANDLES_MEDIA_CONTEXT_SENSITIVE_MENU
703 * @hide
704 */
705 @IntDef(prefix = { "RC_PROFILE_SOURCE_MENU_" }, value = {
706 RC_PROFILE_SOURCE_MENU_HANDLED,
707 RC_PROFILE_SOURCE_MENU_NOT_HANDLED
708 })
709 @Retention(RetentionPolicy.SOURCE)
710 public @interface RcProfileSourceHandlesMenu {}
711
712 // -- Whether the Short Audio Descriptor (SAD) for a specific codec should be queried or not.
713 /**
714 * Query the SAD.
715 *
716 * @see HdmiControlManager#CEC_SETTING_NAME_QUERY_SAD_LPCM
717 * @see HdmiControlManager#CEC_SETTING_NAME_QUERY_SAD_DD
718 * @see HdmiControlManager#CEC_SETTING_NAME_QUERY_SAD_MPEG1
719 * @see HdmiControlManager#CEC_SETTING_NAME_QUERY_SAD_MP3
720 * @see HdmiControlManager#CEC_SETTING_NAME_QUERY_SAD_MPEG2
721 * @see HdmiControlManager#CEC_SETTING_NAME_QUERY_SAD_AAC
722 * @see HdmiControlManager#CEC_SETTING_NAME_QUERY_SAD_DTS
723 * @see HdmiControlManager#CEC_SETTING_NAME_QUERY_SAD_ATRAC
724 * @see HdmiControlManager#CEC_SETTING_NAME_QUERY_SAD_ONEBITAUDIO
725 * @see HdmiControlManager#CEC_SETTING_NAME_QUERY_SAD_DDP
726 * @see HdmiControlManager#CEC_SETTING_NAME_QUERY_SAD_DTSHD
727 * @see HdmiControlManager#CEC_SETTING_NAME_QUERY_SAD_TRUEHD
728 * @see HdmiControlManager#CEC_SETTING_NAME_QUERY_SAD_DST
729 * @see HdmiControlManager#CEC_SETTING_NAME_QUERY_SAD_WMAPRO
730 * @see HdmiControlManager#CEC_SETTING_NAME_QUERY_SAD_MAX
731 */
732 public static final int QUERY_SAD_ENABLED = 1;
733 /**
734 * Don't query the SAD.
735 *
736 * @see HdmiControlManager#CEC_SETTING_NAME_QUERY_SAD_LPCM
737 * @see HdmiControlManager#CEC_SETTING_NAME_QUERY_SAD_DD
738 * @see HdmiControlManager#CEC_SETTING_NAME_QUERY_SAD_MPEG1
739 * @see HdmiControlManager#CEC_SETTING_NAME_QUERY_SAD_MP3
740 * @see HdmiControlManager#CEC_SETTING_NAME_QUERY_SAD_MPEG2
741 * @see HdmiControlManager#CEC_SETTING_NAME_QUERY_SAD_AAC
742 * @see HdmiControlManager#CEC_SETTING_NAME_QUERY_SAD_DTS
743 * @see HdmiControlManager#CEC_SETTING_NAME_QUERY_SAD_ATRAC
744 * @see HdmiControlManager#CEC_SETTING_NAME_QUERY_SAD_ONEBITAUDIO
745 * @see HdmiControlManager#CEC_SETTING_NAME_QUERY_SAD_DDP
746 * @see HdmiControlManager#CEC_SETTING_NAME_QUERY_SAD_DTSHD
747 * @see HdmiControlManager#CEC_SETTING_NAME_QUERY_SAD_TRUEHD
748 * @see HdmiControlManager#CEC_SETTING_NAME_QUERY_SAD_DST
749 * @see HdmiControlManager#CEC_SETTING_NAME_QUERY_SAD_WMAPRO
750 * @see HdmiControlManager#CEC_SETTING_NAME_QUERY_SAD_MAX
751 */
752 public static final int QUERY_SAD_DISABLED = 0;
753 /**
754 * @see HdmiControlManager#CEC_SETTING_NAME_QUERY_SAD_LPCM
755 * @see HdmiControlManager#CEC_SETTING_NAME_QUERY_SAD_DD
756 * @see HdmiControlManager#CEC_SETTING_NAME_QUERY_SAD_MPEG1
757 * @see HdmiControlManager#CEC_SETTING_NAME_QUERY_SAD_MP3
758 * @see HdmiControlManager#CEC_SETTING_NAME_QUERY_SAD_MPEG2
759 * @see HdmiControlManager#CEC_SETTING_NAME_QUERY_SAD_AAC
760 * @see HdmiControlManager#CEC_SETTING_NAME_QUERY_SAD_DTS
761 * @see HdmiControlManager#CEC_SETTING_NAME_QUERY_SAD_ATRAC
762 * @see HdmiControlManager#CEC_SETTING_NAME_QUERY_SAD_ONEBITAUDIO
763 * @see HdmiControlManager#CEC_SETTING_NAME_QUERY_SAD_DDP
764 * @see HdmiControlManager#CEC_SETTING_NAME_QUERY_SAD_DTSHD
765 * @see HdmiControlManager#CEC_SETTING_NAME_QUERY_SAD_TRUEHD
766 * @see HdmiControlManager#CEC_SETTING_NAME_QUERY_SAD_DST
767 * @see HdmiControlManager#CEC_SETTING_NAME_QUERY_SAD_WMAPRO
768 * @see HdmiControlManager#CEC_SETTING_NAME_QUERY_SAD_MAX
769 * @hide
770 */
771 @IntDef(prefix = { "QUERY_SAD_" }, value = {
772 QUERY_SAD_ENABLED,
773 QUERY_SAD_DISABLED
774 })
775 @Retention(RetentionPolicy.SOURCE)
776 public @interface SadPresenceInQuery {}
777
778 // -- Settings available in the CEC Configuration.
779 /**
780 * Name of a setting deciding whether the CEC is enabled.
781 *
782 * @see HdmiControlManager#setHdmiCecEnabled(int)
783 */
784 public static final String CEC_SETTING_NAME_HDMI_CEC_ENABLED = "hdmi_cec_enabled";
785 /**
786 * Name of a setting controlling the version of HDMI-CEC used.
787 *
788 * @see HdmiControlManager#setHdmiCecVersion(int)
789 */
790 public static final String CEC_SETTING_NAME_HDMI_CEC_VERSION = "hdmi_cec_version";
791 /**
792 * Name of a setting deciding whether the Routing Control feature is enabled.
793 *
794 * @see HdmiControlManager#setRoutingControl(int)
795 */
796 public static final String CEC_SETTING_NAME_ROUTING_CONTROL = "routing_control";
797 /**
798 * Name of a setting deciding on the power control mode.
799 *
800 * @see HdmiControlManager#setPowerControlMode(String)
801 */
802 public static final String CEC_SETTING_NAME_POWER_CONTROL_MODE = "power_control_mode";
803 /**
804 * Name of a setting deciding on power state action when losing Active Source.
805 *
806 * @see HdmiControlManager#setPowerStateChangeOnActiveSourceLost(String)
807 */
808 public static final String CEC_SETTING_NAME_POWER_STATE_CHANGE_ON_ACTIVE_SOURCE_LOST =
809 "power_state_change_on_active_source_lost";
810 /**
811 * Name of a setting deciding whether System Audio Control is enabled.
812 *
813 * @see HdmiControlManager#setSystemAudioControl(int)
814 */
815 public static final String CEC_SETTING_NAME_SYSTEM_AUDIO_CONTROL =
816 "system_audio_control";
817 /**
818 * Name of a setting deciding whether System Audio Muting is allowed.
819 *
820 * @see HdmiControlManager#setSystemAudioModeMuting(int)
821 */
822 public static final String CEC_SETTING_NAME_SYSTEM_AUDIO_MODE_MUTING =
823 "system_audio_mode_muting";
824 /**
825 * Controls whether volume control commands via HDMI CEC are enabled.
826 *
827 * <p>Effects on different device types:
828 * <table>
829 * <tr><th>HDMI CEC device type</th><th>0: disabled</th><th>1: enabled</th></tr>
830 * <tr>
831 * <td>TV (type: 0)</td>
832 * <td>Per CEC specification.</td>
833 * <td>TV changes system volume. TV no longer reacts to incoming volume changes
834 * via {@code <User Control Pressed>}. TV no longer handles {@code <Report Audio
835 * Status>}.</td>
836 * </tr>
837 * <tr>
838 * <td>Playback device (type: 4)</td>
839 * <td>Device sends volume commands to TV/Audio system via {@code <User Control
840 * Pressed>}</td>
841 * <td>Device does not send volume commands via {@code <User Control Pressed>}.</td>
842 * </tr>
843 * <tr>
844 * <td>Audio device (type: 5)</td>
845 * <td>Full "System Audio Control" capabilities.</td>
846 * <td>Audio device no longer reacts to incoming {@code <User Control Pressed>}
847 * volume commands. Audio device no longer reports volume changes via {@code
848 * <Report Audio Status>}.</td>
849 * </tr>
850 * </table>
851 *
852 * <p> Due to the resulting behavior, usage on TV and Audio devices is discouraged.
853 *
854 * @see HdmiControlManager#setHdmiCecVolumeControlEnabled(int)
855 */
856 public static final String CEC_SETTING_NAME_VOLUME_CONTROL_MODE =
857 "volume_control_enabled";
858 /**
859 * Name of a setting deciding whether the TV will automatically turn on upon reception
860 * of the CEC command &lt;Text View On&gt; or &lt;Image View On&gt;.
861 *
862 * @see HdmiControlManager#setTvWakeOnOneTouchPlay(int)
863 */
864 public static final String CEC_SETTING_NAME_TV_WAKE_ON_ONE_TOUCH_PLAY =
865 "tv_wake_on_one_touch_play";
866 /**
867 * Name of a setting deciding whether the TV will also turn off other CEC devices
868 * when it goes to standby mode.
869 *
870 * @see HdmiControlManager#setTvSendStandbyOnSleep(int)
871 */
872 public static final String CEC_SETTING_NAME_TV_SEND_STANDBY_ON_SLEEP =
873 "tv_send_standby_on_sleep";
874 /**
875 * Name of a setting deciding whether {@code <Set Menu Language>} message should be
876 * handled by the framework or ignored.
877 *
878 * @hide
879 */
880 public static final String CEC_SETTING_NAME_SET_MENU_LANGUAGE = "set_menu_language";
881 /**
882 * Name of a setting representing the RC profile of a TV panel.
883 *
884 * @hide
885 */
886 public static final String CEC_SETTING_NAME_RC_PROFILE_TV =
887 "rc_profile_tv";
888 /**
889 * Name of a setting representing the RC profile parameter defining if a source handles the root
890 * menu.
891 *
892 * @hide
893 */
894 public static final String CEC_SETTING_NAME_RC_PROFILE_SOURCE_HANDLES_ROOT_MENU =
895 "rc_profile_source_handles_root_menu";
896 /**
897 * Name of a setting representing the RC profile parameter defining if a source handles the
898 * setup menu.
899 *
900 * @hide
901 */
902 public static final String CEC_SETTING_NAME_RC_PROFILE_SOURCE_HANDLES_SETUP_MENU =
903 "rc_profile_source_handles_setup_menu";
904 /**
905 * Name of a setting representing the RC profile parameter defining if a source handles the
906 * contents menu.
907 *
908 * @hide
909 */
910 public static final String CEC_SETTING_NAME_RC_PROFILE_SOURCE_HANDLES_CONTENTS_MENU =
911 "rc_profile_source_handles_contents_menu";
912 /**
913 * Name of a setting representing the RC profile parameter defining if a source handles the top
914 * menu.
915 *
916 * @hide
917 */
918 public static final String CEC_SETTING_NAME_RC_PROFILE_SOURCE_HANDLES_TOP_MENU =
919 "rc_profile_source_handles_top_menu";
920 /**
921 * Name of a setting representing the RC profile parameter defining if a source handles the
922 * media context sensitive menu.
923 *
924 * @hide
925 */
926 public static final String
927 CEC_SETTING_NAME_RC_PROFILE_SOURCE_HANDLES_MEDIA_CONTEXT_SENSITIVE_MENU =
928 "rc_profile_source_handles_media_context_sensitive_menu";
929 /**
930 * Name of a setting representing whether the Short Audio Descriptor (SAD) for the LPCM codec
931 * (0x1) should be queried or not.
932 *
933 * @see HdmiControlManager#setSadPresenceInQuery(String, int)
934 */
935 public static final String CEC_SETTING_NAME_QUERY_SAD_LPCM = "query_sad_lpcm";
936 /**
937 * Name of a setting representing whether the Short Audio Descriptor (SAD) for the DD codec
938 * (0x2) should be queried or not.
939 *
940 * @see HdmiControlManager#setSadPresenceInQuery(String, int)
941 */
942 public static final String CEC_SETTING_NAME_QUERY_SAD_DD = "query_sad_dd";
943 /**
944 * Name of a setting representing whether the Short Audio Descriptor (SAD) for the MPEG1 codec
945 * (0x3) should be queried or not.
946 *
947 * @see HdmiControlManager#setSadPresenceInQuery(String, int)
948 */
949 public static final String CEC_SETTING_NAME_QUERY_SAD_MPEG1 = "query_sad_mpeg1";
950 /**
951 * Name of a setting representing whether the Short Audio Descriptor (SAD) for the MP3 codec
952 * (0x4) should be queried or not.
953 *
954 * @see HdmiControlManager#setSadPresenceInQuery(String, int)
955 */
956 public static final String CEC_SETTING_NAME_QUERY_SAD_MP3 = "query_sad_mp3";
957 /**
958 * Name of a setting representing whether the Short Audio Descriptor (SAD) for the MPEG2 codec
959 * (0x5) should be queried or not.
960 *
961 * @see HdmiControlManager#setSadPresenceInQuery(String, int)
962 */
963 public static final String CEC_SETTING_NAME_QUERY_SAD_MPEG2 = "query_sad_mpeg2";
964 /**
965 * Name of a setting representing whether the Short Audio Descriptor (SAD) for the AAC codec
966 * (0x6) should be queried or not.
967 *
968 * @see HdmiControlManager#setSadPresenceInQuery(String, int)
969 */
970 public static final String CEC_SETTING_NAME_QUERY_SAD_AAC = "query_sad_aac";
971 /**
972 * Name of a setting representing whether the Short Audio Descriptor (SAD) for the DTS codec
973 * (0x7) should be queried or not.
974 *
975 * @see HdmiControlManager#setSadPresenceInQuery(String, int)
976 */
977 public static final String CEC_SETTING_NAME_QUERY_SAD_DTS = "query_sad_dts";
978 /**
979 * Name of a setting representing whether the Short Audio Descriptor (SAD) for the ATRAC codec
980 * (0x8) should be queried or not.
981 *
982 * @see HdmiControlManager#setSadPresenceInQuery(String, int)
983 */
984 public static final String CEC_SETTING_NAME_QUERY_SAD_ATRAC = "query_sad_atrac";
985 /**
986 * Name of a setting representing whether the Short Audio Descriptor (SAD) for the ONEBITAUDIO
987 * codec (0x9) should be queried or not.
988 *
989 * @see HdmiControlManager#setSadPresenceInQuery(String, int)
990 */
991 public static final String CEC_SETTING_NAME_QUERY_SAD_ONEBITAUDIO = "query_sad_onebitaudio";
992 /**
993 * Name of a setting representing whether the Short Audio Descriptor (SAD) for the DDP codec
994 * (0xA) should be queried or not.
995 *
996 * @see HdmiControlManager#setSadPresenceInQuery(String, int)
997 */
998 public static final String CEC_SETTING_NAME_QUERY_SAD_DDP = "query_sad_ddp";
999 /**
1000 * Name of a setting representing whether the Short Audio Descriptor (SAD) for the DTSHD codec
1001 * (0xB) should be queried or not.
1002 *
1003 * @see HdmiControlManager#setSadPresenceInQuery(String, int)
1004 */
1005 public static final String CEC_SETTING_NAME_QUERY_SAD_DTSHD = "query_sad_dtshd";
1006 /**
1007 * Name of a setting representing whether the Short Audio Descriptor (SAD) for the TRUEHD codec
1008 * (0xC) should be queried or not.
1009 *
1010 * @see HdmiControlManager#setSadPresenceInQuery(String, int)
1011 */
1012 public static final String CEC_SETTING_NAME_QUERY_SAD_TRUEHD = "query_sad_truehd";
1013 /**
1014 * Name of a setting representing whether the Short Audio Descriptor (SAD) for the DST codec
1015 * (0xD) should be queried or not.
1016 *
1017 * @see HdmiControlManager#setSadPresenceInQuery(String, int)
1018 */
1019 public static final String CEC_SETTING_NAME_QUERY_SAD_DST = "query_sad_dst";
1020 /**
1021 * Name of a setting representing whether the Short Audio Descriptor (SAD) for the WMAPRO codec
1022 * (0xE) should be queried or not.
1023 *
1024 * @see HdmiControlManager#setSadPresenceInQuery(String, int)
1025 */
1026 public static final String CEC_SETTING_NAME_QUERY_SAD_WMAPRO = "query_sad_wmapro";
1027 /**
1028 * Name of a setting representing whether the Short Audio Descriptor (SAD) for the MAX codec
1029 * (0xF) should be queried or not.
1030 *
1031 * @see HdmiControlManager#setSadPresenceInQuery(String, int)
1032 */
1033 public static final String CEC_SETTING_NAME_QUERY_SAD_MAX = "query_sad_max";
1034 /**
1035 * @hide
1036 */
1037 @StringDef(prefix = { "CEC_SETTING_NAME_" }, value = {
1038 CEC_SETTING_NAME_HDMI_CEC_ENABLED,
1039 CEC_SETTING_NAME_HDMI_CEC_VERSION,
1040 CEC_SETTING_NAME_POWER_CONTROL_MODE,
1041 CEC_SETTING_NAME_POWER_STATE_CHANGE_ON_ACTIVE_SOURCE_LOST,
1042 CEC_SETTING_NAME_SYSTEM_AUDIO_CONTROL,
1043 CEC_SETTING_NAME_SYSTEM_AUDIO_MODE_MUTING,
1044 CEC_SETTING_NAME_VOLUME_CONTROL_MODE,
1045 CEC_SETTING_NAME_TV_WAKE_ON_ONE_TOUCH_PLAY,
1046 CEC_SETTING_NAME_TV_SEND_STANDBY_ON_SLEEP,
1047 CEC_SETTING_NAME_SET_MENU_LANGUAGE,
1048 CEC_SETTING_NAME_RC_PROFILE_TV,
1049 CEC_SETTING_NAME_RC_PROFILE_SOURCE_HANDLES_ROOT_MENU,
1050 CEC_SETTING_NAME_RC_PROFILE_SOURCE_HANDLES_SETUP_MENU,
1051 CEC_SETTING_NAME_RC_PROFILE_SOURCE_HANDLES_CONTENTS_MENU,
1052 CEC_SETTING_NAME_RC_PROFILE_SOURCE_HANDLES_TOP_MENU,
1053 CEC_SETTING_NAME_RC_PROFILE_SOURCE_HANDLES_MEDIA_CONTEXT_SENSITIVE_MENU,
1054 CEC_SETTING_NAME_QUERY_SAD_LPCM,
1055 CEC_SETTING_NAME_QUERY_SAD_DD,
1056 CEC_SETTING_NAME_QUERY_SAD_MPEG1,
1057 CEC_SETTING_NAME_QUERY_SAD_MP3,
1058 CEC_SETTING_NAME_QUERY_SAD_MPEG2,
1059 CEC_SETTING_NAME_QUERY_SAD_AAC,
1060 CEC_SETTING_NAME_QUERY_SAD_DTS,
1061 CEC_SETTING_NAME_QUERY_SAD_ATRAC,
1062 CEC_SETTING_NAME_QUERY_SAD_ONEBITAUDIO,
1063 CEC_SETTING_NAME_QUERY_SAD_DDP,
1064 CEC_SETTING_NAME_QUERY_SAD_DTSHD,
1065 CEC_SETTING_NAME_QUERY_SAD_TRUEHD,
1066 CEC_SETTING_NAME_QUERY_SAD_DST,
1067 CEC_SETTING_NAME_QUERY_SAD_WMAPRO,
1068 CEC_SETTING_NAME_QUERY_SAD_MAX,
1069 })
1070 public @interface CecSettingName {}
1071
1072 /**
1073 * @hide
1074 */
1075 @StringDef(prefix = { "CEC_SETTING_NAME_QUERY_SAD_" }, value = {
1076 CEC_SETTING_NAME_QUERY_SAD_LPCM,
1077 CEC_SETTING_NAME_QUERY_SAD_DD,
1078 CEC_SETTING_NAME_QUERY_SAD_MPEG1,
1079 CEC_SETTING_NAME_QUERY_SAD_MP3,
1080 CEC_SETTING_NAME_QUERY_SAD_MPEG2,
1081 CEC_SETTING_NAME_QUERY_SAD_AAC,
1082 CEC_SETTING_NAME_QUERY_SAD_DTS,
1083 CEC_SETTING_NAME_QUERY_SAD_ATRAC,
1084 CEC_SETTING_NAME_QUERY_SAD_ONEBITAUDIO,
1085 CEC_SETTING_NAME_QUERY_SAD_DDP,
1086 CEC_SETTING_NAME_QUERY_SAD_DTSHD,
1087 CEC_SETTING_NAME_QUERY_SAD_TRUEHD,
1088 CEC_SETTING_NAME_QUERY_SAD_DST,
1089 CEC_SETTING_NAME_QUERY_SAD_WMAPRO,
1090 CEC_SETTING_NAME_QUERY_SAD_MAX,
1091 })
1092 public @interface CecSettingSad {}
1093
1094 // True if we have a logical device of type playback hosted in the system.
1095 private final boolean mHasPlaybackDevice;
1096 // True if we have a logical device of type TV hosted in the system.
1097 private final boolean mHasTvDevice;
1098 // True if we have a logical device of type audio system hosted in the system.
1099 private final boolean mHasAudioSystemDevice;
1100 // True if we have a logical device of type audio system hosted in the system.
1101 private final boolean mHasSwitchDevice;
1102 // True if it's a switch device.
1103 private final boolean mIsSwitchDevice;
1104
1105 /**
1106 * {@hide} - hide this constructor because it has a parameter of type IHdmiControlService,
1107 * which is a system private class. The right way to create an instance of this class is
1108 * using the factory Context.getSystemService.
1109 */
1110 public HdmiControlManager(IHdmiControlService service) {
1111 mService = service;
1112 int[] types = null;
1113 if (mService != null) {
1114 try {
1115 types = mService.getSupportedTypes();
1116 } catch (RemoteException e) {
1117 throw e.rethrowFromSystemServer();
1118 }
1119 }
1120 mHasTvDevice = hasDeviceType(types, HdmiDeviceInfo.DEVICE_TV);
1121 mHasPlaybackDevice = hasDeviceType(types, HdmiDeviceInfo.DEVICE_PLAYBACK);
1122 mHasAudioSystemDevice = hasDeviceType(types, HdmiDeviceInfo.DEVICE_AUDIO_SYSTEM);
1123 mHasSwitchDevice = hasDeviceType(types, HdmiDeviceInfo.DEVICE_PURE_CEC_SWITCH);
1124 mIsSwitchDevice = HdmiProperties.is_switch().orElse(false);
1125 addHotplugEventListener(new ClientHotplugEventListener());
1126 }
1127
1128 private final class ClientHotplugEventListener implements HotplugEventListener {
1129
1130 @Override
1131 public void onReceived(HdmiHotplugEvent event) {
1132 List<HdmiPortInfo> ports = new ArrayList<>();
1133 try {
1134 ports = mService.getPortInfo();
1135 } catch (RemoteException e) {
1136 throw e.rethrowFromSystemServer();
1137 }
1138 if (ports.isEmpty()) {
1139 Log.e(TAG, "Can't find port info, not updating connected status. "
1140 + "Hotplug event:" + event);
1141 return;
1142 }
1143 // If the HDMI OUT port is plugged or unplugged, update the mLocalPhysicalAddress
1144 for (HdmiPortInfo port : ports) {
1145 if (port.getId() == event.getPort()) {
1146 if (port.getType() == HdmiPortInfo.PORT_OUTPUT) {
1147 setLocalPhysicalAddress(
1148 event.isConnected()
1149 ? port.getAddress()
1150 : INVALID_PHYSICAL_ADDRESS);
1151 }
1152 break;
1153 }
1154 }
1155 }
1156 }
1157
1158 private static boolean hasDeviceType(int[] types, int type) {
1159 if (types == null) {
1160 return false;
1161 }
1162 for (int t : types) {
1163 if (t == type) {
1164 return true;
1165 }
1166 }
1167 return false;
1168 }
1169
1170 /**
1171 * Gets an object that represents an HDMI-CEC logical device of a specified type.
1172 *
1173 * @param type CEC device type
1174 * @return {@link HdmiClient} instance. {@code null} on failure.
1175 * See {@link HdmiDeviceInfo#DEVICE_PLAYBACK}
1176 * See {@link HdmiDeviceInfo#DEVICE_TV}
1177 * See {@link HdmiDeviceInfo#DEVICE_AUDIO_SYSTEM}
1178 */
1179 @Nullable
1180 @SuppressLint("RequiresPermission")
1181 public HdmiClient getClient(int type) {
1182 if (mService == null) {
1183 return null;
1184 }
1185 switch (type) {
1186 case HdmiDeviceInfo.DEVICE_TV:
1187 return mHasTvDevice ? new HdmiTvClient(mService) : null;
1188 case HdmiDeviceInfo.DEVICE_PLAYBACK:
1189 return mHasPlaybackDevice ? new HdmiPlaybackClient(mService) : null;
1190 case HdmiDeviceInfo.DEVICE_AUDIO_SYSTEM:
1191 return mHasAudioSystemDevice ? new HdmiAudioSystemClient(mService) : null;
1192 case HdmiDeviceInfo.DEVICE_PURE_CEC_SWITCH:
1193 return (mHasSwitchDevice || mIsSwitchDevice)
1194 ? new HdmiSwitchClient(mService) : null;
1195 default:
1196 return null;
1197 }
1198 }
1199
1200 /**
1201 * Gets an object that represents an HDMI-CEC logical device of type playback on the system.
1202 *
1203 * <p>Used to send HDMI control messages to other devices like TV or audio amplifier through
1204 * HDMI bus. It is also possible to communicate with other logical devices hosted in the same
1205 * system if the system is configured to host more than one type of HDMI-CEC logical devices.
1206 *
1207 * @return {@link HdmiPlaybackClient} instance. {@code null} on failure.
1208 */
1209 @Nullable
1210 @SuppressLint("RequiresPermission")
1211 public HdmiPlaybackClient getPlaybackClient() {
1212 return (HdmiPlaybackClient) getClient(HdmiDeviceInfo.DEVICE_PLAYBACK);
1213 }
1214
1215 /**
1216 * Gets an object that represents an HDMI-CEC logical device of type TV on the system.
1217 *
1218 * <p>Used to send HDMI control messages to other devices and manage them through
1219 * HDMI bus. It is also possible to communicate with other logical devices hosted in the same
1220 * system if the system is configured to host more than one type of HDMI-CEC logical devices.
1221 *
1222 * @return {@link HdmiTvClient} instance. {@code null} on failure.
1223 */
1224 @Nullable
1225 @SuppressLint("RequiresPermission")
1226 public HdmiTvClient getTvClient() {
1227 return (HdmiTvClient) getClient(HdmiDeviceInfo.DEVICE_TV);
1228 }
1229
1230 /**
1231 * Gets an object that represents an HDMI-CEC logical device of type audio system on the system.
1232 *
1233 * <p>Used to send HDMI control messages to other devices like TV through HDMI bus. It is also
1234 * possible to communicate with other logical devices hosted in the same system if the system is
1235 * configured to host more than one type of HDMI-CEC logical devices.
1236 *
1237 * @return {@link HdmiAudioSystemClient} instance. {@code null} on failure.
1238 *
1239 * @hide
1240 */
1241 @Nullable
1242 @SuppressLint("RequiresPermission")
1243 public HdmiAudioSystemClient getAudioSystemClient() {
1244 return (HdmiAudioSystemClient) getClient(HdmiDeviceInfo.DEVICE_AUDIO_SYSTEM);
1245 }
1246
1247 /**
1248 * Gets an object that represents an HDMI-CEC logical device of type switch on the system.
1249 *
1250 * <p>Used to send HDMI control messages to other devices (e.g. TVs) through HDMI bus.
1251 * It is also possible to communicate with other logical devices hosted in the same
1252 * system if the system is configured to host more than one type of HDMI-CEC logical device.
1253 *
1254 * @return {@link HdmiSwitchClient} instance. {@code null} on failure.
1255 */
1256 @Nullable
1257 @SuppressLint("RequiresPermission")
1258 public HdmiSwitchClient getSwitchClient() {
1259 return (HdmiSwitchClient) getClient(HdmiDeviceInfo.DEVICE_PURE_CEC_SWITCH);
1260 }
1261
1262 /**
1263 * Get a snapshot of the real-time status of the devices on the CEC bus.
1264 *
1265 * <p>This only applies to devices with switch functionality, which are devices with one
1266 * or more than one HDMI inputs.
1267 *
1268 * @return a list of {@link HdmiDeviceInfo} of the connected CEC devices on the CEC bus. An
1269 * empty list will be returned if there is none.
1270 */
1271 @NonNull
1272 public List<HdmiDeviceInfo> getConnectedDevices() {
1273 try {
1274 return mService.getDeviceList();
1275 } catch (RemoteException e) {
1276 throw e.rethrowFromSystemServer();
1277 }
1278 }
1279
1280 /**
1281 * @removed
1282 * @deprecated Please use {@link #getConnectedDevices()} instead.
1283 */
1284 @Deprecated
1285 public List<HdmiDeviceInfo> getConnectedDevicesList() {
1286 try {
1287 return mService.getDeviceList();
1288 } catch (RemoteException e) {
1289 throw e.rethrowFromSystemServer();
1290 }
1291 }
1292
1293 /**
1294 * Power off the target device by sending CEC commands. Note that this device can't be the
1295 * current device itself.
1296 *
1297 * <p>The target device info can be obtained by calling {@link #getConnectedDevicesList()}.
1298 *
1299 * @param deviceInfo {@link HdmiDeviceInfo} of the device to be powered off.
1300 */
1301 public void powerOffDevice(@NonNull HdmiDeviceInfo deviceInfo) {
1302 Objects.requireNonNull(deviceInfo);
1303 try {
1304 mService.powerOffRemoteDevice(
1305 deviceInfo.getLogicalAddress(), deviceInfo.getDevicePowerStatus());
1306 } catch (RemoteException e) {
1307 throw e.rethrowFromSystemServer();
1308 }
1309 }
1310
1311 /**
1312 * @removed
1313 * @deprecated Please use {@link #powerOffDevice(deviceInfo)} instead.
1314 */
1315 @Deprecated
1316 public void powerOffRemoteDevice(@NonNull HdmiDeviceInfo deviceInfo) {
1317 Objects.requireNonNull(deviceInfo);
1318 try {
1319 mService.powerOffRemoteDevice(
1320 deviceInfo.getLogicalAddress(), deviceInfo.getDevicePowerStatus());
1321 } catch (RemoteException e) {
1322 throw e.rethrowFromSystemServer();
1323 }
1324 }
1325
1326 /**
1327 * Power on the target device by sending CEC commands. Note that this device can't be the
1328 * current device itself.
1329 *
1330 * <p>The target device info can be obtained by calling {@link #getConnectedDevicesList()}.
1331 *
1332 * @param deviceInfo {@link HdmiDeviceInfo} of the device to be powered on.
1333 *
1334 * @hide
1335 */
1336 public void powerOnDevice(HdmiDeviceInfo deviceInfo) {
1337 Objects.requireNonNull(deviceInfo);
1338 try {
1339 mService.powerOnRemoteDevice(
1340 deviceInfo.getLogicalAddress(), deviceInfo.getDevicePowerStatus());
1341 } catch (RemoteException e) {
1342 throw e.rethrowFromSystemServer();
1343 }
1344 }
1345
1346 /**
1347 * @removed
1348 * @deprecated Please use {@link #powerOnDevice(deviceInfo)} instead.
1349 */
1350 @Deprecated
1351 public void powerOnRemoteDevice(HdmiDeviceInfo deviceInfo) {
1352 Objects.requireNonNull(deviceInfo);
1353 try {
1354 mService.powerOnRemoteDevice(
1355 deviceInfo.getLogicalAddress(), deviceInfo.getDevicePowerStatus());
1356 } catch (RemoteException e) {
1357 throw e.rethrowFromSystemServer();
1358 }
1359 }
1360
1361 /**
1362 * Request the target device to be the new Active Source by sending CEC commands. Note that
1363 * this device can't be the current device itself.
1364 *
1365 * <p>The target device info can be obtained by calling {@link #getConnectedDevicesList()}.
1366 *
1367 * <p>If the target device responds to the command, the users should see the target device
1368 * streaming on their TVs.
1369 *
1370 * @param deviceInfo HdmiDeviceInfo of the target device
1371 */
1372 public void setActiveSource(@NonNull HdmiDeviceInfo deviceInfo) {
1373 Objects.requireNonNull(deviceInfo);
1374 try {
1375 mService.askRemoteDeviceToBecomeActiveSource(deviceInfo.getPhysicalAddress());
1376 } catch (RemoteException e) {
1377 throw e.rethrowFromSystemServer();
1378 }
1379 }
1380
1381 /**
1382 * @removed
1383 * @deprecated Please use {@link #setActiveSource(deviceInfo)} instead.
1384 */
1385 @Deprecated
1386 public void requestRemoteDeviceToBecomeActiveSource(@NonNull HdmiDeviceInfo deviceInfo) {
1387 Objects.requireNonNull(deviceInfo);
1388 try {
1389 mService.askRemoteDeviceToBecomeActiveSource(deviceInfo.getPhysicalAddress());
1390 } catch (RemoteException e) {
1391 throw e.rethrowFromSystemServer();
1392 }
1393 }
1394
1395 /**
1396 * Controls standby mode of the system. It will also try to turn on/off the connected devices if
1397 * necessary.
1398 *
1399 * @param isStandbyModeOn target status of the system's standby mode
1400 */
1401 @RequiresPermission(android.Manifest.permission.HDMI_CEC)
1402 public void setStandbyMode(boolean isStandbyModeOn) {
1403 try {
1404 mService.setStandbyMode(isStandbyModeOn);
1405 } catch (RemoteException e) {
1406 throw e.rethrowFromSystemServer();
1407 }
1408 }
1409
1410 /**
1411 * For CEC source devices (OTT/STB/Audio system): toggle the power status of the HDMI-connected
1412 * display and follow the display's new power status.
1413 * For all other devices: no functionality.
1414 *
1415 * @hide
1416 */
1417 @RequiresPermission(android.Manifest.permission.HDMI_CEC)
1418 public void toggleAndFollowTvPower() {
1419 try {
1420 mService.toggleAndFollowTvPower();
1421 } catch (RemoteException e) {
1422 throw e.rethrowFromSystemServer();
1423 }
1424 }
1425
1426 /**
1427 * Determines whether the HDMI CEC stack should handle KEYCODE_TV_POWER.
1428 *
1429 * @hide
1430 */
1431 @RequiresPermission(android.Manifest.permission.HDMI_CEC)
1432 public boolean shouldHandleTvPowerKey() {
1433 try {
1434 return mService.shouldHandleTvPowerKey();
1435 } catch (RemoteException e) {
1436 throw e.rethrowFromSystemServer();
1437 }
1438 }
1439
1440 /**
1441 * Controls whether volume control commands via HDMI CEC are enabled.
1442 *
1443 * <p>When disabled:
1444 * <ul>
1445 * <li>the device will not send any HDMI CEC audio messages
1446 * <li>received HDMI CEC audio messages are responded to with {@code <Feature Abort>}
1447 * </ul>
1448 *
1449 * <p>Effects on different device types:
1450 * <table>
1451 * <tr><th>HDMI CEC device type</th><th>enabled</th><th>disabled</th></tr>
1452 * <tr>
1453 * <td>TV (type: 0)</td>
1454 * <td>Per CEC specification.</td>
1455 * <td>TV changes system volume. TV no longer reacts to incoming volume changes via
1456 * {@code <User Control Pressed>}. TV no longer handles {@code <Report Audio Status>}
1457 * .</td>
1458 * </tr>
1459 * <tr>
1460 * <td>Playback device (type: 4)</td>
1461 * <td>Device sends volume commands to TV/Audio system via {@code <User Control
1462 * Pressed>}</td><td>Device does not send volume commands via {@code <User Control
1463 * Pressed>}.</td>
1464 * </tr>
1465 * <tr>
1466 * <td>Audio device (type: 5)</td>
1467 * <td>Full "System Audio Control" capabilities.</td>
1468 * <td>Audio device no longer reacts to incoming {@code <User Control Pressed>}
1469 * volume commands. Audio device no longer reports volume changes via {@code <Report
1470 * Audio Status>}.</td>
1471 * </tr>
1472 * </table>
1473 *
1474 * <p> Due to the resulting behavior, usage on TV and Audio devices is discouraged.
1475 *
1476 * @param hdmiCecVolumeControlEnabled target state of HDMI CEC volume control.
1477 * @see HdmiControlManager#CEC_SETTING_NAME_VOLUME_CONTROL_MODE
1478 */
1479 @RequiresPermission(android.Manifest.permission.HDMI_CEC)
1480 public void setHdmiCecVolumeControlEnabled(
1481 @VolumeControl int hdmiCecVolumeControlEnabled) {
1482 try {
1483 mService.setCecSettingIntValue(CEC_SETTING_NAME_VOLUME_CONTROL_MODE,
1484 hdmiCecVolumeControlEnabled);
1485 } catch (RemoteException e) {
1486 throw e.rethrowFromSystemServer();
1487 }
1488 }
1489
1490 /**
1491 * Returns whether volume changes via HDMI CEC are enabled.
1492 *
1493 * @see HdmiControlManager#CEC_SETTING_NAME_VOLUME_CONTROL_MODE
1494 */
1495 @RequiresPermission(android.Manifest.permission.HDMI_CEC)
1496 @VolumeControl
1497 public int getHdmiCecVolumeControlEnabled() {
1498 try {
1499 return mService.getCecSettingIntValue(CEC_SETTING_NAME_VOLUME_CONTROL_MODE);
1500 } catch (RemoteException e) {
1501 throw e.rethrowFromSystemServer();
1502 }
1503 }
1504
1505 /**
1506 * Gets whether the system is in system audio mode.
1507 *
1508 * @hide
1509 */
1510 public boolean getSystemAudioMode() {
1511 try {
1512 return mService.getSystemAudioMode();
1513 } catch (RemoteException e) {
1514 throw e.rethrowFromSystemServer();
1515 }
1516 }
1517
1518 /**
1519 * Get the physical address of the device.
1520 *
1521 * <p>Physical address needs to be automatically adjusted when devices are phyiscally or
1522 * electrically added or removed from the device tree. Please see HDMI Specification Version
1523 * 1.4b 8.7 Physical Address for more details on the address discovery proccess.
1524 */
1525 public int getPhysicalAddress() {
1526 return getLocalPhysicalAddress();
1527 }
1528
1529 /**
1530 * Check if the target device is connected to the current device.
1531 *
1532 * <p>The API also returns true if the current device is the target.
1533 *
1534 * @param targetDevice {@link HdmiDeviceInfo} of the target device.
1535 * @return true if {@code targetDevice} is directly or indirectly
1536 * connected to the current device.
1537 */
1538 public boolean isDeviceConnected(@NonNull HdmiDeviceInfo targetDevice) {
1539 Objects.requireNonNull(targetDevice);
1540 int physicalAddress = getLocalPhysicalAddress();
1541 if (physicalAddress == INVALID_PHYSICAL_ADDRESS) {
1542 return false;
1543 }
1544 int targetPhysicalAddress = targetDevice.getPhysicalAddress();
1545 if (targetPhysicalAddress == INVALID_PHYSICAL_ADDRESS) {
1546 return false;
1547 }
1548 return HdmiUtils.getLocalPortFromPhysicalAddress(targetPhysicalAddress, physicalAddress)
1549 != HdmiUtils.TARGET_NOT_UNDER_LOCAL_DEVICE;
1550 }
1551
1552 /**
1553 * @removed
1554 * @deprecated Please use {@link #isDeviceConnected(targetDevice)} instead.
1555 */
1556 @Deprecated
1557 public boolean isRemoteDeviceConnected(@NonNull HdmiDeviceInfo targetDevice) {
1558 Objects.requireNonNull(targetDevice);
1559 int physicalAddress = getLocalPhysicalAddress();
1560 if (physicalAddress == INVALID_PHYSICAL_ADDRESS) {
1561 return false;
1562 }
1563 int targetPhysicalAddress = targetDevice.getPhysicalAddress();
1564 if (targetPhysicalAddress == INVALID_PHYSICAL_ADDRESS) {
1565 return false;
1566 }
1567 return HdmiUtils.getLocalPortFromPhysicalAddress(targetPhysicalAddress, physicalAddress)
1568 != HdmiUtils.TARGET_NOT_UNDER_LOCAL_DEVICE;
1569 }
1570
1571 /**
1572 * Listener used to get hotplug event from HDMI port.
1573 */
1574 public interface HotplugEventListener {
1575 void onReceived(HdmiHotplugEvent event);
1576 }
1577
1578 private final ArrayMap<HotplugEventListener, IHdmiHotplugEventListener>
1579 mHotplugEventListeners = new ArrayMap<>();
1580
1581 /**
1582 * Listener used to get HDMI Control (CEC) status (enabled/disabled) and the connected display
1583 * status.
1584 * @hide
1585 */
1586 public interface HdmiControlStatusChangeListener {
1587 /**
1588 * Called when HDMI Control (CEC) is enabled/disabled.
1589 *
1590 * @param isCecEnabled status of HDMI Control
1591 * {@link android.hardware.hdmi.HdmiControlManager#CEC_SETTING_NAME_HDMI_CEC_ENABLED}:
1592 * {@code HDMI_CEC_CONTROL_ENABLED} if enabled.
1593 * @param isCecAvailable status of CEC support of the connected display (the TV).
1594 * {@code true} if supported.
1595 *
1596 * Note: Value of isCecAvailable is only valid when isCecEnabled is true.
1597 **/
1598 void onStatusChange(@HdmiControlManager.HdmiCecControl int isCecEnabled,
1599 boolean isCecAvailable);
1600 }
1601
1602 private final ArrayMap<HdmiControlStatusChangeListener, IHdmiControlStatusChangeListener>
1603 mHdmiControlStatusChangeListeners = new ArrayMap<>();
1604
1605 /**
1606 * Listener used to get the status of the HDMI CEC volume control feature (enabled/disabled).
1607 * @hide
1608 */
1609 public interface HdmiCecVolumeControlFeatureListener {
1610 /**
1611 * Called when the HDMI Control (CEC) volume control feature is enabled/disabled.
1612 *
1613 * @param hdmiCecVolumeControl status of HDMI CEC volume control feature
1614 * @see {@link HdmiControlManager#setHdmiCecVolumeControlEnabled(int)} ()}
1615 **/
1616 void onHdmiCecVolumeControlFeature(@VolumeControl int hdmiCecVolumeControl);
1617 }
1618
1619 private final ArrayMap<HdmiCecVolumeControlFeatureListener,
1620 IHdmiCecVolumeControlFeatureListener>
1621 mHdmiCecVolumeControlFeatureListeners = new ArrayMap<>();
1622
1623 /**
1624 * Listener used to get vendor-specific commands.
1625 */
1626 public interface VendorCommandListener {
1627 /**
1628 * Called when a vendor command is received.
1629 *
1630 * @param srcAddress source logical address
1631 * @param destAddress destination logical address
1632 * @param params vendor-specific parameters
1633 * @param hasVendorId {@code true} if the command is &lt;Vendor Command
1634 * With ID&gt;. The first 3 bytes of params is vendor id.
1635 */
1636 void onReceived(int srcAddress, int destAddress, byte[] params, boolean hasVendorId);
1637
1638 /**
1639 * The callback is called:
1640 * <ul>
1641 * <li> before HdmiControlService is disabled.
1642 * <li> after HdmiControlService is enabled and the local address is assigned.
1643 * </ul>
1644 * The client shouldn't hold the thread too long since this is a blocking call.
1645 *
1646 * @param enabled {@code true} if HdmiControlService is enabled.
1647 * @param reason the reason code why the state of HdmiControlService is changed.
1648 * @see #CONTROL_STATE_CHANGED_REASON_START
1649 * @see #CONTROL_STATE_CHANGED_REASON_SETTING
1650 * @see #CONTROL_STATE_CHANGED_REASON_WAKEUP
1651 * @see #CONTROL_STATE_CHANGED_REASON_STANDBY
1652 */
1653 void onControlStateChanged(boolean enabled, int reason);
1654 }
1655
1656 /**
1657 * Adds a listener to get informed of {@link HdmiHotplugEvent}.
1658 *
1659 * <p>To stop getting the notification,
1660 * use {@link #removeHotplugEventListener(HotplugEventListener)}.
1661 *
1662 * Note that each invocation of the callback will be executed on an arbitrary
1663 * Binder thread. This means that all callback implementations must be
1664 * thread safe. To specify the execution thread, use
1665 * {@link addHotplugEventListener(Executor, HotplugEventListener)}.
1666 *
1667 * @param listener {@link HotplugEventListener} instance
1668 * @see HdmiControlManager#removeHotplugEventListener(HotplugEventListener)
1669 */
1670 @RequiresPermission(android.Manifest.permission.HDMI_CEC)
1671 public void addHotplugEventListener(HotplugEventListener listener) {
1672 addHotplugEventListener(ConcurrentUtils.DIRECT_EXECUTOR, listener);
1673 }
1674
1675 /**
1676 * Adds a listener to get informed of {@link HdmiHotplugEvent}.
1677 *
1678 * <p>To stop getting the notification,
1679 * use {@link #removeHotplugEventListener(HotplugEventListener)}.
1680 *
1681 * @param listener {@link HotplugEventListener} instance
1682 * @see HdmiControlManager#removeHotplugEventListener(HotplugEventListener)
1683 */
1684 @RequiresPermission(android.Manifest.permission.HDMI_CEC)
1685 public void addHotplugEventListener(@NonNull @CallbackExecutor Executor executor,
1686 @NonNull HotplugEventListener listener) {
1687 if (mService == null) {
1688 Log.e(TAG, "HdmiControlService is not available");
1689 return;
1690 }
1691 if (mHotplugEventListeners.containsKey(listener)) {
1692 Log.e(TAG, "listener is already registered");
1693 return;
1694 }
1695 IHdmiHotplugEventListener wrappedListener =
1696 getHotplugEventListenerWrapper(executor, listener);
1697 mHotplugEventListeners.put(listener, wrappedListener);
1698 try {
1699 mService.addHotplugEventListener(wrappedListener);
1700 } catch (RemoteException e) {
1701 throw e.rethrowFromSystemServer();
1702 }
1703 }
1704
1705 /**
1706 * Removes a listener to stop getting informed of {@link HdmiHotplugEvent}.
1707 *
1708 * @param listener {@link HotplugEventListener} instance to be removed
1709 */
1710 @RequiresPermission(android.Manifest.permission.HDMI_CEC)
1711 public void removeHotplugEventListener(HotplugEventListener listener) {
1712 if (mService == null) {
1713 Log.e(TAG, "HdmiControlService is not available");
1714 return;
1715 }
1716 IHdmiHotplugEventListener wrappedListener = mHotplugEventListeners.remove(listener);
1717 if (wrappedListener == null) {
1718 Log.e(TAG, "tried to remove not-registered listener");
1719 return;
1720 }
1721 try {
1722 mService.removeHotplugEventListener(wrappedListener);
1723 } catch (RemoteException e) {
1724 throw e.rethrowFromSystemServer();
1725 }
1726 }
1727
1728 private IHdmiHotplugEventListener getHotplugEventListenerWrapper(
1729 Executor executor, final HotplugEventListener listener) {
1730 return new IHdmiHotplugEventListener.Stub() {
1731 @Override
1732 public void onReceived(HdmiHotplugEvent event) {
1733 final long token = Binder.clearCallingIdentity();
1734 try {
1735 executor.execute(() -> listener.onReceived(event));
1736 } finally {
1737 Binder.restoreCallingIdentity(token);
1738 }
1739 }
1740 };
1741 }
1742
1743 /**
1744 * Adds a listener to get informed of {@link HdmiControlStatusChange}.
1745 *
1746 * <p>To stop getting the notification,
1747 * use {@link #removeHdmiControlStatusChangeListener(HdmiControlStatusChangeListener)}.
1748 *
1749 * Note that each invocation of the callback will be executed on an arbitrary
1750 * Binder thread. This means that all callback implementations must be
1751 * thread safe. To specify the execution thread, use
1752 * {@link addHdmiControlStatusChangeListener(Executor, HdmiControlStatusChangeListener)}.
1753 *
1754 * @param listener {@link HdmiControlStatusChangeListener} instance
1755 * @see HdmiControlManager#removeHdmiControlStatusChangeListener(
1756 * HdmiControlStatusChangeListener)
1757 *
1758 * @hide
1759 */
1760 @RequiresPermission(android.Manifest.permission.HDMI_CEC)
1761 public void addHdmiControlStatusChangeListener(HdmiControlStatusChangeListener listener) {
1762 addHdmiControlStatusChangeListener(ConcurrentUtils.DIRECT_EXECUTOR, listener);
1763 }
1764
1765 /**
1766 * Adds a listener to get informed of {@link HdmiControlStatusChange}.
1767 *
1768 * <p>To stop getting the notification,
1769 * use {@link #removeHdmiControlStatusChangeListener(HdmiControlStatusChangeListener)}.
1770 *
1771 * @param listener {@link HdmiControlStatusChangeListener} instance
1772 * @see HdmiControlManager#removeHdmiControlStatusChangeListener(
1773 * HdmiControlStatusChangeListener)
1774 *
1775 * @hide
1776 */
1777 @RequiresPermission(android.Manifest.permission.HDMI_CEC)
1778 public void addHdmiControlStatusChangeListener(@NonNull @CallbackExecutor Executor executor,
1779 @NonNull HdmiControlStatusChangeListener listener) {
1780 if (mService == null) {
1781 Log.e(TAG, "HdmiControlService is not available");
1782 return;
1783 }
1784 if (mHdmiControlStatusChangeListeners.containsKey(listener)) {
1785 Log.e(TAG, "listener is already registered");
1786 return;
1787 }
1788 IHdmiControlStatusChangeListener wrappedListener =
1789 getHdmiControlStatusChangeListenerWrapper(executor, listener);
1790 mHdmiControlStatusChangeListeners.put(listener, wrappedListener);
1791 try {
1792 mService.addHdmiControlStatusChangeListener(wrappedListener);
1793 } catch (RemoteException e) {
1794 throw e.rethrowFromSystemServer();
1795 }
1796 }
1797
1798 /**
1799 * Removes a listener to stop getting informed of {@link HdmiControlStatusChange}.
1800 *
1801 * @param listener {@link HdmiControlStatusChangeListener} instance to be removed
1802 *
1803 * @hide
1804 */
1805 @RequiresPermission(android.Manifest.permission.HDMI_CEC)
1806 public void removeHdmiControlStatusChangeListener(HdmiControlStatusChangeListener listener) {
1807 if (mService == null) {
1808 Log.e(TAG, "HdmiControlService is not available");
1809 return;
1810 }
1811 IHdmiControlStatusChangeListener wrappedListener =
1812 mHdmiControlStatusChangeListeners.remove(listener);
1813 if (wrappedListener == null) {
1814 Log.e(TAG, "tried to remove not-registered listener");
1815 return;
1816 }
1817 try {
1818 mService.removeHdmiControlStatusChangeListener(wrappedListener);
1819 } catch (RemoteException e) {
1820 throw e.rethrowFromSystemServer();
1821 }
1822 }
1823
1824 private IHdmiControlStatusChangeListener getHdmiControlStatusChangeListenerWrapper(
1825 Executor executor, final HdmiControlStatusChangeListener listener) {
1826 return new IHdmiControlStatusChangeListener.Stub() {
1827 @Override
1828 public void onStatusChange(@HdmiCecControl int isCecEnabled, boolean isCecAvailable) {
1829 final long token = Binder.clearCallingIdentity();
1830 try {
1831 executor.execute(() -> listener.onStatusChange(isCecEnabled, isCecAvailable));
1832 } finally {
1833 Binder.restoreCallingIdentity(token);
1834 }
1835 }
1836 };
1837 }
1838
1839 /**
1840 * Adds a listener to get informed of changes to the state of the HDMI CEC volume control
1841 * feature.
1842 *
1843 * Upon adding a listener, the current state of the HDMI CEC volume control feature will be
1844 * sent immediately.
1845 *
1846 * <p>To stop getting the notification,
1847 * use {@link #removeHdmiCecVolumeControlFeatureListener(HdmiCecVolumeControlFeatureListener)}.
1848 *
1849 * @param listener {@link HdmiCecVolumeControlFeatureListener} instance
1850 * @hide
1851 * @see #removeHdmiCecVolumeControlFeatureListener(HdmiCecVolumeControlFeatureListener)
1852 */
1853 @RequiresPermission(android.Manifest.permission.HDMI_CEC)
1854 public void addHdmiCecVolumeControlFeatureListener(@NonNull @CallbackExecutor Executor executor,
1855 @NonNull HdmiCecVolumeControlFeatureListener listener) {
1856 if (mService == null) {
1857 Log.e(TAG, "HdmiControlService is not available");
1858 return;
1859 }
1860 if (mHdmiCecVolumeControlFeatureListeners.containsKey(listener)) {
1861 Log.e(TAG, "listener is already registered");
1862 return;
1863 }
1864 IHdmiCecVolumeControlFeatureListener wrappedListener =
1865 createHdmiCecVolumeControlFeatureListenerWrapper(executor, listener);
1866 mHdmiCecVolumeControlFeatureListeners.put(listener, wrappedListener);
1867 try {
1868 mService.addHdmiCecVolumeControlFeatureListener(wrappedListener);
1869 } catch (RemoteException e) {
1870 throw e.rethrowFromSystemServer();
1871 }
1872 }
1873
1874 /**
1875 * Removes a listener to stop getting informed of changes to the state of the HDMI CEC volume
1876 * control feature.
1877 *
1878 * @param listener {@link HdmiCecVolumeControlFeatureListener} instance to be removed
1879 * @hide
1880 */
1881 @RequiresPermission(android.Manifest.permission.HDMI_CEC)
1882 public void removeHdmiCecVolumeControlFeatureListener(
1883 HdmiCecVolumeControlFeatureListener listener) {
1884 if (mService == null) {
1885 Log.e(TAG, "HdmiControlService is not available");
1886 return;
1887 }
1888 IHdmiCecVolumeControlFeatureListener wrappedListener =
1889 mHdmiCecVolumeControlFeatureListeners.remove(listener);
1890 if (wrappedListener == null) {
1891 Log.e(TAG, "tried to remove not-registered listener");
1892 return;
1893 }
1894 try {
1895 mService.removeHdmiCecVolumeControlFeatureListener(wrappedListener);
1896 } catch (RemoteException e) {
1897 throw e.rethrowFromSystemServer();
1898 }
1899 }
1900
1901 private IHdmiCecVolumeControlFeatureListener createHdmiCecVolumeControlFeatureListenerWrapper(
1902 Executor executor, final HdmiCecVolumeControlFeatureListener listener) {
1903 return new android.hardware.hdmi.IHdmiCecVolumeControlFeatureListener.Stub() {
1904 @Override
1905 public void onHdmiCecVolumeControlFeature(int enabled) {
1906 final long token = Binder.clearCallingIdentity();
1907 try {
1908 executor.execute(() -> listener.onHdmiCecVolumeControlFeature(enabled));
1909 } finally {
1910 Binder.restoreCallingIdentity(token);
1911 }
1912 }
1913 };
1914 }
1915
1916 /**
1917 * Listener used to get setting change notification.
1918 */
1919 public interface CecSettingChangeListener {
1920 /**
1921 * Called when value of a setting changes.
1922 *
1923 * @param setting name of a CEC setting that changed
1924 */
1925 void onChange(@NonNull @CecSettingName String setting);
1926 }
1927
1928 private final ArrayMap<String,
1929 ArrayMap<CecSettingChangeListener, IHdmiCecSettingChangeListener>>
1930 mCecSettingChangeListeners = new ArrayMap<>();
1931
1932 private void addCecSettingChangeListener(
1933 @NonNull @CecSettingName String setting,
1934 @NonNull @CallbackExecutor Executor executor,
1935 @NonNull CecSettingChangeListener listener) {
1936 if (mService == null) {
1937 Log.e(TAG, "HdmiControlService is not available");
1938 return;
1939 }
1940 if (mCecSettingChangeListeners.containsKey(setting)
1941 && mCecSettingChangeListeners.get(setting).containsKey(listener)) {
1942 Log.e(TAG, "listener is already registered");
1943 return;
1944 }
1945 IHdmiCecSettingChangeListener wrappedListener =
1946 getCecSettingChangeListenerWrapper(executor, listener);
1947 if (!mCecSettingChangeListeners.containsKey(setting)) {
1948 mCecSettingChangeListeners.put(setting, new ArrayMap<>());
1949 }
1950 mCecSettingChangeListeners.get(setting).put(listener, wrappedListener);
1951 try {
1952 mService.addCecSettingChangeListener(setting, wrappedListener);
1953 } catch (RemoteException e) {
1954 throw e.rethrowFromSystemServer();
1955 }
1956 }
1957
1958 private void removeCecSettingChangeListener(
1959 @NonNull @CecSettingName String setting,
1960 @NonNull CecSettingChangeListener listener) {
1961 if (mService == null) {
1962 Log.e(TAG, "HdmiControlService is not available");
1963 return;
1964 }
1965 IHdmiCecSettingChangeListener wrappedListener =
1966 !mCecSettingChangeListeners.containsKey(setting) ? null :
1967 mCecSettingChangeListeners.get(setting).remove(listener);
1968 if (wrappedListener == null) {
1969 Log.e(TAG, "tried to remove not-registered listener");
1970 return;
1971 }
1972 try {
1973 mService.removeCecSettingChangeListener(setting, wrappedListener);
1974 } catch (RemoteException e) {
1975 throw e.rethrowFromSystemServer();
1976 }
1977 }
1978
1979 private IHdmiCecSettingChangeListener getCecSettingChangeListenerWrapper(
1980 Executor executor, final CecSettingChangeListener listener) {
1981 return new IHdmiCecSettingChangeListener.Stub() {
1982 @Override
1983 public void onChange(String setting) {
1984 final long token = Binder.clearCallingIdentity();
1985 try {
1986 executor.execute(() -> listener.onChange(setting));
1987 } finally {
1988 Binder.restoreCallingIdentity(token);
1989 }
1990 }
1991 };
1992 }
1993
1994 /**
1995 * Get a set of user-modifiable settings.
1996 *
1997 * @return a set of user-modifiable settings.
1998 * @throws RuntimeException when the HdmiControlService is not available.
1999 */
2000 @NonNull
2001 @CecSettingName
2002 @RequiresPermission(android.Manifest.permission.HDMI_CEC)
2003 public List<String> getUserCecSettings() {
2004 if (mService == null) {
2005 Log.e(TAG, "HdmiControlService is not available");
2006 throw new RuntimeException("HdmiControlService is not available");
2007 }
2008 try {
2009 return mService.getUserCecSettings();
2010 } catch (RemoteException e) {
2011 throw e.rethrowFromSystemServer();
2012 }
2013 }
2014
2015 /**
2016 * Get a set of allowed values for a setting (string value-type).
2017 *
2018 * @param name name of the setting
2019 * @return a set of allowed values for a settings. {@code null} on failure.
2020 * @throws IllegalArgumentException when setting {@code name} does not exist.
2021 * @throws IllegalArgumentException when setting {@code name} value type is invalid.
2022 * @throws RuntimeException when the HdmiControlService is not available.
2023 */
2024 @NonNull
2025 @RequiresPermission(android.Manifest.permission.HDMI_CEC)
2026 public List<String> getAllowedCecSettingStringValues(@NonNull @CecSettingName String name) {
2027 if (mService == null) {
2028 Log.e(TAG, "HdmiControlService is not available");
2029 throw new RuntimeException("HdmiControlService is not available");
2030 }
2031 try {
2032 return mService.getAllowedCecSettingStringValues(name);
2033 } catch (RemoteException e) {
2034 throw e.rethrowFromSystemServer();
2035 }
2036 }
2037
2038 /**
2039 * Get a set of allowed values for a setting (int value-type).
2040 *
2041 * @param name name of the setting
2042 * @return a set of allowed values for a settings. {@code null} on failure.
2043 * @throws IllegalArgumentException when setting {@code name} does not exist.
2044 * @throws IllegalArgumentException when setting {@code name} value type is invalid.
2045 * @throws RuntimeException when the HdmiControlService is not available.
2046 */
2047 @NonNull
2048 @RequiresPermission(android.Manifest.permission.HDMI_CEC)
2049 public List<Integer> getAllowedCecSettingIntValues(@NonNull @CecSettingName String name) {
2050 if (mService == null) {
2051 Log.e(TAG, "HdmiControlService is not available");
2052 throw new RuntimeException("HdmiControlService is not available");
2053 }
2054 try {
2055 int[] allowedValues = mService.getAllowedCecSettingIntValues(name);
2056 return Arrays.stream(allowedValues).boxed().collect(Collectors.toList());
2057 } catch (RemoteException e) {
2058 throw e.rethrowFromSystemServer();
2059 }
2060 }
2061
2062 /**
2063 * Set the global status of HDMI CEC.
2064 *
2065 * <p>This allows to enable/disable HDMI CEC on the device.
2066 */
2067 @RequiresPermission(android.Manifest.permission.HDMI_CEC)
2068 public void setHdmiCecEnabled(@NonNull @HdmiCecControl int value) {
2069 if (mService == null) {
2070 Log.e(TAG, "HdmiControlService is not available");
2071 throw new RuntimeException("HdmiControlService is not available");
2072 }
2073 try {
2074 mService.setCecSettingIntValue(CEC_SETTING_NAME_HDMI_CEC_ENABLED, value);
2075 } catch (RemoteException e) {
2076 throw e.rethrowFromSystemServer();
2077 }
2078 }
2079
2080 /**
2081 * Get the current global status of HDMI CEC.
2082 *
2083 * <p>Reflects whether HDMI CEC is currently enabled on the device.
2084 */
2085 @NonNull
2086 @HdmiCecControl
2087 @RequiresPermission(android.Manifest.permission.HDMI_CEC)
2088 public int getHdmiCecEnabled() {
2089 if (mService == null) {
2090 Log.e(TAG, "HdmiControlService is not available");
2091 throw new RuntimeException("HdmiControlService is not available");
2092 }
2093 try {
2094 return mService.getCecSettingIntValue(CEC_SETTING_NAME_HDMI_CEC_ENABLED);
2095 } catch (RemoteException e) {
2096 throw e.rethrowFromSystemServer();
2097 }
2098 }
2099
2100 /**
2101 * Add change listener for global status of HDMI CEC.
2102 *
2103 * <p>To stop getting the notification,
2104 * use {@link #removeHdmiCecEnabledChangeListener(CecSettingChangeListener)}.
2105 *
2106 * Note that each invocation of the callback will be executed on an arbitrary
2107 * Binder thread. This means that all callback implementations must be
2108 * thread safe. To specify the execution thread, use
2109 * {@link addHdmiCecEnabledChangeListener(Executor, CecSettingChangeListener)}.
2110 */
2111 @RequiresPermission(android.Manifest.permission.HDMI_CEC)
2112 public void addHdmiCecEnabledChangeListener(@NonNull CecSettingChangeListener listener) {
2113 addHdmiCecEnabledChangeListener(ConcurrentUtils.DIRECT_EXECUTOR, listener);
2114 }
2115
2116 /**
2117 * Add change listener for global status of HDMI CEC.
2118 *
2119 * <p>To stop getting the notification,
2120 * use {@link #removeHdmiCecEnabledChangeListener(CecSettingChangeListener)}.
2121 */
2122 @RequiresPermission(android.Manifest.permission.HDMI_CEC)
2123 public void addHdmiCecEnabledChangeListener(
2124 @NonNull @CallbackExecutor Executor executor,
2125 @NonNull CecSettingChangeListener listener) {
2126 addCecSettingChangeListener(CEC_SETTING_NAME_HDMI_CEC_ENABLED, executor, listener);
2127 }
2128
2129 /**
2130 * Remove change listener for global status of HDMI CEC.
2131 */
2132 @RequiresPermission(android.Manifest.permission.HDMI_CEC)
2133 public void removeHdmiCecEnabledChangeListener(
2134 @NonNull CecSettingChangeListener listener) {
2135 removeCecSettingChangeListener(CEC_SETTING_NAME_HDMI_CEC_ENABLED, listener);
2136 }
2137
2138 /**
2139 * Set the version of the HDMI CEC specification currently used.
2140 *
2141 * <p>Allows to select either CEC 1.4b or 2.0 to be used by the device.
2142 *
2143 * @see HdmiControlManager#CEC_SETTING_NAME_HDMI_CEC_VERSION
2144 */
2145 @RequiresPermission(android.Manifest.permission.HDMI_CEC)
2146 public void setHdmiCecVersion(@NonNull @HdmiCecVersion int value) {
2147 if (mService == null) {
2148 Log.e(TAG, "HdmiControlService is not available");
2149 throw new RuntimeException("HdmiControlService is not available");
2150 }
2151 try {
2152 mService.setCecSettingIntValue(CEC_SETTING_NAME_HDMI_CEC_VERSION, value);
2153 } catch (RemoteException e) {
2154 throw e.rethrowFromSystemServer();
2155 }
2156 }
2157
2158 /**
2159 * Get the version of the HDMI CEC specification currently used.
2160 *
2161 * <p>Reflects which CEC version 1.4b or 2.0 is currently used by the device.
2162 *
2163 * @see HdmiControlManager#CEC_SETTING_NAME_HDMI_CEC_VERSION
2164 */
2165 @NonNull
2166 @HdmiCecVersion
2167 @RequiresPermission(android.Manifest.permission.HDMI_CEC)
2168 public int getHdmiCecVersion() {
2169 if (mService == null) {
2170 Log.e(TAG, "HdmiControlService is not available");
2171 throw new RuntimeException("HdmiControlService is not available");
2172 }
2173 try {
2174 return mService.getCecSettingIntValue(CEC_SETTING_NAME_HDMI_CEC_VERSION);
2175 } catch (RemoteException e) {
2176 throw e.rethrowFromSystemServer();
2177 }
2178 }
2179
2180 /**
2181 * Set the status of Routing Control feature.
2182 *
2183 * <p>This allows to enable/disable Routing Control on the device.
2184 * If enabled, the switch device will route to the correct input source on
2185 * receiving Routing Control related messages. If disabled, you can only
2186 * switch the input via controls on this device.
2187 *
2188 * @see HdmiControlManager#CEC_SETTING_NAME_ROUTING_CONTROL
2189 */
2190 @RequiresPermission(android.Manifest.permission.HDMI_CEC)
2191 public void setRoutingControl(@NonNull @RoutingControl int value) {
2192 if (mService == null) {
2193 Log.e(TAG, "HdmiControlService is not available");
2194 throw new RuntimeException("HdmiControlService is not available");
2195 }
2196 try {
2197 mService.setCecSettingIntValue(CEC_SETTING_NAME_ROUTING_CONTROL, value);
2198 } catch (RemoteException e) {
2199 throw e.rethrowFromSystemServer();
2200 }
2201 }
2202
2203 /**
2204 * Get the current status of Routing Control feature.
2205 *
2206 * <p>Reflects whether Routing Control is currently enabled on the device.
2207 * If enabled, the switch device will route to the correct input source on
2208 * receiving Routing Control related messages. If disabled, you can only
2209 * switch the input via controls on this device.
2210 *
2211 * @see HdmiControlManager#CEC_SETTING_NAME_ROUTING_CONTROL
2212 */
2213 @NonNull
2214 @RoutingControl
2215 @RequiresPermission(android.Manifest.permission.HDMI_CEC)
2216 public int getRoutingControl() {
2217 if (mService == null) {
2218 Log.e(TAG, "HdmiControlService is not available");
2219 throw new RuntimeException("HdmiControlService is not available");
2220 }
2221 try {
2222 return mService.getCecSettingIntValue(CEC_SETTING_NAME_ROUTING_CONTROL);
2223 } catch (RemoteException e) {
2224 throw e.rethrowFromSystemServer();
2225 }
2226 }
2227
2228 /**
2229 * Set the status of Power Control.
2230 *
2231 * <p>Specifies to which devices Power Control messages should be sent:
2232 * only to the TV, broadcast to all devices, no power control messages.
2233 *
2234 * @see HdmiControlManager#CEC_SETTING_NAME_POWER_CONTROL_MODE
2235 */
2236 @RequiresPermission(android.Manifest.permission.HDMI_CEC)
2237 public void setPowerControlMode(@NonNull @PowerControlMode String value) {
2238 if (mService == null) {
2239 Log.e(TAG, "HdmiControlService is not available");
2240 throw new RuntimeException("HdmiControlService is not available");
2241 }
2242 try {
2243 mService.setCecSettingStringValue(CEC_SETTING_NAME_POWER_CONTROL_MODE, value);
2244 } catch (RemoteException e) {
2245 throw e.rethrowFromSystemServer();
2246 }
2247 }
2248
2249 /**
2250 * Get the status of Power Control.
2251 *
2252 * <p>Reflects to which devices Power Control messages should be sent:
2253 * only to the TV, broadcast to all devices, no power control messages.
2254 *
2255 * @see HdmiControlManager#CEC_SETTING_NAME_POWER_CONTROL_MODE
2256 */
2257 @NonNull
2258 @PowerControlMode
2259 @RequiresPermission(android.Manifest.permission.HDMI_CEC)
2260 public String getPowerControlMode() {
2261 if (mService == null) {
2262 Log.e(TAG, "HdmiControlService is not available");
2263 throw new RuntimeException("HdmiControlService is not available");
2264 }
2265 try {
2266 return mService.getCecSettingStringValue(CEC_SETTING_NAME_POWER_CONTROL_MODE);
2267 } catch (RemoteException e) {
2268 throw e.rethrowFromSystemServer();
2269 }
2270 }
2271
2272 /**
2273 * Set the current power state behaviour when Active Source is lost.
2274 *
2275 * <p>Sets the action taken: do nothing or go to sleep immediately.
2276 *
2277 * @see HdmiControlManager#CEC_SETTING_NAME_POWER_STATE_CHANGE_ON_ACTIVE_SOURCE_LOST
2278 */
2279 @RequiresPermission(android.Manifest.permission.HDMI_CEC)
2280 public void setPowerStateChangeOnActiveSourceLost(
2281 @NonNull @ActiveSourceLostBehavior String value) {
2282 if (mService == null) {
2283 Log.e(TAG, "HdmiControlService is not available");
2284 throw new RuntimeException("HdmiControlService is not available");
2285 }
2286 try {
2287 mService.setCecSettingStringValue(
2288 CEC_SETTING_NAME_POWER_STATE_CHANGE_ON_ACTIVE_SOURCE_LOST, value);
2289 } catch (RemoteException e) {
2290 throw e.rethrowFromSystemServer();
2291 }
2292 }
2293
2294 /**
2295 * Get the current power state behaviour when Active Source is lost.
2296 *
2297 * <p>Reflects the action taken: do nothing or go to sleep immediately.
2298 *
2299 * @see HdmiControlManager#CEC_SETTING_NAME_POWER_STATE_CHANGE_ON_ACTIVE_SOURCE_LOST
2300 */
2301 @NonNull
2302 @ActiveSourceLostBehavior
2303 @RequiresPermission(android.Manifest.permission.HDMI_CEC)
2304 public String getPowerStateChangeOnActiveSourceLost() {
2305 if (mService == null) {
2306 Log.e(TAG, "HdmiControlService is not available");
2307 throw new RuntimeException("HdmiControlService is not available");
2308 }
2309 try {
2310 return mService.getCecSettingStringValue(
2311 CEC_SETTING_NAME_POWER_STATE_CHANGE_ON_ACTIVE_SOURCE_LOST);
2312 } catch (RemoteException e) {
2313 throw e.rethrowFromSystemServer();
2314 }
2315 }
2316
2317 /**
2318 * Set the current status of System Audio Control.
2319 *
2320 * <p>Sets whether HDMI System Audio Control feature is enabled. If enabled,
2321 * TV or Audio System will try to turn on the System Audio Mode if there's a
2322 * connected CEC-enabled AV Receiver. Then an audio stream will be played on
2323 * the AVR instead of TV speaker or Audio System speakers. If disabled, the
2324 * System Audio Mode will never be activated.
2325 *
2326 * @see HdmiControlManager#CEC_SETTING_NAME_SYSTEM_AUDIO_CONTROL
2327 */
2328 @RequiresPermission(android.Manifest.permission.HDMI_CEC)
2329 public void setSystemAudioControl(@NonNull @SystemAudioControl int value) {
2330 if (mService == null) {
2331 Log.e(TAG, "HdmiControlService is not available");
2332 throw new RuntimeException("HdmiControlService is not available");
2333 }
2334 try {
2335 mService.setCecSettingIntValue(CEC_SETTING_NAME_SYSTEM_AUDIO_CONTROL, value);
2336 } catch (RemoteException e) {
2337 throw e.rethrowFromSystemServer();
2338 }
2339 }
2340
2341 /**
2342 * Get the current status of System Audio Control.
2343 *
2344 * <p>Reflects whether HDMI System Audio Control feature is enabled. If enabled,
2345 * TV or Audio System will try to turn on the System Audio Mode if there's a
2346 * connected CEC-enabled AV Receiver. Then an audio stream will be played on
2347 * the AVR instead of TV speaker or Audio System speakers. If disabled, the
2348 * System Audio Mode will never be activated.
2349 *
2350 * @see HdmiControlManager#CEC_SETTING_NAME_SYSTEM_AUDIO_CONTROL
2351 */
2352 @NonNull
2353 @SystemAudioControl
2354 @RequiresPermission(android.Manifest.permission.HDMI_CEC)
2355 public int getSystemAudioControl() {
2356 if (mService == null) {
2357 Log.e(TAG, "HdmiControlService is not available");
2358 throw new RuntimeException("HdmiControlService is not available");
2359 }
2360 try {
2361 return mService.getCecSettingIntValue(CEC_SETTING_NAME_SYSTEM_AUDIO_CONTROL);
2362 } catch (RemoteException e) {
2363 throw e.rethrowFromSystemServer();
2364 }
2365 }
2366
2367 /**
2368 * Set the current status of System Audio Mode muting.
2369 *
2370 * <p>Sets whether the device should be muted when System Audio Mode is turned off.
2371 *
2372 * @see HdmiControlManager#CEC_SETTING_NAME_SYSTEM_AUDIO_MODE_MUTING
2373 */
2374 @RequiresPermission(android.Manifest.permission.HDMI_CEC)
2375 public void setSystemAudioModeMuting(@NonNull @SystemAudioModeMuting int value) {
2376 if (mService == null) {
2377 Log.e(TAG, "HdmiControlService is not available");
2378 throw new RuntimeException("HdmiControlService is not available");
2379 }
2380 try {
2381 mService.setCecSettingIntValue(CEC_SETTING_NAME_SYSTEM_AUDIO_MODE_MUTING, value);
2382 } catch (RemoteException e) {
2383 throw e.rethrowFromSystemServer();
2384 }
2385 }
2386
2387 /**
2388 * Get the current status of System Audio Mode muting.
2389 *
2390 * <p>Reflects whether the device should be muted when System Audio Mode is turned off.
2391 *
2392 * @see HdmiControlManager#CEC_SETTING_NAME_SYSTEM_AUDIO_MODE_MUTING
2393 */
2394 @NonNull
2395 @SystemAudioModeMuting
2396 @RequiresPermission(android.Manifest.permission.HDMI_CEC)
2397 public int getSystemAudioModeMuting() {
2398 if (mService == null) {
2399 Log.e(TAG, "HdmiControlService is not available");
2400 throw new RuntimeException("HdmiControlService is not available");
2401 }
2402 try {
2403 return mService.getCecSettingIntValue(CEC_SETTING_NAME_SYSTEM_AUDIO_MODE_MUTING);
2404 } catch (RemoteException e) {
2405 throw e.rethrowFromSystemServer();
2406 }
2407 }
2408
2409 /**
2410 * Set the current status of TV Wake on One Touch Play.
2411 *
2412 * <p>Sets whether the TV should wake up upon reception of &lt;Text View On&gt;
2413 * or &lt;Image View On&gt;.
2414 *
2415 * @see HdmiControlManager#CEC_SETTING_NAME_TV_WAKE_ON_ONE_TOUCH_PLAY
2416 */
2417 @RequiresPermission(android.Manifest.permission.HDMI_CEC)
2418 public void setTvWakeOnOneTouchPlay(@NonNull @TvWakeOnOneTouchPlay int value) {
2419 if (mService == null) {
2420 Log.e(TAG, "HdmiControlService is not available");
2421 throw new RuntimeException("HdmiControlService is not available");
2422 }
2423 try {
2424 mService.setCecSettingIntValue(CEC_SETTING_NAME_TV_WAKE_ON_ONE_TOUCH_PLAY, value);
2425 } catch (RemoteException e) {
2426 throw e.rethrowFromSystemServer();
2427 }
2428 }
2429
2430 /**
2431 * Get the current status of TV Wake on One Touch Play.
2432 *
2433 * <p>Reflects whether the TV should wake up upon reception of &lt;Text View On&gt;
2434 * or &lt;Image View On&gt;.
2435 *
2436 * @see HdmiControlManager#CEC_SETTING_NAME_TV_WAKE_ON_ONE_TOUCH_PLAY
2437 */
2438 @NonNull
2439 @TvWakeOnOneTouchPlay
2440 @RequiresPermission(android.Manifest.permission.HDMI_CEC)
2441 public int getTvWakeOnOneTouchPlay() {
2442 if (mService == null) {
2443 Log.e(TAG, "HdmiControlService is not available");
2444 throw new RuntimeException("HdmiControlService is not available");
2445 }
2446 try {
2447 return mService.getCecSettingIntValue(CEC_SETTING_NAME_TV_WAKE_ON_ONE_TOUCH_PLAY);
2448 } catch (RemoteException e) {
2449 throw e.rethrowFromSystemServer();
2450 }
2451 }
2452
2453 /**
2454 * Set the current status of TV send &lt;Standby&gt; on Sleep.
2455 *
2456 * <p>Sets whether the device will also turn off other CEC devices
2457 * when it goes to standby mode.
2458 *
2459 * @see HdmiControlManager#CEC_SETTING_NAME_TV_SEND_STANDBY_ON_SLEEP
2460 */
2461 @RequiresPermission(android.Manifest.permission.HDMI_CEC)
2462 public void setTvSendStandbyOnSleep(@NonNull @TvSendStandbyOnSleep int value) {
2463 if (mService == null) {
2464 Log.e(TAG, "HdmiControlService is not available");
2465 throw new RuntimeException("HdmiControlService is not available");
2466 }
2467 try {
2468 mService.setCecSettingIntValue(CEC_SETTING_NAME_TV_SEND_STANDBY_ON_SLEEP, value);
2469 } catch (RemoteException e) {
2470 throw e.rethrowFromSystemServer();
2471 }
2472 }
2473
2474 /**
2475 * Get the current status of TV send &lt;Standby&gt; on Sleep.
2476 *
2477 * <p>Reflects whether the device will also turn off other CEC devices
2478 * when it goes to standby mode.
2479 *
2480 * @see HdmiControlManager#CEC_SETTING_NAME_TV_SEND_STANDBY_ON_SLEEP
2481 */
2482 @NonNull
2483 @TvSendStandbyOnSleep
2484 @RequiresPermission(android.Manifest.permission.HDMI_CEC)
2485 public int getTvSendStandbyOnSleep() {
2486 if (mService == null) {
2487 Log.e(TAG, "HdmiControlService is not available");
2488 throw new RuntimeException("HdmiControlService is not available");
2489 }
2490 try {
2491 return mService.getCecSettingIntValue(CEC_SETTING_NAME_TV_SEND_STANDBY_ON_SLEEP);
2492 } catch (RemoteException e) {
2493 throw e.rethrowFromSystemServer();
2494 }
2495 }
2496
2497 /**
2498 * Set presence of one Short Audio Descriptor (SAD) in the query.
2499 *
2500 * <p>Allows the caller to specify whether the SAD for a specific audio codec should be
2501 * present in the &lt;Request Short Audio Descriptor&gt; query. Each &lt;Request Short Audio
2502 * Descriptor&gt; message can carry at most 4 SADs at a time. This method allows the caller to
2503 * limit the amount of SADs queried and therefore limit the amount of CEC messages on the bus.
2504 *
2505 * <p>When an ARC connection is established, the TV sends a
2506 * &lt;Request Short Audio Descriptor&gt; query to the Audio System that it's connected to. If
2507 * an SAD is queried and the Audio System reports that it supports that SAD, the TV can send
2508 * audio in that format to be output on the Audio System via ARC.
2509 * If a codec is not queried, the TV doesn't know if the connected Audio System supports this
2510 * SAD and doesn't send audio in that format to the Audio System.
2511 *
2512 * @param setting SAD to set.
2513 * @param value Presence to set the SAD to.
2514 */
2515 @RequiresPermission(android.Manifest.permission.HDMI_CEC)
2516 public void setSadPresenceInQuery(@NonNull @CecSettingSad String setting,
2517 @SadPresenceInQuery int value) {
2518 if (mService == null) {
2519 Log.e(TAG, "HdmiControlService is not available");
2520 throw new RuntimeException("HdmiControlService is not available");
2521 }
2522 try {
2523 mService.setCecSettingIntValue(setting, value);
2524 } catch (RemoteException e) {
2525 throw e.rethrowFromSystemServer();
2526 }
2527 }
2528
2529 /**
2530 * Set presence of multiple Short Audio Descriptors (SADs) in the query.
2531 *
2532 * <p>Allows the caller to specify whether the SADs for specific audio codecs should be present
2533 * in the &lt;Request Short Audio Descriptor&gt; query. For audio codecs that are not specified,
2534 * the SAD's presence remains at its previous value. Each &lt;Request Short Audio Descriptor&gt;
2535 * message can carry at most 4 SADs at a time. This method allows the caller to limit the amount
2536 * of SADs queried and therefore limit the amount of CEC messages on the bus.
2537 *
2538 * <p>When an ARC connection is established, the TV sends a
2539 * &lt;Request Short Audio Descriptor&gt; query to the Audio System that it's connected to. If
2540 * an SAD is queried and the Audio System reports that it supports that SAD, the TV can send
2541 * audio in that format to be output on the Audio System via ARC.
2542 * If a codec is not queried, the TV doesn't know if the connected Audio System supports this
2543 * SAD and doesn't send audio in that format to the Audio System.
2544 *
2545 *
2546 * @param settings SADs to set.
2547 * @param value Presence to set all specified SADs to.
2548 */
2549 @RequiresPermission(android.Manifest.permission.HDMI_CEC)
2550 public void setSadsPresenceInQuery(@NonNull @CecSettingSad List<String> settings,
2551 @SadPresenceInQuery int value) {
2552 if (mService == null) {
2553 Log.e(TAG, "HdmiControlService is not available");
2554 throw new RuntimeException("HdmiControlService is not available");
2555 }
2556 try {
2557 for (String sad : settings) {
2558 mService.setCecSettingIntValue(sad, value);
2559 }
2560 } catch (RemoteException e) {
2561 throw e.rethrowFromSystemServer();
2562 }
2563 }
2564
2565 /**
2566 * Get presence of one Short Audio Descriptor (SAD) in the query.
2567 *
2568 * <p>Reflects whether the SAD for a specific audio codec should be present in the
2569 * &lt;Request Short Audio Descriptor&gt; query.
2570 *
2571 * <p>When an ARC connection is established, the TV sends a
2572 * &lt;Request Short Audio Descriptor&gt; query to the Audio System that it's connected to. If
2573 * an SAD is queried and the Audio System reports that it supports that SAD, the TV can send
2574 * audio in that format to be output on the Audio System via ARC.
2575 * If a codec is not queried, the TV doesn't know if the connected Audio System supports this
2576 * SAD and doesn't send audio in that format to the Audio System.
2577 *
2578 * @param setting SAD to get.
2579 * @return Current presence of the specified SAD.
2580 */
2581 @SadPresenceInQuery
2582 @RequiresPermission(android.Manifest.permission.HDMI_CEC)
2583 public int getSadPresenceInQuery(@NonNull @CecSettingSad String setting) {
2584 if (mService == null) {
2585 Log.e(TAG, "HdmiControlService is not available");
2586 throw new RuntimeException("HdmiControlService is not available");
2587 }
2588 try {
2589 return mService.getCecSettingIntValue(setting);
2590 } catch (RemoteException e) {
2591 throw e.rethrowFromSystemServer();
2592 }
2593 }
2594 }