1 /*
2  * Copyright 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.hardware.input;
18 
19 import android.annotation.IntDef;
20 import android.annotation.NonNull;
21 import android.annotation.Nullable;
22 import android.os.Parcelable;
23 import android.view.inputmethod.InputMethodInfo;
24 import android.view.inputmethod.InputMethodSubtype;
25 
26 import com.android.internal.util.DataClass;
27 
28 import java.lang.annotation.Retention;
29 import java.lang.annotation.RetentionPolicy;
30 
31 /**
32  * Provides information about the selected layout and the selection criteria when the caller calls
33  * {@link InputManager#getKeyboardLayoutForInputDevice(InputDeviceIdentifier, int, InputMethodInfo,
34  * InputMethodSubtype)}
35  *
36  * @hide
37  */
38 
39 @DataClass(genParcelable = true, genToString = true, genEqualsHashCode = true)
40 public final class KeyboardLayoutSelectionResult implements Parcelable {
41     @Nullable
42     private final String mLayoutDescriptor;
43 
44     /** Unspecified layout selection criteria */
45     public static final int LAYOUT_SELECTION_CRITERIA_UNSPECIFIED = 0;
46 
47     /** Manual selection by user */
48     public static final int LAYOUT_SELECTION_CRITERIA_USER = 1;
49 
50     /** Auto-detection based on device provided language tag and layout type */
51     public static final int LAYOUT_SELECTION_CRITERIA_DEVICE = 2;
52 
53     /** Auto-detection based on IME provided language tag and layout type */
54     public static final int LAYOUT_SELECTION_CRITERIA_VIRTUAL_KEYBOARD = 3;
55 
56     /** Default selection */
57     public static final int LAYOUT_SELECTION_CRITERIA_DEFAULT = 4;
58 
59     /** Failed layout selection */
60     public static final KeyboardLayoutSelectionResult FAILED = new KeyboardLayoutSelectionResult(
61             null, LAYOUT_SELECTION_CRITERIA_UNSPECIFIED);
62 
63     @LayoutSelectionCriteria
64     private final int mSelectionCriteria;
65 
66 
67 
68     // Code below generated by codegen v1.0.23.
69     //
70     // DO NOT MODIFY!
71     // CHECKSTYLE:OFF Generated code
72     //
73     // To regenerate run:
74     // $ codegen $ANDROID_BUILD_TOP/frameworks/base/core/java/android/hardware/input/KeyboardLayoutSelectionResult.java
75     //
76     // To exclude the generated code from IntelliJ auto-formatting enable (one-time):
77     //   Settings > Editor > Code Style > Formatter Control
78     //@formatter:off
79 
80 
81     @IntDef(prefix = "LAYOUT_SELECTION_CRITERIA_", value = {
82         LAYOUT_SELECTION_CRITERIA_UNSPECIFIED,
83         LAYOUT_SELECTION_CRITERIA_USER,
84         LAYOUT_SELECTION_CRITERIA_DEVICE,
85         LAYOUT_SELECTION_CRITERIA_VIRTUAL_KEYBOARD,
86         LAYOUT_SELECTION_CRITERIA_DEFAULT
87     })
88     @Retention(RetentionPolicy.SOURCE)
89     @DataClass.Generated.Member
90     public @interface LayoutSelectionCriteria {}
91 
92     @DataClass.Generated.Member
layoutSelectionCriteriaToString(@ayoutSelectionCriteria int value)93     public static String layoutSelectionCriteriaToString(@LayoutSelectionCriteria int value) {
94         switch (value) {
95             case LAYOUT_SELECTION_CRITERIA_UNSPECIFIED:
96                     return "LAYOUT_SELECTION_CRITERIA_UNSPECIFIED";
97             case LAYOUT_SELECTION_CRITERIA_USER:
98                     return "LAYOUT_SELECTION_CRITERIA_USER";
99             case LAYOUT_SELECTION_CRITERIA_DEVICE:
100                     return "LAYOUT_SELECTION_CRITERIA_DEVICE";
101             case LAYOUT_SELECTION_CRITERIA_VIRTUAL_KEYBOARD:
102                     return "LAYOUT_SELECTION_CRITERIA_VIRTUAL_KEYBOARD";
103             case LAYOUT_SELECTION_CRITERIA_DEFAULT:
104                     return "LAYOUT_SELECTION_CRITERIA_DEFAULT";
105             default: return Integer.toHexString(value);
106         }
107     }
108 
109     @DataClass.Generated.Member
KeyboardLayoutSelectionResult( @ullable String layoutDescriptor, @LayoutSelectionCriteria int selectionCriteria)110     public KeyboardLayoutSelectionResult(
111             @Nullable String layoutDescriptor,
112             @LayoutSelectionCriteria int selectionCriteria) {
113         this.mLayoutDescriptor = layoutDescriptor;
114         this.mSelectionCriteria = selectionCriteria;
115 
116         if (!(mSelectionCriteria == LAYOUT_SELECTION_CRITERIA_UNSPECIFIED)
117                 && !(mSelectionCriteria == LAYOUT_SELECTION_CRITERIA_USER)
118                 && !(mSelectionCriteria == LAYOUT_SELECTION_CRITERIA_DEVICE)
119                 && !(mSelectionCriteria == LAYOUT_SELECTION_CRITERIA_VIRTUAL_KEYBOARD)
120                 && !(mSelectionCriteria == LAYOUT_SELECTION_CRITERIA_DEFAULT)) {
121             throw new java.lang.IllegalArgumentException(
122                     "selectionCriteria was " + mSelectionCriteria + " but must be one of: "
123                             + "LAYOUT_SELECTION_CRITERIA_UNSPECIFIED(" + LAYOUT_SELECTION_CRITERIA_UNSPECIFIED + "), "
124                             + "LAYOUT_SELECTION_CRITERIA_USER(" + LAYOUT_SELECTION_CRITERIA_USER + "), "
125                             + "LAYOUT_SELECTION_CRITERIA_DEVICE(" + LAYOUT_SELECTION_CRITERIA_DEVICE + "), "
126                             + "LAYOUT_SELECTION_CRITERIA_VIRTUAL_KEYBOARD(" + LAYOUT_SELECTION_CRITERIA_VIRTUAL_KEYBOARD + "), "
127                             + "LAYOUT_SELECTION_CRITERIA_DEFAULT(" + LAYOUT_SELECTION_CRITERIA_DEFAULT + ")");
128         }
129 
130 
131         // onConstructed(); // You can define this method to get a callback
132     }
133 
134     @DataClass.Generated.Member
getLayoutDescriptor()135     public @Nullable String getLayoutDescriptor() {
136         return mLayoutDescriptor;
137     }
138 
139     @DataClass.Generated.Member
getSelectionCriteria()140     public @LayoutSelectionCriteria int getSelectionCriteria() {
141         return mSelectionCriteria;
142     }
143 
144     @Override
145     @DataClass.Generated.Member
toString()146     public String toString() {
147         // You can override field toString logic by defining methods like:
148         // String fieldNameToString() { ... }
149 
150         return "KeyboardLayoutSelectionResult { " +
151                 "layoutDescriptor = " + mLayoutDescriptor + ", " +
152                 "selectionCriteria = " + layoutSelectionCriteriaToString(mSelectionCriteria) +
153         " }";
154     }
155 
156     @Override
157     @DataClass.Generated.Member
equals(@ullable Object o)158     public boolean equals(@Nullable Object o) {
159         // You can override field equality logic by defining either of the methods like:
160         // boolean fieldNameEquals(KeyboardLayoutSelectionResult other) { ... }
161         // boolean fieldNameEquals(FieldType otherValue) { ... }
162 
163         if (this == o) return true;
164         if (o == null || getClass() != o.getClass()) return false;
165         @SuppressWarnings("unchecked")
166         KeyboardLayoutSelectionResult that = (KeyboardLayoutSelectionResult) o;
167         //noinspection PointlessBooleanExpression
168         return true
169                 && java.util.Objects.equals(mLayoutDescriptor, that.mLayoutDescriptor)
170                 && mSelectionCriteria == that.mSelectionCriteria;
171     }
172 
173     @Override
174     @DataClass.Generated.Member
hashCode()175     public int hashCode() {
176         // You can override field hashCode logic by defining methods like:
177         // int fieldNameHashCode() { ... }
178 
179         int _hash = 1;
180         _hash = 31 * _hash + java.util.Objects.hashCode(mLayoutDescriptor);
181         _hash = 31 * _hash + mSelectionCriteria;
182         return _hash;
183     }
184 
185     @Override
186     @DataClass.Generated.Member
writeToParcel(@onNull android.os.Parcel dest, int flags)187     public void writeToParcel(@NonNull android.os.Parcel dest, int flags) {
188         // You can override field parcelling by defining methods like:
189         // void parcelFieldName(Parcel dest, int flags) { ... }
190 
191         byte flg = 0;
192         if (mLayoutDescriptor != null) flg |= 0x1;
193         dest.writeByte(flg);
194         if (mLayoutDescriptor != null) dest.writeString(mLayoutDescriptor);
195         dest.writeInt(mSelectionCriteria);
196     }
197 
198     @Override
199     @DataClass.Generated.Member
describeContents()200     public int describeContents() { return 0; }
201 
202     /** @hide */
203     @SuppressWarnings({"unchecked", "RedundantCast"})
204     @DataClass.Generated.Member
KeyboardLayoutSelectionResult(@onNull android.os.Parcel in)205     /* package-private */ KeyboardLayoutSelectionResult(@NonNull android.os.Parcel in) {
206         // You can override field unparcelling by defining methods like:
207         // static FieldType unparcelFieldName(Parcel in) { ... }
208 
209         byte flg = in.readByte();
210         String layoutDescriptor = (flg & 0x1) == 0 ? null : in.readString();
211         int selectionCriteria = in.readInt();
212 
213         this.mLayoutDescriptor = layoutDescriptor;
214         this.mSelectionCriteria = selectionCriteria;
215 
216         if (!(mSelectionCriteria == LAYOUT_SELECTION_CRITERIA_UNSPECIFIED)
217                 && !(mSelectionCriteria == LAYOUT_SELECTION_CRITERIA_USER)
218                 && !(mSelectionCriteria == LAYOUT_SELECTION_CRITERIA_DEVICE)
219                 && !(mSelectionCriteria == LAYOUT_SELECTION_CRITERIA_VIRTUAL_KEYBOARD)
220                 && !(mSelectionCriteria == LAYOUT_SELECTION_CRITERIA_DEFAULT)) {
221             throw new java.lang.IllegalArgumentException(
222                     "selectionCriteria was " + mSelectionCriteria + " but must be one of: "
223                             + "LAYOUT_SELECTION_CRITERIA_UNSPECIFIED(" + LAYOUT_SELECTION_CRITERIA_UNSPECIFIED + "), "
224                             + "LAYOUT_SELECTION_CRITERIA_USER(" + LAYOUT_SELECTION_CRITERIA_USER + "), "
225                             + "LAYOUT_SELECTION_CRITERIA_DEVICE(" + LAYOUT_SELECTION_CRITERIA_DEVICE + "), "
226                             + "LAYOUT_SELECTION_CRITERIA_VIRTUAL_KEYBOARD(" + LAYOUT_SELECTION_CRITERIA_VIRTUAL_KEYBOARD + "), "
227                             + "LAYOUT_SELECTION_CRITERIA_DEFAULT(" + LAYOUT_SELECTION_CRITERIA_DEFAULT + ")");
228         }
229 
230 
231         // onConstructed(); // You can define this method to get a callback
232     }
233 
234     @DataClass.Generated.Member
235     public static final @NonNull Parcelable.Creator<KeyboardLayoutSelectionResult> CREATOR
236             = new Parcelable.Creator<KeyboardLayoutSelectionResult>() {
237         @Override
238         public KeyboardLayoutSelectionResult[] newArray(int size) {
239             return new KeyboardLayoutSelectionResult[size];
240         }
241 
242         @Override
243         public KeyboardLayoutSelectionResult createFromParcel(@NonNull android.os.Parcel in) {
244             return new KeyboardLayoutSelectionResult(in);
245         }
246     };
247 
248     @DataClass.Generated(
249             time = 1709568115865L,
250             codegenVersion = "1.0.23",
251             sourceFile = "frameworks/base/core/java/android/hardware/input/KeyboardLayoutSelectionResult.java",
252             inputSignatures = "private final @android.annotation.Nullable java.lang.String mLayoutDescriptor\npublic static final  int LAYOUT_SELECTION_CRITERIA_UNSPECIFIED\npublic static final  int LAYOUT_SELECTION_CRITERIA_USER\npublic static final  int LAYOUT_SELECTION_CRITERIA_DEVICE\npublic static final  int LAYOUT_SELECTION_CRITERIA_VIRTUAL_KEYBOARD\npublic static final  int LAYOUT_SELECTION_CRITERIA_DEFAULT\npublic static final  android.hardware.input.KeyboardLayoutSelectionResult FAILED\nprivate final @android.hardware.input.KeyboardLayoutSelectionResult.LayoutSelectionCriteria int mSelectionCriteria\nclass KeyboardLayoutSelectionResult extends java.lang.Object implements [android.os.Parcelable]\n@com.android.internal.util.DataClass(genParcelable=true, genToString=true, genEqualsHashCode=true)")
253     @Deprecated
__metadata()254     private void __metadata() {}
255 
256 
257     //@formatter:on
258     // End of generated code
259 
260 }
261