1 /*
2  * Copyright (C) 2021 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.view.displayhash;
18 
19 import android.annotation.CurrentTimeMillisLong;
20 import android.annotation.NonNull;
21 import android.graphics.Rect;
22 import android.os.Parcelable;
23 
24 import com.android.internal.util.DataClass;
25 
26 /**
27  * The verified display hash used to validate information about what was present on screen.
28  */
29 @DataClass(genToString = true, genAidl = true)
30 public final class VerifiedDisplayHash implements Parcelable {
31     /**
32      * The timestamp when the hash was generated.
33      */
34     @CurrentTimeMillisLong
35     private final long mTimeMillis;
36 
37     /**
38      * The bounds of the requested area to generate the hash. This is in window space passed in
39      * by the client.
40      */
41     @NonNull
42     private final Rect mBoundsInWindow;
43 
44     /**
45      * The selected hash algorithm that generated the image hash.
46      */
47     @NonNull
48     private final String mHashAlgorithm;
49 
50     /**
51      * The image hash generated when creating the DisplayHash.
52      */
53     @NonNull
54     private final byte[] mImageHash;
55 
imageHashToString()56     private String imageHashToString() {
57         return byteArrayToString(mImageHash);
58     }
59 
byteArrayToString(byte[] byteArray)60     private String byteArrayToString(byte[] byteArray) {
61         if (byteArray == null) {
62             return "null";
63         }
64         int iMax = byteArray.length - 1;
65         if (iMax == -1) {
66             return "[]";
67         }
68 
69         StringBuilder b = new StringBuilder();
70         b.append('[');
71         for (int i = 0; ; i++) {
72             String formatted = String.format("%02X", byteArray[i] & 0xFF);
73             b.append(formatted);
74             if (i == iMax) {
75                 return b.append(']').toString();
76             }
77             b.append(", ");
78         }
79     }
80 
81 
82 
83     // Code below generated by codegen v1.0.23.
84     //
85     // DO NOT MODIFY!
86     // CHECKSTYLE:OFF Generated code
87     //
88     // To regenerate run:
89     // $ codegen $ANDROID_BUILD_TOP/frameworks/base/core/java/android/view/displayhash/VerifiedDisplayHash.java
90     //
91     // To exclude the generated code from IntelliJ auto-formatting enable (one-time):
92     //   Settings > Editor > Code Style > Formatter Control
93     //@formatter:off
94 
95 
96     /**
97      * Creates a new VerifiedDisplayHash.
98      *
99      * @param timeMillis
100      *   The timestamp when the hash was generated.
101      * @param boundsInWindow
102      *   The bounds of the requested area to generate the hash. This is in window space passed in
103      *   by the client.
104      * @param hashAlgorithm
105      *   The selected hash algorithm that generated the image hash.
106      * @param imageHash
107      *   The image hash generated when creating the DisplayHash.
108      */
109     @DataClass.Generated.Member
VerifiedDisplayHash( @urrentTimeMillisLong long timeMillis, @NonNull Rect boundsInWindow, @NonNull String hashAlgorithm, @NonNull byte[] imageHash)110     public VerifiedDisplayHash(
111             @CurrentTimeMillisLong long timeMillis,
112             @NonNull Rect boundsInWindow,
113             @NonNull String hashAlgorithm,
114             @NonNull byte[] imageHash) {
115         this.mTimeMillis = timeMillis;
116         com.android.internal.util.AnnotationValidations.validate(
117                 CurrentTimeMillisLong.class, null, mTimeMillis);
118         this.mBoundsInWindow = boundsInWindow;
119         com.android.internal.util.AnnotationValidations.validate(
120                 NonNull.class, null, mBoundsInWindow);
121         this.mHashAlgorithm = hashAlgorithm;
122         com.android.internal.util.AnnotationValidations.validate(
123                 NonNull.class, null, mHashAlgorithm);
124         this.mImageHash = imageHash;
125         com.android.internal.util.AnnotationValidations.validate(
126                 NonNull.class, null, mImageHash);
127 
128         // onConstructed(); // You can define this method to get a callback
129     }
130 
131     /**
132      * The timestamp when the hash was generated.
133      */
134     @DataClass.Generated.Member
getTimeMillis()135     public @CurrentTimeMillisLong long getTimeMillis() {
136         return mTimeMillis;
137     }
138 
139     /**
140      * The bounds of the requested area to generate the hash. This is in window space passed in
141      * by the client.
142      */
143     @DataClass.Generated.Member
getBoundsInWindow()144     public @NonNull Rect getBoundsInWindow() {
145         return mBoundsInWindow;
146     }
147 
148     /**
149      * The selected hash algorithm that generated the image hash.
150      */
151     @DataClass.Generated.Member
getHashAlgorithm()152     public @NonNull String getHashAlgorithm() {
153         return mHashAlgorithm;
154     }
155 
156     /**
157      * The image hash generated when creating the DisplayHash.
158      */
159     @DataClass.Generated.Member
getImageHash()160     public @NonNull byte[] getImageHash() {
161         return mImageHash;
162     }
163 
164     @Override
165     @DataClass.Generated.Member
toString()166     public String toString() {
167         // You can override field toString logic by defining methods like:
168         // String fieldNameToString() { ... }
169 
170         return "VerifiedDisplayHash { " +
171                 "timeMillis = " + mTimeMillis + ", " +
172                 "boundsInWindow = " + mBoundsInWindow + ", " +
173                 "hashAlgorithm = " + mHashAlgorithm + ", " +
174                 "imageHash = " + imageHashToString() +
175         " }";
176     }
177 
178     @Override
179     @DataClass.Generated.Member
writeToParcel(@onNull android.os.Parcel dest, int flags)180     public void writeToParcel(@NonNull android.os.Parcel dest, int flags) {
181         // You can override field parcelling by defining methods like:
182         // void parcelFieldName(Parcel dest, int flags) { ... }
183 
184         dest.writeLong(mTimeMillis);
185         dest.writeTypedObject(mBoundsInWindow, flags);
186         dest.writeString(mHashAlgorithm);
187         dest.writeByteArray(mImageHash);
188     }
189 
190     @Override
191     @DataClass.Generated.Member
describeContents()192     public int describeContents() { return 0; }
193 
194     /** @hide */
195     @SuppressWarnings({"unchecked", "RedundantCast"})
196     @DataClass.Generated.Member
VerifiedDisplayHash(@onNull android.os.Parcel in)197     /* package-private */ VerifiedDisplayHash(@NonNull android.os.Parcel in) {
198         // You can override field unparcelling by defining methods like:
199         // static FieldType unparcelFieldName(Parcel in) { ... }
200 
201         long timeMillis = in.readLong();
202         Rect boundsInWindow = (Rect) in.readTypedObject(Rect.CREATOR);
203         String hashAlgorithm = in.readString();
204         byte[] imageHash = in.createByteArray();
205 
206         this.mTimeMillis = timeMillis;
207         com.android.internal.util.AnnotationValidations.validate(
208                 CurrentTimeMillisLong.class, null, mTimeMillis);
209         this.mBoundsInWindow = boundsInWindow;
210         com.android.internal.util.AnnotationValidations.validate(
211                 NonNull.class, null, mBoundsInWindow);
212         this.mHashAlgorithm = hashAlgorithm;
213         com.android.internal.util.AnnotationValidations.validate(
214                 NonNull.class, null, mHashAlgorithm);
215         this.mImageHash = imageHash;
216         com.android.internal.util.AnnotationValidations.validate(
217                 NonNull.class, null, mImageHash);
218 
219         // onConstructed(); // You can define this method to get a callback
220     }
221 
222     @DataClass.Generated.Member
223     public static final @NonNull Parcelable.Creator<VerifiedDisplayHash> CREATOR
224             = new Parcelable.Creator<VerifiedDisplayHash>() {
225         @Override
226         public VerifiedDisplayHash[] newArray(int size) {
227             return new VerifiedDisplayHash[size];
228         }
229 
230         @Override
231         public VerifiedDisplayHash createFromParcel(@NonNull android.os.Parcel in) {
232             return new VerifiedDisplayHash(in);
233         }
234     };
235 
236     @DataClass.Generated(
237             time = 1617747271440L,
238             codegenVersion = "1.0.23",
239             sourceFile = "frameworks/base/core/java/android/view/displayhash/VerifiedDisplayHash.java",
240             inputSignatures = "private final @android.annotation.CurrentTimeMillisLong long mTimeMillis\nprivate final @android.annotation.NonNull android.graphics.Rect mBoundsInWindow\nprivate final @android.annotation.NonNull java.lang.String mHashAlgorithm\nprivate final @android.annotation.NonNull byte[] mImageHash\nprivate  java.lang.String imageHashToString()\nprivate  java.lang.String byteArrayToString(byte[])\nclass VerifiedDisplayHash extends java.lang.Object implements [android.os.Parcelable]\n@com.android.internal.util.DataClass(genToString=true, genAidl=true)")
241     @Deprecated
__metadata()242     private void __metadata() {}
243 
244 
245     //@formatter:on
246     // End of generated code
247 
248 }
249