1 /* 2 * Copyright (C) 2023 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.assist.classification; 18 19 import android.annotation.NonNull; 20 import android.annotation.SystemApi; 21 import android.os.Parcel; 22 import android.os.Parcelable; 23 import android.util.ArraySet; 24 import android.view.autofill.AutofillId; 25 26 27 import com.android.internal.util.DataClass; 28 29 import java.util.ArrayList; 30 import java.util.List; 31 import java.util.Set; 32 33 /** 34 * Represents a classified field from the detection service. 35 */ 36 // TODO(b/266930067): Once @SystemApi is supported, use genSetters and genConstructor. 37 @DataClass( 38 genToString = true, 39 genConstructor = false 40 ) 41 public final class FieldClassification implements Parcelable { 42 43 /** 44 * Autofill id of the detected field 45 */ 46 private final @NonNull AutofillId mAutofillId; 47 48 /** 49 * Detected fields types represented as autofill hints 50 * 51 * A particular field can be detected as multiple types. For eg: A sign-in field may take in a 52 * username, an email address or a phone number. In such cases, it should be detected as 53 * "username", "emailAddress" and "phoneNumber" 54 * 55 * The value of these hints are contained in androidx.autofill.HintConstants 56 */ 57 private final @NonNull Set<String> mHints; 58 59 60 /** 61 * Group hints are the hints that may represent the group of related hints (including 62 * themselves). The value of these group hints are contained in androidx.autofill.HintConstants 63 * 64 * <p> 65 * 66 * "creditCardNumber" is the group hint for hints containing credit card related fields: 67 * "creditCardNumber", "creditCardExpirationDate", "creditCardExpirationDay", 68 * "creditCardExpirationMonth", "creditCardExpirationYear", "creditCardSecurityCode", 69 * 70 * <p> 71 * 72 * "postalAddress" is the group hint for hints all postal address related fields: 73 * "postalAddress", "streetAddress", "aptNumber", "dependentLocality", "extendedAddress", 74 * "postalCode", "extendedPostalCode", "addressLocality", "addressRegion", "addressCountry". 75 * 76 * <p> 77 * 78 * "phoneNumber" is the group hint for hints all phone number related fields: "phoneNumber", 79 * "phoneNumberDevice", "phoneNational", "phoneCountryCode". 80 * 81 * <p> 82 * 83 * "personName" is the group hint for hints all name related fields: "personName", 84 * "personFamilyName", "personGivenName", "personMiddleName", "personMiddleInitial", 85 * "personNamePrefix", "personNameSuffix" . 86 * 87 * <p> 88 * 89 * "birthDateFull" is the group hint for hints containing birthday related fields: 90 * "birthDateFull", "birthDateMonth", "birthDateYear", 91 * 92 * @hide 93 */ 94 private final @NonNull Set<String> mGroupHints; 95 96 /** 97 * Autofill id of the detected field. 98 */ getAutofillId()99 public @NonNull AutofillId getAutofillId() { 100 return mAutofillId; 101 } 102 103 /** 104 * Detected fields types represented as autofill hints. 105 * 106 * A particular field can be detected as multiple types. For eg: A sign-in field may take in a 107 * username, an email address or a phone number. In such cases, it should be detected as 108 * "username", "emailAddress" and "phoneNumber" 109 * 110 * The value of these hints are contained in androidx.autofill.HintConstants 111 */ getHints()112 public @NonNull Set<String> getHints() { 113 return mHints; 114 } 115 116 /** 117 * Group hints are the hints that may represent the group of related hints (including 118 * themselves). The value of these group hints are contained in androidx.autofill.HintConstants 119 * 120 * <p> 121 * 122 * "creditCardNumber" is the group hint for hints containing credit card related fields: 123 * "creditCardNumber", "creditCardExpirationDate", "creditCardExpirationDay", 124 * "creditCardExpirationMonth", "creditCardExpirationYear", "creditCardSecurityCode", 125 * 126 * <p> 127 * 128 * "postalAddress" is the group hint for hints all postal address related fields: 129 * "postalAddress", "streetAddress", "aptNumber", "dependentLocality", "extendedAddress", 130 * "postalCode", "extendedPostalCode", "addressLocality", "addressRegion", "addressCountry". 131 * 132 * <p> 133 * 134 * "phoneNumber" is the group hint for hints all phone number related fields: "phoneNumber", 135 * "phoneNumberDevice", "phoneNational", "phoneCountryCode". 136 * 137 * <p> 138 * 139 * "personName" is the group hint for hints all name related fields: "personName", 140 * "personFamilyName", "personGivenName", "personMiddleName", "personMiddleInitial", 141 * "personNamePrefix", "personNameSuffix" . 142 * 143 * <p> 144 * 145 * "birthDateFull" is the group hint for hints containing birthday related fields: 146 * "birthDateFull", "birthDateMonth", "birthDateYear", 147 * 148 * @hide 149 */ 150 @SystemApi getGroupHints()151 public @NonNull Set<String> getGroupHints() { 152 return mGroupHints; 153 } 154 unparcelHints(Parcel in)155 static Set<String> unparcelHints(Parcel in) { 156 List<String> hints = new java.util.ArrayList<>(); 157 in.readStringList(hints); 158 return new ArraySet<>(hints); 159 } 160 parcelHints(Parcel dest, int flags)161 void parcelHints(Parcel dest, int flags) { 162 dest.writeStringList(new ArrayList<>(mHints)); 163 } 164 unparcelGroupHints(Parcel in)165 static Set<String> unparcelGroupHints(Parcel in) { 166 List<String> groupHints = new java.util.ArrayList<>(); 167 in.readStringList(groupHints); 168 return new ArraySet<>(groupHints); 169 } 170 parcelGroupHints(Parcel dest, int flags)171 void parcelGroupHints(Parcel dest, int flags) { 172 dest.writeStringList(new ArrayList<>(mGroupHints)); 173 } 174 175 /** 176 * Creates a new FieldClassification. 177 * 178 * @param autofillId 179 * Autofill id of the detected field 180 * @param hints 181 * Detected fields types represented as autofill hints. 182 * A particular field can be detected as multiple types. For eg: A sign-in field may take in 183 * a username, an email address or a phone number. In such cases, it should be detected as 184 * "username", "emailAddress" and "phoneNumber" 185 */ FieldClassification( @onNull AutofillId autofillId, @NonNull Set<String> hints)186 public FieldClassification( 187 @NonNull AutofillId autofillId, 188 @NonNull Set<String> hints) { 189 this(autofillId, hints, new ArraySet<>()); 190 } 191 192 /** 193 * Creates a new FieldClassification. 194 * 195 * @param autofillId Autofill id of the detected field 196 * @param hints Detected fields types represented as autofill hints A particular field can be 197 * detected as multiple types. For eg: A sign-in field may take in a username, an email 198 * address or a phone number. In such cases, it should be detected as "username", 199 * "emailAddress" and "phoneNumber" 200 * @param groupHints Hints that may represent the group of related hints (including themselves). 201 * The value of these group hints are contained in androidx.autofill.HintConstants. 202 * See {@link #getGroupHints()} for more details 203 * @hide 204 */ 205 @SystemApi 206 @DataClass.Generated.Member FieldClassification( @onNull AutofillId autofillId, @NonNull Set<String> hints, @NonNull Set<String> groupHints)207 public FieldClassification( 208 @NonNull AutofillId autofillId, 209 @NonNull Set<String> hints, 210 @NonNull Set<String> groupHints) { 211 this.mAutofillId = autofillId; 212 // com.android.internal.util.AnnotationValidations.validate( 213 // NonNull.class, null, mAutofillId); 214 this.mHints = hints; 215 // com.android.internal.util.AnnotationValidations.validate( 216 // NonNull.class, null, mHints); 217 this.mGroupHints = groupHints; 218 // com.android.internal.util.AnnotationValidations.validate( 219 // NonNull.class, null, mGroupHints); 220 } 221 222 223 224 // Code below generated by codegen v1.0.23. 225 // 226 // DO NOT MODIFY! 227 // CHECKSTYLE:OFF Generated code 228 // 229 // To regenerate run: 230 // $ codegen $ANDROID_BUILD_TOP/frameworks/base/core/java/android/service/assist/classification/FieldClassification.java 231 // 232 // To exclude the generated code from IntelliJ auto-formatting enable (one-time): 233 // Settings > Editor > Code Style > Formatter Control 234 //@formatter:off 235 236 237 @Override 238 @DataClass.Generated.Member toString()239 public String toString() { 240 // You can override field toString logic by defining methods like: 241 // String fieldNameToString() { ... } 242 243 return "FieldClassification { " + 244 "autofillId = " + mAutofillId + ", " + 245 "hints = " + mHints + ", " + 246 "groupHints = " + mGroupHints + 247 " }"; 248 } 249 250 @Override 251 @DataClass.Generated.Member writeToParcel(@onNull Parcel dest, int flags)252 public void writeToParcel(@NonNull Parcel dest, int flags) { 253 // You can override field parcelling by defining methods like: 254 // void parcelFieldName(Parcel dest, int flags) { ... } 255 256 dest.writeTypedObject(mAutofillId, flags); 257 parcelHints(dest, flags); 258 parcelGroupHints(dest, flags); 259 } 260 261 @Override 262 @DataClass.Generated.Member describeContents()263 public int describeContents() { return 0; } 264 265 /** @hide */ 266 @SuppressWarnings({"unchecked", "RedundantCast"}) 267 @DataClass.Generated.Member FieldClassification(@onNull Parcel in)268 /* package-private */ FieldClassification(@NonNull Parcel in) { 269 // You can override field unparcelling by defining methods like: 270 // static FieldType unparcelFieldName(Parcel in) { ... } 271 272 AutofillId autofillId = (AutofillId) in.readTypedObject(AutofillId.CREATOR); 273 Set<String> hints = unparcelHints(in); 274 Set<String> groupHints = unparcelGroupHints(in); 275 276 this.mAutofillId = autofillId; 277 com.android.internal.util.AnnotationValidations.validate( 278 NonNull.class, null, mAutofillId); 279 this.mHints = hints; 280 com.android.internal.util.AnnotationValidations.validate( 281 NonNull.class, null, mHints); 282 this.mGroupHints = groupHints; 283 com.android.internal.util.AnnotationValidations.validate( 284 NonNull.class, null, mGroupHints); 285 286 // onConstructed(); // You can define this method to get a callback 287 } 288 289 @DataClass.Generated.Member 290 public static final @NonNull Parcelable.Creator<FieldClassification> CREATOR 291 = new Parcelable.Creator<FieldClassification>() { 292 @Override 293 public FieldClassification[] newArray(int size) { 294 return new FieldClassification[size]; 295 } 296 297 @Override 298 public FieldClassification createFromParcel(@NonNull Parcel in) { 299 return new FieldClassification(in); 300 } 301 }; 302 303 @DataClass.Generated( 304 time = 1675320464097L, 305 codegenVersion = "1.0.23", 306 sourceFile = "frameworks/base/core/java/android/service/assist/classification/FieldClassification.java", 307 inputSignatures = "private final @android.annotation.NonNull android.view.autofill.AutofillId mAutofillId\nprivate final @android.annotation.NonNull java.util.Set<java.lang.String> mHints\nprivate final @android.annotation.NonNull java.util.Set<java.lang.String> mGroupHints\npublic @android.annotation.NonNull android.view.autofill.AutofillId getAutofillId()\npublic @android.annotation.NonNull java.util.Set<java.lang.String> getHints()\npublic @android.annotation.SystemApi @android.annotation.NonNull java.util.Set<java.lang.String> getGroupHints()\nstatic java.util.Set<java.lang.String> unparcelHints(android.os.Parcel)\n void parcelHints(android.os.Parcel,int)\nstatic java.util.Set<java.lang.String> unparcelGroupHints(android.os.Parcel)\n void parcelGroupHints(android.os.Parcel,int)\nclass FieldClassification extends java.lang.Object implements [android.os.Parcelable]\n@com.android.internal.util.DataClass(genToString=true, genConstructor=false)") 308 @Deprecated __metadata()309 private void __metadata() {} 310 311 312 //@formatter:on 313 // End of generated code 314 315 } 316