• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2024 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.voice;
18 
19 import android.annotation.NonNull;
20 import android.annotation.Nullable;
21 import android.annotation.SuppressLint;
22 import android.annotation.SystemApi;
23 import android.os.Parcel;
24 import android.os.Parcelable;
25 
26 import com.android.internal.util.DataClass;
27 import com.android.internal.util.Preconditions;
28 
29 import java.util.Objects;
30 
31 /**
32  * Represents a result supporting the visual query detection.
33  *
34  * @hide
35  */
36 @DataClass(
37         genConstructor = false,
38         genBuilder = true,
39         genEqualsHashCode = true,
40         genHiddenConstDefs = true,
41         genParcelable = true,
42         genToString = true
43 )
44 @SystemApi
45 @SuppressLint("UnflaggedApi") // b/325678077 flags not supported in isolated process
46 public final class VisualQueryDetectedResult implements Parcelable {
47 
48     /**
49      * Text query being associated with the detection result.
50      **/
51     @NonNull
52     private final String mPartialQuery;
defaultPartialQuery()53     private static String defaultPartialQuery() {
54         return "";
55     }
56 
57     /** Id of the current speaker
58      *
59      * <p>Only values between 0 and {@link #getMaxSpeakerId} (inclusive) are accepted.
60      */
61     private final int mSpeakerId;
defaultSpeakerId()62     private static int defaultSpeakerId() {
63         return 0;
64     }
65     /** Maximum number of active speaker ids. **/
66     @SuppressLint("UnflaggedApi") // b/325678077 flags not supported in isolated process
getMaxSpeakerId()67     public static int getMaxSpeakerId() {
68         return 15;
69     }
70 
71     /**
72      * Detected signal representing the arbitrary data that will make accessibility detections work.
73      *
74      * This field should only be set if the device setting for allowing accessibility data is on
75      * based on the result of {@link VisualQueryDetector#isAccessibilityDetectionEnabled()}. If the
76      * enable bit return by the method is {@code false}, it would suggest a failure to egress the
77      * {@link VisualQueryDetectedResult} object with this field set. The system server will prevent
78      * egress and invoke
79      * {@link VisualQueryDetector.Callback#onFailure(VisualQueryDetectionServiceFailure)}.
80      */
81     @Nullable
82     private final byte[] mAccessibilityDetectionData;
defaultAccessibilityDetectionData()83     private static byte[] defaultAccessibilityDetectionData() {
84         return null;
85     }
86 
onConstructed()87     private void onConstructed() {
88         Preconditions.checkArgumentInRange(mSpeakerId, 0, getMaxSpeakerId(), "speakerId");
89     }
90 
91     /**
92      * Provides an instance of {@link Builder} with state corresponding to this instance.
93      *
94      * @hide
95      */
buildUpon()96     public Builder buildUpon() {
97         return new Builder()
98                 .setPartialQuery(mPartialQuery)
99                 .setSpeakerId(mSpeakerId)
100                 .setAccessibilityDetectionData(mAccessibilityDetectionData);
101     }
102 
103     /**
104      * TODO(b/301491148): Remove suppressLint on generated API when fixed or sdk finalized.
105      * Codegen does not support flaggedAPI, so needs to review manually on the generated code
106      * and makes sure the following:
107      *     1. SuppressLint is added back to the API after each run of codegen
108      *     2. No unwanted method is modified due to suppressLint annotation
109      *
110      *  Run $ codegen $ANDROID_BUILD_TOP/frameworks/base/core/java/android/service/voice/VisualQueryAttentionResult.java
111      *  for codegen on new APIs.
112      */
113 
114     // Code below generated by codegen v1.0.23.
115     //
116     // DO NOT MODIFY!
117     // CHECKSTYLE:OFF Generated code
118     //
119     // To regenerate run:
120     // $ codegen $ANDROID_BUILD_TOP/frameworks/base/core/java/android/service/voice/VisualQueryDetectedResult.java
121     //
122     // To exclude the generated code from IntelliJ auto-formatting enable (one-time):
123     //   Settings > Editor > Code Style > Formatter Control
124     //@formatter:off
125 
126 
127     @DataClass.Generated.Member
VisualQueryDetectedResult( @onNull String partialQuery, int speakerId, @Nullable byte[] accessibilityDetectionData)128     /* package-private */ VisualQueryDetectedResult(
129             @NonNull String partialQuery,
130             int speakerId,
131             @Nullable byte[] accessibilityDetectionData) {
132         this.mPartialQuery = partialQuery;
133         com.android.internal.util.AnnotationValidations.validate(
134                 NonNull.class, null, mPartialQuery);
135         this.mSpeakerId = speakerId;
136         this.mAccessibilityDetectionData = accessibilityDetectionData;
137 
138         onConstructed();
139     }
140 
141     /**
142      * Text query being associated with the detection result.
143      */
144     @DataClass.Generated.Member
145     @SuppressLint("UnflaggedApi") // b/325678077 flags not supported in isolated process
getPartialQuery()146     public @NonNull String getPartialQuery() {
147         return mPartialQuery;
148     }
149 
150     /**
151      * Id of the current speaker
152      *
153      * <p>Only values between 0 and {@link #getMaxSpeakerId} (inclusive) are accepted.
154      */
155     @DataClass.Generated.Member
156     @SuppressLint("UnflaggedApi") // b/325678077 flags not supported in isolated process
getSpeakerId()157     public int getSpeakerId() {
158         return mSpeakerId;
159     }
160 
161     /**
162      * Detected signal representing the data for allowing accessibility feature. This field can
163      * only be set when the secure device settings is set to true by either settings page UI or
164      * {@link VisualQueryDetector@setAccessibilityDetectionEnabled(boolean)}
165      */
166     @DataClass.Generated.Member
167     @SuppressLint("UnflaggedApi") // b/325678077 flags not supported in isolated process
getAccessibilityDetectionData()168     public @Nullable byte[] getAccessibilityDetectionData() {
169         return mAccessibilityDetectionData;
170     }
171 
172     @Override
173     @DataClass.Generated.Member
toString()174     public String toString() {
175         // You can override field toString logic by defining methods like:
176         // String fieldNameToString() { ... }
177 
178         return "VisualQueryDetectedResult { " +
179                 "partialQuery = " + mPartialQuery + ", " +
180                 "speakerId = " + mSpeakerId + ", " +
181                 "accessibilityDetectionData = " + java.util.Arrays.toString(mAccessibilityDetectionData) +
182         " }";
183     }
184 
185     @Override
186     @DataClass.Generated.Member
equals(@ullable Object o)187     public boolean equals(@Nullable Object o) {
188         // You can override field equality logic by defining either of the methods like:
189         // boolean fieldNameEquals(VisualQueryDetectedResult other) { ... }
190         // boolean fieldNameEquals(FieldType otherValue) { ... }
191 
192         if (this == o) return true;
193         if (o == null || getClass() != o.getClass()) return false;
194         @SuppressWarnings("unchecked")
195         VisualQueryDetectedResult that = (VisualQueryDetectedResult) o;
196         //noinspection PointlessBooleanExpression
197         return true
198                 && Objects.equals(mPartialQuery, that.mPartialQuery)
199                 && mSpeakerId == that.mSpeakerId
200                 && java.util.Arrays.equals(mAccessibilityDetectionData, that.mAccessibilityDetectionData);
201     }
202 
203     @Override
204     @DataClass.Generated.Member
hashCode()205     public int hashCode() {
206         // You can override field hashCode logic by defining methods like:
207         // int fieldNameHashCode() { ... }
208 
209         int _hash = 1;
210         _hash = 31 * _hash + Objects.hashCode(mPartialQuery);
211         _hash = 31 * _hash + mSpeakerId;
212         _hash = 31 * _hash + java.util.Arrays.hashCode(mAccessibilityDetectionData);
213         return _hash;
214     }
215 
216     @Override
217     @DataClass.Generated.Member
218     @SuppressLint("UnflaggedApi") // b/325678077 flags not supported in isolated process
writeToParcel(@onNull Parcel dest, int flags)219     public void writeToParcel(@NonNull Parcel dest, int flags) {
220         // You can override field parcelling by defining methods like:
221         // void parcelFieldName(Parcel dest, int flags) { ... }
222 
223         dest.writeString(mPartialQuery);
224         dest.writeInt(mSpeakerId);
225         dest.writeByteArray(mAccessibilityDetectionData);
226     }
227 
228     @Override
229     @DataClass.Generated.Member
230     @SuppressLint("UnflaggedApi") // b/325678077 flags not supported in isolated process
describeContents()231     public int describeContents() { return 0; }
232 
233     /** @hide */
234     @SuppressWarnings({"unchecked", "RedundantCast"})
235     @DataClass.Generated.Member
VisualQueryDetectedResult(@onNull Parcel in)236     /* package-private */ VisualQueryDetectedResult(@NonNull Parcel in) {
237         // You can override field unparcelling by defining methods like:
238         // static FieldType unparcelFieldName(Parcel in) { ... }
239 
240         String partialQuery = in.readString();
241         int speakerId = in.readInt();
242         byte[] accessibilityDetectionData = in.createByteArray();
243 
244         this.mPartialQuery = partialQuery;
245         com.android.internal.util.AnnotationValidations.validate(
246                 NonNull.class, null, mPartialQuery);
247         this.mSpeakerId = speakerId;
248         this.mAccessibilityDetectionData = accessibilityDetectionData;
249 
250         onConstructed();
251     }
252 
253     @DataClass.Generated.Member
254     @SuppressLint("UnflaggedApi") // b/325678077 flags not supported in isolated process
255     public static final @NonNull Parcelable.Creator<VisualQueryDetectedResult> CREATOR
256             = new Parcelable.Creator<VisualQueryDetectedResult>() {
257         @Override
258         public VisualQueryDetectedResult[] newArray(int size) {
259             return new VisualQueryDetectedResult[size];
260         }
261 
262         @Override
263         public VisualQueryDetectedResult createFromParcel(@NonNull Parcel in) {
264             return new VisualQueryDetectedResult(in);
265         }
266     };
267 
268     /**
269      * A builder for {@link VisualQueryDetectedResult}
270      */
271     @SuppressWarnings("WeakerAccess")
272     @DataClass.Generated.Member
273     @SuppressLint("UnflaggedApi") // b/325678077 flags not supported in isolated process
274     public static final class Builder {
275 
276         private @NonNull String mPartialQuery;
277         private int mSpeakerId;
278         private @Nullable byte[] mAccessibilityDetectionData;
279 
280         private long mBuilderFieldsSet = 0L;
281 
282         @SuppressLint("UnflaggedApi") // b/325678077 flags not supported in isolated process
Builder()283         public Builder() {
284         }
285 
286         /**
287          * Text query being associated with the detection result.
288          */
289         @DataClass.Generated.Member
290         @SuppressLint("UnflaggedApi") // b/325678077 flags not supported in isolated process
setPartialQuery(@onNull String value)291         public @NonNull Builder setPartialQuery(@NonNull String value) {
292             checkNotUsed();
293             mBuilderFieldsSet |= 0x1;
294             mPartialQuery = value;
295             return this;
296         }
297 
298         /**
299          * Id of the current speaker
300          *
301          * <p>Only values between 0 and {@link #getMaxSpeakerId} (inclusive) are accepted.
302          */
303         @DataClass.Generated.Member
304         @SuppressLint("UnflaggedApi") // b/325678077 flags not supported in isolated process
setSpeakerId(int value)305         public @NonNull Builder setSpeakerId(int value) {
306             checkNotUsed();
307             mBuilderFieldsSet |= 0x2;
308             mSpeakerId = value;
309             return this;
310         }
311 
312         /**
313          * Detected signal representing the data for allowing accessibility feature. This field can
314          * only be set when the secure device settings is set to true by either settings page UI or
315          * {@link VisualQueryDetector@setAccessibilityDetectionEnabled(boolean)}
316          */
317         @DataClass.Generated.Member
318         @SuppressLint("UnflaggedApi") // b/325678077 flags not supported in isolated process
setAccessibilityDetectionData(@onNull byte... value)319         public @NonNull Builder setAccessibilityDetectionData(@NonNull byte... value) {
320             checkNotUsed();
321             mBuilderFieldsSet |= 0x4;
322             mAccessibilityDetectionData = value;
323             return this;
324         }
325 
326         /** Builds the instance. This builder should not be touched after calling this! */
327         @SuppressLint("UnflaggedApi") // b/325678077 flags not supported in isolated process
build()328         public @NonNull VisualQueryDetectedResult build() {
329             checkNotUsed();
330             mBuilderFieldsSet |= 0x8; // Mark builder used
331 
332             if ((mBuilderFieldsSet & 0x1) == 0) {
333                 mPartialQuery = defaultPartialQuery();
334             }
335             if ((mBuilderFieldsSet & 0x2) == 0) {
336                 mSpeakerId = defaultSpeakerId();
337             }
338             if ((mBuilderFieldsSet & 0x4) == 0) {
339                 mAccessibilityDetectionData = defaultAccessibilityDetectionData();
340             }
341             VisualQueryDetectedResult o = new VisualQueryDetectedResult(
342                     mPartialQuery,
343                     mSpeakerId,
344                     mAccessibilityDetectionData);
345             return o;
346         }
347 
checkNotUsed()348         private void checkNotUsed() {
349             if ((mBuilderFieldsSet & 0x8) != 0) {
350                 throw new IllegalStateException(
351                         "This Builder should not be reused. Use a new Builder instance instead");
352             }
353         }
354     }
355 
356     @DataClass.Generated(
357             time = 1710958903381L,
358             codegenVersion = "1.0.23",
359             sourceFile = "frameworks/base/core/java/android/service/voice/VisualQueryDetectedResult.java",
360             inputSignatures = "private final @android.annotation.NonNull java.lang.String mPartialQuery\nprivate final  int mSpeakerId\nprivate final @android.annotation.Nullable byte[] mAccessibilityDetectionData\nprivate static  java.lang.String defaultPartialQuery()\nprivate static  int defaultSpeakerId()\npublic static @android.annotation.SuppressLint int getMaxSpeakerId()\nprivate static  byte[] defaultAccessibilityDetectionData()\nprivate  void onConstructed()\npublic  android.service.voice.VisualQueryDetectedResult.Builder buildUpon()\nclass VisualQueryDetectedResult extends java.lang.Object implements [android.os.Parcelable]\n@com.android.internal.util.DataClass(genConstructor=false, genBuilder=true, genEqualsHashCode=true, genHiddenConstDefs=true, genParcelable=true, genToString=true)")
361     @Deprecated
__metadata()362     private void __metadata() {}
363 
364 
365     //@formatter:on
366     // End of generated code
367 
368 }
369