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

Commit 961db4b0 authored by Philip P. Moltmann's avatar Philip P. Moltmann Committed by android-build-merger
Browse files

Expose SoundTriggerManager and SoundTrigger APIs

am: a5fd0294

Change-Id: I71c2698aa282d33fb5468164b0b5bf90b28f8323
parents 32355d12 a5fd0294
Loading
Loading
Loading
Loading
+16 −0
Original line number Original line Diff line number Diff line
@@ -99,6 +99,7 @@ package android {
    field public static final java.lang.String MANAGE_CARRIER_OEM_UNLOCK_STATE = "android.permission.MANAGE_CARRIER_OEM_UNLOCK_STATE";
    field public static final java.lang.String MANAGE_CARRIER_OEM_UNLOCK_STATE = "android.permission.MANAGE_CARRIER_OEM_UNLOCK_STATE";
    field public static final java.lang.String MANAGE_CA_CERTIFICATES = "android.permission.MANAGE_CA_CERTIFICATES";
    field public static final java.lang.String MANAGE_CA_CERTIFICATES = "android.permission.MANAGE_CA_CERTIFICATES";
    field public static final java.lang.String MANAGE_DEVICE_ADMINS = "android.permission.MANAGE_DEVICE_ADMINS";
    field public static final java.lang.String MANAGE_DEVICE_ADMINS = "android.permission.MANAGE_DEVICE_ADMINS";
    field public static final java.lang.String MANAGE_SOUND_TRIGGER = "android.permission.MANAGE_SOUND_TRIGGER";
    field public static final java.lang.String MANAGE_SUBSCRIPTION_PLANS = "android.permission.MANAGE_SUBSCRIPTION_PLANS";
    field public static final java.lang.String MANAGE_SUBSCRIPTION_PLANS = "android.permission.MANAGE_SUBSCRIPTION_PLANS";
    field public static final java.lang.String MANAGE_USB = "android.permission.MANAGE_USB";
    field public static final java.lang.String MANAGE_USB = "android.permission.MANAGE_USB";
    field public static final java.lang.String MANAGE_USERS = "android.permission.MANAGE_USERS";
    field public static final java.lang.String MANAGE_USERS = "android.permission.MANAGE_USERS";
@@ -2222,6 +2223,21 @@ package android.hardware.radio {


}
}


package android.hardware.soundtrigger {

  public class SoundTrigger {
    field public static final int STATUS_OK = 0; // 0x0
  }

  public static class SoundTrigger.RecognitionEvent {
    method public android.media.AudioFormat getCaptureFormat();
    method public int getCaptureSession();
    method public byte[] getData();
    method public boolean isCaptureAvailable();
  }

}

