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

Commit d3c1f27b authored by Nicholas Ambur's avatar Nicholas Ambur
Browse files

add KeyphraseEnrollmentInfo to TestApi

KeyphraseEnrollmentInfo is used for testing the system enrollment
application support within GTS.

Bug: 153264697
Test: gts-tradefed run gts-dev -m GtsAssistIntentTestCases \
-t com.google.android.assist.gts.KeyphraseModelManagerTest# \
testAllSystemKeyphrasesAndLocales

Change-Id: I66558cf849f2815f2c917d128f9f9cc0673750ef
Merged-In: I66558cf849f2815f2c917d128f9f9cc0673750ef
parent f996e424
Loading
Loading
Loading
Loading
+28 −0
Original line number Original line Diff line number Diff line
@@ -1320,6 +1320,34 @@ package android.hardware.lights {


}
}


package android.hardware.soundtrigger {

  public class KeyphraseEnrollmentInfo {
    ctor public KeyphraseEnrollmentInfo(@NonNull android.content.pm.PackageManager);
    method @Nullable public android.hardware.soundtrigger.KeyphraseMetadata getKeyphraseMetadata(@NonNull String, @NonNull java.util.Locale);
    method @Nullable public android.content.Intent getManageKeyphraseIntent(int, @NonNull String, @NonNull java.util.Locale);
    method @NonNull public String getParseError();
    method @NonNull public java.util.Collection<android.hardware.soundtrigger.KeyphraseMetadata> listKeyphraseMetadata();
    field public static final int MANAGE_ACTION_ENROLL = 0; // 0x0
    field public static final int MANAGE_ACTION_RE_ENROLL = 1; // 0x1
    field public static final int MANAGE_ACTION_UN_ENROLL = 2; // 0x2
  }

  public final class KeyphraseMetadata implements android.os.Parcelable {
    ctor public KeyphraseMetadata(int, @NonNull String, @NonNull java.util.Set<java.util.Locale>, int);
    method public int describeContents();
    method public int getId();
    method @NonNull public String getKeyphrase();
    method public int getRecognitionModeFlags();
    method @NonNull public java.util.Set<java.util.Locale> getSupportedLocales();
    method public boolean supportsLocale(@Nullable java.util.Locale);
    method public boolean supportsPhrase(@Nullable String);
    method public void writeToParcel(@NonNull android.os.Parcel, int);
    field @NonNull public static final android.os.Parcelable.Creator<android.hardware.soundtrigger.KeyphraseMetadata> CREATOR;
  }

}

