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

Commit 4c460aca authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Defined trigger result structures for positive / negative hotword triggers." into sc-dev

parents 6c9f7d99 b481d8c8
Loading
Loading
Loading
Loading
+40 −0
Original line number Diff line number Diff line
@@ -10342,6 +10342,32 @@ package android.service.voice {
    method public int getStart();
  }
  public final class HotwordDetectedResult implements android.os.Parcelable {
    method public int describeContents();
    method public int getByteOffset();
    method public int getConfidenceLevel();
    method @NonNull public android.os.Bundle getExtras();
    method @Nullable public String getHotwordPhrase();
    method public static int getMaxBundleSize();
    method public static int getMaxScore();
    method public int getPersonalizedScore();
    method public int getScore();
    method public void writeToParcel(@NonNull android.os.Parcel, int);
    field public static final int BYTE_OFFSET_UNSET = -1; // 0xffffffff
    field @NonNull public static final android.os.Parcelable.Creator<android.service.voice.HotwordDetectedResult> CREATOR;
  }
  public static final class HotwordDetectedResult.Builder {
    ctor public HotwordDetectedResult.Builder();
    method @NonNull public android.service.voice.HotwordDetectedResult build();
    method @NonNull public android.service.voice.HotwordDetectedResult.Builder setByteOffset(int);
    method @NonNull public android.service.voice.HotwordDetectedResult.Builder setConfidenceLevel(int);
    method @NonNull public android.service.voice.HotwordDetectedResult.Builder setExtras(@NonNull android.os.Bundle);
    method @NonNull public android.service.voice.HotwordDetectedResult.Builder setHotwordPhrase(@NonNull String);
    method @NonNull public android.service.voice.HotwordDetectedResult.Builder setPersonalizedScore(int);
    method @NonNull public android.service.voice.HotwordDetectedResult.Builder setScore(int);
  }
  public abstract class HotwordDetectionService extends android.app.Service {
    ctor public HotwordDetectionService();
    method @Nullable public final android.os.IBinder onBind(@NonNull android.content.Intent);
@@ -10355,6 +10381,20 @@ package android.service.voice {
    method public void onRejected();
  }
  public interface HotwordDetector {
    field public static final int CONFIDENCE_LEVEL_HIGH = 3; // 0x3
    field public static final int CONFIDENCE_LEVEL_LOW = 1; // 0x1
    field public static final int CONFIDENCE_LEVEL_MEDIUM = 2; // 0x2
    field public static final int CONFIDENCE_LEVEL_NONE = 0; // 0x0
  }
  public final class HotwordRejectedResult implements android.os.Parcelable {
    method public int describeContents();
    method public int getConfidenceLevel();
    method public void writeToParcel(@NonNull android.os.Parcel, int);
    field @NonNull public static final android.os.Parcelable.Creator<android.service.voice.HotwordRejectedResult> CREATOR;
  }
  public class VoiceInteractionService extends android.app.Service {
    method @NonNull public final android.service.voice.AlwaysOnHotwordDetector createAlwaysOnHotwordDetector(String, java.util.Locale, android.service.voice.AlwaysOnHotwordDetector.Callback);
    method @NonNull @RequiresPermission(android.Manifest.permission.MANAGE_HOTWORD_DETECTION) public final android.service.voice.AlwaysOnHotwordDetector createAlwaysOnHotwordDetector(String, java.util.Locale, @Nullable android.os.Bundle, @Nullable android.os.SharedMemory, android.service.voice.AlwaysOnHotwordDetector.Callback);
+19 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2021 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;

parcelable HotwordDetectedResult;
+501 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2021 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 static android.service.voice.HotwordDetector.CONFIDENCE_LEVEL_NONE;

import android.annotation.NonNull;
import android.annotation.Nullable;
import android.annotation.SystemApi;
import android.os.Bundle;
import android.os.Parcelable;

import com.android.internal.util.DataClass;

/**
 * Represents a result supporting the hotword detection.
 *
 * @hide
 */
@DataClass(
        genConstructor = false,
        genBuilder = true,
        genEqualsHashCode = true,
        genHiddenConstDefs = true,
        genParcelable = true,
        genToString = true
)
@SystemApi
public final class HotwordDetectedResult implements Parcelable {

    /** Represents unset value for byte offset. */
    public static final int BYTE_OFFSET_UNSET = -1;

    /** Confidence level in the trigger outcome. */
    @HotwordDetector.HotwordConfidenceLevelValue
    private final int mConfidenceLevel;
    private static int defaultConfidenceLevel() {
        return CONFIDENCE_LEVEL_NONE;
    }

    /**
     * Byte offset in the audio stream when the trigger event happened.
     *
     * <p>If unset, the most recent bytes in the audio stream will be used.
     */
    private final int mByteOffset;
    private static int defaultByteOffset() {
        return BYTE_OFFSET_UNSET;
    }

    /**
     * Score for the hotword trigger.
     *
     * <p>Only values between 0 and {@link #getMaxScore} (inclusive) are accepted.
     */
    private final int mScore;
    private static int defaultScore() {
        return 0;
    }

    /**
     * Score for the hotword trigger for device user.
     *
     * <p>Only values between 0 and {@link #getMaxScore} (inclusive) are accepted.
     */
    private final int mPersonalizedScore;
    private static int defaultPersonalizedScore() {
        return 0;
    }

    /**
     * Returns the maximum values of {@link #getScore} and {@link #getPersonalizedScore}.
     *
     * The float value should be calculated as {@code getScore() / getMaxScore()}.
     */
    public static int getMaxScore() {
        return 255;
    }

    /**
     * Triggered phrase.
     *
     * <p>This phrase has to be listed in the AndroidManifest of the application in order for
     * trigger to be accepted by the system.
     */
    // TODO(b/183128696): allow listing this in the manifest.
    @Nullable
    private final String mHotwordPhrase;
    private static String defaultHotwordPhrase() {
        return null;
    }

    /**
     * App-specific extras to support trigger.
     *
     * <p>The size of this bundle will be limited to {@link #getMaxBundleSize}. Results will larger
     * bundles will be rejected.
     *
     * <p>Only primitive types are supported in this bundle. Complex types will be removed from the
     * bundle.
     *
     * <p>The use of this method is discouraged, and support for it will be removed in future
     * versions of Android.
     */
    @NonNull
    private final Bundle mExtras;
    private static Bundle defaultExtras() {
        return new Bundle();
    }

    /**
     * Returns the maximum byte size of the information contained in the bundle.
     *
     * <p>The total size will be calculated as a sum of byte sizes over all bundle keys.
     *
     * <p>For example, for a bundle containing a single key: {@code "example_key" -> 42.0f}, the
     * bundle size will be {@code 11 + Float.BYTES = 15} bytes.
     */
    public static int getMaxBundleSize() {
        return 50;
    }



    // Code below generated by codegen v1.0.22.
    //
    // DO NOT MODIFY!
    // CHECKSTYLE:OFF Generated code
    //
    // To regenerate run:
    // $ codegen $ANDROID_BUILD_TOP/frameworks/base/core/java/android/service/voice/HotwordDetectedResult.java
    //
    // To exclude the generated code from IntelliJ auto-formatting enable (one-time):
    //   Settings > Editor > Code Style > Formatter Control
    //@formatter:off


    @DataClass.Generated.Member
    /* package-private */ HotwordDetectedResult(
            @HotwordDetector.HotwordConfidenceLevelValue int confidenceLevel,
            int byteOffset,
            int score,
            int personalizedScore,
            @Nullable String hotwordPhrase,
            @NonNull Bundle extras) {
        this.mConfidenceLevel = confidenceLevel;
        com.android.internal.util.AnnotationValidations.validate(
                HotwordDetector.HotwordConfidenceLevelValue.class, null, mConfidenceLevel);
        this.mByteOffset = byteOffset;
        this.mScore = score;
        this.mPersonalizedScore = personalizedScore;
        this.mHotwordPhrase = hotwordPhrase;
        this.mExtras = extras;
        com.android.internal.util.AnnotationValidations.validate(
                NonNull.class, null, mExtras);

        // onConstructed(); // You can define this method to get a callback
    }

    /**
     * Confidence level in the trigger outcome.
     */
    @DataClass.Generated.Member
    public @HotwordDetector.HotwordConfidenceLevelValue int getConfidenceLevel() {
        return mConfidenceLevel;
    }

    /**
     * Byte offset in the audio stream when the trigger event happened.
     *
     * <p>If unset, the most recent bytes in the audio stream will be used.
     */
    @DataClass.Generated.Member
    public int getByteOffset() {
        return mByteOffset;
    }

    /**
     * Score for the hotword trigger.
     *
     * <p>Only values between 0 and {@link #getMaxScore} (inclusive) are accepted.
     */
    @DataClass.Generated.Member
    public int getScore() {
        return mScore;
    }

    /**
     * Score for the hotword trigger for device user.
     *
     * <p>Only values between 0 and {@link #getMaxScore} (inclusive) are accepted.
     */
    @DataClass.Generated.Member
    public int getPersonalizedScore() {
        return mPersonalizedScore;
    }

    @DataClass.Generated.Member
    public @Nullable String getHotwordPhrase() {
        return mHotwordPhrase;
    }

    /**
     * App-specific extras to support trigger.
     *
     * <p>The size of this bundle will be limited to {@link #getMaxBundleSize}. Results will larger
     * bundles will be rejected.
     *
     * <p>Only primitive types are supported in this bundle. Complex types will be removed from the
     * bundle.
     *
     * <p>The use of this method is discouraged, and support for it will be removed in future
     * versions of Android.
     */
    @DataClass.Generated.Member
    public @NonNull Bundle getExtras() {
        return mExtras;
    }

    @Override
    @DataClass.Generated.Member
    public String toString() {
        // You can override field toString logic by defining methods like:
        // String fieldNameToString() { ... }

        return "HotwordDetectedResult { " +
                "confidenceLevel = " + mConfidenceLevel + ", " +
                "byteOffset = " + mByteOffset + ", " +
                "score = " + mScore + ", " +
                "personalizedScore = " + mPersonalizedScore + ", " +
                "hotwordPhrase = " + mHotwordPhrase + ", " +
                "extras = " + mExtras +
        " }";
    }

    @Override
    @DataClass.Generated.Member
    public boolean equals(@Nullable Object o) {
        // You can override field equality logic by defining either of the methods like:
        // boolean fieldNameEquals(HotwordDetectedResult other) { ... }
        // boolean fieldNameEquals(FieldType otherValue) { ... }

        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        @SuppressWarnings("unchecked")
        HotwordDetectedResult that = (HotwordDetectedResult) o;
        //noinspection PointlessBooleanExpression
        return true
                && mConfidenceLevel == that.mConfidenceLevel
                && mByteOffset == that.mByteOffset
                && mScore == that.mScore
                && mPersonalizedScore == that.mPersonalizedScore
                && java.util.Objects.equals(mHotwordPhrase, that.mHotwordPhrase)
                && java.util.Objects.equals(mExtras, that.mExtras);
    }

    @Override
    @DataClass.Generated.Member
    public int hashCode() {
        // You can override field hashCode logic by defining methods like:
        // int fieldNameHashCode() { ... }

        int _hash = 1;
        _hash = 31 * _hash + mConfidenceLevel;
        _hash = 31 * _hash + mByteOffset;
        _hash = 31 * _hash + mScore;
        _hash = 31 * _hash + mPersonalizedScore;
        _hash = 31 * _hash + java.util.Objects.hashCode(mHotwordPhrase);
        _hash = 31 * _hash + java.util.Objects.hashCode(mExtras);
        return _hash;
    }

    @Override
    @DataClass.Generated.Member
    public void writeToParcel(@NonNull android.os.Parcel dest, int flags) {
        // You can override field parcelling by defining methods like:
        // void parcelFieldName(Parcel dest, int flags) { ... }

        byte flg = 0;
        if (mHotwordPhrase != null) flg |= 0x10;
        dest.writeByte(flg);
        dest.writeInt(mConfidenceLevel);
        dest.writeInt(mByteOffset);
        dest.writeInt(mScore);
        dest.writeInt(mPersonalizedScore);
        if (mHotwordPhrase != null) dest.writeString(mHotwordPhrase);
        dest.writeBundle(mExtras);
    }

    @Override
    @DataClass.Generated.Member
    public int describeContents() { return 0; }

    /** @hide */
    @SuppressWarnings({"unchecked", "RedundantCast"})
    @DataClass.Generated.Member
    /* package-private */ HotwordDetectedResult(@NonNull android.os.Parcel in) {
        // You can override field unparcelling by defining methods like:
        // static FieldType unparcelFieldName(Parcel in) { ... }

        byte flg = in.readByte();
        int confidenceLevel = in.readInt();
        int byteOffset = in.readInt();
        int score = in.readInt();
        int personalizedScore = in.readInt();
        String hotwordPhrase = (flg & 0x10) == 0 ? null : in.readString();
        Bundle extras = in.readBundle();

        this.mConfidenceLevel = confidenceLevel;
        com.android.internal.util.AnnotationValidations.validate(
                HotwordDetector.HotwordConfidenceLevelValue.class, null, mConfidenceLevel);
        this.mByteOffset = byteOffset;
        this.mScore = score;
        this.mPersonalizedScore = personalizedScore;
        this.mHotwordPhrase = hotwordPhrase;
        this.mExtras = extras;
        com.android.internal.util.AnnotationValidations.validate(
                NonNull.class, null, mExtras);

        // onConstructed(); // You can define this method to get a callback
    }

    @DataClass.Generated.Member
    public static final @NonNull Parcelable.Creator<HotwordDetectedResult> CREATOR
            = new Parcelable.Creator<HotwordDetectedResult>() {
        @Override
        public HotwordDetectedResult[] newArray(int size) {
            return new HotwordDetectedResult[size];
        }

        @Override
        public HotwordDetectedResult createFromParcel(@NonNull android.os.Parcel in) {
            return new HotwordDetectedResult(in);
        }
    };

    /**
     * A builder for {@link HotwordDetectedResult}
     */
    @SuppressWarnings("WeakerAccess")
    @DataClass.Generated.Member
    public static final class Builder {

        private @HotwordDetector.HotwordConfidenceLevelValue int mConfidenceLevel;
        private int mByteOffset;
        private int mScore;
        private int mPersonalizedScore;
        private @Nullable String mHotwordPhrase;
        private @NonNull Bundle mExtras;

        private long mBuilderFieldsSet = 0L;

        public Builder() {
        }

        /**
         * Confidence level in the trigger outcome.
         */
        @DataClass.Generated.Member
        public @NonNull Builder setConfidenceLevel(@HotwordDetector.HotwordConfidenceLevelValue int value) {
            checkNotUsed();
            mBuilderFieldsSet |= 0x1;
            mConfidenceLevel = value;
            return this;
        }

        /**
         * Byte offset in the audio stream when the trigger event happened.
         *
         * <p>If unset, the most recent bytes in the audio stream will be used.
         */
        @DataClass.Generated.Member
        public @NonNull Builder setByteOffset(int value) {
            checkNotUsed();
            mBuilderFieldsSet |= 0x2;
            mByteOffset = value;
            return this;
        }

        /**
         * Score for the hotword trigger.
         *
         * <p>Only values between 0 and {@link #getMaxScore} (inclusive) are accepted.
         */
        @DataClass.Generated.Member
        public @NonNull Builder setScore(int value) {
            checkNotUsed();
            mBuilderFieldsSet |= 0x4;
            mScore = value;
            return this;
        }

        /**
         * Score for the hotword trigger for device user.
         *
         * <p>Only values between 0 and {@link #getMaxScore} (inclusive) are accepted.
         */
        @DataClass.Generated.Member
        public @NonNull Builder setPersonalizedScore(int value) {
            checkNotUsed();
            mBuilderFieldsSet |= 0x8;
            mPersonalizedScore = value;
            return this;
        }

        @DataClass.Generated.Member
        public @NonNull Builder setHotwordPhrase(@NonNull String value) {
            checkNotUsed();
            mBuilderFieldsSet |= 0x10;
            mHotwordPhrase = value;
            return this;
        }

        /**
         * App-specific extras to support trigger.
         *
         * <p>The size of this bundle will be limited to {@link #getMaxBundleSize}. Results will larger
         * bundles will be rejected.
         *
         * <p>Only primitive types are supported in this bundle. Complex types will be removed from the
         * bundle.
         *
         * <p>The use of this method is discouraged, and support for it will be removed in future
         * versions of Android.
         */
        @DataClass.Generated.Member
        public @NonNull Builder setExtras(@NonNull Bundle value) {
            checkNotUsed();
            mBuilderFieldsSet |= 0x20;
            mExtras = value;
            return this;
        }

        /** Builds the instance. This builder should not be touched after calling this! */
        public @NonNull HotwordDetectedResult build() {
            checkNotUsed();
            mBuilderFieldsSet |= 0x40; // Mark builder used

            if ((mBuilderFieldsSet & 0x1) == 0) {
                mConfidenceLevel = defaultConfidenceLevel();
            }
            if ((mBuilderFieldsSet & 0x2) == 0) {
                mByteOffset = defaultByteOffset();
            }
            if ((mBuilderFieldsSet & 0x4) == 0) {
                mScore = defaultScore();
            }
            if ((mBuilderFieldsSet & 0x8) == 0) {
                mPersonalizedScore = defaultPersonalizedScore();
            }
            if ((mBuilderFieldsSet & 0x10) == 0) {
                mHotwordPhrase = defaultHotwordPhrase();
            }
            if ((mBuilderFieldsSet & 0x20) == 0) {
                mExtras = defaultExtras();
            }
            HotwordDetectedResult o = new HotwordDetectedResult(
                    mConfidenceLevel,
                    mByteOffset,
                    mScore,
                    mPersonalizedScore,
                    mHotwordPhrase,
                    mExtras);
            return o;
        }

        private void checkNotUsed() {
            if ((mBuilderFieldsSet & 0x40) != 0) {
                throw new IllegalStateException(
                        "This Builder should not be reused. Use a new Builder instance instead");
            }
        }
    }

    @DataClass.Generated(
            time = 1616110545582L,
            codegenVersion = "1.0.22",
            sourceFile = "frameworks/base/core/java/android/service/voice/HotwordDetectedResult.java",
            inputSignatures = "public static final  int BYTE_OFFSET_UNSET\nprivate final @android.service.voice.HotwordDetector.HotwordConfidenceLevelValue int mConfidenceLevel\nprivate final  int mByteOffset\nprivate final  int mScore\nprivate final  int mPersonalizedScore\nprivate final @android.annotation.Nullable java.lang.String mHotwordPhrase\nprivate final @android.annotation.NonNull android.os.Bundle mExtras\nprivate static  int defaultConfidenceLevel()\nprivate static  int defaultByteOffset()\nprivate static  int defaultScore()\nprivate static  int defaultPersonalizedScore()\npublic static  int getMaxScore()\nprivate static  java.lang.String defaultHotwordPhrase()\nprivate static  android.os.Bundle defaultExtras()\npublic static  int getMaxBundleSize()\nclass HotwordDetectedResult extends java.lang.Object implements [android.os.Parcelable]\n@com.android.internal.util.DataClass(genConstructor=false, genBuilder=true, genEqualsHashCode=true, genHiddenConstDefs=true, genParcelable=true, genToString=true)")
    @Deprecated
    private void __metadata() {}


    //@formatter:on
    // End of generated code

}
+50 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2021 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 android.annotation.IntDef;
import android.annotation.SystemApi;

/**
 * Basic functionality for hotword detectors.
 *
 * @hide
 */
@SystemApi
public interface HotwordDetector {

    /** No confidence in hotword detector result. */
    int CONFIDENCE_LEVEL_NONE = 0;

    /** Small confidence in hotword detector result. */
    int CONFIDENCE_LEVEL_LOW = 1;

    /** Medium confidence in hotword detector result. */
    int CONFIDENCE_LEVEL_MEDIUM = 2;

    /** High confidence in hotword detector result. */
    int CONFIDENCE_LEVEL_HIGH = 3;

    /** @hide */
    @IntDef(prefix = { "CONFIDENCE_LEVEL_" }, value = {
            CONFIDENCE_LEVEL_NONE,
            CONFIDENCE_LEVEL_LOW,
            CONFIDENCE_LEVEL_MEDIUM,
            CONFIDENCE_LEVEL_HIGH
    })
    @interface HotwordConfidenceLevelValue {}
}
+19 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2021 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;

parcelable HotwordRejectedResult;
Loading