diff options
author | Sandeep Siddhartha <sansid@google.com> | 2014-06-03 16:29:37 -0700 |
---|---|---|
committer | Sandeep Siddhartha <sansid@google.com> | 2014-06-11 15:34:26 -0700 |
commit | e912ac012e7146e9b0e8589bd9d88790e55372e3 (patch) | |
tree | 7a78ec4308615b4c7c5c0aa20dbe2865e1f25b03 | |
parent | e5706787599f8397e19e66afa70753ba350cc91b (diff) | |
download | frameworks_base-e912ac012e7146e9b0e8589bd9d88790e55372e3.zip frameworks_base-e912ac012e7146e9b0e8589bd9d88790e55372e3.tar.gz frameworks_base-e912ac012e7146e9b0e8589bd9d88790e55372e3.tar.bz2 |
Add capability APIs to VoiceInteractionService
The only API we currently need is one that tells us whether the system
is capable of running hotword detection for a given keyphrase+locale on
the hardware.
Also adds support in the KeyphraseEnrollmentInfo to provide an intent
for enrollment.
Change-Id: Iec102a4a94e7b161087b8d19785d761346e927c2
4 files changed, 153 insertions, 3 deletions
diff --git a/core/java/android/service/voice/DspInfo.java b/core/java/android/service/voice/DspInfo.java new file mode 100644 index 0000000..5c11388 --- /dev/null +++ b/core/java/android/service/voice/DspInfo.java @@ -0,0 +1,56 @@ +/* + * Copyright (C) 2014 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package android.service.voice; + +import java.util.UUID; + +/** + * Properties of the DSP hardware on the device. + * @hide + */ +public class DspInfo { + /** + * Unique voice engine Id (changes with each version). + */ + public final UUID voiceEngineId; + + /** + * Human readable voice detection engine implementor. + */ + public final String voiceEngineImplementor; + /** + * Human readable voice detection engine description. + */ + public final String voiceEngineDescription; + /** + * Human readable voice detection engine version + */ + public final String voiceEngineVersion; + /** + * Rated power consumption when detection is active. + */ + public final int powerConsumptionMw; + + public DspInfo(UUID voiceEngineId, String voiceEngineImplementor, + String voiceEngineDescription, String voiceEngineVersion, int powerConsumptionMw) { + this.voiceEngineId = voiceEngineId; + this.voiceEngineImplementor = voiceEngineImplementor; + this.voiceEngineDescription = voiceEngineDescription; + this.voiceEngineVersion = voiceEngineVersion; + this.powerConsumptionMw = powerConsumptionMw; + } +} diff --git a/core/java/android/service/voice/KeyphraseEnrollmentInfo.java b/core/java/android/service/voice/KeyphraseEnrollmentInfo.java index 41b8613..3af8054 100644 --- a/core/java/android/service/voice/KeyphraseEnrollmentInfo.java +++ b/core/java/android/service/voice/KeyphraseEnrollmentInfo.java @@ -45,7 +45,6 @@ public class KeyphraseEnrollmentInfo { * voice-enrollment-application}></code> tag. */ private static final String VOICE_KEYPHRASE_META_DATA = "android.voice_enrollment"; - /** * Activity Action: Show activity for managing the keyphrases for hotword detection. * This needs to be defined by an activity that supports enrolling users for hotword/keyphrase @@ -53,8 +52,24 @@ public class KeyphraseEnrollmentInfo { */ public static final String ACTION_MANAGE_VOICE_KEYPHRASES = "com.android.intent.action.MANAGE_VOICE_KEYPHRASES"; + /** + * Intent extra: The intent extra for un-enrolling a user for a particular keyphrase. + */ + public static final String EXTRA_VOICE_KEYPHRASE_UNENROLL = + "com.android.intent.extra.VOICE_KEYPHRASE_UNENROLL"; + /** + * Intent extra: The hint text to be shown on the voice keyphrase management UI. + */ + public static final String EXTRA_VOICE_KEYPHRASE_HINT_TEXT = + "com.android.intent.extra.VOICE_KEYPHRASE_HINT_TEXT"; + /** + * Intent extra: The voice locale to use while managing the keyphrase. + */ + public static final String EXTRA_VOICE_KEYPHRASE_LOCALE = + "com.android.intent.extra.VOICE_KEYPHRASE_LOCALE"; private KeyphraseInfo[] mKeyphrases; + private String mEnrollmentPackage; private String mParseError; public KeyphraseEnrollmentInfo(PackageManager pm) { @@ -85,6 +100,7 @@ public class KeyphraseEnrollmentInfo { // require the MANAGE_VOICE_KEYPHRASES permission. continue; } + mEnrollmentPackage = ai.packageName; found = true; break; } catch (PackageManager.NameNotFoundException e) { @@ -93,6 +109,7 @@ public class KeyphraseEnrollmentInfo { } if (!found) { + mKeyphrases = null; mParseError = "No suitable enrollment application found"; return; } @@ -164,4 +181,56 @@ public class KeyphraseEnrollmentInfo { public String getParseError() { return mParseError; } + + /** + * Returns an intent to launch an activity that manages the given keyphrase + * for the locale. + * + * @param enroll Indicates if the intent should enroll the user or un-enroll them. + * @param keyphrase The keyphrase that the user needs to be enrolled to. + * @param locale The locale for which the enrollment needs to be performed. + * @return An {@link Intent} to manage the keyphrase. This can be null if managing the + * given keyphrase/locale combination isn't possible. + */ + public Intent getManageKeyphraseIntent(boolean enroll, String keyphrase, String locale) { + if (mEnrollmentPackage == null || mEnrollmentPackage.isEmpty()) { + Log.w(TAG, "No enrollment application exists"); + return null; + } + + if (isKeyphraseEnrollmentSupported(keyphrase, locale)) { + Intent intent = new Intent(ACTION_MANAGE_VOICE_KEYPHRASES) + .setPackage(mEnrollmentPackage) + .putExtra(EXTRA_VOICE_KEYPHRASE_HINT_TEXT, keyphrase) + .putExtra(EXTRA_VOICE_KEYPHRASE_LOCALE, locale); + if (!enroll) intent.putExtra(EXTRA_VOICE_KEYPHRASE_UNENROLL, true); + return intent; + } + return null; + } + + /** + * Indicates if enrollment is supported for the given keyphrase & locale. + * + * @param keyphrase The keyphrase that the user needs to be enrolled to. + * @param locale The locale for which the enrollment needs to be performed. + * @return true, if an enrollment client supports the given keyphrase and the given locale. + */ + public boolean isKeyphraseEnrollmentSupported(String keyphrase, String locale) { + if (mKeyphrases == null || mKeyphrases.length == 0) { + Log.w(TAG, "Enrollment application doesn't support keyphrases"); + return false; + } + for (KeyphraseInfo keyphraseInfo : mKeyphrases) { + // Check if the given keyphrase is supported in the locale provided by + // the enrollment application. + String supportedKeyphrase = keyphraseInfo.keyphrase; + if (supportedKeyphrase.equalsIgnoreCase(keyphrase) + && keyphraseInfo.supportedLocales.contains(locale)) { + return true; + } + } + Log.w(TAG, "Enrollment application doesn't support the given keyphrase"); + return false; + } } diff --git a/core/java/android/service/voice/KeyphraseInfo.java b/core/java/android/service/voice/KeyphraseInfo.java index 55734e8..303aac4 100644 --- a/core/java/android/service/voice/KeyphraseInfo.java +++ b/core/java/android/service/voice/KeyphraseInfo.java @@ -2,7 +2,10 @@ package android.service.voice; import android.util.ArraySet; -/** @hide */ +/** + * A Voice Keyphrase. + * @hide + */ public class KeyphraseInfo { public final int id; public final String keyphrase; diff --git a/core/java/android/service/voice/VoiceInteractionService.java b/core/java/android/service/voice/VoiceInteractionService.java index 2154719..175a968 100644 --- a/core/java/android/service/voice/VoiceInteractionService.java +++ b/core/java/android/service/voice/VoiceInteractionService.java @@ -17,7 +17,6 @@ package android.service.voice; import android.annotation.SdkConstant; -import android.app.Instrumentation; import android.app.Service; import android.content.Context; import android.content.Intent; @@ -65,6 +64,9 @@ public class VoiceInteractionService extends Service { IVoiceInteractionManagerService mSystemService; + private DspInfo mDspInfo; + private KeyphraseEnrollmentInfo mKeyphraseEnrollmentInfo; + public void startSession(Bundle args) { try { mSystemService.startSession(mInterface, args); @@ -77,6 +79,8 @@ public class VoiceInteractionService extends Service { super.onCreate(); mSystemService = IVoiceInteractionManagerService.Stub.asInterface( ServiceManager.getService(Context.VOICE_INTERACTION_MANAGER_SERVICE)); + mKeyphraseEnrollmentInfo = new KeyphraseEnrollmentInfo(getPackageManager()); + // TODO(sansid): Read mDspInfo from the SoundTriggerModel API. } @Override @@ -86,4 +90,22 @@ public class VoiceInteractionService extends Service { } return null; } + + /** + * Indicates if always-on hotword detection is available for the given keyphrase and locale + * on this system. + * Availability implies that the hardware on this system is capable of listening for + * the given keyphrase or not. + * @param keyphrase The keyphrase whose availability is being checked. + * @param locale The locale for which the availability is being checked. + * @return Indicates if always-on hotword detection is available for the given keyphrase. + * TODO(sansid): Unhide this. + * @hide + */ + public final boolean isAlwaysOnHotwordAvailable(String keyphrase, String locale) { + // The available keyphrases is a combination of DSP availability and + // the keyphrases that have an enrollment application for them. + return mDspInfo != null + && mKeyphraseEnrollmentInfo.isKeyphraseEnrollmentSupported(keyphrase, locale); + } } |