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

Commit e0b8b8cd authored by Nicholas Ambur's avatar Nicholas Ambur Committed by Android (Google) Code Review
Browse files

Merge "add SoundTrigger HAL 2.3 per model parameter apis"

parents 056d51ce a0be6be3
Loading
Loading
Loading
Loading
+12 −1
Original line number Diff line number Diff line
@@ -3410,6 +3410,14 @@ package android.hardware.soundtrigger {
    field public static final int STATUS_OK = 0; // 0x0
  }
  public static final class SoundTrigger.ModelParamRange implements android.os.Parcelable {
    method public int describeContents();
    method public void writeToParcel(@NonNull android.os.Parcel, int);
    field @NonNull public static final android.os.Parcelable.Creator<android.hardware.soundtrigger.SoundTrigger.ModelParamRange> CREATOR;
    field public final int end;
    field public final int start;
  }
  public static final class SoundTrigger.ModuleProperties implements android.os.Parcelable {
    method public int describeContents();
    method public void writeToParcel(android.os.Parcel, int);
@@ -4199,8 +4207,11 @@ package android.media.soundtrigger {
    method @Nullable @RequiresPermission(android.Manifest.permission.MANAGE_SOUND_TRIGGER) public android.media.soundtrigger.SoundTriggerDetector createSoundTriggerDetector(java.util.UUID, @NonNull android.media.soundtrigger.SoundTriggerDetector.Callback, @Nullable android.os.Handler);
    method @RequiresPermission(android.Manifest.permission.MANAGE_SOUND_TRIGGER) public void deleteModel(java.util.UUID);
    method public int getDetectionServiceOperationsTimeout();
    method @RequiresPermission(android.Manifest.permission.MANAGE_SOUND_TRIGGER) public android.media.soundtrigger.SoundTriggerManager.Model getModel(java.util.UUID);
    method @Nullable @RequiresPermission(android.Manifest.permission.MANAGE_SOUND_TRIGGER) public android.media.soundtrigger.SoundTriggerManager.Model getModel(java.util.UUID);
    method @Nullable @RequiresPermission(android.Manifest.permission.MANAGE_SOUND_TRIGGER) public android.hardware.soundtrigger.SoundTrigger.ModuleProperties getModuleProperties();
    method @RequiresPermission(android.Manifest.permission.MANAGE_SOUND_TRIGGER) public int getParameter(@NonNull java.util.UUID, int) throws java.lang.IllegalArgumentException, java.lang.UnsupportedOperationException;
    method @Nullable @RequiresPermission(android.Manifest.permission.MANAGE_SOUND_TRIGGER) public android.hardware.soundtrigger.SoundTrigger.ModelParamRange queryParameter(@Nullable java.util.UUID, int);
    method @RequiresPermission(android.Manifest.permission.MANAGE_SOUND_TRIGGER) public int setParameter(@Nullable java.util.UUID, int, int) throws java.lang.IllegalArgumentException, java.lang.UnsupportedOperationException;
    method @RequiresPermission(android.Manifest.permission.MANAGE_SOUND_TRIGGER) public void updateModel(android.media.soundtrigger.SoundTriggerManager.Model);
  }
+37 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2019 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.hardware.soundtrigger;

/**
 * Model specific parameters to be used with parameter set and get APIs
 * {@hide}
 */
@Backing(type="int")
enum ModelParams {
  /**
   * Placeholder for invalid model parameter used for returning error or
   * passing an invalid value.
   */
  INVALID = -1,
  /**
   * Controls the sensitivity threshold adjustment factor for a given model.
   * Negative value corresponds to less sensitive model (high threshold) and
   * a positive value corresponds to a more sensitive model (low threshold).
   * Default value is 0.
   */
  THRESHOLD_FACTOR = 0,
}
+1 −0
Original line number Diff line number Diff line
@@ -24,5 +24,6 @@ parcelable SoundTrigger.GenericRecognitionEvent;
parcelable SoundTrigger.KeyphraseRecognitionExtra;
parcelable SoundTrigger.KeyphraseSoundModel;
parcelable SoundTrigger.GenericSoundModel;
parcelable SoundTrigger.ModelParamRange;
parcelable SoundTrigger.ModuleProperties;
parcelable SoundTrigger.RecognitionConfig;
+59 −0
Original line number Diff line number Diff line
@@ -567,6 +567,65 @@ public class SoundTrigger {
        }
    }

    /*****************************************************************************
     * A ModelParamRange is a representation of supported parameter range for a
     * given loaded model.
     ****************************************************************************/
    public static final class ModelParamRange implements Parcelable {

        /**
         * start of supported range inclusive
         */
        public final int start;

        /**
         * end of supported range inclusive
         */
        public final int end;

        ModelParamRange(int start, int end) {
            this.start = start;
            this.end = end;
        }

        private ModelParamRange(@NonNull Parcel in) {
            this.start = in.readInt();
            this.end = in.readInt();
        }

        @NonNull
        public static final Creator<ModelParamRange> CREATOR = new Creator<ModelParamRange>() {
            @Override
            @NonNull
            public ModelParamRange createFromParcel(@NonNull Parcel in) {
                return new ModelParamRange(in);
            }

            @Override
            @NonNull
            public ModelParamRange[] newArray(int size) {
                return new ModelParamRange[size];
            }
        };

        @Override
        public int describeContents() {
            return 0;
        }

        @Override
        public void writeToParcel(@NonNull Parcel dest, int flags) {
            dest.writeInt(start);
            dest.writeInt(end);
        }

        @Override
        @NonNull
        public String toString() {
            return "ModelParamRange [start=" + start + ", end=" + end + "]";
        }
    }

    /**
     *  Modes for key phrase recognition
     */
