blob: d282b56aedb6d221ebf6660f0f86565d9670b77f [file] [log] [blame]
Feng Cao04830a32019-11-13 00:45:19 -08001/*
2 * Copyright (C) 2019 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
17package android.view.inputmethod;
18
19import android.annotation.NonNull;
Feng Cao16b2de52020-01-09 17:27:27 -080020import android.annotation.Nullable;
21import android.app.ActivityThread;
Feng Cao5f7e99e2020-02-14 19:27:46 -080022import android.os.Bundle;
Adam He40116252020-02-04 14:55:39 -080023import android.os.IBinder;
Feng Cao5f7e99e2020-02-14 19:27:46 -080024import android.os.LocaleList;
Svet Ganov02fdd342020-02-20 20:48:34 -080025import android.os.Parcel;
Feng Cao04830a32019-11-13 00:45:19 -080026import android.os.Parcelable;
Svet Ganov02fdd342020-02-20 20:48:34 -080027import android.view.Display;
Adam Hef27433a2020-03-25 15:11:18 -070028import android.widget.inline.InlinePresentationSpec;
Feng Cao04830a32019-11-13 00:45:19 -080029
30import com.android.internal.util.DataClass;
31import com.android.internal.util.Preconditions;
Feng Cao59b682f2020-03-30 17:43:16 -070032import com.android.internal.widget.InlinePresentationStyleUtils;
Feng Cao04830a32019-11-13 00:45:19 -080033
34import java.util.ArrayList;
35import java.util.List;
36
37/**
38 * This class represents an inline suggestion request made by one app to get suggestions from the
39 * other source. See {@link InlineSuggestion} for more information.
40 */
41@DataClass(genEqualsHashCode = true, genToString = true, genBuilder = true)
42public final class InlineSuggestionsRequest implements Parcelable {
43
44 /** Constant used to indicate not putting a cap on the number of suggestions to return. */
45 public static final int SUGGESTION_COUNT_UNLIMITED = Integer.MAX_VALUE;
46
Feng Cao7a0f0022019-12-17 18:49:24 -080047 /**
Feng Cao44dc2bd2020-03-09 23:02:33 -070048 * Max number of suggestions expected from the response. It must be a positive value.
49 * Defaults to {@code SUGGESTION_COUNT_UNLIMITED} if not set.
Feng Cao7a0f0022019-12-17 18:49:24 -080050 */
Feng Cao04830a32019-11-13 00:45:19 -080051 private final int mMaxSuggestionCount;
Feng Cao7a0f0022019-12-17 18:49:24 -080052
53 /**
54 * The {@link InlinePresentationSpec} for each suggestion in the response. If the max suggestion
55 * count is larger than the number of specs in the list, then the last spec is used for the
Feng Cao44dc2bd2020-03-09 23:02:33 -070056 * remainder of the suggestions. The list should not be empty.
Feng Cao7a0f0022019-12-17 18:49:24 -080057 */
Adam Hef27433a2020-03-25 15:11:18 -070058 private final @NonNull List<InlinePresentationSpec> mInlinePresentationSpecs;
Feng Cao04830a32019-11-13 00:45:19 -080059
Feng Cao16b2de52020-01-09 17:27:27 -080060 /**
61 * The package name of the app that requests for the inline suggestions and will host the
62 * embedded suggestion views. The app does not have to set the value for the field because
63 * it'll be set by the system for safety reasons.
64 */
65 private @NonNull String mHostPackageName;
66
67 /**
Feng Cao5f7e99e2020-02-14 19:27:46 -080068 * The IME provided locales for the request. If non-empty, the inline suggestions should
69 * return languages from the supported locales. If not provided, it'll default to system locale.
70 */
71 private @NonNull LocaleList mSupportedLocales;
72
Svet Ganov02fdd342020-02-20 20:48:34 -080073 /**
74 * The extras state propagated from the IME to pass extra data.
75 */
Feng Caoedb332c2020-03-30 14:26:42 -070076 private @NonNull Bundle mExtras;
Svet Ganov02fdd342020-02-20 20:48:34 -080077
Feng Cao5f7e99e2020-02-14 19:27:46 -080078 /**
Adam He40116252020-02-04 14:55:39 -080079 * The host input token of the IME that made the request. This will be set by the system for
80 * safety reasons.
81 *
82 * @hide
83 */
84 private @Nullable IBinder mHostInputToken;
85
86 /**
Svet Ganov02fdd342020-02-20 20:48:34 -080087 * The host display id of the IME that made the request. This will be set by the system for
88 * safety reasons.
89 *
90 * @hide
Feng Cao16b2de52020-01-09 17:27:27 -080091 */
Svet Ganov02fdd342020-02-20 20:48:34 -080092 private int mHostDisplayId;
Feng Cao16b2de52020-01-09 17:27:27 -080093
Adam He40116252020-02-04 14:55:39 -080094 /**
95 * @hide
96 * @see {@link #mHostInputToken}.
97 */
98 public void setHostInputToken(IBinder hostInputToken) {
99 mHostInputToken = hostInputToken;
100 }
101
Feng Cao59b682f2020-03-30 17:43:16 -0700102 private boolean extrasEquals(@NonNull Bundle extras) {
103 return InlinePresentationStyleUtils.bundleEquals(mExtras, extras);
104 }
105
Svet Ganov02fdd342020-02-20 20:48:34 -0800106 // TODO(b/149609075): remove once IBinder parcelling is natively supported
107 private void parcelHostInputToken(@NonNull Parcel parcel, int flags) {
108 parcel.writeStrongBinder(mHostInputToken);
109 }
110
111 // TODO(b/149609075): remove once IBinder parcelling is natively supported
112 private @Nullable IBinder unparcelHostInputToken(Parcel parcel) {
113 return parcel.readStrongBinder();
114 }
115
116 /**
117 * @hide
118 * @see {@link #mHostDisplayId}.
119 */
120 public void setHostDisplayId(int hostDisplayId) {
121 mHostDisplayId = hostDisplayId;
122 }
123
Feng Cao04830a32019-11-13 00:45:19 -0800124 private void onConstructed() {
Adam Hef27433a2020-03-25 15:11:18 -0700125 Preconditions.checkState(!mInlinePresentationSpecs.isEmpty());
126 Preconditions.checkState(mMaxSuggestionCount >= mInlinePresentationSpecs.size());
Feng Cao04830a32019-11-13 00:45:19 -0800127 }
128
129 private static int defaultMaxSuggestionCount() {
130 return SUGGESTION_COUNT_UNLIMITED;
131 }
132
Feng Cao16b2de52020-01-09 17:27:27 -0800133 private static String defaultHostPackageName() {
134 return ActivityThread.currentPackageName();
135 }
136
Feng Cao5f7e99e2020-02-14 19:27:46 -0800137 private static LocaleList defaultSupportedLocales() {
138 return LocaleList.getDefault();
139 }
140
141 @Nullable
Adam He40116252020-02-04 14:55:39 -0800142 private static IBinder defaultHostInputToken() {
143 return null;
144 }
145
Feng Cao5f7e99e2020-02-14 19:27:46 -0800146 @Nullable
Svet Ganov02fdd342020-02-20 20:48:34 -0800147 private static int defaultHostDisplayId() {
148 return Display.INVALID_DISPLAY;
149 }
150
Feng Caoedb332c2020-03-30 14:26:42 -0700151 @NonNull
Feng Cao5f7e99e2020-02-14 19:27:46 -0800152 private static Bundle defaultExtras() {
Feng Caoedb332c2020-03-30 14:26:42 -0700153 return Bundle.EMPTY;
Feng Cao5f7e99e2020-02-14 19:27:46 -0800154 }
155
Feng Cao04830a32019-11-13 00:45:19 -0800156 /** @hide */
157 abstract static class BaseBuilder {
Adam Hef27433a2020-03-25 15:11:18 -0700158 abstract Builder setInlinePresentationSpecs(
159 @NonNull List<android.widget.inline.InlinePresentationSpec> specs);
Feng Cao16b2de52020-01-09 17:27:27 -0800160
161 abstract Builder setHostPackageName(@Nullable String value);
Adam He40116252020-02-04 14:55:39 -0800162
163 abstract Builder setHostInputToken(IBinder hostInputToken);
Svet Ganov02fdd342020-02-20 20:48:34 -0800164
165 abstract Builder setHostDisplayId(int value);
Feng Cao04830a32019-11-13 00:45:19 -0800166 }
167
168
169
Feng Cao44dc2bd2020-03-09 23:02:33 -0700170 // Code below generated by codegen v1.0.15.
Feng Cao04830a32019-11-13 00:45:19 -0800171 //
172 // DO NOT MODIFY!
173 // CHECKSTYLE:OFF Generated code
174 //
175 // To regenerate run:
176 // $ codegen $ANDROID_BUILD_TOP/frameworks/base/core/java/android/view/inputmethod/InlineSuggestionsRequest.java
177 //
178 // To exclude the generated code from IntelliJ auto-formatting enable (one-time):
179 // Settings > Editor > Code Style > Formatter Control
180 //@formatter:off
181
182
183 @DataClass.Generated.Member
184 /* package-private */ InlineSuggestionsRequest(
185 int maxSuggestionCount,
Adam Hef27433a2020-03-25 15:11:18 -0700186 @NonNull List<InlinePresentationSpec> inlinePresentationSpecs,
Adam He40116252020-02-04 14:55:39 -0800187 @NonNull String hostPackageName,
Feng Cao5f7e99e2020-02-14 19:27:46 -0800188 @NonNull LocaleList supportedLocales,
Feng Caoedb332c2020-03-30 14:26:42 -0700189 @NonNull Bundle extras,
Feng Cao5f7e99e2020-02-14 19:27:46 -0800190 @Nullable IBinder hostInputToken,
Svet Ganov02fdd342020-02-20 20:48:34 -0800191 int hostDisplayId) {
Feng Cao04830a32019-11-13 00:45:19 -0800192 this.mMaxSuggestionCount = maxSuggestionCount;
Adam Hef27433a2020-03-25 15:11:18 -0700193 this.mInlinePresentationSpecs = inlinePresentationSpecs;
Feng Cao04830a32019-11-13 00:45:19 -0800194 com.android.internal.util.AnnotationValidations.validate(
Adam Hef27433a2020-03-25 15:11:18 -0700195 NonNull.class, null, mInlinePresentationSpecs);
Feng Cao16b2de52020-01-09 17:27:27 -0800196 this.mHostPackageName = hostPackageName;
197 com.android.internal.util.AnnotationValidations.validate(
198 NonNull.class, null, mHostPackageName);
Feng Cao5f7e99e2020-02-14 19:27:46 -0800199 this.mSupportedLocales = supportedLocales;
200 com.android.internal.util.AnnotationValidations.validate(
201 NonNull.class, null, mSupportedLocales);
Feng Cao5f7e99e2020-02-14 19:27:46 -0800202 this.mExtras = extras;
Feng Caoedb332c2020-03-30 14:26:42 -0700203 com.android.internal.util.AnnotationValidations.validate(
204 NonNull.class, null, mExtras);
Svet Ganov02fdd342020-02-20 20:48:34 -0800205 this.mHostInputToken = hostInputToken;
206 this.mHostDisplayId = hostDisplayId;
Feng Cao04830a32019-11-13 00:45:19 -0800207
208 onConstructed();
209 }
210
Feng Cao7a0f0022019-12-17 18:49:24 -0800211 /**
Feng Cao44dc2bd2020-03-09 23:02:33 -0700212 * Max number of suggestions expected from the response. It must be a positive value.
213 * Defaults to {@code SUGGESTION_COUNT_UNLIMITED} if not set.
Feng Cao7a0f0022019-12-17 18:49:24 -0800214 */
Feng Cao04830a32019-11-13 00:45:19 -0800215 @DataClass.Generated.Member
216 public int getMaxSuggestionCount() {
217 return mMaxSuggestionCount;
218 }
219
Feng Cao7a0f0022019-12-17 18:49:24 -0800220 /**
221 * The {@link InlinePresentationSpec} for each suggestion in the response. If the max suggestion
222 * count is larger than the number of specs in the list, then the last spec is used for the
Feng Cao44dc2bd2020-03-09 23:02:33 -0700223 * remainder of the suggestions. The list should not be empty.
Feng Cao7a0f0022019-12-17 18:49:24 -0800224 */
Feng Cao04830a32019-11-13 00:45:19 -0800225 @DataClass.Generated.Member
Adam Hef27433a2020-03-25 15:11:18 -0700226 public @NonNull List<InlinePresentationSpec> getInlinePresentationSpecs() {
227 return mInlinePresentationSpecs;
Feng Cao04830a32019-11-13 00:45:19 -0800228 }
229
Feng Cao16b2de52020-01-09 17:27:27 -0800230 /**
231 * The package name of the app that requests for the inline suggestions and will host the
232 * embedded suggestion views. The app does not have to set the value for the field because
233 * it'll be set by the system for safety reasons.
234 */
235 @DataClass.Generated.Member
236 public @NonNull String getHostPackageName() {
237 return mHostPackageName;
238 }
239
Adam He40116252020-02-04 14:55:39 -0800240 /**
Feng Cao5f7e99e2020-02-14 19:27:46 -0800241 * The IME provided locales for the request. If non-empty, the inline suggestions should
242 * return languages from the supported locales. If not provided, it'll default to system locale.
243 */
244 @DataClass.Generated.Member
245 public @NonNull LocaleList getSupportedLocales() {
246 return mSupportedLocales;
247 }
248
249 /**
Svet Ganov02fdd342020-02-20 20:48:34 -0800250 * The extras state propagated from the IME to pass extra data.
251 */
252 @DataClass.Generated.Member
Feng Caoedb332c2020-03-30 14:26:42 -0700253 public @NonNull Bundle getExtras() {
Svet Ganov02fdd342020-02-20 20:48:34 -0800254 return mExtras;
255 }
256
257 /**
Adam He40116252020-02-04 14:55:39 -0800258 * The host input token of the IME that made the request. This will be set by the system for
259 * safety reasons.
260 *
261 * @hide
262 */
263 @DataClass.Generated.Member
264 public @Nullable IBinder getHostInputToken() {
265 return mHostInputToken;
266 }
267
Feng Cao5f7e99e2020-02-14 19:27:46 -0800268 /**
Svet Ganov02fdd342020-02-20 20:48:34 -0800269 * The host display id of the IME that made the request. This will be set by the system for
270 * safety reasons.
271 *
272 * @hide
Feng Cao5f7e99e2020-02-14 19:27:46 -0800273 */
274 @DataClass.Generated.Member
Svet Ganov02fdd342020-02-20 20:48:34 -0800275 public int getHostDisplayId() {
276 return mHostDisplayId;
Feng Cao5f7e99e2020-02-14 19:27:46 -0800277 }
278
Feng Cao04830a32019-11-13 00:45:19 -0800279 @Override
280 @DataClass.Generated.Member
281 public String toString() {
282 // You can override field toString logic by defining methods like:
283 // String fieldNameToString() { ... }
284
285 return "InlineSuggestionsRequest { " +
286 "maxSuggestionCount = " + mMaxSuggestionCount + ", " +
Adam Hef27433a2020-03-25 15:11:18 -0700287 "inlinePresentationSpecs = " + mInlinePresentationSpecs + ", " +
Adam He40116252020-02-04 14:55:39 -0800288 "hostPackageName = " + mHostPackageName + ", " +
Feng Cao5f7e99e2020-02-14 19:27:46 -0800289 "supportedLocales = " + mSupportedLocales + ", " +
Svet Ganov02fdd342020-02-20 20:48:34 -0800290 "extras = " + mExtras + ", " +
Feng Cao5f7e99e2020-02-14 19:27:46 -0800291 "hostInputToken = " + mHostInputToken + ", " +
Svet Ganov02fdd342020-02-20 20:48:34 -0800292 "hostDisplayId = " + mHostDisplayId +
Feng Cao04830a32019-11-13 00:45:19 -0800293 " }";
294 }
295
296 @Override
297 @DataClass.Generated.Member
Feng Cao16b2de52020-01-09 17:27:27 -0800298 public boolean equals(@Nullable Object o) {
Feng Cao04830a32019-11-13 00:45:19 -0800299 // You can override field equality logic by defining either of the methods like:
300 // boolean fieldNameEquals(InlineSuggestionsRequest other) { ... }
301 // boolean fieldNameEquals(FieldType otherValue) { ... }
302
303 if (this == o) return true;
304 if (o == null || getClass() != o.getClass()) return false;
305 @SuppressWarnings("unchecked")
306 InlineSuggestionsRequest that = (InlineSuggestionsRequest) o;
307 //noinspection PointlessBooleanExpression
308 return true
309 && mMaxSuggestionCount == that.mMaxSuggestionCount
Adam Hef27433a2020-03-25 15:11:18 -0700310 && java.util.Objects.equals(mInlinePresentationSpecs, that.mInlinePresentationSpecs)
Adam He40116252020-02-04 14:55:39 -0800311 && java.util.Objects.equals(mHostPackageName, that.mHostPackageName)
Feng Cao5f7e99e2020-02-14 19:27:46 -0800312 && java.util.Objects.equals(mSupportedLocales, that.mSupportedLocales)
Feng Cao59b682f2020-03-30 17:43:16 -0700313 && extrasEquals(that.mExtras)
Feng Cao5f7e99e2020-02-14 19:27:46 -0800314 && java.util.Objects.equals(mHostInputToken, that.mHostInputToken)
Svet Ganov02fdd342020-02-20 20:48:34 -0800315 && mHostDisplayId == that.mHostDisplayId;
Feng Cao04830a32019-11-13 00:45:19 -0800316 }
317
318 @Override
319 @DataClass.Generated.Member
320 public int hashCode() {
321 // You can override field hashCode logic by defining methods like:
322 // int fieldNameHashCode() { ... }
323
324 int _hash = 1;
325 _hash = 31 * _hash + mMaxSuggestionCount;
Adam Hef27433a2020-03-25 15:11:18 -0700326 _hash = 31 * _hash + java.util.Objects.hashCode(mInlinePresentationSpecs);
Feng Cao16b2de52020-01-09 17:27:27 -0800327 _hash = 31 * _hash + java.util.Objects.hashCode(mHostPackageName);
Feng Cao5f7e99e2020-02-14 19:27:46 -0800328 _hash = 31 * _hash + java.util.Objects.hashCode(mSupportedLocales);
Feng Cao5f7e99e2020-02-14 19:27:46 -0800329 _hash = 31 * _hash + java.util.Objects.hashCode(mExtras);
Svet Ganov02fdd342020-02-20 20:48:34 -0800330 _hash = 31 * _hash + java.util.Objects.hashCode(mHostInputToken);
331 _hash = 31 * _hash + mHostDisplayId;
Feng Cao04830a32019-11-13 00:45:19 -0800332 return _hash;
333 }
334
335 @Override
336 @DataClass.Generated.Member
Svet Ganov02fdd342020-02-20 20:48:34 -0800337 public void writeToParcel(@NonNull Parcel dest, int flags) {
Feng Cao04830a32019-11-13 00:45:19 -0800338 // You can override field parcelling by defining methods like:
339 // void parcelFieldName(Parcel dest, int flags) { ... }
340
Adam He40116252020-02-04 14:55:39 -0800341 byte flg = 0;
Svet Ganov02fdd342020-02-20 20:48:34 -0800342 if (mHostInputToken != null) flg |= 0x20;
Adam He40116252020-02-04 14:55:39 -0800343 dest.writeByte(flg);
Feng Cao04830a32019-11-13 00:45:19 -0800344 dest.writeInt(mMaxSuggestionCount);
Adam Hef27433a2020-03-25 15:11:18 -0700345 dest.writeParcelableList(mInlinePresentationSpecs, flags);
Feng Cao16b2de52020-01-09 17:27:27 -0800346 dest.writeString(mHostPackageName);
Feng Cao5f7e99e2020-02-14 19:27:46 -0800347 dest.writeTypedObject(mSupportedLocales, flags);
Feng Caoedb332c2020-03-30 14:26:42 -0700348 dest.writeBundle(mExtras);
Svet Ganov02fdd342020-02-20 20:48:34 -0800349 parcelHostInputToken(dest, flags);
350 dest.writeInt(mHostDisplayId);
Feng Cao04830a32019-11-13 00:45:19 -0800351 }
352
353 @Override
354 @DataClass.Generated.Member
355 public int describeContents() { return 0; }
356
357 /** @hide */
358 @SuppressWarnings({"unchecked", "RedundantCast"})
359 @DataClass.Generated.Member
Svet Ganov02fdd342020-02-20 20:48:34 -0800360 /* package-private */ InlineSuggestionsRequest(@NonNull Parcel in) {
Feng Cao04830a32019-11-13 00:45:19 -0800361 // You can override field unparcelling by defining methods like:
362 // static FieldType unparcelFieldName(Parcel in) { ... }
363
Adam He40116252020-02-04 14:55:39 -0800364 byte flg = in.readByte();
Feng Cao04830a32019-11-13 00:45:19 -0800365 int maxSuggestionCount = in.readInt();
Adam Hef27433a2020-03-25 15:11:18 -0700366 List<InlinePresentationSpec> inlinePresentationSpecs = new ArrayList<>();
367 in.readParcelableList(inlinePresentationSpecs, InlinePresentationSpec.class.getClassLoader());
Feng Cao16b2de52020-01-09 17:27:27 -0800368 String hostPackageName = in.readString();
Feng Cao5f7e99e2020-02-14 19:27:46 -0800369 LocaleList supportedLocales = (LocaleList) in.readTypedObject(LocaleList.CREATOR);
Feng Caoedb332c2020-03-30 14:26:42 -0700370 Bundle extras = in.readBundle();
Svet Ganov02fdd342020-02-20 20:48:34 -0800371 IBinder hostInputToken = unparcelHostInputToken(in);
372 int hostDisplayId = in.readInt();
Feng Cao04830a32019-11-13 00:45:19 -0800373
374 this.mMaxSuggestionCount = maxSuggestionCount;
Adam Hef27433a2020-03-25 15:11:18 -0700375 this.mInlinePresentationSpecs = inlinePresentationSpecs;
Feng Cao04830a32019-11-13 00:45:19 -0800376 com.android.internal.util.AnnotationValidations.validate(
Adam Hef27433a2020-03-25 15:11:18 -0700377 NonNull.class, null, mInlinePresentationSpecs);
Feng Cao16b2de52020-01-09 17:27:27 -0800378 this.mHostPackageName = hostPackageName;
379 com.android.internal.util.AnnotationValidations.validate(
380 NonNull.class, null, mHostPackageName);
Feng Cao5f7e99e2020-02-14 19:27:46 -0800381 this.mSupportedLocales = supportedLocales;
382 com.android.internal.util.AnnotationValidations.validate(
383 NonNull.class, null, mSupportedLocales);
Feng Cao5f7e99e2020-02-14 19:27:46 -0800384 this.mExtras = extras;
Feng Caoedb332c2020-03-30 14:26:42 -0700385 com.android.internal.util.AnnotationValidations.validate(
386 NonNull.class, null, mExtras);
Svet Ganov02fdd342020-02-20 20:48:34 -0800387 this.mHostInputToken = hostInputToken;
388 this.mHostDisplayId = hostDisplayId;
Feng Cao04830a32019-11-13 00:45:19 -0800389
390 onConstructed();
391 }
392
393 @DataClass.Generated.Member
394 public static final @NonNull Parcelable.Creator<InlineSuggestionsRequest> CREATOR
395 = new Parcelable.Creator<InlineSuggestionsRequest>() {
396 @Override
397 public InlineSuggestionsRequest[] newArray(int size) {
398 return new InlineSuggestionsRequest[size];
399 }
400
401 @Override
Svet Ganov02fdd342020-02-20 20:48:34 -0800402 public InlineSuggestionsRequest createFromParcel(@NonNull Parcel in) {
Feng Cao04830a32019-11-13 00:45:19 -0800403 return new InlineSuggestionsRequest(in);
404 }
405 };
406
407 /**
408 * A builder for {@link InlineSuggestionsRequest}
409 */
410 @SuppressWarnings("WeakerAccess")
411 @DataClass.Generated.Member
412 public static final class Builder extends BaseBuilder {
413
414 private int mMaxSuggestionCount;
Adam Hef27433a2020-03-25 15:11:18 -0700415 private @NonNull List<InlinePresentationSpec> mInlinePresentationSpecs;
Feng Cao16b2de52020-01-09 17:27:27 -0800416 private @NonNull String mHostPackageName;
Feng Cao5f7e99e2020-02-14 19:27:46 -0800417 private @NonNull LocaleList mSupportedLocales;
Feng Caoedb332c2020-03-30 14:26:42 -0700418 private @NonNull Bundle mExtras;
Svet Ganov02fdd342020-02-20 20:48:34 -0800419 private @Nullable IBinder mHostInputToken;
420 private int mHostDisplayId;
Feng Cao04830a32019-11-13 00:45:19 -0800421
422 private long mBuilderFieldsSet = 0L;
423
Feng Cao7a0f0022019-12-17 18:49:24 -0800424 /**
425 * Creates a new Builder.
426 *
Adam Hef27433a2020-03-25 15:11:18 -0700427 * @param inlinePresentationSpecs
Feng Cao7a0f0022019-12-17 18:49:24 -0800428 * The {@link InlinePresentationSpec} for each suggestion in the response. If the max suggestion
429 * count is larger than the number of specs in the list, then the last spec is used for the
Feng Cao44dc2bd2020-03-09 23:02:33 -0700430 * remainder of the suggestions. The list should not be empty.
Feng Cao7a0f0022019-12-17 18:49:24 -0800431 */
Feng Cao04830a32019-11-13 00:45:19 -0800432 public Builder(
Adam Hef27433a2020-03-25 15:11:18 -0700433 @NonNull List<InlinePresentationSpec> inlinePresentationSpecs) {
434 mInlinePresentationSpecs = inlinePresentationSpecs;
Feng Cao04830a32019-11-13 00:45:19 -0800435 com.android.internal.util.AnnotationValidations.validate(
Adam Hef27433a2020-03-25 15:11:18 -0700436 NonNull.class, null, mInlinePresentationSpecs);
Feng Cao04830a32019-11-13 00:45:19 -0800437 }
438
Feng Cao7a0f0022019-12-17 18:49:24 -0800439 /**
Feng Cao44dc2bd2020-03-09 23:02:33 -0700440 * Max number of suggestions expected from the response. It must be a positive value.
441 * Defaults to {@code SUGGESTION_COUNT_UNLIMITED} if not set.
Feng Cao7a0f0022019-12-17 18:49:24 -0800442 */
Feng Cao04830a32019-11-13 00:45:19 -0800443 @DataClass.Generated.Member
444 public @NonNull Builder setMaxSuggestionCount(int value) {
445 checkNotUsed();
446 mBuilderFieldsSet |= 0x1;
447 mMaxSuggestionCount = value;
448 return this;
449 }
450
Feng Cao7a0f0022019-12-17 18:49:24 -0800451 /**
452 * The {@link InlinePresentationSpec} for each suggestion in the response. If the max suggestion
453 * count is larger than the number of specs in the list, then the last spec is used for the
Feng Cao44dc2bd2020-03-09 23:02:33 -0700454 * remainder of the suggestions. The list should not be empty.
Feng Cao7a0f0022019-12-17 18:49:24 -0800455 */
Feng Cao04830a32019-11-13 00:45:19 -0800456 @DataClass.Generated.Member
Adam Hef27433a2020-03-25 15:11:18 -0700457 public @NonNull Builder setInlinePresentationSpecs(@NonNull List<InlinePresentationSpec> value) {
Feng Cao04830a32019-11-13 00:45:19 -0800458 checkNotUsed();
459 mBuilderFieldsSet |= 0x2;
Adam Hef27433a2020-03-25 15:11:18 -0700460 mInlinePresentationSpecs = value;
Feng Cao04830a32019-11-13 00:45:19 -0800461 return this;
462 }
463
Adam Hef27433a2020-03-25 15:11:18 -0700464 /** @see #setInlinePresentationSpecs */
Feng Cao04830a32019-11-13 00:45:19 -0800465 @DataClass.Generated.Member
Adam Hef27433a2020-03-25 15:11:18 -0700466 public @NonNull Builder addInlinePresentationSpecs(@NonNull InlinePresentationSpec value) {
Feng Cao04830a32019-11-13 00:45:19 -0800467 // You can refine this method's name by providing item's singular name, e.g.:
468 // @DataClass.PluralOf("item")) mItems = ...
469
Adam Hef27433a2020-03-25 15:11:18 -0700470 if (mInlinePresentationSpecs == null) setInlinePresentationSpecs(new ArrayList<>());
471 mInlinePresentationSpecs.add(value);
Feng Cao04830a32019-11-13 00:45:19 -0800472 return this;
473 }
474
Feng Cao16b2de52020-01-09 17:27:27 -0800475 /**
476 * The package name of the app that requests for the inline suggestions and will host the
477 * embedded suggestion views. The app does not have to set the value for the field because
478 * it'll be set by the system for safety reasons.
479 */
480 @DataClass.Generated.Member
481 @Override
482 @NonNull Builder setHostPackageName(@NonNull String value) {
483 checkNotUsed();
484 mBuilderFieldsSet |= 0x4;
485 mHostPackageName = value;
486 return this;
487 }
488
Adam He40116252020-02-04 14:55:39 -0800489 /**
Feng Cao5f7e99e2020-02-14 19:27:46 -0800490 * The IME provided locales for the request. If non-empty, the inline suggestions should
491 * return languages from the supported locales. If not provided, it'll default to system locale.
492 */
493 @DataClass.Generated.Member
494 public @NonNull Builder setSupportedLocales(@NonNull LocaleList value) {
495 checkNotUsed();
496 mBuilderFieldsSet |= 0x8;
497 mSupportedLocales = value;
498 return this;
499 }
500
501 /**
Svet Ganov02fdd342020-02-20 20:48:34 -0800502 * The extras state propagated from the IME to pass extra data.
503 */
504 @DataClass.Generated.Member
Feng Cao1ee5afa2020-03-12 20:32:45 -0700505 public @NonNull Builder setExtras(@NonNull Bundle value) {
Svet Ganov02fdd342020-02-20 20:48:34 -0800506 checkNotUsed();
507 mBuilderFieldsSet |= 0x10;
508 mExtras = value;
509 return this;
510 }
511
512 /**
Adam He40116252020-02-04 14:55:39 -0800513 * The host input token of the IME that made the request. This will be set by the system for
514 * safety reasons.
515 *
516 * @hide
517 */
518 @DataClass.Generated.Member
519 @Override
Feng Cao1ee5afa2020-03-12 20:32:45 -0700520 @NonNull Builder setHostInputToken(@NonNull IBinder value) {
Adam He40116252020-02-04 14:55:39 -0800521 checkNotUsed();
Svet Ganov02fdd342020-02-20 20:48:34 -0800522 mBuilderFieldsSet |= 0x20;
Adam He40116252020-02-04 14:55:39 -0800523 mHostInputToken = value;
524 return this;
525 }
526
Feng Cao5f7e99e2020-02-14 19:27:46 -0800527 /**
Svet Ganov02fdd342020-02-20 20:48:34 -0800528 * The host display id of the IME that made the request. This will be set by the system for
529 * safety reasons.
530 *
531 * @hide
Feng Cao5f7e99e2020-02-14 19:27:46 -0800532 */
533 @DataClass.Generated.Member
Svet Ganov02fdd342020-02-20 20:48:34 -0800534 @Override
535 @NonNull Builder setHostDisplayId(int value) {
Feng Cao5f7e99e2020-02-14 19:27:46 -0800536 checkNotUsed();
Svet Ganov02fdd342020-02-20 20:48:34 -0800537 mBuilderFieldsSet |= 0x40;
538 mHostDisplayId = value;
Feng Cao5f7e99e2020-02-14 19:27:46 -0800539 return this;
540 }
541
Feng Cao04830a32019-11-13 00:45:19 -0800542 /** Builds the instance. This builder should not be touched after calling this! */
543 public @NonNull InlineSuggestionsRequest build() {
544 checkNotUsed();
Svet Ganov02fdd342020-02-20 20:48:34 -0800545 mBuilderFieldsSet |= 0x80; // Mark builder used
Feng Cao04830a32019-11-13 00:45:19 -0800546
547 if ((mBuilderFieldsSet & 0x1) == 0) {
548 mMaxSuggestionCount = defaultMaxSuggestionCount();
549 }
Feng Cao16b2de52020-01-09 17:27:27 -0800550 if ((mBuilderFieldsSet & 0x4) == 0) {
551 mHostPackageName = defaultHostPackageName();
552 }
Adam He40116252020-02-04 14:55:39 -0800553 if ((mBuilderFieldsSet & 0x8) == 0) {
Feng Cao5f7e99e2020-02-14 19:27:46 -0800554 mSupportedLocales = defaultSupportedLocales();
555 }
556 if ((mBuilderFieldsSet & 0x10) == 0) {
Svet Ganov02fdd342020-02-20 20:48:34 -0800557 mExtras = defaultExtras();
Adam He40116252020-02-04 14:55:39 -0800558 }
Feng Cao5f7e99e2020-02-14 19:27:46 -0800559 if ((mBuilderFieldsSet & 0x20) == 0) {
Svet Ganov02fdd342020-02-20 20:48:34 -0800560 mHostInputToken = defaultHostInputToken();
561 }
562 if ((mBuilderFieldsSet & 0x40) == 0) {
563 mHostDisplayId = defaultHostDisplayId();
Feng Cao5f7e99e2020-02-14 19:27:46 -0800564 }
Feng Cao04830a32019-11-13 00:45:19 -0800565 InlineSuggestionsRequest o = new InlineSuggestionsRequest(
566 mMaxSuggestionCount,
Adam Hef27433a2020-03-25 15:11:18 -0700567 mInlinePresentationSpecs,
Adam He40116252020-02-04 14:55:39 -0800568 mHostPackageName,
Feng Cao5f7e99e2020-02-14 19:27:46 -0800569 mSupportedLocales,
Svet Ganov02fdd342020-02-20 20:48:34 -0800570 mExtras,
Feng Cao5f7e99e2020-02-14 19:27:46 -0800571 mHostInputToken,
Svet Ganov02fdd342020-02-20 20:48:34 -0800572 mHostDisplayId);
Feng Cao04830a32019-11-13 00:45:19 -0800573 return o;
574 }
575
576 private void checkNotUsed() {
Svet Ganov02fdd342020-02-20 20:48:34 -0800577 if ((mBuilderFieldsSet & 0x80) != 0) {
Feng Cao04830a32019-11-13 00:45:19 -0800578 throw new IllegalStateException(
579 "This Builder should not be reused. Use a new Builder instance instead");
580 }
581 }
582 }
583
584 @DataClass.Generated(
Adam He3f8cdb52020-04-15 15:31:46 -0700585 time = 1586992395497L,
Feng Cao44dc2bd2020-03-09 23:02:33 -0700586 codegenVersion = "1.0.15",
Feng Cao04830a32019-11-13 00:45:19 -0800587 sourceFile = "frameworks/base/core/java/android/view/inputmethod/InlineSuggestionsRequest.java",
Adam He3f8cdb52020-04-15 15:31:46 -0700588 inputSignatures = "public static final int SUGGESTION_COUNT_UNLIMITED\nprivate final int mMaxSuggestionCount\nprivate final @android.annotation.NonNull java.util.List<android.widget.inline.InlinePresentationSpec> mInlinePresentationSpecs\nprivate @android.annotation.NonNull java.lang.String mHostPackageName\nprivate @android.annotation.NonNull android.os.LocaleList mSupportedLocales\nprivate @android.annotation.NonNull android.os.Bundle mExtras\nprivate @android.annotation.Nullable android.os.IBinder mHostInputToken\nprivate int mHostDisplayId\npublic void setHostInputToken(android.os.IBinder)\nprivate boolean extrasEquals(android.os.Bundle)\nprivate void parcelHostInputToken(android.os.Parcel,int)\nprivate @android.annotation.Nullable android.os.IBinder unparcelHostInputToken(android.os.Parcel)\npublic void setHostDisplayId(int)\nprivate void onConstructed()\nprivate static int defaultMaxSuggestionCount()\nprivate static java.lang.String defaultHostPackageName()\nprivate static android.os.LocaleList defaultSupportedLocales()\nprivate static @android.annotation.Nullable android.os.IBinder defaultHostInputToken()\nprivate static @android.annotation.Nullable int defaultHostDisplayId()\nprivate static @android.annotation.NonNull android.os.Bundle defaultExtras()\nclass InlineSuggestionsRequest extends java.lang.Object implements [android.os.Parcelable]\n@com.android.internal.util.DataClass(genEqualsHashCode=true, genToString=true, genBuilder=true)\nabstract android.view.inputmethod.InlineSuggestionsRequest.Builder setInlinePresentationSpecs(java.util.List<android.widget.inline.InlinePresentationSpec>)\nabstract android.view.inputmethod.InlineSuggestionsRequest.Builder setHostPackageName(java.lang.String)\nabstract android.view.inputmethod.InlineSuggestionsRequest.Builder setHostInputToken(android.os.IBinder)\nabstract android.view.inputmethod.InlineSuggestionsRequest.Builder setHostDisplayId(int)\nclass BaseBuilder extends java.lang.Object implements []")
Feng Cao04830a32019-11-13 00:45:19 -0800589 @Deprecated
590 private void __metadata() {}
591
592
593 //@formatter:on
594 // End of generated code
595
596}