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

Commit 93c117c8 authored by Ytai Ben-Tsvi's avatar Ytai Ben-Tsvi
Browse files

Implement the soundtrigger_middlewware service

This service is intended to replace:
frameworks/av/include/soundtrigger/ISoundTriggerHwService.h

This change only adds the replacement service, follow up
changes migrate the clients to use the new service and remove
the old one. The new service is feature-equivalent to the new
one, but offers the following advantages:
- AIDL interface (as opposed to hand-written parceling code).
- Pure Java implementation all the way to the HAL.
- Better documentation.
- Rigorous error handling.
- Unit tests.
- Reduced code complexity (less layers, better separation of
  concerns).
- Permission-based security model (as opposed to some baked-in
  assumptions about process affinity).

Change-Id: I79f4eff105d3e6245990be068b933d4d48c35a0d
Bug: 142070343
parent 0b0441d1
Loading
Loading
Loading
Loading
+9 −0
Original line number Diff line number Diff line
@@ -4324,6 +4324,15 @@ public abstract class Context {
     */
    public static final String SOUND_TRIGGER_SERVICE = "soundtrigger";

    /**
     * Use with {@link #getSystemService(String)} to access the
     * {@link com.android.server.soundtrigger_middleware.SoundTriggerMiddlewareService}.
     *
     * @hide
     * @see #getSystemService(String)
     */
    public static final String SOUND_TRIGGER_MIDDLEWARE_SERVICE = "soundtrigger_middleware";

    /**
     * Official published name of the (internal) permission service.
     *
+2 −0
Original line number Diff line number Diff line
@@ -141,6 +141,8 @@ aidl_interface {
        "java/android/media/soundtrigger_middleware/ISoundTriggerCallback.aidl",
        "java/android/media/soundtrigger_middleware/ISoundTriggerMiddlewareService.aidl",
        "java/android/media/soundtrigger_middleware/ISoundTriggerModule.aidl",
        "java/android/media/soundtrigger_middleware/ModelParameter.aidl",
        "java/android/media/soundtrigger_middleware/ModelParameterRange.aidl",
        "java/android/media/soundtrigger_middleware/Phrase.aidl",
        "java/android/media/soundtrigger_middleware/PhraseRecognitionEvent.aidl",
        "java/android/media/soundtrigger_middleware/PhraseRecognitionExtra.aidl",
+43 −0
Original line number Diff line number Diff line
@@ -15,6 +15,8 @@
 */
package android.media.soundtrigger_middleware;

import android.media.soundtrigger_middleware.ModelParameter;
import android.media.soundtrigger_middleware.ModelParameterRange;
import android.media.soundtrigger_middleware.SoundModel;
import android.media.soundtrigger_middleware.PhraseSoundModel;
import android.media.soundtrigger_middleware.RecognitionConfig;
@@ -96,6 +98,47 @@ interface ISoundTriggerModule {
     */
    void forceRecognitionEvent(int modelHandle);

    /**
     * Set a model specific parameter 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.
     * It is expected to check if the handle supports the parameter via the
     * queryModelParameterSupport API prior to calling this method.
     *
     * @param modelHandle The sound model handle indicating which model to modify parameters
     * @param modelParam Parameter to set which will be validated against the
     *                   ModelParameter type.
     * @param value The value to set for the given model parameter
     */
    void setModelParameter(int modelHandle, ModelParameter modelParam, int value);

    /**
     * Get a model specific parameter. 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 ModelParameter for parameter default values.
     * It is expected to check if the handle supports the parameter via the
     * queryModelParameterSupport API prior to calling this method.
     *
     * @param modelHandle The sound model associated with given modelParam
     * @param modelParam Parameter to set which will be validated against the
     *                   ModelParameter type.
     * @return Value set to the requested parameter.
     */
    int getModelParameter(int modelHandle, ModelParameter modelParam);

    /**
     * Determine if parameter control is supported for the given model handle, and its valid value
     * range if it is.
     *
     * @param modelHandle The sound model handle indicating which model to query
     * @param modelParam Parameter to set which will be validated against the
     *                   ModelParameter type.
     * @return If parameter is supported, the return value is its valid range, otherwise null.
     */
    @nullable ModelParameterRange queryModelParameterSupport(int modelHandle,
                                                             ModelParameter modelParam);

    /**
     * Detach from the module, releasing any active resources.
     * This will ensure the client callback is no longer called after this call returns.
+38 −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.media.soundtrigger_middleware;

/**
 * Model specific parameters to be used with parameter set and get APIs.
 *
 * {@hide}
 */
@Backing(type="int")
enum ModelParameter {
    /**
     * 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,
}
+28 −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.media.soundtrigger_middleware;

/**
 * Value range for a model parameter.
 *
 * {@hide}
 */
parcelable ModelParameterRange {
    /** Minimum (inclusive) */
    int minInclusive;
    /** Maximum (inclusive) */
    int maxInclusive;
}
Loading