blob: be9370a7e2af2c61ba0b0e1f1aea2f0848bbe10c [file] [log] [blame]
/*
* Copyright (C) 2019 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package android.view.inputmethod;
import android.annotation.NonNull;
import android.annotation.Nullable;
import android.app.ActivityThread;
import android.os.IBinder;
import android.os.Parcelable;
import android.view.inline.InlinePresentationSpec;
import com.android.internal.util.DataClass;
import com.android.internal.util.Preconditions;
import java.util.ArrayList;
import java.util.List;
/**
* This class represents an inline suggestion request made by one app to get suggestions from the
* other source. See {@link InlineSuggestion} for more information.
*/
@DataClass(genEqualsHashCode = true, genToString = true, genBuilder = true)
public final class InlineSuggestionsRequest implements Parcelable {
/** Constant used to indicate not putting a cap on the number of suggestions to return. */
public static final int SUGGESTION_COUNT_UNLIMITED = Integer.MAX_VALUE;
/**
* Max number of suggestions expected from the response. Defaults to {@code
* SUGGESTION_COUNT_UNLIMITED} if not set.
*/
private final int mMaxSuggestionCount;
/**
* The {@link InlinePresentationSpec} for each suggestion in the response. If the max suggestion
* count is larger than the number of specs in the list, then the last spec is used for the
* remainder of the suggestions.
*/
private final @NonNull List<InlinePresentationSpec> mPresentationSpecs;
/**
* The package name of the app that requests for the inline suggestions and will host the
* embedded suggestion views. The app does not have to set the value for the field because
* it'll be set by the system for safety reasons.
*/
private @NonNull String mHostPackageName;
/**
* The host input token of the IME that made the request. This will be set by the system for
* safety reasons.
*
* @hide
*/
private @Nullable IBinder mHostInputToken;
/**
* @hide
* @see {@link #mHostPackageName}.
*/
public void setHostPackageName(@NonNull String hostPackageName) {
mHostPackageName = hostPackageName;
}
/**
* @hide
* @see {@link #mHostInputToken}.
*/
public void setHostInputToken(IBinder hostInputToken) {
mHostInputToken = hostInputToken;
}
private void onConstructed() {
Preconditions.checkState(mMaxSuggestionCount >= mPresentationSpecs.size());
}
private static int defaultMaxSuggestionCount() {
return SUGGESTION_COUNT_UNLIMITED;
}
private static String defaultHostPackageName() {
return ActivityThread.currentPackageName();
}
private static IBinder defaultHostInputToken() {
return null;
}
/** @hide */
abstract static class BaseBuilder {
abstract Builder setPresentationSpecs(@NonNull List<InlinePresentationSpec> value);
abstract Builder setHostPackageName(@Nullable String value);
abstract Builder setHostInputToken(IBinder hostInputToken);
}
// Code below generated by codegen v1.0.14.
//
// DO NOT MODIFY!
// CHECKSTYLE:OFF Generated code
//
// To regenerate run:
// $ codegen $ANDROID_BUILD_TOP/frameworks/base/core/java/android/view/inputmethod/InlineSuggestionsRequest.java
//
// To exclude the generated code from IntelliJ auto-formatting enable (one-time):
// Settings > Editor > Code Style > Formatter Control
//@formatter:off
@DataClass.Generated.Member
/* package-private */ InlineSuggestionsRequest(
int maxSuggestionCount,
@NonNull List<InlinePresentationSpec> presentationSpecs,
@NonNull String hostPackageName,
@Nullable IBinder hostInputToken) {
this.mMaxSuggestionCount = maxSuggestionCount;
this.mPresentationSpecs = presentationSpecs;
com.android.internal.util.AnnotationValidations.validate(
NonNull.class, null, mPresentationSpecs);
this.mHostPackageName = hostPackageName;
com.android.internal.util.AnnotationValidations.validate(
NonNull.class, null, mHostPackageName);
this.mHostInputToken = hostInputToken;
onConstructed();
}
/**
* Max number of suggestions expected from the response. Defaults to {@code
* SUGGESTION_COUNT_UNLIMITED} if not set.
*/
@DataClass.Generated.Member
public int getMaxSuggestionCount() {
return mMaxSuggestionCount;
}
/**
* The {@link InlinePresentationSpec} for each suggestion in the response. If the max suggestion
* count is larger than the number of specs in the list, then the last spec is used for the
* remainder of the suggestions.
*/
@DataClass.Generated.Member
public @NonNull List<InlinePresentationSpec> getPresentationSpecs() {
return mPresentationSpecs;
}
/**
* The package name of the app that requests for the inline suggestions and will host the
* embedded suggestion views. The app does not have to set the value for the field because
* it'll be set by the system for safety reasons.
*/
@DataClass.Generated.Member
public @NonNull String getHostPackageName() {
return mHostPackageName;
}
/**
* The host input token of the IME that made the request. This will be set by the system for
* safety reasons.
*
* @hide
*/
@DataClass.Generated.Member
public @Nullable IBinder getHostInputToken() {
return mHostInputToken;
}
@Override
@DataClass.Generated.Member
public String toString() {
// You can override field toString logic by defining methods like:
// String fieldNameToString() { ... }
return "InlineSuggestionsRequest { " +
"maxSuggestionCount = " + mMaxSuggestionCount + ", " +
"presentationSpecs = " + mPresentationSpecs + ", " +
"hostPackageName = " + mHostPackageName + ", " +
"hostInputToken = " + mHostInputToken +
" }";
}
@Override
@DataClass.Generated.Member
public boolean equals(@Nullable Object o) {
// You can override field equality logic by defining either of the methods like:
// boolean fieldNameEquals(InlineSuggestionsRequest other) { ... }
// boolean fieldNameEquals(FieldType otherValue) { ... }
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
@SuppressWarnings("unchecked")
InlineSuggestionsRequest that = (InlineSuggestionsRequest) o;
//noinspection PointlessBooleanExpression
return true
&& mMaxSuggestionCount == that.mMaxSuggestionCount
&& java.util.Objects.equals(mPresentationSpecs, that.mPresentationSpecs)
&& java.util.Objects.equals(mHostPackageName, that.mHostPackageName)
&& java.util.Objects.equals(mHostInputToken, that.mHostInputToken);
}
@Override
@DataClass.Generated.Member
public int hashCode() {
// You can override field hashCode logic by defining methods like:
// int fieldNameHashCode() { ... }
int _hash = 1;
_hash = 31 * _hash + mMaxSuggestionCount;
_hash = 31 * _hash + java.util.Objects.hashCode(mPresentationSpecs);
_hash = 31 * _hash + java.util.Objects.hashCode(mHostPackageName);
_hash = 31 * _hash + java.util.Objects.hashCode(mHostInputToken);
return _hash;
}
@Override
@DataClass.Generated.Member
public void writeToParcel(@NonNull android.os.Parcel dest, int flags) {
// You can override field parcelling by defining methods like:
// void parcelFieldName(Parcel dest, int flags) { ... }
byte flg = 0;
if (mHostInputToken != null) flg |= 0x8;
dest.writeByte(flg);
dest.writeInt(mMaxSuggestionCount);
dest.writeParcelableList(mPresentationSpecs, flags);
dest.writeString(mHostPackageName);
if (mHostInputToken != null) dest.writeStrongBinder(mHostInputToken);
}
@Override
@DataClass.Generated.Member
public int describeContents() { return 0; }
/** @hide */
@SuppressWarnings({"unchecked", "RedundantCast"})
@DataClass.Generated.Member
/* package-private */ InlineSuggestionsRequest(@NonNull android.os.Parcel in) {
// You can override field unparcelling by defining methods like:
// static FieldType unparcelFieldName(Parcel in) { ... }
byte flg = in.readByte();
int maxSuggestionCount = in.readInt();
List<InlinePresentationSpec> presentationSpecs = new ArrayList<>();
in.readParcelableList(presentationSpecs, InlinePresentationSpec.class.getClassLoader());
String hostPackageName = in.readString();
IBinder hostInputToken = (flg & 0x8) == 0 ? null : in.readStrongBinder();
this.mMaxSuggestionCount = maxSuggestionCount;
this.mPresentationSpecs = presentationSpecs;
com.android.internal.util.AnnotationValidations.validate(
NonNull.class, null, mPresentationSpecs);
this.mHostPackageName = hostPackageName;
com.android.internal.util.AnnotationValidations.validate(
NonNull.class, null, mHostPackageName);
this.mHostInputToken = hostInputToken;
onConstructed();
}
@DataClass.Generated.Member
public static final @NonNull Parcelable.Creator<InlineSuggestionsRequest> CREATOR
= new Parcelable.Creator<InlineSuggestionsRequest>() {
@Override
public InlineSuggestionsRequest[] newArray(int size) {
return new InlineSuggestionsRequest[size];
}
@Override
public InlineSuggestionsRequest createFromParcel(@NonNull android.os.Parcel in) {
return new InlineSuggestionsRequest(in);
}
};
/**
* A builder for {@link InlineSuggestionsRequest}
*/
@SuppressWarnings("WeakerAccess")
@DataClass.Generated.Member
public static final class Builder extends BaseBuilder {
private int mMaxSuggestionCount;
private @NonNull List<InlinePresentationSpec> mPresentationSpecs;
private @NonNull String mHostPackageName;
private @Nullable IBinder mHostInputToken;
private long mBuilderFieldsSet = 0L;
/**
* Creates a new Builder.
*
* @param presentationSpecs
* The {@link InlinePresentationSpec} for each suggestion in the response. If the max suggestion
* count is larger than the number of specs in the list, then the last spec is used for the
* remainder of the suggestions.
*/
public Builder(
@NonNull List<InlinePresentationSpec> presentationSpecs) {
mPresentationSpecs = presentationSpecs;
com.android.internal.util.AnnotationValidations.validate(
NonNull.class, null, mPresentationSpecs);
}
/**
* Max number of suggestions expected from the response. Defaults to {@code
* SUGGESTION_COUNT_UNLIMITED} if not set.
*/
@DataClass.Generated.Member
public @NonNull Builder setMaxSuggestionCount(int value) {
checkNotUsed();
mBuilderFieldsSet |= 0x1;
mMaxSuggestionCount = value;
return this;
}
/**
* The {@link InlinePresentationSpec} for each suggestion in the response. If the max suggestion
* count is larger than the number of specs in the list, then the last spec is used for the
* remainder of the suggestions.
*/
@DataClass.Generated.Member
@Override
@NonNull Builder setPresentationSpecs(@NonNull List<InlinePresentationSpec> value) {
checkNotUsed();
mBuilderFieldsSet |= 0x2;
mPresentationSpecs = value;
return this;
}
/** @see #setPresentationSpecs */
@DataClass.Generated.Member
public @NonNull Builder addPresentationSpecs(@NonNull InlinePresentationSpec value) {
// You can refine this method's name by providing item's singular name, e.g.:
// @DataClass.PluralOf("item")) mItems = ...
if (mPresentationSpecs == null) setPresentationSpecs(new ArrayList<>());
mPresentationSpecs.add(value);
return this;
}
/**
* The package name of the app that requests for the inline suggestions and will host the
* embedded suggestion views. The app does not have to set the value for the field because
* it'll be set by the system for safety reasons.
*/
@DataClass.Generated.Member
@Override
@NonNull Builder setHostPackageName(@NonNull String value) {
checkNotUsed();
mBuilderFieldsSet |= 0x4;
mHostPackageName = value;
return this;
}
/**
* The host input token of the IME that made the request. This will be set by the system for
* safety reasons.
*
* @hide
*/
@DataClass.Generated.Member
@Override
@NonNull Builder setHostInputToken(@Nullable IBinder value) {
checkNotUsed();
mBuilderFieldsSet |= 0x8;
mHostInputToken = value;
return this;
}
/** Builds the instance. This builder should not be touched after calling this! */
public @NonNull InlineSuggestionsRequest build() {
checkNotUsed();
mBuilderFieldsSet |= 0x10; // Mark builder used
if ((mBuilderFieldsSet & 0x1) == 0) {
mMaxSuggestionCount = defaultMaxSuggestionCount();
}
if ((mBuilderFieldsSet & 0x4) == 0) {
mHostPackageName = defaultHostPackageName();
}
if ((mBuilderFieldsSet & 0x8) == 0) {
mHostInputToken = defaultHostInputToken();
}
InlineSuggestionsRequest o = new InlineSuggestionsRequest(
mMaxSuggestionCount,
mPresentationSpecs,
mHostPackageName,
mHostInputToken);
return o;
}
private void checkNotUsed() {
if ((mBuilderFieldsSet & 0x10) != 0) {
throw new IllegalStateException(
"This Builder should not be reused. Use a new Builder instance instead");
}
}
}
@DataClass.Generated(
time = 1581555687721L,
codegenVersion = "1.0.14",
sourceFile = "frameworks/base/core/java/android/view/inputmethod/InlineSuggestionsRequest.java",
inputSignatures = "public static final int SUGGESTION_COUNT_UNLIMITED\nprivate final int mMaxSuggestionCount\nprivate final @android.annotation.NonNull java.util.List<android.view.inline.InlinePresentationSpec> mPresentationSpecs\nprivate @android.annotation.NonNull java.lang.String mHostPackageName\nprivate @android.annotation.Nullable android.os.IBinder mHostInputToken\npublic void setHostPackageName(java.lang.String)\npublic void setHostInputToken(android.os.IBinder)\nprivate void onConstructed()\nprivate static int defaultMaxSuggestionCount()\nprivate static java.lang.String defaultHostPackageName()\nprivate static android.os.IBinder defaultHostInputToken()\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 setPresentationSpecs(java.util.List<android.view.inline.InlinePresentationSpec>)\nabstract android.view.inputmethod.InlineSuggestionsRequest.Builder setHostPackageName(java.lang.String)\nabstract android.view.inputmethod.InlineSuggestionsRequest.Builder setHostInputToken(android.os.IBinder)\nclass BaseBuilder extends java.lang.Object implements []")
@Deprecated
private void __metadata() {}
//@formatter:on
// End of generated code
}