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 com.android.internal.app;
18 
19 import android.content.ComponentName;
20 import android.content.Intent;
21 import android.media.AudioFormat;
22 import android.media.permission.Identity;
23 import android.os.Bundle;
24 import android.os.ParcelFileDescriptor;
25 import android.os.PersistableBundle;
26 import android.os.RemoteCallback;
27 import android.os.SharedMemory;
28 
29 import com.android.internal.app.IHotwordRecognitionStatusCallback;
30 import com.android.internal.app.IVoiceActionCheckCallback;
31 import com.android.internal.app.IVoiceInteractionSessionShowCallback;
32 import com.android.internal.app.IVoiceInteractor;
33 import com.android.internal.app.IVoiceInteractionSessionListener;
34 import com.android.internal.app.IVoiceInteractionSoundTriggerSession;
35 import android.hardware.soundtrigger.KeyphraseMetadata;
36 import android.hardware.soundtrigger.SoundTrigger;
37 import android.service.voice.IVoiceInteractionService;
38 import android.service.voice.IVoiceInteractionSession;
39 import android.service.voice.IMicrophoneHotwordDetectionVoiceInteractionCallback;
40 
41 interface IVoiceInteractionManagerService {
showSession(in Bundle sessionArgs, int flags)42     void showSession(in Bundle sessionArgs, int flags);
deliverNewSession(IBinder token, IVoiceInteractionSession session, IVoiceInteractor interactor)43     boolean deliverNewSession(IBinder token, IVoiceInteractionSession session,
44             IVoiceInteractor interactor);
showSessionFromSession(IBinder token, in Bundle sessionArgs, int flags)45     boolean showSessionFromSession(IBinder token, in Bundle sessionArgs, int flags);
hideSessionFromSession(IBinder token)46     boolean hideSessionFromSession(IBinder token);
startVoiceActivity(IBinder token, in Intent intent, String resolvedType, String callingFeatureId)47     int startVoiceActivity(IBinder token, in Intent intent, String resolvedType,
48             String callingFeatureId);
startAssistantActivity(IBinder token, in Intent intent, String resolvedType, String callingFeatureId)49     int startAssistantActivity(IBinder token, in Intent intent, String resolvedType,
50             String callingFeatureId);
setKeepAwake(IBinder token, boolean keepAwake)51     void setKeepAwake(IBinder token, boolean keepAwake);
closeSystemDialogs(IBinder token)52     void closeSystemDialogs(IBinder token);
finish(IBinder token)53     void finish(IBinder token);
setDisabledShowContext(int flags)54     void setDisabledShowContext(int flags);
getDisabledShowContext()55     int getDisabledShowContext();
getUserDisabledShowContext()56     int getUserDisabledShowContext();
57 
58     /**
59      * Gets the registered Sound model for keyphrase detection for the current user.
60      * May be null if no matching sound model exists.
61      * Caller must either be the active voice interaction service via
62      * {@link Settings.Secure.VOICE_INTERACTION_SERVICE}, or the caller must be a voice model
63      * enrollment application detected by
64      * {@link android.hardware.soundtrigger.KeyphraseEnrollmentInfo}.
65      *
66      * @param keyphraseId The unique identifier for the keyphrase.
67      * @param bcp47Locale The BCP47 language tag  for the keyphrase's locale.
68      * @RequiresPermission Manifest.permission.MANAGE_VOICE_KEYPHRASES
69      */
70     @UnsupportedAppUsage(maxTargetSdk = 30, trackingBug = 170729553)
getKeyphraseSoundModel(int keyphraseId, in String bcp47Locale)71     SoundTrigger.KeyphraseSoundModel getKeyphraseSoundModel(int keyphraseId, in String bcp47Locale);
72     /**
73      * Add/Update the given keyphrase sound model for the current user.
74      * Caller must either be the active voice interaction service via
75      * {@link Settings.Secure.VOICE_INTERACTION_SERVICE}, or the caller must be a voice model
76      * enrollment application detected by
77      * {@link android.hardware.soundtrigger.KeyphraseEnrollmentInfo}.
78      *
79      * @param model The keyphrase sound model to store peristantly.
80      * @RequiresPermission Manifest.permission.MANAGE_VOICE_KEYPHRASES
81      */
updateKeyphraseSoundModel(in SoundTrigger.KeyphraseSoundModel model)82     int updateKeyphraseSoundModel(in SoundTrigger.KeyphraseSoundModel model);
83     /**
84      * Deletes the given keyphrase sound model for the current user.
85      * Caller must either be the active voice interaction service via
86      * {@link Settings.Secure.VOICE_INTERACTION_SERVICE}, or the caller must be a voice model
87      * enrollment application detected by
88      * {@link android.hardware.soundtrigger.KeyphraseEnrollmentInfo}.
89      *
90      * @param keyphraseId The unique identifier for the keyphrase.
91      * @param bcp47Locale The BCP47 language tag  for the keyphrase's locale.
92      * @RequiresPermission Manifest.permission.MANAGE_VOICE_KEYPHRASES
93      */
deleteKeyphraseSoundModel(int keyphraseId, in String bcp47Locale)94     int deleteKeyphraseSoundModel(int keyphraseId, in String bcp47Locale);
95     /**
96      * Indicates if there's a keyphrase sound model available for the given keyphrase ID and the
97      * user ID of the caller.
98      * Caller must be the active voice interaction service via
99      * {@link Settings.Secure.VOICE_INTERACTION_SERVICE}.
100      *
101      * @param keyphraseId The unique identifier for the keyphrase.
102      * @param bcp47Locale The BCP47 language tag  for the keyphrase's locale.
103      */
isEnrolledForKeyphrase(int keyphraseId, String bcp47Locale)104     boolean isEnrolledForKeyphrase(int keyphraseId, String bcp47Locale);
105     /**
106      * Generates KeyphraseMetadata for an enrolled sound model based on keyphrase string, locale,
107      * and the user ID of the caller.
108      * Caller must be the active voice interaction service via
109      * {@link Settings.Secure.VOICE_INTERACTION_SERVICE}.
110      *
111      * @param keyphrase Keyphrase text associated with the enrolled model
112      * @param bcp47Locale The BCP47 language tag for the keyphrase's locale.
113      * @return The metadata for the enrolled voice model bassed on the passed in parameters. Null if
114      *         no matching voice model exists.
115      */
getEnrolledKeyphraseMetadata(String keyphrase, String bcp47Locale)116     KeyphraseMetadata getEnrolledKeyphraseMetadata(String keyphrase, String bcp47Locale);
117     /**
118      * @return the component name for the currently active voice interaction service
119      */
getActiveServiceComponentName()120     ComponentName getActiveServiceComponentName();
121 
122     /**
123      * Shows the session for the currently active service. Used to start a new session from system
124      * affordances.
125      *
126      * @param args the bundle to pass as arguments to the voice interaction session
127      * @param sourceFlags flags indicating the source of this show
128      * @param showCallback optional callback to be notified when the session was shown
129      * @param activityToken optional token of activity that needs to be on top
130      * @RequiresPermission Manifest.permission.ACCESS_VOICE_INTERACTION_SERVICE
131      */
showSessionForActiveService(in Bundle args, int sourceFlags, IVoiceInteractionSessionShowCallback showCallback, IBinder activityToken)132     boolean showSessionForActiveService(in Bundle args, int sourceFlags,
133             IVoiceInteractionSessionShowCallback showCallback, IBinder activityToken);
134 
135     /**
136      * Hides the session from the active service, if it is showing.
137      * @RequiresPermission Manifest.permission.ACCESS_VOICE_INTERACTION_SERVICE
138      */
hideCurrentSession()139     void hideCurrentSession();
140 
141     /**
142      * Notifies the active service that a launch was requested from the Keyguard. This will only
143      * be called if {@link #activeServiceSupportsLaunchFromKeyguard()} returns true.
144      * @RequiresPermission Manifest.permission.ACCESS_VOICE_INTERACTION_SERVICE
145      */
launchVoiceAssistFromKeyguard()146     void launchVoiceAssistFromKeyguard();
147 
148     /**
149      * Indicates whether there is a voice session running (but not necessarily showing).
150      * @RequiresPermission Manifest.permission.ACCESS_VOICE_INTERACTION_SERVICE
151      */
isSessionRunning()152     boolean isSessionRunning();
153 
154     /**
155      * Indicates whether the currently active voice interaction service is capable of handling the
156      * assist gesture.
157      * @RequiresPermission Manifest.permission.ACCESS_VOICE_INTERACTION_SERVICE
158      */
activeServiceSupportsAssist()159     boolean activeServiceSupportsAssist();
160 
161     /**
162      * Indicates whether the currently active voice interaction service is capable of being launched
163      * from the lockscreen.
164      * @RequiresPermission Manifest.permission.ACCESS_VOICE_INTERACTION_SERVICE
165      */
activeServiceSupportsLaunchFromKeyguard()166     boolean activeServiceSupportsLaunchFromKeyguard();
167 
168     /**
169      * Called when the lockscreen got shown.
170      * @RequiresPermission Manifest.permission.ACCESS_VOICE_INTERACTION_SERVICE
171      */
onLockscreenShown()172     void onLockscreenShown();
173 
174     /**
175      * Register a voice interaction listener.
176      * @RequiresPermission Manifest.permission.ACCESS_VOICE_INTERACTION_SERVICE
177      */
registerVoiceInteractionSessionListener(IVoiceInteractionSessionListener listener)178     void registerVoiceInteractionSessionListener(IVoiceInteractionSessionListener listener);
179 
180     /**
181      * Checks the availability of a set of voice actions for the current active voice service.
182      * Returns all supported voice actions.
183      * @RequiresPermission Manifest.permission.ACCESS_VOICE_INTERACTION_SERVICE
184      */
getActiveServiceSupportedActions(in List<String> voiceActions, in IVoiceActionCheckCallback callback)185     void getActiveServiceSupportedActions(in List<String> voiceActions,
186      in IVoiceActionCheckCallback callback);
187 
188     /**
189      * Provide hints for showing UI.
190      * Caller must be the active voice interaction service via
191      * {@link Settings.Secure.VOICE_INTERACTION_SERVICE}.
192      */
setUiHints(in Bundle hints)193     void setUiHints(in Bundle hints);
194 
195     /**
196      * Requests a list of supported actions from a specific activity.
197      */
requestDirectActions(in IBinder token, int taskId, IBinder assistToken, in RemoteCallback cancellationCallback, in RemoteCallback callback)198     void requestDirectActions(in IBinder token, int taskId, IBinder assistToken,
199              in RemoteCallback cancellationCallback, in RemoteCallback callback);
200 
201     /**
202      * Requests performing an action from a specific activity.
203      */
performDirectAction(in IBinder token, String actionId, in Bundle arguments, int taskId, IBinder assistToken, in RemoteCallback cancellationCallback, in RemoteCallback resultCallback)204     void performDirectAction(in IBinder token, String actionId, in Bundle arguments, int taskId,
205             IBinder assistToken, in RemoteCallback cancellationCallback,
206             in RemoteCallback resultCallback);
207 
208     /**
209      * Temporarily disables voice interaction (for example, on Automotive when the display is off).
210      *
211      * It will shutdown the service, and only re-enable it after it's called again (or after a
212      * system restart).
213      *
214      * NOTE: it's only effective when the service itself is available / enabled in the device, so
215      * calling setDisable(false) would be a no-op when it isn't.
216      */
setDisabled(boolean disabled)217     void setDisabled(boolean disabled);
218 
219     /**
220      * Creates a session, allowing controlling running sound models on detection hardware.
221      * Caller must provide an identity, used for permission tracking purposes.
222      * The uid/pid elements of the identity will be ignored by the server and replaced with the ones
223      * provided by binder.
224      *
225      * The client argument is any binder owned by the client, used for tracking is death and
226      * cleaning up in this event.
227      */
createSoundTriggerSessionAsOriginator( in Identity originatorIdentity, IBinder client)228     IVoiceInteractionSoundTriggerSession createSoundTriggerSessionAsOriginator(
229             in Identity originatorIdentity,
230             IBinder client);
231 
232     /**
233      * Set configuration and pass read-only data to hotword detection service.
234      * Caller must provide an identity, used for permission tracking purposes.
235      * The uid/pid elements of the identity will be ignored by the server and replaced with the ones
236      * provided by binder.
237      *
238      * @param options Application configuration data to provide to the
239      * {@link HotwordDetectionService}. PersistableBundle does not allow any remotable objects or
240      * other contents that can be used to communicate with other processes.
241      * @param sharedMemory The unrestricted data blob to provide to the
242      * {@link HotwordDetectionService}. Use this to provide the hotword models data or other
243      * such data to the trusted process.
244      * @param callback Use this to report {@link HotwordDetectionService} status.
245      */
updateState( in Identity originatorIdentity, in PersistableBundle options, in SharedMemory sharedMemory, in IHotwordRecognitionStatusCallback callback)246     void updateState(
247             in Identity originatorIdentity,
248             in PersistableBundle options,
249             in SharedMemory sharedMemory,
250             in IHotwordRecognitionStatusCallback callback);
251 
252     /**
253      * Requests to shutdown hotword detection service.
254      */
shutdownHotwordDetectionService()255     void shutdownHotwordDetectionService();
256 
startListeningFromMic( in AudioFormat audioFormat, in IMicrophoneHotwordDetectionVoiceInteractionCallback callback)257     void startListeningFromMic(
258         in AudioFormat audioFormat,
259         in IMicrophoneHotwordDetectionVoiceInteractionCallback callback);
260 
stopListeningFromMic()261     void stopListeningFromMic();
262 
startListeningFromExternalSource( in ParcelFileDescriptor audioStream, in AudioFormat audioFormat, in PersistableBundle options, in IMicrophoneHotwordDetectionVoiceInteractionCallback callback)263     void startListeningFromExternalSource(
264         in ParcelFileDescriptor audioStream,
265         in AudioFormat audioFormat,
266         in PersistableBundle options,
267         in IMicrophoneHotwordDetectionVoiceInteractionCallback callback);
268 
269     /**
270      * Test API to simulate to trigger hardware recognition event for test.
271      */
triggerHardwareRecognitionEventForTest( in SoundTrigger.KeyphraseRecognitionEvent event, in IHotwordRecognitionStatusCallback callback)272     void triggerHardwareRecognitionEventForTest(
273             in SoundTrigger.KeyphraseRecognitionEvent event,
274             in IHotwordRecognitionStatusCallback callback);
275 
276     /**
277      * Starts to listen the status of visible activity.
278      */
startListeningVisibleActivityChanged(in IBinder token)279     void startListeningVisibleActivityChanged(in IBinder token);
280 
281     /**
282      * Stops to listen the status of visible activity.
283      */
stopListeningVisibleActivityChanged(in IBinder token)284     void stopListeningVisibleActivityChanged(in IBinder token);
285 }
286