diff options
author | Sandeep Siddhartha <sansid@google.com> | 2014-08-22 16:36:34 -0700 |
---|---|---|
committer | Sandeep Siddhartha <sansid@google.com> | 2014-08-22 17:23:13 -0700 |
commit | dcf3068fcb55f101680e70a8a6f84f3b2c9cb1e3 (patch) | |
tree | c1ddf18c69ab22a4ccc2d3f54b57780494dc6470 /core/java/android/service | |
parent | 7653a30ea0232ab8323ec51ddcba8d8054ca8a2f (diff) | |
download | frameworks_base-dcf3068fcb55f101680e70a8a6f84f3b2c9cb1e3.zip frameworks_base-dcf3068fcb55f101680e70a8a6f84f3b2c9cb1e3.tar.gz frameworks_base-dcf3068fcb55f101680e70a8a6f84f3b2c9cb1e3.tar.bz2 |
Fix the Locale story in the hotword API
Tighten the API by taking in a locale rather than a string tag.
Tighten the checks when reading the enrollment metadata, bail out if any
attribute is missing or invalid.
Add missing recycle call for a TypedArray
Stop recognition when sound model(s) change. This is needed during
un-enrollment/re-enrollment.
Bug: 17187528
Bug: 17205230
Change-Id: Idb00b51ef8c4ea0a8f8993decea582223181fa3d
Diffstat (limited to 'core/java/android/service')
-rw-r--r-- | core/java/android/service/voice/AlwaysOnHotwordDetector.java | 15 | ||||
-rw-r--r-- | core/java/android/service/voice/VoiceInteractionService.java | 17 |
2 files changed, 24 insertions, 8 deletions
diff --git a/core/java/android/service/voice/AlwaysOnHotwordDetector.java b/core/java/android/service/voice/AlwaysOnHotwordDetector.java index 15e66a0..2095773 100644 --- a/core/java/android/service/voice/AlwaysOnHotwordDetector.java +++ b/core/java/android/service/voice/AlwaysOnHotwordDetector.java @@ -39,10 +39,10 @@ import android.util.Slog; import com.android.internal.app.IVoiceInteractionManagerService; -import java.io.FileDescriptor; import java.io.PrintWriter; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; +import java.util.Locale; /** * A class that lets a VoiceInteractionService implementation interact with @@ -167,7 +167,7 @@ public class AlwaysOnHotwordDetector { private static final int MSG_DETECTION_RESUME = 5; private final String mText; - private final String mLocale; + private final Locale mLocale; /** * The metadata of the Keyphrase, derived from the enrollment application. * This may be null if this keyphrase isn't supported by the enrollment application. @@ -317,7 +317,7 @@ public class AlwaysOnHotwordDetector { * * @hide */ - public AlwaysOnHotwordDetector(String text, String locale, Callback callback, + public AlwaysOnHotwordDetector(String text, Locale locale, Callback callback, KeyphraseEnrollmentInfo keyphraseEnrollmentInfo, IVoiceInteractionService voiceInteractionService, IVoiceInteractionManagerService modelManagementService) { @@ -491,8 +491,6 @@ public class AlwaysOnHotwordDetector { */ void onSoundModelsChanged() { synchronized (mLock) { - // FIXME: This should stop the recognition if it was using an enrolled sound model - // that's no longer available. if (mAvailability == STATE_INVALID || mAvailability == STATE_HARDWARE_UNAVAILABLE || mAvailability == STATE_KEYPHRASE_UNSUPPORTED) { @@ -500,6 +498,13 @@ public class AlwaysOnHotwordDetector { return; } + // Stop the recognition before proceeding. + // This is done because we want to stop the recognition on an older model if it changed + // or was deleted. + // The availability change callback should ensure that the client starts recognition + // again if needed. + stopRecognitionLocked(); + // Execute a refresh availability task - which should then notify of a change. new RefreshAvailabiltyTask().execute(); } diff --git a/core/java/android/service/voice/VoiceInteractionService.java b/core/java/android/service/voice/VoiceInteractionService.java index b200356..884fa9f 100644 --- a/core/java/android/service/voice/VoiceInteractionService.java +++ b/core/java/android/service/voice/VoiceInteractionService.java @@ -35,6 +35,7 @@ import com.android.internal.app.IVoiceInteractionManagerService; import java.io.FileDescriptor; import java.io.PrintWriter; +import java.util.Locale; /** @@ -163,7 +164,7 @@ public class VoiceInteractionService extends Service { * 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, String, android.service.voice.AlwaysOnHotwordDetector.Callback)} + * {@link #createAlwaysOnHotwordDetector(String, Locale, android.service.voice.AlwaysOnHotwordDetector.Callback)} * will not be operational until this point. */ public void onReady() { @@ -200,6 +201,17 @@ public class VoiceInteractionService extends Service { } /** + * FIXME: Remove once the prebuilts are updated. + * + * @hide + */ + @Deprecated + public final AlwaysOnHotwordDetector createAlwaysOnHotwordDetector( + String keyphrase, String locale, AlwaysOnHotwordDetector.Callback callback) { + return createAlwaysOnHotwordDetector(keyphrase, new Locale(locale), 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 @@ -207,12 +219,11 @@ public class VoiceInteractionService extends Service { * * @param keyphrase The keyphrase that's being used, for example "Hello Android". * @param locale The locale for which the enrollment needs to be performed. - * This is a Java locale, for example "en_US". * @param callback The callback to notify of detection events. * @return An always-on hotword detector for the given keyphrase and locale. */ public final AlwaysOnHotwordDetector createAlwaysOnHotwordDetector( - String keyphrase, String locale, AlwaysOnHotwordDetector.Callback callback) { + String keyphrase, Locale locale, AlwaysOnHotwordDetector.Callback callback) { if (mSystemService == null) { throw new IllegalStateException("Not available until onReady() is called"); } |