blob: af896fca932a8c215355e73fa34ca369ffe61733 [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 Cao77636e82020-03-30 19:57:12 -070022import android.compat.annotation.UnsupportedAppUsage;
Feng Cao5f7e99e2020-02-14 19:27:46 -080023import android.os.Bundle;
Adam He40116252020-02-04 14:55:39 -080024import android.os.IBinder;
Feng Cao5f7e99e2020-02-14 19:27:46 -080025import android.os.LocaleList;
Svet Ganov02fdd342020-02-20 20:48:34 -080026import android.os.Parcel;
Feng Cao04830a32019-11-13 00:45:19 -080027import android.os.Parcelable;
Svet Ganov02fdd342020-02-20 20:48:34 -080028import android.view.Display;
Adam Hef27433a2020-03-25 15:11:18 -070029import android.widget.inline.InlinePresentationSpec;
Feng Cao04830a32019-11-13 00:45:19 -080030
31import com.android.internal.util.DataClass;
32import com.android.internal.util.Preconditions;
Feng Cao59b682f2020-03-30 17:43:16 -070033import com.android.internal.widget.InlinePresentationStyleUtils;
Feng Cao04830a32019-11-13 00:45:19 -080034
35import java.util.ArrayList;
36import java.util.List;
37
38/**
39 * This class represents an inline suggestion request made by one app to get suggestions from the
40 * other source. See {@link InlineSuggestion} for more information.
41 */
42@DataClass(genEqualsHashCode = true, genToString = true, genBuilder = true)
43public final class InlineSuggestionsRequest implements Parcelable {
44
45 /** Constant used to indicate not putting a cap on the number of suggestions to return. */
46 public static final int SUGGESTION_COUNT_UNLIMITED = Integer.MAX_VALUE;
47
Feng Cao7a0f0022019-12-17 18:49:24 -080048 /**
Feng Cao44dc2bd2020-03-09 23:02:33 -070049 * Max number of suggestions expected from the response. It must be a positive value.
50 * Defaults to {@code SUGGESTION_COUNT_UNLIMITED} if not set.
Feng Cao7a0f0022019-12-17 18:49:24 -080051 */
Feng Cao04830a32019-11-13 00:45:19 -080052 private final int mMaxSuggestionCount;
Feng Cao7a0f0022019-12-17 18:49:24 -080053
54 /**
55 * The {@link InlinePresentationSpec} for each suggestion in the response. If the max suggestion
56 * 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 -070057 * remainder of the suggestions. The list should not be empty.
Feng Cao7a0f0022019-12-17 18:49:24 -080058 */
Adam Hef27433a2020-03-25 15:11:18 -070059 private final @NonNull List<InlinePresentationSpec> mInlinePresentationSpecs;
Feng Cao04830a32019-11-13 00:45:19 -080060
Feng Cao16b2de52020-01-09 17:27:27 -080061 /**
62 * The package name of the app that requests for the inline suggestions and will host the
63 * embedded suggestion views. The app does not have to set the value for the field because
64 * it'll be set by the system for safety reasons.
65 */
66 private @NonNull String mHostPackageName;
67
68 /**
Feng Cao5f7e99e2020-02-14 19:27:46 -080069 * The IME provided locales for the request. If non-empty, the inline suggestions should
70 * return languages from the supported locales. If not provided, it'll default to system locale.
71 */
72 private @NonNull LocaleList mSupportedLocales;
73
Svet Ganov02fdd342020-02-20 20:48:34 -080074 /**
75 * The extras state propagated from the IME to pass extra data.
76 */
Feng Caoedb332c2020-03-30 14:26:42 -070077 private @NonNull Bundle mExtras;
Svet Ganov02fdd342020-02-20 20:48:34 -080078
Feng Cao5f7e99e2020-02-14 19:27:46 -080079 /**
Adam He40116252020-02-04 14:55:39 -080080 * The host input token of the IME that made the request. This will be set by the system for
81 * safety reasons.
82 *
83 * @hide
84 */
85 private @Nullable IBinder mHostInputToken;
86
87 /**
Svet Ganov02fdd342020-02-20 20:48:34 -080088 * The host display id of the IME that made the request. This will be set by the system for
89 * safety reasons.
90 *
91 * @hide
Feng Cao16b2de52020-01-09 17:27:27 -080092 */
Svet Ganov02fdd342020-02-20 20:48:34 -080093 private int mHostDisplayId;
Feng Cao16b2de52020-01-09 17:27:27 -080094
Adam He40116252020-02-04 14:55:39 -080095 /**
Adam Hef27433a2020-03-25 15:11:18 -070096 * The {@link InlinePresentationSpec} for each suggestion in the response. If the max suggestion
97 * count is larger than the number of specs in the list, then the last spec is used for the
98 * remainder of the suggestions. The list should not be empty.
99 *
100 * @hide
101 * @removed
102 */
Feng Cao77636e82020-03-30 19:57:12 -0700103 @UnsupportedAppUsage
104 @NonNull
105 public List<android.view.inline.InlinePresentationSpec> getPresentationSpecs() {
106 return android.view.inline.InlinePresentationSpec.fromWidgets(mInlinePresentationSpecs);
Adam Hef27433a2020-03-25 15:11:18 -0700107 }
108
109 /**
Adam He40116252020-02-04 14:55:39 -0800110 * @hide
111 * @see {@link #mHostInputToken}.
112 */
113 public void setHostInputToken(IBinder hostInputToken) {
114 mHostInputToken = hostInputToken;
115 }
116
Feng Cao59b682f2020-03-30 17:43:16 -0700117 private boolean extrasEquals(@NonNull Bundle extras) {
118 return InlinePresentationStyleUtils.bundleEquals(mExtras, extras);
119 }
120
Svet Ganov02fdd342020-02-20 20:48:34 -0800121 // TODO(b/149609075): remove once IBinder parcelling is natively supported
122 private void parcelHostInputToken(@NonNull Parcel parcel, int flags) {
123 parcel.writeStrongBinder(mHostInputToken);
124 }
125
126 // TODO(b/149609075): remove once IBinder parcelling is natively supported
127 private @Nullable IBinder unparcelHostInputToken(Parcel parcel) {
128 return parcel.readStrongBinder();
129 }
130
131 /**
132 * @hide
133 * @see {@link #mHostDisplayId}.
134 */
135 public void setHostDisplayId(int hostDisplayId) {
136 mHostDisplayId = hostDisplayId;
137 }
138
Feng Cao04830a32019-11-13 00:45:19 -0800139 private void onConstructed() {
Adam Hef27433a2020-03-25 15:11:18 -0700140 Preconditions.checkState(!mInlinePresentationSpecs.isEmpty());
141 Preconditions.checkState(mMaxSuggestionCount >= mInlinePresentationSpecs.size());
Feng Cao04830a32019-11-13 00:45:19 -0800142 }
143
144 private static int defaultMaxSuggestionCount() {
145 return SUGGESTION_COUNT_UNLIMITED;
146 }
147
Feng Cao16b2de52020-01-09 17:27:27 -0800148 private static String defaultHostPackageName() {
149 return ActivityThread.currentPackageName();
150 }
151
Feng Cao5f7e99e2020-02-14 19:27:46 -0800152 private static LocaleList defaultSupportedLocales() {
153 return LocaleList.getDefault();
154 }
155
156 @Nullable
Adam He40116252020-02-04 14:55:39 -0800157 private static IBinder defaultHostInputToken() {
158 return null;
159 }
160
Feng Cao5f7e99e2020-02-14 19:27:46 -0800161 @Nullable
Svet Ganov02fdd342020-02-20 20:48:34 -0800162 private static int defaultHostDisplayId() {
163 return Display.INVALID_DISPLAY;
164 }
165
Feng Caoedb332c2020-03-30 14:26:42 -0700166 @NonNull
Feng Cao5f7e99e2020-02-14 19:27:46 -0800167 private static Bundle defaultExtras() {
Feng Caoedb332c2020-03-30 14:26:42 -0700168 return Bundle.EMPTY;
Feng Cao5f7e99e2020-02-14 19:27:46 -0800169 }
170
Feng Cao04830a32019-11-13 00:45:19 -0800171 /** @hide */
172 abstract static class BaseBuilder {
Adam Hef27433a2020-03-25 15:11:18 -0700173 /**
Adam Hef27433a2020-03-25 15:11:18 -0700174 * @hide
175 * @removed
176 */
Feng Cao77636e82020-03-30 19:57:12 -0700177 @UnsupportedAppUsage
178 @NonNull
179 public Builder addPresentationSpecs(
Adam Hef27433a2020-03-25 15:11:18 -0700180 @NonNull android.view.inline.InlinePresentationSpec value) {
Feng Cao77636e82020-03-30 19:57:12 -0700181 return ((Builder) this).addInlinePresentationSpecs(value.toWidget());
Adam Hef27433a2020-03-25 15:11:18 -0700182 }
183
184 abstract Builder setInlinePresentationSpecs(
185 @NonNull List<android.widget.inline.InlinePresentationSpec> specs);
Feng Cao16b2de52020-01-09 17:27:27 -0800186
187 abstract Builder setHostPackageName(@Nullable String value);
Adam He40116252020-02-04 14:55:39 -0800188
189 abstract Builder setHostInputToken(IBinder hostInputToken);
Svet Ganov02fdd342020-02-20 20:48:34 -0800190
191 abstract Builder setHostDisplayId(int value);
Feng Cao04830a32019-11-13 00:45:19 -0800192 }
193
194
195
Feng Cao44dc2bd2020-03-09 23:02:33 -0700196 // Code below generated by codegen v1.0.15.
Feng Cao04830a32019-11-13 00:45:19 -0800197 //
198 // DO NOT MODIFY!
199 // CHECKSTYLE:OFF Generated code
200 //
201 // To regenerate run:
202 // $ codegen $ANDROID_BUILD_TOP/frameworks/base/core/java/android/view/inputmethod/InlineSuggestionsRequest.java
203 //
204 // To exclude the generated code from IntelliJ auto-formatting enable (one-time):
205 // Settings > Editor > Code Style > Formatter Control
206 //@formatter:off
207
208
209 @DataClass.Generated.Member
210 /* package-private */ InlineSuggestionsRequest(
211 int maxSuggestionCount,
Adam Hef27433a2020-03-25 15:11:18 -0700212 @NonNull List<InlinePresentationSpec> inlinePresentationSpecs,
Adam He40116252020-02-04 14:55:39 -0800213 @NonNull String hostPackageName,
Feng Cao5f7e99e2020-02-14 19:27:46 -0800214 @NonNull LocaleList supportedLocales,
Feng Caoedb332c2020-03-30 14:26:42 -0700215 @NonNull Bundle extras,
Feng Cao5f7e99e2020-02-14 19:27:46 -0800216 @Nullable IBinder hostInputToken,
Svet Ganov02fdd342020-02-20 20:48:34 -0800217 int hostDisplayId) {
Feng Cao04830a32019-11-13 00:45:19 -0800218 this.mMaxSuggestionCount = maxSuggestionCount;
Adam Hef27433a2020-03-25 15:11:18 -0700219 this.mInlinePresentationSpecs = inlinePresentationSpecs;
Feng Cao04830a32019-11-13 00:45:19 -0800220 com.android.internal.util.AnnotationValidations.validate(
Adam Hef27433a2020-03-25 15:11:18 -0700221 NonNull.class, null, mInlinePresentationSpecs);
Feng Cao16b2de52020-01-09 17:27:27 -0800222 this.mHostPackageName = hostPackageName;
223 com.android.internal.util.AnnotationValidations.validate(
224 NonNull.class, null, mHostPackageName);
Feng Cao5f7e99e2020-02-14 19:27:46 -0800225 this.mSupportedLocales = supportedLocales;
226 com.android.internal.util.AnnotationValidations.validate(
227 NonNull.class, null, mSupportedLocales);
Feng Cao5f7e99e2020-02-14 19:27:46 -0800228 this.mExtras = extras;
Feng Caoedb332c2020-03-30 14:26:42 -0700229 com.android.internal.util.AnnotationValidations.validate(
230 NonNull.class, null, mExtras);
Svet Ganov02fdd342020-02-20 20:48:34 -0800231 this.mHostInputToken = hostInputToken;
232 this.mHostDisplayId = hostDisplayId;
Feng Cao04830a32019-11-13 00:45:19 -0800233
234 onConstructed();
235 }
236
Feng Cao7a0f0022019-12-17 18:49:24 -0800237 /**
Feng Cao44dc2bd2020-03-09 23:02:33 -0700238 * Max number of suggestions expected from the response. It must be a positive value.
239 * Defaults to {@code SUGGESTION_COUNT_UNLIMITED} if not set.
Feng Cao7a0f0022019-12-17 18:49:24 -0800240 */
Feng Cao04830a32019-11-13 00:45:19 -0800241 @DataClass.Generated.Member
242 public int getMaxSuggestionCount() {
243 return mMaxSuggestionCount;
244 }
245
Feng Cao7a0f0022019-12-17 18:49:24 -0800246 /**
247 * The {@link InlinePresentationSpec} for each suggestion in the response. If the max suggestion
248 * 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 -0700249 * remainder of the suggestions. The list should not be empty.
Feng Cao7a0f0022019-12-17 18:49:24 -0800250 */
Feng Cao04830a32019-11-13 00:45:19 -0800251 @DataClass.Generated.Member
Adam Hef27433a2020-03-25 15:11:18 -0700252 public @NonNull List<InlinePresentationSpec> getInlinePresentationSpecs() {
253 return mInlinePresentationSpecs;
Feng Cao04830a32019-11-13 00:45:19 -0800254 }
255
Feng Cao16b2de52020-01-09 17:27:27 -0800256 /**
257 * The package name of the app that requests for the inline suggestions and will host the
258 * embedded suggestion views. The app does not have to set the value for the field because
259 * it'll be set by the system for safety reasons.
260 */
261 @DataClass.Generated.Member
262 public @NonNull String getHostPackageName() {
263 return mHostPackageName;
264 }
265
Adam He40116252020-02-04 14:55:39 -0800266 /**
Feng Cao5f7e99e2020-02-14 19:27:46 -0800267 * The IME provided locales for the request. If non-empty, the inline suggestions should
268 * return languages from the supported locales. If not provided, it'll default to system locale.
269 */
270 @DataClass.Generated.Member
271 public @NonNull LocaleList getSupportedLocales() {
272 return mSupportedLocales;
273 }
274
275 /**
Svet Ganov02fdd342020-02-20 20:48:34 -0800276 * The extras state propagated from the IME to pass extra data.
277 */
278 @DataClass.Generated.Member
Feng Caoedb332c2020-03-30 14:26:42 -0700279 public @NonNull Bundle getExtras() {
Svet Ganov02fdd342020-02-20 20:48:34 -0800280 return mExtras;
281 }
282
283 /**
Adam He40116252020-02-04 14:55:39 -0800284 * The host input token of the IME that made the request. This will be set by the system for
285 * safety reasons.
286 *
287 * @hide
288 */
289 @DataClass.Generated.Member
290 public @Nullable IBinder getHostInputToken() {
291 return mHostInputToken;
292 }
293
Feng Cao5f7e99e2020-02-14 19:27:46 -0800294 /**
Svet Ganov02fdd342020-02-20 20:48:34 -0800295 * The host display id of the IME that made the request. This will be set by the system for
296 * safety reasons.
297 *
298 * @hide
Feng Cao5f7e99e2020-02-14 19:27:46 -0800299 */
300 @DataClass.Generated.Member
Svet Ganov02fdd342020-02-20 20:48:34 -0800301 public int getHostDisplayId() {
302 return mHostDisplayId;
Feng Cao5f7e99e2020-02-14 19:27:46 -0800303 }
304
Feng Cao04830a32019-11-13 00:45:19 -0800305 @Override
306 @DataClass.Generated.Member
307 public String toString() {
308 // You can override field toString logic by defining methods like:
309 // String fieldNameToString() { ... }
310
311 return "InlineSuggestionsRequest { " +
312 "maxSuggestionCount = " + mMaxSuggestionCount + ", " +
Adam Hef27433a2020-03-25 15:11:18 -0700313 "inlinePresentationSpecs = " + mInlinePresentationSpecs + ", " +
Adam He40116252020-02-04 14:55:39 -0800314 "hostPackageName = " + mHostPackageName + ", " +
Feng Cao5f7e99e2020-02-14 19:27:46 -0800315 "supportedLocales = " + mSupportedLocales + ", " +
Svet Ganov02fdd342020-02-20 20:48:34 -0800316 "extras = " + mExtras + ", " +
Feng Cao5f7e99e2020-02-14 19:27:46 -0800317 "hostInputToken = " + mHostInputToken + ", " +
Svet Ganov02fdd342020-02-20 20:48:34 -0800318 "hostDisplayId = " + mHostDisplayId +
Feng Cao04830a32019-11-13 00:45:19 -0800319 " }";
320 }
321
322 @Override
323 @DataClass.Generated.Member
Feng Cao16b2de52020-01-09 17:27:27 -0800324 public boolean equals(@Nullable Object o) {
Feng Cao04830a32019-11-13 00:45:19 -0800325 // You can override field equality logic by defining either of the methods like:
326 // boolean fieldNameEquals(InlineSuggestionsRequest other) { ... }
327 // boolean fieldNameEquals(FieldType otherValue) { ... }
328
329 if (this == o) return true;
330 if (o == null || getClass() != o.getClass()) return false;
331 @SuppressWarnings("unchecked")
332 InlineSuggestionsRequest that = (InlineSuggestionsRequest) o;
333 //noinspection PointlessBooleanExpression
334 return true
335 && mMaxSuggestionCount == that.mMaxSuggestionCount
Adam Hef27433a2020-03-25 15:11:18 -0700336 && java.util.Objects.equals(mInlinePresentationSpecs, that.mInlinePresentationSpecs)
Adam He40116252020-02-04 14:55:39 -0800337 && java.util.Objects.equals(mHostPackageName, that.mHostPackageName)
Feng Cao5f7e99e2020-02-14 19:27:46 -0800338 && java.util.Objects.equals(mSupportedLocales, that.mSupportedLocales)
Feng Cao59b682f2020-03-30 17:43:16 -0700339 && extrasEquals(that.mExtras)
Feng Cao5f7e99e2020-02-14 19:27:46 -0800340 && java.util.Objects.equals(mHostInputToken, that.mHostInputToken)
Svet Ganov02fdd342020-02-20 20:48:34 -0800341 && mHostDisplayId == that.mHostDisplayId;
Feng Cao04830a32019-11-13 00:45:19 -0800342 }
343
344 @Override
345 @DataClass.Generated.Member
346 public int hashCode() {
347 // You can override field hashCode logic by defining methods like:
348 // int fieldNameHashCode() { ... }
349
350 int _hash = 1;
351 _hash = 31 * _hash + mMaxSuggestionCount;
Adam Hef27433a2020-03-25 15:11:18 -0700352 _hash = 31 * _hash + java.util.Objects.hashCode(mInlinePresentationSpecs);
Feng Cao16b2de52020-01-09 17:27:27 -0800353 _hash = 31 * _hash + java.util.Objects.hashCode(mHostPackageName);
Feng Cao5f7e99e2020-02-14 19:27:46 -0800354 _hash = 31 * _hash + java.util.Objects.hashCode(mSupportedLocales);
Feng Cao5f7e99e2020-02-14 19:27:46 -0800355 _hash = 31 * _hash + java.util.Objects.hashCode(mExtras);
Svet Ganov02fdd342020-02-20 20:48:34 -0800356 _hash = 31 * _hash + java.util.Objects.hashCode(mHostInputToken);
357 _hash = 31 * _hash + mHostDisplayId;
Feng Cao04830a32019-11-13 00:45:19 -0800358 return _hash;
359 }
360
361 @Override
362 @DataClass.Generated.Member
Svet Ganov02fdd342020-02-20 20:48:34 -0800363 public void writeToParcel(@NonNull Parcel dest, int flags) {
Feng Cao04830a32019-11-13 00:45:19 -0800364 // You can override field parcelling by defining methods like:
365 // void parcelFieldName(Parcel dest, int flags) { ... }
366
Adam He40116252020-02-04 14:55:39 -0800367 byte flg = 0;
Svet Ganov02fdd342020-02-20 20:48:34 -0800368 if (mHostInputToken != null) flg |= 0x20;
Adam He40116252020-02-04 14:55:39 -0800369 dest.writeByte(flg);
Feng Cao04830a32019-11-13 00:45:19 -0800370 dest.writeInt(mMaxSuggestionCount);
Adam Hef27433a2020-03-25 15:11:18 -0700371 dest.writeParcelableList(mInlinePresentationSpecs, flags);
Feng Cao16b2de52020-01-09 17:27:27 -0800372 dest.writeString(mHostPackageName);
Feng Cao5f7e99e2020-02-14 19:27:46 -0800373 dest.writeTypedObject(mSupportedLocales, flags);
Feng Caoedb332c2020-03-30 14:26:42 -0700374 dest.writeBundle(mExtras);
Svet Ganov02fdd342020-02-20 20:48:34 -0800375 parcelHostInputToken(dest, flags);
376 dest.writeInt(mHostDisplayId);
Feng Cao04830a32019-11-13 00:45:19 -0800377 }
378
379 @Override
380 @DataClass.Generated.Member
381 public int describeContents() { return 0; }
382
383 /** @hide */
384 @SuppressWarnings({"unchecked", "RedundantCast"})
385 @DataClass.Generated.Member
Svet Ganov02fdd342020-02-20 20:48:34 -0800386 /* package-private */ InlineSuggestionsRequest(@NonNull Parcel in) {
Feng Cao04830a32019-11-13 00:45:19 -0800387 // You can override field unparcelling by defining methods like:
388 // static FieldType unparcelFieldName(Parcel in) { ... }
389
Adam He40116252020-02-04 14:55:39 -0800390 byte flg = in.readByte();
Feng Cao04830a32019-11-13 00:45:19 -0800391 int maxSuggestionCount = in.readInt();
Adam Hef27433a2020-03-25 15:11:18 -0700392 List<InlinePresentationSpec> inlinePresentationSpecs = new ArrayList<>();
393 in.readParcelableList(inlinePresentationSpecs, InlinePresentationSpec.class.getClassLoader());
Feng Cao16b2de52020-01-09 17:27:27 -0800394 String hostPackageName = in.readString();
Feng Cao5f7e99e2020-02-14 19:27:46 -0800395 LocaleList supportedLocales = (LocaleList) in.readTypedObject(LocaleList.CREATOR);
Feng Caoedb332c2020-03-30 14:26:42 -0700396 Bundle extras = in.readBundle();
Svet Ganov02fdd342020-02-20 20:48:34 -0800397 IBinder hostInputToken = unparcelHostInputToken(in);
398 int hostDisplayId = in.readInt();
Feng Cao04830a32019-11-13 00:45:19 -0800399
400 this.mMaxSuggestionCount = maxSuggestionCount;
Adam Hef27433a2020-03-25 15:11:18 -0700401 this.mInlinePresentationSpecs = inlinePresentationSpecs;
Feng Cao04830a32019-11-13 00:45:19 -0800402 com.android.internal.util.AnnotationValidations.validate(
Adam Hef27433a2020-03-25 15:11:18 -0700403 NonNull.class, null, mInlinePresentationSpecs);
Feng Cao16b2de52020-01-09 17:27:27 -0800404 this.mHostPackageName = hostPackageName;
405 com.android.internal.util.AnnotationValidations.validate(
406 NonNull.class, null, mHostPackageName);
Feng Cao5f7e99e2020-02-14 19:27:46 -0800407 this.mSupportedLocales = supportedLocales;
408 com.android.internal.util.AnnotationValidations.validate(
409 NonNull.class, null, mSupportedLocales);
Feng Cao5f7e99e2020-02-14 19:27:46 -0800410 this.mExtras = extras;
Feng Caoedb332c2020-03-30 14:26:42 -0700411 com.android.internal.util.AnnotationValidations.validate(
412 NonNull.class, null, mExtras);
Svet Ganov02fdd342020-02-20 20:48:34 -0800413 this.mHostInputToken = hostInputToken;
414 this.mHostDisplayId = hostDisplayId;
Feng Cao04830a32019-11-13 00:45:19 -0800415
416 onConstructed();
417 }
418
419 @DataClass.Generated.Member
420 public static final @NonNull Parcelable.Creator<InlineSuggestionsRequest> CREATOR
421 = new Parcelable.Creator<InlineSuggestionsRequest>() {
422 @Override
423 public InlineSuggestionsRequest[] newArray(int size) {
424 return new InlineSuggestionsRequest[size];
425 }
426
427 @Override
Svet Ganov02fdd342020-02-20 20:48:34 -0800428 public InlineSuggestionsRequest createFromParcel(@NonNull Parcel in) {
Feng Cao04830a32019-11-13 00:45:19 -0800429 return new InlineSuggestionsRequest(in);
430 }
431 };
432
433 /**
434 * A builder for {@link InlineSuggestionsRequest}
435 */
436 @SuppressWarnings("WeakerAccess")
437 @DataClass.Generated.Member
438 public static final class Builder extends BaseBuilder {
439
440 private int mMaxSuggestionCount;
Adam Hef27433a2020-03-25 15:11:18 -0700441 private @NonNull List<InlinePresentationSpec> mInlinePresentationSpecs;
Feng Cao16b2de52020-01-09 17:27:27 -0800442 private @NonNull String mHostPackageName;
Feng Cao5f7e99e2020-02-14 19:27:46 -0800443 private @NonNull LocaleList mSupportedLocales;
Feng Caoedb332c2020-03-30 14:26:42 -0700444 private @NonNull Bundle mExtras;
Svet Ganov02fdd342020-02-20 20:48:34 -0800445 private @Nullable IBinder mHostInputToken;
446 private int mHostDisplayId;
Feng Cao04830a32019-11-13 00:45:19 -0800447
448 private long mBuilderFieldsSet = 0L;
449
Feng Cao7a0f0022019-12-17 18:49:24 -0800450 /**
451 * Creates a new Builder.
452 *
Adam Hef27433a2020-03-25 15:11:18 -0700453 * @param inlinePresentationSpecs
Feng Cao7a0f0022019-12-17 18:49:24 -0800454 * The {@link InlinePresentationSpec} for each suggestion in the response. If the max suggestion
455 * 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 -0700456 * remainder of the suggestions. The list should not be empty.
Feng Cao7a0f0022019-12-17 18:49:24 -0800457 */
Feng Cao04830a32019-11-13 00:45:19 -0800458 public Builder(
Adam Hef27433a2020-03-25 15:11:18 -0700459 @NonNull List<InlinePresentationSpec> inlinePresentationSpecs) {
460 mInlinePresentationSpecs = inlinePresentationSpecs;
Feng Cao04830a32019-11-13 00:45:19 -0800461 com.android.internal.util.AnnotationValidations.validate(
Adam Hef27433a2020-03-25 15:11:18 -0700462 NonNull.class, null, mInlinePresentationSpecs);
Feng Cao04830a32019-11-13 00:45:19 -0800463 }
464
Feng Cao7a0f0022019-12-17 18:49:24 -0800465 /**
Feng Cao44dc2bd2020-03-09 23:02:33 -0700466 * Max number of suggestions expected from the response. It must be a positive value.
467 * Defaults to {@code SUGGESTION_COUNT_UNLIMITED} if not set.
Feng Cao7a0f0022019-12-17 18:49:24 -0800468 */
Feng Cao04830a32019-11-13 00:45:19 -0800469 @DataClass.Generated.Member
470 public @NonNull Builder setMaxSuggestionCount(int value) {
471 checkNotUsed();
472 mBuilderFieldsSet |= 0x1;
473 mMaxSuggestionCount = value;
474 return this;
475 }
476
Feng Cao7a0f0022019-12-17 18:49:24 -0800477 /**
478 * The {@link InlinePresentationSpec} for each suggestion in the response. If the max suggestion
479 * 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 -0700480 * remainder of the suggestions. The list should not be empty.
Feng Cao7a0f0022019-12-17 18:49:24 -0800481 */
Feng Cao04830a32019-11-13 00:45:19 -0800482 @DataClass.Generated.Member
Adam Hef27433a2020-03-25 15:11:18 -0700483 public @NonNull Builder setInlinePresentationSpecs(@NonNull List<InlinePresentationSpec> value) {
Feng Cao04830a32019-11-13 00:45:19 -0800484 checkNotUsed();
485 mBuilderFieldsSet |= 0x2;
Adam Hef27433a2020-03-25 15:11:18 -0700486 mInlinePresentationSpecs = value;
Feng Cao04830a32019-11-13 00:45:19 -0800487 return this;
488 }
489
Adam Hef27433a2020-03-25 15:11:18 -0700490 /** @see #setInlinePresentationSpecs */
Feng Cao04830a32019-11-13 00:45:19 -0800491 @DataClass.Generated.Member
Adam Hef27433a2020-03-25 15:11:18 -0700492 public @NonNull Builder addInlinePresentationSpecs(@NonNull InlinePresentationSpec value) {
Feng Cao04830a32019-11-13 00:45:19 -0800493 // You can refine this method's name by providing item's singular name, e.g.:
494 // @DataClass.PluralOf("item")) mItems = ...
495
Adam Hef27433a2020-03-25 15:11:18 -0700496 if (mInlinePresentationSpecs == null) setInlinePresentationSpecs(new ArrayList<>());
497 mInlinePresentationSpecs.add(value);
Feng Cao04830a32019-11-13 00:45:19 -0800498 return this;
499 }
500
Feng Cao16b2de52020-01-09 17:27:27 -0800501 /**
502 * The package name of the app that requests for the inline suggestions and will host the
503 * embedded suggestion views. The app does not have to set the value for the field because
504 * it'll be set by the system for safety reasons.
505 */
506 @DataClass.Generated.Member
507 @Override
508 @NonNull Builder setHostPackageName(@NonNull String value) {
509 checkNotUsed();
510 mBuilderFieldsSet |= 0x4;
511 mHostPackageName = value;
512 return this;
513 }
514
Adam He40116252020-02-04 14:55:39 -0800515 /**
Feng Cao5f7e99e2020-02-14 19:27:46 -0800516 * The IME provided locales for the request. If non-empty, the inline suggestions should
517 * return languages from the supported locales. If not provided, it'll default to system locale.
518 */
519 @DataClass.Generated.Member
520 public @NonNull Builder setSupportedLocales(@NonNull LocaleList value) {
521 checkNotUsed();
522 mBuilderFieldsSet |= 0x8;
523 mSupportedLocales = value;
524 return this;
525 }
526
527 /**
Svet Ganov02fdd342020-02-20 20:48:34 -0800528 * The extras state propagated from the IME to pass extra data.
529 */
530 @DataClass.Generated.Member
Feng Cao1ee5afa2020-03-12 20:32:45 -0700531 public @NonNull Builder setExtras(@NonNull Bundle value) {
Svet Ganov02fdd342020-02-20 20:48:34 -0800532 checkNotUsed();
533 mBuilderFieldsSet |= 0x10;
534 mExtras = value;
535 return this;
536 }
537
538 /**
Adam He40116252020-02-04 14:55:39 -0800539 * The host input token of the IME that made the request. This will be set by the system for
540 * safety reasons.
541 *
542 * @hide
543 */
544 @DataClass.Generated.Member
545 @Override
Feng Cao1ee5afa2020-03-12 20:32:45 -0700546 @NonNull Builder setHostInputToken(@NonNull IBinder value) {
Adam He40116252020-02-04 14:55:39 -0800547 checkNotUsed();
Svet Ganov02fdd342020-02-20 20:48:34 -0800548 mBuilderFieldsSet |= 0x20;
Adam He40116252020-02-04 14:55:39 -0800549 mHostInputToken = value;
550 return this;
551 }
552
Feng Cao5f7e99e2020-02-14 19:27:46 -0800553 /**
Svet Ganov02fdd342020-02-20 20:48:34 -0800554 * The host display id of the IME that made the request. This will be set by the system for
555 * safety reasons.
556 *
557 * @hide
Feng Cao5f7e99e2020-02-14 19:27:46 -0800558 */
559 @DataClass.Generated.Member
Svet Ganov02fdd342020-02-20 20:48:34 -0800560 @Override
561 @NonNull Builder setHostDisplayId(int value) {
Feng Cao5f7e99e2020-02-14 19:27:46 -0800562 checkNotUsed();
Svet Ganov02fdd342020-02-20 20:48:34 -0800563 mBuilderFieldsSet |= 0x40;
564 mHostDisplayId = value;
Feng Cao5f7e99e2020-02-14 19:27:46 -0800565 return this;
566 }
567
Feng Cao04830a32019-11-13 00:45:19 -0800568 /** Builds the instance. This builder should not be touched after calling this! */
569 public @NonNull InlineSuggestionsRequest build() {
570 checkNotUsed();
Svet Ganov02fdd342020-02-20 20:48:34 -0800571 mBuilderFieldsSet |= 0x80; // Mark builder used
Feng Cao04830a32019-11-13 00:45:19 -0800572
573 if ((mBuilderFieldsSet & 0x1) == 0) {
574 mMaxSuggestionCount = defaultMaxSuggestionCount();
575 }
Feng Cao16b2de52020-01-09 17:27:27 -0800576 if ((mBuilderFieldsSet & 0x4) == 0) {
577 mHostPackageName = defaultHostPackageName();
578 }
Adam He40116252020-02-04 14:55:39 -0800579 if ((mBuilderFieldsSet & 0x8) == 0) {
Feng Cao5f7e99e2020-02-14 19:27:46 -0800580 mSupportedLocales = defaultSupportedLocales();
581 }
582 if ((mBuilderFieldsSet & 0x10) == 0) {
Svet Ganov02fdd342020-02-20 20:48:34 -0800583 mExtras = defaultExtras();
Adam He40116252020-02-04 14:55:39 -0800584 }
Feng Cao5f7e99e2020-02-14 19:27:46 -0800585 if ((mBuilderFieldsSet & 0x20) == 0) {
Svet Ganov02fdd342020-02-20 20:48:34 -0800586 mHostInputToken = defaultHostInputToken();
587 }
588 if ((mBuilderFieldsSet & 0x40) == 0) {
589 mHostDisplayId = defaultHostDisplayId();
Feng Cao5f7e99e2020-02-14 19:27:46 -0800590 }
Feng Cao04830a32019-11-13 00:45:19 -0800591 InlineSuggestionsRequest o = new InlineSuggestionsRequest(
592 mMaxSuggestionCount,
Adam Hef27433a2020-03-25 15:11:18 -0700593 mInlinePresentationSpecs,
Adam He40116252020-02-04 14:55:39 -0800594 mHostPackageName,
Feng Cao5f7e99e2020-02-14 19:27:46 -0800595 mSupportedLocales,
Svet Ganov02fdd342020-02-20 20:48:34 -0800596 mExtras,
Feng Cao5f7e99e2020-02-14 19:27:46 -0800597 mHostInputToken,
Svet Ganov02fdd342020-02-20 20:48:34 -0800598 mHostDisplayId);
Feng Cao04830a32019-11-13 00:45:19 -0800599 return o;
600 }
601
602 private void checkNotUsed() {
Svet Ganov02fdd342020-02-20 20:48:34 -0800603 if ((mBuilderFieldsSet & 0x80) != 0) {
Feng Cao04830a32019-11-13 00:45:19 -0800604 throw new IllegalStateException(
605 "This Builder should not be reused. Use a new Builder instance instead");
606 }
607 }
608 }
609
610 @DataClass.Generated(
Feng Cao59b682f2020-03-30 17:43:16 -0700611 time = 1585768018462L,
Feng Cao44dc2bd2020-03-09 23:02:33 -0700612 codegenVersion = "1.0.15",
Feng Cao04830a32019-11-13 00:45:19 -0800613 sourceFile = "frameworks/base/core/java/android/view/inputmethod/InlineSuggestionsRequest.java",
Feng Cao59b682f2020-03-30 17:43:16 -0700614 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 @android.compat.annotation.UnsupportedAppUsage @android.annotation.NonNull java.util.List<android.view.inline.InlinePresentationSpec> getPresentationSpecs()\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)\npublic @android.compat.annotation.UnsupportedAppUsage @android.annotation.NonNull android.view.inputmethod.InlineSuggestionsRequest.Builder addPresentationSpecs(android.view.inline.InlinePresentationSpec)\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 -0800615 @Deprecated
616 private void __metadata() {}
617
618
619 //@formatter:on
620 // End of generated code
621
622}