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.service.displayhash;
18 
19 import android.annotation.NonNull;
20 import android.annotation.Nullable;
21 import android.annotation.SystemApi;
22 import android.graphics.Rect;
23 import android.hardware.HardwareBuffer;
24 import android.os.Parcelable;
25 import android.util.Size;
26 import android.view.displayhash.DisplayHashResultCallback;
27 
28 import com.android.internal.util.DataClass;
29 
30 /**
31  * Information passed from the {@link DisplayHashingService} to system server about how to get the
32  * display data that will be used to generate the {@link android.view.displayhash.DisplayHash}
33  *
34  * @hide
35  */
36 @SystemApi
37 @DataClass(genAidl = true, genToString = true, genParcelable = true, genHiddenConstructor = true)
38 public final class DisplayHashParams implements Parcelable {
39     /**
40      * The size to scale the buffer to so the hash algorithm can properly generate the hash. The
41      * buffer given to the {@link DisplayHashingService#onGenerateDisplayHash(byte[],
42      * HardwareBuffer, Rect, String, DisplayHashResultCallback)} will be stretched based on the
43      * value set here. If {@code null}, the buffer size will not be changed.
44      */
45     @Nullable
46     private final Size mBufferSize;
47 
48     /**
49      * Whether the content will be captured in grayscale or color.
50      */
51     private final boolean mGrayscaleBuffer;
52 
53     /**
54      * A builder for {@link DisplayHashParams}
55      */
56     public static final class Builder {
57         @Nullable
58         private Size mBufferSize;
59         private boolean mGrayscaleBuffer;
60 
61         /**
62          * Creates a new Builder.
63          */
Builder()64         public Builder() {
65         }
66 
67         /**
68          * The size to scale the buffer to so the hash algorithm can properly generate the hash.
69          */
70         @NonNull
setBufferSize(int width, int height)71         public Builder setBufferSize(int width, int height) {
72             mBufferSize = new Size(width, height);
73             return this;
74         }
75 
76         /**
77          * Whether the content will be captured in grayscale or color.
78          */
79         @NonNull
setGrayscaleBuffer(boolean grayscaleBuffer)80         public Builder setGrayscaleBuffer(boolean grayscaleBuffer) {
81             mGrayscaleBuffer = grayscaleBuffer;
82             return this;
83         }
84 
85         /** Builds the instance. This builder should not be touched after calling this! */
86         @NonNull
build()87         public DisplayHashParams build() {
88             return new DisplayHashParams(mBufferSize, mGrayscaleBuffer);
89         }
90     }
91 
92 
93 
94     // Code below generated by codegen v1.0.23.
95     //
96     // DO NOT MODIFY!
97     // CHECKSTYLE:OFF Generated code
98     //
99     // To regenerate run:
100     // $ codegen $ANDROID_BUILD_TOP/frameworks/base/core/java/android/service/displayhash/DisplayHashParams.java
101     //
102     // To exclude the generated code from IntelliJ auto-formatting enable (one-time):
103     //   Settings > Editor > Code Style > Formatter Control
104     //@formatter:off
105 
106 
107     /**
108      * Creates a new DisplayHashParams.
109      *
110      * @param bufferSize
111      *   The size to scale the buffer to so the hash algorithm can properly generate the hash. The
112      *   buffer given to the {@link DisplayHashingService#onGenerateDisplayHash(byte[],
113      *   HardwareBuffer, Rect, String, DisplayHashResultCallback)} will be stretched based on the
114      *   value set here. If {@code null}, the buffer size will not be changed.
115      * @param grayscaleBuffer
116      *   Whether the content will be captured in grayscale or color.
117      * @hide
118      */
119     @DataClass.Generated.Member
DisplayHashParams( @ullable Size bufferSize, boolean grayscaleBuffer)120     public DisplayHashParams(
121             @Nullable Size bufferSize,
122             boolean grayscaleBuffer) {
123         this.mBufferSize = bufferSize;
124         this.mGrayscaleBuffer = grayscaleBuffer;
125 
126         // onConstructed(); // You can define this method to get a callback
127     }
128 
129     /**
130      * The size to scale the buffer to so the hash algorithm can properly generate the hash. The
131      * buffer given to the {@link DisplayHashingService#onGenerateDisplayHash(byte[],
132      * HardwareBuffer, Rect, String, DisplayHashResultCallback)} will be stretched based on the
133      * value set here. If {@code null}, the buffer size will not be changed.
134      */
135     @DataClass.Generated.Member
getBufferSize()136     public @Nullable Size getBufferSize() {
137         return mBufferSize;
138     }
139 
140     /**
141      * Whether the content will be captured in grayscale or color.
142      */
143     @DataClass.Generated.Member
isGrayscaleBuffer()144     public boolean isGrayscaleBuffer() {
145         return mGrayscaleBuffer;
146     }
147 
148     @Override
149     @DataClass.Generated.Member
toString()150     public String toString() {
151         // You can override field toString logic by defining methods like:
152         // String fieldNameToString() { ... }
153 
154         return "DisplayHashParams { " +
155                 "bufferSize = " + mBufferSize + ", " +
156                 "grayscaleBuffer = " + mGrayscaleBuffer +
157         " }";
158     }
159 
160     @Override
161     @DataClass.Generated.Member
writeToParcel(@onNull android.os.Parcel dest, int flags)162     public void writeToParcel(@NonNull android.os.Parcel dest, int flags) {
163         // You can override field parcelling by defining methods like:
164         // void parcelFieldName(Parcel dest, int flags) { ... }
165 
166         byte flg = 0;
167         if (mGrayscaleBuffer) flg |= 0x2;
168         if (mBufferSize != null) flg |= 0x1;
169         dest.writeByte(flg);
170         if (mBufferSize != null) dest.writeSize(mBufferSize);
171     }
172 
173     @Override
174     @DataClass.Generated.Member
describeContents()175     public int describeContents() { return 0; }
176 
177     /** @hide */
178     @SuppressWarnings({"unchecked", "RedundantCast"})
179     @DataClass.Generated.Member
DisplayHashParams(@onNull android.os.Parcel in)180     /* package-private */ DisplayHashParams(@NonNull android.os.Parcel in) {
181         // You can override field unparcelling by defining methods like:
182         // static FieldType unparcelFieldName(Parcel in) { ... }
183 
184         byte flg = in.readByte();
185         boolean grayscaleBuffer = (flg & 0x2) != 0;
186         Size bufferSize = (flg & 0x1) == 0 ? null : (Size) in.readSize();
187 
188         this.mBufferSize = bufferSize;
189         this.mGrayscaleBuffer = grayscaleBuffer;
190 
191         // onConstructed(); // You can define this method to get a callback
192     }
193 
194     @DataClass.Generated.Member
195     public static final @NonNull Parcelable.Creator<DisplayHashParams> CREATOR
196             = new Parcelable.Creator<DisplayHashParams>() {
197         @Override
198         public DisplayHashParams[] newArray(int size) {
199             return new DisplayHashParams[size];
200         }
201 
202         @Override
203         public DisplayHashParams createFromParcel(@NonNull android.os.Parcel in) {
204             return new DisplayHashParams(in);
205         }
206     };
207 
208     @DataClass.Generated(
209             time = 1619638159453L,
210             codegenVersion = "1.0.23",
211             sourceFile = "frameworks/base/core/java/android/service/displayhash/DisplayHashParams.java",
212             inputSignatures = "private final @android.annotation.Nullable android.util.Size mBufferSize\nprivate final  boolean mGrayscaleBuffer\nclass DisplayHashParams extends java.lang.Object implements [android.os.Parcelable]\nprivate @android.annotation.Nullable android.util.Size mBufferSize\nprivate  boolean mGrayscaleBuffer\npublic @android.annotation.NonNull android.service.displayhash.DisplayHashParams.Builder setBufferSize(int,int)\npublic @android.annotation.NonNull android.service.displayhash.DisplayHashParams.Builder setGrayscaleBuffer(boolean)\npublic @android.annotation.NonNull android.service.displayhash.DisplayHashParams build()\nclass Builder extends java.lang.Object implements []\n@com.android.internal.util.DataClass(genAidl=true, genToString=true, genParcelable=true, genHiddenConstructor=true)")
213     @Deprecated
__metadata()214     private void __metadata() {}
215 
216 
217     //@formatter:on
218     // End of generated code
219 
220 }
221