Jinsuk Kim | 91120c5 | 2014-05-08 17:12:51 +0900 | [diff] [blame] | 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 | |
Amy | 17ee20f | 2018-10-11 11:08:23 -0700 | [diff] [blame] | 19 | import static com.android.internal.os.RoSystemProperties.PROPERTY_HDMI_IS_DEVICE_HDMI_CEC_SWITCH; |
| 20 | |
Amy | 9444cdd | 2019-01-16 13:42:30 -0800 | [diff] [blame] | 21 | import android.annotation.IntDef; |
Amy | f741f34 | 2019-02-28 13:38:23 -0800 | [diff] [blame] | 22 | import android.annotation.NonNull; |
Jinsuk Kim | 91120c5 | 2014-05-08 17:12:51 +0900 | [diff] [blame] | 23 | import android.annotation.Nullable; |
Jeff Sharkey | 98af2e4 | 2018-02-16 10:14:57 -0700 | [diff] [blame] | 24 | import android.annotation.RequiresFeature; |
Jeff Sharkey | bfc4fcd | 2017-06-05 17:38:17 -0600 | [diff] [blame] | 25 | import android.annotation.RequiresPermission; |
Jinsuk Kim | c7eba0f | 2014-07-07 14:18:02 +0900 | [diff] [blame] | 26 | import android.annotation.SdkConstant; |
| 27 | import android.annotation.SdkConstant.SdkConstantType; |
Jeff Sharkey | bfc4fcd | 2017-06-05 17:38:17 -0600 | [diff] [blame] | 28 | import android.annotation.SuppressLint; |
Jinsuk Kim | 66d1eb2 | 2014-06-06 16:12:18 +0900 | [diff] [blame] | 29 | import android.annotation.SystemApi; |
Jeff Sharkey | d86b8fe | 2017-06-02 17:36:26 -0600 | [diff] [blame] | 30 | import android.annotation.SystemService; |
Shubang | 6737319 | 2018-06-08 18:30:15 -0700 | [diff] [blame] | 31 | import android.content.Context; |
| 32 | import android.content.pm.PackageManager; |
Jinsuk Kim | 78d695d | 2014-05-13 16:36:15 +0900 | [diff] [blame] | 33 | import android.os.RemoteException; |
Amy | 17ee20f | 2018-10-11 11:08:23 -0700 | [diff] [blame] | 34 | import android.os.SystemProperties; |
Yuncheol Heo | 2b0da5c | 2014-10-22 14:32:27 +0900 | [diff] [blame] | 35 | import android.util.ArrayMap; |
| 36 | import android.util.Log; |
Jinsuk Kim | 78d695d | 2014-05-13 16:36:15 +0900 | [diff] [blame] | 37 | |
Amy | 9444cdd | 2019-01-16 13:42:30 -0800 | [diff] [blame] | 38 | import com.android.internal.util.Preconditions; |
| 39 | |
Amy | 6f031af | 2018-10-30 16:38:33 -0700 | [diff] [blame] | 40 | import java.util.List; |
| 41 | |
Jinsuk Kim | 91120c5 | 2014-05-08 17:12:51 +0900 | [diff] [blame] | 42 | /** |
| 43 | * The {@link HdmiControlManager} class is used to send HDMI control messages |
| 44 | * to attached CEC devices. |
| 45 | * |
| 46 | * <p>Provides various HDMI client instances that represent HDMI-CEC logical devices |
| 47 | * hosted in the system. {@link #getTvClient()}, for instance will return an |
| 48 | * {@link HdmiTvClient} object if the system is configured to host one. Android system |
| 49 | * can host more than one logical CEC devices. If multiple types are configured they |
| 50 | * all work as if they were independent logical devices running in the system. |
Jinsuk Kim | 66d1eb2 | 2014-06-06 16:12:18 +0900 | [diff] [blame] | 51 | * |
| 52 | * @hide |
Jinsuk Kim | 91120c5 | 2014-05-08 17:12:51 +0900 | [diff] [blame] | 53 | */ |
Jinsuk Kim | 66d1eb2 | 2014-06-06 16:12:18 +0900 | [diff] [blame] | 54 | @SystemApi |
Jeff Sharkey | d86b8fe | 2017-06-02 17:36:26 -0600 | [diff] [blame] | 55 | @SystemService(Context.HDMI_CONTROL_SERVICE) |
Jeff Sharkey | 98af2e4 | 2018-02-16 10:14:57 -0700 | [diff] [blame] | 56 | @RequiresFeature(PackageManager.FEATURE_HDMI_CEC) |
Jinsuk Kim | 91120c5 | 2014-05-08 17:12:51 +0900 | [diff] [blame] | 57 | public final class HdmiControlManager { |
Yuncheol Heo | 2b0da5c | 2014-10-22 14:32:27 +0900 | [diff] [blame] | 58 | private static final String TAG = "HdmiControlManager"; |
| 59 | |
Jinsuk Kim | 91120c5 | 2014-05-08 17:12:51 +0900 | [diff] [blame] | 60 | @Nullable private final IHdmiControlService mService; |
| 61 | |
Amy | ff115f1 | 2018-11-21 14:26:16 -0800 | [diff] [blame] | 62 | private static final int INVALID_PHYSICAL_ADDRESS = 0xFFFF; |
| 63 | |
| 64 | private int mPhysicalAddress = INVALID_PHYSICAL_ADDRESS; |
| 65 | |
Jinsuk Kim | c7eba0f | 2014-07-07 14:18:02 +0900 | [diff] [blame] | 66 | /** |
| 67 | * Broadcast Action: Display OSD message. |
| 68 | * <p>Send when the service has a message to display on screen for events |
| 69 | * that need user's attention such as ARC status change. |
Jungshik Jang | e5a9337 | 2014-07-25 13:41:14 +0900 | [diff] [blame] | 70 | * <p>Always contains the extra fields {@link #EXTRA_MESSAGE_ID}. |
Jinsuk Kim | c7eba0f | 2014-07-07 14:18:02 +0900 | [diff] [blame] | 71 | * <p>Requires {@link android.Manifest.permission#HDMI_CEC} to receive. |
| 72 | */ |
| 73 | @SdkConstant(SdkConstantType.BROADCAST_INTENT_ACTION) |
| 74 | public static final String ACTION_OSD_MESSAGE = "android.hardware.hdmi.action.OSD_MESSAGE"; |
| 75 | |
Jungshik Jang | 339227d | 2014-08-25 15:37:20 +0900 | [diff] [blame] | 76 | // --- Messages for ACTION_OSD_MESSAGE --- |
| 77 | /** |
| 78 | * Message that ARC enabled device is connected to invalid port (non-ARC port). |
| 79 | */ |
| 80 | public static final int OSD_MESSAGE_ARC_CONNECTED_INVALID_PORT = 1; |
| 81 | |
Jinsuk Kim | c7eba0f | 2014-07-07 14:18:02 +0900 | [diff] [blame] | 82 | /** |
Jungshik Jang | 2e8f1b6 | 2014-09-03 08:28:02 +0900 | [diff] [blame] | 83 | * Message used by TV to receive volume status from Audio Receiver. It should check volume value |
Yuncheol Heo | 2b0da5c | 2014-10-22 14:32:27 +0900 | [diff] [blame] | 84 | * that is retrieved from extra value with the key {@link #EXTRA_MESSAGE_EXTRA_PARAM1}. If the |
Jungshik Jang | 2e8f1b6 | 2014-09-03 08:28:02 +0900 | [diff] [blame] | 85 | * value is in range of [0,100], it is current volume of Audio Receiver. And there is another |
| 86 | * value, {@link #AVR_VOLUME_MUTED}, which is used to inform volume mute. |
| 87 | */ |
| 88 | public static final int OSD_MESSAGE_AVR_VOLUME_CHANGED = 2; |
| 89 | |
| 90 | /** |
Jinsuk Kim | c7eba0f | 2014-07-07 14:18:02 +0900 | [diff] [blame] | 91 | * Used as an extra field in the intent {@link #ACTION_OSD_MESSAGE}. Contains the ID of |
| 92 | * the message to display on screen. |
| 93 | */ |
| 94 | public static final String EXTRA_MESSAGE_ID = "android.hardware.hdmi.extra.MESSAGE_ID"; |
Jungshik Jang | 2e8f1b6 | 2014-09-03 08:28:02 +0900 | [diff] [blame] | 95 | /** |
| 96 | * Used as an extra field in the intent {@link #ACTION_OSD_MESSAGE}. Contains the extra value |
| 97 | * of the message. |
| 98 | */ |
Yuncheol Heo | 2b0da5c | 2014-10-22 14:32:27 +0900 | [diff] [blame] | 99 | public static final String EXTRA_MESSAGE_EXTRA_PARAM1 = |
Jungshik Jang | 2e8f1b6 | 2014-09-03 08:28:02 +0900 | [diff] [blame] | 100 | "android.hardware.hdmi.extra.MESSAGE_EXTRA_PARAM1"; |
| 101 | |
| 102 | /** |
| 103 | * Volume value for mute state. |
| 104 | */ |
| 105 | public static final int AVR_VOLUME_MUTED = 101; |
Jinsuk Kim | c7eba0f | 2014-07-07 14:18:02 +0900 | [diff] [blame] | 106 | |
Jinsuk Kim | c0c20d0 | 2014-07-04 14:34:31 +0900 | [diff] [blame] | 107 | public static final int POWER_STATUS_UNKNOWN = -1; |
| 108 | public static final int POWER_STATUS_ON = 0; |
| 109 | public static final int POWER_STATUS_STANDBY = 1; |
| 110 | public static final int POWER_STATUS_TRANSIENT_TO_ON = 2; |
| 111 | public static final int POWER_STATUS_TRANSIENT_TO_STANDBY = 3; |
| 112 | |
Amy | 9444cdd | 2019-01-16 13:42:30 -0800 | [diff] [blame] | 113 | @IntDef ({ |
| 114 | RESULT_SUCCESS, |
| 115 | RESULT_TIMEOUT, |
| 116 | RESULT_SOURCE_NOT_AVAILABLE, |
| 117 | RESULT_TARGET_NOT_AVAILABLE, |
| 118 | RESULT_ALREADY_IN_PROGRESS, |
| 119 | RESULT_EXCEPTION, |
| 120 | RESULT_INCORRECT_MODE, |
| 121 | RESULT_COMMUNICATION_FAILED, |
| 122 | }) |
| 123 | public @interface ControlCallbackResult {} |
| 124 | |
| 125 | /** Control operation is successfully handled by the framework. */ |
Jinsuk Kim | c0c20d0 | 2014-07-04 14:34:31 +0900 | [diff] [blame] | 126 | public static final int RESULT_SUCCESS = 0; |
| 127 | public static final int RESULT_TIMEOUT = 1; |
Amy | 9444cdd | 2019-01-16 13:42:30 -0800 | [diff] [blame] | 128 | /** Source device that the application is using is not available. */ |
Jinsuk Kim | c0c20d0 | 2014-07-04 14:34:31 +0900 | [diff] [blame] | 129 | public static final int RESULT_SOURCE_NOT_AVAILABLE = 2; |
Amy | 9444cdd | 2019-01-16 13:42:30 -0800 | [diff] [blame] | 130 | /** Target device that the application is controlling is not available. */ |
Jinsuk Kim | c0c20d0 | 2014-07-04 14:34:31 +0900 | [diff] [blame] | 131 | public static final int RESULT_TARGET_NOT_AVAILABLE = 3; |
Jinsuk Kim | cb80287 | 2015-10-13 08:22:09 +0900 | [diff] [blame] | 132 | |
| 133 | @Deprecated public static final int RESULT_ALREADY_IN_PROGRESS = 4; |
Jinsuk Kim | c0c20d0 | 2014-07-04 14:34:31 +0900 | [diff] [blame] | 134 | public static final int RESULT_EXCEPTION = 5; |
| 135 | public static final int RESULT_INCORRECT_MODE = 6; |
Jinsuk Kim | b38cd68 | 2014-07-07 08:05:03 +0900 | [diff] [blame] | 136 | public static final int RESULT_COMMUNICATION_FAILED = 7; |
Jinsuk Kim | c0c20d0 | 2014-07-04 14:34:31 +0900 | [diff] [blame] | 137 | |
Jungshik Jang | 61daf6b | 2014-08-08 11:38:28 +0900 | [diff] [blame] | 138 | public static final int DEVICE_EVENT_ADD_DEVICE = 1; |
| 139 | public static final int DEVICE_EVENT_REMOVE_DEVICE = 2; |
| 140 | public static final int DEVICE_EVENT_UPDATE_DEVICE = 3; |
| 141 | |
Jungshik Jang | 12e5dce | 2014-07-24 15:27:44 +0900 | [diff] [blame] | 142 | // --- One Touch Recording success result |
Jungshik Jang | b6591b8 | 2014-07-23 16:10:23 +0900 | [diff] [blame] | 143 | /** Recording currently selected source. Indicates the status of a recording. */ |
Jungshik Jang | 12e5dce | 2014-07-24 15:27:44 +0900 | [diff] [blame] | 144 | public static final int ONE_TOUCH_RECORD_RECORDING_CURRENTLY_SELECTED_SOURCE = 0x01; |
Jungshik Jang | b6591b8 | 2014-07-23 16:10:23 +0900 | [diff] [blame] | 145 | /** Recording Digital Service. Indicates the status of a recording. */ |
Jungshik Jang | 12e5dce | 2014-07-24 15:27:44 +0900 | [diff] [blame] | 146 | public static final int ONE_TOUCH_RECORD_RECORDING_DIGITAL_SERVICE = 0x02; |
Jungshik Jang | b6591b8 | 2014-07-23 16:10:23 +0900 | [diff] [blame] | 147 | /** Recording Analogue Service. Indicates the status of a recording. */ |
Jungshik Jang | 12e5dce | 2014-07-24 15:27:44 +0900 | [diff] [blame] | 148 | public static final int ONE_TOUCH_RECORD_RECORDING_ANALOGUE_SERVICE = 0x03; |
Jungshik Jang | b6591b8 | 2014-07-23 16:10:23 +0900 | [diff] [blame] | 149 | /** Recording External input. Indicates the status of a recording. */ |
Jungshik Jang | 12e5dce | 2014-07-24 15:27:44 +0900 | [diff] [blame] | 150 | public static final int ONE_TOUCH_RECORD_RECORDING_EXTERNAL_INPUT = 0x04; |
| 151 | |
| 152 | // --- One Touch Record failure result |
Jungshik Jang | b6591b8 | 2014-07-23 16:10:23 +0900 | [diff] [blame] | 153 | /** No recording – unable to record Digital Service. No suitable tuner. */ |
Jungshik Jang | 12e5dce | 2014-07-24 15:27:44 +0900 | [diff] [blame] | 154 | public static final int ONE_TOUCH_RECORD_UNABLE_DIGITAL_SERVICE = 0x05; |
Jungshik Jang | b6591b8 | 2014-07-23 16:10:23 +0900 | [diff] [blame] | 155 | /** No recording – unable to record Analogue Service. No suitable tuner. */ |
Jungshik Jang | 12e5dce | 2014-07-24 15:27:44 +0900 | [diff] [blame] | 156 | public static final int ONE_TOUCH_RECORD_UNABLE_ANALOGUE_SERVICE = 0x06; |
Jungshik Jang | b6591b8 | 2014-07-23 16:10:23 +0900 | [diff] [blame] | 157 | /** |
| 158 | * No recording – unable to select required service. as suitable tuner, but the requested |
| 159 | * parameters are invalid or out of range for that tuner. |
| 160 | */ |
Jungshik Jang | 12e5dce | 2014-07-24 15:27:44 +0900 | [diff] [blame] | 161 | public static final int ONE_TOUCH_RECORD_UNABLE_SELECTED_SERVICE = 0x07; |
Jungshik Jang | b6591b8 | 2014-07-23 16:10:23 +0900 | [diff] [blame] | 162 | /** No recording – invalid External plug number */ |
Jungshik Jang | 12e5dce | 2014-07-24 15:27:44 +0900 | [diff] [blame] | 163 | public static final int ONE_TOUCH_RECORD_INVALID_EXTERNAL_PLUG_NUMBER = 0x09; |
Jungshik Jang | b6591b8 | 2014-07-23 16:10:23 +0900 | [diff] [blame] | 164 | /** No recording – invalid External Physical Address */ |
Jungshik Jang | 12e5dce | 2014-07-24 15:27:44 +0900 | [diff] [blame] | 165 | public static final int ONE_TOUCH_RECORD_INVALID_EXTERNAL_PHYSICAL_ADDRESS = 0x0A; |
Jungshik Jang | b6591b8 | 2014-07-23 16:10:23 +0900 | [diff] [blame] | 166 | /** No recording – CA system not supported */ |
Jungshik Jang | 12e5dce | 2014-07-24 15:27:44 +0900 | [diff] [blame] | 167 | public static final int ONE_TOUCH_RECORD_UNSUPPORTED_CA = 0x0B; |
Jungshik Jang | b6591b8 | 2014-07-23 16:10:23 +0900 | [diff] [blame] | 168 | /** No Recording – No or Insufficient CA Entitlements” */ |
Jungshik Jang | 12e5dce | 2014-07-24 15:27:44 +0900 | [diff] [blame] | 169 | public static final int ONE_TOUCH_RECORD_NO_OR_INSUFFICIENT_CA_ENTITLEMENTS = 0x0C; |
Jungshik Jang | b6591b8 | 2014-07-23 16:10:23 +0900 | [diff] [blame] | 170 | /** No recording – Not allowed to copy source. Source is “copy never”. */ |
Jungshik Jang | 12e5dce | 2014-07-24 15:27:44 +0900 | [diff] [blame] | 171 | public static final int ONE_TOUCH_RECORD_DISALLOW_TO_COPY = 0x0D; |
Jungshik Jang | b6591b8 | 2014-07-23 16:10:23 +0900 | [diff] [blame] | 172 | /** No recording – No further copies allowed */ |
Jungshik Jang | 12e5dce | 2014-07-24 15:27:44 +0900 | [diff] [blame] | 173 | public static final int ONE_TOUCH_RECORD_DISALLOW_TO_FUTHER_COPIES = 0x0E; |
Jungshik Jang | b6591b8 | 2014-07-23 16:10:23 +0900 | [diff] [blame] | 174 | /** No recording – No media */ |
Jungshik Jang | 12e5dce | 2014-07-24 15:27:44 +0900 | [diff] [blame] | 175 | public static final int ONE_TOUCH_RECORD_NO_MEDIA = 0x10; |
Jungshik Jang | b6591b8 | 2014-07-23 16:10:23 +0900 | [diff] [blame] | 176 | /** No recording – playing */ |
Jungshik Jang | 12e5dce | 2014-07-24 15:27:44 +0900 | [diff] [blame] | 177 | public static final int ONE_TOUCH_RECORD_PLAYING = 0x11; |
Jungshik Jang | b6591b8 | 2014-07-23 16:10:23 +0900 | [diff] [blame] | 178 | /** No recording – already recording */ |
Jungshik Jang | 12e5dce | 2014-07-24 15:27:44 +0900 | [diff] [blame] | 179 | public static final int ONE_TOUCH_RECORD_ALREADY_RECORDING = 0x12; |
Jungshik Jang | b6591b8 | 2014-07-23 16:10:23 +0900 | [diff] [blame] | 180 | /** No recording – media protected */ |
Jungshik Jang | 12e5dce | 2014-07-24 15:27:44 +0900 | [diff] [blame] | 181 | public static final int ONE_TOUCH_RECORD_MEDIA_PROTECTED = 0x13; |
Jungshik Jang | b6591b8 | 2014-07-23 16:10:23 +0900 | [diff] [blame] | 182 | /** No recording – no source signal */ |
Jungshik Jang | 12e5dce | 2014-07-24 15:27:44 +0900 | [diff] [blame] | 183 | public static final int ONE_TOUCH_RECORD_NO_SOURCE_SIGNAL = 0x14; |
Jungshik Jang | b6591b8 | 2014-07-23 16:10:23 +0900 | [diff] [blame] | 184 | /** No recording – media problem */ |
Jungshik Jang | 12e5dce | 2014-07-24 15:27:44 +0900 | [diff] [blame] | 185 | public static final int ONE_TOUCH_RECORD_MEDIA_PROBLEM = 0x15; |
Jungshik Jang | b6591b8 | 2014-07-23 16:10:23 +0900 | [diff] [blame] | 186 | /** No recording – not enough space available */ |
Jungshik Jang | 12e5dce | 2014-07-24 15:27:44 +0900 | [diff] [blame] | 187 | public static final int ONE_TOUCH_RECORD_NOT_ENOUGH_SPACE = 0x16; |
Jungshik Jang | b6591b8 | 2014-07-23 16:10:23 +0900 | [diff] [blame] | 188 | /** No recording – Parental Lock On */ |
Jungshik Jang | 12e5dce | 2014-07-24 15:27:44 +0900 | [diff] [blame] | 189 | public static final int ONE_TOUCH_RECORD_PARENT_LOCK_ON = 0x17; |
Jungshik Jang | b6591b8 | 2014-07-23 16:10:23 +0900 | [diff] [blame] | 190 | /** Recording terminated normally */ |
Jungshik Jang | 12e5dce | 2014-07-24 15:27:44 +0900 | [diff] [blame] | 191 | public static final int ONE_TOUCH_RECORD_RECORDING_TERMINATED_NORMALLY = 0x1A; |
Jungshik Jang | b6591b8 | 2014-07-23 16:10:23 +0900 | [diff] [blame] | 192 | /** Recording has already terminated */ |
Jungshik Jang | 12e5dce | 2014-07-24 15:27:44 +0900 | [diff] [blame] | 193 | public static final int ONE_TOUCH_RECORD_RECORDING_ALREADY_TERMINATED = 0x1B; |
Jungshik Jang | b6591b8 | 2014-07-23 16:10:23 +0900 | [diff] [blame] | 194 | /** No recording – other reason */ |
Jungshik Jang | 12e5dce | 2014-07-24 15:27:44 +0900 | [diff] [blame] | 195 | public static final int ONE_TOUCH_RECORD_OTHER_REASON = 0x1F; |
Jungshik Jang | b6591b8 | 2014-07-23 16:10:23 +0900 | [diff] [blame] | 196 | // From here extra message for recording that is not mentioned in CEC spec |
| 197 | /** No recording. Previous recording request in progress. */ |
Jungshik Jang | 12e5dce | 2014-07-24 15:27:44 +0900 | [diff] [blame] | 198 | public static final int ONE_TOUCH_RECORD_PREVIOUS_RECORDING_IN_PROGRESS = 0x30; |
Jungshik Jang | b6591b8 | 2014-07-23 16:10:23 +0900 | [diff] [blame] | 199 | /** No recording. Please check recorder and connection. */ |
Jungshik Jang | 12e5dce | 2014-07-24 15:27:44 +0900 | [diff] [blame] | 200 | public static final int ONE_TOUCH_RECORD_CHECK_RECORDER_CONNECTION = 0x31; |
Jungshik Jang | b6591b8 | 2014-07-23 16:10:23 +0900 | [diff] [blame] | 201 | /** Cannot record currently displayed source. */ |
Jungshik Jang | 12e5dce | 2014-07-24 15:27:44 +0900 | [diff] [blame] | 202 | public static final int ONE_TOUCH_RECORD_FAIL_TO_RECORD_DISPLAYED_SCREEN = 0x32; |
| 203 | /** CEC is disabled. */ |
| 204 | public static final int ONE_TOUCH_RECORD_CEC_DISABLED = 0x33; |
Jungshik Jang | b6591b8 | 2014-07-23 16:10:23 +0900 | [diff] [blame] | 205 | |
Jungshik Jang | 12e5dce | 2014-07-24 15:27:44 +0900 | [diff] [blame] | 206 | // --- Types for timer recording |
Jungshik Jang | b6591b8 | 2014-07-23 16:10:23 +0900 | [diff] [blame] | 207 | /** Timer recording type for digital service source. */ |
| 208 | public static final int TIMER_RECORDING_TYPE_DIGITAL = 1; |
| 209 | /** Timer recording type for analogue service source. */ |
| 210 | public static final int TIMER_RECORDING_TYPE_ANALOGUE = 2; |
| 211 | /** Timer recording type for external source. */ |
| 212 | public static final int TIMER_RECORDING_TYPE_EXTERNAL = 3; |
| 213 | |
Jungshik Jang | e5a9337 | 2014-07-25 13:41:14 +0900 | [diff] [blame] | 214 | // --- Timer Status Data |
| 215 | /** [Timer Status Data/Media Info] - Media present and not protected. */ |
| 216 | public static final int TIMER_STATUS_MEDIA_INFO_PRESENT_NOT_PROTECTED = 0x0; |
| 217 | /** [Timer Status Data/Media Info] - Media present, but protected. */ |
| 218 | public static final int TIMER_STATUS_MEDIA_INFO_PRESENT_PROTECTED = 0x1; |
| 219 | /** [Timer Status Data/Media Info] - Media not present. */ |
| 220 | public static final int TIMER_STATUS_MEDIA_INFO_NOT_PRESENT = 0x2; |
| 221 | |
| 222 | /** [Timer Status Data/Programmed Info] - Enough space available for recording. */ |
| 223 | public static final int TIMER_STATUS_PROGRAMMED_INFO_ENOUGH_SPACE = 0x8; |
| 224 | /** [Timer Status Data/Programmed Info] - Not enough space available for recording. */ |
| 225 | public static final int TIMER_STATUS_PROGRAMMED_INFO_NOT_ENOUGH_SPACE = 0x9; |
| 226 | /** [Timer Status Data/Programmed Info] - Might not enough space available for recording. */ |
| 227 | public static final int TIMER_STATUS_PROGRAMMED_INFO_MIGHT_NOT_ENOUGH_SPACE = 0xB; |
| 228 | /** [Timer Status Data/Programmed Info] - No media info available. */ |
| 229 | public static final int TIMER_STATUS_PROGRAMMED_INFO_NO_MEDIA_INFO = 0xA; |
| 230 | |
| 231 | /** [Timer Status Data/Not Programmed Error Info] - No free timer available. */ |
| 232 | public static final int TIMER_STATUS_NOT_PROGRAMMED_NO_FREE_TIME = 0x1; |
| 233 | /** [Timer Status Data/Not Programmed Error Info] - Date out of range. */ |
| 234 | public static final int TIMER_STATUS_NOT_PROGRAMMED_DATE_OUT_OF_RANGE = 0x2; |
| 235 | /** [Timer Status Data/Not Programmed Error Info] - Recording Sequence error. */ |
| 236 | public static final int TIMER_STATUS_NOT_PROGRAMMED_INVALID_SEQUENCE = 0x3; |
| 237 | /** [Timer Status Data/Not Programmed Error Info] - Invalid External Plug Number. */ |
| 238 | public static final int TIMER_STATUS_NOT_PROGRAMMED_INVALID_EXTERNAL_PLUG_NUMBER = 0x4; |
| 239 | /** [Timer Status Data/Not Programmed Error Info] - Invalid External Physical Address. */ |
| 240 | public static final int TIMER_STATUS_NOT_PROGRAMMED_INVALID_EXTERNAL_PHYSICAL_NUMBER = 0x5; |
| 241 | /** [Timer Status Data/Not Programmed Error Info] - CA system not supported. */ |
| 242 | public static final int TIMER_STATUS_NOT_PROGRAMMED_CA_NOT_SUPPORTED = 0x6; |
| 243 | /** [Timer Status Data/Not Programmed Error Info] - No or insufficient CA Entitlements. */ |
| 244 | public static final int TIMER_STATUS_NOT_PROGRAMMED_NO_CA_ENTITLEMENTS = 0x7; |
| 245 | /** [Timer Status Data/Not Programmed Error Info] - Does not support resolution. */ |
| 246 | public static final int TIMER_STATUS_NOT_PROGRAMMED_UNSUPPORTED_RESOLUTION = 0x8; |
| 247 | /** [Timer Status Data/Not Programmed Error Info] - Parental Lock On. */ |
| 248 | public static final int TIMER_STATUS_NOT_PROGRAMMED_PARENTAL_LOCK_ON= 0x9; |
| 249 | /** [Timer Status Data/Not Programmed Error Info] - Clock Failure. */ |
| 250 | public static final int TIMER_STATUS_NOT_PROGRAMMED_CLOCK_FAILURE = 0xA; |
| 251 | /** [Timer Status Data/Not Programmed Error Info] - Duplicate: already programmed. */ |
| 252 | public static final int TIMER_STATUS_NOT_PROGRAMMED_DUPLICATED = 0xE; |
| 253 | |
Jungshik Jang | 12e5dce | 2014-07-24 15:27:44 +0900 | [diff] [blame] | 254 | // --- Extra result value for timer recording. |
Jungshik Jang | e5a9337 | 2014-07-25 13:41:14 +0900 | [diff] [blame] | 255 | /** No extra error. */ |
| 256 | public static final int TIMER_RECORDING_RESULT_EXTRA_NO_ERROR = 0x00; |
Jungshik Jang | 12e5dce | 2014-07-24 15:27:44 +0900 | [diff] [blame] | 257 | /** No timer recording - check recorder and connection. */ |
Jungshik Jang | e5a9337 | 2014-07-25 13:41:14 +0900 | [diff] [blame] | 258 | public static final int TIMER_RECORDING_RESULT_EXTRA_CHECK_RECORDER_CONNECTION = 0x01; |
Jungshik Jang | 12e5dce | 2014-07-24 15:27:44 +0900 | [diff] [blame] | 259 | /** No timer recording - cannot record selected source. */ |
Jungshik Jang | e5a9337 | 2014-07-25 13:41:14 +0900 | [diff] [blame] | 260 | public static final int TIMER_RECORDING_RESULT_EXTRA_FAIL_TO_RECORD_SELECTED_SOURCE = 0x02; |
Jungshik Jang | 12e5dce | 2014-07-24 15:27:44 +0900 | [diff] [blame] | 261 | /** CEC is disabled. */ |
Jungshik Jang | e5a9337 | 2014-07-25 13:41:14 +0900 | [diff] [blame] | 262 | public static final int TIMER_RECORDING_RESULT_EXTRA_CEC_DISABLED = 0x03; |
| 263 | |
| 264 | // -- Timer cleared status data code used for result of onClearTimerRecordingResult. |
| 265 | /** Timer not cleared – recording. */ |
| 266 | public static final int CLEAR_TIMER_STATUS_TIMER_NOT_CLEARED_RECORDING = 0x00; |
| 267 | /** Timer not cleared – no matching. */ |
| 268 | public static final int CLEAR_TIMER_STATUS_TIMER_NOT_CLEARED_NO_MATCHING = 0x01; |
| 269 | /** Timer not cleared – no info available. */ |
| 270 | public static final int CLEAR_TIMER_STATUS_TIMER_NOT_CLEARED_NO_INFO_AVAILABLE = 0x02; |
| 271 | /** Timer cleared. */ |
| 272 | public static final int CLEAR_TIMER_STATUS_TIMER_CLEARED = 0x80; |
| 273 | /** Clear timer error - check recorder and connection. */ |
| 274 | public static final int CLEAR_TIMER_STATUS_CHECK_RECORDER_CONNECTION = 0xA0; |
| 275 | /** Clear timer error - cannot clear timer for selected source. */ |
| 276 | public static final int CLEAR_TIMER_STATUS_FAIL_TO_CLEAR_SELECTED_SOURCE = 0xA1; |
| 277 | /** Clear timer error - CEC is disabled. */ |
| 278 | public static final int CLEAR_TIMER_STATUS_CEC_DISABLE = 0xA2; |
Jungshik Jang | 12e5dce | 2014-07-24 15:27:44 +0900 | [diff] [blame] | 279 | |
Yuncheol Heo | 0608b93 | 2014-10-13 16:39:18 +0900 | [diff] [blame] | 280 | /** The HdmiControlService is started. */ |
| 281 | public static final int CONTROL_STATE_CHANGED_REASON_START = 0; |
| 282 | /** The state of HdmiControlService is changed by changing of settings. */ |
| 283 | public static final int CONTROL_STATE_CHANGED_REASON_SETTING = 1; |
| 284 | /** The HdmiControlService is enabled to wake up. */ |
| 285 | public static final int CONTROL_STATE_CHANGED_REASON_WAKEUP = 2; |
| 286 | /** The HdmiControlService will be disabled to standby. */ |
| 287 | public static final int CONTROL_STATE_CHANGED_REASON_STANDBY = 3; |
| 288 | |
Jinsuk Kim | 78d695d | 2014-05-13 16:36:15 +0900 | [diff] [blame] | 289 | // True if we have a logical device of type playback hosted in the system. |
| 290 | private final boolean mHasPlaybackDevice; |
| 291 | // True if we have a logical device of type TV hosted in the system. |
| 292 | private final boolean mHasTvDevice; |
Shubang | 6737319 | 2018-06-08 18:30:15 -0700 | [diff] [blame] | 293 | // True if we have a logical device of type audio system hosted in the system. |
| 294 | private final boolean mHasAudioSystemDevice; |
Amy | 17ee20f | 2018-10-11 11:08:23 -0700 | [diff] [blame] | 295 | // True if we have a logical device of type audio system hosted in the system. |
| 296 | private final boolean mHasSwitchDevice; |
| 297 | // True if it's a switch device. |
| 298 | private final boolean mIsSwitchDevice; |
Jinsuk Kim | 78d695d | 2014-05-13 16:36:15 +0900 | [diff] [blame] | 299 | |
Jinsuk Kim | 91120c5 | 2014-05-08 17:12:51 +0900 | [diff] [blame] | 300 | /** |
Yuncheol Heo | 2b0da5c | 2014-10-22 14:32:27 +0900 | [diff] [blame] | 301 | * {@hide} - hide this constructor because it has a parameter of type IHdmiControlService, |
| 302 | * which is a system private class. The right way to create an instance of this class is |
| 303 | * using the factory Context.getSystemService. |
Jinsuk Kim | 91120c5 | 2014-05-08 17:12:51 +0900 | [diff] [blame] | 304 | */ |
| 305 | public HdmiControlManager(IHdmiControlService service) { |
| 306 | mService = service; |
Jinsuk Kim | 78d695d | 2014-05-13 16:36:15 +0900 | [diff] [blame] | 307 | int[] types = null; |
| 308 | if (mService != null) { |
| 309 | try { |
| 310 | types = mService.getSupportedTypes(); |
| 311 | } catch (RemoteException e) { |
Jeff Sharkey | c53962d | 2016-03-01 19:27:23 -0700 | [diff] [blame] | 312 | throw e.rethrowFromSystemServer(); |
Jinsuk Kim | 78d695d | 2014-05-13 16:36:15 +0900 | [diff] [blame] | 313 | } |
| 314 | } |
Jungshik Jang | 61f4fbd | 2014-08-06 19:21:12 +0900 | [diff] [blame] | 315 | mHasTvDevice = hasDeviceType(types, HdmiDeviceInfo.DEVICE_TV); |
| 316 | mHasPlaybackDevice = hasDeviceType(types, HdmiDeviceInfo.DEVICE_PLAYBACK); |
Shubang | 6737319 | 2018-06-08 18:30:15 -0700 | [diff] [blame] | 317 | mHasAudioSystemDevice = hasDeviceType(types, HdmiDeviceInfo.DEVICE_AUDIO_SYSTEM); |
Amy | 17ee20f | 2018-10-11 11:08:23 -0700 | [diff] [blame] | 318 | mHasSwitchDevice = hasDeviceType(types, HdmiDeviceInfo.DEVICE_PURE_CEC_SWITCH); |
| 319 | mIsSwitchDevice = SystemProperties.getBoolean( |
| 320 | PROPERTY_HDMI_IS_DEVICE_HDMI_CEC_SWITCH, false); |
Jinsuk Kim | 78d695d | 2014-05-13 16:36:15 +0900 | [diff] [blame] | 321 | } |
| 322 | |
| 323 | private static boolean hasDeviceType(int[] types, int type) { |
| 324 | if (types == null) { |
| 325 | return false; |
| 326 | } |
| 327 | for (int t : types) { |
| 328 | if (t == type) { |
| 329 | return true; |
| 330 | } |
| 331 | } |
| 332 | return false; |
Jinsuk Kim | 91120c5 | 2014-05-08 17:12:51 +0900 | [diff] [blame] | 333 | } |
| 334 | |
| 335 | /** |
Jinsuk Kim | 6ffb038 | 2014-08-01 19:13:53 +0900 | [diff] [blame] | 336 | * Gets an object that represents an HDMI-CEC logical device of a specified type. |
| 337 | * |
| 338 | * @param type CEC device type |
| 339 | * @return {@link HdmiClient} instance. {@code null} on failure. |
Jungshik Jang | 61f4fbd | 2014-08-06 19:21:12 +0900 | [diff] [blame] | 340 | * See {@link HdmiDeviceInfo#DEVICE_PLAYBACK} |
| 341 | * See {@link HdmiDeviceInfo#DEVICE_TV} |
Shubang | 6737319 | 2018-06-08 18:30:15 -0700 | [diff] [blame] | 342 | * See {@link HdmiDeviceInfo#DEVICE_AUDIO_SYSTEM} |
Jinsuk Kim | 6ffb038 | 2014-08-01 19:13:53 +0900 | [diff] [blame] | 343 | */ |
| 344 | @Nullable |
Jeff Sharkey | bfc4fcd | 2017-06-05 17:38:17 -0600 | [diff] [blame] | 345 | @SuppressLint("Doclava125") |
Jinsuk Kim | 6ffb038 | 2014-08-01 19:13:53 +0900 | [diff] [blame] | 346 | public HdmiClient getClient(int type) { |
| 347 | if (mService == null) { |
| 348 | return null; |
| 349 | } |
| 350 | switch (type) { |
Jungshik Jang | 61f4fbd | 2014-08-06 19:21:12 +0900 | [diff] [blame] | 351 | case HdmiDeviceInfo.DEVICE_TV: |
Jinsuk Kim | 6ffb038 | 2014-08-01 19:13:53 +0900 | [diff] [blame] | 352 | return mHasTvDevice ? new HdmiTvClient(mService) : null; |
Jungshik Jang | 61f4fbd | 2014-08-06 19:21:12 +0900 | [diff] [blame] | 353 | case HdmiDeviceInfo.DEVICE_PLAYBACK: |
Jinsuk Kim | 6ffb038 | 2014-08-01 19:13:53 +0900 | [diff] [blame] | 354 | return mHasPlaybackDevice ? new HdmiPlaybackClient(mService) : null; |
Shubang | 6737319 | 2018-06-08 18:30:15 -0700 | [diff] [blame] | 355 | case HdmiDeviceInfo.DEVICE_AUDIO_SYSTEM: |
| 356 | return mHasAudioSystemDevice ? new HdmiAudioSystemClient(mService) : null; |
Amy | 17ee20f | 2018-10-11 11:08:23 -0700 | [diff] [blame] | 357 | case HdmiDeviceInfo.DEVICE_PURE_CEC_SWITCH: |
| 358 | return (mHasSwitchDevice || mIsSwitchDevice) |
| 359 | ? new HdmiSwitchClient(mService) : null; |
Jinsuk Kim | 6ffb038 | 2014-08-01 19:13:53 +0900 | [diff] [blame] | 360 | default: |
| 361 | return null; |
| 362 | } |
| 363 | } |
| 364 | |
| 365 | /** |
| 366 | * Gets an object that represents an HDMI-CEC logical device of type playback on the system. |
Jinsuk Kim | 91120c5 | 2014-05-08 17:12:51 +0900 | [diff] [blame] | 367 | * |
| 368 | * <p>Used to send HDMI control messages to other devices like TV or audio amplifier through |
| 369 | * HDMI bus. It is also possible to communicate with other logical devices hosted in the same |
| 370 | * system if the system is configured to host more than one type of HDMI-CEC logical devices. |
| 371 | * |
| 372 | * @return {@link HdmiPlaybackClient} instance. {@code null} on failure. |
| 373 | */ |
| 374 | @Nullable |
Jeff Sharkey | bfc4fcd | 2017-06-05 17:38:17 -0600 | [diff] [blame] | 375 | @SuppressLint("Doclava125") |
Jinsuk Kim | 91120c5 | 2014-05-08 17:12:51 +0900 | [diff] [blame] | 376 | public HdmiPlaybackClient getPlaybackClient() { |
Jungshik Jang | 61f4fbd | 2014-08-06 19:21:12 +0900 | [diff] [blame] | 377 | return (HdmiPlaybackClient) getClient(HdmiDeviceInfo.DEVICE_PLAYBACK); |
Jinsuk Kim | 91120c5 | 2014-05-08 17:12:51 +0900 | [diff] [blame] | 378 | } |
| 379 | |
| 380 | /** |
Jinsuk Kim | 6ffb038 | 2014-08-01 19:13:53 +0900 | [diff] [blame] | 381 | * Gets an object that represents an HDMI-CEC logical device of type TV on the system. |
Jinsuk Kim | 91120c5 | 2014-05-08 17:12:51 +0900 | [diff] [blame] | 382 | * |
| 383 | * <p>Used to send HDMI control messages to other devices and manage them through |
| 384 | * HDMI bus. It is also possible to communicate with other logical devices hosted in the same |
| 385 | * system if the system is configured to host more than one type of HDMI-CEC logical devices. |
| 386 | * |
| 387 | * @return {@link HdmiTvClient} instance. {@code null} on failure. |
| 388 | */ |
| 389 | @Nullable |
Jeff Sharkey | bfc4fcd | 2017-06-05 17:38:17 -0600 | [diff] [blame] | 390 | @SuppressLint("Doclava125") |
Jinsuk Kim | 91120c5 | 2014-05-08 17:12:51 +0900 | [diff] [blame] | 391 | public HdmiTvClient getTvClient() { |
Jungshik Jang | 61f4fbd | 2014-08-06 19:21:12 +0900 | [diff] [blame] | 392 | return (HdmiTvClient) getClient(HdmiDeviceInfo.DEVICE_TV); |
Jinsuk Kim | 91120c5 | 2014-05-08 17:12:51 +0900 | [diff] [blame] | 393 | } |
Jinsuk Kim | 78d695d | 2014-05-13 16:36:15 +0900 | [diff] [blame] | 394 | |
| 395 | /** |
Shubang | 6737319 | 2018-06-08 18:30:15 -0700 | [diff] [blame] | 396 | * Gets an object that represents an HDMI-CEC logical device of type audio system on the system. |
| 397 | * |
| 398 | * <p>Used to send HDMI control messages to other devices like TV through HDMI bus. It is also |
| 399 | * possible to communicate with other logical devices hosted in the same system if the system is |
| 400 | * configured to host more than one type of HDMI-CEC logical devices. |
| 401 | * |
| 402 | * @return {@link HdmiAudioSystemClient} instance. {@code null} on failure. |
| 403 | * |
| 404 | * TODO(b/110094868): unhide for Q |
| 405 | * @hide |
| 406 | */ |
| 407 | @Nullable |
| 408 | @SuppressLint("Doclava125") |
| 409 | public HdmiAudioSystemClient getAudioSystemClient() { |
| 410 | return (HdmiAudioSystemClient) getClient(HdmiDeviceInfo.DEVICE_AUDIO_SYSTEM); |
| 411 | } |
| 412 | |
| 413 | /** |
Amy | 17ee20f | 2018-10-11 11:08:23 -0700 | [diff] [blame] | 414 | * Gets an object that represents an HDMI-CEC logical device of type switch on the system. |
| 415 | * |
Amy | 9444cdd | 2019-01-16 13:42:30 -0800 | [diff] [blame] | 416 | * <p>Used to send HDMI control messages to other devices (e.g. TVs) through HDMI bus. |
| 417 | * It is also possible to communicate with other logical devices hosted in the same |
| 418 | * system if the system is configured to host more than one type of HDMI-CEC logical device. |
Amy | 17ee20f | 2018-10-11 11:08:23 -0700 | [diff] [blame] | 419 | * |
| 420 | * @return {@link HdmiSwitchClient} instance. {@code null} on failure. |
Amy | 17ee20f | 2018-10-11 11:08:23 -0700 | [diff] [blame] | 421 | * @hide |
| 422 | */ |
| 423 | @Nullable |
Amy | 9444cdd | 2019-01-16 13:42:30 -0800 | [diff] [blame] | 424 | @SystemApi |
Amy | 17ee20f | 2018-10-11 11:08:23 -0700 | [diff] [blame] | 425 | @SuppressLint("Doclava125") |
| 426 | public HdmiSwitchClient getSwitchClient() { |
| 427 | return (HdmiSwitchClient) getClient(HdmiDeviceInfo.DEVICE_PURE_CEC_SWITCH); |
| 428 | } |
| 429 | |
| 430 | /** |
Amy | 6f031af | 2018-10-30 16:38:33 -0700 | [diff] [blame] | 431 | * Get a snapshot of the real-time status of the remote devices. |
| 432 | * |
Amy | 9444cdd | 2019-01-16 13:42:30 -0800 | [diff] [blame] | 433 | * <p>This only applies to devices with multiple HDMI inputs. |
Amy | 6f031af | 2018-10-30 16:38:33 -0700 | [diff] [blame] | 434 | * |
Amy | 9444cdd | 2019-01-16 13:42:30 -0800 | [diff] [blame] | 435 | * @return a list of {@link HdmiDeviceInfo} of the connected CEC devices. An empty |
| 436 | * list will be returned if there is none. |
| 437 | * |
Amy | 6f031af | 2018-10-30 16:38:33 -0700 | [diff] [blame] | 438 | * @hide |
| 439 | */ |
Amy | 9444cdd | 2019-01-16 13:42:30 -0800 | [diff] [blame] | 440 | @SystemApi |
| 441 | @Nullable |
Amy | 6f031af | 2018-10-30 16:38:33 -0700 | [diff] [blame] | 442 | public List<HdmiDeviceInfo> getConnectedDevicesList() { |
| 443 | try { |
| 444 | return mService.getDeviceList(); |
| 445 | } catch (RemoteException e) { |
| 446 | throw e.rethrowFromSystemServer(); |
| 447 | } |
| 448 | } |
| 449 | |
| 450 | /** |
Amy | 9444cdd | 2019-01-16 13:42:30 -0800 | [diff] [blame] | 451 | * Power off the target device by sending CEC commands. |
Amy | 6f031af | 2018-10-30 16:38:33 -0700 | [diff] [blame] | 452 | * |
Amy | 9444cdd | 2019-01-16 13:42:30 -0800 | [diff] [blame] | 453 | * <p>The target device info can be obtained by calling {@link #getConnectedDevicesList()}. |
Amy | 6f031af | 2018-10-30 16:38:33 -0700 | [diff] [blame] | 454 | * |
Amy | 9444cdd | 2019-01-16 13:42:30 -0800 | [diff] [blame] | 455 | * @param deviceInfo {@link HdmiDeviceInfo} of the device to be powered off. |
| 456 | * |
Amy | 6f031af | 2018-10-30 16:38:33 -0700 | [diff] [blame] | 457 | * @hide |
| 458 | */ |
Amy | 9444cdd | 2019-01-16 13:42:30 -0800 | [diff] [blame] | 459 | @SystemApi |
Amy | f741f34 | 2019-02-28 13:38:23 -0800 | [diff] [blame] | 460 | public void powerOffRemoteDevice(@NonNull HdmiDeviceInfo deviceInfo) { |
Amy | 9444cdd | 2019-01-16 13:42:30 -0800 | [diff] [blame] | 461 | Preconditions.checkNotNull(deviceInfo); |
Amy | 6f031af | 2018-10-30 16:38:33 -0700 | [diff] [blame] | 462 | try { |
| 463 | mService.powerOffRemoteDevice( |
| 464 | deviceInfo.getLogicalAddress(), deviceInfo.getDevicePowerStatus()); |
| 465 | } catch (RemoteException e) { |
| 466 | throw e.rethrowFromSystemServer(); |
| 467 | } |
| 468 | } |
| 469 | |
| 470 | /** |
Amy | 9444cdd | 2019-01-16 13:42:30 -0800 | [diff] [blame] | 471 | * Power on the target device by sending CEC commands. |
Amy | 6f031af | 2018-10-30 16:38:33 -0700 | [diff] [blame] | 472 | * |
Amy | 9444cdd | 2019-01-16 13:42:30 -0800 | [diff] [blame] | 473 | * <p>The target device info can be obtained by calling {@link #getConnectedDevicesList()}. |
Amy | 6f031af | 2018-10-30 16:38:33 -0700 | [diff] [blame] | 474 | * |
Amy | 9444cdd | 2019-01-16 13:42:30 -0800 | [diff] [blame] | 475 | * @param deviceInfo {@link HdmiDeviceInfo} of the device to be powered on. |
| 476 | * |
Amy | 6f031af | 2018-10-30 16:38:33 -0700 | [diff] [blame] | 477 | * @hide |
| 478 | */ |
| 479 | public void powerOnRemoteDevice(HdmiDeviceInfo deviceInfo) { |
Amy | 9444cdd | 2019-01-16 13:42:30 -0800 | [diff] [blame] | 480 | Preconditions.checkNotNull(deviceInfo); |
Amy | 6f031af | 2018-10-30 16:38:33 -0700 | [diff] [blame] | 481 | try { |
| 482 | mService.powerOnRemoteDevice( |
| 483 | deviceInfo.getLogicalAddress(), deviceInfo.getDevicePowerStatus()); |
| 484 | } catch (RemoteException e) { |
| 485 | throw e.rethrowFromSystemServer(); |
| 486 | } |
| 487 | } |
| 488 | |
| 489 | /** |
Amy | 9444cdd | 2019-01-16 13:42:30 -0800 | [diff] [blame] | 490 | * Request the target device to be the new Active Source by sending CEC commands. |
| 491 | * |
| 492 | * <p>The target device info can be obtained by calling {@link #getConnectedDevicesList()}. |
Amy | 6f031af | 2018-10-30 16:38:33 -0700 | [diff] [blame] | 493 | * |
| 494 | * @param deviceInfo HdmiDeviceInfo of the target device |
| 495 | * |
Amy | 6f031af | 2018-10-30 16:38:33 -0700 | [diff] [blame] | 496 | * @hide |
| 497 | */ |
Amy | 9444cdd | 2019-01-16 13:42:30 -0800 | [diff] [blame] | 498 | @SystemApi |
Amy | f741f34 | 2019-02-28 13:38:23 -0800 | [diff] [blame] | 499 | public void requestRemoteDeviceToBecomeActiveSource(@NonNull HdmiDeviceInfo deviceInfo) { |
Amy | 9444cdd | 2019-01-16 13:42:30 -0800 | [diff] [blame] | 500 | Preconditions.checkNotNull(deviceInfo); |
Amy | 6f031af | 2018-10-30 16:38:33 -0700 | [diff] [blame] | 501 | try { |
| 502 | mService.askRemoteDeviceToBecomeActiveSource(deviceInfo.getPhysicalAddress()); |
| 503 | } catch (RemoteException e) { |
| 504 | throw e.rethrowFromSystemServer(); |
| 505 | } |
| 506 | } |
| 507 | |
| 508 | /** |
Donghyun Cho | b351564 | 2017-03-02 13:47:40 +0900 | [diff] [blame] | 509 | * Controls standby mode of the system. It will also try to turn on/off the connected devices if |
| 510 | * necessary. |
| 511 | * |
| 512 | * @param isStandbyModeOn target status of the system's standby mode |
| 513 | */ |
Jeff Sharkey | bfc4fcd | 2017-06-05 17:38:17 -0600 | [diff] [blame] | 514 | @RequiresPermission(android.Manifest.permission.HDMI_CEC) |
Donghyun Cho | b351564 | 2017-03-02 13:47:40 +0900 | [diff] [blame] | 515 | public void setStandbyMode(boolean isStandbyModeOn) { |
| 516 | try { |
| 517 | mService.setStandbyMode(isStandbyModeOn); |
| 518 | } catch (RemoteException e) { |
| 519 | throw e.rethrowFromSystemServer(); |
| 520 | } |
| 521 | } |
| 522 | |
| 523 | /** |
Shubang Lu | 00b976a | 2018-08-01 18:11:46 -0700 | [diff] [blame] | 524 | * Gets whether the system is in system audio mode. |
| 525 | * |
| 526 | * @hide |
| 527 | */ |
| 528 | public boolean getSystemAudioMode() { |
| 529 | try { |
| 530 | return mService.getSystemAudioMode(); |
| 531 | } catch (RemoteException e) { |
| 532 | throw e.rethrowFromSystemServer(); |
| 533 | } |
| 534 | } |
| 535 | |
| 536 | /** |
Amy | d58d0aa | 2018-10-18 14:08:57 -0700 | [diff] [blame] | 537 | * Get the physical address of the device. |
| 538 | * |
Amy | 9444cdd | 2019-01-16 13:42:30 -0800 | [diff] [blame] | 539 | * <p>Physical address needs to be automatically adjusted when devices are phyiscally or |
| 540 | * electrically added or removed from the device tree. Please see HDMI Specification Version |
| 541 | * 1.4b 8.7 Physical Address for more details on the address discovery proccess. |
| 542 | * |
Amy | d58d0aa | 2018-10-18 14:08:57 -0700 | [diff] [blame] | 543 | * @hide |
| 544 | */ |
Amy | 9444cdd | 2019-01-16 13:42:30 -0800 | [diff] [blame] | 545 | @SystemApi |
Amy | d58d0aa | 2018-10-18 14:08:57 -0700 | [diff] [blame] | 546 | public int getPhysicalAddress() { |
Amy | ff115f1 | 2018-11-21 14:26:16 -0800 | [diff] [blame] | 547 | if (mPhysicalAddress != INVALID_PHYSICAL_ADDRESS) { |
| 548 | return mPhysicalAddress; |
| 549 | } |
Amy | d58d0aa | 2018-10-18 14:08:57 -0700 | [diff] [blame] | 550 | try { |
Amy | ff115f1 | 2018-11-21 14:26:16 -0800 | [diff] [blame] | 551 | mPhysicalAddress = mService.getPhysicalAddress(); |
| 552 | return mPhysicalAddress; |
Amy | d58d0aa | 2018-10-18 14:08:57 -0700 | [diff] [blame] | 553 | } catch (RemoteException e) { |
| 554 | throw e.rethrowFromSystemServer(); |
| 555 | } |
| 556 | } |
| 557 | |
| 558 | /** |
Amy | 9444cdd | 2019-01-16 13:42:30 -0800 | [diff] [blame] | 559 | * Check if the target remote device is connected to the current device. |
| 560 | * |
| 561 | * <p>The API also returns true if the current device is the target. |
Amy | ff115f1 | 2018-11-21 14:26:16 -0800 | [diff] [blame] | 562 | * |
| 563 | * @param targetDevice {@link HdmiDeviceInfo} of the target device. |
Amy | 9444cdd | 2019-01-16 13:42:30 -0800 | [diff] [blame] | 564 | * @return true if {@code targetDevice} is directly or indirectly |
| 565 | * connected to the current device. |
Amy | ff115f1 | 2018-11-21 14:26:16 -0800 | [diff] [blame] | 566 | * |
Amy | ff115f1 | 2018-11-21 14:26:16 -0800 | [diff] [blame] | 567 | * @hide |
| 568 | */ |
Amy | 9444cdd | 2019-01-16 13:42:30 -0800 | [diff] [blame] | 569 | @SystemApi |
Amy | f741f34 | 2019-02-28 13:38:23 -0800 | [diff] [blame] | 570 | public boolean isRemoteDeviceConnected(@NonNull HdmiDeviceInfo targetDevice) { |
Amy | 9444cdd | 2019-01-16 13:42:30 -0800 | [diff] [blame] | 571 | Preconditions.checkNotNull(targetDevice); |
Amy | ff115f1 | 2018-11-21 14:26:16 -0800 | [diff] [blame] | 572 | mPhysicalAddress = getPhysicalAddress(); |
| 573 | if (mPhysicalAddress == INVALID_PHYSICAL_ADDRESS) { |
| 574 | return false; |
| 575 | } |
| 576 | int targetPhysicalAddress = targetDevice.getPhysicalAddress(); |
| 577 | if (targetPhysicalAddress == INVALID_PHYSICAL_ADDRESS) { |
| 578 | return false; |
| 579 | } |
| 580 | return HdmiUtils.getLocalPortFromPhysicalAddress(targetPhysicalAddress, mPhysicalAddress) |
| 581 | != HdmiUtils.TARGET_NOT_UNDER_LOCAL_DEVICE; |
| 582 | } |
| 583 | |
| 584 | /** |
Jinsuk Kim | 78d695d | 2014-05-13 16:36:15 +0900 | [diff] [blame] | 585 | * Listener used to get hotplug event from HDMI port. |
| 586 | */ |
| 587 | public interface HotplugEventListener { |
| 588 | void onReceived(HdmiHotplugEvent event); |
| 589 | } |
| 590 | |
Yuncheol Heo | 2b0da5c | 2014-10-22 14:32:27 +0900 | [diff] [blame] | 591 | private final ArrayMap<HotplugEventListener, IHdmiHotplugEventListener> |
| 592 | mHotplugEventListeners = new ArrayMap<>(); |
| 593 | |
Jinsuk Kim | 78d695d | 2014-05-13 16:36:15 +0900 | [diff] [blame] | 594 | /** |
Jinsuk Kim | 119160a | 2014-07-07 18:48:10 +0900 | [diff] [blame] | 595 | * Listener used to get vendor-specific commands. |
| 596 | */ |
| 597 | public interface VendorCommandListener { |
| 598 | /** |
| 599 | * Called when a vendor command is received. |
| 600 | * |
| 601 | * @param srcAddress source logical address |
Yuncheol Heo | 0608b93 | 2014-10-13 16:39:18 +0900 | [diff] [blame] | 602 | * @param destAddress destination logical address |
Jinsuk Kim | 119160a | 2014-07-07 18:48:10 +0900 | [diff] [blame] | 603 | * @param params vendor-specific parameters |
| 604 | * @param hasVendorId {@code true} if the command is <Vendor Command |
| 605 | * With ID>. The first 3 bytes of params is vendor id. |
| 606 | */ |
Yuncheol Heo | 0608b93 | 2014-10-13 16:39:18 +0900 | [diff] [blame] | 607 | void onReceived(int srcAddress, int destAddress, byte[] params, boolean hasVendorId); |
| 608 | |
| 609 | /** |
| 610 | * The callback is called: |
| 611 | * <ul> |
| 612 | * <li> before HdmiControlService is disabled. |
| 613 | * <li> after HdmiControlService is enabled and the local address is assigned. |
| 614 | * </ul> |
| 615 | * The client shouldn't hold the thread too long since this is a blocking call. |
| 616 | * |
| 617 | * @param enabled {@code true} if HdmiControlService is enabled. |
| 618 | * @param reason the reason code why the state of HdmiControlService is changed. |
| 619 | * @see #CONTROL_STATE_CHANGED_REASON_START |
| 620 | * @see #CONTROL_STATE_CHANGED_REASON_SETTING |
| 621 | * @see #CONTROL_STATE_CHANGED_REASON_WAKEUP |
| 622 | * @see #CONTROL_STATE_CHANGED_REASON_STANDBY |
| 623 | */ |
| 624 | void onControlStateChanged(boolean enabled, int reason); |
Jinsuk Kim | 119160a | 2014-07-07 18:48:10 +0900 | [diff] [blame] | 625 | } |
| 626 | |
| 627 | /** |
Jinsuk Kim | 78d695d | 2014-05-13 16:36:15 +0900 | [diff] [blame] | 628 | * Adds a listener to get informed of {@link HdmiHotplugEvent}. |
| 629 | * |
| 630 | * <p>To stop getting the notification, |
Jinsuk Kim | 9302a73 | 2014-05-22 13:24:55 +0900 | [diff] [blame] | 631 | * use {@link #removeHotplugEventListener(HotplugEventListener)}. |
Jinsuk Kim | 78d695d | 2014-05-13 16:36:15 +0900 | [diff] [blame] | 632 | * |
| 633 | * @param listener {@link HotplugEventListener} instance |
Jinsuk Kim | 9302a73 | 2014-05-22 13:24:55 +0900 | [diff] [blame] | 634 | * @see HdmiControlManager#removeHotplugEventListener(HotplugEventListener) |
Jinsuk Kim | 78d695d | 2014-05-13 16:36:15 +0900 | [diff] [blame] | 635 | */ |
Jeff Sharkey | bfc4fcd | 2017-06-05 17:38:17 -0600 | [diff] [blame] | 636 | @RequiresPermission(android.Manifest.permission.HDMI_CEC) |
Jinsuk Kim | 78d695d | 2014-05-13 16:36:15 +0900 | [diff] [blame] | 637 | public void addHotplugEventListener(HotplugEventListener listener) { |
| 638 | if (mService == null) { |
Yuncheol Heo | 2b0da5c | 2014-10-22 14:32:27 +0900 | [diff] [blame] | 639 | Log.e(TAG, "HdmiControlService is not available"); |
Jinsuk Kim | 78d695d | 2014-05-13 16:36:15 +0900 | [diff] [blame] | 640 | return; |
| 641 | } |
Yuncheol Heo | 2b0da5c | 2014-10-22 14:32:27 +0900 | [diff] [blame] | 642 | if (mHotplugEventListeners.containsKey(listener)) { |
| 643 | Log.e(TAG, "listener is already registered"); |
| 644 | return; |
| 645 | } |
| 646 | IHdmiHotplugEventListener wrappedListener = getHotplugEventListenerWrapper(listener); |
| 647 | mHotplugEventListeners.put(listener, wrappedListener); |
Jinsuk Kim | 78d695d | 2014-05-13 16:36:15 +0900 | [diff] [blame] | 648 | try { |
Yuncheol Heo | 2b0da5c | 2014-10-22 14:32:27 +0900 | [diff] [blame] | 649 | mService.addHotplugEventListener(wrappedListener); |
Jinsuk Kim | 78d695d | 2014-05-13 16:36:15 +0900 | [diff] [blame] | 650 | } catch (RemoteException e) { |
Jeff Sharkey | c53962d | 2016-03-01 19:27:23 -0700 | [diff] [blame] | 651 | throw e.rethrowFromSystemServer(); |
Jinsuk Kim | 78d695d | 2014-05-13 16:36:15 +0900 | [diff] [blame] | 652 | } |
| 653 | } |
| 654 | |
| 655 | /** |
| 656 | * Removes a listener to stop getting informed of {@link HdmiHotplugEvent}. |
| 657 | * |
| 658 | * @param listener {@link HotplugEventListener} instance to be removed |
| 659 | */ |
Jeff Sharkey | bfc4fcd | 2017-06-05 17:38:17 -0600 | [diff] [blame] | 660 | @RequiresPermission(android.Manifest.permission.HDMI_CEC) |
Jinsuk Kim | 9302a73 | 2014-05-22 13:24:55 +0900 | [diff] [blame] | 661 | public void removeHotplugEventListener(HotplugEventListener listener) { |
Jinsuk Kim | 78d695d | 2014-05-13 16:36:15 +0900 | [diff] [blame] | 662 | if (mService == null) { |
Yuncheol Heo | 2b0da5c | 2014-10-22 14:32:27 +0900 | [diff] [blame] | 663 | Log.e(TAG, "HdmiControlService is not available"); |
| 664 | return; |
| 665 | } |
| 666 | IHdmiHotplugEventListener wrappedListener = mHotplugEventListeners.remove(listener); |
| 667 | if (wrappedListener == null) { |
| 668 | Log.e(TAG, "tried to remove not-registered listener"); |
Jinsuk Kim | 78d695d | 2014-05-13 16:36:15 +0900 | [diff] [blame] | 669 | return; |
| 670 | } |
| 671 | try { |
Yuncheol Heo | 2b0da5c | 2014-10-22 14:32:27 +0900 | [diff] [blame] | 672 | mService.removeHotplugEventListener(wrappedListener); |
Jinsuk Kim | 78d695d | 2014-05-13 16:36:15 +0900 | [diff] [blame] | 673 | } catch (RemoteException e) { |
Jeff Sharkey | c53962d | 2016-03-01 19:27:23 -0700 | [diff] [blame] | 674 | throw e.rethrowFromSystemServer(); |
Jinsuk Kim | 78d695d | 2014-05-13 16:36:15 +0900 | [diff] [blame] | 675 | } |
| 676 | } |
| 677 | |
| 678 | private IHdmiHotplugEventListener getHotplugEventListenerWrapper( |
| 679 | final HotplugEventListener listener) { |
| 680 | return new IHdmiHotplugEventListener.Stub() { |
Jungshik Jang | e5a9337 | 2014-07-25 13:41:14 +0900 | [diff] [blame] | 681 | @Override |
Jinsuk Kim | 78d695d | 2014-05-13 16:36:15 +0900 | [diff] [blame] | 682 | public void onReceived(HdmiHotplugEvent event) { |
| 683 | listener.onReceived(event);; |
| 684 | } |
| 685 | }; |
| 686 | } |
Jinsuk Kim | 91120c5 | 2014-05-08 17:12:51 +0900 | [diff] [blame] | 687 | } |