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 com.android.server.autofill; 18 19 import static android.service.autofill.SaveInfo.SAVE_DATA_TYPE_ADDRESS; 20 import static android.service.autofill.SaveInfo.SAVE_DATA_TYPE_CREDIT_CARD; 21 import static android.service.autofill.SaveInfo.SAVE_DATA_TYPE_DEBIT_CARD; 22 import static android.service.autofill.SaveInfo.SAVE_DATA_TYPE_EMAIL_ADDRESS; 23 import static android.service.autofill.SaveInfo.SAVE_DATA_TYPE_GENERIC_CARD; 24 import static android.service.autofill.SaveInfo.SAVE_DATA_TYPE_PASSWORD; 25 import static android.service.autofill.SaveInfo.SAVE_DATA_TYPE_PAYMENT_CARD; 26 import static android.service.autofill.SaveInfo.SAVE_DATA_TYPE_USERNAME; 27 28 import android.util.ArraySet; 29 30 import java.util.Set; 31 32 /** 33 * Helper class to manage autofill hints. 34 * Provides utility methods like converting SaveTypes to applicable HintsConstants. 35 */ 36 public class HintsHelper { 37 // Username fields 38 public static final String AUTOFILL_HINT_NEW_USERNAME = "newUsername"; 39 public static final String AUTOFILL_HINT_USERNAME = "username"; 40 41 // Password fields 42 public static final String AUTOFILL_HINT_NEW_PASSWORD = "newPassword"; 43 public static final String AUTOFILL_HINT_PASSWORD = "password"; 44 45 // Email hints 46 public static final String AUTOFILL_HINT_EMAIL_ADDRESS = "emailAddress"; 47 48 // Phone number hints 49 public static final String AUTOFILL_HINT_PHONE_COUNTRY_CODE = "phoneCountryCode"; 50 public static final String AUTOFILL_HINT_PHONE = "phone"; 51 public static final String AUTOFILL_HINT_PHONE_NATIONAL = "phoneNational"; 52 public static final String AUTOFILL_HINT_PHONE_NUMBER = "phoneNumber"; 53 public static final String AUTOFILL_HINT_PHONE_NUMBER_DEVICE = "phoneNumberDevice"; 54 55 // Credit card hints 56 public static final String AUTOFILL_HINT_CREDIT_CARD_EXPIRATION_DATE = 57 "creditCardExpirationDate"; 58 public static final String AUTOFILL_HINT_CREDIT_CARD_EXPIRATION_DAY = "creditCardExpirationDay"; 59 public static final String AUTOFILL_HINT_CREDIT_CARD_EXPIRATION_MONTH = 60 "creditCardExpirationMonth"; 61 public static final String AUTOFILL_HINT_CREDIT_CARD_EXPIRATION_YEAR = 62 "creditCardExpirationYear"; 63 public static final String AUTOFILL_HINT_CREDIT_CARD_NUMBER = "creditCardNumber"; 64 public static final String AUTOFILL_HINT_CREDIT_CARD_SECURITY_CODE = "creditCardSecurityCode"; 65 66 // Address hints 67 public static final String AUTOFILL_HINT_POSTAL_ADDRESS = "postalAddress"; 68 public static final String AUTOFILL_HINT_POSTAL_ADDRESS_APT_NUMBER = "aptNumber"; 69 public static final String AUTOFILL_HINT_POSTAL_ADDRESS_COUNTRY = "addressCountry"; 70 public static final String AUTOFILL_HINT_POSTAL_ADDRESS_DEPENDENT_LOCALITY = 71 "dependentLocality"; 72 public static final String AUTOFILL_HINT_POSTAL_ADDRESS_EXTENDED_ADDRESS = "extendedAddress"; 73 public static final String AUTOFILL_HINT_POSTAL_ADDRESS_EXTENDED_POSTAL_CODE = 74 "extendedPostalCode"; 75 public static final String AUTOFILL_HINT_POSTAL_ADDRESS_LOCALITY = "addressLocality"; 76 public static final String AUTOFILL_HINT_POSTAL_ADDRESS_REGION = "addressRegion"; 77 public static final String AUTOFILL_HINT_POSTAL_ADDRESS_STREET_ADDRESS = "streetAddress"; 78 public static final String AUTOFILL_HINT_POSTAL_CODE = "postalCode"; 79 HintsHelper()80 private HintsHelper() {} 81 82 /** 83 * Converts saveType to Autofill HintsConstants. 84 * @param saveType 85 * @return 86 */ getHintsForSaveType(int saveType)87 public static Set<String> getHintsForSaveType(int saveType) { 88 ArraySet<String> hintSet = new ArraySet<>(); 89 switch (saveType) { 90 case SAVE_DATA_TYPE_PASSWORD: 91 hintSet.add(AUTOFILL_HINT_NEW_USERNAME); 92 hintSet.add(AUTOFILL_HINT_USERNAME); 93 hintSet.add(AUTOFILL_HINT_NEW_PASSWORD); 94 hintSet.add(AUTOFILL_HINT_PASSWORD); 95 return hintSet; 96 case SAVE_DATA_TYPE_USERNAME: 97 hintSet.add(AUTOFILL_HINT_NEW_USERNAME); 98 hintSet.add(AUTOFILL_HINT_USERNAME); 99 return hintSet; 100 case SAVE_DATA_TYPE_EMAIL_ADDRESS: 101 hintSet.add(AUTOFILL_HINT_EMAIL_ADDRESS); 102 return hintSet; 103 case SAVE_DATA_TYPE_CREDIT_CARD: 104 case SAVE_DATA_TYPE_DEBIT_CARD: 105 case SAVE_DATA_TYPE_PAYMENT_CARD: 106 case SAVE_DATA_TYPE_GENERIC_CARD: 107 hintSet.add(AUTOFILL_HINT_CREDIT_CARD_EXPIRATION_DATE); 108 hintSet.add(AUTOFILL_HINT_CREDIT_CARD_EXPIRATION_DAY); 109 hintSet.add(AUTOFILL_HINT_CREDIT_CARD_EXPIRATION_MONTH); 110 hintSet.add(AUTOFILL_HINT_CREDIT_CARD_EXPIRATION_YEAR); 111 hintSet.add(AUTOFILL_HINT_CREDIT_CARD_NUMBER); 112 hintSet.add(AUTOFILL_HINT_CREDIT_CARD_SECURITY_CODE); 113 return hintSet; 114 case SAVE_DATA_TYPE_ADDRESS: 115 hintSet.add(AUTOFILL_HINT_POSTAL_ADDRESS); 116 hintSet.add(AUTOFILL_HINT_POSTAL_ADDRESS_APT_NUMBER); 117 hintSet.add(AUTOFILL_HINT_POSTAL_ADDRESS_COUNTRY); 118 hintSet.add(AUTOFILL_HINT_POSTAL_ADDRESS_DEPENDENT_LOCALITY); 119 hintSet.add(AUTOFILL_HINT_POSTAL_ADDRESS_EXTENDED_ADDRESS); 120 hintSet.add(AUTOFILL_HINT_POSTAL_ADDRESS_EXTENDED_POSTAL_CODE); 121 hintSet.add(AUTOFILL_HINT_POSTAL_ADDRESS_LOCALITY); 122 hintSet.add(AUTOFILL_HINT_POSTAL_ADDRESS_REGION); 123 hintSet.add(AUTOFILL_HINT_POSTAL_ADDRESS_STREET_ADDRESS); 124 hintSet.add(AUTOFILL_HINT_POSTAL_CODE); 125 return hintSet; 126 default: 127 return hintSet; 128 } 129 } 130 } 131