remove SoundTrigger public member variables am: 1e43767f10 am: f5bd2f0b5c

Change-Id: I0d1350e737e11c6d8fe4f7b14dfc1c0d8f8ff858
This commit is contained in:
Nicholas Ambur
2020-03-27 21:30:16 +00:00
committed by Automerger Merge Worker
15 changed files with 513 additions and 395 deletions

View File

@@ -3575,23 +3575,23 @@ package android.hardware.soundtrigger {
public static final class SoundTrigger.Keyphrase implements android.os.Parcelable { public static final class SoundTrigger.Keyphrase implements android.os.Parcelable {
ctor public SoundTrigger.Keyphrase(int, int, @NonNull java.util.Locale, @NonNull String, @Nullable int[]); 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 @NonNull public static android.hardware.soundtrigger.SoundTrigger.Keyphrase readFromParcel(@NonNull android.os.Parcel);
method public void writeToParcel(@NonNull android.os.Parcel, int); 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 @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 { 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[], int);
ctor public SoundTrigger.KeyphraseSoundModel(@NonNull java.util.UUID, @NonNull java.util.UUID, @Nullable byte[], @Nullable android.hardware.soundtrigger.SoundTrigger.Keyphrase[]); 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 @NonNull public static android.hardware.soundtrigger.SoundTrigger.KeyphraseSoundModel readFromParcel(@NonNull android.os.Parcel);
method public void writeToParcel(@NonNull android.os.Parcel, int); 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 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 { 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 { public static final class SoundTrigger.ModuleProperties implements android.os.Parcelable {
method public int describeContents(); 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); 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_ECHO_CANCELLATION = 1; // 0x1
field public static final int AUDIO_CAPABILITY_NOISE_SUPPRESSION = 2; // 0x2 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 @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 { public static class SoundTrigger.RecognitionEvent {
@@ -3633,13 +3633,13 @@ package android.hardware.soundtrigger {
} }
public static class SoundTrigger.SoundModel { 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_GENERIC_SOUND = 1; // 0x1
field public static final int TYPE_KEYPHRASE = 0; // 0x0 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;
} }
} }

View File

@@ -106,11 +106,11 @@ class ConversionUtil {
public static SoundModel api2aidlSoundModel(SoundTrigger.SoundModel apiModel) { public static SoundModel api2aidlSoundModel(SoundTrigger.SoundModel apiModel) {
SoundModel aidlModel = new SoundModel(); SoundModel aidlModel = new SoundModel();
aidlModel.type = apiModel.type; aidlModel.type = apiModel.getType();
aidlModel.uuid = api2aidlUuid(apiModel.uuid); aidlModel.uuid = api2aidlUuid(apiModel.getUuid());
aidlModel.vendorUuid = api2aidlUuid(apiModel.vendorUuid); aidlModel.vendorUuid = api2aidlUuid(apiModel.getVendorUuid());
aidlModel.data = byteArrayToSharedMemory(apiModel.data, "SoundTrigger SoundModel"); aidlModel.data = byteArrayToSharedMemory(apiModel.getData(), "SoundTrigger SoundModel");
aidlModel.dataSize = apiModel.data.length; aidlModel.dataSize = apiModel.getData().length;
return aidlModel; return aidlModel;
} }
@@ -122,20 +122,20 @@ class ConversionUtil {
SoundTrigger.KeyphraseSoundModel apiModel) { SoundTrigger.KeyphraseSoundModel apiModel) {
PhraseSoundModel aidlModel = new PhraseSoundModel(); PhraseSoundModel aidlModel = new PhraseSoundModel();
aidlModel.common = api2aidlSoundModel(apiModel); aidlModel.common = api2aidlSoundModel(apiModel);
aidlModel.phrases = new Phrase[apiModel.keyphrases.length]; aidlModel.phrases = new Phrase[apiModel.getKeyphrases().length];
for (int i = 0; i < apiModel.keyphrases.length; ++i) { for (int i = 0; i < apiModel.getKeyphrases().length; ++i) {
aidlModel.phrases[i] = api2aidlPhrase(apiModel.keyphrases[i]); aidlModel.phrases[i] = api2aidlPhrase(apiModel.getKeyphrases()[i]);
} }
return aidlModel; return aidlModel;
} }
public static Phrase api2aidlPhrase(SoundTrigger.Keyphrase apiPhrase) { public static Phrase api2aidlPhrase(SoundTrigger.Keyphrase apiPhrase) {
Phrase aidlPhrase = new Phrase(); Phrase aidlPhrase = new Phrase();
aidlPhrase.id = apiPhrase.id; aidlPhrase.id = apiPhrase.getId();
aidlPhrase.recognitionModes = api2aidlRecognitionModes(apiPhrase.recognitionModes); aidlPhrase.recognitionModes = api2aidlRecognitionModes(apiPhrase.getRecognitionModes());
aidlPhrase.users = Arrays.copyOf(apiPhrase.users, apiPhrase.users.length); aidlPhrase.users = Arrays.copyOf(apiPhrase.getUsers(), apiPhrase.getUsers().length);
aidlPhrase.locale = apiPhrase.locale.toLanguageTag(); aidlPhrase.locale = apiPhrase.getLocale().toLanguageTag();
aidlPhrase.text = apiPhrase.text; aidlPhrase.text = apiPhrase.getText();
return aidlPhrase; return aidlPhrase;
} }

View File

@@ -104,76 +104,37 @@ public class SoundTrigger {
/** /**
* If set the underlying module supports AEC. * 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; public static final int AUDIO_CAPABILITY_ECHO_CANCELLATION = 0x1;
/** /**
* If set, the underlying module supports noise suppression. * 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; public static final int AUDIO_CAPABILITY_NOISE_SUPPRESSION = 0x2;
/** Unique module ID provided by the native service */ private final int mId;
public final int id;
/** human readable voice detection engine implementor */
@NonNull @NonNull
public final String implementor; private final String mImplementor;
/** human readable voice detection engine description */
@NonNull @NonNull
public final String description; private final String mDescription;
/** Unique voice engine Id (changes with each version) */
@NonNull @NonNull
public final UUID uuid; private final UUID mUuid;
private final int mVersion;
/** Voice detection engine version */
public final int version;
/**
* String naming the architecture used for running the supported models.
* (eg. a platform running models on a DSP could implement this string to convey the DSP
* architecture used)
*/
@NonNull @NonNull
public final String supportedModelArch; private final String mSupportedModelArch;
private final int mMaxSoundModels;
/** Maximum number of active sound models */ private final int mMaxKeyphrases;
public final int maxSoundModels; private final int mMaxUsers;
/** Maximum number of key phrases */
public final int maxKeyphrases;
/** Maximum number of users per key phrase */
public final int maxUsers;
/** Supported recognition modes (bit field, RECOGNITION_MODE_VOICE_TRIGGER ...) */
@RecognitionModes @RecognitionModes
public final int recognitionModes; private final int mRecognitionModes;
private final boolean mSupportsCaptureTransition;
/** Supports seamless transition to capture mode after recognition */ private final int mMaxBufferMillis;
public final boolean supportsCaptureTransition; private final boolean mSupportsConcurrentCapture;
private final int mPowerConsumptionMw;
/** Maximum buffering capacity in ms if supportsCaptureTransition() is true */ private final boolean mReturnsTriggerInEvent;
public final int maxBufferMs;
/** Supports capture by other use cases while detection is active */
public final boolean supportsConcurrentCapture;
/** Rated power consumption when detection is active with TDB silence/sound/speech ratio */
public final int powerConsumptionMw;
/** Returns the trigger (key phrase) capture in the binary data of the
* recognition callback event */
public final boolean returnsTriggerInEvent;
/**
* Bit field encoding of the AudioCapabilities
* supported by the firmware.
*/
@AudioCapabilities @AudioCapabilities
public final int audioCapabilities; private final int mAudioCapabilities;
ModuleProperties(int id, @NonNull String implementor, @NonNull String description, ModuleProperties(int id, @NonNull String implementor, @NonNull String description,
@NonNull String uuid, int version, @NonNull String supportedModelArch, @NonNull String uuid, int version, @NonNull String supportedModelArch,
@@ -181,22 +142,116 @@ public class SoundTrigger {
@RecognitionModes int recognitionModes, boolean supportsCaptureTransition, @RecognitionModes int recognitionModes, boolean supportsCaptureTransition,
int maxBufferMs, boolean supportsConcurrentCapture, int powerConsumptionMw, int maxBufferMs, boolean supportsConcurrentCapture, int powerConsumptionMw,
boolean returnsTriggerInEvent, int audioCapabilities) { boolean returnsTriggerInEvent, int audioCapabilities) {
this.id = id; this.mId = id;
this.implementor = requireNonNull(implementor); this.mImplementor = requireNonNull(implementor);
this.description = requireNonNull(description); this.mDescription = requireNonNull(description);
this.uuid = UUID.fromString(requireNonNull(uuid)); this.mUuid = UUID.fromString(requireNonNull(uuid));
this.version = version; this.mVersion = version;
this.supportedModelArch = requireNonNull(supportedModelArch); this.mSupportedModelArch = requireNonNull(supportedModelArch);
this.maxSoundModels = maxSoundModels; this.mMaxSoundModels = maxSoundModels;
this.maxKeyphrases = maxKeyphrases; this.mMaxKeyphrases = maxKeyphrases;
this.maxUsers = maxUsers; this.mMaxUsers = maxUsers;
this.recognitionModes = recognitionModes; this.mRecognitionModes = recognitionModes;
this.supportsCaptureTransition = supportsCaptureTransition; this.mSupportsCaptureTransition = supportsCaptureTransition;
this.maxBufferMs = maxBufferMs; this.mMaxBufferMillis = maxBufferMs;
this.supportsConcurrentCapture = supportsConcurrentCapture; this.mSupportsConcurrentCapture = supportsConcurrentCapture;
this.powerConsumptionMw = powerConsumptionMw; this.mPowerConsumptionMw = powerConsumptionMw;
this.returnsTriggerInEvent = returnsTriggerInEvent; this.mReturnsTriggerInEvent = returnsTriggerInEvent;
this.audioCapabilities = audioCapabilities; this.mAudioCapabilities = audioCapabilities;
}
/** Unique module ID provided by the native service */
public int getId() {
return mId;
}
/** human readable voice detection engine implementor */
@NonNull
public String getImplementor() {
return mImplementor;
}
/** human readable voice detection engine description */
@NonNull
public String getDescription() {
return mDescription;
}
/** Unique voice engine Id (changes with each version) */
@NonNull
public UUID getUuid() {
return mUuid;
}
/** Voice detection engine version */
public int getVersion() {
return mVersion;
}
/**
* String naming the architecture used for running the supported models.
* (eg. a platform running models on a DSP could implement this string to convey the DSP
* architecture used)
*/
@NonNull
public String getSupportedModelArch() {
return mSupportedModelArch;
}
/** Maximum number of active sound models */
public int getMaxSoundModels() {
return mMaxSoundModels;
}
/** Maximum number of key phrases */
public int getMaxKeyphrases() {
return mMaxKeyphrases;
}
/** Maximum number of users per key phrase */
public int getMaxUsers() {
return mMaxUsers;
}
/** Supported recognition modes (bit field, RECOGNITION_MODE_VOICE_TRIGGER ...) */
@RecognitionModes
public int getRecognitionModes() {
return mRecognitionModes;
}
/** Supports seamless transition to capture mode after recognition */
public boolean isCaptureTransitionSupported() {
return mSupportsCaptureTransition;
}
/** Maximum buffering capacity in ms if supportsCaptureTransition() is true */
public int getMaxBufferMillis() {
return mMaxBufferMillis;
}
/** Supports capture by other use cases while detection is active */
public boolean isConcurrentCaptureSupported() {
return mSupportsConcurrentCapture;
}
/** Rated power consumption when detection is active with TDB silence/sound/speech ratio */
public int getPowerConsumptionMw() {
return mPowerConsumptionMw;
}
/** Returns the trigger (key phrase) capture in the binary data of the
* recognition callback event */
public boolean isTriggerReturnedInEvent() {
return mReturnsTriggerInEvent;
}
/**
* Bit field encoding of the AudioCapabilities
* supported by the firmware.
*/
@AudioCapabilities
public int getAudioCapabilities() {
return mAudioCapabilities;
} }
public static final @android.annotation.NonNull Parcelable.Creator<ModuleProperties> CREATOR public static final @android.annotation.NonNull Parcelable.Creator<ModuleProperties> CREATOR
@@ -235,22 +290,22 @@ public class SoundTrigger {
@Override @Override
public void writeToParcel(Parcel dest, int flags) { public void writeToParcel(Parcel dest, int flags) {
dest.writeInt(id); dest.writeInt(getId());
dest.writeString(implementor); dest.writeString(getImplementor());
dest.writeString(description); dest.writeString(getDescription());
dest.writeString(uuid.toString()); dest.writeString(getUuid().toString());
dest.writeInt(version); dest.writeInt(getVersion());
dest.writeString(supportedModelArch); dest.writeString(getSupportedModelArch());
dest.writeInt(maxSoundModels); dest.writeInt(getMaxSoundModels());
dest.writeInt(maxKeyphrases); dest.writeInt(getMaxKeyphrases());
dest.writeInt(maxUsers); dest.writeInt(getMaxUsers());
dest.writeInt(recognitionModes); dest.writeInt(getRecognitionModes());
dest.writeByte((byte) (supportsCaptureTransition ? 1 : 0)); dest.writeByte((byte) (isCaptureTransitionSupported() ? 1 : 0));
dest.writeInt(maxBufferMs); dest.writeInt(getMaxBufferMillis());
dest.writeByte((byte) (supportsConcurrentCapture ? 1 : 0)); dest.writeByte((byte) (isConcurrentCaptureSupported() ? 1 : 0));
dest.writeInt(powerConsumptionMw); dest.writeInt(getPowerConsumptionMw());
dest.writeByte((byte) (returnsTriggerInEvent ? 1 : 0)); dest.writeByte((byte) (isTriggerReturnedInEvent() ? 1 : 0));
dest.writeInt(audioCapabilities); dest.writeInt(getAudioCapabilities());
} }
@Override @Override
@@ -260,16 +315,17 @@ public class SoundTrigger {
@Override @Override
public String toString() { public String toString() {
return "ModuleProperties [id=" + id + ", implementor=" + implementor + ", description=" return "ModuleProperties [id=" + getId() + ", implementor=" + getImplementor()
+ description + ", uuid=" + uuid + ", version=" + version + ", description=" + getDescription() + ", uuid=" + getUuid()
+ " , supportedModelArch=" + supportedModelArch + ", maxSoundModels=" + ", version=" + getVersion() + " , supportedModelArch="
+ maxSoundModels + ", maxKeyphrases=" + maxKeyphrases + ", maxUsers=" + getSupportedModelArch() + ", maxSoundModels=" + getMaxSoundModels()
+ maxUsers + ", recognitionModes=" + recognitionModes + ", maxKeyphrases=" + getMaxKeyphrases() + ", maxUsers=" + getMaxUsers()
+ ", supportsCaptureTransition=" + supportsCaptureTransition + ", maxBufferMs=" + ", recognitionModes=" + getRecognitionModes() + ", supportsCaptureTransition="
+ maxBufferMs + ", supportsConcurrentCapture=" + supportsConcurrentCapture + isCaptureTransitionSupported() + ", maxBufferMs=" + getMaxBufferMillis()
+ ", powerConsumptionMw=" + powerConsumptionMw + ", supportsConcurrentCapture=" + isConcurrentCaptureSupported()
+ ", returnsTriggerInEvent=" + returnsTriggerInEvent + ", powerConsumptionMw=" + getPowerConsumptionMw()
+ ", audioCapabilities=" + audioCapabilities + "]"; + ", returnsTriggerInEvent=" + isTriggerReturnedInEvent()
+ ", audioCapabilities=" + getAudioCapabilities() + "]";
} }
} }
@@ -305,44 +361,64 @@ public class SoundTrigger {
*/ */
public static final int TYPE_GENERIC_SOUND = 1; public static final int TYPE_GENERIC_SOUND = 1;
/** Unique sound model identifier */
@NonNull @NonNull
public final UUID uuid; private final UUID mUuid;
/** Sound model type (e.g. TYPE_KEYPHRASE); */
@SoundModelType @SoundModelType
public final int type; private final int mType;
/** Unique sound model vendor identifier */
@NonNull @NonNull
public final UUID vendorUuid; private final UUID mVendorUuid;
private final int mVersion;
/** vendor specific version number of the model */
public final int version;
/** Opaque data. For use by vendor implementation and enrollment application */
@NonNull @NonNull
public final byte[] data; private final byte[] mData;
/** @hide */ /** @hide */
public SoundModel(@NonNull UUID uuid, @Nullable UUID vendorUuid, @SoundModelType int type, public SoundModel(@NonNull UUID uuid, @Nullable UUID vendorUuid, @SoundModelType int type,
@Nullable byte[] data, int version) { @Nullable byte[] data, int version) {
this.uuid = requireNonNull(uuid); this.mUuid = requireNonNull(uuid);
this.vendorUuid = vendorUuid != null ? vendorUuid : new UUID(0, 0); this.mVendorUuid = vendorUuid != null ? vendorUuid : new UUID(0, 0);
this.type = type; this.mType = type;
this.version = version; this.mVersion = version;
this.data = data != null ? data : new byte[0]; this.mData = data != null ? data : new byte[0];
}
/** Unique sound model identifier */
@NonNull
public UUID getUuid() {
return mUuid;
}
/** Sound model type (e.g. TYPE_KEYPHRASE); */
@SoundModelType
public int getType() {
return mType;
}
/** Unique sound model vendor identifier */
@NonNull
public UUID getVendorUuid() {
return mVendorUuid;
}
/** vendor specific version number of the model */
public int getVersion() {
return mVersion;
}
/** Opaque data. For use by vendor implementation and enrollment application */
@NonNull
public byte[] getData() {
return mData;
} }
@Override @Override
public int hashCode() { public int hashCode() {
final int prime = 31; final int prime = 31;
int result = 1; int result = 1;
result = prime * result + version; result = prime * result + getVersion();
result = prime * result + Arrays.hashCode(data); result = prime * result + Arrays.hashCode(getData());
result = prime * result + type; result = prime * result + getType();
result = prime * result + ((uuid == null) ? 0 : uuid.hashCode()); result = prime * result + ((getUuid() == null) ? 0 : getUuid().hashCode());
result = prime * result + ((vendorUuid == null) ? 0 : vendorUuid.hashCode()); result = prime * result + ((getVendorUuid() == null) ? 0 : getVendorUuid().hashCode());
return result; return result;
} }
@@ -358,27 +434,27 @@ public class SoundTrigger {
return false; return false;
} }
SoundModel other = (SoundModel) obj; SoundModel other = (SoundModel) obj;
if (type != other.type) { if (getType() != other.getType()) {
return false; return false;
} }
if (uuid == null) { if (getUuid() == null) {
if (other.uuid != null) { if (other.getUuid() != null) {
return false; return false;
} }
} else if (!uuid.equals(other.uuid)) { } else if (!getUuid().equals(other.getUuid())) {
return false; return false;
} }
if (vendorUuid == null) { if (getVendorUuid() == null) {
if (other.vendorUuid != null) { if (other.getVendorUuid() != null) {
return false; return false;
} }
} else if (!vendorUuid.equals(other.vendorUuid)) { } else if (!getVendorUuid().equals(other.getVendorUuid())) {
return false; return false;
} }
if (!Arrays.equals(data, other.data)) { if (!Arrays.equals(getData(), other.getData())) {
return false; return false;
} }
if (version != other.version) { if (getVersion() != other.getVersion()) {
return false; return false;
} }
return true; return true;
@@ -390,34 +466,16 @@ public class SoundTrigger {
* {@link KeyphraseSoundModel} * {@link KeyphraseSoundModel}
*/ */
public static final class Keyphrase implements Parcelable { public static final class Keyphrase implements Parcelable {
/** Unique identifier for this keyphrase */
public final int id;
/** private final int mId;
* Recognition modes supported for this key phrase in the model
*
* @see #RECOGNITION_MODE_VOICE_TRIGGER
* @see #RECOGNITION_MODE_USER_IDENTIFICATION
* @see #RECOGNITION_MODE_USER_AUTHENTICATION
* @see #RECOGNITION_MODE_GENERIC
*/
@RecognitionModes @RecognitionModes
public final int recognitionModes; private final int mRecognitionModes;
/** Locale of the keyphrase. */
@NonNull @NonNull
public final Locale locale; private final Locale mLocale;
/** Key phrase text */
@NonNull @NonNull
public final String text; private final String 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 @NonNull
public final int[] users; private final int[] mUsers;
/** /**
* Constructor for Keyphrase describes a key phrase that can be detected by a * Constructor for Keyphrase describes a key phrase that can be detected by a
@@ -432,11 +490,50 @@ public class SoundTrigger {
*/ */
public Keyphrase(int id, @RecognitionModes int recognitionModes, @NonNull Locale locale, public Keyphrase(int id, @RecognitionModes int recognitionModes, @NonNull Locale locale,
@NonNull String text, @Nullable int[] users) { @NonNull String text, @Nullable int[] users) {
this.id = id; this.mId = id;
this.recognitionModes = recognitionModes; this.mRecognitionModes = recognitionModes;
this.locale = requireNonNull(locale); this.mLocale = requireNonNull(locale);
this.text = requireNonNull(text); this.mText = requireNonNull(text);
this.users = users != null ? users : new int[0]; this.mUsers = users != null ? users : new int[0];
}
/** Unique identifier for this keyphrase */
public int getId() {
return mId;
}
/**
* Recognition modes supported for this key phrase in the model
*
* @see #RECOGNITION_MODE_VOICE_TRIGGER
* @see #RECOGNITION_MODE_USER_IDENTIFICATION
* @see #RECOGNITION_MODE_USER_AUTHENTICATION
* @see #RECOGNITION_MODE_GENERIC
*/
@RecognitionModes
public int getRecognitionModes() {
return mRecognitionModes;
}
/** Locale of the keyphrase. */
@NonNull
public Locale getLocale() {
return mLocale;
}
/** Key phrase text */
@NonNull
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 int[] getUsers() {
return mUsers;
} }
public static final @NonNull Parcelable.Creator<Keyphrase> CREATOR = public static final @NonNull Parcelable.Creator<Keyphrase> CREATOR =
@@ -472,13 +569,13 @@ public class SoundTrigger {
@Override @Override
public void writeToParcel(@NonNull Parcel dest, int flags) { public void writeToParcel(@NonNull Parcel dest, int flags) {
dest.writeInt(id); dest.writeInt(getId());
dest.writeInt(recognitionModes); dest.writeInt(getRecognitionModes());
dest.writeString(locale.toLanguageTag()); dest.writeString(getLocale().toLanguageTag());
dest.writeString(text); dest.writeString(getText());
if (users != null) { if (getUsers() != null) {
dest.writeInt(users.length); dest.writeInt(getUsers().length);
dest.writeIntArray(users); dest.writeIntArray(getUsers());
} else { } else {
dest.writeInt(-1); dest.writeInt(-1);
} }
@@ -494,11 +591,11 @@ public class SoundTrigger {
public int hashCode() { public int hashCode() {
final int prime = 31; final int prime = 31;
int result = 1; int result = 1;
result = prime * result + ((text == null) ? 0 : text.hashCode()); result = prime * result + ((getText() == null) ? 0 : getText().hashCode());
result = prime * result + id; result = prime * result + getId();
result = prime * result + ((locale == null) ? 0 : locale.hashCode()); result = prime * result + ((getLocale() == null) ? 0 : getLocale().hashCode());
result = prime * result + recognitionModes; result = prime * result + getRecognitionModes();
result = prime * result + Arrays.hashCode(users); result = prime * result + Arrays.hashCode(getUsers());
return result; return result;
} }
@@ -514,27 +611,27 @@ public class SoundTrigger {
return false; return false;
} }
Keyphrase other = (Keyphrase) obj; Keyphrase other = (Keyphrase) obj;
if (text == null) { if (getText() == null) {
if (other.text != null) { if (other.getText() != null) {
return false; return false;
} }
} else if (!text.equals(other.text)) { } else if (!getText().equals(other.getText())) {
return false; return false;
} }
if (id != other.id) { if (getId() != other.getId()) {
return false; return false;
} }
if (locale == null) { if (getLocale() == null) {
if (other.locale != null) { if (other.getLocale() != null) {
return false; return false;
} }
} else if (!locale.equals(other.locale)) { } else if (!getLocale().equals(other.getLocale())) {
return false; return false;
} }
if (recognitionModes != other.recognitionModes) { if (getRecognitionModes() != other.getRecognitionModes()) {
return false; return false;
} }
if (!Arrays.equals(users, other.users)) { if (!Arrays.equals(getUsers(), other.getUsers())) {
return false; return false;
} }
return true; return true;
@@ -542,9 +639,9 @@ public class SoundTrigger {
@Override @Override
public String toString() { public String toString() {
return "Keyphrase [id=" + id + ", recognitionModes=" + recognitionModes return "Keyphrase [id=" + getId() + ", recognitionModes=" + getRecognitionModes()
+ ", locale=" + locale.toLanguageTag() + ", text=" + text + ", locale=" + getLocale().toLanguageTag() + ", text=" + getText()
+ ", users=" + Arrays.toString(users) + "]"; + ", users=" + Arrays.toString(getUsers()) + "]";
} }
} }
@@ -554,15 +651,15 @@ public class SoundTrigger {
* and the list of corresponding {@link Keyphrase} descriptors. * and the list of corresponding {@link Keyphrase} descriptors.
*/ */
public static final class KeyphraseSoundModel extends SoundModel implements Parcelable { public static final class KeyphraseSoundModel extends SoundModel implements Parcelable {
/** Key phrases in this sound model */
@NonNull @NonNull
public final Keyphrase[] keyphrases; // keyword phrases in model private final Keyphrase[] mKeyphrases;
public KeyphraseSoundModel( public KeyphraseSoundModel(
@NonNull UUID uuid, @NonNull UUID vendorUuid, @Nullable byte[] data, @NonNull UUID uuid, @NonNull UUID vendorUuid, @Nullable byte[] data,
@Nullable Keyphrase[] keyphrases, int version) { @Nullable Keyphrase[] keyphrases, int version) {
super(uuid, vendorUuid, TYPE_KEYPHRASE, data, 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, public KeyphraseSoundModel(@NonNull UUID uuid, @NonNull UUID vendorUuid,
@@ -570,6 +667,12 @@ public class SoundTrigger {
this(uuid, vendorUuid, data, keyphrases, -1); 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 = public static final @NonNull Parcelable.Creator<KeyphraseSoundModel> CREATOR =
new Parcelable.Creator<KeyphraseSoundModel>() { new Parcelable.Creator<KeyphraseSoundModel>() {
@NonNull @NonNull
@@ -608,32 +711,32 @@ public class SoundTrigger {
@Override @Override
public void writeToParcel(@NonNull Parcel dest, int flags) { public void writeToParcel(@NonNull Parcel dest, int flags) {
dest.writeString(uuid.toString()); dest.writeString(getUuid().toString());
if (vendorUuid == null) { if (getVendorUuid() == null) {
dest.writeInt(-1); dest.writeInt(-1);
} else { } else {
dest.writeInt(vendorUuid.toString().length()); dest.writeInt(getVendorUuid().toString().length());
dest.writeString(vendorUuid.toString()); dest.writeString(getVendorUuid().toString());
} }
dest.writeInt(version); dest.writeInt(getVersion());
dest.writeBlob(data); dest.writeBlob(getData());
dest.writeTypedArray(keyphrases, flags); dest.writeTypedArray(getKeyphrases(), flags);
} }
@Override @Override
public String toString() { public String toString() {
return "KeyphraseSoundModel [keyphrases=" + Arrays.toString(keyphrases) return "KeyphraseSoundModel [keyphrases=" + Arrays.toString(getKeyphrases())
+ ", uuid=" + uuid + ", vendorUuid=" + vendorUuid + ", uuid=" + getUuid() + ", vendorUuid=" + getVendorUuid()
+ ", type=" + type + ", type=" + getType()
+ ", data=" + (data == null ? 0 : data.length) + ", data=" + (getData() == null ? 0 : getData().length)
+ ", version=" + version + "]"; + ", version=" + getVersion() + "]";
} }
@Override @Override
public int hashCode() { public int hashCode() {
final int prime = 31; final int prime = 31;
int result = super.hashCode(); int result = super.hashCode();
result = prime * result + Arrays.hashCode(keyphrases); result = prime * result + Arrays.hashCode(getKeyphrases());
return result; return result;
} }
@@ -649,7 +752,7 @@ public class SoundTrigger {
return false; return false;
} }
KeyphraseSoundModel other = (KeyphraseSoundModel) obj; KeyphraseSoundModel other = (KeyphraseSoundModel) obj;
if (!Arrays.equals(keyphrases, other.keyphrases)) { if (!Arrays.equals(getKeyphrases(), other.getKeyphrases())) {
return false; return false;
} }
return true; return true;
@@ -706,23 +809,23 @@ public class SoundTrigger {
@Override @Override
public void writeToParcel(Parcel dest, int flags) { public void writeToParcel(Parcel dest, int flags) {
dest.writeString(uuid.toString()); dest.writeString(getUuid().toString());
if (vendorUuid == null) { if (getVendorUuid() == null) {
dest.writeInt(-1); dest.writeInt(-1);
} else { } else {
dest.writeInt(vendorUuid.toString().length()); dest.writeInt(getVendorUuid().toString().length());
dest.writeString(vendorUuid.toString()); dest.writeString(getVendorUuid().toString());
} }
dest.writeBlob(data); dest.writeBlob(getData());
dest.writeInt(version); dest.writeInt(getVersion());
} }
@Override @Override
public String toString() { public String toString() {
return "GenericSoundModel [uuid=" + uuid + ", vendorUuid=" + vendorUuid return "GenericSoundModel [uuid=" + getUuid() + ", vendorUuid=" + getVendorUuid()
+ ", type=" + type + ", type=" + getType()
+ ", data=" + (data == null ? 0 : data.length) + ", data=" + (getData() == null ? 0 : getData().length)
+ ", version=" + version + "]"; + ", version=" + getVersion() + "]";
} }
} }
@@ -1825,7 +1928,7 @@ public class SoundTrigger {
/** /**
* Get an interface on a hardware module to control sound models and recognition on * Get an interface on a hardware module to control sound models and recognition on
* this module. * 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 listener {@link StatusListener} interface. Mandatory.
* @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.

View File

@@ -487,7 +487,7 @@ public class AlwaysOnHotwordDetector {
ModuleProperties properties = ModuleProperties properties =
mModelManagementService.getDspModuleProperties(); mModelManagementService.getDspModuleProperties();
if (properties != null) { if (properties != null) {
return properties.audioCapabilities; return properties.getAudioCapabilities();
} }
return 0; return 0;

View File

@@ -211,7 +211,7 @@ public final class SoundTriggerManager {
*/ */
@NonNull @NonNull
public UUID getModelUuid() { public UUID getModelUuid() {
return mGenericSoundModel.uuid; return mGenericSoundModel.getUuid();
} }
/** /**
@@ -221,7 +221,7 @@ public final class SoundTriggerManager {
*/ */
@NonNull @NonNull
public UUID getVendorUuid() { public UUID getVendorUuid() {
return mGenericSoundModel.vendorUuid; return mGenericSoundModel.getVendorUuid();
} }
/** /**
@@ -230,7 +230,7 @@ public final class SoundTriggerManager {
* @return Version associated with the model * @return Version associated with the model
*/ */
public int getVersion() { public int getVersion() {
return mGenericSoundModel.version; return mGenericSoundModel.getVersion();
} }
/** /**
@@ -240,7 +240,7 @@ public final class SoundTriggerManager {
*/ */
@Nullable @Nullable
public byte[] getModelData() { public byte[] getModelData() {
return mGenericSoundModel.data; return mGenericSoundModel.getData();
} }
/** /**
@@ -307,7 +307,7 @@ public final class SoundTriggerManager {
} }
try { try {
switch (soundModel.type) { switch (soundModel.getType()) {
case SoundModel.TYPE_GENERIC_SOUND: case SoundModel.TYPE_GENERIC_SOUND:
return mSoundTriggerService.loadGenericSoundModel( return mSoundTriggerService.loadGenericSoundModel(
(GenericSoundModel) soundModel); (GenericSoundModel) soundModel);

View File

@@ -86,10 +86,11 @@ public class SoundTriggerDbHelper extends SQLiteOpenHelper {
synchronized(this) { synchronized(this) {
SQLiteDatabase db = getWritableDatabase(); SQLiteDatabase db = getWritableDatabase();
ContentValues values = new ContentValues(); ContentValues values = new ContentValues();
values.put(GenericSoundModelContract.KEY_MODEL_UUID, soundModel.uuid.toString()); values.put(GenericSoundModelContract.KEY_MODEL_UUID, soundModel.getUuid().toString());
values.put(GenericSoundModelContract.KEY_VENDOR_UUID, soundModel.vendorUuid.toString()); values.put(GenericSoundModelContract.KEY_VENDOR_UUID,
values.put(GenericSoundModelContract.KEY_DATA, soundModel.data); soundModel.getVendorUuid().toString());
values.put(GenericSoundModelContract.KEY_MODEL_VERSION, soundModel.version); values.put(GenericSoundModelContract.KEY_DATA, soundModel.getData());
values.put(GenericSoundModelContract.KEY_MODEL_VERSION, soundModel.getVersion());
try { try {
return db.insertWithOnConflict(GenericSoundModelContract.TABLE, null, values, 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. // Delete all sound models for the given keyphrase and specified user.
SQLiteDatabase db = getWritableDatabase(); SQLiteDatabase db = getWritableDatabase();
String soundModelClause = GenericSoundModelContract.KEY_MODEL_UUID String soundModelClause = GenericSoundModelContract.KEY_MODEL_UUID
+ "='" + soundModel.uuid.toString() + "'"; + "='" + soundModel.getUuid().toString() + "'";
try { try {
return db.delete(GenericSoundModelContract.TABLE, soundModelClause, null) != 0; return db.delete(GenericSoundModelContract.TABLE, soundModelClause, null) != 0;
} finally { } finally {

View File

@@ -195,7 +195,7 @@ public class SoundTriggerHelper implements SoundTrigger.StatusListener {
} }
// Process existing model first. // 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. // The existing model has a different UUID, should be replaced.
int status = cleanUpExistingKeyphraseModelLocked(model); int status = cleanUpExistingKeyphraseModelLocked(model);
if (status != STATUS_OK) { 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 // 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. // or the existing model had a different UUID and was cleaned up.
if (model == null) { if (model == null) {
model = createKeyphraseModelDataLocked(soundModel.uuid, keyphraseId); model = createKeyphraseModelDataLocked(soundModel.getUuid(), keyphraseId);
} }
return startRecognition(soundModel, model, callback, recognitionConfig, return startRecognition(soundModel, model, callback, recognitionConfig,
@@ -249,7 +249,7 @@ public class SoundTriggerHelper implements SoundTrigger.StatusListener {
return STATUS_ERROR; return STATUS_ERROR;
} }
if (mModule == null) { if (mModule == null) {
mModule = SoundTrigger.attachModule(mModuleProperties.id, this, null); mModule = SoundTrigger.attachModule(mModuleProperties.getId(), this, null);
if (mModule == null) { if (mModule == null) {
Slog.w(TAG, "startRecognition cannot attach to sound trigger module"); Slog.w(TAG, "startRecognition cannot attach to sound trigger module");
return STATUS_ERROR; return STATUS_ERROR;

View File

@@ -358,7 +358,7 @@ public class SoundTriggerService extends SystemService {
public int loadGenericSoundModel(GenericSoundModel soundModel) { public int loadGenericSoundModel(GenericSoundModel soundModel) {
enforceCallingPermission(Manifest.permission.MANAGE_SOUND_TRIGGER); enforceCallingPermission(Manifest.permission.MANAGE_SOUND_TRIGGER);
if (!isInitialized()) return STATUS_ERROR; if (!isInitialized()) return STATUS_ERROR;
if (soundModel == null || soundModel.uuid == null) { if (soundModel == null || soundModel.getUuid() == null) {
Slog.e(TAG, "Invalid sound model"); Slog.e(TAG, "Invalid sound model");
sEventLogger.log(new SoundTriggerLogger.StringEvent( sEventLogger.log(new SoundTriggerLogger.StringEvent(
@@ -367,24 +367,24 @@ public class SoundTriggerService extends SystemService {
return STATUS_ERROR; return STATUS_ERROR;
} }
if (DEBUG) { if (DEBUG) {
Slog.i(TAG, "loadGenericSoundModel(): id = " + soundModel.uuid); Slog.i(TAG, "loadGenericSoundModel(): id = " + soundModel.getUuid());
} }
sEventLogger.log(new SoundTriggerLogger.StringEvent("loadGenericSoundModel(): id = " sEventLogger.log(new SoundTriggerLogger.StringEvent("loadGenericSoundModel(): id = "
+ soundModel.uuid)); + soundModel.getUuid()));
synchronized (mLock) { 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 // 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 // should unload that other model now. We don't care about return codes since we
// don't know if the other model is loaded. // don't know if the other model is loaded.
if (oldModel != null && !oldModel.equals(soundModel)) { if (oldModel != null && !oldModel.equals(soundModel)) {
mSoundTriggerHelper.unloadGenericSoundModel(soundModel.uuid); mSoundTriggerHelper.unloadGenericSoundModel(soundModel.getUuid());
synchronized (mCallbacksLock) { synchronized (mCallbacksLock) {
mCallbacks.remove(soundModel.uuid); mCallbacks.remove(soundModel.getUuid());
} }
} }
mLoadedModels.put(soundModel.uuid, soundModel); mLoadedModels.put(soundModel.getUuid(), soundModel);
} }
return STATUS_OK; return STATUS_OK;
} }
@@ -393,7 +393,7 @@ public class SoundTriggerService extends SystemService {
public int loadKeyphraseSoundModel(KeyphraseSoundModel soundModel) { public int loadKeyphraseSoundModel(KeyphraseSoundModel soundModel) {
enforceCallingPermission(Manifest.permission.MANAGE_SOUND_TRIGGER); enforceCallingPermission(Manifest.permission.MANAGE_SOUND_TRIGGER);
if (!isInitialized()) return STATUS_ERROR; if (!isInitialized()) return STATUS_ERROR;
if (soundModel == null || soundModel.uuid == null) { if (soundModel == null || soundModel.getUuid() == null) {
Slog.e(TAG, "Invalid sound model"); Slog.e(TAG, "Invalid sound model");
sEventLogger.log(new SoundTriggerLogger.StringEvent( sEventLogger.log(new SoundTriggerLogger.StringEvent(
@@ -401,7 +401,7 @@ public class SoundTriggerService extends SystemService {
return STATUS_ERROR; 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."); Slog.e(TAG, "Only one keyphrase per model is currently supported.");
sEventLogger.log(new SoundTriggerLogger.StringEvent( sEventLogger.log(new SoundTriggerLogger.StringEvent(
@@ -411,24 +411,25 @@ public class SoundTriggerService extends SystemService {
return STATUS_ERROR; return STATUS_ERROR;
} }
if (DEBUG) { if (DEBUG) {
Slog.i(TAG, "loadKeyphraseSoundModel(): id = " + soundModel.uuid); Slog.i(TAG, "loadKeyphraseSoundModel(): id = " + soundModel.getUuid());
} }
sEventLogger.log(new SoundTriggerLogger.StringEvent("loadKeyphraseSoundModel(): id = " sEventLogger.log(new SoundTriggerLogger.StringEvent("loadKeyphraseSoundModel(): id = "
+ soundModel.uuid)); + soundModel.getUuid()));
synchronized (mLock) { 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 // 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 // should unload that other model now. We don't care about return codes since we
// don't know if the other model is loaded. // don't know if the other model is loaded.
if (oldModel != null && !oldModel.equals(soundModel)) { if (oldModel != null && !oldModel.equals(soundModel)) {
mSoundTriggerHelper.unloadKeyphraseSoundModel(soundModel.keyphrases[0].id); mSoundTriggerHelper.unloadKeyphraseSoundModel(
soundModel.getKeyphrases()[0].getId());
synchronized (mCallbacksLock) { synchronized (mCallbacksLock) {
mCallbacks.remove(soundModel.uuid); mCallbacks.remove(soundModel.getUuid());
} }
} }
mLoadedModels.put(soundModel.uuid, soundModel); mLoadedModels.put(soundModel.getUuid(), soundModel);
} }
return STATUS_OK; return STATUS_OK;
} }
@@ -478,9 +479,9 @@ public class SoundTriggerService extends SystemService {
return STATUS_ERROR; return STATUS_ERROR;
} }
int ret; int ret;
switch (soundModel.type) { switch (soundModel.getType()) {
case SoundModel.TYPE_GENERIC_SOUND: case SoundModel.TYPE_GENERIC_SOUND:
ret = mSoundTriggerHelper.startGenericRecognition(soundModel.uuid, ret = mSoundTriggerHelper.startGenericRecognition(soundModel.getUuid(),
(GenericSoundModel) soundModel, callback, config); (GenericSoundModel) soundModel, callback, config);
break; break;
default: default:
@@ -545,9 +546,10 @@ public class SoundTriggerService extends SystemService {
return STATUS_ERROR; return STATUS_ERROR;
} }
int ret; int ret;
switch (soundModel.type) { switch (soundModel.getType()) {
case SoundModel.TYPE_GENERIC_SOUND: case SoundModel.TYPE_GENERIC_SOUND:
ret = mSoundTriggerHelper.stopGenericRecognition(soundModel.uuid, callback); ret = mSoundTriggerHelper.stopGenericRecognition(
soundModel.getUuid(), callback);
break; break;
default: default:
Slog.e(TAG, "Unknown model type"); Slog.e(TAG, "Unknown model type");
@@ -597,13 +599,13 @@ public class SoundTriggerService extends SystemService {
return STATUS_ERROR; return STATUS_ERROR;
} }
int ret; int ret;
switch (soundModel.type) { switch (soundModel.getType()) {
case SoundModel.TYPE_KEYPHRASE: case SoundModel.TYPE_KEYPHRASE:
ret = mSoundTriggerHelper.unloadKeyphraseSoundModel( ret = mSoundTriggerHelper.unloadKeyphraseSoundModel(
((KeyphraseSoundModel)soundModel).keyphrases[0].id); ((KeyphraseSoundModel) soundModel).getKeyphrases()[0].getId());
break; break;
case SoundModel.TYPE_GENERIC_SOUND: case SoundModel.TYPE_GENERIC_SOUND:
ret = mSoundTriggerHelper.unloadGenericSoundModel(soundModel.uuid); ret = mSoundTriggerHelper.unloadGenericSoundModel(soundModel.getUuid());
break; break;
default: default:
Slog.e(TAG, "Unknown model type"); Slog.e(TAG, "Unknown model type");
@@ -661,16 +663,16 @@ public class SoundTriggerService extends SystemService {
return ret; return ret;
} }
switch (soundModel.type) { switch (soundModel.getType()) {
case SoundModel.TYPE_GENERIC_SOUND: case SoundModel.TYPE_GENERIC_SOUND:
ret = mSoundTriggerHelper.getGenericModelState(soundModel.uuid); ret = mSoundTriggerHelper.getGenericModelState(soundModel.getUuid());
break; break;
default: default:
// SoundModel.TYPE_KEYPHRASE is not supported to increase privacy. // 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( sEventLogger.log(new SoundTriggerLogger.StringEvent(
"getModelState(): Unsupported model type, " "getModelState(): Unsupported model type, "
+ soundModel.type)); + soundModel.getType()));
break; break;
} }
@@ -723,7 +725,7 @@ public class SoundTriggerService extends SystemService {
return STATUS_BAD_VALUE; 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"); 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 null;
} }
return mSoundTriggerHelper.queryParameter(soundModel.uuid, modelParam); return mSoundTriggerHelper.queryParameter(soundModel.getUuid(), modelParam);
} }
} }
} }

View File

@@ -162,23 +162,26 @@ public class DatabaseHelper extends SQLiteOpenHelper {
synchronized(this) { synchronized(this) {
SQLiteDatabase db = getWritableDatabase(); SQLiteDatabase db = getWritableDatabase();
ContentValues values = new ContentValues(); ContentValues values = new ContentValues();
values.put(SoundModelContract.KEY_MODEL_UUID, soundModel.uuid.toString()); values.put(SoundModelContract.KEY_MODEL_UUID, soundModel.getUuid().toString());
if (soundModel.vendorUuid != null) { if (soundModel.getVendorUuid() != null) {
values.put(SoundModelContract.KEY_VENDOR_UUID, soundModel.vendorUuid.toString()); values.put(SoundModelContract.KEY_VENDOR_UUID,
soundModel.getVendorUuid().toString());
} }
values.put(SoundModelContract.KEY_TYPE, SoundTrigger.SoundModel.TYPE_KEYPHRASE); values.put(SoundModelContract.KEY_TYPE, SoundTrigger.SoundModel.TYPE_KEYPHRASE);
values.put(SoundModelContract.KEY_DATA, soundModel.data); values.put(SoundModelContract.KEY_DATA, soundModel.getData());
values.put(SoundModelContract.KEY_MODEL_VERSION, soundModel.version); values.put(SoundModelContract.KEY_MODEL_VERSION, soundModel.getVersion());
if (soundModel.keyphrases != null && soundModel.keyphrases.length == 1) { if (soundModel.getKeyphrases() != null && soundModel.getKeyphrases().length == 1) {
values.put(SoundModelContract.KEY_KEYPHRASE_ID, soundModel.keyphrases[0].id); values.put(SoundModelContract.KEY_KEYPHRASE_ID,
soundModel.getKeyphrases()[0].getId());
values.put(SoundModelContract.KEY_RECOGNITION_MODES, values.put(SoundModelContract.KEY_RECOGNITION_MODES,
soundModel.keyphrases[0].recognitionModes); soundModel.getKeyphrases()[0].getRecognitionModes());
values.put(SoundModelContract.KEY_USERS, values.put(SoundModelContract.KEY_USERS,
getCommaSeparatedString(soundModel.keyphrases[0].users)); getCommaSeparatedString(soundModel.getKeyphrases()[0].getUsers()));
values.put(SoundModelContract.KEY_LOCALE, values.put(SoundModelContract.KEY_LOCALE,
soundModel.keyphrases[0].locale.toLanguageTag()); soundModel.getKeyphrases()[0].getLocale().toLanguageTag());
values.put(SoundModelContract.KEY_HINT_TEXT, soundModel.keyphrases[0].text); values.put(SoundModelContract.KEY_HINT_TEXT,
soundModel.getKeyphrases()[0].getText());
try { try {
return db.insertWithOnConflict(SoundModelContract.TABLE, null, values, return db.insertWithOnConflict(SoundModelContract.TABLE, null, values,
SQLiteDatabase.CONFLICT_REPLACE) != -1; SQLiteDatabase.CONFLICT_REPLACE) != -1;
@@ -206,7 +209,7 @@ public class DatabaseHelper extends SQLiteOpenHelper {
// Delete all sound models for the given keyphrase and specified user. // Delete all sound models for the given keyphrase and specified user.
SQLiteDatabase db = getWritableDatabase(); SQLiteDatabase db = getWritableDatabase();
String soundModelClause = SoundModelContract.KEY_MODEL_UUID String soundModelClause = SoundModelContract.KEY_MODEL_UUID
+ "='" + soundModel.uuid.toString() + "'"; + "='" + soundModel.getUuid().toString() + "'";
try { try {
return db.delete(SoundModelContract.TABLE, soundModelClause, null) != 0; return db.delete(SoundModelContract.TABLE, soundModelClause, null) != 0;
} finally { } finally {

View File

@@ -1045,12 +1045,12 @@ public class VoiceInteractionManagerService extends SystemService {
return null; return null;
} }
for (SoundTrigger.Keyphrase phrase : model.keyphrases) { for (SoundTrigger.Keyphrase phrase : model.getKeyphrases()) {
if (keyphrase.equals(phrase.text)) { if (keyphrase.equals(phrase.getText())) {
ArraySet<Locale> locales = new ArraySet<>(); ArraySet<Locale> locales = new ArraySet<>();
locales.add(phrase.locale); locales.add(phrase.getLocale());
return new KeyphraseMetadata(phrase.id, phrase.text, locales, return new KeyphraseMetadata(phrase.getId(), phrase.getText(), locales,
phrase.recognitionModes); phrase.getRecognitionModes());
} }
} }
} finally { } finally {
@@ -1093,8 +1093,8 @@ public class VoiceInteractionManagerService extends SystemService {
KeyphraseSoundModel soundModel = KeyphraseSoundModel soundModel =
mDbHelper.getKeyphraseSoundModel(keyphraseId, callingUid, bcp47Locale); mDbHelper.getKeyphraseSoundModel(keyphraseId, callingUid, bcp47Locale);
if (soundModel == null if (soundModel == null
|| soundModel.uuid == null || soundModel.getUuid() == null
|| soundModel.keyphrases == null) { || soundModel.getKeyphrases() == null) {
Slog.w(TAG, "No matching sound model found in startRecognition"); Slog.w(TAG, "No matching sound model found in startRecognition");
return SoundTriggerInternal.STATUS_ERROR; return SoundTriggerInternal.STATUS_ERROR;
} else { } else {

View File

@@ -250,10 +250,12 @@ public class SoundTriggerTestService extends Service {
boolean status = mSoundTriggerUtil.addOrUpdateSoundModel(soundModel); boolean status = mSoundTriggerUtil.addOrUpdateSoundModel(soundModel);
if (status) { if (status) {
postToast("Successfully loaded " + modelInfo.name + ", UUID=" + soundModel.uuid); postToast("Successfully loaded " + modelInfo.name + ", UUID="
+ soundModel.getUuid());
setModelState(modelInfo, "Loaded"); setModelState(modelInfo, "Loaded");
} else { } else {
postErrorToast("Failed to load " + modelInfo.name + ", UUID=" + soundModel.uuid + "!"); postErrorToast("Failed to load " + modelInfo.name + ", UUID="
+ soundModel.getUuid() + "!");
setModelState(modelInfo, "Failed to load"); setModelState(modelInfo, "Failed to load");
} }
} }
@@ -275,11 +277,12 @@ public class SoundTriggerTestService extends Service {
modelInfo.detector = null; modelInfo.detector = null;
boolean status = mSoundTriggerUtil.deleteSoundModel(modelUuid); boolean status = mSoundTriggerUtil.deleteSoundModel(modelUuid);
if (status) { if (status) {
postToast("Successfully unloaded " + modelInfo.name + ", UUID=" + soundModel.uuid); postToast("Successfully unloaded " + modelInfo.name + ", UUID="
+ soundModel.getUuid());
setModelState(modelInfo, "Unloaded"); setModelState(modelInfo, "Unloaded");
} else { } else {
postErrorToast("Failed to unload " + postErrorToast("Failed to unload " +
modelInfo.name + ", UUID=" + soundModel.uuid + "!"); modelInfo.name + ", UUID=" + soundModel.getUuid() + "!");
setModelState(modelInfo, "Failed to unload"); setModelState(modelInfo, "Failed to unload");
} }
} }
@@ -299,7 +302,8 @@ public class SoundTriggerTestService extends Service {
GenericSoundModel updated = createNewSoundModel(modelInfo); GenericSoundModel updated = createNewSoundModel(modelInfo);
boolean status = mSoundTriggerUtil.addOrUpdateSoundModel(updated); boolean status = mSoundTriggerUtil.addOrUpdateSoundModel(updated);
if (status) { if (status) {
postToast("Successfully reloaded " + modelInfo.name + ", UUID=" + modelInfo.modelUuid); postToast("Successfully reloaded " + modelInfo.name + ", UUID="
+ modelInfo.modelUuid);
setModelState(modelInfo, "Reloaded"); setModelState(modelInfo, "Reloaded");
} else { } else {
postErrorToast("Failed to reload " postErrorToast("Failed to reload "
@@ -321,7 +325,8 @@ public class SoundTriggerTestService extends Service {
modelUuid, new DetectorCallback(modelInfo)); 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 ? if (modelInfo.detector.startRecognition(modelInfo.captureAudio ?
SoundTriggerDetector.RECOGNITION_FLAG_CAPTURE_TRIGGER_AUDIO : SoundTriggerDetector.RECOGNITION_FLAG_CAPTURE_TRIGGER_AUDIO :
SoundTriggerDetector.RECOGNITION_FLAG_ALLOW_MULTIPLE_TRIGGERS)) { SoundTriggerDetector.RECOGNITION_FLAG_ALLOW_MULTIPLE_TRIGGERS)) {
@@ -495,7 +500,8 @@ public class SoundTriggerTestService extends Service {
if (properties.containsKey("dataFile")) { if (properties.containsKey("dataFile")) {
File modelDataFile = new File( File modelDataFile = new File(
getFilesDir().getPath() + "/" + properties.getProperty("dataFile")); getFilesDir().getPath() + "/"
+ properties.getProperty("dataFile"));
modelInfo.modelData = new byte[(int) modelDataFile.length()]; modelInfo.modelData = new byte[(int) modelDataFile.length()];
FileInputStream input = new FileInputStream(modelDataFile); FileInputStream input = new FileInputStream(modelDataFile);
input.read(modelInfo.modelData, 0, modelInfo.modelData.length); input.read(modelInfo.modelData, 0, modelInfo.modelData.length);
@@ -602,12 +608,14 @@ public class SoundTriggerTestService extends Service {
FileOutputStream fos = null; FileOutputStream fos = null;
try { try {
fos = new FileOutputStream( new File( fos = new FileOutputStream( new File(
getFilesDir() + File.separator + mModelInfo.name.replace(' ', '_') + getFilesDir() + File.separator
"_capture_" + format.getChannelCount() + "ch_" + + mModelInfo.name.replace(' ', '_')
format.getSampleRate() + "hz_" + encoding + ".pcm")); + "_capture_" + format.getChannelCount() + "ch_"
+ format.getSampleRate() + "hz_" + encoding + ".pcm"));
} catch (IOException e) { } catch (IOException e) {
Log.e(TAG, "Failed to open output for saving PCM data", 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. // Inform the user we're recording.
@@ -690,7 +698,8 @@ public class SoundTriggerTestService extends Service {
AudioFormat format = event.getCaptureAudioFormat(); AudioFormat format = event.getCaptureAudioFormat();
result = result + "AudioFormat: " + ((format == null) ? "null" : format.toString()); result = result + "AudioFormat: " + ((format == null) ? "null" : format.toString());
byte[] triggerAudio = event.getTriggerAudio(); byte[] triggerAudio = event.getTriggerAudio();
result = result + ", TriggerAudio: " + (triggerAudio == null ? "null" : triggerAudio.length); result = result + ", TriggerAudio: "
+ (triggerAudio == null ? "null" : triggerAudio.length);
byte[] data = event.getData(); byte[] data = event.getData();
result = result + ", Data: " + (data == null ? "null" : data.length); result = result + ", Data: " + (data == null ? "null" : data.length);
if (data != null) { if (data != null) {

View File

@@ -16,7 +16,6 @@
package android.hardware.soundtrigger; package android.hardware.soundtrigger;
import android.hardware.soundtrigger.SoundTrigger;
import android.hardware.soundtrigger.SoundTrigger.ConfidenceLevel; import android.hardware.soundtrigger.SoundTrigger.ConfidenceLevel;
import android.hardware.soundtrigger.SoundTrigger.Keyphrase; import android.hardware.soundtrigger.SoundTrigger.Keyphrase;
import android.hardware.soundtrigger.SoundTrigger.KeyphraseRecognitionEvent; import android.hardware.soundtrigger.SoundTrigger.KeyphraseRecognitionEvent;
@@ -51,10 +50,10 @@ public class SoundTriggerTest extends InstrumentationTestCase {
Keyphrase unparceled = Keyphrase.CREATOR.createFromParcel(parcel); Keyphrase unparceled = Keyphrase.CREATOR.createFromParcel(parcel);
// Verify that they are the same // Verify that they are the same
assertEquals(keyphrase.id, unparceled.id); assertEquals(keyphrase.getId(), unparceled.getId());
assertNull(unparceled.users); assertNull(unparceled.getUsers());
assertEquals(keyphrase.locale, unparceled.locale); assertEquals(keyphrase.getLocale(), unparceled.getLocale());
assertEquals(keyphrase.text, unparceled.text); assertEquals(keyphrase.getText(), unparceled.getText());
} }
@SmallTest @SmallTest
@@ -71,10 +70,10 @@ public class SoundTriggerTest extends InstrumentationTestCase {
Keyphrase unparceled = Keyphrase.CREATOR.createFromParcel(parcel); Keyphrase unparceled = Keyphrase.CREATOR.createFromParcel(parcel);
// Verify that they are the same // Verify that they are the same
assertEquals(keyphrase.id, unparceled.id); assertEquals(keyphrase.getId(), unparceled.getId());
assertTrue(Arrays.equals(keyphrase.users, unparceled.users)); assertTrue(Arrays.equals(keyphrase.getUsers(), unparceled.getUsers()));
assertEquals(keyphrase.locale, unparceled.locale); assertEquals(keyphrase.getLocale(), unparceled.getLocale());
assertEquals(keyphrase.text, unparceled.text); assertEquals(keyphrase.getText(), unparceled.getText());
} }
@SmallTest @SmallTest
@@ -91,10 +90,10 @@ public class SoundTriggerTest extends InstrumentationTestCase {
Keyphrase unparceled = Keyphrase.CREATOR.createFromParcel(parcel); Keyphrase unparceled = Keyphrase.CREATOR.createFromParcel(parcel);
// Verify that they are the same // Verify that they are the same
assertEquals(keyphrase.id, unparceled.id); assertEquals(keyphrase.getId(), unparceled.getId());
assertTrue(Arrays.equals(keyphrase.users, unparceled.users)); assertTrue(Arrays.equals(keyphrase.getUsers(), unparceled.getUsers()));
assertEquals(keyphrase.locale, unparceled.locale); assertEquals(keyphrase.getLocale(), unparceled.getLocale());
assertEquals(keyphrase.text, unparceled.text); assertEquals(keyphrase.getText(), unparceled.getText());
} }
@SmallTest @SmallTest
@@ -116,10 +115,10 @@ public class SoundTriggerTest extends InstrumentationTestCase {
KeyphraseSoundModel unparceled = KeyphraseSoundModel.CREATOR.createFromParcel(parcel); KeyphraseSoundModel unparceled = KeyphraseSoundModel.CREATOR.createFromParcel(parcel);
// Verify that they are the same // Verify that they are the same
assertEquals(ksm.uuid, unparceled.uuid); assertEquals(ksm.getUuid(), unparceled.getUuid());
assertNull(unparceled.data); assertNull(unparceled.getData());
assertEquals(ksm.type, unparceled.type); assertEquals(ksm.getType(), unparceled.getType());
assertTrue(Arrays.equals(keyphrases, unparceled.keyphrases)); assertTrue(Arrays.equals(keyphrases, unparceled.getKeyphrases()));
} }
@SmallTest @SmallTest
@@ -141,10 +140,10 @@ public class SoundTriggerTest extends InstrumentationTestCase {
KeyphraseSoundModel unparceled = KeyphraseSoundModel.CREATOR.createFromParcel(parcel); KeyphraseSoundModel unparceled = KeyphraseSoundModel.CREATOR.createFromParcel(parcel);
// Verify that they are the same // Verify that they are the same
assertEquals(ksm.uuid, unparceled.uuid); assertEquals(ksm.getUuid(), unparceled.getUuid());
assertEquals(ksm.type, unparceled.type); assertEquals(ksm.getType(), unparceled.getType());
assertTrue(Arrays.equals(ksm.keyphrases, unparceled.keyphrases)); assertTrue(Arrays.equals(ksm.getKeyphrases(), unparceled.getKeyphrases()));
assertTrue(Arrays.equals(ksm.data, unparceled.data)); assertTrue(Arrays.equals(ksm.getData(), unparceled.getData()));
} }
@SmallTest @SmallTest
@@ -163,10 +162,10 @@ public class SoundTriggerTest extends InstrumentationTestCase {
KeyphraseSoundModel unparceled = KeyphraseSoundModel.CREATOR.createFromParcel(parcel); KeyphraseSoundModel unparceled = KeyphraseSoundModel.CREATOR.createFromParcel(parcel);
// Verify that they are the same // Verify that they are the same
assertEquals(ksm.uuid, unparceled.uuid); assertEquals(ksm.getUuid(), unparceled.getUuid());
assertEquals(ksm.type, unparceled.type); assertEquals(ksm.getType(), unparceled.getType());
assertNull(unparceled.keyphrases); assertNull(unparceled.getKeyphrases());
assertTrue(Arrays.equals(ksm.data, unparceled.data)); assertTrue(Arrays.equals(ksm.getData(), unparceled.getData()));
} }
@SmallTest @SmallTest
@@ -185,10 +184,10 @@ public class SoundTriggerTest extends InstrumentationTestCase {
KeyphraseSoundModel unparceled = KeyphraseSoundModel.CREATOR.createFromParcel(parcel); KeyphraseSoundModel unparceled = KeyphraseSoundModel.CREATOR.createFromParcel(parcel);
// Verify that they are the same // Verify that they are the same
assertEquals(ksm.uuid, unparceled.uuid); assertEquals(ksm.getUuid(), unparceled.getUuid());
assertEquals(ksm.type, unparceled.type); assertEquals(ksm.getType(), unparceled.getType());
assertTrue(Arrays.equals(ksm.keyphrases, unparceled.keyphrases)); assertTrue(Arrays.equals(ksm.getKeyphrases(), unparceled.getKeyphrases()));
assertTrue(Arrays.equals(ksm.data, unparceled.data)); assertTrue(Arrays.equals(ksm.getData(), unparceled.getData()));
} }
@LargeTest @LargeTest
@@ -212,10 +211,10 @@ public class SoundTriggerTest extends InstrumentationTestCase {
KeyphraseSoundModel unparceled = KeyphraseSoundModel.CREATOR.createFromParcel(parcel); KeyphraseSoundModel unparceled = KeyphraseSoundModel.CREATOR.createFromParcel(parcel);
// Verify that they are the same // Verify that they are the same
assertEquals(ksm.uuid, unparceled.uuid); assertEquals(ksm.getUuid(), unparceled.getUuid());
assertEquals(ksm.type, unparceled.type); assertEquals(ksm.getType(), unparceled.getType());
assertTrue(Arrays.equals(ksm.data, unparceled.data)); assertTrue(Arrays.equals(ksm.getData(), unparceled.getData()));
assertTrue(Arrays.equals(ksm.keyphrases, unparceled.keyphrases)); assertTrue(Arrays.equals(ksm.getKeyphrases(), unparceled.getKeyphrases()));
} }
@SmallTest @SmallTest

View File

@@ -17,7 +17,6 @@
package android.hardware.soundtrigger; package android.hardware.soundtrigger;
import static org.mockito.Matchers.any; import static org.mockito.Matchers.any;
import static org.mockito.Matchers.eq;
import static org.mockito.Mockito.reset; import static org.mockito.Mockito.reset;
import static org.mockito.Mockito.spy; import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.timeout; import static org.mockito.Mockito.timeout;
@@ -37,6 +36,8 @@ import android.test.suitebuilder.annotation.SmallTest;
import com.android.internal.app.ISoundTriggerService; import com.android.internal.app.ISoundTriggerService;
import org.mockito.MockitoAnnotations;
import java.io.DataOutputStream; import java.io.DataOutputStream;
import java.net.InetAddress; import java.net.InetAddress;
import java.net.Socket; import java.net.Socket;
@@ -45,8 +46,6 @@ import java.util.HashSet;
import java.util.Random; import java.util.Random;
import java.util.UUID; import java.util.UUID;
import org.mockito.MockitoAnnotations;
public class GenericSoundModelTest extends AndroidTestCase { public class GenericSoundModelTest extends AndroidTestCase {
static final int MSG_DETECTION_ERROR = -1; static final int MSG_DETECTION_ERROR = -1;
static final int MSG_DETECTION_RESUME = 0; static final int MSG_DETECTION_RESUME = 0;
@@ -96,11 +95,11 @@ public class GenericSoundModelTest extends AndroidTestCase {
// Update sound model // Update sound model
soundTriggerService.updateSoundModel(model); soundTriggerService.updateSoundModel(model);
loadedModelUuids.add(model.uuid); loadedModelUuids.add(model.getUuid());
// Confirm it was updated // Confirm it was updated
GenericSoundModel returnedModel = GenericSoundModel returnedModel =
soundTriggerService.getSoundModel(new ParcelUuid(model.uuid)); soundTriggerService.getSoundModel(new ParcelUuid(model.getUuid()));
assertEquals(model, returnedModel); assertEquals(model, returnedModel);
} }
@@ -110,15 +109,15 @@ public class GenericSoundModelTest extends AndroidTestCase {
// Update sound model // Update sound model
soundTriggerService.updateSoundModel(model); soundTriggerService.updateSoundModel(model);
loadedModelUuids.add(model.uuid); loadedModelUuids.add(model.getUuid());
// Delete sound model // Delete sound model
soundTriggerService.deleteSoundModel(new ParcelUuid(model.uuid)); soundTriggerService.deleteSoundModel(new ParcelUuid(model.getUuid()));
loadedModelUuids.remove(model.uuid); loadedModelUuids.remove(model.getUuid());
// Confirm it was deleted // Confirm it was deleted
GenericSoundModel returnedModel = GenericSoundModel returnedModel =
soundTriggerService.getSoundModel(new ParcelUuid(model.uuid)); soundTriggerService.getSoundModel(new ParcelUuid(model.getUuid()));
assertEquals(null, returnedModel); assertEquals(null, returnedModel);
} }
@@ -134,14 +133,14 @@ public class GenericSoundModelTest extends AndroidTestCase {
// Update and start sound model recognition // Update and start sound model recognition
soundTriggerService.updateSoundModel(model); soundTriggerService.updateSoundModel(model);
loadedModelUuids.add(model.uuid); loadedModelUuids.add(model.getUuid());
int r = soundTriggerService.startRecognition(new ParcelUuid(model.uuid), spyCallback, int r = soundTriggerService.startRecognition(new ParcelUuid(model.getUuid()), spyCallback,
config); config);
assertEquals("Could Not Start Recognition with code: " + r, assertEquals("Could Not Start Recognition with code: " + r,
android.hardware.soundtrigger.SoundTrigger.STATUS_OK, r); android.hardware.soundtrigger.SoundTrigger.STATUS_OK, r);
// Stop recognition // 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, assertEquals("Could Not Stop Recognition with code: " + r,
android.hardware.soundtrigger.SoundTrigger.STATUS_OK, r); android.hardware.soundtrigger.SoundTrigger.STATUS_OK, r);
} }
@@ -158,13 +157,13 @@ public class GenericSoundModelTest extends AndroidTestCase {
// Update and start sound model // Update and start sound model
soundTriggerService.updateSoundModel(model); soundTriggerService.updateSoundModel(model);
loadedModelUuids.add(model.uuid); loadedModelUuids.add(model.getUuid());
soundTriggerService.startRecognition(new ParcelUuid(model.uuid), spyCallback, config); soundTriggerService.startRecognition(new ParcelUuid(model.getUuid()), spyCallback, config);
// Send trigger to stub HAL // Send trigger to stub HAL
Socket socket = new Socket(InetAddress.getLocalHost(), 14035); Socket socket = new Socket(InetAddress.getLocalHost(), 14035);
DataOutputStream out = new DataOutputStream(socket.getOutputStream()); DataOutputStream out = new DataOutputStream(socket.getOutputStream());
out.writeBytes("trig " + model.uuid.toString() + "\r\n"); out.writeBytes("trig " + model.getUuid().toString() + "\r\n");
out.flush(); out.flush();
socket.close(); socket.close();
@@ -227,11 +226,12 @@ public class GenericSoundModelTest extends AndroidTestCase {
if (operation == 0 && modelInfo.status == STATUS_UNLOADED) { if (operation == 0 && modelInfo.status == STATUS_UNLOADED) {
// Update and start sound model // Update and start sound model
soundTriggerService.updateSoundModel(modelInfo.model); soundTriggerService.updateSoundModel(modelInfo.model);
loadedModelUuids.add(modelInfo.model.uuid); loadedModelUuids.add(modelInfo.model.getUuid());
modelInfo.status = STATUS_LOADED; modelInfo.status = STATUS_LOADED;
} else if (operation == 1 && modelInfo.status == STATUS_LOADED) { } else if (operation == 1 && modelInfo.status == STATUS_LOADED) {
// Start the sound model // Start the sound model
int r = soundTriggerService.startRecognition(new ParcelUuid(modelInfo.model.uuid), int r = soundTriggerService.startRecognition(new ParcelUuid(
modelInfo.model.getUuid()),
spyCallback, config); spyCallback, config);
assertEquals("Could Not Start Recognition with code: " + r, assertEquals("Could Not Start Recognition with code: " + r,
android.hardware.soundtrigger.SoundTrigger.STATUS_OK, r); android.hardware.soundtrigger.SoundTrigger.STATUS_OK, r);
@@ -240,7 +240,7 @@ public class GenericSoundModelTest extends AndroidTestCase {
// Send trigger to stub HAL // Send trigger to stub HAL
Socket socket = new Socket(InetAddress.getLocalHost(), 14035); Socket socket = new Socket(InetAddress.getLocalHost(), 14035);
DataOutputStream out = new DataOutputStream(socket.getOutputStream()); DataOutputStream out = new DataOutputStream(socket.getOutputStream());
out.writeBytes("trig " + modelInfo.model.uuid + "\r\n"); out.writeBytes("trig " + modelInfo.model.getUuid() + "\r\n");
out.flush(); out.flush();
socket.close(); socket.close();
@@ -249,19 +249,20 @@ public class GenericSoundModelTest extends AndroidTestCase {
reset(spyCallback); reset(spyCallback);
} else if (operation == 3 && modelInfo.status == STATUS_STARTED) { } else if (operation == 3 && modelInfo.status == STATUS_STARTED) {
// Stop recognition // Stop recognition
int r = soundTriggerService.stopRecognition(new ParcelUuid(modelInfo.model.uuid), int r = soundTriggerService.stopRecognition(new ParcelUuid(
modelInfo.model.getUuid()),
spyCallback); spyCallback);
assertEquals("Could Not Stop Recognition with code: " + r, assertEquals("Could Not Stop Recognition with code: " + r,
android.hardware.soundtrigger.SoundTrigger.STATUS_OK, r); android.hardware.soundtrigger.SoundTrigger.STATUS_OK, r);
modelInfo.status = STATUS_LOADED; modelInfo.status = STATUS_LOADED;
} else if (operation == 4 && modelInfo.status != STATUS_UNLOADED) { } else if (operation == 4 && modelInfo.status != STATUS_UNLOADED) {
// Delete sound model // Delete sound model
soundTriggerService.deleteSoundModel(new ParcelUuid(modelInfo.model.uuid)); soundTriggerService.deleteSoundModel(new ParcelUuid(modelInfo.model.getUuid()));
loadedModelUuids.remove(modelInfo.model.uuid); loadedModelUuids.remove(modelInfo.model.getUuid());
// Confirm it was deleted // Confirm it was deleted
GenericSoundModel returnedModel = GenericSoundModel returnedModel = soundTriggerService.getSoundModel(
soundTriggerService.getSoundModel(new ParcelUuid(modelInfo.model.uuid)); new ParcelUuid(modelInfo.model.getUuid()));
assertEquals(null, returnedModel); assertEquals(null, returnedModel);
modelInfo.status = STATUS_UNLOADED; modelInfo.status = STATUS_UNLOADED;
} }

View File

@@ -159,36 +159,36 @@ public class EnrollmentUtil {
Log.e(TAG, "KeyphraseSoundModel must be non-null"); Log.e(TAG, "KeyphraseSoundModel must be non-null");
return false; return false;
} }
if (soundModel.uuid == null) { if (soundModel.getUuid() == null) {
Log.e(TAG, "KeyphraseSoundModel must have a UUID"); Log.e(TAG, "KeyphraseSoundModel must have a UUID");
return false; return false;
} }
if (soundModel.data == null) { if (soundModel.getData() == null) {
Log.e(TAG, "KeyphraseSoundModel must have data"); Log.e(TAG, "KeyphraseSoundModel must have data");
return false; 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"); Log.e(TAG, "Keyphrase must be exactly 1");
return false; return false;
} }
Keyphrase keyphrase = soundModel.keyphrases[0]; Keyphrase keyphrase = soundModel.getKeyphrases()[0];
if (keyphrase.id <= 0) { if (keyphrase.getId() <= 0) {
Log.e(TAG, "Keyphrase must have a valid ID"); Log.e(TAG, "Keyphrase must have a valid ID");
return false; return false;
} }
if (keyphrase.recognitionModes < 0) { if (keyphrase.getRecognitionModes() < 0) {
Log.e(TAG, "Recognition modes must be valid"); Log.e(TAG, "Recognition modes must be valid");
return false; return false;
} }
if (keyphrase.locale == null) { if (keyphrase.getLocale() == null) {
Log.e(TAG, "Locale must not be null"); Log.e(TAG, "Locale must not be null");
return false; return false;
} }
if (keyphrase.text == null) { if (keyphrase.getText() == null) {
Log.e(TAG, "Text must not be null"); Log.e(TAG, "Text must not be null");
return false; 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)"); Log.e(TAG, "Keyphrase must have valid user(s)");
return false; return false;
} }

View File

@@ -91,7 +91,7 @@ public class TestEnrollmentActivity extends Activity {
} }
boolean status = mEnrollmentUtil.deleteSoundModel(KEYPHRASE_ID, BCP47_LOCALE); boolean status = mEnrollmentUtil.deleteSoundModel(KEYPHRASE_ID, BCP47_LOCALE);
if (status) { 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) Toast.LENGTH_SHORT)
.show(); .show();
} else { } else {
@@ -112,11 +112,11 @@ public class TestEnrollmentActivity extends Activity {
// Generate a fake model to push. // Generate a fake model to push.
byte[] data = new byte[2048]; byte[] data = new byte[2048];
mRandom.nextBytes(data); mRandom.nextBytes(data);
KeyphraseSoundModel updated = new KeyphraseSoundModel(soundModel.uuid, KeyphraseSoundModel updated = new KeyphraseSoundModel(soundModel.getUuid(),
soundModel.vendorUuid, data, soundModel.keyphrases); soundModel.getVendorUuid(), data, soundModel.getKeyphrases());
boolean status = mEnrollmentUtil.addOrUpdateSoundModel(updated); boolean status = mEnrollmentUtil.addOrUpdateSoundModel(updated);
if (status) { 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) Toast.LENGTH_SHORT)
.show(); .show();
} else { } else {