1 /*
2  * Copyright (C) 2020 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 com.android.libraries.tv.tvsystem.display;
18 
19 import android.annotation.IntDef;
20 
21 import java.lang.annotation.Retention;
22 import java.lang.annotation.RetentionPolicy;
23 import java.util.Objects;
24 
25 /**
26  * Product-specific information about the display or the directly connected device on the
27  * display chain. For example, if the display is transitively connected, this field may contain
28  * product information about the intermediate device.
29  */
30 public final class DeviceProductInfo {
31     /** @hide */
32     @IntDef(prefix = {"CONNECTION_TO_SINK_"}, value = {
33             CONNECTION_TO_SINK_UNKNOWN,
34             CONNECTION_TO_SINK_BUILT_IN,
35             CONNECTION_TO_SINK_DIRECT,
36             CONNECTION_TO_SINK_TRANSITIVE
37     })
38     @Retention(RetentionPolicy.SOURCE)
39     public @interface ConnectionToSinkType { }
40 
41     /** The device connection to the display sink is unknown. */
42     public static final int CONNECTION_TO_SINK_UNKNOWN = 0;
43 
44     /** The display sink is built-in to the device */
45     public static final int CONNECTION_TO_SINK_BUILT_IN = 1;
46 
47     /** The device is directly connected to the display sink. */
48     public static final int CONNECTION_TO_SINK_DIRECT = 2;
49 
50     /** The device is transitively connected to the display sink. */
51     public static final int CONNECTION_TO_SINK_TRANSITIVE = 3;
52 
53     private final String mName;
54     private final String mManufacturerPnpId;
55     private final String mProductId;
56     private final Integer mModelYear;
57     private final ManufactureDate mManufactureDate;
58     private final @ConnectionToSinkType int mConnectionToSinkType;
59 
60     /** @deprecated use
61      * {@link #DeviceProductInfo(String, String, String, Integer, ManufactureDate, int)} ()}
62      * instead.*/
63     @Deprecated
DeviceProductInfo( String name, String manufacturerPnpId, String productId, Integer modelYear, ManufactureDate manufactureDate, int[] relativeAddress)64     public DeviceProductInfo(
65             String name,
66             String manufacturerPnpId,
67             String productId,
68             Integer modelYear,
69             ManufactureDate manufactureDate,
70             int[] relativeAddress) {
71         this.mName = name;
72         this.mManufacturerPnpId = manufacturerPnpId;
73         this.mProductId = productId;
74         this.mModelYear = modelYear;
75         this.mManufactureDate = manufactureDate;
76         this.mConnectionToSinkType = CONNECTION_TO_SINK_UNKNOWN;
77     }
78 
79     /** @hide */
DeviceProductInfo( String name, String manufacturerPnpId, String productId, Integer modelYear, ManufactureDate manufactureDate, int connectionToSinkType)80     public DeviceProductInfo(
81             String name,
82             String manufacturerPnpId,
83             String productId,
84             Integer modelYear,
85             ManufactureDate manufactureDate,
86             int connectionToSinkType) {
87         this.mName = name;
88         this.mManufacturerPnpId = manufacturerPnpId;
89         this.mProductId = productId;
90         this.mModelYear = modelYear;
91         this.mManufactureDate = manufactureDate;
92         this.mConnectionToSinkType = connectionToSinkType;
93     }
94 
95     /**
96      * @return Display name.
97      */
getName()98     public String getName() {
99         return mName;
100     }
101 
102     /**
103      * @return Manufacturer Plug and Play ID.
104      */
getManufacturerPnpId()105     public String getManufacturerPnpId() {
106         return mManufacturerPnpId;
107     }
108 
109     /**
110      * @return Manufacturer product ID.
111      */
getProductId()112     public String getProductId() {
113         return mProductId;
114     }
115 
116     /**
117      * @return Model year of the device. Typically exactly one of model year or
118      *      manufacture date will be present.
119      */
getModelYear()120     public Integer getModelYear() {
121         return mModelYear;
122     }
123 
124     /**
125      * @return Manufacture date. Typically exactly one of model year or manufacture
126      * date will be present.
127      */
getManufactureDate()128     public ManufactureDate getManufactureDate() {
129         return mManufactureDate;
130     }
131 
132     /**
133      * @return Relative address in the display network. For example, for HDMI connected devices this
134      * can be its physical address. Each component of the address is in the range [0, 255].
135      *
136      * @deprecated use {@link #getConnectionToSinkType()} instead.
137      */
138     @Deprecated
getRelativeAddress()139     public int[] getRelativeAddress() {
140         return null;
141     }
142 
143     /**
144      * @return How the current device is connected to the display sink. For example, the display
145      * can be connected immediately to the device or there can be a receiver in between.
146      */
147     @ConnectionToSinkType
getConnectionToSinkType()148     public int getConnectionToSinkType() {
149         return mConnectionToSinkType;
150     }
151 
152     @Override
toString()153     public String toString() {
154         return "DeviceProductInfo{"
155                 + "name="
156                 + mName
157                 + ", manufacturerPnpId="
158                 + mManufacturerPnpId
159                 + ", productId="
160                 + mProductId
161                 + ", modelYear="
162                 + mModelYear
163                 + ", manufactureDate="
164                 + mManufactureDate
165                 + ", connectionToSinkType="
166                 + mConnectionToSinkType
167                 + '}';
168     }
169 
170     @Override
equals(Object o)171     public boolean equals(Object o) {
172         if (this == o) return true;
173         if (o == null || getClass() != o.getClass()) return false;
174         DeviceProductInfo that = (DeviceProductInfo) o;
175         return Objects.equals(mName, that.mName)
176                 && Objects.equals(mManufacturerPnpId, that.mManufacturerPnpId)
177                 && Objects.equals(mProductId, that.mProductId)
178                 && Objects.equals(mModelYear, that.mModelYear)
179                 && Objects.equals(mManufactureDate, that.mManufactureDate)
180                 && mConnectionToSinkType == that.mConnectionToSinkType;
181     }
182 
183     @Override
hashCode()184     public int hashCode() {
185         return Objects.hash(mName, mManufacturerPnpId, mProductId, mModelYear, mManufactureDate,
186                 mConnectionToSinkType);
187     }
188 
189     /**
190      * Stores information about the date of manufacture.
191      */
192     public static class ManufactureDate {
193         private final Integer mWeek;
194         private final Integer mYear;
195 
ManufactureDate(Integer week, Integer year)196         public ManufactureDate(Integer week, Integer year) {
197             mWeek = week;
198             mYear = year;
199         }
200 
getYear()201         public Integer getYear() {
202             return mYear;
203         }
204 
getWeek()205         public Integer getWeek() {
206             return mWeek;
207         }
208 
209         @Override
toString()210         public String toString() {
211             return "ManufactureDate{week=" + mWeek + ", year=" + mYear + '}';
212         }
213 
214         @Override
equals(Object o)215         public boolean equals(Object o) {
216             if (this == o) return true;
217             if (o == null || getClass() != o.getClass()) return false;
218             ManufactureDate that = (ManufactureDate) o;
219             return Objects.equals(mWeek, that.mWeek) && Objects.equals(mYear, that.mYear);
220         }
221 
222         @Override
hashCode()223         public int hashCode() {
224             return Objects.hash(mWeek, mYear);
225         }
226     }
227 }