package android.hardware.usb {
package android.hardware.usb {


  public class UsbDeviceConnection {
  public class UsbDeviceConnection {
+195 −32
Original line number Original line Diff line number Diff line
@@ -16,6 +16,14 @@


package android.hardware.soundtrigger;
package android.hardware.soundtrigger;


import static android.system.OsConstants.EINVAL;
import static android.system.OsConstants.ENODEV;
import static android.system.OsConstants.ENOSYS;
import static android.system.OsConstants.EPERM;
import static android.system.OsConstants.EPIPE;

import android.annotation.Nullable;
import android.annotation.SystemApi;
import android.media.AudioFormat;
import android.media.AudioFormat;
import android.os.Handler;
import android.os.Handler;
import android.os.Parcel;
import android.os.Parcel;
@@ -25,22 +33,33 @@ import java.util.ArrayList;
import java.util.Arrays;
import java.util.Arrays;
import java.util.UUID;
import java.util.UUID;


import static android.system.OsConstants.*;

/**
/**
 * The SoundTrigger class provides access via JNI to the native service managing
 * The SoundTrigger class provides access via JNI to the native service managing
 * the sound trigger HAL.
 * the sound trigger HAL.
 *
 *
 * @hide
 * @hide
 */
 */
@SystemApi
public class SoundTrigger {
public class SoundTrigger {


    private SoundTrigger() {
    }

    /**
     * Status code used when the operation succeeded
     */
    public static final int STATUS_OK = 0;
    public static final int STATUS_OK = 0;
    /** @hide */
    public static final int STATUS_ERROR = Integer.MIN_VALUE;
    public static final int STATUS_ERROR = Integer.MIN_VALUE;
    /** @hide */
    public static final int STATUS_PERMISSION_DENIED = -EPERM;
    public static final int STATUS_PERMISSION_DENIED = -EPERM;
    /** @hide */
    public static final int STATUS_NO_INIT = -ENODEV;
    public static final int STATUS_NO_INIT = -ENODEV;
    /** @hide */
    public static final int STATUS_BAD_VALUE = -EINVAL;
    public static final int STATUS_BAD_VALUE = -EINVAL;
    /** @hide */
    public static final int STATUS_DEAD_OBJECT = -EPIPE;
    public static final int STATUS_DEAD_OBJECT = -EPIPE;
    /** @hide */
    public static final int STATUS_INVALID_OPERATION = -ENOSYS;
    public static final int STATUS_INVALID_OPERATION = -ENOSYS;


    /*****************************************************************************
    /*****************************************************************************
@@ -48,6 +67,8 @@ public class SoundTrigger {
     * managed by the native sound trigger service. Each module has a unique
     * managed by the native sound trigger service. Each module has a unique
     * ID used to target any API call to this paricular module. Module
     * ID used to target any API call to this paricular module. Module
     * properties are returned by listModules() method.
     * properties are returned by listModules() method.
     *
     * @hide
     ****************************************************************************/
     ****************************************************************************/
    public static class ModuleProperties implements Parcelable {
    public static class ModuleProperties implements Parcelable {
        /** Unique module ID provided by the native service */
        /** Unique module ID provided by the native service */
@@ -187,6 +208,8 @@ public class SoundTrigger {
     * implementation to detect a particular sound pattern.
     * implementation to detect a particular sound pattern.
     * A specialized version {@link KeyphraseSoundModel} is defined for key phrase
     * A specialized version {@link KeyphraseSoundModel} is defined for key phrase
     * sound models.
     * sound models.
     *
     * @hide
     ****************************************************************************/
     ****************************************************************************/
    public static class SoundModel {
    public static class SoundModel {
        /** Undefined sound model type */
        /** Undefined sound model type */
@@ -261,6 +284,8 @@ public class SoundTrigger {
    /*****************************************************************************
    /*****************************************************************************
     * A Keyphrase describes a key phrase that can be detected by a
     * A Keyphrase describes a key phrase that can be detected by a
     * {@link KeyphraseSoundModel}
     * {@link KeyphraseSoundModel}
     *
     * @hide
     ****************************************************************************/
     ****************************************************************************/
    public static class Keyphrase implements Parcelable {
    public static class Keyphrase implements Parcelable {
        /** Unique identifier for this keyphrase */
        /** Unique identifier for this keyphrase */
@@ -382,6 +407,8 @@ public class SoundTrigger {
     * A KeyphraseSoundModel is a specialized {@link SoundModel} for key phrases.
     * A KeyphraseSoundModel is a specialized {@link SoundModel} for key phrases.
     * It contains data needed by the hardware to detect a certain number of key phrases
     * It contains data needed by the hardware to detect a certain number of key phrases
     * and the list of corresponding {@link Keyphrase} descriptors.
     * and the list of corresponding {@link Keyphrase} descriptors.
     *
     * @hide
     ****************************************************************************/
     ****************************************************************************/
    public static class KeyphraseSoundModel extends SoundModel implements Parcelable {
    public static class KeyphraseSoundModel extends SoundModel implements Parcelable {
        /** Key phrases in this sound model */
        /** Key phrases in this sound model */
@@ -468,6 +495,8 @@ public class SoundTrigger {
    /*****************************************************************************
    /*****************************************************************************
     * A GenericSoundModel is a specialized {@link SoundModel} for non-voice sound
     * A GenericSoundModel is a specialized {@link SoundModel} for non-voice sound
     * patterns.
     * patterns.
     *
     * @hide
     ****************************************************************************/
     ****************************************************************************/
    public static class GenericSoundModel extends SoundModel implements Parcelable {
    public static class GenericSoundModel extends SoundModel implements Parcelable {


@@ -524,52 +553,115 @@ public class SoundTrigger {
    /**
    /**
     *  Modes for key phrase recognition
     *  Modes for key phrase recognition
     */
     */
    /** Simple recognition of the key phrase */

    /**
     * Simple recognition of the key phrase
     *
     * @hide
     */
    public static final int RECOGNITION_MODE_VOICE_TRIGGER = 0x1;
    public static final int RECOGNITION_MODE_VOICE_TRIGGER = 0x1;
    /** Trigger only if one user is identified */
    /**
     * Trigger only if one user is identified
     *
     * @hide
     */
    public static final int RECOGNITION_MODE_USER_IDENTIFICATION = 0x2;
    public static final int RECOGNITION_MODE_USER_IDENTIFICATION = 0x2;
    /** Trigger only if one user is authenticated */
    /**
     * Trigger only if one user is authenticated
     *
     * @hide
     */
    public static final int RECOGNITION_MODE_USER_AUTHENTICATION = 0x4;
    public static final int RECOGNITION_MODE_USER_AUTHENTICATION = 0x4;


    /**
    /**
     *  Status codes for {@link RecognitionEvent}
     *  Status codes for {@link RecognitionEvent}
     */
     */
    /** Recognition success */
    /**
     * Recognition success
     *
     * @hide
     */
    public static final int RECOGNITION_STATUS_SUCCESS = 0;
    public static final int RECOGNITION_STATUS_SUCCESS = 0;
    /** Recognition aborted (e.g. capture preempted by anotehr use case */
    /**
     * Recognition aborted (e.g. capture preempted by anotehr use case
     *
     * @hide
     */
    public static final int RECOGNITION_STATUS_ABORT = 1;
    public static final int RECOGNITION_STATUS_ABORT = 1;
    /** Recognition failure */
    /**
     * Recognition failure
     *
     * @hide
     */
    public static final int RECOGNITION_STATUS_FAILURE = 2;
    public static final int RECOGNITION_STATUS_FAILURE = 2;


    /**
    /**
     *  A RecognitionEvent is provided by the
     *  A RecognitionEvent is provided by the
     *  {@link StatusListener#onRecognition(RecognitionEvent)}
     *  {@code StatusListener#onRecognition(RecognitionEvent)}
     *  callback upon recognition success or failure.
     *  callback upon recognition success or failure.
     */
     */
    public static class RecognitionEvent implements Parcelable {
    public static class RecognitionEvent {
        /** Recognition status e.g {@link #RECOGNITION_STATUS_SUCCESS} */
        /**
         * Recognition status e.g RECOGNITION_STATUS_SUCCESS
         *
         * @hide
         */
        public final int status;
        public final int status;
        /** Sound Model corresponding to this event callback */
        /**
         *
         * Sound Model corresponding to this event callback
         *
         * @hide
         */
        public final int soundModelHandle;
        public final int soundModelHandle;
        /** True if it is possible to capture audio from this utterance buffered by the hardware */
        /**
         * True if it is possible to capture audio from this utterance buffered by the hardware
         *
         * @hide
         */
        public final boolean captureAvailable;
        public final boolean captureAvailable;
        /** Audio session ID to be used when capturing the utterance with an AudioRecord
        /**
         * if captureAvailable() is true. */
         * Audio session ID to be used when capturing the utterance with an AudioRecord
         * if captureAvailable() is true.
         *
         * @hide
         */
        public final int captureSession;
        public final int captureSession;
        /** Delay in ms between end of model detection and start of audio available for capture.
        /**
         * A negative value is possible (e.g. if keyphrase is also available for capture) */
         * Delay in ms between end of model detection and start of audio available for capture.
         * A negative value is possible (e.g. if keyphrase is also available for capture)
         *
         * @hide
         */
        public final int captureDelayMs;
        public final int captureDelayMs;
        /** Duration in ms of audio captured before the start of the trigger. 0 if none. */
        /**
         * Duration in ms of audio captured before the start of the trigger. 0 if none.
         *
         * @hide
         */
        public final int capturePreambleMs;
        public final int capturePreambleMs;
        /** True if  the trigger (key phrase capture is present in binary data */
        /**
         * True if  the trigger (key phrase capture is present in binary data
         *
         * @hide
         */
        public final boolean triggerInData;
        public final boolean triggerInData;
        /** Audio format of either the trigger in event data or to use for capture of the
        /**
          * rest of the utterance */
         * Audio format of either the trigger in event data or to use for capture of the
        public AudioFormat captureFormat;
         * rest of the utterance
        /** Opaque data for use by system applications who know about voice engine internals,
         *
         * typically during enrollment. */
         * @hide
         */
        public final AudioFormat captureFormat;
        /**
         * Opaque data for use by system applications who know about voice engine internals,
         * typically during enrollment.
         *
         * @hide
         */
        public final byte[] data;
        public final byte[] data;


        /** @hide */
        public RecognitionEvent(int status, int soundModelHandle, boolean captureAvailable,
        public RecognitionEvent(int status, int soundModelHandle, boolean captureAvailable,
                int captureSession, int captureDelayMs, int capturePreambleMs,
                int captureSession, int captureDelayMs, int capturePreambleMs,
                boolean triggerInData, AudioFormat captureFormat, byte[] data) {
                boolean triggerInData, AudioFormat captureFormat, byte[] data) {
@@ -584,6 +676,46 @@ public class SoundTrigger {
            this.data = data;
            this.data = data;
        }
        }


        /**
         * Check if is possible to capture audio from this utterance buffered by the hardware.
         *
         * @return {@code true} iff a capturing is possible
         */
        public boolean isCaptureAvailable() {
            return captureAvailable;
        }

        /**
         * Get the audio format of either the trigger in event data or to use for capture of the
         * rest of the utterance
         *
         * @return the audio format
         */
        @Nullable public AudioFormat getCaptureFormat() {
            return captureFormat;
        }

        /**
         * Get Audio session ID to be used when capturing the utterance with an {@link AudioRecord}
         * if {@link #isCaptureAvailable()} is true.
         *
         * @return The id of the capture session
         */
        public int getCaptureSession() {
            return captureSession;
        }

        /**
         * Get the opaque data for use by system applications who know about voice engine
         * internals, typically during enrollment.
         *
         * @return The data of the event
         */
        public byte[] getData() {
            return data;
        }

        /** @hide */
        public static final Parcelable.Creator<RecognitionEvent> CREATOR
        public static final Parcelable.Creator<RecognitionEvent> CREATOR
                = new Parcelable.Creator<RecognitionEvent>() {
                = new Parcelable.Creator<RecognitionEvent>() {
            public RecognitionEvent createFromParcel(Parcel in) {
            public RecognitionEvent createFromParcel(Parcel in) {
@@ -595,6 +727,7 @@ public class SoundTrigger {
            }
            }
        };
        };


        /** @hide */
        protected static RecognitionEvent fromParcel(Parcel in) {
        protected static RecognitionEvent fromParcel(Parcel in) {
            int status = in.readInt();
            int status = in.readInt();
            int soundModelHandle = in.readInt();
            int soundModelHandle = in.readInt();
@@ -619,12 +752,12 @@ public class SoundTrigger {
                    captureDelayMs, capturePreambleMs, triggerInData, captureFormat, data);
                    captureDelayMs, capturePreambleMs, triggerInData, captureFormat, data);
        }
        }


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


        @Override
        /** @hide */
        public void writeToParcel(Parcel dest, int flags) {
        public void writeToParcel(Parcel dest, int flags) {
            dest.writeInt(status);
            dest.writeInt(status);
            dest.writeInt(soundModelHandle);
            dest.writeInt(soundModelHandle);
@@ -726,6 +859,8 @@ public class SoundTrigger {
     *  A RecognitionConfig is provided to
     *  A RecognitionConfig is provided to
     *  {@link SoundTriggerModule#startRecognition(int, RecognitionConfig)} to configure the
     *  {@link SoundTriggerModule#startRecognition(int, RecognitionConfig)} to configure the
     *  recognition request.
     *  recognition request.
     *
     *  @hide
     */
     */
    public static class RecognitionConfig implements Parcelable {
    public static class RecognitionConfig implements Parcelable {
        /** True if the DSP should capture the trigger sound and make it available for further
        /** True if the DSP should capture the trigger sound and make it available for further
@@ -744,7 +879,7 @@ public class SoundTrigger {
        public final byte[] data;
        public final byte[] data;


        public RecognitionConfig(boolean captureRequested, boolean allowMultipleTriggers,
        public RecognitionConfig(boolean captureRequested, boolean allowMultipleTriggers,
                KeyphraseRecognitionExtra keyphrases[], byte[] data) {
                KeyphraseRecognitionExtra[] keyphrases, byte[] data) {
            this.captureRequested = captureRequested;
            this.captureRequested = captureRequested;
            this.allowMultipleTriggers = allowMultipleTriggers;
            this.allowMultipleTriggers = allowMultipleTriggers;
            this.keyphrases = keyphrases;
            this.keyphrases = keyphrases;
@@ -799,6 +934,8 @@ public class SoundTrigger {
     * When used in a {@link RecognitionConfig} it indicates the minimum confidence level that
     * When used in a {@link RecognitionConfig} it indicates the minimum confidence level that
     * should trigger a recognition.
     * should trigger a recognition.
     * - The user ID is derived from the system ID {@link android.os.UserHandle#getIdentifier()}.
     * - The user ID is derived from the system ID {@link android.os.UserHandle#getIdentifier()}.
     *
     * @hide
     */
     */
    public static class ConfidenceLevel implements Parcelable {
    public static class ConfidenceLevel implements Parcelable {
        public final int userId;
        public final int userId;
@@ -872,6 +1009,8 @@ public class SoundTrigger {
    /**
    /**
     *  Additional data conveyed by a {@link KeyphraseRecognitionEvent}
     *  Additional data conveyed by a {@link KeyphraseRecognitionEvent}
     *  for a key phrase detection.
     *  for a key phrase detection.
     *
     * @hide
     */
     */
    public static class KeyphraseRecognitionExtra implements Parcelable {
    public static class KeyphraseRecognitionExtra implements Parcelable {
        /** The keyphrase ID */
        /** The keyphrase ID */
@@ -970,8 +1109,10 @@ public class SoundTrigger {


    /**
    /**
     *  Specialized {@link RecognitionEvent} for a key phrase detection.
     *  Specialized {@link RecognitionEvent} for a key phrase detection.
     *
     *  @hide
     */
     */
    public static class KeyphraseRecognitionEvent extends RecognitionEvent {
    public static class KeyphraseRecognitionEvent extends RecognitionEvent implements Parcelable {
        /** Indicates if the key phrase is present in the buffered audio available for capture */
        /** Indicates if the key phrase is present in the buffered audio available for capture */
        public final KeyphraseRecognitionExtra[] keyphraseExtras;
        public final KeyphraseRecognitionExtra[] keyphraseExtras;


@@ -1091,8 +1232,10 @@ public class SoundTrigger {
    /**
    /**
     * Sub-class of RecognitionEvent specifically for sound-trigger based sound
     * Sub-class of RecognitionEvent specifically for sound-trigger based sound
     * models(non-keyphrase). Currently does not contain any additional fields.
     * models(non-keyphrase). Currently does not contain any additional fields.
     *
     * @hide
     */
     */
    public static class GenericRecognitionEvent extends RecognitionEvent {
    public static class GenericRecognitionEvent extends RecognitionEvent implements Parcelable {
        public GenericRecognitionEvent(int status, int soundModelHandle,
        public GenericRecognitionEvent(int status, int soundModelHandle,
                boolean captureAvailable, int captureSession, int captureDelayMs,
                boolean captureAvailable, int captureSession, int captureDelayMs,
                int capturePreambleMs, boolean triggerInData, AudioFormat captureFormat,
                int capturePreambleMs, boolean triggerInData, AudioFormat captureFormat,
@@ -1140,13 +1283,19 @@ public class SoundTrigger {
    /**
    /**
     *  Status codes for {@link SoundModelEvent}
     *  Status codes for {@link SoundModelEvent}
     */
     */
    /** Sound Model was updated */
    /**
     * Sound Model was updated
     *
     * @hide
     */
    public static final int SOUNDMODEL_STATUS_UPDATED = 0;
    public static final int SOUNDMODEL_STATUS_UPDATED = 0;


    /**
    /**
     *  A SoundModelEvent is provided by the
     *  A SoundModelEvent is provided by the
     *  {@link StatusListener#onSoundModelUpdate(SoundModelEvent)}
     *  {@link StatusListener#onSoundModelUpdate(SoundModelEvent)}
     *  callback when a sound model has been updated by the implementation
     *  callback when a sound model has been updated by the implementation
     *
     *  @hide
     */
     */
    public static class SoundModelEvent implements Parcelable {
    public static class SoundModelEvent implements Parcelable {
        /** Status e.g {@link #SOUNDMODEL_STATUS_UPDATED} */
        /** Status e.g {@link #SOUNDMODEL_STATUS_UPDATED} */
@@ -1231,9 +1380,17 @@ public class SoundTrigger {
     *  Native service state. {@link StatusListener#onServiceStateChange(int)}
     *  Native service state. {@link StatusListener#onServiceStateChange(int)}
     */
     */
    // Keep in sync with system/core/include/system/sound_trigger.h
    // Keep in sync with system/core/include/system/sound_trigger.h
    /** Sound trigger service is enabled */
    /**
     * Sound trigger service is enabled
     *
     * @hide
     */
    public static final int SERVICE_STATE_ENABLED = 0;
    public static final int SERVICE_STATE_ENABLED = 0;
    /** Sound trigger service is disabled */
    /**
     * Sound trigger service is disabled
     *
     * @hide
     */
    public static final int SERVICE_STATE_DISABLED = 1;
    public static final int SERVICE_STATE_DISABLED = 1;


    /**
    /**
@@ -1245,6 +1402,8 @@ public class SoundTrigger {
     *         - {@link #STATUS_NO_INIT} if the native service cannot be reached
     *         - {@link #STATUS_NO_INIT} if the native service cannot be reached
     *         - {@link #STATUS_BAD_VALUE} if modules is null
     *         - {@link #STATUS_BAD_VALUE} if modules is null
     *         - {@link #STATUS_DEAD_OBJECT} if the binder transaction to the native service fails
     *         - {@link #STATUS_DEAD_OBJECT} if the binder transaction to the native service fails
     *
     * @hide
     */
     */
    public static native int listModules(ArrayList <ModuleProperties> modules);
    public static native int listModules(ArrayList <ModuleProperties> modules);


@@ -1256,6 +1415,8 @@ public class SoundTrigger {
     * @param handler the Handler that will receive the callabcks. Can be null if default handler
     * @param handler the Handler that will receive the callabcks. Can be null if default handler
     *                is OK.
     *                is OK.
     * @return a valid sound module in case of success or null in case of error.
     * @return a valid sound module in case of success or null in case of error.
     *
     * @hide
     */
     */
    public static SoundTriggerModule attachModule(int moduleId,
    public static SoundTriggerModule attachModule(int moduleId,
                                                  StatusListener listener,
                                                  StatusListener listener,
@@ -1270,6 +1431,8 @@ public class SoundTrigger {
    /**
    /**
     * Interface provided by the client application when attaching to a {@link SoundTriggerModule}
     * Interface provided by the client application when attaching to a {@link SoundTriggerModule}
     * to received recognition and error notifications.
     * to received recognition and error notifications.
     *
     * @hide
     */
     */
    public static interface StatusListener {
    public static interface StatusListener {
        /**
        /**
+2 −1
Original line number Original line Diff line number Diff line
@@ -3754,7 +3754,8 @@


    <!-- Must be required by system/priv apps when accessing the sound trigger
    <!-- Must be required by system/priv apps when accessing the sound trigger
         APIs given by {@link SoundTriggerManager}.
         APIs given by {@link SoundTriggerManager}.
         @hide <p>Not for use by third-party applications.</p> -->
         @hide
         @SystemApi -->
    <permission android:name="android.permission.MANAGE_SOUND_TRIGGER"
    <permission android:name="android.permission.MANAGE_SOUND_TRIGGER"
        android:protectionLevel="signature|privileged" />
        android:protectionLevel="signature|privileged" />