diff options
| -rw-r--r-- | core/api/system-current.txt | 10 | ||||
| -rw-r--r-- | core/api/test-current.txt | 2 | ||||
| -rw-r--r-- | core/java/android/hardware/soundtrigger/SoundTrigger.java | 87 |
3 files changed, 98 insertions, 1 deletions
diff --git a/core/api/system-current.txt b/core/api/system-current.txt index bfddf4fb5fac..a1561c242027 100644 --- a/core/api/system-current.txt +++ b/core/api/system-current.txt @@ -6833,6 +6833,16 @@ package android.hardware.soundtrigger { field @NonNull public static final android.os.Parcelable.Creator<android.hardware.soundtrigger.SoundTrigger.RecognitionConfig> CREATOR; } + public static final class SoundTrigger.RecognitionConfig.Builder { + ctor public SoundTrigger.RecognitionConfig.Builder(); + method @NonNull public android.hardware.soundtrigger.SoundTrigger.RecognitionConfig build(); + method @NonNull public android.hardware.soundtrigger.SoundTrigger.RecognitionConfig.Builder setAllowMultipleTriggers(boolean); + method @NonNull public android.hardware.soundtrigger.SoundTrigger.RecognitionConfig.Builder setAudioCapabilities(int); + method @NonNull public android.hardware.soundtrigger.SoundTrigger.RecognitionConfig.Builder setCaptureRequested(boolean); + method @NonNull public android.hardware.soundtrigger.SoundTrigger.RecognitionConfig.Builder setData(@Nullable byte[]); + method @NonNull public android.hardware.soundtrigger.SoundTrigger.RecognitionConfig.Builder setKeyphrases(@NonNull java.util.Collection<android.hardware.soundtrigger.SoundTrigger.KeyphraseRecognitionExtra>); + } + public static class SoundTrigger.RecognitionEvent { method @Nullable public android.media.AudioFormat getCaptureFormat(); method public int getCaptureSession(); diff --git a/core/api/test-current.txt b/core/api/test-current.txt index cc9e8367dc3d..6511c214ee52 100644 --- a/core/api/test-current.txt +++ b/core/api/test-current.txt @@ -1887,7 +1887,7 @@ package android.hardware.soundtrigger { } @FlaggedApi("android.media.soundtrigger.manager_api") public static final class SoundTrigger.RecognitionConfig implements android.os.Parcelable { - ctor public SoundTrigger.RecognitionConfig(boolean, boolean, @Nullable android.hardware.soundtrigger.SoundTrigger.KeyphraseRecognitionExtra[], @Nullable byte[], int); + ctor @Deprecated public SoundTrigger.RecognitionConfig(boolean, boolean, @Nullable android.hardware.soundtrigger.SoundTrigger.KeyphraseRecognitionExtra[], @Nullable byte[], int); ctor public SoundTrigger.RecognitionConfig(boolean, boolean, @Nullable android.hardware.soundtrigger.SoundTrigger.KeyphraseRecognitionExtra[], @Nullable byte[]); } diff --git a/core/java/android/hardware/soundtrigger/SoundTrigger.java b/core/java/android/hardware/soundtrigger/SoundTrigger.java index 79cbd19b248d..05e91e447a43 100644 --- a/core/java/android/hardware/soundtrigger/SoundTrigger.java +++ b/core/java/android/hardware/soundtrigger/SoundTrigger.java @@ -1529,6 +1529,8 @@ public class SoundTrigger { * config that can be used by * {@link SoundTriggerModule#startRecognition(int, RecognitionConfig)} * + * @deprecated should use builder-based constructor instead. + * TODO(b/368042125): remove this method. * @param captureRequested Whether the DSP should capture the trigger sound. * @param allowMultipleTriggers Whether the service should restart listening after the DSP * triggers. @@ -1539,6 +1541,8 @@ public class SoundTrigger { * * @hide */ + @Deprecated + @SuppressWarnings("Todo") @TestApi public RecognitionConfig(boolean captureRequested, boolean allowMultipleTriggers, @SuppressLint("ArrayReturn") @Nullable KeyphraseRecognitionExtra[] keyphrases, @@ -1695,6 +1699,89 @@ public class SoundTrigger { result = prime * result + mAudioCapabilities; return result; } + + /** + * Builder class for {@link RecognitionConfig} objects. + */ + public static final class Builder { + private boolean mCaptureRequested; + private boolean mAllowMultipleTriggers; + @Nullable private KeyphraseRecognitionExtra[] mKeyphrases; + @Nullable private byte[] mData; + private int mAudioCapabilities; + + /** + * Constructs a new Builder with the default values. + */ + public Builder() { + } + + /** + * Sets capture requested state. + * @param captureRequested The new requested state. + * @return the same Builder instance. + */ + public @NonNull Builder setCaptureRequested(boolean captureRequested) { + mCaptureRequested = captureRequested; + return this; + } + + /** + * Sets allow multiple triggers state. + * @param allowMultipleTriggers The new allow multiple triggers state. + * @return the same Builder instance. + */ + public @NonNull Builder setAllowMultipleTriggers(boolean allowMultipleTriggers) { + mAllowMultipleTriggers = allowMultipleTriggers; + return this; + } + + /** + * Sets the keyphrases field. + * @param keyphrases The new keyphrases. + * @return the same Builder instance. + */ + public @NonNull Builder setKeyphrases( + @NonNull Collection<KeyphraseRecognitionExtra> keyphrases) { + mKeyphrases = keyphrases.toArray(new KeyphraseRecognitionExtra[keyphrases.size()]); + return this; + } + + /** + * Sets the data field. + * @param data The new data. + * @return the same Builder instance. + */ + public @NonNull Builder setData(@Nullable byte[] data) { + mData = data; + return this; + } + + /** + * Sets the audio capabilities field. + * @param audioCapabilities The new audio capabilities. + * @return the same Builder instance. + */ + public @NonNull Builder setAudioCapabilities(int audioCapabilities) { + mAudioCapabilities = audioCapabilities; + return this; + } + + /** + * Combines all of the parameters that have been set and return a new + * {@link RecognitionConfig} object. + * @return a new {@link RecognitionConfig} object + */ + public @NonNull RecognitionConfig build() { + RecognitionConfig config = new RecognitionConfig( + /* captureRequested= */ mCaptureRequested, + /* allowMultipleTriggers= */ mAllowMultipleTriggers, + /* keyphrases= */ mKeyphrases, + /* data= */ mData, + /* audioCapabilities= */ mAudioCapabilities); + return config; + } + }; } /** |