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