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.util.ArraySet;
20 
21 import java.util.Locale;
22 
23 /**
24  * A Voice Keyphrase metadata read from the enrollment application.
25  *
26  * @hide
27  */
28 public class KeyphraseMetadata {
29     public final int id;
30     public final String keyphrase;
31     public final ArraySet<Locale> supportedLocales;
32     public final int recognitionModeFlags;
33 
KeyphraseMetadata(int id, String keyphrase, ArraySet<Locale> supportedLocales, int recognitionModeFlags)34     public KeyphraseMetadata(int id, String keyphrase, ArraySet<Locale> supportedLocales,
35             int recognitionModeFlags) {
36         this.id = id;
37         this.keyphrase = keyphrase;
38         this.supportedLocales = supportedLocales;
39         this.recognitionModeFlags = recognitionModeFlags;
40     }
41 
42     @Override
toString()43     public String toString() {
44         return "id=" + id + ", keyphrase=" + keyphrase + ", supported-locales=" + supportedLocales
45                 + ", recognition-modes=" + recognitionModeFlags;
46     }
47 
48     /**
49      * @return Indicates if we support the given phrase.
50      */
supportsPhrase(String phrase)51     public boolean supportsPhrase(String phrase) {
52         return keyphrase.isEmpty() || keyphrase.equalsIgnoreCase(phrase);
53     }
54 
55     /**
56      * @return Indicates if we support the given locale.
57      */
supportsLocale(Locale locale)58     public boolean supportsLocale(Locale locale) {
59         return supportedLocales.isEmpty() || supportedLocales.contains(locale);
60     }
61 }
62