1 /** 2 * Copyright (C) 2014 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.soundtrigger; 18 19 import android.annotation.NonNull; 20 import android.annotation.Nullable; 21 import android.annotation.TestApi; 22 import android.os.Parcelable; 23 import android.util.ArraySet; 24 25 import com.android.internal.util.DataClass; 26 27 import java.util.Locale; 28 import java.util.Set; 29 30 /** 31 * A Voice Keyphrase metadata read from the enrollment application. 32 * 33 * @hide 34 */ 35 @TestApi 36 @DataClass( 37 genEqualsHashCode = true, 38 genToString = true, 39 genConstructor = false, 40 genHiddenConstDefs = true) 41 public final class KeyphraseMetadata implements Parcelable { 42 private final int mId; 43 @NonNull 44 private final String mKeyphrase; 45 @NonNull 46 private final ArraySet<Locale> mSupportedLocales; 47 private final int mRecognitionModeFlags; 48 KeyphraseMetadata(int id, @NonNull String keyphrase, @NonNull Set<Locale> supportedLocales, int recognitionModeFlags)49 public KeyphraseMetadata(int id, @NonNull String keyphrase, 50 @NonNull Set<Locale> supportedLocales, int recognitionModeFlags) { 51 this.mId = id; 52 this.mKeyphrase = keyphrase; 53 this.mSupportedLocales = new ArraySet<>(supportedLocales); 54 this.mRecognitionModeFlags = recognitionModeFlags; 55 } 56 getId()57 public int getId() { 58 return mId; 59 } 60 61 @NonNull getKeyphrase()62 public String getKeyphrase() { 63 return mKeyphrase; 64 } 65 66 @NonNull getSupportedLocales()67 public Set<Locale> getSupportedLocales() { 68 return mSupportedLocales; 69 } 70 getRecognitionModeFlags()71 public int getRecognitionModeFlags() { 72 return mRecognitionModeFlags; 73 } 74 75 /** 76 * @return Indicates if we support the given phrase. 77 */ supportsPhrase(@ullable String phrase)78 public boolean supportsPhrase(@Nullable String phrase) { 79 return getKeyphrase().isEmpty() || getKeyphrase().equalsIgnoreCase(phrase); 80 } 81 82 /** 83 * @return Indicates if we support the given locale. 84 */ supportsLocale(@ullable Locale locale)85 public boolean supportsLocale(@Nullable Locale locale) { 86 return getSupportedLocales().isEmpty() || getSupportedLocales().contains(locale); 87 } 88 89 90 91 92 // Code below generated by codegen v1.0.15. 93 // 94 // DO NOT MODIFY! 95 // CHECKSTYLE:OFF Generated code 96 // 97 // To regenerate run: 98 // $ codegen $ANDROID_BUILD_TOP/frameworks/base/core/java/android/hardware/soundtrigger/KeyphraseMetadata.java 99 // 100 // To exclude the generated code from IntelliJ auto-formatting enable (one-time): 101 // Settings > Editor > Code Style > Formatter Control 102 //@formatter:off 103 104 105 @Override 106 @DataClass.Generated.Member toString()107 public String toString() { 108 // You can override field toString logic by defining methods like: 109 // String fieldNameToString() { ... } 110 111 return "KeyphraseMetadata { " + 112 "id = " + mId + ", " + 113 "keyphrase = " + mKeyphrase + ", " + 114 "supportedLocales = " + mSupportedLocales + ", " + 115 "recognitionModeFlags = " + mRecognitionModeFlags + 116 " }"; 117 } 118 119 @Override 120 @DataClass.Generated.Member equals(@ullable Object o)121 public boolean equals(@Nullable Object o) { 122 // You can override field equality logic by defining either of the methods like: 123 // boolean fieldNameEquals(KeyphraseMetadata other) { ... } 124 // boolean fieldNameEquals(FieldType otherValue) { ... } 125 126 if (this == o) return true; 127 if (o == null || getClass() != o.getClass()) return false; 128 @SuppressWarnings("unchecked") 129 KeyphraseMetadata that = (KeyphraseMetadata) o; 130 //noinspection PointlessBooleanExpression 131 return true 132 && mId == that.mId 133 && java.util.Objects.equals(mKeyphrase, that.mKeyphrase) 134 && java.util.Objects.equals(mSupportedLocales, that.mSupportedLocales) 135 && mRecognitionModeFlags == that.mRecognitionModeFlags; 136 } 137 138 @Override 139 @DataClass.Generated.Member hashCode()140 public int hashCode() { 141 // You can override field hashCode logic by defining methods like: 142 // int fieldNameHashCode() { ... } 143 144 int _hash = 1; 145 _hash = 31 * _hash + mId; 146 _hash = 31 * _hash + java.util.Objects.hashCode(mKeyphrase); 147 _hash = 31 * _hash + java.util.Objects.hashCode(mSupportedLocales); 148 _hash = 31 * _hash + mRecognitionModeFlags; 149 return _hash; 150 } 151 152 @Override 153 @DataClass.Generated.Member writeToParcel(@onNull android.os.Parcel dest, int flags)154 public void writeToParcel(@NonNull android.os.Parcel dest, int flags) { 155 // You can override field parcelling by defining methods like: 156 // void parcelFieldName(Parcel dest, int flags) { ... } 157 158 dest.writeInt(mId); 159 dest.writeString(mKeyphrase); 160 dest.writeArraySet(mSupportedLocales); 161 dest.writeInt(mRecognitionModeFlags); 162 } 163 164 @Override 165 @DataClass.Generated.Member describeContents()166 public int describeContents() { return 0; } 167 168 /** @hide */ 169 @SuppressWarnings({"unchecked", "RedundantCast"}) 170 @DataClass.Generated.Member KeyphraseMetadata(@onNull android.os.Parcel in)171 /* package-private */ KeyphraseMetadata(@NonNull android.os.Parcel in) { 172 // You can override field unparcelling by defining methods like: 173 // static FieldType unparcelFieldName(Parcel in) { ... } 174 175 int id = in.readInt(); 176 String keyphrase = in.readString(); 177 ArraySet<Locale> supportedLocales = (ArraySet) in.readArraySet(null); 178 int recognitionModeFlags = in.readInt(); 179 180 this.mId = id; 181 this.mKeyphrase = keyphrase; 182 com.android.internal.util.AnnotationValidations.validate( 183 NonNull.class, null, mKeyphrase); 184 this.mSupportedLocales = supportedLocales; 185 com.android.internal.util.AnnotationValidations.validate( 186 NonNull.class, null, mSupportedLocales); 187 this.mRecognitionModeFlags = recognitionModeFlags; 188 189 // onConstructed(); // You can define this method to get a callback 190 } 191 192 @DataClass.Generated.Member 193 public static final @NonNull Parcelable.Creator<KeyphraseMetadata> CREATOR 194 = new Parcelable.Creator<KeyphraseMetadata>() { 195 @Override 196 public KeyphraseMetadata[] newArray(int size) { 197 return new KeyphraseMetadata[size]; 198 } 199 200 @Override 201 public KeyphraseMetadata createFromParcel(@NonNull android.os.Parcel in) { 202 return new KeyphraseMetadata(in); 203 } 204 }; 205 206 @DataClass.Generated( 207 time = 1586191622057L, 208 codegenVersion = "1.0.15", 209 sourceFile = "frameworks/base/core/java/android/hardware/soundtrigger/KeyphraseMetadata.java", 210 inputSignatures = "private final int mId\nprivate final @android.annotation.NonNull java.lang.String mKeyphrase\nprivate final @android.annotation.NonNull android.util.ArraySet<java.util.Locale> mSupportedLocales\nprivate final int mRecognitionModeFlags\npublic int getId()\npublic @android.annotation.NonNull java.lang.String getKeyphrase()\npublic @android.annotation.NonNull java.util.Set<java.util.Locale> getSupportedLocales()\npublic int getRecognitionModeFlags()\npublic boolean supportsPhrase(java.lang.String)\npublic boolean supportsLocale(java.util.Locale)\nclass KeyphraseMetadata extends java.lang.Object implements [android.os.Parcelable]\n@com.android.internal.util.DataClass(genEqualsHashCode=true, genToString=true, genConstructor=false, genHiddenConstDefs=true)") 211 @Deprecated __metadata()212 private void __metadata() {} 213 214 215 //@formatter:on 216 // End of generated code 217 218 } 219