Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit bf8288ce authored by Chris Thornton's avatar Chris Thornton
Browse files

Add API for querying if a given keyphrase/locale is supported for AOHD.

Test: Use test VoiceInteraction app to verify function behaves as
expected, and no longer crashes in the framework if you try to use a
AOHD with a null KeyphraseEnrollmentMetaData object.

Change-Id: I12923b8ebf37e6de9be336b4397c24679c86fff8
parent 78c44910
Loading
Loading
Loading
Loading
+2 −1
Original line number Diff line number Diff line
@@ -341,7 +341,8 @@ public class KeyphraseEnrollmentInfo {
              }
          }
        }
        Slog.w(TAG, "No Enrollment application supports the given keyphrase/locale");
        Slog.w(TAG, "No enrollment application supports the given keyphrase/locale: '"
                + keyphrase + "'/" + locale);
        return null;
    }

+20 −3
Original line number Diff line number Diff line
@@ -262,7 +262,8 @@ 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.
     * @param callback The callback to notify of detection events.
     * @return An always-on hotword detector for the given keyphrase and locale.
     * @return An always-on hotword detector for the given keyphrase and locale. Is null if the
     * keyphrase and locale is not supported.
     */
    public final AlwaysOnHotwordDetector createAlwaysOnHotwordDetector(
            String keyphrase, Locale locale, AlwaysOnHotwordDetector.Callback callback) {
@@ -272,9 +273,11 @@ public class VoiceInteractionService extends Service {
        synchronized (mLock) {
            // Allow only one concurrent recognition via the APIs.
            safelyShutdownHotwordDetector();
            if (isKeyphraseAndLocaleSupportedForHotword(keyphrase, locale)) {
                mHotwordDetector = new AlwaysOnHotwordDetector(keyphrase, locale, callback,
                        mKeyphraseEnrollmentInfo, mInterface, mSystemService);
            }
        }
        return mHotwordDetector;
    }

@@ -287,6 +290,20 @@ public class VoiceInteractionService extends Service {
        return mKeyphraseEnrollmentInfo;
    }

    /**
      * Checks if a given keyphrase and locale are supported to create an
      * {@link AlwaysOnHotwordDetector}.
      *
      * @return true if the keyphrase and locale combination is supported, false otherwise.
      * @hide
      */
    public final boolean isKeyphraseAndLocaleSupportedForHotword(String keyphrase, Locale locale) {
        if (mKeyphraseEnrollmentInfo == null) {
            return false;
        }
        return mKeyphraseEnrollmentInfo.getKeyphraseMetadata(keyphrase, locale) != null;
    }

    private void safelyShutdownHotwordDetector() {
        try {
            synchronized (mLock) {