diff options
author | Nicholas Ambur <nambur@google.com> | 2020-03-27 20:54:22 +0000 |
---|---|---|
committer | Android (Google) Code Review <android-gerrit@google.com> | 2020-03-27 20:54:22 +0000 |
commit | 95ee3d7ad55dd46583eb0b4531b904f8bae88992 (patch) | |
tree | cb10a3f9df18738f0c98c00de298a286f7d25b7a | |
parent | 4bb11f7b63edaea028f46423d9230ed405880afe (diff) | |
parent | 1e43767f10f8a3d6dc25cc9960554372a1a22a3a (diff) |
Merge "remove SoundTrigger public member variables" into rvc-dev
15 files changed, 472 insertions, 354 deletions
diff --git a/api/system-current.txt b/api/system-current.txt index 156d81e7ba2a..caa74bfb74f5 100755 --- a/api/system-current.txt +++ b/api/system-current.txt @@ -3575,23 +3575,23 @@ package android.hardware.soundtrigger { public static final class SoundTrigger.Keyphrase implements android.os.Parcelable { ctor public SoundTrigger.Keyphrase(int, int, @NonNull java.util.Locale, @NonNull String, @Nullable int[]); + method public int getId(); + method @NonNull public java.util.Locale getLocale(); + method public int getRecognitionModes(); + method @NonNull public String getText(); + method @NonNull public int[] getUsers(); method @NonNull public static android.hardware.soundtrigger.SoundTrigger.Keyphrase readFromParcel(@NonNull android.os.Parcel); method public void writeToParcel(@NonNull android.os.Parcel, int); field @NonNull public static final android.os.Parcelable.Creator<android.hardware.soundtrigger.SoundTrigger.Keyphrase> CREATOR; - field public final int id; - field @NonNull public final java.util.Locale locale; - field public final int recognitionModes; - field @NonNull public final String text; - field @NonNull public final int[] users; } public static final class SoundTrigger.KeyphraseSoundModel extends android.hardware.soundtrigger.SoundTrigger.SoundModel implements android.os.Parcelable { ctor public SoundTrigger.KeyphraseSoundModel(@NonNull java.util.UUID, @NonNull java.util.UUID, @Nullable byte[], @Nullable android.hardware.soundtrigger.SoundTrigger.Keyphrase[], int); ctor public SoundTrigger.KeyphraseSoundModel(@NonNull java.util.UUID, @NonNull java.util.UUID, @Nullable byte[], @Nullable android.hardware.soundtrigger.SoundTrigger.Keyphrase[]); + method @NonNull public android.hardware.soundtrigger.SoundTrigger.Keyphrase[] getKeyphrases(); method @NonNull public static android.hardware.soundtrigger.SoundTrigger.KeyphraseSoundModel readFromParcel(@NonNull android.os.Parcel); method public void writeToParcel(@NonNull android.os.Parcel, int); field @NonNull public static final android.os.Parcelable.Creator<android.hardware.soundtrigger.SoundTrigger.KeyphraseSoundModel> CREATOR; - field @NonNull public final android.hardware.soundtrigger.SoundTrigger.Keyphrase[] keyphrases; } public static final class SoundTrigger.ModelParamRange implements android.os.Parcelable { @@ -3603,26 +3603,26 @@ package android.hardware.soundtrigger { public static final class SoundTrigger.ModuleProperties implements android.os.Parcelable { method public int describeContents(); + method public int getAudioCapabilities(); + method @NonNull public String getDescription(); + method public int getId(); + method @NonNull public String getImplementor(); + method public int getMaxBufferMillis(); + method public int getMaxKeyphrases(); + method public int getMaxSoundModels(); + method public int getMaxUsers(); + method public int getPowerConsumptionMw(); + method public int getRecognitionModes(); + method @NonNull public String getSupportedModelArch(); + method @NonNull public java.util.UUID getUuid(); + method public int getVersion(); + method public boolean isCaptureTransitionSupported(); + method public boolean isConcurrentCaptureSupported(); + method public boolean isTriggerReturnedInEvent(); method public void writeToParcel(android.os.Parcel, int); field public static final int AUDIO_CAPABILITY_ECHO_CANCELLATION = 1; // 0x1 field public static final int AUDIO_CAPABILITY_NOISE_SUPPRESSION = 2; // 0x2 field @NonNull public static final android.os.Parcelable.Creator<android.hardware.soundtrigger.SoundTrigger.ModuleProperties> CREATOR; - field public final int audioCapabilities; - field @NonNull public final String description; - field public final int id; - field @NonNull public final String implementor; - field public final int maxBufferMs; - field public final int maxKeyphrases; - field public final int maxSoundModels; - field public final int maxUsers; - field public final int powerConsumptionMw; - field public final int recognitionModes; - field public final boolean returnsTriggerInEvent; - field @NonNull public final String supportedModelArch; - field public final boolean supportsCaptureTransition; - field public final boolean supportsConcurrentCapture; - field @NonNull public final java.util.UUID uuid; - field public final int version; } public static class SoundTrigger.RecognitionEvent { @@ -3633,13 +3633,13 @@ package android.hardware.soundtrigger { } public static class SoundTrigger.SoundModel { + method @NonNull public byte[] getData(); + method public int getType(); + method @NonNull public java.util.UUID getUuid(); + method @NonNull public java.util.UUID getVendorUuid(); + method public int getVersion(); field public static final int TYPE_GENERIC_SOUND = 1; // 0x1 field public static final int TYPE_KEYPHRASE = 0; // 0x0 - field @NonNull public final byte[] data; - field public final int type; - field @NonNull public final java.util.UUID uuid; - field @NonNull public final java.util.UUID vendorUuid; - field public final int version; } } diff --git a/core/java/android/hardware/soundtrigger/ConversionUtil.java b/core/java/android/hardware/soundtrigger/ConversionUtil.java index 3d763e630bd0..425218a63cf7 100644 --- a/core/java/android/hardware/soundtrigger/ConversionUtil.java +++ b/core/java/android/hardware/soundtrigger/ConversionUtil.java @@ -106,11 +106,11 @@ class ConversionUtil { public static SoundModel api2aidlSoundModel(SoundTrigger.SoundModel apiModel) { SoundModel aidlModel = new SoundModel(); - aidlModel.type = apiModel.type; - aidlModel.uuid = api2aidlUuid(apiModel.uuid); - aidlModel.vendorUuid = api2aidlUuid(apiModel.vendorUuid); - aidlModel.data = byteArrayToSharedMemory(apiModel.data, "SoundTrigger SoundModel"); - aidlModel.dataSize = apiModel.data.length; + aidlModel.type = apiModel.getType(); + aidlModel.uuid = api2aidlUuid(apiModel.getUuid()); + aidlModel.vendorUuid = api2aidlUuid(apiModel.getVendorUuid()); + aidlModel.data = byteArrayToSharedMemory(apiModel.getData(), "SoundTrigger SoundModel"); + aidlModel.dataSize = apiModel.getData().length; return aidlModel; } @@ -122,20 +122,20 @@ class ConversionUtil { SoundTrigger.KeyphraseSoundModel apiModel) { PhraseSoundModel aidlModel = new PhraseSoundModel(); aidlModel.common = api2aidlSoundModel(apiModel); - aidlModel.phrases = new Phrase[apiModel.keyphrases.length]; - for (int i = 0; i < apiModel.keyphrases.length; ++i) { - aidlModel.phrases[i] = api2aidlPhrase(apiModel.keyphrases[i]); + aidlModel.phrases = new Phrase[apiModel.getKeyphrases().length]; + for (int i = 0; i < apiModel.getKeyphrases().length; ++i) { + aidlModel.phrases[i] = api2aidlPhrase(apiModel.getKeyphrases()[i]); } return aidlModel; } public static Phrase api2aidlPhrase(SoundTrigger.Keyphrase apiPhrase) { Phrase aidlPhrase = new Phrase(); - aidlPhrase.id = apiPhrase.id; - aidlPhrase.recognitionModes = api2aidlRecognitionModes(apiPhrase.recognitionModes); - aidlPhrase.users = Arrays.copyOf(apiPhrase.users, apiPhrase.users.length); - aidlPhrase.locale = apiPhrase.locale.toLanguageTag(); - aidlPhrase.text = apiPhrase.text; + aidlPhrase.id = apiPhrase.getId(); + aidlPhrase.recognitionModes = api2aidlRecognitionModes(apiPhrase.getRecognitionModes()); + aidlPhrase.users = Arrays.copyOf(apiPhrase.getUsers(), apiPhrase.getUsers().length); + aidlPhrase.locale = apiPhrase.getLocale().toLanguageTag(); + aidlPhrase.text = apiPhrase.getText(); return aidlPhrase; } diff --git a/core/java/android/hardware/soundtrigger/SoundTrigger.java b/core/java/android/hardware/soundtrigger/SoundTrigger.java index a74871d29041..98c4f618be18 100644 --- a/core/java/android/hardware/soundtrigger/SoundTrigger.java +++ b/core/java/android/hardware/soundtrigger/SoundTrigger.java @@ -104,32 +104,89 @@ public class SoundTrigger { /** * If set the underlying module supports AEC. - * Describes bit field {@link ModuleProperties#audioCapabilities} + * Describes bit field {@link ModuleProperties#mAudioCapabilities} */ public static final int AUDIO_CAPABILITY_ECHO_CANCELLATION = 0x1; /** * If set, the underlying module supports noise suppression. - * Describes bit field {@link ModuleProperties#audioCapabilities} + * Describes bit field {@link ModuleProperties#mAudioCapabilities} */ public static final int AUDIO_CAPABILITY_NOISE_SUPPRESSION = 0x2; + private final int mId; + @NonNull + private final String mImplementor; + @NonNull + private final String mDescription; + @NonNull + private final UUID mUuid; + private final int mVersion; + @NonNull + private final String mSupportedModelArch; + private final int mMaxSoundModels; + private final int mMaxKeyphrases; + private final int mMaxUsers; + @RecognitionModes + private final int mRecognitionModes; + private final boolean mSupportsCaptureTransition; + private final int mMaxBufferMillis; + private final boolean mSupportsConcurrentCapture; + private final int mPowerConsumptionMw; + private final boolean mReturnsTriggerInEvent; + @AudioCapabilities + private final int mAudioCapabilities; + + ModuleProperties(int id, @NonNull String implementor, @NonNull String description, + @NonNull String uuid, int version, @NonNull String supportedModelArch, + int maxSoundModels, int maxKeyphrases, int maxUsers, + @RecognitionModes int recognitionModes, boolean supportsCaptureTransition, + int maxBufferMs, boolean supportsConcurrentCapture, int powerConsumptionMw, + boolean returnsTriggerInEvent, int audioCapabilities) { + this.mId = id; + this.mImplementor = requireNonNull(implementor); + this.mDescription = requireNonNull(description); + this.mUuid = UUID.fromString(requireNonNull(uuid)); + this.mVersion = version; + this.mSupportedModelArch = requireNonNull(supportedModelArch); + this.mMaxSoundModels = maxSoundModels; + this.mMaxKeyphrases = maxKeyphrases; + this.mMaxUsers = maxUsers; + this.mRecognitionModes = recognitionModes; + this.mSupportsCaptureTransition = supportsCaptureTransition; + this.mMaxBufferMillis = maxBufferMs; + this.mSupportsConcurrentCapture = supportsConcurrentCapture; + this.mPowerConsumptionMw = powerConsumptionMw; + this.mReturnsTriggerInEvent = returnsTriggerInEvent; + this.mAudioCapabilities = audioCapabilities; + } + /** Unique module ID provided by the native service */ - public final int id; + public int getId() { + return mId; + } /** human readable voice detection engine implementor */ @NonNull - public final String implementor; + public String getImplementor() { + return mImplementor; + } /** human readable voice detection engine description */ @NonNull - public final String description; + public String getDescription() { + return mDescription; + } /** Unique voice engine Id (changes with each version) */ @NonNull - public final UUID uuid; + public UUID getUuid() { + return mUuid; + } /** Voice detection engine version */ - public final int version; + public int getVersion() { + return mVersion; + } /** * String naming the architecture used for running the supported models. @@ -137,66 +194,64 @@ public class SoundTrigger { * architecture used) */ @NonNull - public final String supportedModelArch; + public String getSupportedModelArch() { + return mSupportedModelArch; + } /** Maximum number of active sound models */ - public final int maxSoundModels; + public int getMaxSoundModels() { + return mMaxSoundModels; + } /** Maximum number of key phrases */ - public final int maxKeyphrases; + public int getMaxKeyphrases() { + return mMaxKeyphrases; + } /** Maximum number of users per key phrase */ - public final int maxUsers; + public int getMaxUsers() { + return mMaxUsers; + } /** Supported recognition modes (bit field, RECOGNITION_MODE_VOICE_TRIGGER ...) */ @RecognitionModes - public final int recognitionModes; + public int getRecognitionModes() { + return mRecognitionModes; + } /** Supports seamless transition to capture mode after recognition */ - public final boolean supportsCaptureTransition; + public boolean isCaptureTransitionSupported() { + return mSupportsCaptureTransition; + } /** Maximum buffering capacity in ms if supportsCaptureTransition() is true */ - public final int maxBufferMs; + public int getMaxBufferMillis() { + return mMaxBufferMillis; + } /** Supports capture by other use cases while detection is active */ - public final boolean supportsConcurrentCapture; + public boolean isConcurrentCaptureSupported() { + return mSupportsConcurrentCapture; + } /** Rated power consumption when detection is active with TDB silence/sound/speech ratio */ - public final int powerConsumptionMw; + public int getPowerConsumptionMw() { + return mPowerConsumptionMw; + } /** Returns the trigger (key phrase) capture in the binary data of the * recognition callback event */ - public final boolean returnsTriggerInEvent; + public boolean isTriggerReturnedInEvent() { + return mReturnsTriggerInEvent; + } /** * Bit field encoding of the AudioCapabilities * supported by the firmware. */ @AudioCapabilities - public final int audioCapabilities; - - ModuleProperties(int id, @NonNull String implementor, @NonNull String description, - @NonNull String uuid, int version, @NonNull String supportedModelArch, - int maxSoundModels, int maxKeyphrases, int maxUsers, - @RecognitionModes int recognitionModes, boolean supportsCaptureTransition, - int maxBufferMs, boolean supportsConcurrentCapture, int powerConsumptionMw, - boolean returnsTriggerInEvent, int audioCapabilities) { - this.id = id; - this.implementor = requireNonNull(implementor); - this.description = requireNonNull(description); - this.uuid = UUID.fromString(requireNonNull(uuid)); - this.version = version; - this.supportedModelArch = requireNonNull(supportedModelArch); - this.maxSoundModels = maxSoundModels; - this.maxKeyphrases = maxKeyphrases; - this.maxUsers = maxUsers; - this.recognitionModes = recognitionModes; - this.supportsCaptureTransition = supportsCaptureTransition; - this.maxBufferMs = maxBufferMs; - this.supportsConcurrentCapture = supportsConcurrentCapture; - this.powerConsumptionMw = powerConsumptionMw; - this.returnsTriggerInEvent = returnsTriggerInEvent; - this.audioCapabilities = audioCapabilities; + public int getAudioCapabilities() { + return mAudioCapabilities; } public static final @android.annotation.NonNull Parcelable.Creator<ModuleProperties> CREATOR @@ -235,22 +290,22 @@ public class SoundTrigger { @Override public void writeToParcel(Parcel dest, int flags) { - dest.writeInt(id); - dest.writeString(implementor); - dest.writeString(description); - dest.writeString(uuid.toString()); - dest.writeInt(version); - dest.writeString(supportedModelArch); - dest.writeInt(maxSoundModels); - dest.writeInt(maxKeyphrases); - dest.writeInt(maxUsers); - dest.writeInt(recognitionModes); - dest.writeByte((byte) (supportsCaptureTransition ? 1 : 0)); - dest.writeInt(maxBufferMs); - dest.writeByte((byte) (supportsConcurrentCapture ? 1 : 0)); - dest.writeInt(powerConsumptionMw); - dest.writeByte((byte) (returnsTriggerInEvent ? 1 : 0)); - dest.writeInt(audioCapabilities); + dest.writeInt(getId()); + dest.writeString(getImplementor()); + dest.writeString(getDescription()); + dest.writeString(getUuid().toString()); + dest.writeInt(getVersion()); + dest.writeString(getSupportedModelArch()); + dest.writeInt(getMaxSoundModels()); + dest.writeInt(getMaxKeyphrases()); + dest.writeInt(getMaxUsers()); + dest.writeInt(getRecognitionModes()); + dest.writeByte((byte) (isCaptureTransitionSupported() ? 1 : 0)); + dest.writeInt(getMaxBufferMillis()); + dest.writeByte((byte) (isConcurrentCaptureSupported() ? 1 : 0)); + dest.writeInt(getPowerConsumptionMw()); + dest.writeByte((byte) (isTriggerReturnedInEvent() ? 1 : 0)); + dest.writeInt(getAudioCapabilities()); } @Override @@ -260,16 +315,17 @@ public class SoundTrigger { @Override public String toString() { - return "ModuleProperties [id=" + id + ", implementor=" + implementor + ", description=" - + description + ", uuid=" + uuid + ", version=" + version - + " , supportedModelArch=" + supportedModelArch + ", maxSoundModels=" - + maxSoundModels + ", maxKeyphrases=" + maxKeyphrases + ", maxUsers=" - + maxUsers + ", recognitionModes=" + recognitionModes - + ", supportsCaptureTransition=" + supportsCaptureTransition + ", maxBufferMs=" - + maxBufferMs + ", supportsConcurrentCapture=" + supportsConcurrentCapture - + ", powerConsumptionMw=" + powerConsumptionMw - + ", returnsTriggerInEvent=" + returnsTriggerInEvent - + ", audioCapabilities=" + audioCapabilities + "]"; + return "ModuleProperties [id=" + getId() + ", implementor=" + getImplementor() + + ", description=" + getDescription() + ", uuid=" + getUuid() + + ", version=" + getVersion() + " , supportedModelArch=" + + getSupportedModelArch() + ", maxSoundModels=" + getMaxSoundModels() + + ", maxKeyphrases=" + getMaxKeyphrases() + ", maxUsers=" + getMaxUsers() + + ", recognitionModes=" + getRecognitionModes() + ", supportsCaptureTransition=" + + isCaptureTransitionSupported() + ", maxBufferMs=" + getMaxBufferMillis() + + ", supportsConcurrentCapture=" + isConcurrentCaptureSupported() + + ", powerConsumptionMw=" + getPowerConsumptionMw() + + ", returnsTriggerInEvent=" + isTriggerReturnedInEvent() + + ", audioCapabilities=" + getAudioCapabilities() + "]"; } } @@ -305,44 +361,64 @@ public class SoundTrigger { */ public static final int TYPE_GENERIC_SOUND = 1; + @NonNull + private final UUID mUuid; + @SoundModelType + private final int mType; + @NonNull + private final UUID mVendorUuid; + private final int mVersion; + @NonNull + private final byte[] mData; + + /** @hide */ + public SoundModel(@NonNull UUID uuid, @Nullable UUID vendorUuid, @SoundModelType int type, + @Nullable byte[] data, int version) { + this.mUuid = requireNonNull(uuid); + this.mVendorUuid = vendorUuid != null ? vendorUuid : new UUID(0, 0); + this.mType = type; + this.mVersion = version; + this.mData = data != null ? data : new byte[0]; + } + /** Unique sound model identifier */ @NonNull - public final UUID uuid; + public UUID getUuid() { + return mUuid; + } /** Sound model type (e.g. TYPE_KEYPHRASE); */ @SoundModelType - public final int type; + public int getType() { + return mType; + } /** Unique sound model vendor identifier */ @NonNull - public final UUID vendorUuid; + public UUID getVendorUuid() { + return mVendorUuid; + } /** vendor specific version number of the model */ - public final int version; + public int getVersion() { + return mVersion; + } /** Opaque data. For use by vendor implementation and enrollment application */ @NonNull - public final byte[] data; - - /** @hide */ - public SoundModel(@NonNull UUID uuid, @Nullable UUID vendorUuid, @SoundModelType int type, - @Nullable byte[] data, int version) { - this.uuid = requireNonNull(uuid); - this.vendorUuid = vendorUuid != null ? vendorUuid : new UUID(0, 0); - this.type = type; - this.version = version; - this.data = data != null ? data : new byte[0]; + public byte[] getData() { + return mData; } @Override public int hashCode() { final int prime = 31; int result = 1; - result = prime * result + version; - result = prime * result + Arrays.hashCode(data); - result = prime * result + type; - result = prime * result + ((uuid == null) ? 0 : uuid.hashCode()); - result = prime * result + ((vendorUuid == null) ? 0 : vendorUuid.hashCode()); + result = prime * result + getVersion(); + result = prime * result + Arrays.hashCode(getData()); + result = prime * result + getType(); + result = prime * result + ((getUuid() == null) ? 0 : getUuid().hashCode()); + result = prime * result + ((getVendorUuid() == null) ? 0 : getVendorUuid().hashCode()); return result; } @@ -358,27 +434,27 @@ public class SoundTrigger { return false; } SoundModel other = (SoundModel) obj; - if (type != other.type) { + if (getType() != other.getType()) { return false; } - if (uuid == null) { - if (other.uuid != null) { + if (getUuid() == null) { + if (other.getUuid() != null) { return false; } - } else if (!uuid.equals(other.uuid)) { + } else if (!getUuid().equals(other.getUuid())) { return false; } - if (vendorUuid == null) { - if (other.vendorUuid != null) { + if (getVendorUuid() == null) { + if (other.getVendorUuid() != null) { return false; } - } else if (!vendorUuid.equals(other.vendorUuid)) { + } else if (!getVendorUuid().equals(other.getVendorUuid())) { return false; } - if (!Arrays.equals(data, other.data)) { + if (!Arrays.equals(getData(), other.getData())) { return false; } - if (version != other.version) { + if (getVersion() != other.getVersion()) { return false; } return true; @@ -390,8 +466,41 @@ public class SoundTrigger { * {@link KeyphraseSoundModel} */ public static final class Keyphrase implements Parcelable { + + private final int mId; + @RecognitionModes + private final int mRecognitionModes; + @NonNull + private final Locale mLocale; + @NonNull + private final String mText; + @NonNull + private final int[] mUsers; + + /** + * Constructor for Keyphrase describes a key phrase that can be detected by a + * {@link KeyphraseSoundModel} + * + * @param id Unique keyphrase identifier for this keyphrase + * @param recognitionModes Bit field representation of recognition modes this keyphrase + * supports + * @param locale Locale of the keyphrase + * @param text Key phrase text + * @param users Users this key phrase has been trained for. + */ + public Keyphrase(int id, @RecognitionModes int recognitionModes, @NonNull Locale locale, + @NonNull String text, @Nullable int[] users) { + this.mId = id; + this.mRecognitionModes = recognitionModes; + this.mLocale = requireNonNull(locale); + this.mText = requireNonNull(text); + this.mUsers = users != null ? users : new int[0]; + } + /** Unique identifier for this keyphrase */ - public final int id; + public int getId() { + return mId; + } /** * Recognition modes supported for this key phrase in the model @@ -402,41 +511,29 @@ public class SoundTrigger { * @see #RECOGNITION_MODE_GENERIC */ @RecognitionModes - public final int recognitionModes; + public int getRecognitionModes() { + return mRecognitionModes; + } /** Locale of the keyphrase. */ @NonNull - public final Locale locale; + public Locale getLocale() { + return mLocale; + } /** Key phrase text */ @NonNull - public final String text; + public String getText() { + return mText; + } /** * Users this key phrase has been trained for. countains sound trigger specific user IDs * derived from system user IDs {@link android.os.UserHandle#getIdentifier()}. */ @NonNull - public final int[] users; - - /** - * Constructor for Keyphrase describes a key phrase that can be detected by a - * {@link KeyphraseSoundModel} - * - * @param id Unique keyphrase identifier for this keyphrase - * @param recognitionModes Bit field representation of recognition modes this keyphrase - * supports - * @param locale Locale of the keyphrase - * @param text Key phrase text - * @param users Users this key phrase has been trained for. - */ - public Keyphrase(int id, @RecognitionModes int recognitionModes, @NonNull Locale locale, - @NonNull String text, @Nullable int[] users) { - this.id = id; - this.recognitionModes = recognitionModes; - this.locale = requireNonNull(locale); - this.text = requireNonNull(text); - this.users = users != null ? users : new int[0]; + public int[] getUsers() { + return mUsers; } public static final @NonNull Parcelable.Creator<Keyphrase> CREATOR = @@ -472,13 +569,13 @@ public class SoundTrigger { @Override public void writeToParcel(@NonNull Parcel dest, int flags) { - dest.writeInt(id); - dest.writeInt(recognitionModes); - dest.writeString(locale.toLanguageTag()); - dest.writeString(text); - if (users != null) { - dest.writeInt(users.length); - dest.writeIntArray(users); + dest.writeInt(getId()); + dest.writeInt(getRecognitionModes()); + dest.writeString(getLocale().toLanguageTag()); + dest.writeString(getText()); + if (getUsers() != null) { + dest.writeInt(getUsers().length); + dest.writeIntArray(getUsers()); } else { dest.writeInt(-1); } @@ -494,11 +591,11 @@ public class SoundTrigger { public int hashCode() { final int prime = 31; int result = 1; - result = prime * result + ((text == null) ? 0 : text.hashCode()); - result = prime * result + id; - result = prime * result + ((locale == null) ? 0 : locale.hashCode()); - result = prime * result + recognitionModes; - result = prime * result + Arrays.hashCode(users); + result = prime * result + ((getText() == null) ? 0 : getText().hashCode()); + result = prime * result + getId(); + result = prime * result + ((getLocale() == null) ? 0 : getLocale().hashCode()); + result = prime * result + getRecognitionModes(); + result = prime * result + Arrays.hashCode(getUsers()); return result; } @@ -514,27 +611,27 @@ public class SoundTrigger { return false; } Keyphrase other = (Keyphrase) obj; - if (text == null) { - if (other.text != null) { + if (getText() == null) { + if (other.getText() != null) { return false; } - } else if (!text.equals(other.text)) { + } else if (!getText().equals(other.getText())) { return false; } - if (id != other.id) { + if (getId() != other.getId()) { return false; } - if (locale == null) { - if (other.locale != null) { + if (getLocale() == null) { + if (other.getLocale() != null) { return false; } - } else if (!locale.equals(other.locale)) { + } else if (!getLocale().equals(other.getLocale())) { return false; } - if (recognitionModes != other.recognitionModes) { + if (getRecognitionModes() != other.getRecognitionModes()) { return false; } - if (!Arrays.equals(users, other.users)) { + if (!Arrays.equals(getUsers(), other.getUsers())) { return false; } return true; @@ -542,9 +639,9 @@ public class SoundTrigger { @Override public String toString() { - return "Keyphrase [id=" + id + ", recognitionModes=" + recognitionModes - + ", locale=" + locale.toLanguageTag() + ", text=" + text - + ", users=" + Arrays.toString(users) + "]"; + return "Keyphrase [id=" + getId() + ", recognitionModes=" + getRecognitionModes() + + ", locale=" + getLocale().toLanguageTag() + ", text=" + getText() + + ", users=" + Arrays.toString(getUsers()) + "]"; } } @@ -554,15 +651,15 @@ public class SoundTrigger { * and the list of corresponding {@link Keyphrase} descriptors. */ public static final class KeyphraseSoundModel extends SoundModel implements Parcelable { - /** Key phrases in this sound model */ + @NonNull - public final Keyphrase[] keyphrases; // keyword phrases in model + private final Keyphrase[] mKeyphrases; public KeyphraseSoundModel( @NonNull UUID uuid, @NonNull UUID vendorUuid, @Nullable byte[] data, @Nullable Keyphrase[] keyphrases, int version) { super(uuid, vendorUuid, TYPE_KEYPHRASE, data, version); - this.keyphrases = keyphrases != null ? keyphrases : new Keyphrase[0]; + this.mKeyphrases = keyphrases != null ? keyphrases : new Keyphrase[0]; } public KeyphraseSoundModel(@NonNull UUID uuid, @NonNull UUID vendorUuid, @@ -570,6 +667,12 @@ public class SoundTrigger { this(uuid, vendorUuid, data, keyphrases, -1); } + /** Key phrases in this sound model */ + @NonNull + public Keyphrase[] getKeyphrases() { + return mKeyphrases; + } + public static final @NonNull Parcelable.Creator<KeyphraseSoundModel> CREATOR = new Parcelable.Creator<KeyphraseSoundModel>() { @NonNull @@ -608,32 +711,32 @@ public class SoundTrigger { @Override public void writeToParcel(@NonNull Parcel dest, int flags) { - dest.writeString(uuid.toString()); - if (vendorUuid == null) { + dest.writeString(getUuid().toString()); + if (getVendorUuid() == null) { dest.writeInt(-1); } else { - dest.writeInt(vendorUuid.toString().length()); - dest.writeString(vendorUuid.toString()); + dest.writeInt(getVendorUuid().toString().length()); + dest.writeString(getVendorUuid().toString()); } - dest.writeInt(version); - dest.writeBlob(data); - dest.writeTypedArray(keyphrases, flags); + dest.writeInt(getVersion()); + dest.writeBlob(getData()); + dest.writeTypedArray(getKeyphrases(), flags); } @Override public String toString() { - return "KeyphraseSoundModel [keyphrases=" + Arrays.toString(keyphrases) - + ", uuid=" + uuid + ", vendorUuid=" + vendorUuid - + ", type=" + type - + ", data=" + (data == null ? 0 : data.length) - + ", version=" + version + "]"; + return "KeyphraseSoundModel [keyphrases=" + Arrays.toString(getKeyphrases()) + + ", uuid=" + getUuid() + ", vendorUuid=" + getVendorUuid() + + ", type=" + getType() + + ", data=" + (getData() == null ? 0 : getData().length) + + ", version=" + getVersion() + "]"; } @Override public int hashCode() { final int prime = 31; int result = super.hashCode(); - result = prime * result + Arrays.hashCode(keyphrases); + result = prime * result + Arrays.hashCode(getKeyphrases()); return result; } @@ -649,7 +752,7 @@ public class SoundTrigger { return false; } KeyphraseSoundModel other = (KeyphraseSoundModel) obj; - if (!Arrays.equals(keyphrases, other.keyphrases)) { + if (!Arrays.equals(getKeyphrases(), other.getKeyphrases())) { return false; } return true; @@ -706,23 +809,23 @@ public class SoundTrigger { @Override public void writeToParcel(Parcel dest, int flags) { - dest.writeString(uuid.toString()); - if (vendorUuid == null) { + dest.writeString(getUuid().toString()); + if (getVendorUuid() == null) { dest.writeInt(-1); } else { - dest.writeInt(vendorUuid.toString().length()); - dest.writeString(vendorUuid.toString()); + dest.writeInt(getVendorUuid().toString().length()); + dest.writeString(getVendorUuid().toString()); } - dest.writeBlob(data); - dest.writeInt(version); + dest.writeBlob(getData()); + dest.writeInt(getVersion()); } @Override public String toString() { - return "GenericSoundModel [uuid=" + uuid + ", vendorUuid=" + vendorUuid - + ", type=" + type - + ", data=" + (data == null ? 0 : data.length) - + ", version=" + version + "]"; + return "GenericSoundModel [uuid=" + getUuid() + ", vendorUuid=" + getVendorUuid() + + ", type=" + getType() + + ", data=" + (getData() == null ? 0 : getData().length) + + ", version=" + getVersion() + "]"; } } @@ -1825,7 +1928,7 @@ public class SoundTrigger { /** * Get an interface on a hardware module to control sound models and recognition on * this module. - * @param moduleId Sound module system identifier {@link ModuleProperties#id}. mandatory. + * @param moduleId Sound module system identifier {@link ModuleProperties#mId}. mandatory. * @param listener {@link StatusListener} interface. Mandatory. * @param handler the Handler that will receive the callabcks. Can be null if default handler * is OK. diff --git a/core/java/android/service/voice/AlwaysOnHotwordDetector.java b/core/java/android/service/voice/AlwaysOnHotwordDetector.java index f8265d6366ab..97cd7608f876 100644 --- a/core/java/android/service/voice/AlwaysOnHotwordDetector.java +++ b/core/java/android/service/voice/AlwaysOnHotwordDetector.java @@ -487,7 +487,7 @@ public class AlwaysOnHotwordDetector { ModuleProperties properties = mModelManagementService.getDspModuleProperties(); if (properties != null) { - return properties.audioCapabilities; + return properties.getAudioCapabilities(); } return 0; diff --git a/media/java/android/media/soundtrigger/SoundTriggerManager.java b/media/java/android/media/soundtrigger/SoundTriggerManager.java index 6a8483c58276..7d51b104a47d 100644 --- a/media/java/android/media/soundtrigger/SoundTriggerManager.java +++ b/media/java/android/media/soundtrigger/SoundTriggerManager.java @@ -211,7 +211,7 @@ public final class SoundTriggerManager { */ @NonNull public UUID getModelUuid() { - return mGenericSoundModel.uuid; + return mGenericSoundModel.getUuid(); } /** @@ -221,7 +221,7 @@ public final class SoundTriggerManager { */ @NonNull public UUID getVendorUuid() { - return mGenericSoundModel.vendorUuid; + return mGenericSoundModel.getVendorUuid(); } /** @@ -230,7 +230,7 @@ public final class SoundTriggerManager { * @return Version associated with the model */ public int getVersion() { - return mGenericSoundModel.version; + return mGenericSoundModel.getVersion(); } /** @@ -240,7 +240,7 @@ public final class SoundTriggerManager { */ @Nullable public byte[] getModelData() { - return mGenericSoundModel.data; + return mGenericSoundModel.getData(); } /** @@ -307,7 +307,7 @@ public final class SoundTriggerManager { } try { - switch (soundModel.type) { + switch (soundModel.getType()) { case SoundModel.TYPE_GENERIC_SOUND: return mSoundTriggerService.loadGenericSoundModel( (GenericSoundModel) soundModel); diff --git a/services/voiceinteraction/java/com/android/server/soundtrigger/SoundTriggerDbHelper.java b/services/voiceinteraction/java/com/android/server/soundtrigger/SoundTriggerDbHelper.java index 99065854445a..71da8dd267db 100644 --- a/services/voiceinteraction/java/com/android/server/soundtrigger/SoundTriggerDbHelper.java +++ b/services/voiceinteraction/java/com/android/server/soundtrigger/SoundTriggerDbHelper.java @@ -86,10 +86,11 @@ public class SoundTriggerDbHelper extends SQLiteOpenHelper { synchronized(this) { SQLiteDatabase db = getWritableDatabase(); ContentValues values = new ContentValues(); - values.put(GenericSoundModelContract.KEY_MODEL_UUID, soundModel.uuid.toString()); - values.put(GenericSoundModelContract.KEY_VENDOR_UUID, soundModel.vendorUuid.toString()); - values.put(GenericSoundModelContract.KEY_DATA, soundModel.data); - values.put(GenericSoundModelContract.KEY_MODEL_VERSION, soundModel.version); + values.put(GenericSoundModelContract.KEY_MODEL_UUID, soundModel.getUuid().toString()); + values.put(GenericSoundModelContract.KEY_VENDOR_UUID, + soundModel.getVendorUuid().toString()); + values.put(GenericSoundModelContract.KEY_DATA, soundModel.getData()); + values.put(GenericSoundModelContract.KEY_MODEL_VERSION, soundModel.getVersion()); try { return db.insertWithOnConflict(GenericSoundModelContract.TABLE, null, values, @@ -140,7 +141,7 @@ public class SoundTriggerDbHelper extends SQLiteOpenHelper { // Delete all sound models for the given keyphrase and specified user. SQLiteDatabase db = getWritableDatabase(); String soundModelClause = GenericSoundModelContract.KEY_MODEL_UUID - + "='" + soundModel.uuid.toString() + "'"; + + "='" + soundModel.getUuid().toString() + "'"; try { return db.delete(GenericSoundModelContract.TABLE, soundModelClause, null) != 0; } finally { diff --git a/services/voiceinteraction/java/com/android/server/soundtrigger/SoundTriggerHelper.java b/services/voiceinteraction/java/com/android/server/soundtrigger/SoundTriggerHelper.java index 7099c0935ee9..6c0f2b0cd278 100644 --- a/services/voiceinteraction/java/com/android/server/soundtrigger/SoundTriggerHelper.java +++ b/services/voiceinteraction/java/com/android/server/soundtrigger/SoundTriggerHelper.java @@ -195,7 +195,7 @@ public class SoundTriggerHelper implements SoundTrigger.StatusListener { } // Process existing model first. - if (model != null && !model.getModelId().equals(soundModel.uuid)) { + if (model != null && !model.getModelId().equals(soundModel.getUuid())) { // The existing model has a different UUID, should be replaced. int status = cleanUpExistingKeyphraseModelLocked(model); if (status != STATUS_OK) { @@ -208,7 +208,7 @@ public class SoundTriggerHelper implements SoundTrigger.StatusListener { // We need to create a new one: either no previous models existed for given keyphrase id // or the existing model had a different UUID and was cleaned up. if (model == null) { - model = createKeyphraseModelDataLocked(soundModel.uuid, keyphraseId); + model = createKeyphraseModelDataLocked(soundModel.getUuid(), keyphraseId); } return startRecognition(soundModel, model, callback, recognitionConfig, @@ -249,7 +249,7 @@ public class SoundTriggerHelper implements SoundTrigger.StatusListener { return STATUS_ERROR; } if (mModule == null) { - mModule = SoundTrigger.attachModule(mModuleProperties.id, this, null); + mModule = SoundTrigger.attachModule(mModuleProperties.getId(), this, null); if (mModule == null) { Slog.w(TAG, "startRecognition cannot attach to sound trigger module"); return STATUS_ERROR; diff --git a/services/voiceinteraction/java/com/android/server/soundtrigger/SoundTriggerService.java b/services/voiceinteraction/java/com/android/server/soundtrigger/SoundTriggerService.java index 00cb6dc7400d..170bee841e74 100644 --- a/services/voiceinteraction/java/com/android/server/soundtrigger/SoundTriggerService.java +++ b/services/voiceinteraction/java/com/android/server/soundtrigger/SoundTriggerService.java @@ -358,7 +358,7 @@ public class SoundTriggerService extends SystemService { public int loadGenericSoundModel(GenericSoundModel soundModel) { enforceCallingPermission(Manifest.permission.MANAGE_SOUND_TRIGGER); if (!isInitialized()) return STATUS_ERROR; - if (soundModel == null || soundModel.uuid == null) { + if (soundModel == null || soundModel.getUuid() == null) { Slog.e(TAG, "Invalid sound model"); sEventLogger.log(new SoundTriggerLogger.StringEvent( @@ -367,24 +367,24 @@ public class SoundTriggerService extends SystemService { return STATUS_ERROR; } if (DEBUG) { - Slog.i(TAG, "loadGenericSoundModel(): id = " + soundModel.uuid); + Slog.i(TAG, "loadGenericSoundModel(): id = " + soundModel.getUuid()); } sEventLogger.log(new SoundTriggerLogger.StringEvent("loadGenericSoundModel(): id = " - + soundModel.uuid)); + + soundModel.getUuid())); synchronized (mLock) { - SoundModel oldModel = mLoadedModels.get(soundModel.uuid); + SoundModel oldModel = mLoadedModels.get(soundModel.getUuid()); // If the model we're loading is actually different than what we had loaded, we // should unload that other model now. We don't care about return codes since we // don't know if the other model is loaded. if (oldModel != null && !oldModel.equals(soundModel)) { - mSoundTriggerHelper.unloadGenericSoundModel(soundModel.uuid); + mSoundTriggerHelper.unloadGenericSoundModel(soundModel.getUuid()); synchronized (mCallbacksLock) { - mCallbacks.remove(soundModel.uuid); + mCallbacks.remove(soundModel.getUuid()); } } - mLoadedModels.put(soundModel.uuid, soundModel); + mLoadedModels.put(soundModel.getUuid(), soundModel); } return STATUS_OK; } @@ -393,7 +393,7 @@ public class SoundTriggerService extends SystemService { public int loadKeyphraseSoundModel(KeyphraseSoundModel soundModel) { enforceCallingPermission(Manifest.permission.MANAGE_SOUND_TRIGGER); if (!isInitialized()) return STATUS_ERROR; - if (soundModel == null || soundModel.uuid == null) { + if (soundModel == null || soundModel.getUuid() == null) { Slog.e(TAG, "Invalid sound model"); sEventLogger.log(new SoundTriggerLogger.StringEvent( @@ -401,7 +401,7 @@ public class SoundTriggerService extends SystemService { return STATUS_ERROR; } - if (soundModel.keyphrases == null || soundModel.keyphrases.length != 1) { + if (soundModel.getKeyphrases() == null || soundModel.getKeyphrases().length != 1) { Slog.e(TAG, "Only one keyphrase per model is currently supported."); sEventLogger.log(new SoundTriggerLogger.StringEvent( @@ -411,24 +411,25 @@ public class SoundTriggerService extends SystemService { return STATUS_ERROR; } if (DEBUG) { - Slog.i(TAG, "loadKeyphraseSoundModel(): id = " + soundModel.uuid); + Slog.i(TAG, "loadKeyphraseSoundModel(): id = " + soundModel.getUuid()); } sEventLogger.log(new SoundTriggerLogger.StringEvent("loadKeyphraseSoundModel(): id = " - + soundModel.uuid)); + + soundModel.getUuid())); synchronized (mLock) { - SoundModel oldModel = mLoadedModels.get(soundModel.uuid); + SoundModel oldModel = mLoadedModels.get(soundModel.getUuid()); // If the model we're loading is actually different than what we had loaded, we // should unload that other model now. We don't care about return codes since we // don't know if the other model is loaded. if (oldModel != null && !oldModel.equals(soundModel)) { - mSoundTriggerHelper.unloadKeyphraseSoundModel(soundModel.keyphrases[0].id); + mSoundTriggerHelper.unloadKeyphraseSoundModel( + soundModel.getKeyphrases()[0].getId()); synchronized (mCallbacksLock) { - mCallbacks.remove(soundModel.uuid); + mCallbacks.remove(soundModel.getUuid()); } } - mLoadedModels.put(soundModel.uuid, soundModel); + mLoadedModels.put(soundModel.getUuid(), soundModel); } return STATUS_OK; } @@ -478,9 +479,9 @@ public class SoundTriggerService extends SystemService { return STATUS_ERROR; } int ret; - switch (soundModel.type) { + switch (soundModel.getType()) { case SoundModel.TYPE_GENERIC_SOUND: - ret = mSoundTriggerHelper.startGenericRecognition(soundModel.uuid, + ret = mSoundTriggerHelper.startGenericRecognition(soundModel.getUuid(), (GenericSoundModel) soundModel, callback, config); break; default: @@ -545,9 +546,10 @@ public class SoundTriggerService extends SystemService { return STATUS_ERROR; } int ret; - switch (soundModel.type) { + switch (soundModel.getType()) { case SoundModel.TYPE_GENERIC_SOUND: - ret = mSoundTriggerHelper.stopGenericRecognition(soundModel.uuid, callback); + ret = mSoundTriggerHelper.stopGenericRecognition( + soundModel.getUuid(), callback); break; default: Slog.e(TAG, "Unknown model type"); @@ -597,13 +599,13 @@ public class SoundTriggerService extends SystemService { return STATUS_ERROR; } int ret; - switch (soundModel.type) { + switch (soundModel.getType()) { case SoundModel.TYPE_KEYPHRASE: ret = mSoundTriggerHelper.unloadKeyphraseSoundModel( - ((KeyphraseSoundModel)soundModel).keyphrases[0].id); + ((KeyphraseSoundModel) soundModel).getKeyphrases()[0].getId()); break; case SoundModel.TYPE_GENERIC_SOUND: - ret = mSoundTriggerHelper.unloadGenericSoundModel(soundModel.uuid); + ret = mSoundTriggerHelper.unloadGenericSoundModel(soundModel.getUuid()); break; default: Slog.e(TAG, "Unknown model type"); @@ -661,16 +663,16 @@ public class SoundTriggerService extends SystemService { return ret; } - switch (soundModel.type) { + switch (soundModel.getType()) { case SoundModel.TYPE_GENERIC_SOUND: - ret = mSoundTriggerHelper.getGenericModelState(soundModel.uuid); + ret = mSoundTriggerHelper.getGenericModelState(soundModel.getUuid()); break; default: // SoundModel.TYPE_KEYPHRASE is not supported to increase privacy. - Slog.e(TAG, "Unsupported model type, " + soundModel.type); + Slog.e(TAG, "Unsupported model type, " + soundModel.getType()); sEventLogger.log(new SoundTriggerLogger.StringEvent( "getModelState(): Unsupported model type, " - + soundModel.type)); + + soundModel.getType())); break; } @@ -723,7 +725,7 @@ public class SoundTriggerService extends SystemService { return STATUS_BAD_VALUE; } - return mSoundTriggerHelper.setParameter(soundModel.uuid, modelParam, value); + return mSoundTriggerHelper.setParameter(soundModel.getUuid(), modelParam, value); } } @@ -755,7 +757,7 @@ public class SoundTriggerService extends SystemService { throw new IllegalArgumentException("sound model is not loaded"); } - return mSoundTriggerHelper.getParameter(soundModel.uuid, modelParam); + return mSoundTriggerHelper.getParameter(soundModel.getUuid(), modelParam); } } @@ -786,7 +788,7 @@ public class SoundTriggerService extends SystemService { return null; } - return mSoundTriggerHelper.queryParameter(soundModel.uuid, modelParam); + return mSoundTriggerHelper.queryParameter(soundModel.getUuid(), modelParam); } } } diff --git a/services/voiceinteraction/java/com/android/server/voiceinteraction/DatabaseHelper.java b/services/voiceinteraction/java/com/android/server/voiceinteraction/DatabaseHelper.java index be0987d745ba..aaf7a9eacce6 100644 --- a/services/voiceinteraction/java/com/android/server/voiceinteraction/DatabaseHelper.java +++ b/services/voiceinteraction/java/com/android/server/voiceinteraction/DatabaseHelper.java @@ -162,23 +162,26 @@ public class DatabaseHelper extends SQLiteOpenHelper { synchronized(this) { SQLiteDatabase db = getWritableDatabase(); ContentValues values = new ContentValues(); - values.put(SoundModelContract.KEY_MODEL_UUID, soundModel.uuid.toString()); - if (soundModel.vendorUuid != null) { - values.put(SoundModelContract.KEY_VENDOR_UUID, soundModel.vendorUuid.toString()); + values.put(SoundModelContract.KEY_MODEL_UUID, soundModel.getUuid().toString()); + if (soundModel.getVendorUuid() != null) { + values.put(SoundModelContract.KEY_VENDOR_UUID, + soundModel.getVendorUuid().toString()); } values.put(SoundModelContract.KEY_TYPE, SoundTrigger.SoundModel.TYPE_KEYPHRASE); - values.put(SoundModelContract.KEY_DATA, soundModel.data); - values.put(SoundModelContract.KEY_MODEL_VERSION, soundModel.version); + values.put(SoundModelContract.KEY_DATA, soundModel.getData()); + values.put(SoundModelContract.KEY_MODEL_VERSION, soundModel.getVersion()); - if (soundModel.keyphrases != null && soundModel.keyphrases.length == 1) { - values.put(SoundModelContract.KEY_KEYPHRASE_ID, soundModel.keyphrases[0].id); + if (soundModel.getKeyphrases() != null && soundModel.getKeyphrases().length == 1) { + values.put(SoundModelContract.KEY_KEYPHRASE_ID, + soundModel.getKeyphrases()[0].getId()); values.put(SoundModelContract.KEY_RECOGNITION_MODES, - soundModel.keyphrases[0].recognitionModes); + soundModel.getKeyphrases()[0].getRecognitionModes()); values.put(SoundModelContract.KEY_USERS, - getCommaSeparatedString(soundModel.keyphrases[0].users)); + getCommaSeparatedString(soundModel.getKeyphrases()[0].getUsers())); values.put(SoundModelContract.KEY_LOCALE, - soundModel.keyphrases[0].locale.toLanguageTag()); - values.put(SoundModelContract.KEY_HINT_TEXT, soundModel.keyphrases[0].text); + soundModel.getKeyphrases()[0].getLocale().toLanguageTag()); + values.put(SoundModelContract.KEY_HINT_TEXT, + soundModel.getKeyphrases()[0].getText()); try { return db.insertWithOnConflict(SoundModelContract.TABLE, null, values, SQLiteDatabase.CONFLICT_REPLACE) != -1; @@ -206,7 +209,7 @@ public class DatabaseHelper extends SQLiteOpenHelper { // Delete all sound models for the given keyphrase and specified user. SQLiteDatabase db = getWritableDatabase(); String soundModelClause = SoundModelContract.KEY_MODEL_UUID - + "='" + soundModel.uuid.toString() + "'"; + + "='" + soundModel.getUuid().toString() + "'"; try { return db.delete(SoundModelContract.TABLE, soundModelClause, null) != 0; } finally { diff --git a/services/voiceinteraction/java/com/android/server/voiceinteraction/VoiceInteractionManagerService.java b/services/voiceinteraction/java/com/android/server/voiceinteraction/VoiceInteractionManagerService.java index 18d581964f2a..ef282ba110c5 100644 --- a/services/voiceinteraction/java/com/android/server/voiceinteraction/VoiceInteractionManagerService.java +++ b/services/voiceinteraction/java/com/android/server/voiceinteraction/VoiceInteractionManagerService.java @@ -1045,12 +1045,12 @@ public class VoiceInteractionManagerService extends SystemService { return null; } - for (SoundTrigger.Keyphrase phrase : model.keyphrases) { - if (keyphrase.equals(phrase.text)) { + for (SoundTrigger.Keyphrase phrase : model.getKeyphrases()) { + if (keyphrase.equals(phrase.getText())) { ArraySet<Locale> locales = new ArraySet<>(); - locales.add(phrase.locale); - return new KeyphraseMetadata(phrase.id, phrase.text, locales, - phrase.recognitionModes); + locales.add(phrase.getLocale()); + return new KeyphraseMetadata(phrase.getId(), phrase.getText(), locales, + phrase.getRecognitionModes()); } } } finally { @@ -1093,8 +1093,8 @@ public class VoiceInteractionManagerService extends SystemService { KeyphraseSoundModel soundModel = mDbHelper.getKeyphraseSoundModel(keyphraseId, callingUid, bcp47Locale); if (soundModel == null - || soundModel.uuid == null - || soundModel.keyphrases == null) { + || soundModel.getUuid() == null + || soundModel.getKeyphrases() == null) { Slog.w(TAG, "No matching sound model found in startRecognition"); return SoundTriggerInternal.STATUS_ERROR; } else { diff --git a/tests/SoundTriggerTestApp/src/com/android/test/soundtrigger/SoundTriggerTestService.java b/tests/SoundTriggerTestApp/src/com/android/test/soundtrigger/SoundTriggerTestService.java index b185a26bb972..9324ba0b8b72 100644 --- a/tests/SoundTriggerTestApp/src/com/android/test/soundtrigger/SoundTriggerTestService.java +++ b/tests/SoundTriggerTestApp/src/com/android/test/soundtrigger/SoundTriggerTestService.java @@ -250,10 +250,12 @@ public class SoundTriggerTestService extends Service { boolean status = mSoundTriggerUtil.addOrUpdateSoundModel(soundModel); if (status) { - postToast("Successfully loaded " + modelInfo.name + ", UUID=" + soundModel.uuid); + postToast("Successfully loaded " + modelInfo.name + ", UUID=" + + soundModel.getUuid()); setModelState(modelInfo, "Loaded"); } else { - postErrorToast("Failed to load " + modelInfo.name + ", UUID=" + soundModel.uuid + "!"); + postErrorToast("Failed to load " + modelInfo.name + ", UUID=" + + soundModel.getUuid() + "!"); setModelState(modelInfo, "Failed to load"); } } @@ -275,11 +277,12 @@ public class SoundTriggerTestService extends Service { modelInfo.detector = null; boolean status = mSoundTriggerUtil.deleteSoundModel(modelUuid); if (status) { - postToast("Successfully unloaded " + modelInfo.name + ", UUID=" + soundModel.uuid); + postToast("Successfully unloaded " + modelInfo.name + ", UUID=" + + soundModel.getUuid()); setModelState(modelInfo, "Unloaded"); } else { postErrorToast("Failed to unload " + - modelInfo.name + ", UUID=" + soundModel.uuid + "!"); + modelInfo.name + ", UUID=" + soundModel.getUuid() + "!"); setModelState(modelInfo, "Failed to unload"); } } @@ -299,7 +302,8 @@ public class SoundTriggerTestService extends Service { GenericSoundModel updated = createNewSoundModel(modelInfo); boolean status = mSoundTriggerUtil.addOrUpdateSoundModel(updated); if (status) { - postToast("Successfully reloaded " + modelInfo.name + ", UUID=" + modelInfo.modelUuid); + postToast("Successfully reloaded " + modelInfo.name + ", UUID=" + + modelInfo.modelUuid); setModelState(modelInfo, "Reloaded"); } else { postErrorToast("Failed to reload " @@ -321,7 +325,8 @@ public class SoundTriggerTestService extends Service { modelUuid, new DetectorCallback(modelInfo)); } - postMessage("Starting recognition for " + modelInfo.name + ", UUID=" + modelInfo.modelUuid); + postMessage("Starting recognition for " + modelInfo.name + ", UUID=" + + modelInfo.modelUuid); if (modelInfo.detector.startRecognition(modelInfo.captureAudio ? SoundTriggerDetector.RECOGNITION_FLAG_CAPTURE_TRIGGER_AUDIO : SoundTriggerDetector.RECOGNITION_FLAG_ALLOW_MULTIPLE_TRIGGERS)) { @@ -495,7 +500,8 @@ public class SoundTriggerTestService extends Service { if (properties.containsKey("dataFile")) { File modelDataFile = new File( - getFilesDir().getPath() + "/" + properties.getProperty("dataFile")); + getFilesDir().getPath() + "/" + + properties.getProperty("dataFile")); modelInfo.modelData = new byte[(int) modelDataFile.length()]; FileInputStream input = new FileInputStream(modelDataFile); input.read(modelInfo.modelData, 0, modelInfo.modelData.length); @@ -602,12 +608,14 @@ public class SoundTriggerTestService extends Service { FileOutputStream fos = null; try { fos = new FileOutputStream( new File( - getFilesDir() + File.separator + mModelInfo.name.replace(' ', '_') + - "_capture_" + format.getChannelCount() + "ch_" + - format.getSampleRate() + "hz_" + encoding + ".pcm")); + getFilesDir() + File.separator + + mModelInfo.name.replace(' ', '_') + + "_capture_" + format.getChannelCount() + "ch_" + + format.getSampleRate() + "hz_" + encoding + ".pcm")); } catch (IOException e) { Log.e(TAG, "Failed to open output for saving PCM data", e); - postErrorToast("Failed to open output for saving PCM data: " + e.getMessage()); + postErrorToast("Failed to open output for saving PCM data: " + + e.getMessage()); } // Inform the user we're recording. @@ -690,7 +698,8 @@ public class SoundTriggerTestService extends Service { AudioFormat format = event.getCaptureAudioFormat(); result = result + "AudioFormat: " + ((format == null) ? "null" : format.toString()); byte[] triggerAudio = event.getTriggerAudio(); - result = result + ", TriggerAudio: " + (triggerAudio == null ? "null" : triggerAudio.length); + result = result + ", TriggerAudio: " + + (triggerAudio == null ? "null" : triggerAudio.length); byte[] data = event.getData(); result = result + ", Data: " + (data == null ? "null" : data.length); if (data != null) { diff --git a/tests/SoundTriggerTests/src/android/hardware/soundtrigger/SoundTriggerTest.java b/tests/SoundTriggerTests/src/android/hardware/soundtrigger/SoundTriggerTest.java index c900eaedbdae..e36f398c53ea 100644 --- a/tests/SoundTriggerTests/src/android/hardware/soundtrigger/SoundTriggerTest.java +++ b/tests/SoundTriggerTests/src/android/hardware/soundtrigger/SoundTriggerTest.java @@ -16,7 +16,6 @@ package android.hardware.soundtrigger; -import android.hardware.soundtrigger.SoundTrigger; import android.hardware.soundtrigger.SoundTrigger.ConfidenceLevel; import android.hardware.soundtrigger.SoundTrigger.Keyphrase; import android.hardware.soundtrigger.SoundTrigger.KeyphraseRecognitionEvent; @@ -51,10 +50,10 @@ public class SoundTriggerTest extends InstrumentationTestCase { Keyphrase unparceled = Keyphrase.CREATOR.createFromParcel(parcel); // Verify that they are the same - assertEquals(keyphrase.id, unparceled.id); - assertNull(unparceled.users); - assertEquals(keyphrase.locale, unparceled.locale); - assertEquals(keyphrase.text, unparceled.text); + assertEquals(keyphrase.getId(), unparceled.getId()); + assertNull(unparceled.getUsers()); + assertEquals(keyphrase.getLocale(), unparceled.getLocale()); + assertEquals(keyphrase.getText(), unparceled.getText()); } @SmallTest @@ -71,10 +70,10 @@ public class SoundTriggerTest extends InstrumentationTestCase { Keyphrase unparceled = Keyphrase.CREATOR.createFromParcel(parcel); // Verify that they are the same - assertEquals(keyphrase.id, unparceled.id); - assertTrue(Arrays.equals(keyphrase.users, unparceled.users)); - assertEquals(keyphrase.locale, unparceled.locale); - assertEquals(keyphrase.text, unparceled.text); + assertEquals(keyphrase.getId(), unparceled.getId()); + assertTrue(Arrays.equals(keyphrase.getUsers(), unparceled.getUsers())); + assertEquals(keyphrase.getLocale(), unparceled.getLocale()); + assertEquals(keyphrase.getText(), unparceled.getText()); } @SmallTest @@ -91,10 +90,10 @@ public class SoundTriggerTest extends InstrumentationTestCase { Keyphrase unparceled = Keyphrase.CREATOR.createFromParcel(parcel); // Verify that they are the same - assertEquals(keyphrase.id, unparceled.id); - assertTrue(Arrays.equals(keyphrase.users, unparceled.users)); - assertEquals(keyphrase.locale, unparceled.locale); - assertEquals(keyphrase.text, unparceled.text); + assertEquals(keyphrase.getId(), unparceled.getId()); + assertTrue(Arrays.equals(keyphrase.getUsers(), unparceled.getUsers())); + assertEquals(keyphrase.getLocale(), unparceled.getLocale()); + assertEquals(keyphrase.getText(), unparceled.getText()); } @SmallTest @@ -116,10 +115,10 @@ public class SoundTriggerTest extends InstrumentationTestCase { KeyphraseSoundModel unparceled = KeyphraseSoundModel.CREATOR.createFromParcel(parcel); // Verify that they are the same - assertEquals(ksm.uuid, unparceled.uuid); - assertNull(unparceled.data); - assertEquals(ksm.type, unparceled.type); - assertTrue(Arrays.equals(keyphrases, unparceled.keyphrases)); + assertEquals(ksm.getUuid(), unparceled.getUuid()); + assertNull(unparceled.getData()); + assertEquals(ksm.getType(), unparceled.getType()); + assertTrue(Arrays.equals(keyphrases, unparceled.getKeyphrases())); } @SmallTest @@ -141,10 +140,10 @@ public class SoundTriggerTest extends InstrumentationTestCase { KeyphraseSoundModel unparceled = KeyphraseSoundModel.CREATOR.createFromParcel(parcel); // Verify that they are the same - assertEquals(ksm.uuid, unparceled.uuid); - assertEquals(ksm.type, unparceled.type); - assertTrue(Arrays.equals(ksm.keyphrases, unparceled.keyphrases)); - assertTrue(Arrays.equals(ksm.data, unparceled.data)); + assertEquals(ksm.getUuid(), unparceled.getUuid()); + assertEquals(ksm.getType(), unparceled.getType()); + assertTrue(Arrays.equals(ksm.getKeyphrases(), unparceled.getKeyphrases())); + assertTrue(Arrays.equals(ksm.getData(), unparceled.getData())); } @SmallTest @@ -163,10 +162,10 @@ public class SoundTriggerTest extends InstrumentationTestCase { KeyphraseSoundModel unparceled = KeyphraseSoundModel.CREATOR.createFromParcel(parcel); // Verify that they are the same - assertEquals(ksm.uuid, unparceled.uuid); - assertEquals(ksm.type, unparceled.type); - assertNull(unparceled.keyphrases); - assertTrue(Arrays.equals(ksm.data, unparceled.data)); + assertEquals(ksm.getUuid(), unparceled.getUuid()); + assertEquals(ksm.getType(), unparceled.getType()); + assertNull(unparceled.getKeyphrases()); + assertTrue(Arrays.equals(ksm.getData(), unparceled.getData())); } @SmallTest @@ -185,10 +184,10 @@ public class SoundTriggerTest extends InstrumentationTestCase { KeyphraseSoundModel unparceled = KeyphraseSoundModel.CREATOR.createFromParcel(parcel); // Verify that they are the same - assertEquals(ksm.uuid, unparceled.uuid); - assertEquals(ksm.type, unparceled.type); - assertTrue(Arrays.equals(ksm.keyphrases, unparceled.keyphrases)); - assertTrue(Arrays.equals(ksm.data, unparceled.data)); + assertEquals(ksm.getUuid(), unparceled.getUuid()); + assertEquals(ksm.getType(), unparceled.getType()); + assertTrue(Arrays.equals(ksm.getKeyphrases(), unparceled.getKeyphrases())); + assertTrue(Arrays.equals(ksm.getData(), unparceled.getData())); } @LargeTest @@ -212,10 +211,10 @@ public class SoundTriggerTest extends InstrumentationTestCase { KeyphraseSoundModel unparceled = KeyphraseSoundModel.CREATOR.createFromParcel(parcel); // Verify that they are the same - assertEquals(ksm.uuid, unparceled.uuid); - assertEquals(ksm.type, unparceled.type); - assertTrue(Arrays.equals(ksm.data, unparceled.data)); - assertTrue(Arrays.equals(ksm.keyphrases, unparceled.keyphrases)); + assertEquals(ksm.getUuid(), unparceled.getUuid()); + assertEquals(ksm.getType(), unparceled.getType()); + assertTrue(Arrays.equals(ksm.getData(), unparceled.getData())); + assertTrue(Arrays.equals(ksm.getKeyphrases(), unparceled.getKeyphrases())); } @SmallTest diff --git a/tests/SoundTriggerTests/src/android/hardware/soundtrigger/stubhal/GenericSoundModelTest.java b/tests/SoundTriggerTests/src/android/hardware/soundtrigger/stubhal/GenericSoundModelTest.java index c0583ceb2fab..2c3592c640bc 100644 --- a/tests/SoundTriggerTests/src/android/hardware/soundtrigger/stubhal/GenericSoundModelTest.java +++ b/tests/SoundTriggerTests/src/android/hardware/soundtrigger/stubhal/GenericSoundModelTest.java @@ -17,7 +17,6 @@ package android.hardware.soundtrigger; import static org.mockito.Matchers.any; -import static org.mockito.Matchers.eq; import static org.mockito.Mockito.reset; import static org.mockito.Mockito.spy; import static org.mockito.Mockito.timeout; @@ -37,6 +36,8 @@ import android.test.suitebuilder.annotation.SmallTest; import com.android.internal.app.ISoundTriggerService; +import org.mockito.MockitoAnnotations; + import java.io.DataOutputStream; import java.net.InetAddress; import java.net.Socket; @@ -45,8 +46,6 @@ import java.util.HashSet; import java.util.Random; import java.util.UUID; -import org.mockito.MockitoAnnotations; - public class GenericSoundModelTest extends AndroidTestCase { static final int MSG_DETECTION_ERROR = -1; static final int MSG_DETECTION_RESUME = 0; @@ -96,11 +95,11 @@ public class GenericSoundModelTest extends AndroidTestCase { // Update sound model soundTriggerService.updateSoundModel(model); - loadedModelUuids.add(model.uuid); + loadedModelUuids.add(model.getUuid()); // Confirm it was updated GenericSoundModel returnedModel = - soundTriggerService.getSoundModel(new ParcelUuid(model.uuid)); + soundTriggerService.getSoundModel(new ParcelUuid(model.getUuid())); assertEquals(model, returnedModel); } @@ -110,15 +109,15 @@ public class GenericSoundModelTest extends AndroidTestCase { // Update sound model soundTriggerService.updateSoundModel(model); - loadedModelUuids.add(model.uuid); + loadedModelUuids.add(model.getUuid()); // Delete sound model - soundTriggerService.deleteSoundModel(new ParcelUuid(model.uuid)); - loadedModelUuids.remove(model.uuid); + soundTriggerService.deleteSoundModel(new ParcelUuid(model.getUuid())); + loadedModelUuids.remove(model.getUuid()); // Confirm it was deleted GenericSoundModel returnedModel = - soundTriggerService.getSoundModel(new ParcelUuid(model.uuid)); + soundTriggerService.getSoundModel(new ParcelUuid(model.getUuid())); assertEquals(null, returnedModel); } @@ -134,14 +133,14 @@ public class GenericSoundModelTest extends AndroidTestCase { // Update and start sound model recognition soundTriggerService.updateSoundModel(model); - loadedModelUuids.add(model.uuid); - int r = soundTriggerService.startRecognition(new ParcelUuid(model.uuid), spyCallback, + loadedModelUuids.add(model.getUuid()); + int r = soundTriggerService.startRecognition(new ParcelUuid(model.getUuid()), spyCallback, config); assertEquals("Could Not Start Recognition with code: " + r, android.hardware.soundtrigger.SoundTrigger.STATUS_OK, r); // Stop recognition - r = soundTriggerService.stopRecognition(new ParcelUuid(model.uuid), spyCallback); + r = soundTriggerService.stopRecognition(new ParcelUuid(model.getUuid()), spyCallback); assertEquals("Could Not Stop Recognition with code: " + r, android.hardware.soundtrigger.SoundTrigger.STATUS_OK, r); } @@ -158,13 +157,13 @@ public class GenericSoundModelTest extends AndroidTestCase { // Update and start sound model soundTriggerService.updateSoundModel(model); - loadedModelUuids.add(model.uuid); - soundTriggerService.startRecognition(new ParcelUuid(model.uuid), spyCallback, config); + loadedModelUuids.add(model.getUuid()); + soundTriggerService.startRecognition(new ParcelUuid(model.getUuid()), spyCallback, config); // Send trigger to stub HAL Socket socket = new Socket(InetAddress.getLocalHost(), 14035); DataOutputStream out = new DataOutputStream(socket.getOutputStream()); - out.writeBytes("trig " + model.uuid.toString() + "\r\n"); + out.writeBytes("trig " + model.getUuid().toString() + "\r\n"); out.flush(); socket.close(); @@ -227,11 +226,12 @@ public class GenericSoundModelTest extends AndroidTestCase { if (operation == 0 && modelInfo.status == STATUS_UNLOADED) { // Update and start sound model soundTriggerService.updateSoundModel(modelInfo.model); - loadedModelUuids.add(modelInfo.model.uuid); + loadedModelUuids.add(modelInfo.model.getUuid()); modelInfo.status = STATUS_LOADED; } else if (operation == 1 && modelInfo.status == STATUS_LOADED) { // Start the sound model - int r = soundTriggerService.startRecognition(new ParcelUuid(modelInfo.model.uuid), + int r = soundTriggerService.startRecognition(new ParcelUuid( + modelInfo.model.getUuid()), spyCallback, config); assertEquals("Could Not Start Recognition with code: " + r, android.hardware.soundtrigger.SoundTrigger.STATUS_OK, r); @@ -240,7 +240,7 @@ public class GenericSoundModelTest extends AndroidTestCase { // Send trigger to stub HAL Socket socket = new Socket(InetAddress.getLocalHost(), 14035); DataOutputStream out = new DataOutputStream(socket.getOutputStream()); - out.writeBytes("trig " + modelInfo.model.uuid + "\r\n"); + out.writeBytes("trig " + modelInfo.model.getUuid() + "\r\n"); out.flush(); socket.close(); @@ -249,19 +249,20 @@ public class GenericSoundModelTest extends AndroidTestCase { reset(spyCallback); } else if (operation == 3 && modelInfo.status == STATUS_STARTED) { // Stop recognition - int r = soundTriggerService.stopRecognition(new ParcelUuid(modelInfo.model.uuid), + int r = soundTriggerService.stopRecognition(new ParcelUuid( + modelInfo.model.getUuid()), spyCallback); assertEquals("Could Not Stop Recognition with code: " + r, android.hardware.soundtrigger.SoundTrigger.STATUS_OK, r); modelInfo.status = STATUS_LOADED; } else if (operation == 4 && modelInfo.status != STATUS_UNLOADED) { // Delete sound model - soundTriggerService.deleteSoundModel(new ParcelUuid(modelInfo.model.uuid)); - loadedModelUuids.remove(modelInfo.model.uuid); + soundTriggerService.deleteSoundModel(new ParcelUuid(modelInfo.model.getUuid())); + loadedModelUuids.remove(modelInfo.model.getUuid()); // Confirm it was deleted - GenericSoundModel returnedModel = - soundTriggerService.getSoundModel(new ParcelUuid(modelInfo.model.uuid)); + GenericSoundModel returnedModel = soundTriggerService.getSoundModel( + new ParcelUuid(modelInfo.model.getUuid())); assertEquals(null, returnedModel); modelInfo.status = STATUS_UNLOADED; } diff --git a/tests/VoiceEnrollment/src/com/android/test/voiceenrollment/EnrollmentUtil.java b/tests/VoiceEnrollment/src/com/android/test/voiceenrollment/EnrollmentUtil.java index 7927ac4cb895..287364fec8eb 100644 --- a/tests/VoiceEnrollment/src/com/android/test/voiceenrollment/EnrollmentUtil.java +++ b/tests/VoiceEnrollment/src/com/android/test/voiceenrollment/EnrollmentUtil.java @@ -159,36 +159,36 @@ public class EnrollmentUtil { Log.e(TAG, "KeyphraseSoundModel must be non-null"); return false; } - if (soundModel.uuid == null) { + if (soundModel.getUuid() == null) { Log.e(TAG, "KeyphraseSoundModel must have a UUID"); return false; } - if (soundModel.data == null) { + if (soundModel.getData() == null) { Log.e(TAG, "KeyphraseSoundModel must have data"); return false; } - if (soundModel.keyphrases == null || soundModel.keyphrases.length != 1) { + if (soundModel.getKeyphrases() == null || soundModel.getKeyphrases().length != 1) { Log.e(TAG, "Keyphrase must be exactly 1"); return false; } - Keyphrase keyphrase = soundModel.keyphrases[0]; - if (keyphrase.id <= 0) { + Keyphrase keyphrase = soundModel.getKeyphrases()[0]; + if (keyphrase.getId() <= 0) { Log.e(TAG, "Keyphrase must have a valid ID"); return false; } - if (keyphrase.recognitionModes < 0) { + if (keyphrase.getRecognitionModes() < 0) { Log.e(TAG, "Recognition modes must be valid"); return false; } - if (keyphrase.locale == null) { + if (keyphrase.getLocale() == null) { Log.e(TAG, "Locale must not be null"); return false; } - if (keyphrase.text == null) { + if (keyphrase.getText() == null) { Log.e(TAG, "Text must not be null"); return false; } - if (keyphrase.users == null || keyphrase.users.length == 0) { + if (keyphrase.getUsers() == null || keyphrase.getUsers().length == 0) { Log.e(TAG, "Keyphrase must have valid user(s)"); return false; } diff --git a/tests/VoiceEnrollment/src/com/android/test/voiceenrollment/TestEnrollmentActivity.java b/tests/VoiceEnrollment/src/com/android/test/voiceenrollment/TestEnrollmentActivity.java index b357ad076c11..e4880fd10d67 100644 --- a/tests/VoiceEnrollment/src/com/android/test/voiceenrollment/TestEnrollmentActivity.java +++ b/tests/VoiceEnrollment/src/com/android/test/voiceenrollment/TestEnrollmentActivity.java @@ -91,7 +91,7 @@ public class TestEnrollmentActivity extends Activity { } boolean status = mEnrollmentUtil.deleteSoundModel(KEYPHRASE_ID, BCP47_LOCALE); if (status) { - Toast.makeText(this, "Successfully un-enrolled, model UUID=" + soundModel.uuid, + Toast.makeText(this, "Successfully un-enrolled, model UUID=" + soundModel.getUuid(), Toast.LENGTH_SHORT) .show(); } else { @@ -112,11 +112,11 @@ public class TestEnrollmentActivity extends Activity { // Generate a fake model to push. byte[] data = new byte[2048]; mRandom.nextBytes(data); - KeyphraseSoundModel updated = new KeyphraseSoundModel(soundModel.uuid, - soundModel.vendorUuid, data, soundModel.keyphrases); + KeyphraseSoundModel updated = new KeyphraseSoundModel(soundModel.getUuid(), + soundModel.getVendorUuid(), data, soundModel.getKeyphrases()); boolean status = mEnrollmentUtil.addOrUpdateSoundModel(updated); if (status) { - Toast.makeText(this, "Successfully re-enrolled, model UUID=" + updated.uuid, + Toast.makeText(this, "Successfully re-enrolled, model UUID=" + updated.getUuid(), Toast.LENGTH_SHORT) .show(); } else { |