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