package android.location {
package android.location {


  public final class GnssClock implements android.os.Parcelable {
  public final class GnssClock implements android.os.Parcelable {
+34 −14
Original line number Original line Diff line number Diff line
@@ -18,6 +18,9 @@ package android.hardware.soundtrigger;


import android.Manifest;
import android.Manifest;
import android.annotation.IntDef;
import android.annotation.IntDef;
import android.annotation.NonNull;
import android.annotation.Nullable;
import android.annotation.TestApi;
import android.content.Intent;
import android.content.Intent;
import android.content.pm.ApplicationInfo;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager;
import android.content.pm.PackageManager;
@@ -37,18 +40,22 @@ import org.xmlpull.v1.XmlPullParserException;
import java.io.IOException;
import java.io.IOException;
import java.lang.annotation.Retention;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.RetentionPolicy;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.LinkedList;
import java.util.List;
import java.util.List;
import java.util.Locale;
import java.util.Locale;
import java.util.Map;
import java.util.Map;
import java.util.Objects;


/**
/**
 * Enrollment information about the different available keyphrases.
 * Enrollment information about the different available keyphrases.
 *
 *
 * @hide
 * @hide
 */
 */
@TestApi
public class KeyphraseEnrollmentInfo {
public class KeyphraseEnrollmentInfo {
    private static final String TAG = "KeyphraseEnrollmentInfo";
    private static final String TAG = "KeyphraseEnrollmentInfo";
    /**
    /**
@@ -63,6 +70,7 @@ public class KeyphraseEnrollmentInfo {
     * Intent Action: for managing the keyphrases for hotword detection.
     * Intent Action: for managing the keyphrases for hotword detection.
     * This needs to be defined by a service that supports enrolling users for hotword/keyphrase
     * This needs to be defined by a service that supports enrolling users for hotword/keyphrase
     * detection.
     * detection.
     * @hide
     */
     */
    public static final String ACTION_MANAGE_VOICE_KEYPHRASES =
    public static final String ACTION_MANAGE_VOICE_KEYPHRASES =
            "com.android.intent.action.MANAGE_VOICE_KEYPHRASES";
            "com.android.intent.action.MANAGE_VOICE_KEYPHRASES";
@@ -72,18 +80,21 @@ public class KeyphraseEnrollmentInfo {
     * @see #MANAGE_ACTION_ENROLL
     * @see #MANAGE_ACTION_ENROLL
     * @see #MANAGE_ACTION_RE_ENROLL
     * @see #MANAGE_ACTION_RE_ENROLL
     * @see #MANAGE_ACTION_UN_ENROLL
     * @see #MANAGE_ACTION_UN_ENROLL
     * @hide
     */
     */
    public static final String EXTRA_VOICE_KEYPHRASE_ACTION =
    public static final String EXTRA_VOICE_KEYPHRASE_ACTION =
            "com.android.intent.extra.VOICE_KEYPHRASE_ACTION";
            "com.android.intent.extra.VOICE_KEYPHRASE_ACTION";


    /**
    /**
     * Intent extra: The hint text to be shown on the voice keyphrase management UI.
     * Intent extra: The hint text to be shown on the voice keyphrase management UI.
     * @hide
     */
     */
    public static final String EXTRA_VOICE_KEYPHRASE_HINT_TEXT =
    public static final String EXTRA_VOICE_KEYPHRASE_HINT_TEXT =
            "com.android.intent.extra.VOICE_KEYPHRASE_HINT_TEXT";
            "com.android.intent.extra.VOICE_KEYPHRASE_HINT_TEXT";
    /**
    /**
     * Intent extra: The voice locale to use while managing the keyphrase.
     * Intent extra: The voice locale to use while managing the keyphrase.
     * This is a BCP-47 language tag.
     * This is a BCP-47 language tag.
     * @hide
     */
     */
    public static final String EXTRA_VOICE_KEYPHRASE_LOCALE =
    public static final String EXTRA_VOICE_KEYPHRASE_LOCALE =
            "com.android.intent.extra.VOICE_KEYPHRASE_LOCALE";
            "com.android.intent.extra.VOICE_KEYPHRASE_LOCALE";
@@ -125,7 +136,8 @@ public class KeyphraseEnrollmentInfo {


    private String mParseError;
    private String mParseError;


    public KeyphraseEnrollmentInfo(PackageManager pm) {
    public KeyphraseEnrollmentInfo(@NonNull PackageManager pm) {
        Objects.requireNonNull(pm);
        // Find the apps that supports enrollment for hotword keyhphrases,
        // Find the apps that supports enrollment for hotword keyhphrases,
        // Pick a privileged app and obtain the information about the supported keyphrases
        // Pick a privileged app and obtain the information about the supported keyphrases
        // from its metadata.
        // from its metadata.
@@ -134,13 +146,13 @@ public class KeyphraseEnrollmentInfo {
        if (ris == null || ris.isEmpty()) {
        if (ris == null || ris.isEmpty()) {
            // No application capable of enrolling for voice keyphrases is present.
            // No application capable of enrolling for voice keyphrases is present.
            mParseError = "No enrollment applications found";
            mParseError = "No enrollment applications found";
            mKeyphrasePackageMap = Collections.<KeyphraseMetadata, String>emptyMap();
            mKeyphrasePackageMap = Collections.emptyMap();
            mKeyphrases = null;
            mKeyphrases = null;
            return;
            return;
        }
        }


        List<String> parseErrors = new LinkedList<String>();
        List<String> parseErrors = new LinkedList<>();
        mKeyphrasePackageMap = new HashMap<KeyphraseMetadata, String>();
        mKeyphrasePackageMap = new HashMap<>();
        for (ResolveInfo ri : ris) {
        for (ResolveInfo ri : ris) {
            try {
            try {
                ApplicationInfo ai = pm.getApplicationInfo(
                ApplicationInfo ai = pm.getApplicationInfo(
@@ -178,7 +190,7 @@ public class KeyphraseEnrollmentInfo {
            mKeyphrases = null;
            mKeyphrases = null;
        } else {
        } else {
            mKeyphrases = mKeyphrasePackageMap.keySet().toArray(
            mKeyphrases = mKeyphrasePackageMap.keySet().toArray(
                    new KeyphraseMetadata[mKeyphrasePackageMap.size()]);
                    new KeyphraseMetadata[0]);
        }
        }


        if (!parseErrors.isEmpty()) {
        if (!parseErrors.isEmpty()) {
@@ -269,8 +281,8 @@ public class KeyphraseEnrollmentInfo {
        if (!TextUtils.isEmpty(searchKeyphraseSupportedLocales)) {
        if (!TextUtils.isEmpty(searchKeyphraseSupportedLocales)) {
            try {
            try {
                String[] supportedLocalesDelimited = searchKeyphraseSupportedLocales.split(",");
                String[] supportedLocalesDelimited = searchKeyphraseSupportedLocales.split(",");
                for (int i = 0; i < supportedLocalesDelimited.length; i++) {
                for (String s : supportedLocalesDelimited) {
                    locales.add(Locale.forLanguageTag(supportedLocalesDelimited[i]));
                    locales.add(Locale.forLanguageTag(s));
                }
                }
            } catch (Exception ex) {
            } catch (Exception ex) {
                // We catch a generic exception here because we don't want the system service
                // We catch a generic exception here because we don't want the system service
@@ -297,6 +309,7 @@ public class KeyphraseEnrollmentInfo {
        return new KeyphraseMetadata(searchKeyphraseId, searchKeyphrase, locales, recognitionModes);
        return new KeyphraseMetadata(searchKeyphraseId, searchKeyphrase, locales, recognitionModes);
    }
    }


    @NonNull
    public String getParseError() {
    public String getParseError() {
        return mParseError;
        return mParseError;
    }
    }
@@ -305,8 +318,9 @@ public class KeyphraseEnrollmentInfo {
     * @return An array of available keyphrases that can be enrolled on the system.
     * @return An array of available keyphrases that can be enrolled on the system.
     *         It may be null if no keyphrases can be enrolled.
     *         It may be null if no keyphrases can be enrolled.
     */
     */
    public KeyphraseMetadata[] listKeyphraseMetadata() {
    @NonNull
        return mKeyphrases;
    public Collection<KeyphraseMetadata> listKeyphraseMetadata() {
        return Arrays.asList(mKeyphrases);
    }
    }


    /**
    /**
@@ -319,8 +333,11 @@ public class KeyphraseEnrollmentInfo {
     * @return An {@link Intent} to manage the keyphrase. This can be null if managing the
     * @return An {@link Intent} to manage the keyphrase. This can be null if managing the
     *         given keyphrase/locale combination isn't possible.
     *         given keyphrase/locale combination isn't possible.
     */
     */
    public Intent getManageKeyphraseIntent(@ManageActions int action, String keyphrase,
    @Nullable
            Locale locale) {
    public Intent getManageKeyphraseIntent(@ManageActions int action, @NonNull String keyphrase,
            @NonNull Locale locale) {
        Objects.requireNonNull(keyphrase);
        Objects.requireNonNull(locale);
        if (mKeyphrasePackageMap == null || mKeyphrasePackageMap.isEmpty()) {
        if (mKeyphrasePackageMap == null || mKeyphrasePackageMap.isEmpty()) {
            Slog.w(TAG, "No enrollment application exists");
            Slog.w(TAG, "No enrollment application exists");
            return null;
            return null;
@@ -328,12 +345,11 @@ public class KeyphraseEnrollmentInfo {


        KeyphraseMetadata keyphraseMetadata = getKeyphraseMetadata(keyphrase, locale);
        KeyphraseMetadata keyphraseMetadata = getKeyphraseMetadata(keyphrase, locale);
        if (keyphraseMetadata != null) {
        if (keyphraseMetadata != null) {
            Intent intent = new Intent(ACTION_MANAGE_VOICE_KEYPHRASES)
            return new Intent(ACTION_MANAGE_VOICE_KEYPHRASES)
                    .setPackage(mKeyphrasePackageMap.get(keyphraseMetadata))
                    .setPackage(mKeyphrasePackageMap.get(keyphraseMetadata))
                    .putExtra(EXTRA_VOICE_KEYPHRASE_HINT_TEXT, keyphrase)
                    .putExtra(EXTRA_VOICE_KEYPHRASE_HINT_TEXT, keyphrase)
                    .putExtra(EXTRA_VOICE_KEYPHRASE_LOCALE, locale.toLanguageTag())
                    .putExtra(EXTRA_VOICE_KEYPHRASE_LOCALE, locale.toLanguageTag())
                    .putExtra(EXTRA_VOICE_KEYPHRASE_ACTION, action);
                    .putExtra(EXTRA_VOICE_KEYPHRASE_ACTION, action);
            return intent;
        }
        }
        return null;
        return null;
    }
    }
@@ -348,7 +364,11 @@ public class KeyphraseEnrollmentInfo {
     * @return The metadata, if the enrollment client supports the given keyphrase
     * @return The metadata, if the enrollment client supports the given keyphrase
     *         and locale, null otherwise.
     *         and locale, null otherwise.
     */
     */
    public KeyphraseMetadata getKeyphraseMetadata(String keyphrase, Locale locale) {
    @Nullable
    public KeyphraseMetadata getKeyphraseMetadata(@NonNull String keyphrase,
            @NonNull Locale locale) {
        Objects.requireNonNull(keyphrase);
        Objects.requireNonNull(locale);
        if (mKeyphrases != null && mKeyphrases.length > 0) {
        if (mKeyphrases != null && mKeyphrases.length > 0) {
          for (KeyphraseMetadata keyphraseMetadata : mKeyphrases) {
          for (KeyphraseMetadata keyphraseMetadata : mKeyphrases) {
              // Check if the given keyphrase is supported in the locale provided by
              // Check if the given keyphrase is supported in the locale provided by
+62 −41
Original line number Original line Diff line number Diff line
@@ -18,57 +18,78 @@ package android.hardware.soundtrigger;


import android.annotation.NonNull;
import android.annotation.NonNull;
import android.annotation.Nullable;
import android.annotation.Nullable;
import android.annotation.TestApi;
import android.os.Parcelable;
import android.os.Parcelable;
import android.util.ArraySet;
import android.util.ArraySet;


import com.android.internal.util.DataClass;
import com.android.internal.util.DataClass;


import java.util.Locale;
import java.util.Locale;
import java.util.Set;


/**
/**
 * A Voice Keyphrase metadata read from the enrollment application.
 * A Voice Keyphrase metadata read from the enrollment application.
 *
 *
 * @hide
 * @hide
 */
 */
@TestApi
@DataClass(
@DataClass(
        genEqualsHashCode = true,
        genEqualsHashCode = true,
        genToString = true,
        genToString = true,
        genConstructor = false,
        genConstructor = false,
        genHiddenConstDefs = true)
        genHiddenConstDefs = true)
public final class KeyphraseMetadata implements Parcelable {
public final class KeyphraseMetadata implements Parcelable {
    public final int id;
    private final int mId;
    @NonNull
    @NonNull
    public final String keyphrase;
    private final String mKeyphrase;
    @NonNull
    @NonNull
    public final ArraySet<Locale> supportedLocales;
    private final ArraySet<Locale> mSupportedLocales;
    public final int recognitionModeFlags;
    private final int mRecognitionModeFlags;


    public KeyphraseMetadata(int id, @NonNull String keyphrase,
    public KeyphraseMetadata(int id, @NonNull String keyphrase,
            @NonNull ArraySet<Locale> supportedLocales, int recognitionModeFlags) {
            @NonNull Set<Locale> supportedLocales, int recognitionModeFlags) {
        this.id = id;
        this.mId = id;
        this.keyphrase = keyphrase;
        this.mKeyphrase = keyphrase;
        this.supportedLocales = supportedLocales;
        this.mSupportedLocales = new ArraySet<>(supportedLocales);
        this.recognitionModeFlags = recognitionModeFlags;
        this.mRecognitionModeFlags = recognitionModeFlags;
    }

    public int getId() {
        return mId;
    }

    @NonNull
    public String getKeyphrase() {
        return mKeyphrase;
    }

    @NonNull
    public Set<Locale> getSupportedLocales() {
        return mSupportedLocales;
    }

    public int getRecognitionModeFlags() {
        return mRecognitionModeFlags;
    }
    }


    /**
    /**
     * @return Indicates if we support the given phrase.
     * @return Indicates if we support the given phrase.
     */
     */
    public boolean supportsPhrase(@Nullable String phrase) {
    public boolean supportsPhrase(@Nullable String phrase) {
        return keyphrase.isEmpty() || keyphrase.equalsIgnoreCase(phrase);
        return getKeyphrase().isEmpty() || getKeyphrase().equalsIgnoreCase(phrase);
    }
    }


    /**
    /**
     * @return Indicates if we support the given locale.
     * @return Indicates if we support the given locale.
     */
     */
    public boolean supportsLocale(@Nullable Locale locale) {
    public boolean supportsLocale(@Nullable Locale locale) {
        return supportedLocales.isEmpty() || supportedLocales.contains(locale);
        return getSupportedLocales().isEmpty() || getSupportedLocales().contains(locale);
    }
    }








    // Code below generated by codegen v1.0.14.
    // Code below generated by codegen v1.0.15.
    //
    //
    // DO NOT MODIFY!
    // DO NOT MODIFY!
    // CHECKSTYLE:OFF Generated code
    // CHECKSTYLE:OFF Generated code
@@ -88,10 +109,10 @@ public final class KeyphraseMetadata implements Parcelable {
        // String fieldNameToString() { ... }
        // String fieldNameToString() { ... }


        return "KeyphraseMetadata { " +
        return "KeyphraseMetadata { " +
                "id = " + id + ", " +
                "id = " + mId + ", " +
                "keyphrase = " + keyphrase + ", " +
                "keyphrase = " + mKeyphrase + ", " +
                "supportedLocales = " + supportedLocales + ", " +
                "supportedLocales = " + mSupportedLocales + ", " +
                "recognitionModeFlags = " + recognitionModeFlags +
                "recognitionModeFlags = " + mRecognitionModeFlags +
        " }";
        " }";
    }
    }


@@ -108,10 +129,10 @@ public final class KeyphraseMetadata implements Parcelable {
        KeyphraseMetadata that = (KeyphraseMetadata) o;
        KeyphraseMetadata that = (KeyphraseMetadata) o;
        //noinspection PointlessBooleanExpression
        //noinspection PointlessBooleanExpression
        return true
        return true
                && id == that.id
                && mId == that.mId
                && java.util.Objects.equals(keyphrase, that.keyphrase)
                && java.util.Objects.equals(mKeyphrase, that.mKeyphrase)
                && java.util.Objects.equals(supportedLocales, that.supportedLocales)
                && java.util.Objects.equals(mSupportedLocales, that.mSupportedLocales)
                && recognitionModeFlags == that.recognitionModeFlags;
                && mRecognitionModeFlags == that.mRecognitionModeFlags;
    }
    }


    @Override
    @Override
@@ -121,10 +142,10 @@ public final class KeyphraseMetadata implements Parcelable {
        // int fieldNameHashCode() { ... }
        // int fieldNameHashCode() { ... }


        int _hash = 1;
        int _hash = 1;
        _hash = 31 * _hash + id;
        _hash = 31 * _hash + mId;
        _hash = 31 * _hash + java.util.Objects.hashCode(keyphrase);
        _hash = 31 * _hash + java.util.Objects.hashCode(mKeyphrase);
        _hash = 31 * _hash + java.util.Objects.hashCode(supportedLocales);
        _hash = 31 * _hash + java.util.Objects.hashCode(mSupportedLocales);
        _hash = 31 * _hash + recognitionModeFlags;
        _hash = 31 * _hash + mRecognitionModeFlags;
        return _hash;
        return _hash;
    }
    }


@@ -134,10 +155,10 @@ public final class KeyphraseMetadata implements Parcelable {
        // You can override field parcelling by defining methods like:
        // You can override field parcelling by defining methods like:
        // void parcelFieldName(Parcel dest, int flags) { ... }
        // void parcelFieldName(Parcel dest, int flags) { ... }


        dest.writeInt(id);
        dest.writeInt(mId);
        dest.writeString(keyphrase);
        dest.writeString(mKeyphrase);
        dest.writeArraySet(supportedLocales);
        dest.writeArraySet(mSupportedLocales);
        dest.writeInt(recognitionModeFlags);
        dest.writeInt(mRecognitionModeFlags);
    }
    }


    @Override
    @Override
@@ -151,19 +172,19 @@ public final class KeyphraseMetadata implements Parcelable {
        // You can override field unparcelling by defining methods like:
        // You can override field unparcelling by defining methods like:
        // static FieldType unparcelFieldName(Parcel in) { ... }
        // static FieldType unparcelFieldName(Parcel in) { ... }


        int _id = in.readInt();
        int id = in.readInt();
        String _keyphrase = in.readString();
        String keyphrase = in.readString();
        ArraySet<Locale> _supportedLocales = (ArraySet) in.readArraySet(null);
        ArraySet<Locale> supportedLocales = (ArraySet) in.readArraySet(null);
        int _recognitionModeFlags = in.readInt();
        int recognitionModeFlags = in.readInt();


        this.id = _id;
        this.mId = id;
        this.keyphrase = _keyphrase;
        this.mKeyphrase = keyphrase;
        com.android.internal.util.AnnotationValidations.validate(
        com.android.internal.util.AnnotationValidations.validate(
                NonNull.class, null, keyphrase);
                NonNull.class, null, mKeyphrase);
        this.supportedLocales = _supportedLocales;
        this.mSupportedLocales = supportedLocales;
        com.android.internal.util.AnnotationValidations.validate(
        com.android.internal.util.AnnotationValidations.validate(
                NonNull.class, null, supportedLocales);
                NonNull.class, null, mSupportedLocales);
        this.recognitionModeFlags = _recognitionModeFlags;
        this.mRecognitionModeFlags = recognitionModeFlags;


        // onConstructed(); // You can define this method to get a callback
        // onConstructed(); // You can define this method to get a callback
    }
    }
@@ -183,10 +204,10 @@ public final class KeyphraseMetadata implements Parcelable {
    };
    };


    @DataClass.Generated(
    @DataClass.Generated(
            time = 1579290593964L,
            time = 1586191622057L,
            codegenVersion = "1.0.14",
            codegenVersion = "1.0.15",
            sourceFile = "frameworks/base/core/java/android/hardware/soundtrigger/KeyphraseMetadata.java",
            sourceFile = "frameworks/base/core/java/android/hardware/soundtrigger/KeyphraseMetadata.java",
            inputSignatures = "public final  int id\npublic final @android.annotation.NonNull java.lang.String keyphrase\npublic final @android.annotation.NonNull android.util.ArraySet<java.util.Locale> supportedLocales\npublic final  int recognitionModeFlags\npublic  boolean supportsPhrase(java.lang.String)\npublic  boolean supportsLocale(java.util.Locale)\nclass KeyphraseMetadata extends java.lang.Object implements [android.os.Parcelable]\n@com.android.internal.util.DataClass(genEqualsHashCode=true, genToString=true, genConstructor=false, genHiddenConstDefs=true)")
            inputSignatures = "private final  int mId\nprivate final @android.annotation.NonNull java.lang.String mKeyphrase\nprivate final @android.annotation.NonNull android.util.ArraySet<java.util.Locale> mSupportedLocales\nprivate final  int mRecognitionModeFlags\npublic  int getId()\npublic @android.annotation.NonNull java.lang.String getKeyphrase()\npublic @android.annotation.NonNull java.util.Set<java.util.Locale> getSupportedLocales()\npublic  int getRecognitionModeFlags()\npublic  boolean supportsPhrase(java.lang.String)\npublic  boolean supportsLocale(java.util.Locale)\nclass KeyphraseMetadata extends java.lang.Object implements [android.os.Parcelable]\n@com.android.internal.util.DataClass(genEqualsHashCode=true, genToString=true, genConstructor=false, genHiddenConstDefs=true)")
    @Deprecated
    @Deprecated
    private void __metadata() {}
    private void __metadata() {}


+8 −8
Original line number Original line Diff line number Diff line
@@ -460,7 +460,7 @@ public class AlwaysOnHotwordDetector {
                    "Getting supported recognition modes for the keyphrase is not supported");
                    "Getting supported recognition modes for the keyphrase is not supported");
        }
        }


        return mKeyphraseMetadata.recognitionModeFlags;
        return mKeyphraseMetadata.getRecognitionModeFlags();
    }
    }


    /**
    /**
@@ -765,8 +765,8 @@ public class AlwaysOnHotwordDetector {
    private int startRecognitionLocked(int recognitionFlags) {
    private int startRecognitionLocked(int recognitionFlags) {
        KeyphraseRecognitionExtra[] recognitionExtra = new KeyphraseRecognitionExtra[1];
        KeyphraseRecognitionExtra[] recognitionExtra = new KeyphraseRecognitionExtra[1];
        // TODO: Do we need to do something about the confidence level here?
        // TODO: Do we need to do something about the confidence level here?
        recognitionExtra[0] = new KeyphraseRecognitionExtra(mKeyphraseMetadata.id,
        recognitionExtra[0] = new KeyphraseRecognitionExtra(mKeyphraseMetadata.getId(),
                mKeyphraseMetadata.recognitionModeFlags, 0, new ConfidenceLevel[0]);
                mKeyphraseMetadata.getRecognitionModeFlags(), 0, new ConfidenceLevel[0]);
        boolean captureTriggerAudio =
        boolean captureTriggerAudio =
                (recognitionFlags&RECOGNITION_FLAG_CAPTURE_TRIGGER_AUDIO) != 0;
                (recognitionFlags&RECOGNITION_FLAG_CAPTURE_TRIGGER_AUDIO) != 0;
        boolean allowMultipleTriggers =
        boolean allowMultipleTriggers =
@@ -783,7 +783,7 @@ public class AlwaysOnHotwordDetector {
        int code;
        int code;
        try {
        try {
            code = mModelManagementService.startRecognition(
            code = mModelManagementService.startRecognition(
                    mKeyphraseMetadata.id, mLocale.toLanguageTag(), mInternalCallback,
                    mKeyphraseMetadata.getId(), mLocale.toLanguageTag(), mInternalCallback,
                    new RecognitionConfig(captureTriggerAudio, allowMultipleTriggers,
                    new RecognitionConfig(captureTriggerAudio, allowMultipleTriggers,
                            recognitionExtra, null /* additional data */, audioCapabilities));
                            recognitionExtra, null /* additional data */, audioCapabilities));
        } catch (RemoteException e) {
        } catch (RemoteException e) {
@@ -799,7 +799,7 @@ public class AlwaysOnHotwordDetector {
    private int stopRecognitionLocked() {
    private int stopRecognitionLocked() {
        int code;
        int code;
        try {
        try {
            code = mModelManagementService.stopRecognition(mKeyphraseMetadata.id,
            code = mModelManagementService.stopRecognition(mKeyphraseMetadata.getId(),
                    mInternalCallback);
                    mInternalCallback);
        } catch (RemoteException e) {
        } catch (RemoteException e) {
            throw e.rethrowFromSystemServer();
            throw e.rethrowFromSystemServer();
@@ -813,7 +813,7 @@ public class AlwaysOnHotwordDetector {


    private int setParameterLocked(@ModelParams int modelParam, int value) {
    private int setParameterLocked(@ModelParams int modelParam, int value) {
        try {
        try {
            int code = mModelManagementService.setParameter(mKeyphraseMetadata.id, modelParam,
            int code = mModelManagementService.setParameter(mKeyphraseMetadata.getId(), modelParam,
                    value);
                    value);


            if (code != STATUS_OK) {
            if (code != STATUS_OK) {
@@ -828,7 +828,7 @@ public class AlwaysOnHotwordDetector {


    private int getParameterLocked(@ModelParams int modelParam) {
    private int getParameterLocked(@ModelParams int modelParam) {
        try {
        try {
            return mModelManagementService.getParameter(mKeyphraseMetadata.id, modelParam);
            return mModelManagementService.getParameter(mKeyphraseMetadata.getId(), modelParam);
        } catch (RemoteException e) {
        } catch (RemoteException e) {
            throw e.rethrowFromSystemServer();
            throw e.rethrowFromSystemServer();
        }
        }
@@ -838,7 +838,7 @@ public class AlwaysOnHotwordDetector {
    private ModelParamRange queryParameterLocked(@ModelParams int modelParam) {
    private ModelParamRange queryParameterLocked(@ModelParams int modelParam) {
        try {
        try {
            SoundTrigger.ModelParamRange modelParamRange =
            SoundTrigger.ModelParamRange modelParamRange =
                    mModelManagementService.queryParameter(mKeyphraseMetadata.id, modelParam);
                    mModelManagementService.queryParameter(mKeyphraseMetadata.getId(), modelParam);


            if (modelParamRange == null) {
            if (modelParamRange == null) {
                return null;
                return null;
+2 −4
Original line number Original line Diff line number Diff line
@@ -16,14 +16,11 @@


package com.android.test.voiceinteraction;
package com.android.test.voiceinteraction;


import android.content.ComponentName;
import android.content.Intent;
import android.content.Intent;
import android.os.Bundle;
import android.service.voice.AlwaysOnHotwordDetector;
import android.service.voice.AlwaysOnHotwordDetector;
import android.service.voice.AlwaysOnHotwordDetector.Callback;
import android.service.voice.AlwaysOnHotwordDetector.Callback;
import android.service.voice.AlwaysOnHotwordDetector.EventPayload;
import android.service.voice.AlwaysOnHotwordDetector.EventPayload;
import android.service.voice.VoiceInteractionService;
import android.service.voice.VoiceInteractionService;
import android.service.voice.VoiceInteractionSession;
import android.util.Log;
import android.util.Log;


import java.util.Arrays;
import java.util.Arrays;
@@ -68,7 +65,8 @@ public class MainInteractionService extends VoiceInteractionService {
        Log.i(TAG, "Creating " + this);
        Log.i(TAG, "Creating " + this);
        Log.i(TAG, "Keyphrase enrollment error? " + getKeyphraseEnrollmentInfo().getParseError());
        Log.i(TAG, "Keyphrase enrollment error? " + getKeyphraseEnrollmentInfo().getParseError());
        Log.i(TAG, "Keyphrase enrollment meta-data: "
        Log.i(TAG, "Keyphrase enrollment meta-data: "
                + Arrays.toString(getKeyphraseEnrollmentInfo().listKeyphraseMetadata()));
                + Arrays.toString(getKeyphraseEnrollmentInfo().listKeyphraseMetadata().toArray(
                new android.hardware.soundtrigger.KeyphraseMetadata[0])));


        mHotwordDetector = createAlwaysOnHotwordDetector(
        mHotwordDetector = createAlwaysOnHotwordDetector(
                "Hello There", Locale.forLanguageTag("en-US"), mHotwordCallback);
                "Hello There", Locale.forLanguageTag("en-US"), mHotwordCallback);