diff options
author | Sandeep Siddhartha <sansid@google.com> | 2014-07-28 13:25:30 -0700 |
---|---|---|
committer | Sandeep Siddhartha <sansid@google.com> | 2014-07-29 11:24:51 -0700 |
commit | 6817337118655d5792e36e954b123e6daa4174a6 (patch) | |
tree | bacd4155507f64d701c3c7a3e4fa70da89d7d658 /services/voiceinteraction/java | |
parent | 94703148bc522b9f3fab9257fd07021e678d43f2 (diff) | |
download | frameworks_base-6817337118655d5792e36e954b123e6daa4174a6.zip frameworks_base-6817337118655d5792e36e954b123e6daa4174a6.tar.gz frameworks_base-6817337118655d5792e36e954b123e6daa4174a6.tar.bz2 |
Read the keyphrase ID from the recognition event
Bug: 16516658
Change-Id: Ibeee81c9543aa1091bb075066cfc2269107f13c0
Diffstat (limited to 'services/voiceinteraction/java')
-rw-r--r-- | services/voiceinteraction/java/com/android/server/voiceinteraction/SoundTriggerHelper.java | 75 |
1 files changed, 53 insertions, 22 deletions
diff --git a/services/voiceinteraction/java/com/android/server/voiceinteraction/SoundTriggerHelper.java b/services/voiceinteraction/java/com/android/server/voiceinteraction/SoundTriggerHelper.java index 1e4a518..cae7ca5 100644 --- a/services/voiceinteraction/java/com/android/server/voiceinteraction/SoundTriggerHelper.java +++ b/services/voiceinteraction/java/com/android/server/voiceinteraction/SoundTriggerHelper.java @@ -19,6 +19,8 @@ package com.android.server.voiceinteraction; import android.hardware.soundtrigger.IRecognitionStatusCallback; import android.hardware.soundtrigger.SoundTrigger; import android.hardware.soundtrigger.SoundTrigger.Keyphrase; +import android.hardware.soundtrigger.SoundTrigger.KeyphraseRecognitionEvent; +import android.hardware.soundtrigger.SoundTrigger.KeyphraseRecognitionExtra; import android.hardware.soundtrigger.SoundTrigger.KeyphraseSoundModel; import android.hardware.soundtrigger.SoundTrigger.ModuleProperties; import android.hardware.soundtrigger.SoundTrigger.RecognitionConfig; @@ -40,8 +42,6 @@ public class SoundTriggerHelper implements SoundTrigger.StatusListener { static final String TAG = "SoundTriggerHelper"; // TODO: Set to false. static final boolean DBG = true; - // TODO: Remove this. - static final int TEMP_KEYPHRASE_ID = 100; /** * Return codes for {@link #startRecognition(int, KeyphraseSoundModel, @@ -117,7 +117,7 @@ public class SoundTriggerHelper implements SoundTrigger.StatusListener { } if (mCurrentSoundModelHandle != INVALID_SOUND_MODEL_HANDLE) { - Slog.w(TAG, "Canceling previous recognition"); + Slog.w(TAG, "Unloading previous sound model"); // TODO: Inspect the return codes here. mModule.unloadSoundModel(mCurrentSoundModelHandle); mCurrentSoundModelHandle = INVALID_SOUND_MODEL_HANDLE; @@ -127,6 +127,7 @@ public class SoundTriggerHelper implements SoundTrigger.StatusListener { // Notify them that it was stopped. IRecognitionStatusCallback oldListener = mActiveListeners.get(keyphraseId); if (oldListener != null && oldListener.asBinder() != listener.asBinder()) { + Slog.w(TAG, "Canceling previous recognition"); try { oldListener.onDetectionStopped(); } catch (RemoteException e) { @@ -221,33 +222,52 @@ public class SoundTriggerHelper implements SoundTrigger.StatusListener { //---- SoundTrigger.StatusListener methods @Override public void onRecognition(RecognitionEvent event) { - // Check which keyphrase triggered, and fire the appropriate event. - // TODO: Get the keyphrase out of the event and fire events on it. - // For now, as a nasty workaround, we fire all events to the listener for - // keyphrase with TEMP_KEYPHRASE_ID. - IRecognitionStatusCallback listener = null; - synchronized(this) { - // TODO: The keyphrase should come from the recognition event - // as it may be for a different keyphrase than the current one. - listener = mActiveListeners.get(TEMP_KEYPHRASE_ID); - } - if (listener == null) { - Slog.w(TAG, "received onRecognition event without any listener for it"); + if (event == null) { + Slog.w(TAG, "Invalid recognition event!"); return; } + if (DBG) Slog.d(TAG, "onRecognition: " + event); switch (event.status) { - case SoundTrigger.RECOGNITION_STATUS_SUCCESS: + // Fire aborts/failures to all listeners since it's not tied to a keyphrase. + case SoundTrigger.RECOGNITION_STATUS_ABORT: // fall-through + case SoundTrigger.RECOGNITION_STATUS_FAILURE: try { - listener.onDetected(event); + synchronized (this) { + for (int i = 0; i < mActiveListeners.size(); i++) { + mActiveListeners.valueAt(i).onDetectionStopped(); + } + } } catch (RemoteException e) { - Slog.w(TAG, "RemoteException in onDetected"); + Slog.w(TAG, "RemoteException in onDetectionStopped"); } break; - case SoundTrigger.RECOGNITION_STATUS_ABORT: // fall-through - case SoundTrigger.RECOGNITION_STATUS_FAILURE: + case SoundTrigger.RECOGNITION_STATUS_SUCCESS: + if (!(event instanceof KeyphraseRecognitionEvent)) { + Slog.w(TAG, "Invalid recognition event!"); + return; + } + + KeyphraseRecognitionExtra[] keyphraseExtras = + ((KeyphraseRecognitionEvent) event).keyphraseExtras; + if (keyphraseExtras == null || keyphraseExtras.length == 0) { + Slog.w(TAG, "Invalid keyphrase recognition event!"); + return; + } + // TODO: Handle more than one keyphrase extras. + // TODO: Use keyphraseExtras[0].id here instead of 100. + int keyphraseId = 100; try { - listener.onDetectionStopped(); + synchronized(this) { + // Check which keyphrase triggered, and fire the appropriate event. + IRecognitionStatusCallback listener = mActiveListeners.get(keyphraseId); + if (listener != null) { + listener.onDetected((KeyphraseRecognitionEvent) event); + } else { + Slog.w(TAG, "received onRecognition event without any listener for it"); + return; + } + } } catch (RemoteException e) { Slog.w(TAG, "RemoteException in onDetectionStopped"); } @@ -257,6 +277,17 @@ public class SoundTriggerHelper implements SoundTrigger.StatusListener { @Override public void onServiceDied() { - // TODO: Figure out how to restart the recognition here. + synchronized (this) { + try { + for (int i = 0; i < mActiveListeners.size(); i++) { + mActiveListeners.valueAt(i).onDetectionStopped(); + } + } catch (RemoteException e) { + Slog.w(TAG, "RemoteException in onDetectionStopped"); + } + mCurrentSoundModelHandle = INVALID_SOUND_MODEL_HANDLE; + // Remove all listeners. + mActiveListeners.clear(); + } } } |