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 package android.hardware.hdmi; 17 18 import android.annotation.SystemApi; 19 import android.os.Parcel; 20 import android.os.Parcelable; 21 22 /** 23 * A class to encapsulate HDMI port information. Contains the capability of the ports such as 24 * HDMI-CEC, MHL, ARC(Audio Return Channel), and physical address assigned to each port. 25 * 26 * @hide 27 */ 28 @SystemApi 29 public final class HdmiPortInfo implements Parcelable { 30 /** HDMI port type: Input */ 31 public static final int PORT_INPUT = 0; 32 33 /** HDMI port type: Output */ 34 public static final int PORT_OUTPUT = 1; 35 36 private final int mId; 37 private final int mType; 38 private final int mAddress; 39 private final boolean mCecSupported; 40 private final boolean mArcSupported; 41 private final boolean mMhlSupported; 42 43 /** 44 * Constructor. 45 * 46 * @param id identifier assigned to each port. 1 for HDMI port 1 47 * @param type HDMI port input/output type 48 * @param address physical address of the port 49 * @param cec {@code true} if HDMI-CEC is supported on the port 50 * @param mhl {@code true} if MHL is supported on the port 51 * @param arc {@code true} if audio return channel is supported on the port 52 */ HdmiPortInfo(int id, int type, int address, boolean cec, boolean mhl, boolean arc)53 public HdmiPortInfo(int id, int type, int address, boolean cec, boolean mhl, boolean arc) { 54 mId = id; 55 mType = type; 56 mAddress = address; 57 mCecSupported = cec; 58 mArcSupported = arc; 59 mMhlSupported = mhl; 60 } 61 62 /** 63 * Returns the port id. 64 * 65 * @return port id 66 */ getId()67 public int getId() { 68 return mId; 69 } 70 71 /** 72 * Returns the port type. 73 * 74 * @return port type 75 */ getType()76 public int getType() { 77 return mType; 78 } 79 80 /** 81 * Returns the port address. 82 * 83 * @return port address 84 */ getAddress()85 public int getAddress() { 86 return mAddress; 87 } 88 89 /** 90 * Returns {@code true} if the port supports HDMI-CEC signaling. 91 * 92 * @return {@code true} if the port supports HDMI-CEC signaling. 93 */ isCecSupported()94 public boolean isCecSupported() { 95 return mCecSupported; 96 } 97 98 /** 99 * Returns {@code true} if the port supports MHL signaling. 100 * 101 * @return {@code true} if the port supports MHL signaling. 102 */ isMhlSupported()103 public boolean isMhlSupported() { 104 return mMhlSupported; 105 } 106 107 /** 108 * Returns {@code true} if the port supports audio return channel. 109 * 110 * @return {@code true} if the port supports audio return channel 111 */ isArcSupported()112 public boolean isArcSupported() { 113 return mArcSupported; 114 } 115 116 /** 117 * Describes the kinds of special objects contained in this Parcelable's 118 * marshalled representation. 119 */ 120 @Override describeContents()121 public int describeContents() { 122 return 0; 123 } 124 125 126 /** 127 * A helper class to deserialize {@link HdmiPortInfo} for a parcel. 128 */ 129 public static final Parcelable.Creator<HdmiPortInfo> CREATOR = 130 new Parcelable.Creator<HdmiPortInfo>() { 131 @Override 132 public HdmiPortInfo createFromParcel(Parcel source) { 133 int id = source.readInt(); 134 int type = source.readInt(); 135 int address = source.readInt(); 136 boolean cec = (source.readInt() == 1); 137 boolean arc = (source.readInt() == 1); 138 boolean mhl = (source.readInt() == 1); 139 return new HdmiPortInfo(id, type, address, cec, mhl, arc); 140 } 141 142 @Override 143 public HdmiPortInfo[] newArray(int size) { 144 return new HdmiPortInfo[size]; 145 } 146 }; 147 148 /** 149 * Serializes this object into a {@link Parcel}. 150 * 151 * @param dest The Parcel in which the object should be written. 152 * @param flags Additional flags about how the object should be written. 153 * May be 0 or {@link Parcelable#PARCELABLE_WRITE_RETURN_VALUE}. 154 */ 155 @Override writeToParcel(Parcel dest, int flags)156 public void writeToParcel(Parcel dest, int flags) { 157 dest.writeInt(mId); 158 dest.writeInt(mType); 159 dest.writeInt(mAddress); 160 dest.writeInt(mCecSupported ? 1 : 0); 161 dest.writeInt(mArcSupported ? 1 : 0); 162 dest.writeInt(mMhlSupported ? 1 : 0); 163 } 164 165 @Override toString()166 public String toString() { 167 StringBuffer s = new StringBuffer(); 168 s.append("port_id: ").append(mId).append(", "); 169 s.append("address: ").append(String.format("0x%04x", mAddress)).append(", "); 170 s.append("cec: ").append(mCecSupported).append(", "); 171 s.append("arc: ").append(mArcSupported).append(", "); 172 s.append("mhl: ").append(mMhlSupported); 173 return s.toString(); 174 } 175 176 @Override equals(Object o)177 public boolean equals(Object o) { 178 if (!(o instanceof HdmiPortInfo)) { 179 return false; 180 } 181 final HdmiPortInfo other = (HdmiPortInfo) o; 182 return mId == other.mId && mType == other.mType && mAddress == other.mAddress 183 && mCecSupported == other.mCecSupported && mArcSupported == other.mArcSupported 184 && mMhlSupported == other.mMhlSupported; 185 } 186 } 187