Fields Summary |
---|
public static final String | SERVICE_INTERFACEThe {@link Intent} that must be declared as handled by the service.
To be supported, the service must also require the
{@link android.Manifest.permission#BIND_VOICE_INTERACTION} permission so
that other applications can not abuse it. |
public static final String | SERVICE_META_DATAName under which a VoiceInteractionService component publishes information about itself.
This meta-data should reference an XML resource containing a
<{@link
android.R.styleable#VoiceInteractionService voice-interaction-service}> tag. |
IVoiceInteractionService | mInterface |
MyHandler | mHandler |
com.android.internal.app.IVoiceInteractionManagerService | mSystemService |
private final Object | mLock |
private android.hardware.soundtrigger.KeyphraseEnrollmentInfo | mKeyphraseEnrollmentInfo |
private AlwaysOnHotwordDetector | mHotwordDetector |
static final int | MSG_READY |
static final int | MSG_SHUTDOWN |
static final int | MSG_SOUND_MODELS_CHANGED |
Methods Summary |
---|
public final AlwaysOnHotwordDetector | createAlwaysOnHotwordDetector(java.lang.String keyphrase, java.util.Locale locale, AlwaysOnHotwordDetector.Callback callback)Creates an {@link AlwaysOnHotwordDetector} for the given keyphrase and locale.
This instance must be retained and used by the client.
Calling this a second time invalidates the previously created hotword detector
which can no longer be used to manage recognition.
if (mSystemService == null) {
throw new IllegalStateException("Not available until onReady() is called");
}
synchronized (mLock) {
// Allow only one concurrent recognition via the APIs.
safelyShutdownHotwordDetector();
mHotwordDetector = new AlwaysOnHotwordDetector(keyphrase, locale, callback,
mKeyphraseEnrollmentInfo, mInterface, mSystemService);
}
return mHotwordDetector;
|
protected void | dump(java.io.FileDescriptor fd, java.io.PrintWriter pw, java.lang.String[] args)
pw.println("VOICE INTERACTION");
synchronized (mLock) {
pw.println(" AlwaysOnHotwordDetector");
if (mHotwordDetector == null) {
pw.println(" NULL");
} else {
mHotwordDetector.dump(" ", pw);
}
}
|
protected final android.hardware.soundtrigger.KeyphraseEnrollmentInfo | getKeyphraseEnrollmentInfo()
return mKeyphraseEnrollmentInfo;
|
public static boolean | isActiveService(android.content.Context context, android.content.ComponentName service)Check whether the given service component is the currently active
VoiceInteractionService.
String cur = Settings.Secure.getString(context.getContentResolver(),
Settings.Secure.VOICE_INTERACTION_SERVICE);
if (cur == null || cur.isEmpty()) {
return false;
}
ComponentName curComp = ComponentName.unflattenFromString(cur);
if (curComp == null) {
return false;
}
return curComp.equals(service);
|
public android.os.IBinder | onBind(android.content.Intent intent)
if (SERVICE_INTERFACE.equals(intent.getAction())) {
return mInterface.asBinder();
}
return null;
|
public void | onCreate()
super.onCreate();
mHandler = new MyHandler();
|
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 {@link #onCreate()}. Methods such as {@link #startSession(Bundle)} and
{@link #createAlwaysOnHotwordDetector(String, Locale, android.service.voice.AlwaysOnHotwordDetector.Callback)}
will not be operational until this point.
mSystemService = IVoiceInteractionManagerService.Stub.asInterface(
ServiceManager.getService(Context.VOICE_INTERACTION_MANAGER_SERVICE));
mKeyphraseEnrollmentInfo = new KeyphraseEnrollmentInfo(getPackageManager());
|
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 {@link VoiceInteractionService}.
|
private void | onShutdownInternal()
onShutdown();
// Stop any active recognitions when shutting down.
// This ensures that if implementations forget to stop any active recognition,
// It's still guaranteed to have been stopped.
// This helps with cases where the voice interaction implementation is changed
// by the user.
safelyShutdownHotwordDetector();
|
private void | onSoundModelsChangedInternal()
synchronized (this) {
if (mHotwordDetector != null) {
// TODO: Stop recognition if a sound model that was being recognized gets deleted.
mHotwordDetector.onSoundModelsChanged();
}
}
|
private void | safelyShutdownHotwordDetector()
try {
synchronized (mLock) {
if (mHotwordDetector != null) {
mHotwordDetector.stopRecognition();
mHotwordDetector.invalidate();
mHotwordDetector = null;
}
}
} catch (Exception ex) {
// Ignore.
}
|
public void | startSession(android.os.Bundle args)Initiate the execution of a new {@link android.service.voice.VoiceInteractionSession}.
if (mSystemService == null) {
throw new IllegalStateException("Not available until onReady() is called");
}
try {
mSystemService.startSession(mInterface, args);
} catch (RemoteException e) {
}
|