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