VoiceInteractionService
public
class
VoiceInteractionService
extends Service
java.lang.Object | ||||
↳ | android.content.Context | |||
↳ | android.content.ContextWrapper | |||
↳ | android.app.Service | |||
↳ | android.service.voice.VoiceInteractionService |
Top-level service of the current global voice interactor, which is providing
support for hotwording, the back-end of a VoiceInteractor
, etc.
The current VoiceInteractionService that has been selected by the user is kept
always running by the system, to allow it to do things like listen for hotwords
in the background to instigate voice interactions.
Because this service is always running, it should be kept as lightweight as
possible. Heavy-weight operations (including showing UI) should be implemented
in the associated VoiceInteractionSessionService
when
an actual voice interaction is taking place, and that service should run in a
separate process from this one.
Summary
Constants | |
---|---|
String |
SERVICE_INTERFACE
The |
String |
SERVICE_META_DATA
Name under which a VoiceInteractionService component publishes information about itself. |
Inherited constants | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
From class
android.app.Service
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
From class
android.content.Context
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
From interface
android.content.ComponentCallbacks2
|
Public constructors | |
---|---|
VoiceInteractionService()
|
Public methods | |
---|---|
int
|
getDisabledShowContext()
Return the value set by |
static
boolean
|
isActiveService(Context context, ComponentName service)
Check whether the given service component is the currently active VoiceInteractionService. |
IBinder
|
onBind(Intent intent)
Return the communication channel to the service. |
Set<String>
|
onGetSupportedVoiceActions(Set<String> voiceActions)
Request to query for what extended voice actions this service supports. |
void
|
onLaunchVoiceAssistFromKeyguard()
Called when a user has activated an affordance to launch voice assist from the Keyguard. |
void
|
onPrepareToShowSession(Bundle args, int flags)
Notify the interactor when the system prepares to show session. |
void
|
onReady()
Called during service initialization to tell you when the system is ready to receive interaction from it. |
void
|
onShowSessionFailed(Bundle args)
Called when the show session failed. |
void
|
onShutdown()
Called during service de-initialization to tell you when the system is shutting the service down. |
void
|
setDisabledShowContext(int flags)
Set contextual options you would always like to have disabled when a session is shown. |
final
void
|
setInvocationEffectEnabled(boolean enabled)
Sets the enabled state for the invocation effect, a graphical indication displayed when a voice session is launched by the system. |
final
void
|
setUiHints(Bundle hints)
Provide hints to be reflected in the system UI. |
void
|
showSession(Bundle args, int flags)
Request that the associated |
Protected methods | |
---|---|
void
|
dump(FileDescriptor fd, PrintWriter pw, String[] args)
Print the Service's state into the given stream. |
Inherited methods | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
From class
android.app.Service
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
From class
android.content.ContextWrapper
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
From class
android.content.Context
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
From class
java.lang.Object
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
From interface
android.content.ComponentCallbacks2
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
From interface
android.content.ComponentCallbacks
|
Constants
SERVICE_INTERFACE
public static final String SERVICE_INTERFACE
The Intent
that must be declared as handled by the service.
To be supported, the service must also require the
Manifest.permission.BIND_VOICE_INTERACTION
permission so
that other applications can not abuse it.
Constant Value: "android.service.voice.VoiceInteractionService"
SERVICE_META_DATA
public static final String SERVICE_META_DATA
Name under which a VoiceInteractionService component publishes information about itself.
This meta-data should reference an XML resource containing a
<
tag.voice-interaction-service
>
Constant Value: "android.voice_interaction"
Public constructors
VoiceInteractionService
public VoiceInteractionService ()
Public methods
getDisabledShowContext
public int getDisabledShowContext ()
Return the value set by setDisabledShowContext(int)
.
Returns | |
---|---|
int |
isActiveService
public static boolean isActiveService (Context context, ComponentName service)
Check whether the given service component is the currently active VoiceInteractionService.
Parameters | |
---|---|
context |
Context |
service |
ComponentName |
Returns | |
---|---|
boolean |
onBind
public IBinder onBind (Intent intent)
Return the communication channel to the service. May return null if
clients can not bind to the service. The returned
IBinder
is usually for a complex interface
that has been described using
aidl.
Note that unlike other application components, calls on to the IBinder interface returned here may not happen on the main thread of the process. More information about the main thread can be found in Processes and Threads.
Parameters | |
---|---|
intent |
Intent : The Intent that was used to bind to this service,
as given to Context.bindService . Note that any extras that were included with
the Intent at that point will not be seen here. |
Returns | |
---|---|
IBinder |
Return an IBinder through which clients can call on to the service. |
onGetSupportedVoiceActions
public Set<String> onGetSupportedVoiceActions (Set<String> voiceActions)
Request to query for what extended voice actions this service supports. This method will
be called when the system checks the supported actions of this
VoiceInteractionService
. Supported actions may be delivered to
VoiceInteractionSession
later to request a session to perform an action.
Voice actions are defined in support libraries and could vary based on platform context. For example, car related voice actions will be defined in car support libraries.
Parameters | |
---|---|
voiceActions |
Set : A set of checked voice actions.
This value cannot be null . |
Returns | |
---|---|
Set<String> |
Returns a subset of checked voice actions. Additional voice actions in the
returned set will be ignored. Returns empty set if no actions are supported.
This value cannot be null . |
onLaunchVoiceAssistFromKeyguard
public void onLaunchVoiceAssistFromKeyguard ()
Called when a user has activated an affordance to launch voice assist from the Keyguard.
This method will only be called if the VoiceInteractionService has set
R.attr.supportsLaunchVoiceAssistFromKeyguard
and the Keyguard is showing.
A valid implementation must start a new activity that should use WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED
to display
on top of the lock screen.
onPrepareToShowSession
public void onPrepareToShowSession (Bundle args, int flags)
Notify the interactor when the system prepares to show session. The system is going to bind the session service.
Parameters | |
---|---|
args |
Bundle : The arguments that were supplied to showSession(android.os.Bundle, int) .
It always includes VoiceInteractionSession.KEY_SHOW_SESSION_ID .
This value cannot be null . |
flags |
int : The show flags originally provided to showSession(android.os.Bundle, int) . |
onReady
public void onReady ()
Called during service initialization to tell you when the system is ready
to receive interaction from it. You should generally do initialization here
rather than in Service.onCreate()
. Methods such as showSession(Bundle, int)
will
not be operational until this point.
onShowSessionFailed
public void onShowSessionFailed (Bundle args)
Called when the show session failed. E.g. When the system bound the session service failed.
Parameters | |
---|---|
args |
Bundle : Additional info about the show session attempt that failed. For now, includes
VoiceInteractionSession.KEY_SHOW_SESSION_ID .
This value cannot be null . |
onShutdown
public void onShutdown ()
Called during service de-initialization to tell you when the system is shutting the
service down.
At this point this service may no longer be the active VoiceInteractionService
.
setDisabledShowContext
public void setDisabledShowContext (int flags)
Set contextual options you would always like to have disabled when a session
is shown. The flags may be any combination of
VoiceInteractionSession.SHOW_WITH_ASSIST
and
VoiceInteractionSession.SHOW_WITH_SCREENSHOT
.
Parameters | |
---|---|
flags |
int |
setInvocationEffectEnabled
public final void setInvocationEffectEnabled (boolean enabled)
Sets the enabled state for the invocation effect, a graphical indication displayed when a voice session is launched by the system.
This effect is specifically triggered when a voice session is initiated via a dedicated
system entry point, e.g. by long-pressing the power button to activate the current
VoiceInteractionService
. It does not apply to voice sessions
started by general Intent.ACTION_ASSIST
intents from arbitrary applications.
Controlling the Effect and Persistence:
The VoiceInteractionService
(the API caller) controls this
setting. The choice (enabled or disabled) made through this method is persisted by SystemUI
for the current user and their selected assistant. This allows the setting to be remembered
across device reboots or if the same VoiceInteractionService
is restarted for that specific user and assistant combination.
Default State and Behavior on Context Change:
- The invocation effect is disabled by default.
- If the current user changes, or if the selected assistant for that user changes, any previously persisted setting for a different user/assistant combination will not automatically apply to the new context.
- In such new contexts (e.g., a new user or a change in the selected assistant), or if this method has not been explicitly called to enable the effect for the current context, the effect will remain disabled (its default state).
- To enable the effect, or to ensure a specific state (enabled or disabled) is applied,
the
VoiceInteractionService
must call this method. It is strongly recommended to do so every time the service becomes active to assert the intended state for the current operational context.
System Conditions: SystemUI will honor the state set by this method for the invocation effect, provided other system-level conditions are met, such as the correct hardware gesture for invocation (e.g., power button long-press) being detected. Note that the actual visualization of this effect is contingent on the specific SystemUI implementation; some variants, such as those on automotive or television platforms, may not have a visual representation for this effect.
Parameters | |
---|---|
enabled |
boolean : true to enable the invocation effect for the current user and
assistant,
false to disable it. This state is persisted by SystemUI. |
Throws | |
---|---|
SecurityException |
if the caller is not the current active
VoiceInteractionService . |
setUiHints
public final void setUiHints (Bundle hints)
Provide hints to be reflected in the system UI.
Parameters | |
---|---|
hints |
Bundle : Arguments used to show UI.
This value cannot be null . |
showSession
public void showSession (Bundle args, int flags)
Request that the associated VoiceInteractionSession
be
shown to the user, starting it if necessary.
Parameters | |
---|---|
args |
Bundle : Arbitrary arguments that will be propagated to the session. |
flags |
int : Indicates additional optional behavior that should be performed. May
be any combination of
VoiceInteractionSession.SHOW_WITH_ASSIST and
VoiceInteractionSession.SHOW_WITH_SCREENSHOT
to request that the system generate and deliver assist data on the current foreground
app as part of showing the session UI. |
Protected methods
dump
protected void dump (FileDescriptor fd, PrintWriter pw, String[] args)
Print the Service's state into the given stream. This gets invoked if
you run "adb shell dumpsys activity service <yourservicename>"
(note that for this command to work, the service must be running, and
you must specify a fully-qualified service name).
This is distinct from "dumpsys <servicename>", which only works for
named system services and which invokes the IBinder.dump
method
on the IBinder
interface registered with ServiceManager.
Parameters | |
---|---|
fd |
FileDescriptor : The raw file descriptor that the dump is being sent to. |
pw |
PrintWriter : The PrintWriter to which you should dump your state. This will be
closed for you after you return. |
args |
String : additional arguments to the dump request. |