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.voiceinteraction;
18 
19 import android.hardware.soundtrigger.SoundTrigger.Keyphrase;
20 import android.hardware.soundtrigger.SoundTrigger.KeyphraseSoundModel;
21 
22 import java.io.PrintWriter;
23 
24 /**
25  * Interface for registering and querying the enrolled keyphrase model database for
26  * {@link VoiceInteractionManagerService}.
27  * This interface only supports one keyphrase per {@link KeyphraseSoundModel}.
28  * The non-update methods are uniquely keyed on fields of the first keyphrase
29  * {@link KeyphraseSoundModel#getKeyphrases()}.
30  * @hide
31  */
32 public interface IEnrolledModelDb {
33 
34     //TODO(273286174): We only support one keyphrase currently.
35     /**
36      * Register the given {@link KeyphraseSoundModel}, or updates it if it already exists.
37      *
38      * @param soundModel - The sound model to register in the database.
39      * Updates the sound model if the keyphrase id, users, locale match an existing entry.
40      * Must have one and only one associated {@link Keyphrase}.
41      * @return - {@code true} if successful, {@code false} if unsuccessful
42      */
updateKeyphraseSoundModel(KeyphraseSoundModel soundModel)43     boolean updateKeyphraseSoundModel(KeyphraseSoundModel soundModel);
44 
45     /**
46      * Deletes the previously registered keyphrase sound model from the database.
47      *
48      * @param keyphraseId - The (first) keyphrase ID of the KeyphraseSoundModel to delete.
49      * @param userHandle - The user handle making this request. Must be included in the user
50      *                     list of the registered sound model.
51      * @param bcp47Locale - The locale of the (first) keyphrase associated with this model.
52      * @return - {@code true} if successful, {@code false} if unsuccessful
53      */
deleteKeyphraseSoundModel(int keyphraseId, int userHandle, String bcp47Locale)54     boolean deleteKeyphraseSoundModel(int keyphraseId, int userHandle, String bcp47Locale);
55 
56     //TODO(273286174): We only support one keyphrase currently.
57     /**
58      * Returns the first matching {@link KeyphraseSoundModel} for the keyphrase ID, locale pair,
59      * contingent on the userHandle existing in the user list for the model.
60      * Returns null if a match isn't found.
61      *
62      * @param keyphraseId - The (first) keyphrase ID of the KeyphraseSoundModel to query.
63      * @param userHandle - The user handle making this request. Must be included in the user
64      *                     list of the registered sound model.
65      * @param bcp47Locale - The locale of the (first) keyphrase associated with this model.
66      * @return - {@code true} if successful, {@code false} if unsuccessful
67      */
getKeyphraseSoundModel(int keyphraseId, int userHandle, String bcp47Locale)68     KeyphraseSoundModel getKeyphraseSoundModel(int keyphraseId, int userHandle,
69             String bcp47Locale);
70 
71     //TODO(273286174): We only support one keyphrase currently.
72     /**
73      * Returns the first matching {@link KeyphraseSoundModel} for the keyphrase ID, locale pair,
74      * contingent on the userHandle existing in the user list for the model.
75      * Returns null if a match isn't found.
76      *
77      * @param keyphrase - The text of (the first) keyphrase of the KeyphraseSoundModel to query.
78      * @param userHandle - The user handle making this request. Must be included in the user
79      *                     list of the registered sound model.
80      * @param bcp47Locale - The locale of the (first) keyphrase associated with this model.
81      * @return - {@code true} if successful, {@code false} if unsuccessful
82      */
getKeyphraseSoundModel(String keyphrase, int userHandle, String bcp47Locale)83     KeyphraseSoundModel getKeyphraseSoundModel(String keyphrase, int userHandle,
84             String bcp47Locale);
85 
86     /**
87      * Dumps contents of database for dumpsys
88      */
dump(PrintWriter pw)89     void dump(PrintWriter pw);
90 }
91