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.IVisualQueryDetectionVoiceInteractionCallback; 31 import android.service.voice.IMicrophoneHotwordDetectionVoiceInteractionCallback; 32 import android.service.voice.IVoiceInteractionService; 33 import android.service.voice.IVoiceInteractionSession; 34 import android.service.voice.VisibleActivityInfo; 35 36 import com.android.internal.app.IHotwordRecognitionStatusCallback; 37 import com.android.internal.app.IVoiceActionCheckCallback; 38 import com.android.internal.app.IVoiceInteractionAccessibilitySettingsListener; 39 import com.android.internal.app.IVoiceInteractionSessionListener; 40 import com.android.internal.app.IVoiceInteractionSessionShowCallback; 41 import com.android.internal.app.IVoiceInteractionSoundTriggerSession; 42 import com.android.internal.app.IVoiceInteractor; 43 import com.android.internal.app.IVisualQueryDetectionAttentionListener; 44 import com.android.internal.app.IVisualQueryRecognitionStatusListener; 45 46 interface IVoiceInteractionManagerService { showSession(in Bundle sessionArgs, int flags, String attributionTag)47 void showSession(in Bundle sessionArgs, int flags, String attributionTag); deliverNewSession(IBinder token, IVoiceInteractionSession session, IVoiceInteractor interactor)48 boolean deliverNewSession(IBinder token, IVoiceInteractionSession session, 49 IVoiceInteractor interactor); showSessionFromSession(IBinder token, in Bundle sessionArgs, int flags, String attributionTag)50 boolean showSessionFromSession(IBinder token, in Bundle sessionArgs, int flags, 51 String attributionTag); hideSessionFromSession(IBinder token)52 boolean hideSessionFromSession(IBinder token); startVoiceActivity(IBinder token, in Intent intent, String resolvedType, String attributionTag)53 int startVoiceActivity(IBinder token, in Intent intent, String resolvedType, 54 String attributionTag); startAssistantActivity(IBinder token, in Intent intent, String resolvedType, String attributionTag, in Bundle bundle)55 int startAssistantActivity(IBinder token, in Intent intent, String resolvedType, 56 String attributionTag, in Bundle bundle); setKeepAwake(IBinder token, boolean keepAwake)57 void setKeepAwake(IBinder token, boolean keepAwake); closeSystemDialogs(IBinder token)58 void closeSystemDialogs(IBinder token); finish(IBinder token)59 void finish(IBinder token); setDisabledShowContext(int flags)60 void setDisabledShowContext(int flags); getDisabledShowContext()61 int getDisabledShowContext(); getUserDisabledShowContext()62 int getUserDisabledShowContext(); 63 64 /** 65 * Gets the registered Sound model for keyphrase detection for the current user. 66 * May be null if no matching sound model exists. 67 * Caller must either be the active voice interaction service via 68 * {@link Settings.Secure.VOICE_INTERACTION_SERVICE}, or the caller must be a voice model 69 * enrollment application detected by 70 * {@link android.hardware.soundtrigger.KeyphraseEnrollmentInfo}. 71 * 72 * @param keyphraseId The unique identifier for the keyphrase. 73 * @param bcp47Locale The BCP47 language tag for the keyphrase's locale. 74 * @RequiresPermission Manifest.permission.MANAGE_VOICE_KEYPHRASES 75 */ 76 @UnsupportedAppUsage(maxTargetSdk = 30, trackingBug = 170729553) getKeyphraseSoundModel(int keyphraseId, in String bcp47Locale)77 SoundTrigger.KeyphraseSoundModel getKeyphraseSoundModel(int keyphraseId, in String bcp47Locale); 78 /** 79 * Add/Update the given keyphrase sound model for the current user. 80 * Caller must either be the active voice interaction service via 81 * {@link Settings.Secure.VOICE_INTERACTION_SERVICE}, or the caller must be a voice model 82 * enrollment application detected by 83 * {@link android.hardware.soundtrigger.KeyphraseEnrollmentInfo}. 84 * 85 * @param model The keyphrase sound model to store peristantly. 86 * @RequiresPermission Manifest.permission.MANAGE_VOICE_KEYPHRASES 87 */ updateKeyphraseSoundModel(in SoundTrigger.KeyphraseSoundModel model)88 int updateKeyphraseSoundModel(in SoundTrigger.KeyphraseSoundModel model); 89 /** 90 * Deletes the given keyphrase sound model for the current user. 91 * Caller must either be the active voice interaction service via 92 * {@link Settings.Secure.VOICE_INTERACTION_SERVICE}, or the caller must be a voice model 93 * enrollment application detected by 94 * {@link android.hardware.soundtrigger.KeyphraseEnrollmentInfo}. 95 * 96 * @param keyphraseId The unique identifier for the keyphrase. 97 * @param bcp47Locale The BCP47 language tag for the keyphrase's locale. 98 * @RequiresPermission Manifest.permission.MANAGE_VOICE_KEYPHRASES 99 */ deleteKeyphraseSoundModel(int keyphraseId, in String bcp47Locale)100 int deleteKeyphraseSoundModel(int keyphraseId, in String bcp47Locale); 101 102 /** 103 * Override the persistent enrolled model database with an in-memory 104 * fake for testing purposes. 105 * 106 * @param enabled - {@code true} to enable the test database. {@code false} to enable 107 * the real, persistent database. 108 * @param token - IBinder used to register a death listener to clean-up the override 109 * if tests do not clean up gracefully. 110 */ 111 @EnforcePermission("MANAGE_VOICE_KEYPHRASES") 112 @JavaPassthrough(annotation= "@android.annotation.RequiresPermission(" + 113 "android.Manifest.permission.MANAGE_VOICE_KEYPHRASES)") setModelDatabaseForTestEnabled(boolean enabled, IBinder token)114 void setModelDatabaseForTestEnabled(boolean enabled, IBinder token); 115 116 /** 117 * Indicates if there's a keyphrase sound model available for the given keyphrase ID and the 118 * user ID of the caller. 119 * Caller must be the active voice interaction service via 120 * {@link Settings.Secure.VOICE_INTERACTION_SERVICE}. 121 * 122 * @param keyphraseId The unique identifier for the keyphrase. 123 * @param bcp47Locale The BCP47 language tag for the keyphrase's locale. 124 */ isEnrolledForKeyphrase(int keyphraseId, String bcp47Locale)125 boolean isEnrolledForKeyphrase(int keyphraseId, String bcp47Locale); 126 127 /** 128 * Generates KeyphraseMetadata for an enrolled sound model based on keyphrase string, locale, 129 * and the user ID of the caller. 130 * Caller must be the active voice interaction service via 131 * {@link Settings.Secure.VOICE_INTERACTION_SERVICE}. 132 * 133 * @param keyphrase Keyphrase text associated with the enrolled model 134 * @param bcp47Locale The BCP47 language tag for the keyphrase's locale. 135 * @return The metadata for the enrolled voice model bassed on the passed in parameters. Null if 136 * no matching voice model exists. 137 */ getEnrolledKeyphraseMetadata(String keyphrase, String bcp47Locale)138 KeyphraseMetadata getEnrolledKeyphraseMetadata(String keyphrase, String bcp47Locale); 139 /** 140 * @return the component name for the currently active voice interaction service 141 */ getActiveServiceComponentName()142 ComponentName getActiveServiceComponentName(); 143 144 /** 145 * Shows the session for the currently active service. Used to start a new session from system 146 * affordances. 147 * 148 * @param args the bundle to pass as arguments to the voice interaction session 149 * @param sourceFlags flags indicating the source of this show 150 * @param attributionTag the attribution tag of the calling context or {@code null} for default 151 * attribution 152 * @param showCallback optional callback to be notified when the session was shown 153 * @param activityToken optional token of activity that needs to be on top 154 * @RequiresPermission Manifest.permission.ACCESS_VOICE_INTERACTION_SERVICE 155 */ 156 @EnforcePermission("ACCESS_VOICE_INTERACTION_SERVICE") showSessionForActiveService(in Bundle args, int sourceFlags, String attributionTag, IVoiceInteractionSessionShowCallback showCallback, IBinder activityToken)157 boolean showSessionForActiveService(in Bundle args, int sourceFlags, String attributionTag, 158 IVoiceInteractionSessionShowCallback showCallback, IBinder activityToken); 159 160 /** 161 * Hides the session from the active service, if it is showing. 162 * @RequiresPermission Manifest.permission.ACCESS_VOICE_INTERACTION_SERVICE 163 */ 164 @EnforcePermission("ACCESS_VOICE_INTERACTION_SERVICE") hideCurrentSession()165 void hideCurrentSession(); 166 167 /** 168 * Notifies the active service that a launch was requested from the Keyguard. This will only 169 * be called if {@link #activeServiceSupportsLaunchFromKeyguard()} returns true. 170 * @RequiresPermission Manifest.permission.ACCESS_VOICE_INTERACTION_SERVICE 171 */ 172 @EnforcePermission("ACCESS_VOICE_INTERACTION_SERVICE") launchVoiceAssistFromKeyguard()173 void launchVoiceAssistFromKeyguard(); 174 175 /** 176 * Indicates whether there is a voice session running (but not necessarily showing). 177 * @RequiresPermission Manifest.permission.ACCESS_VOICE_INTERACTION_SERVICE 178 */ 179 @EnforcePermission("ACCESS_VOICE_INTERACTION_SERVICE") isSessionRunning()180 boolean isSessionRunning(); 181 182 /** 183 * Indicates whether the currently active voice interaction service is capable of handling the 184 * assist gesture. 185 * @RequiresPermission Manifest.permission.ACCESS_VOICE_INTERACTION_SERVICE 186 */ 187 @EnforcePermission("ACCESS_VOICE_INTERACTION_SERVICE") activeServiceSupportsAssist()188 boolean activeServiceSupportsAssist(); 189 190 /** 191 * Indicates whether the currently active voice interaction service is capable of being launched 192 * from the lockscreen. 193 * @RequiresPermission Manifest.permission.ACCESS_VOICE_INTERACTION_SERVICE 194 */ 195 @EnforcePermission("ACCESS_VOICE_INTERACTION_SERVICE") activeServiceSupportsLaunchFromKeyguard()196 boolean activeServiceSupportsLaunchFromKeyguard(); 197 198 /** 199 * Called when the lockscreen got shown. 200 * @RequiresPermission Manifest.permission.ACCESS_VOICE_INTERACTION_SERVICE 201 */ 202 @EnforcePermission("ACCESS_VOICE_INTERACTION_SERVICE") onLockscreenShown()203 void onLockscreenShown(); 204 205 /** 206 * Register a voice interaction listener. 207 * @RequiresPermission Manifest.permission.ACCESS_VOICE_INTERACTION_SERVICE 208 */ 209 @EnforcePermission("ACCESS_VOICE_INTERACTION_SERVICE") registerVoiceInteractionSessionListener(IVoiceInteractionSessionListener listener)210 void registerVoiceInteractionSessionListener(IVoiceInteractionSessionListener listener); 211 212 /** 213 * Checks the availability of a set of voice actions for the current active voice service. 214 * Returns all supported voice actions. 215 * @RequiresPermission Manifest.permission.ACCESS_VOICE_INTERACTION_SERVICE 216 */ 217 @EnforcePermission("ACCESS_VOICE_INTERACTION_SERVICE") getActiveServiceSupportedActions(in List<String> voiceActions, in IVoiceActionCheckCallback callback)218 void getActiveServiceSupportedActions(in List<String> voiceActions, 219 in IVoiceActionCheckCallback callback); 220 221 /** 222 * Provide hints for showing UI. 223 * Caller must be the active voice interaction service via 224 * {@link Settings.Secure.VOICE_INTERACTION_SERVICE}. 225 */ setUiHints(in Bundle hints)226 void setUiHints(in Bundle hints); 227 228 /** 229 * Requests a list of supported actions from a specific activity. 230 */ requestDirectActions(in IBinder token, int taskId, IBinder assistToken, in RemoteCallback cancellationCallback, in RemoteCallback callback)231 void requestDirectActions(in IBinder token, int taskId, IBinder assistToken, 232 in RemoteCallback cancellationCallback, in RemoteCallback callback); 233 234 /** 235 * Requests performing an action from a specific activity. 236 */ performDirectAction(in IBinder token, String actionId, in Bundle arguments, int taskId, IBinder assistToken, in RemoteCallback cancellationCallback, in RemoteCallback resultCallback)237 void performDirectAction(in IBinder token, String actionId, in Bundle arguments, int taskId, 238 IBinder assistToken, in RemoteCallback cancellationCallback, 239 in RemoteCallback resultCallback); 240 241 /** 242 * Temporarily disables voice interaction (for example, on Automotive when the display is off). 243 * 244 * It will shutdown the service, and only re-enable it after it's called again (or after a 245 * system restart). 246 * 247 * NOTE: it's only effective when the service itself is available / enabled in the device, so 248 * calling setDisable(false) would be a no-op when it isn't. 249 */ 250 @EnforcePermission("ACCESS_VOICE_INTERACTION_SERVICE") setDisabled(boolean disabled)251 void setDisabled(boolean disabled); 252 253 /** 254 * Creates a session, allowing controlling running sound models on detection hardware. 255 * Caller must provide an identity, used for permission tracking purposes. 256 * The uid/pid elements of the identity will be ignored by the server and replaced with the ones 257 * provided by binder. 258 * 259 * The client argument is any binder owned by the client, used for tracking is death and 260 * cleaning up in this event. 261 */ createSoundTriggerSessionAsOriginator( in Identity originatorIdentity, IBinder client, in SoundTrigger.ModuleProperties moduleProperties)262 IVoiceInteractionSoundTriggerSession createSoundTriggerSessionAsOriginator( 263 in Identity originatorIdentity, 264 IBinder client, 265 in SoundTrigger.ModuleProperties moduleProperties); 266 267 /** 268 * Lists properties of SoundTrigger modules that can be attached to by 269 * @{link createSoundTriggerSessionAsOriginator}. 270 */ listModuleProperties(in Identity originatorIdentity)271 List<SoundTrigger.ModuleProperties> listModuleProperties(in Identity originatorIdentity); 272 273 /** 274 * Set configuration and pass read-only data to hotword detection service. 275 * 276 * @param options Application configuration data to provide to the 277 * {@link HotwordDetectionService}. PersistableBundle does not allow any remotable objects or 278 * other contents that can be used to communicate with other processes. 279 * @param sharedMemory The unrestricted data blob to provide to the 280 * {@link HotwordDetectionService}. Use this to provide the hotword models data or other 281 * such data to the trusted process. 282 * @param token Use this to identify which detector calls this method. 283 */ 284 @EnforcePermission("MANAGE_HOTWORD_DETECTION") updateState( in PersistableBundle options, in SharedMemory sharedMemory, in IBinder token)285 void updateState( 286 in PersistableBundle options, 287 in SharedMemory sharedMemory, 288 in IBinder token); 289 290 /** 291 * Set configuration and pass read-only data to hotword detection service when creating 292 * the detector. 293 * 294 * Caller must provide an identity, used for permission tracking purposes. 295 * The uid/pid elements of the identity will be ignored by the server and replaced with the ones 296 * provided by binder. 297 * 298 * @param options Application configuration data to provide to the 299 * {@link HotwordDetectionService}. PersistableBundle does not allow any remotable objects or 300 * other contents that can be used to communicate with other processes. 301 * @param sharedMemory The unrestricted data blob to provide to the 302 * {@link HotwordDetectionService}. Use this to provide the hotword models data or other 303 * such data to the trusted process. 304 * @param token Use this to identify which detector calls this method. 305 * @param callback Use this to report {@link HotwordDetectionService} status. 306 * @param detectorType Indicate which detector is used. 307 */ 308 @EnforcePermission("MANAGE_HOTWORD_DETECTION") initAndVerifyDetector( in Identity originatorIdentity, in PersistableBundle options, in SharedMemory sharedMemory, in IBinder token, in IHotwordRecognitionStatusCallback callback, int detectorType)309 void initAndVerifyDetector( 310 in Identity originatorIdentity, 311 in PersistableBundle options, 312 in SharedMemory sharedMemory, 313 in IBinder token, 314 in IHotwordRecognitionStatusCallback callback, 315 int detectorType); 316 317 /** 318 * Destroy the detector callback. 319 * 320 * @param token Indicate which callback will be destroyed. 321 */ destroyDetector(in IBinder token)322 void destroyDetector(in IBinder token); 323 324 /** 325 * Requests to shutdown hotword detection service. 326 */ shutdownHotwordDetectionService()327 void shutdownHotwordDetectionService(); 328 329 @EnforcePermission("ACCESS_VOICE_INTERACTION_SERVICE") subscribeVisualQueryRecognitionStatus(in IVisualQueryRecognitionStatusListener listener)330 void subscribeVisualQueryRecognitionStatus(in IVisualQueryRecognitionStatusListener listener); 331 332 @EnforcePermission("ACCESS_VOICE_INTERACTION_SERVICE") enableVisualQueryDetection(in IVisualQueryDetectionAttentionListener Listener)333 void enableVisualQueryDetection(in IVisualQueryDetectionAttentionListener Listener); 334 335 @EnforcePermission("ACCESS_VOICE_INTERACTION_SERVICE") disableVisualQueryDetection()336 void disableVisualQueryDetection(); 337 startPerceiving(in IVisualQueryDetectionVoiceInteractionCallback callback)338 void startPerceiving(in IVisualQueryDetectionVoiceInteractionCallback callback); 339 stopPerceiving()340 void stopPerceiving(); 341 startListeningFromMic( in AudioFormat audioFormat, in IMicrophoneHotwordDetectionVoiceInteractionCallback callback)342 void startListeningFromMic( 343 in AudioFormat audioFormat, 344 in IMicrophoneHotwordDetectionVoiceInteractionCallback callback); 345 stopListeningFromMic()346 void stopListeningFromMic(); 347 startListeningFromExternalSource( in ParcelFileDescriptor audioStream, in AudioFormat audioFormat, in PersistableBundle options, in IBinder token, in IMicrophoneHotwordDetectionVoiceInteractionCallback callback)348 void startListeningFromExternalSource( 349 in ParcelFileDescriptor audioStream, 350 in AudioFormat audioFormat, 351 in PersistableBundle options, 352 in IBinder token, 353 in IMicrophoneHotwordDetectionVoiceInteractionCallback callback); 354 355 /** 356 * Test API to simulate to trigger hardware recognition event for test. 357 */ triggerHardwareRecognitionEventForTest( in SoundTrigger.KeyphraseRecognitionEvent event, in IHotwordRecognitionStatusCallback callback)358 void triggerHardwareRecognitionEventForTest( 359 in SoundTrigger.KeyphraseRecognitionEvent event, 360 in IHotwordRecognitionStatusCallback callback); 361 362 /** 363 * Starts to listen the status of visible activity. 364 */ startListeningVisibleActivityChanged(in IBinder token)365 void startListeningVisibleActivityChanged(in IBinder token); 366 367 /** 368 * Stops to listen the status of visible activity. 369 */ stopListeningVisibleActivityChanged(in IBinder token)370 void stopListeningVisibleActivityChanged(in IBinder token); 371 372 /** 373 * Notifies when the session window is shown or hidden. 374 */ setSessionWindowVisible(in IBinder token, boolean visible)375 void setSessionWindowVisible(in IBinder token, boolean visible); 376 377 /** 378 * Notifies when the Activity lifecycle event changed. 379 * 380 * @param activityToken The token of activity. 381 * @param type The type of lifecycle event of the activity lifecycle. 382 */ notifyActivityEventChanged( in IBinder activityToken, int type)383 oneway void notifyActivityEventChanged( 384 in IBinder activityToken, 385 int type); 386 387 /** 388 * rely on the system server to get the secure settings 389 */ getAccessibilityDetectionEnabled()390 boolean getAccessibilityDetectionEnabled(); 391 392 /** 393 * register the listener 394 */ registerAccessibilityDetectionSettingsListener( in IVoiceInteractionAccessibilitySettingsListener listener)395 oneway void registerAccessibilityDetectionSettingsListener( 396 in IVoiceInteractionAccessibilitySettingsListener listener); 397 398 /** 399 * unregister the listener 400 */ unregisterAccessibilityDetectionSettingsListener( in IVoiceInteractionAccessibilitySettingsListener listener)401 oneway void unregisterAccessibilityDetectionSettingsListener( 402 in IVoiceInteractionAccessibilitySettingsListener listener); 403 } 404