1 /*
2  * Copyright (C) 2020 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.internal.app;
18 
19 import android.hardware.soundtrigger.ModelParams;
20 import android.hardware.soundtrigger.SoundTrigger;
21 
22 import com.android.internal.app.IHotwordRecognitionStatusCallback;
23 
24 /**
25  * This interface allows performing sound-trigger related operations with the actual sound trigger
26  * hardware.
27  *
28  * Every instance of this interface is associated with a client identity ("originator"), established
29  * upon the creation of the instance and used for permission accounting.
30  */
31 interface IVoiceInteractionSoundTriggerSession {
32     /**
33      * Gets the properties of the DSP hardware on this device, null if not present.
34      * Caller must be the active voice interaction service via
35      * {@link Settings.Secure.VOICE_INTERACTION_SERVICE}.
36      */
getDspModuleProperties()37     SoundTrigger.ModuleProperties getDspModuleProperties();
38     /**
39      * Starts a recognition for the given keyphrase.
40      * Caller must be the active voice interaction service via
41      * {@link Settings.Secure.VOICE_INTERACTION_SERVICE}.
42      */
startRecognition(int keyphraseId, in String bcp47Locale, in IHotwordRecognitionStatusCallback callback, in SoundTrigger.RecognitionConfig recognitionConfig, boolean runInBatterySaver)43     int startRecognition(int keyphraseId, in String bcp47Locale,
44             in IHotwordRecognitionStatusCallback callback,
45             in SoundTrigger.RecognitionConfig recognitionConfig,
46             boolean runInBatterySaver);
47     /**
48      * Stops a recognition for the given keyphrase.
49      * Caller must be the active voice interaction service via
50      * {@link Settings.Secure.VOICE_INTERACTION_SERVICE}.
51      */
stopRecognition(int keyphraseId, in IHotwordRecognitionStatusCallback callback)52     int stopRecognition(int keyphraseId, in IHotwordRecognitionStatusCallback callback);
53     /**
54      * Set a model specific ModelParams with the given value. This
55      * parameter will keep its value for the duration the model is loaded regardless of starting and
56      * stopping recognition. Once the model is unloaded, the value will be lost.
57      * queryParameter should be checked first before calling this method.
58      * Caller must be the active voice interaction service via
59      * {@link Settings.Secure.VOICE_INTERACTION_SERVICE}.
60      *
61      * @param keyphraseId The unique identifier for the keyphrase.
62      * @param modelParam   ModelParams
63      * @param value        Value to set
64      * @return - {@link SoundTrigger#STATUS_OK} in case of success
65      *         - {@link SoundTrigger#STATUS_NO_INIT} if the native service cannot be reached
66      *         - {@link SoundTrigger#STATUS_BAD_VALUE} invalid input parameter
67      *         - {@link SoundTrigger#STATUS_INVALID_OPERATION} if the call is out of sequence or
68      *           if API is not supported by HAL
69      */
setParameter(int keyphraseId, in ModelParams modelParam, int value)70     int setParameter(int keyphraseId, in ModelParams modelParam, int value);
71     /**
72      * Get a model specific ModelParams. This parameter will keep its value
73      * for the duration the model is loaded regardless of starting and stopping recognition.
74      * Once the model is unloaded, the value will be lost. If the value is not set, a default
75      * value is returned. See ModelParams for parameter default values.
76      * queryParameter should be checked first before calling this method.
77      * Caller must be the active voice interaction service via
78      * {@link Settings.Secure.VOICE_INTERACTION_SERVICE}.
79      *
80      * @param keyphraseId The unique identifier for the keyphrase.
81      * @param modelParam   ModelParams
82      * @return value of parameter
83      */
getParameter(int keyphraseId, in ModelParams modelParam)84     int getParameter(int keyphraseId, in ModelParams modelParam);
85     /**
86      * Determine if parameter control is supported for the given model handle.
87      * This method should be checked prior to calling setParameter or getParameter.
88      * Caller must be the active voice interaction service via
89      * {@link Settings.Secure.VOICE_INTERACTION_SERVICE}.
90      *
91      * @param keyphraseId The unique identifier for the keyphrase.
92      * @param modelParam ModelParams
93      * @return supported range of parameter, null if not supported
94      */
queryParameter(int keyphraseId, in ModelParams modelParam)95     @nullable SoundTrigger.ModelParamRange queryParameter(int keyphraseId,
96             in ModelParams modelParam);
97     /**
98      * Invalidates the sound trigger session and clears any associated resources. Subsequent calls
99      * to this object will throw IllegalStateException.
100      */
detach()101     void detach();
102 }
103