Wonsik Kim | c22dbb6 | 2014-05-26 02:26:04 +0000 | [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 | |
Jae Seo | d5cc4a2 | 2014-05-30 16:57:43 -0700 | [diff] [blame] | 17 | package android.media.tv; |
Wonsik Kim | c22dbb6 | 2014-05-26 02:26:04 +0000 | [diff] [blame] | 18 | |
Shubang | 71d5c76 | 2017-02-23 15:46:40 -0800 | [diff] [blame] | 19 | import static java.lang.annotation.RetentionPolicy.SOURCE; |
| 20 | |
| 21 | import android.annotation.IntDef; |
Ji-Hwan Lee | d811af2 | 2014-07-18 21:39:57 +0900 | [diff] [blame] | 22 | import android.annotation.SystemApi; |
Shubang | 39f285d | 2017-03-21 12:56:08 -0700 | [diff] [blame] | 23 | import android.hardware.tv.input.V1_0.Constants; |
Wonsik Kim | d7c2918 | 2014-05-27 10:38:21 +0900 | [diff] [blame] | 24 | import android.media.AudioManager; |
Wonsik Kim | c22dbb6 | 2014-05-26 02:26:04 +0000 | [diff] [blame] | 25 | import android.os.Parcel; |
| 26 | import android.os.Parcelable; |
| 27 | import android.util.Log; |
Shubang | 71d5c76 | 2017-02-23 15:46:40 -0800 | [diff] [blame] | 28 | import java.lang.annotation.Retention; |
Wonsik Kim | c22dbb6 | 2014-05-26 02:26:04 +0000 | [diff] [blame] | 29 | |
| 30 | /** |
| 31 | * Simple container for information about TV input hardware. |
| 32 | * Not for third-party developers. |
| 33 | * |
| 34 | * @hide |
| 35 | */ |
Ji-Hwan Lee | d811af2 | 2014-07-18 21:39:57 +0900 | [diff] [blame] | 36 | @SystemApi |
Wonsik Kim | c22dbb6 | 2014-05-26 02:26:04 +0000 | [diff] [blame] | 37 | public final class TvInputHardwareInfo implements Parcelable { |
| 38 | static final String TAG = "TvInputHardwareInfo"; |
| 39 | |
| 40 | // Match hardware/libhardware/include/hardware/tv_input.h |
Shubang | 39f285d | 2017-03-21 12:56:08 -0700 | [diff] [blame] | 41 | public static final int TV_INPUT_TYPE_OTHER_HARDWARE = Constants.TV_INPUT_TYPE_OTHER; |
| 42 | public static final int TV_INPUT_TYPE_TUNER = Constants.TV_INPUT_TYPE_TUNER; |
| 43 | public static final int TV_INPUT_TYPE_COMPOSITE = Constants.TV_INPUT_TYPE_COMPOSITE; |
| 44 | public static final int TV_INPUT_TYPE_SVIDEO = Constants.TV_INPUT_TYPE_SVIDEO; |
| 45 | public static final int TV_INPUT_TYPE_SCART = Constants.TV_INPUT_TYPE_SCART; |
| 46 | public static final int TV_INPUT_TYPE_COMPONENT = Constants.TV_INPUT_TYPE_COMPONENT; |
| 47 | public static final int TV_INPUT_TYPE_VGA = Constants.TV_INPUT_TYPE_VGA; |
| 48 | public static final int TV_INPUT_TYPE_DVI = Constants.TV_INPUT_TYPE_DVI; |
| 49 | public static final int TV_INPUT_TYPE_HDMI = Constants.TV_INPUT_TYPE_HDMI; |
| 50 | public static final int TV_INPUT_TYPE_DISPLAY_PORT = Constants.TV_INPUT_TYPE_DISPLAY_PORT; |
Wonsik Kim | c22dbb6 | 2014-05-26 02:26:04 +0000 | [diff] [blame] | 51 | |
Shubang | 71d5c76 | 2017-02-23 15:46:40 -0800 | [diff] [blame] | 52 | /** @hide */ |
| 53 | @Retention(SOURCE) |
| 54 | @IntDef({CABLE_CONNECTION_STATUS_UNKNOWN, CABLE_CONNECTION_STATUS_CONNECTED, |
| 55 | CABLE_CONNECTION_STATUS_DISCONNECTED}) |
| 56 | public @interface CableConnectionStatus {} |
| 57 | |
| 58 | // Match hardware/interfaces/tv/input/1.0/types.hal |
| 59 | /** |
| 60 | * The hardware is unsure about the connection status or does not support cable detection. |
| 61 | */ |
Shubang | 39f285d | 2017-03-21 12:56:08 -0700 | [diff] [blame] | 62 | public static final int CABLE_CONNECTION_STATUS_UNKNOWN = |
| 63 | Constants.CABLE_CONNECTION_STATUS_UNKNOWN; |
Shubang | 71d5c76 | 2017-02-23 15:46:40 -0800 | [diff] [blame] | 64 | |
| 65 | /** |
| 66 | * Cable is connected to the hardware. |
| 67 | */ |
Shubang | 39f285d | 2017-03-21 12:56:08 -0700 | [diff] [blame] | 68 | public static final int CABLE_CONNECTION_STATUS_CONNECTED = |
| 69 | Constants.CABLE_CONNECTION_STATUS_CONNECTED; |
Shubang | 71d5c76 | 2017-02-23 15:46:40 -0800 | [diff] [blame] | 70 | |
| 71 | /** |
| 72 | * Cable is disconnected to the hardware. |
| 73 | */ |
Shubang | 39f285d | 2017-03-21 12:56:08 -0700 | [diff] [blame] | 74 | public static final int CABLE_CONNECTION_STATUS_DISCONNECTED = |
| 75 | Constants.CABLE_CONNECTION_STATUS_DISCONNECTED; |
Shubang | 71d5c76 | 2017-02-23 15:46:40 -0800 | [diff] [blame] | 76 | |
Jeff Sharkey | 9e8f83d | 2019-02-28 12:06:45 -0700 | [diff] [blame^] | 77 | public static final @android.annotation.NonNull Parcelable.Creator<TvInputHardwareInfo> CREATOR = |
Wonsik Kim | c22dbb6 | 2014-05-26 02:26:04 +0000 | [diff] [blame] | 78 | new Parcelable.Creator<TvInputHardwareInfo>() { |
| 79 | @Override |
| 80 | public TvInputHardwareInfo createFromParcel(Parcel source) { |
| 81 | try { |
| 82 | TvInputHardwareInfo info = new TvInputHardwareInfo(); |
| 83 | info.readFromParcel(source); |
| 84 | return info; |
| 85 | } catch (Exception e) { |
| 86 | Log.e(TAG, "Exception creating TvInputHardwareInfo from parcel", e); |
| 87 | return null; |
| 88 | } |
| 89 | } |
| 90 | |
| 91 | @Override |
| 92 | public TvInputHardwareInfo[] newArray(int size) { |
| 93 | return new TvInputHardwareInfo[size]; |
| 94 | } |
| 95 | }; |
| 96 | |
| 97 | private int mDeviceId; |
| 98 | private int mType; |
Wonsik Kim | d7c2918 | 2014-05-27 10:38:21 +0900 | [diff] [blame] | 99 | private int mAudioType; |
| 100 | private String mAudioAddress; |
Wonsik Kim | a358b53 | 2014-06-12 14:56:18 +0900 | [diff] [blame] | 101 | private int mHdmiPortId; |
Shubang | 71d5c76 | 2017-02-23 15:46:40 -0800 | [diff] [blame] | 102 | @CableConnectionStatus |
| 103 | private int mCableConnectionStatus; |
Wonsik Kim | c22dbb6 | 2014-05-26 02:26:04 +0000 | [diff] [blame] | 104 | |
Wonsik Kim | d7c2918 | 2014-05-27 10:38:21 +0900 | [diff] [blame] | 105 | private TvInputHardwareInfo() { |
Wonsik Kim | c22dbb6 | 2014-05-26 02:26:04 +0000 | [diff] [blame] | 106 | } |
| 107 | |
| 108 | public int getDeviceId() { |
| 109 | return mDeviceId; |
| 110 | } |
| 111 | |
| 112 | public int getType() { |
| 113 | return mType; |
| 114 | } |
| 115 | |
Wonsik Kim | d7c2918 | 2014-05-27 10:38:21 +0900 | [diff] [blame] | 116 | public int getAudioType() { |
| 117 | return mAudioType; |
| 118 | } |
| 119 | |
| 120 | public String getAudioAddress() { |
| 121 | return mAudioAddress; |
| 122 | } |
| 123 | |
Wonsik Kim | a358b53 | 2014-06-12 14:56:18 +0900 | [diff] [blame] | 124 | public int getHdmiPortId() { |
| 125 | if (mType != TV_INPUT_TYPE_HDMI) { |
| 126 | throw new IllegalStateException(); |
| 127 | } |
| 128 | return mHdmiPortId; |
| 129 | } |
| 130 | |
Shubang | 71d5c76 | 2017-02-23 15:46:40 -0800 | [diff] [blame] | 131 | /** |
| 132 | * Gets the cable connection status of the hardware. |
| 133 | * |
| 134 | * @return {@code CABLE_CONNECTION_STATUS_CONNECTED} if cable is connected. |
| 135 | * {@code CABLE_CONNECTION_STATUS_DISCONNECTED} if cable is disconnected. |
| 136 | * {@code CABLE_CONNECTION_STATUS_UNKNOWN} if the hardware is unsure about the |
| 137 | * connection status or does not support cable detection. |
| 138 | */ |
| 139 | @CableConnectionStatus |
| 140 | public int getCableConnectionStatus() { |
| 141 | return mCableConnectionStatus; |
| 142 | } |
| 143 | |
Dongwon Kang | 1034df8 | 2014-07-19 13:54:44 +0900 | [diff] [blame] | 144 | @Override |
| 145 | public String toString() { |
| 146 | StringBuilder b = new StringBuilder(128); |
| 147 | b.append("TvInputHardwareInfo {id=").append(mDeviceId); |
| 148 | b.append(", type=").append(mType); |
| 149 | b.append(", audio_type=").append(mAudioType); |
| 150 | b.append(", audio_addr=").append(mAudioAddress); |
| 151 | if (mType == TV_INPUT_TYPE_HDMI) { |
| 152 | b.append(", hdmi_port=").append(mHdmiPortId); |
| 153 | } |
Shubang | 71d5c76 | 2017-02-23 15:46:40 -0800 | [diff] [blame] | 154 | b.append(", cable_connection_status=").append(mCableConnectionStatus); |
Dongwon Kang | 1034df8 | 2014-07-19 13:54:44 +0900 | [diff] [blame] | 155 | b.append("}"); |
| 156 | return b.toString(); |
| 157 | } |
| 158 | |
Wonsik Kim | c22dbb6 | 2014-05-26 02:26:04 +0000 | [diff] [blame] | 159 | // Parcelable |
| 160 | @Override |
| 161 | public int describeContents() { |
| 162 | return 0; |
| 163 | } |
| 164 | |
| 165 | @Override |
| 166 | public void writeToParcel(Parcel dest, int flags) { |
| 167 | dest.writeInt(mDeviceId); |
| 168 | dest.writeInt(mType); |
Wonsik Kim | d7c2918 | 2014-05-27 10:38:21 +0900 | [diff] [blame] | 169 | dest.writeInt(mAudioType); |
| 170 | dest.writeString(mAudioAddress); |
Wonsik Kim | a358b53 | 2014-06-12 14:56:18 +0900 | [diff] [blame] | 171 | if (mType == TV_INPUT_TYPE_HDMI) { |
| 172 | dest.writeInt(mHdmiPortId); |
| 173 | } |
Shubang | 71d5c76 | 2017-02-23 15:46:40 -0800 | [diff] [blame] | 174 | dest.writeInt(mCableConnectionStatus); |
Wonsik Kim | c22dbb6 | 2014-05-26 02:26:04 +0000 | [diff] [blame] | 175 | } |
| 176 | |
| 177 | public void readFromParcel(Parcel source) { |
| 178 | mDeviceId = source.readInt(); |
| 179 | mType = source.readInt(); |
Wonsik Kim | d7c2918 | 2014-05-27 10:38:21 +0900 | [diff] [blame] | 180 | mAudioType = source.readInt(); |
| 181 | mAudioAddress = source.readString(); |
Wonsik Kim | a358b53 | 2014-06-12 14:56:18 +0900 | [diff] [blame] | 182 | if (mType == TV_INPUT_TYPE_HDMI) { |
| 183 | mHdmiPortId = source.readInt(); |
| 184 | } |
Shubang | 71d5c76 | 2017-02-23 15:46:40 -0800 | [diff] [blame] | 185 | mCableConnectionStatus = source.readInt(); |
Wonsik Kim | d7c2918 | 2014-05-27 10:38:21 +0900 | [diff] [blame] | 186 | } |
| 187 | |
| 188 | public static final class Builder { |
| 189 | private Integer mDeviceId = null; |
| 190 | private Integer mType = null; |
| 191 | private int mAudioType = AudioManager.DEVICE_NONE; |
| 192 | private String mAudioAddress = ""; |
Wonsik Kim | a358b53 | 2014-06-12 14:56:18 +0900 | [diff] [blame] | 193 | private Integer mHdmiPortId = null; |
Shubang | 71d5c76 | 2017-02-23 15:46:40 -0800 | [diff] [blame] | 194 | private Integer mCableConnectionStatus = CABLE_CONNECTION_STATUS_UNKNOWN; |
Wonsik Kim | d7c2918 | 2014-05-27 10:38:21 +0900 | [diff] [blame] | 195 | |
| 196 | public Builder() { |
| 197 | } |
| 198 | |
| 199 | public Builder deviceId(int deviceId) { |
| 200 | mDeviceId = deviceId; |
| 201 | return this; |
| 202 | } |
| 203 | |
| 204 | public Builder type(int type) { |
| 205 | mType = type; |
| 206 | return this; |
| 207 | } |
| 208 | |
| 209 | public Builder audioType(int audioType) { |
| 210 | mAudioType = audioType; |
| 211 | return this; |
| 212 | } |
| 213 | |
| 214 | public Builder audioAddress(String audioAddress) { |
| 215 | mAudioAddress = audioAddress; |
| 216 | return this; |
| 217 | } |
| 218 | |
Wonsik Kim | a358b53 | 2014-06-12 14:56:18 +0900 | [diff] [blame] | 219 | public Builder hdmiPortId(int hdmiPortId) { |
| 220 | mHdmiPortId = hdmiPortId; |
| 221 | return this; |
| 222 | } |
| 223 | |
Shubang | 71d5c76 | 2017-02-23 15:46:40 -0800 | [diff] [blame] | 224 | /** |
| 225 | * Sets cable connection status. |
| 226 | */ |
| 227 | public Builder cableConnectionStatus(@CableConnectionStatus int cableConnectionStatus) { |
| 228 | mCableConnectionStatus = cableConnectionStatus; |
| 229 | return this; |
| 230 | } |
| 231 | |
Wonsik Kim | d7c2918 | 2014-05-27 10:38:21 +0900 | [diff] [blame] | 232 | public TvInputHardwareInfo build() { |
| 233 | if (mDeviceId == null || mType == null) { |
| 234 | throw new UnsupportedOperationException(); |
| 235 | } |
Wonsik Kim | a358b53 | 2014-06-12 14:56:18 +0900 | [diff] [blame] | 236 | if ((mType == TV_INPUT_TYPE_HDMI && mHdmiPortId == null) || |
| 237 | (mType != TV_INPUT_TYPE_HDMI && mHdmiPortId != null)) { |
| 238 | throw new UnsupportedOperationException(); |
| 239 | } |
Wonsik Kim | d7c2918 | 2014-05-27 10:38:21 +0900 | [diff] [blame] | 240 | |
| 241 | TvInputHardwareInfo info = new TvInputHardwareInfo(); |
| 242 | info.mDeviceId = mDeviceId; |
| 243 | info.mType = mType; |
| 244 | info.mAudioType = mAudioType; |
| 245 | if (info.mAudioType != AudioManager.DEVICE_NONE) { |
| 246 | info.mAudioAddress = mAudioAddress; |
| 247 | } |
Wonsik Kim | a358b53 | 2014-06-12 14:56:18 +0900 | [diff] [blame] | 248 | if (mHdmiPortId != null) { |
| 249 | info.mHdmiPortId = mHdmiPortId; |
| 250 | } |
Shubang | 71d5c76 | 2017-02-23 15:46:40 -0800 | [diff] [blame] | 251 | info.mCableConnectionStatus = mCableConnectionStatus; |
Wonsik Kim | d7c2918 | 2014-05-27 10:38:21 +0900 | [diff] [blame] | 252 | return info; |
| 253 | } |
Wonsik Kim | c22dbb6 | 2014-05-26 02:26:04 +0000 | [diff] [blame] | 254 | } |
| 255 | } |