+53 −0
Original line number Diff line number Diff line
@@ -16,7 +16,9 @@

package android.hardware.soundtrigger;

import android.annotation.Nullable;
import android.annotation.UnsupportedAppUsage;
import android.hardware.soundtrigger.SoundTrigger.ModelParamRange;
import android.os.Handler;
import android.os.Looper;
import android.os.Message;
@@ -150,6 +152,57 @@ public class SoundTriggerModule {
     */
    public native int getModelState(int soundModelHandle);

    /**
     * Set a model specific {@link ModelParams} with the given value. This
     * parameter will keep its value for the duration the model is loaded regardless of starting and
     * stopping recognition. Once the model is unloaded, the value will be lost.
     * {@link SoundTriggerModule#isParameterSupported} should be checked first before calling this
     * method.
     *
     * @param soundModelHandle handle of model to apply parameter
     * @param modelParam   {@link ModelParams}
     * @param value        Value to set
     * @return - {@link SoundTrigger#STATUS_OK} in case of success
     *         - {@link SoundTrigger#STATUS_NO_INIT} if the native service cannot be reached
     *         - {@link SoundTrigger#STATUS_BAD_VALUE} invalid input parameter
     *         - {@link SoundTrigger#STATUS_INVALID_OPERATION} if the call is out of sequence or
     *           if API is not supported by HAL
     */
    public native int setParameter(int soundModelHandle,
            @ModelParams int modelParam, int value);

    /**
     * Get a model specific {@link ModelParams}. This parameter will keep its value
     * for the duration the model is loaded regardless of starting and stopping recognition.
     * Once the model is unloaded, the value will be lost. If the value is not set, a default
     * value is returned. See {@link ModelParams} for parameter default values.
     * {@link SoundTriggerModule#isParameterSupported} should be checked first before
     * calling this method. Otherwise, an exception can be thrown.
     *
     * @param soundModelHandle handle of model to get parameter
     * @param modelParam   {@link ModelParams}
     * @return value of parameter
     * @throws UnsupportedOperationException if hal or model do not support this API.
     *         {@link SoundTriggerModule#isParameterSupported} should be checked first.
     * @throws IllegalArgumentException if invalid model handle or parameter is passed.
     *         {@link SoundTriggerModule#isParameterSupported} should be checked first.
     */
    public native int getParameter(int soundModelHandle,
            @ModelParams int modelParam)
            throws UnsupportedOperationException, IllegalArgumentException;

    /**
     * Determine if parameter control is supported for the given model handle.
     * This method should be checked prior to calling {@link SoundTriggerModule#setParameter} or
     * {@link SoundTriggerModule#getParameter}.
     *
     * @param soundModelHandle handle of model to get parameter
     * @param modelParam {@link ModelParams}
     * @return supported range of parameter, null if not supported
     */
    @Nullable
    public native ModelParamRange queryParameter(int soundModelHandle, @ModelParams int modelParam);

    private class NativeEventHandlerDelegate {
        private final Handler mHandler;

Loading