blob: 007f4bcd43fcaf3bbf635ae8eb5d41616e5d5a66 [file] [log] [blame]
Sandeepd7018202014-07-10 15:15:39 -07001/**
Eric Laurente48188c2014-04-18 17:44:11 -07002 * Copyright (C) 2014 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package android.hardware.soundtrigger;
18
Philip P. Moltmanna5fd0292018-03-06 13:44:07 -080019import static android.system.OsConstants.EINVAL;
20import static android.system.OsConstants.ENODEV;
21import static android.system.OsConstants.ENOSYS;
22import static android.system.OsConstants.EPERM;
23import static android.system.OsConstants.EPIPE;
24
25import android.annotation.Nullable;
26import android.annotation.SystemApi;
Mathew Inwoodbcbe4402018-08-08 15:42:59 +010027import android.annotation.UnsupportedAppUsage;
Eric Laurentd3b82232014-07-30 08:57:39 -070028import android.media.AudioFormat;
Eric Laurente48188c2014-04-18 17:44:11 -070029import android.os.Handler;
Sandeep Siddhartha05589722014-07-17 16:21:54 -070030import android.os.Parcel;
31import android.os.Parcelable;
Eric Laurente48188c2014-04-18 17:44:11 -070032
33import java.util.ArrayList;
Sandeep Siddhartha05589722014-07-17 16:21:54 -070034import java.util.Arrays;
Eric Laurente48188c2014-04-18 17:44:11 -070035import java.util.UUID;
36
37/**
38 * The SoundTrigger class provides access via JNI to the native service managing
39 * the sound trigger HAL.
40 *
41 * @hide
42 */
Philip P. Moltmanna5fd0292018-03-06 13:44:07 -080043@SystemApi
Eric Laurente48188c2014-04-18 17:44:11 -070044public class SoundTrigger {
45
Philip P. Moltmanna5fd0292018-03-06 13:44:07 -080046 private SoundTrigger() {
47 }
48
49 /**
50 * Status code used when the operation succeeded
51 */
Eric Laurente48188c2014-04-18 17:44:11 -070052 public static final int STATUS_OK = 0;
Philip P. Moltmanna5fd0292018-03-06 13:44:07 -080053 /** @hide */
Eric Laurente48188c2014-04-18 17:44:11 -070054 public static final int STATUS_ERROR = Integer.MIN_VALUE;
Philip P. Moltmanna5fd0292018-03-06 13:44:07 -080055 /** @hide */
Lazar Trsic8ea56f62015-07-07 17:31:20 +020056 public static final int STATUS_PERMISSION_DENIED = -EPERM;
Philip P. Moltmanna5fd0292018-03-06 13:44:07 -080057 /** @hide */
Lazar Trsic8ea56f62015-07-07 17:31:20 +020058 public static final int STATUS_NO_INIT = -ENODEV;
Philip P. Moltmanna5fd0292018-03-06 13:44:07 -080059 /** @hide */
Lazar Trsic8ea56f62015-07-07 17:31:20 +020060 public static final int STATUS_BAD_VALUE = -EINVAL;
Philip P. Moltmanna5fd0292018-03-06 13:44:07 -080061 /** @hide */
Lazar Trsic8ea56f62015-07-07 17:31:20 +020062 public static final int STATUS_DEAD_OBJECT = -EPIPE;
Philip P. Moltmanna5fd0292018-03-06 13:44:07 -080063 /** @hide */
Lazar Trsic8ea56f62015-07-07 17:31:20 +020064 public static final int STATUS_INVALID_OPERATION = -ENOSYS;
Eric Laurente48188c2014-04-18 17:44:11 -070065
66 /*****************************************************************************
67 * A ModuleProperties describes a given sound trigger hardware module
68 * managed by the native sound trigger service. Each module has a unique
69 * ID used to target any API call to this paricular module. Module
70 * properties are returned by listModules() method.
Philip P. Moltmanna5fd0292018-03-06 13:44:07 -080071 *
72 * @hide
Eric Laurente48188c2014-04-18 17:44:11 -070073 ****************************************************************************/
Sandeep Siddhartha05589722014-07-17 16:21:54 -070074 public static class ModuleProperties implements Parcelable {
Eric Laurente48188c2014-04-18 17:44:11 -070075 /** Unique module ID provided by the native service */
Mathew Inwoodbcbe4402018-08-08 15:42:59 +010076 @UnsupportedAppUsage
Eric Laurente48188c2014-04-18 17:44:11 -070077 public final int id;
78
79 /** human readable voice detection engine implementor */
80 public final String implementor;
81
82 /** human readable voice detection engine description */
83 public final String description;
84
85 /** Unique voice engine Id (changes with each version) */
Mathew Inwoodbcbe4402018-08-08 15:42:59 +010086 @UnsupportedAppUsage
Eric Laurente48188c2014-04-18 17:44:11 -070087 public final UUID uuid;
88
89 /** Voice detection engine version */
90 public final int version;
91
92 /** Maximum number of active sound models */
Mathew Inwoodbcbe4402018-08-08 15:42:59 +010093 @UnsupportedAppUsage
Eric Laurente48188c2014-04-18 17:44:11 -070094 public final int maxSoundModels;
95
96 /** Maximum number of key phrases */
Sandeep Siddharthad4233c62014-06-12 18:31:19 -070097 public final int maxKeyphrases;
Eric Laurente48188c2014-04-18 17:44:11 -070098
99 /** Maximum number of users per key phrase */
100 public final int maxUsers;
101
102 /** Supported recognition modes (bit field, RECOGNITION_MODE_VOICE_TRIGGER ...) */
103 public final int recognitionModes;
104
105 /** Supports seamless transition to capture mode after recognition */
106 public final boolean supportsCaptureTransition;
107
108 /** Maximum buffering capacity in ms if supportsCaptureTransition() is true */
109 public final int maxBufferMs;
110
111 /** Supports capture by other use cases while detection is active */
112 public final boolean supportsConcurrentCapture;
113
114 /** Rated power consumption when detection is active with TDB silence/sound/speech ratio */
115 public final int powerConsumptionMw;
116
Eric Laurentd3b82232014-07-30 08:57:39 -0700117 /** Returns the trigger (key phrase) capture in the binary data of the
118 * recognition callback event */
119 public final boolean returnsTriggerInEvent;
120
Mathew Inwoodbcbe4402018-08-08 15:42:59 +0100121 @UnsupportedAppUsage
Eric Laurente48188c2014-04-18 17:44:11 -0700122 ModuleProperties(int id, String implementor, String description,
Sandeep Siddharthad4233c62014-06-12 18:31:19 -0700123 String uuid, int version, int maxSoundModels, int maxKeyphrases,
Eric Laurente48188c2014-04-18 17:44:11 -0700124 int maxUsers, int recognitionModes, boolean supportsCaptureTransition,
125 int maxBufferMs, boolean supportsConcurrentCapture,
Eric Laurentd3b82232014-07-30 08:57:39 -0700126 int powerConsumptionMw, boolean returnsTriggerInEvent) {
Eric Laurente48188c2014-04-18 17:44:11 -0700127 this.id = id;
128 this.implementor = implementor;
129 this.description = description;
130 this.uuid = UUID.fromString(uuid);
131 this.version = version;
132 this.maxSoundModels = maxSoundModels;
Sandeep Siddharthad4233c62014-06-12 18:31:19 -0700133 this.maxKeyphrases = maxKeyphrases;
Eric Laurente48188c2014-04-18 17:44:11 -0700134 this.maxUsers = maxUsers;
135 this.recognitionModes = recognitionModes;
136 this.supportsCaptureTransition = supportsCaptureTransition;
137 this.maxBufferMs = maxBufferMs;
138 this.supportsConcurrentCapture = supportsConcurrentCapture;
139 this.powerConsumptionMw = powerConsumptionMw;
Eric Laurentd3b82232014-07-30 08:57:39 -0700140 this.returnsTriggerInEvent = returnsTriggerInEvent;
Eric Laurente48188c2014-04-18 17:44:11 -0700141 }
Sandeep Siddhartha05589722014-07-17 16:21:54 -0700142
143 public static final Parcelable.Creator<ModuleProperties> CREATOR
144 = new Parcelable.Creator<ModuleProperties>() {
145 public ModuleProperties createFromParcel(Parcel in) {
146 return ModuleProperties.fromParcel(in);
147 }
148
149 public ModuleProperties[] newArray(int size) {
150 return new ModuleProperties[size];
151 }
152 };
153
154 private static ModuleProperties fromParcel(Parcel in) {
155 int id = in.readInt();
156 String implementor = in.readString();
157 String description = in.readString();
158 String uuid = in.readString();
159 int version = in.readInt();
160 int maxSoundModels = in.readInt();
161 int maxKeyphrases = in.readInt();
162 int maxUsers = in.readInt();
163 int recognitionModes = in.readInt();
164 boolean supportsCaptureTransition = in.readByte() == 1;
165 int maxBufferMs = in.readInt();
166 boolean supportsConcurrentCapture = in.readByte() == 1;
167 int powerConsumptionMw = in.readInt();
Eric Laurentd3b82232014-07-30 08:57:39 -0700168 boolean returnsTriggerInEvent = in.readByte() == 1;
Sandeep Siddhartha05589722014-07-17 16:21:54 -0700169 return new ModuleProperties(id, implementor, description, uuid, version,
170 maxSoundModels, maxKeyphrases, maxUsers, recognitionModes,
171 supportsCaptureTransition, maxBufferMs, supportsConcurrentCapture,
Eric Laurentd3b82232014-07-30 08:57:39 -0700172 powerConsumptionMw, returnsTriggerInEvent);
Sandeep Siddhartha05589722014-07-17 16:21:54 -0700173 }
174
175 @Override
176 public void writeToParcel(Parcel dest, int flags) {
177 dest.writeInt(id);
178 dest.writeString(implementor);
179 dest.writeString(description);
180 dest.writeString(uuid.toString());
181 dest.writeInt(version);
182 dest.writeInt(maxSoundModels);
183 dest.writeInt(maxKeyphrases);
184 dest.writeInt(maxUsers);
185 dest.writeInt(recognitionModes);
186 dest.writeByte((byte) (supportsCaptureTransition ? 1 : 0));
187 dest.writeInt(maxBufferMs);
188 dest.writeByte((byte) (supportsConcurrentCapture ? 1 : 0));
189 dest.writeInt(powerConsumptionMw);
Eric Laurentd3b82232014-07-30 08:57:39 -0700190 dest.writeByte((byte) (returnsTriggerInEvent ? 1 : 0));
Sandeep Siddhartha05589722014-07-17 16:21:54 -0700191 }
192
193 @Override
194 public int describeContents() {
195 return 0;
196 }
197
198 @Override
199 public String toString() {
200 return "ModuleProperties [id=" + id + ", implementor=" + implementor + ", description="
201 + description + ", uuid=" + uuid + ", version=" + version + ", maxSoundModels="
202 + maxSoundModels + ", maxKeyphrases=" + maxKeyphrases + ", maxUsers="
203 + maxUsers + ", recognitionModes=" + recognitionModes
204 + ", supportsCaptureTransition=" + supportsCaptureTransition + ", maxBufferMs="
205 + maxBufferMs + ", supportsConcurrentCapture=" + supportsConcurrentCapture
Eric Laurentd3b82232014-07-30 08:57:39 -0700206 + ", powerConsumptionMw=" + powerConsumptionMw
207 + ", returnsTriggerInEvent=" + returnsTriggerInEvent + "]";
Sandeep Siddhartha05589722014-07-17 16:21:54 -0700208 }
Eric Laurente48188c2014-04-18 17:44:11 -0700209 }
210
211 /*****************************************************************************
212 * A SoundModel describes the attributes and contains the binary data used by the hardware
213 * implementation to detect a particular sound pattern.
Sandeep Siddharthad4233c62014-06-12 18:31:19 -0700214 * A specialized version {@link KeyphraseSoundModel} is defined for key phrase
Eric Laurente48188c2014-04-18 17:44:11 -0700215 * sound models.
Philip P. Moltmanna5fd0292018-03-06 13:44:07 -0800216 *
217 * @hide
Eric Laurente48188c2014-04-18 17:44:11 -0700218 ****************************************************************************/
219 public static class SoundModel {
220 /** Undefined sound model type */
221 public static final int TYPE_UNKNOWN = -1;
222
223 /** Keyphrase sound model */
224 public static final int TYPE_KEYPHRASE = 0;
225
Arunesh Mishraa772e5f2016-01-25 10:33:11 -0800226 /**
227 * A generic sound model. Use this type only for non-keyphrase sound models such as
228 * ones that match a particular sound pattern.
229 */
230 public static final int TYPE_GENERIC_SOUND = 1;
231
Sandeep Siddharthad4233c62014-06-12 18:31:19 -0700232 /** Unique sound model identifier */
Mathew Inwoodbcbe4402018-08-08 15:42:59 +0100233 @UnsupportedAppUsage
Sandeep Siddharthad4233c62014-06-12 18:31:19 -0700234 public final UUID uuid;
235
Eric Laurente48188c2014-04-18 17:44:11 -0700236 /** Sound model type (e.g. TYPE_KEYPHRASE); */
237 public final int type;
238
Eric Laurentd3b82232014-07-30 08:57:39 -0700239 /** Unique sound model vendor identifier */
Mathew Inwoodbcbe4402018-08-08 15:42:59 +0100240 @UnsupportedAppUsage
Eric Laurentd3b82232014-07-30 08:57:39 -0700241 public final UUID vendorUuid;
242
Eric Laurente48188c2014-04-18 17:44:11 -0700243 /** Opaque data. For use by vendor implementation and enrollment application */
Mathew Inwoodbcbe4402018-08-08 15:42:59 +0100244 @UnsupportedAppUsage
Eric Laurente48188c2014-04-18 17:44:11 -0700245 public final byte[] data;
246
Eric Laurentd3b82232014-07-30 08:57:39 -0700247 public SoundModel(UUID uuid, UUID vendorUuid, int type, byte[] data) {
Sandeep Siddharthad4233c62014-06-12 18:31:19 -0700248 this.uuid = uuid;
Eric Laurentd3b82232014-07-30 08:57:39 -0700249 this.vendorUuid = vendorUuid;
Eric Laurente48188c2014-04-18 17:44:11 -0700250 this.type = type;
251 this.data = data;
252 }
Sandeep Siddhartha45c00b52014-10-16 16:17:11 -0700253
254 @Override
255 public int hashCode() {
256 final int prime = 31;
257 int result = 1;
258 result = prime * result + Arrays.hashCode(data);
259 result = prime * result + type;
260 result = prime * result + ((uuid == null) ? 0 : uuid.hashCode());
261 result = prime * result + ((vendorUuid == null) ? 0 : vendorUuid.hashCode());
262 return result;
263 }
264
265 @Override
266 public boolean equals(Object obj) {
267 if (this == obj)
268 return true;
269 if (obj == null)
270 return false;
271 if (!(obj instanceof SoundModel))
272 return false;
273 SoundModel other = (SoundModel) obj;
274 if (!Arrays.equals(data, other.data))
275 return false;
276 if (type != other.type)
277 return false;
278 if (uuid == null) {
279 if (other.uuid != null)
280 return false;
281 } else if (!uuid.equals(other.uuid))
282 return false;
283 if (vendorUuid == null) {
284 if (other.vendorUuid != null)
285 return false;
286 } else if (!vendorUuid.equals(other.vendorUuid))
287 return false;
288 return true;
289 }
Eric Laurente48188c2014-04-18 17:44:11 -0700290 }
291
292 /*****************************************************************************
Sandeep Siddharthad4233c62014-06-12 18:31:19 -0700293 * A Keyphrase describes a key phrase that can be detected by a
294 * {@link KeyphraseSoundModel}
Philip P. Moltmanna5fd0292018-03-06 13:44:07 -0800295 *
296 * @hide
Eric Laurente48188c2014-04-18 17:44:11 -0700297 ****************************************************************************/
Sandeep Siddhartha05589722014-07-17 16:21:54 -0700298 public static class Keyphrase implements Parcelable {
Sandeep Siddharthad4233c62014-06-12 18:31:19 -0700299 /** Unique identifier for this keyphrase */
Mathew Inwoodbcbe4402018-08-08 15:42:59 +0100300 @UnsupportedAppUsage
Sandeep Siddharthad4233c62014-06-12 18:31:19 -0700301 public final int id;
302
Eric Laurente48188c2014-04-18 17:44:11 -0700303 /** Recognition modes supported for this key phrase in the model */
Mathew Inwoodbcbe4402018-08-08 15:42:59 +0100304 @UnsupportedAppUsage
Eric Laurente48188c2014-04-18 17:44:11 -0700305 public final int recognitionModes;
306
307 /** Locale of the keyphrase. JAVA Locale string e.g en_US */
Mathew Inwoodbcbe4402018-08-08 15:42:59 +0100308 @UnsupportedAppUsage
Eric Laurente48188c2014-04-18 17:44:11 -0700309 public final String locale;
310
311 /** Key phrase text */
Mathew Inwoodbcbe4402018-08-08 15:42:59 +0100312 @UnsupportedAppUsage
Eric Laurente48188c2014-04-18 17:44:11 -0700313 public final String text;
314
Eric Laurent013f66b2014-07-06 16:35:00 -0700315 /** Users this key phrase has been trained for. countains sound trigger specific user IDs
316 * derived from system user IDs {@link android.os.UserHandle#getIdentifier()}. */
Mathew Inwoodbcbe4402018-08-08 15:42:59 +0100317 @UnsupportedAppUsage
Eric Laurent013f66b2014-07-06 16:35:00 -0700318 public final int[] users;
Eric Laurente48188c2014-04-18 17:44:11 -0700319
Mathew Inwoodbcbe4402018-08-08 15:42:59 +0100320 @UnsupportedAppUsage
Eric Laurent013f66b2014-07-06 16:35:00 -0700321 public Keyphrase(int id, int recognitionModes, String locale, String text, int[] users) {
Sandeep Siddharthad4233c62014-06-12 18:31:19 -0700322 this.id = id;
Eric Laurente48188c2014-04-18 17:44:11 -0700323 this.recognitionModes = recognitionModes;
324 this.locale = locale;
325 this.text = text;
Eric Laurent013f66b2014-07-06 16:35:00 -0700326 this.users = users;
Eric Laurente48188c2014-04-18 17:44:11 -0700327 }
Sandeep Siddhartha05589722014-07-17 16:21:54 -0700328
329 public static final Parcelable.Creator<Keyphrase> CREATOR
330 = new Parcelable.Creator<Keyphrase>() {
331 public Keyphrase createFromParcel(Parcel in) {
332 return Keyphrase.fromParcel(in);
333 }
334
335 public Keyphrase[] newArray(int size) {
336 return new Keyphrase[size];
337 }
338 };
339
340 private static Keyphrase fromParcel(Parcel in) {
341 int id = in.readInt();
342 int recognitionModes = in.readInt();
343 String locale = in.readString();
344 String text = in.readString();
345 int[] users = null;
346 int numUsers = in.readInt();
Sandeep Siddhartha110f5692014-07-20 12:22:56 -0700347 if (numUsers >= 0) {
Sandeep Siddhartha05589722014-07-17 16:21:54 -0700348 users = new int[numUsers];
349 in.readIntArray(users);
350 }
351 return new Keyphrase(id, recognitionModes, locale, text, users);
352 }
353
354 @Override
355 public void writeToParcel(Parcel dest, int flags) {
356 dest.writeInt(id);
357 dest.writeInt(recognitionModes);
358 dest.writeString(locale);
359 dest.writeString(text);
360 if (users != null) {
361 dest.writeInt(users.length);
362 dest.writeIntArray(users);
363 } else {
Sandeep Siddhartha110f5692014-07-20 12:22:56 -0700364 dest.writeInt(-1);
Sandeep Siddhartha05589722014-07-17 16:21:54 -0700365 }
366 }
367
368 @Override
369 public int describeContents() {
370 return 0;
371 }
372
373 @Override
374 public int hashCode() {
375 final int prime = 31;
376 int result = 1;
377 result = prime * result + ((text == null) ? 0 : text.hashCode());
378 result = prime * result + id;
379 result = prime * result + ((locale == null) ? 0 : locale.hashCode());
380 result = prime * result + recognitionModes;
381 result = prime * result + Arrays.hashCode(users);
382 return result;
383 }
384
385 @Override
386 public boolean equals(Object obj) {
387 if (this == obj)
388 return true;
389 if (obj == null)
390 return false;
391 if (getClass() != obj.getClass())
392 return false;
393 Keyphrase other = (Keyphrase) obj;
394 if (text == null) {
395 if (other.text != null)
396 return false;
397 } else if (!text.equals(other.text))
398 return false;
399 if (id != other.id)
400 return false;
401 if (locale == null) {
402 if (other.locale != null)
403 return false;
404 } else if (!locale.equals(other.locale))
405 return false;
406 if (recognitionModes != other.recognitionModes)
407 return false;
408 if (!Arrays.equals(users, other.users))
409 return false;
410 return true;
411 }
412
413 @Override
414 public String toString() {
415 return "Keyphrase [id=" + id + ", recognitionModes=" + recognitionModes + ", locale="
416 + locale + ", text=" + text + ", users=" + Arrays.toString(users) + "]";
417 }
Eric Laurente48188c2014-04-18 17:44:11 -0700418 }
419
420 /*****************************************************************************
Sandeep Siddharthad4233c62014-06-12 18:31:19 -0700421 * A KeyphraseSoundModel is a specialized {@link SoundModel} for key phrases.
Eric Laurente48188c2014-04-18 17:44:11 -0700422 * It contains data needed by the hardware to detect a certain number of key phrases
Sandeep Siddharthad4233c62014-06-12 18:31:19 -0700423 * and the list of corresponding {@link Keyphrase} descriptors.
Philip P. Moltmanna5fd0292018-03-06 13:44:07 -0800424 *
425 * @hide
Eric Laurente48188c2014-04-18 17:44:11 -0700426 ****************************************************************************/
Sandeep Siddhartha05589722014-07-17 16:21:54 -0700427 public static class KeyphraseSoundModel extends SoundModel implements Parcelable {
Eric Laurente48188c2014-04-18 17:44:11 -0700428 /** Key phrases in this sound model */
Mathew Inwoodbcbe4402018-08-08 15:42:59 +0100429 @UnsupportedAppUsage
Sandeep Siddharthad4233c62014-06-12 18:31:19 -0700430 public final Keyphrase[] keyphrases; // keyword phrases in model
Eric Laurente48188c2014-04-18 17:44:11 -0700431
Mathew Inwoodbcbe4402018-08-08 15:42:59 +0100432 @UnsupportedAppUsage
Eric Laurentd3b82232014-07-30 08:57:39 -0700433 public KeyphraseSoundModel(
434 UUID uuid, UUID vendorUuid, byte[] data, Keyphrase[] keyphrases) {
435 super(uuid, vendorUuid, TYPE_KEYPHRASE, data);
Sandeep Siddharthad4233c62014-06-12 18:31:19 -0700436 this.keyphrases = keyphrases;
Eric Laurente48188c2014-04-18 17:44:11 -0700437 }
Sandeep Siddhartha05589722014-07-17 16:21:54 -0700438
439 public static final Parcelable.Creator<KeyphraseSoundModel> CREATOR
440 = new Parcelable.Creator<KeyphraseSoundModel>() {
441 public KeyphraseSoundModel createFromParcel(Parcel in) {
442 return KeyphraseSoundModel.fromParcel(in);
443 }
444
445 public KeyphraseSoundModel[] newArray(int size) {
446 return new KeyphraseSoundModel[size];
447 }
448 };
449
450 private static KeyphraseSoundModel fromParcel(Parcel in) {
451 UUID uuid = UUID.fromString(in.readString());
Eric Laurentd3b82232014-07-30 08:57:39 -0700452 UUID vendorUuid = null;
453 int length = in.readInt();
454 if (length >= 0) {
455 vendorUuid = UUID.fromString(in.readString());
456 }
Sandeep Siddhartha39c12fa2014-07-25 18:37:29 -0700457 byte[] data = in.readBlob();
Sandeep Siddhartha05589722014-07-17 16:21:54 -0700458 Keyphrase[] keyphrases = in.createTypedArray(Keyphrase.CREATOR);
Eric Laurentd3b82232014-07-30 08:57:39 -0700459 return new KeyphraseSoundModel(uuid, vendorUuid, data, keyphrases);
Sandeep Siddhartha05589722014-07-17 16:21:54 -0700460 }
461
462 @Override
463 public int describeContents() {
464 return 0;
465 }
466
467 @Override
468 public void writeToParcel(Parcel dest, int flags) {
469 dest.writeString(uuid.toString());
Eric Laurentd3b82232014-07-30 08:57:39 -0700470 if (vendorUuid == null) {
471 dest.writeInt(-1);
472 } else {
473 dest.writeInt(vendorUuid.toString().length());
474 dest.writeString(vendorUuid.toString());
475 }
Sandeep Siddhartha39c12fa2014-07-25 18:37:29 -0700476 dest.writeBlob(data);
Sandeep Siddhartha68173372014-07-28 13:25:30 -0700477 dest.writeTypedArray(keyphrases, flags);
Sandeep Siddhartha05589722014-07-17 16:21:54 -0700478 }
Sandeep Siddhartha110f5692014-07-20 12:22:56 -0700479
480 @Override
481 public String toString() {
Eric Laurentd3b82232014-07-30 08:57:39 -0700482 return "KeyphraseSoundModel [keyphrases=" + Arrays.toString(keyphrases)
483 + ", uuid=" + uuid + ", vendorUuid=" + vendorUuid
484 + ", type=" + type + ", data=" + (data == null ? 0 : data.length) + "]";
Sandeep Siddhartha110f5692014-07-20 12:22:56 -0700485 }
Sandeep Siddhartha45c00b52014-10-16 16:17:11 -0700486
487 @Override
488 public int hashCode() {
489 final int prime = 31;
490 int result = super.hashCode();
491 result = prime * result + Arrays.hashCode(keyphrases);
492 return result;
493 }
494
495 @Override
496 public boolean equals(Object obj) {
497 if (this == obj)
498 return true;
499 if (!super.equals(obj))
500 return false;
501 if (!(obj instanceof KeyphraseSoundModel))
502 return false;
503 KeyphraseSoundModel other = (KeyphraseSoundModel) obj;
504 if (!Arrays.equals(keyphrases, other.keyphrases))
505 return false;
506 return true;
507 }
Eric Laurente48188c2014-04-18 17:44:11 -0700508 }
509
Arunesh Mishraa772e5f2016-01-25 10:33:11 -0800510
511 /*****************************************************************************
512 * A GenericSoundModel is a specialized {@link SoundModel} for non-voice sound
513 * patterns.
Philip P. Moltmanna5fd0292018-03-06 13:44:07 -0800514 *
515 * @hide
Arunesh Mishraa772e5f2016-01-25 10:33:11 -0800516 ****************************************************************************/
517 public static class GenericSoundModel extends SoundModel implements Parcelable {
518
519 public static final Parcelable.Creator<GenericSoundModel> CREATOR
520 = new Parcelable.Creator<GenericSoundModel>() {
521 public GenericSoundModel createFromParcel(Parcel in) {
522 return GenericSoundModel.fromParcel(in);
523 }
524
525 public GenericSoundModel[] newArray(int size) {
526 return new GenericSoundModel[size];
527 }
528 };
529
Mathew Inwoodbcbe4402018-08-08 15:42:59 +0100530 @UnsupportedAppUsage
Arunesh Mishraa772e5f2016-01-25 10:33:11 -0800531 public GenericSoundModel(UUID uuid, UUID vendorUuid, byte[] data) {
532 super(uuid, vendorUuid, TYPE_GENERIC_SOUND, data);
533 }
534
535 @Override
536 public int describeContents() {
537 return 0;
538 }
539
540 private static GenericSoundModel fromParcel(Parcel in) {
541 UUID uuid = UUID.fromString(in.readString());
542 UUID vendorUuid = null;
543 int length = in.readInt();
544 if (length >= 0) {
545 vendorUuid = UUID.fromString(in.readString());
546 }
547 byte[] data = in.readBlob();
548 return new GenericSoundModel(uuid, vendorUuid, data);
549 }
550
551 @Override
552 public void writeToParcel(Parcel dest, int flags) {
553 dest.writeString(uuid.toString());
554 if (vendorUuid == null) {
555 dest.writeInt(-1);
556 } else {
557 dest.writeInt(vendorUuid.toString().length());
558 dest.writeString(vendorUuid.toString());
559 }
560 dest.writeBlob(data);
561 }
562
563 @Override
564 public String toString() {
565 return "GenericSoundModel [uuid=" + uuid + ", vendorUuid=" + vendorUuid
566 + ", type=" + type + ", data=" + (data == null ? 0 : data.length) + "]";
567 }
568 }
569
Eric Laurente48188c2014-04-18 17:44:11 -0700570 /**
571 * Modes for key phrase recognition
572 */
Philip P. Moltmanna5fd0292018-03-06 13:44:07 -0800573
574 /**
575 * Simple recognition of the key phrase
576 *
577 * @hide
578 */
Eric Laurente48188c2014-04-18 17:44:11 -0700579 public static final int RECOGNITION_MODE_VOICE_TRIGGER = 0x1;
Philip P. Moltmanna5fd0292018-03-06 13:44:07 -0800580 /**
581 * Trigger only if one user is identified
582 *
583 * @hide
584 */
Eric Laurente48188c2014-04-18 17:44:11 -0700585 public static final int RECOGNITION_MODE_USER_IDENTIFICATION = 0x2;
Philip P. Moltmanna5fd0292018-03-06 13:44:07 -0800586 /**
587 * Trigger only if one user is authenticated
588 *
589 * @hide
590 */
Eric Laurente48188c2014-04-18 17:44:11 -0700591 public static final int RECOGNITION_MODE_USER_AUTHENTICATION = 0x4;
592
593 /**
594 * Status codes for {@link RecognitionEvent}
595 */
Philip P. Moltmanna5fd0292018-03-06 13:44:07 -0800596 /**
597 * Recognition success
598 *
599 * @hide
600 */
Eric Laurente48188c2014-04-18 17:44:11 -0700601 public static final int RECOGNITION_STATUS_SUCCESS = 0;
Philip P. Moltmanna5fd0292018-03-06 13:44:07 -0800602 /**
603 * Recognition aborted (e.g. capture preempted by anotehr use case
604 *
605 * @hide
606 */
Eric Laurente48188c2014-04-18 17:44:11 -0700607 public static final int RECOGNITION_STATUS_ABORT = 1;
Philip P. Moltmanna5fd0292018-03-06 13:44:07 -0800608 /**
609 * Recognition failure
610 *
611 * @hide
612 */
Eric Laurente48188c2014-04-18 17:44:11 -0700613 public static final int RECOGNITION_STATUS_FAILURE = 2;
614
615 /**
616 * A RecognitionEvent is provided by the
Philip P. Moltmanna5fd0292018-03-06 13:44:07 -0800617 * {@code StatusListener#onRecognition(RecognitionEvent)}
Eric Laurente48188c2014-04-18 17:44:11 -0700618 * callback upon recognition success or failure.
619 */
Philip P. Moltmanna5fd0292018-03-06 13:44:07 -0800620 public static class RecognitionEvent {
621 /**
622 * Recognition status e.g RECOGNITION_STATUS_SUCCESS
623 *
624 * @hide
625 */
Mathew Inwoodbcbe4402018-08-08 15:42:59 +0100626 @UnsupportedAppUsage
Eric Laurente48188c2014-04-18 17:44:11 -0700627 public final int status;
Philip P. Moltmanna5fd0292018-03-06 13:44:07 -0800628 /**
629 *
630 * Sound Model corresponding to this event callback
631 *
632 * @hide
633 */
Mathew Inwoodbcbe4402018-08-08 15:42:59 +0100634 @UnsupportedAppUsage
Eric Laurente48188c2014-04-18 17:44:11 -0700635 public final int soundModelHandle;
Philip P. Moltmanna5fd0292018-03-06 13:44:07 -0800636 /**
637 * True if it is possible to capture audio from this utterance buffered by the hardware
638 *
639 * @hide
640 */
Mathew Inwoodbcbe4402018-08-08 15:42:59 +0100641 @UnsupportedAppUsage
Eric Laurente48188c2014-04-18 17:44:11 -0700642 public final boolean captureAvailable;
Philip P. Moltmanna5fd0292018-03-06 13:44:07 -0800643 /**
644 * Audio session ID to be used when capturing the utterance with an AudioRecord
645 * if captureAvailable() is true.
646 *
647 * @hide
648 */
Mathew Inwoodbcbe4402018-08-08 15:42:59 +0100649 @UnsupportedAppUsage
Eric Laurente48188c2014-04-18 17:44:11 -0700650 public final int captureSession;
Philip P. Moltmanna5fd0292018-03-06 13:44:07 -0800651 /**
652 * Delay in ms between end of model detection and start of audio available for capture.
653 * A negative value is possible (e.g. if keyphrase is also available for capture)
654 *
655 * @hide
656 */
Eric Laurente48188c2014-04-18 17:44:11 -0700657 public final int captureDelayMs;
Philip P. Moltmanna5fd0292018-03-06 13:44:07 -0800658 /**
659 * Duration in ms of audio captured before the start of the trigger. 0 if none.
660 *
661 * @hide
662 */
Eric Laurent013f66b2014-07-06 16:35:00 -0700663 public final int capturePreambleMs;
Philip P. Moltmanna5fd0292018-03-06 13:44:07 -0800664 /**
665 * True if the trigger (key phrase capture is present in binary data
666 *
667 * @hide
668 */
Eric Laurentd3b82232014-07-30 08:57:39 -0700669 public final boolean triggerInData;
Philip P. Moltmanna5fd0292018-03-06 13:44:07 -0800670 /**
671 * Audio format of either the trigger in event data or to use for capture of the
672 * rest of the utterance
673 *
674 * @hide
675 */
676 public final AudioFormat captureFormat;
677 /**
678 * Opaque data for use by system applications who know about voice engine internals,
679 * typically during enrollment.
680 *
681 * @hide
682 */
Mathew Inwoodbcbe4402018-08-08 15:42:59 +0100683 @UnsupportedAppUsage
Eric Laurente48188c2014-04-18 17:44:11 -0700684 public final byte[] data;
685
Philip P. Moltmanna5fd0292018-03-06 13:44:07 -0800686 /** @hide */
Mathew Inwoodbcbe4402018-08-08 15:42:59 +0100687 @UnsupportedAppUsage
Sandeep Siddhartha39c12fa2014-07-25 18:37:29 -0700688 public RecognitionEvent(int status, int soundModelHandle, boolean captureAvailable,
Eric Laurentd3b82232014-07-30 08:57:39 -0700689 int captureSession, int captureDelayMs, int capturePreambleMs,
690 boolean triggerInData, AudioFormat captureFormat, byte[] data) {
Eric Laurente48188c2014-04-18 17:44:11 -0700691 this.status = status;
692 this.soundModelHandle = soundModelHandle;
693 this.captureAvailable = captureAvailable;
694 this.captureSession = captureSession;
695 this.captureDelayMs = captureDelayMs;
Eric Laurent013f66b2014-07-06 16:35:00 -0700696 this.capturePreambleMs = capturePreambleMs;
Eric Laurentd3b82232014-07-30 08:57:39 -0700697 this.triggerInData = triggerInData;
698 this.captureFormat = captureFormat;
Eric Laurente48188c2014-04-18 17:44:11 -0700699 this.data = data;
700 }
Sandeep Siddhartha39c12fa2014-07-25 18:37:29 -0700701
Philip P. Moltmanna5fd0292018-03-06 13:44:07 -0800702 /**
703 * Check if is possible to capture audio from this utterance buffered by the hardware.
704 *
705 * @return {@code true} iff a capturing is possible
706 */
707 public boolean isCaptureAvailable() {
708 return captureAvailable;
709 }
710
711 /**
712 * Get the audio format of either the trigger in event data or to use for capture of the
713 * rest of the utterance
714 *
715 * @return the audio format
716 */
717 @Nullable public AudioFormat getCaptureFormat() {
718 return captureFormat;
719 }
720
721 /**
722 * Get Audio session ID to be used when capturing the utterance with an {@link AudioRecord}
723 * if {@link #isCaptureAvailable()} is true.
724 *
725 * @return The id of the capture session
726 */
727 public int getCaptureSession() {
728 return captureSession;
729 }
730
731 /**
732 * Get the opaque data for use by system applications who know about voice engine
733 * internals, typically during enrollment.
734 *
735 * @return The data of the event
736 */
737 public byte[] getData() {
738 return data;
739 }
740
741 /** @hide */
Sandeep Siddhartha39c12fa2014-07-25 18:37:29 -0700742 public static final Parcelable.Creator<RecognitionEvent> CREATOR
743 = new Parcelable.Creator<RecognitionEvent>() {
744 public RecognitionEvent createFromParcel(Parcel in) {
745 return RecognitionEvent.fromParcel(in);
746 }
747
748 public RecognitionEvent[] newArray(int size) {
749 return new RecognitionEvent[size];
750 }
751 };
752
Philip P. Moltmanna5fd0292018-03-06 13:44:07 -0800753 /** @hide */
Arunesh Mishraf47f1732016-02-18 16:16:12 -0800754 protected static RecognitionEvent fromParcel(Parcel in) {
Sandeep Siddhartha39c12fa2014-07-25 18:37:29 -0700755 int status = in.readInt();
756 int soundModelHandle = in.readInt();
757 boolean captureAvailable = in.readByte() == 1;
758 int captureSession = in.readInt();
759 int captureDelayMs = in.readInt();
760 int capturePreambleMs = in.readInt();
Eric Laurentd3b82232014-07-30 08:57:39 -0700761 boolean triggerInData = in.readByte() == 1;
762 AudioFormat captureFormat = null;
Eric Laurent39fcca02014-09-05 16:44:19 -0700763 if (in.readByte() == 1) {
Eric Laurentd3b82232014-07-30 08:57:39 -0700764 int sampleRate = in.readInt();
765 int encoding = in.readInt();
766 int channelMask = in.readInt();
767 captureFormat = (new AudioFormat.Builder())
768 .setChannelMask(channelMask)
769 .setEncoding(encoding)
770 .setSampleRate(sampleRate)
771 .build();
772 }
Sandeep Siddhartha39c12fa2014-07-25 18:37:29 -0700773 byte[] data = in.readBlob();
774 return new RecognitionEvent(status, soundModelHandle, captureAvailable, captureSession,
Eric Laurentd3b82232014-07-30 08:57:39 -0700775 captureDelayMs, capturePreambleMs, triggerInData, captureFormat, data);
Sandeep Siddhartha39c12fa2014-07-25 18:37:29 -0700776 }
777
Philip P. Moltmanna5fd0292018-03-06 13:44:07 -0800778 /** @hide */
Sandeep Siddhartha39c12fa2014-07-25 18:37:29 -0700779 public int describeContents() {
780 return 0;
781 }
782
Philip P. Moltmanna5fd0292018-03-06 13:44:07 -0800783 /** @hide */
Sandeep Siddhartha39c12fa2014-07-25 18:37:29 -0700784 public void writeToParcel(Parcel dest, int flags) {
785 dest.writeInt(status);
786 dest.writeInt(soundModelHandle);
787 dest.writeByte((byte) (captureAvailable ? 1 : 0));
788 dest.writeInt(captureSession);
789 dest.writeInt(captureDelayMs);
790 dest.writeInt(capturePreambleMs);
Eric Laurent39fcca02014-09-05 16:44:19 -0700791 dest.writeByte((byte) (triggerInData ? 1 : 0));
792 if (captureFormat != null) {
Eric Laurentd3b82232014-07-30 08:57:39 -0700793 dest.writeByte((byte)1);
794 dest.writeInt(captureFormat.getSampleRate());
795 dest.writeInt(captureFormat.getEncoding());
796 dest.writeInt(captureFormat.getChannelMask());
797 } else {
798 dest.writeByte((byte)0);
799 }
Sandeep Siddhartha39c12fa2014-07-25 18:37:29 -0700800 dest.writeBlob(data);
801 }
802
803 @Override
804 public int hashCode() {
805 final int prime = 31;
806 int result = 1;
807 result = prime * result + (captureAvailable ? 1231 : 1237);
808 result = prime * result + captureDelayMs;
809 result = prime * result + capturePreambleMs;
810 result = prime * result + captureSession;
Eric Laurentd3b82232014-07-30 08:57:39 -0700811 result = prime * result + (triggerInData ? 1231 : 1237);
812 if (captureFormat != null) {
813 result = prime * result + captureFormat.getSampleRate();
814 result = prime * result + captureFormat.getEncoding();
815 result = prime * result + captureFormat.getChannelMask();
816 }
Sandeep Siddhartha39c12fa2014-07-25 18:37:29 -0700817 result = prime * result + Arrays.hashCode(data);
818 result = prime * result + soundModelHandle;
819 result = prime * result + status;
820 return result;
821 }
822
823 @Override
824 public boolean equals(Object obj) {
825 if (this == obj)
826 return true;
827 if (obj == null)
828 return false;
829 if (getClass() != obj.getClass())
830 return false;
831 RecognitionEvent other = (RecognitionEvent) obj;
832 if (captureAvailable != other.captureAvailable)
833 return false;
834 if (captureDelayMs != other.captureDelayMs)
835 return false;
836 if (capturePreambleMs != other.capturePreambleMs)
837 return false;
838 if (captureSession != other.captureSession)
839 return false;
840 if (!Arrays.equals(data, other.data))
841 return false;
842 if (soundModelHandle != other.soundModelHandle)
843 return false;
844 if (status != other.status)
845 return false;
Eric Laurentd3b82232014-07-30 08:57:39 -0700846 if (triggerInData != other.triggerInData)
847 return false;
Ryan Bavettaea04e8f2016-03-02 18:34:50 -0800848 if (captureFormat == null) {
849 if (other.captureFormat != null)
850 return false;
851 } else {
852 if (other.captureFormat == null)
853 return false;
854 if (captureFormat.getSampleRate() != other.captureFormat.getSampleRate())
855 return false;
856 if (captureFormat.getEncoding() != other.captureFormat.getEncoding())
857 return false;
858 if (captureFormat.getChannelMask() != other.captureFormat.getChannelMask())
859 return false;
860 }
Sandeep Siddhartha39c12fa2014-07-25 18:37:29 -0700861 return true;
862 }
Sandeep Siddhartha68173372014-07-28 13:25:30 -0700863
864 @Override
865 public String toString() {
866 return "RecognitionEvent [status=" + status + ", soundModelHandle=" + soundModelHandle
867 + ", captureAvailable=" + captureAvailable + ", captureSession="
868 + captureSession + ", captureDelayMs=" + captureDelayMs
869 + ", capturePreambleMs=" + capturePreambleMs
Eric Laurentd3b82232014-07-30 08:57:39 -0700870 + ", triggerInData=" + triggerInData
871 + ((captureFormat == null) ? "" :
872 (", sampleRate=" + captureFormat.getSampleRate()))
873 + ((captureFormat == null) ? "" :
874 (", encoding=" + captureFormat.getEncoding()))
875 + ((captureFormat == null) ? "" :
876 (", channelMask=" + captureFormat.getChannelMask()))
Sandeep Siddhartha68173372014-07-28 13:25:30 -0700877 + ", data=" + (data == null ? 0 : data.length) + "]";
878 }
Eric Laurente48188c2014-04-18 17:44:11 -0700879 }
880
881 /**
Eric Laurent013f66b2014-07-06 16:35:00 -0700882 * A RecognitionConfig is provided to
883 * {@link SoundTriggerModule#startRecognition(int, RecognitionConfig)} to configure the
884 * recognition request.
Philip P. Moltmanna5fd0292018-03-06 13:44:07 -0800885 *
886 * @hide
Eric Laurent013f66b2014-07-06 16:35:00 -0700887 */
Sandeep Siddhartha05589722014-07-17 16:21:54 -0700888 public static class RecognitionConfig implements Parcelable {
Eric Laurent013f66b2014-07-06 16:35:00 -0700889 /** True if the DSP should capture the trigger sound and make it available for further
890 * capture. */
Mathew Inwoodbcbe4402018-08-08 15:42:59 +0100891 @UnsupportedAppUsage
Eric Laurent013f66b2014-07-06 16:35:00 -0700892 public final boolean captureRequested;
Sandeep Siddhartha2c0273e2014-08-01 11:32:03 -0700893 /**
894 * True if the service should restart listening after the DSP triggers.
895 * Note: This config flag is currently used at the service layer rather than by the DSP.
896 */
897 public final boolean allowMultipleTriggers;
Eric Laurent013f66b2014-07-06 16:35:00 -0700898 /** List of all keyphrases in the sound model for which recognition should be performed with
899 * options for each keyphrase. */
Mathew Inwoodbcbe4402018-08-08 15:42:59 +0100900 @UnsupportedAppUsage
Eric Laurent013f66b2014-07-06 16:35:00 -0700901 public final KeyphraseRecognitionExtra keyphrases[];
902 /** Opaque data for use by system applications who know about voice engine internals,
903 * typically during enrollment. */
Mathew Inwoodbcbe4402018-08-08 15:42:59 +0100904 @UnsupportedAppUsage
Eric Laurent013f66b2014-07-06 16:35:00 -0700905 public final byte[] data;
906
Mathew Inwoodbcbe4402018-08-08 15:42:59 +0100907 @UnsupportedAppUsage
Sandeep Siddhartha2c0273e2014-08-01 11:32:03 -0700908 public RecognitionConfig(boolean captureRequested, boolean allowMultipleTriggers,
Philip P. Moltmanna5fd0292018-03-06 13:44:07 -0800909 KeyphraseRecognitionExtra[] keyphrases, byte[] data) {
Eric Laurent013f66b2014-07-06 16:35:00 -0700910 this.captureRequested = captureRequested;
Sandeep Siddhartha2c0273e2014-08-01 11:32:03 -0700911 this.allowMultipleTriggers = allowMultipleTriggers;
Eric Laurent013f66b2014-07-06 16:35:00 -0700912 this.keyphrases = keyphrases;
913 this.data = data;
914 }
Sandeep Siddhartha05589722014-07-17 16:21:54 -0700915
916 public static final Parcelable.Creator<RecognitionConfig> CREATOR
917 = new Parcelable.Creator<RecognitionConfig>() {
918 public RecognitionConfig createFromParcel(Parcel in) {
919 return RecognitionConfig.fromParcel(in);
920 }
921
922 public RecognitionConfig[] newArray(int size) {
923 return new RecognitionConfig[size];
924 }
925 };
926
927 private static RecognitionConfig fromParcel(Parcel in) {
928 boolean captureRequested = in.readByte() == 1;
Sandeep Siddhartha2c0273e2014-08-01 11:32:03 -0700929 boolean allowMultipleTriggers = in.readByte() == 1;
Sandeep Siddhartha05589722014-07-17 16:21:54 -0700930 KeyphraseRecognitionExtra[] keyphrases =
931 in.createTypedArray(KeyphraseRecognitionExtra.CREATOR);
Sandeep Siddhartha39c12fa2014-07-25 18:37:29 -0700932 byte[] data = in.readBlob();
Sandeep Siddhartha2c0273e2014-08-01 11:32:03 -0700933 return new RecognitionConfig(captureRequested, allowMultipleTriggers, keyphrases, data);
Sandeep Siddhartha05589722014-07-17 16:21:54 -0700934 }
935
936 @Override
937 public void writeToParcel(Parcel dest, int flags) {
938 dest.writeByte((byte) (captureRequested ? 1 : 0));
Sandeep Siddhartha2c0273e2014-08-01 11:32:03 -0700939 dest.writeByte((byte) (allowMultipleTriggers ? 1 : 0));
Sandeep Siddhartha68173372014-07-28 13:25:30 -0700940 dest.writeTypedArray(keyphrases, flags);
Sandeep Siddhartha39c12fa2014-07-25 18:37:29 -0700941 dest.writeBlob(data);
Sandeep Siddhartha05589722014-07-17 16:21:54 -0700942 }
943
944 @Override
945 public int describeContents() {
946 return 0;
947 }
Sandeep Siddhartha110f5692014-07-20 12:22:56 -0700948
949 @Override
950 public String toString() {
Sandeep Siddhartha2c0273e2014-08-01 11:32:03 -0700951 return "RecognitionConfig [captureRequested=" + captureRequested
952 + ", allowMultipleTriggers=" + allowMultipleTriggers + ", keyphrases="
953 + Arrays.toString(keyphrases) + ", data=" + Arrays.toString(data) + "]";
Sandeep Siddhartha110f5692014-07-20 12:22:56 -0700954 }
Eric Laurent013f66b2014-07-06 16:35:00 -0700955 }
956
957 /**
958 * Confidence level for users defined in a keyphrase.
959 * - The confidence level is expressed in percent (0% -100%).
960 * When used in a {@link KeyphraseRecognitionEvent} it indicates the detected confidence level
961 * When used in a {@link RecognitionConfig} it indicates the minimum confidence level that
962 * should trigger a recognition.
963 * - The user ID is derived from the system ID {@link android.os.UserHandle#getIdentifier()}.
Philip P. Moltmanna5fd0292018-03-06 13:44:07 -0800964 *
965 * @hide
Eric Laurent013f66b2014-07-06 16:35:00 -0700966 */
Sandeep Siddhartha05589722014-07-17 16:21:54 -0700967 public static class ConfidenceLevel implements Parcelable {
Mathew Inwoodbcbe4402018-08-08 15:42:59 +0100968 @UnsupportedAppUsage
Eric Laurent013f66b2014-07-06 16:35:00 -0700969 public final int userId;
Mathew Inwoodbcbe4402018-08-08 15:42:59 +0100970 @UnsupportedAppUsage
Eric Laurent013f66b2014-07-06 16:35:00 -0700971 public final int confidenceLevel;
972
Mathew Inwoodbcbe4402018-08-08 15:42:59 +0100973 @UnsupportedAppUsage
Eric Laurent013f66b2014-07-06 16:35:00 -0700974 public ConfidenceLevel(int userId, int confidenceLevel) {
975 this.userId = userId;
976 this.confidenceLevel = confidenceLevel;
977 }
Sandeep Siddhartha05589722014-07-17 16:21:54 -0700978
979 public static final Parcelable.Creator<ConfidenceLevel> CREATOR
980 = new Parcelable.Creator<ConfidenceLevel>() {
981 public ConfidenceLevel createFromParcel(Parcel in) {
982 return ConfidenceLevel.fromParcel(in);
983 }
984
985 public ConfidenceLevel[] newArray(int size) {
986 return new ConfidenceLevel[size];
987 }
988 };
989
990 private static ConfidenceLevel fromParcel(Parcel in) {
991 int userId = in.readInt();
992 int confidenceLevel = in.readInt();
993 return new ConfidenceLevel(userId, confidenceLevel);
994 }
995
996 @Override
997 public void writeToParcel(Parcel dest, int flags) {
998 dest.writeInt(userId);
999 dest.writeInt(confidenceLevel);
1000 }
1001
1002 @Override
1003 public int describeContents() {
1004 return 0;
1005 }
Sandeep Siddhartha68173372014-07-28 13:25:30 -07001006
1007 @Override
1008 public int hashCode() {
1009 final int prime = 31;
1010 int result = 1;
1011 result = prime * result + confidenceLevel;
1012 result = prime * result + userId;
1013 return result;
1014 }
1015
1016 @Override
1017 public boolean equals(Object obj) {
1018 if (this == obj)
1019 return true;
1020 if (obj == null)
1021 return false;
1022 if (getClass() != obj.getClass())
1023 return false;
1024 ConfidenceLevel other = (ConfidenceLevel) obj;
1025 if (confidenceLevel != other.confidenceLevel)
1026 return false;
1027 if (userId != other.userId)
1028 return false;
1029 return true;
1030 }
1031
1032 @Override
1033 public String toString() {
1034 return "ConfidenceLevel [userId=" + userId
1035 + ", confidenceLevel=" + confidenceLevel + "]";
1036 }
Eric Laurent013f66b2014-07-06 16:35:00 -07001037 }
1038
1039 /**
Sandeep Siddharthad4233c62014-06-12 18:31:19 -07001040 * Additional data conveyed by a {@link KeyphraseRecognitionEvent}
Eric Laurente48188c2014-04-18 17:44:11 -07001041 * for a key phrase detection.
Philip P. Moltmanna5fd0292018-03-06 13:44:07 -08001042 *
1043 * @hide
Eric Laurente48188c2014-04-18 17:44:11 -07001044 */
Sandeep Siddhartha05589722014-07-17 16:21:54 -07001045 public static class KeyphraseRecognitionExtra implements Parcelable {
1046 /** The keyphrase ID */
Mathew Inwoodbcbe4402018-08-08 15:42:59 +01001047 @UnsupportedAppUsage
Eric Laurent013f66b2014-07-06 16:35:00 -07001048 public final int id;
Eric Laurente48188c2014-04-18 17:44:11 -07001049
1050 /** Recognition modes matched for this event */
Mathew Inwoodbcbe4402018-08-08 15:42:59 +01001051 @UnsupportedAppUsage
Eric Laurente48188c2014-04-18 17:44:11 -07001052 public final int recognitionModes;
1053
Eric Laurentd3b82232014-07-30 08:57:39 -07001054 /** Confidence level for mode RECOGNITION_MODE_VOICE_TRIGGER when user identification
1055 * is not performed */
Mathew Inwoodbcbe4402018-08-08 15:42:59 +01001056 @UnsupportedAppUsage
Eric Laurentd3b82232014-07-30 08:57:39 -07001057 public final int coarseConfidenceLevel;
1058
Eric Laurent013f66b2014-07-06 16:35:00 -07001059 /** Confidence levels for all users recognized (KeyphraseRecognitionEvent) or to
1060 * be recognized (RecognitionConfig) */
Mathew Inwoodbcbe4402018-08-08 15:42:59 +01001061 @UnsupportedAppUsage
Eric Laurent013f66b2014-07-06 16:35:00 -07001062 public final ConfidenceLevel[] confidenceLevels;
1063
Mathew Inwoodbcbe4402018-08-08 15:42:59 +01001064 @UnsupportedAppUsage
Eric Laurentd3b82232014-07-30 08:57:39 -07001065 public KeyphraseRecognitionExtra(int id, int recognitionModes, int coarseConfidenceLevel,
1066 ConfidenceLevel[] confidenceLevels) {
Eric Laurent013f66b2014-07-06 16:35:00 -07001067 this.id = id;
Eric Laurente48188c2014-04-18 17:44:11 -07001068 this.recognitionModes = recognitionModes;
Eric Laurentd3b82232014-07-30 08:57:39 -07001069 this.coarseConfidenceLevel = coarseConfidenceLevel;
Eric Laurent013f66b2014-07-06 16:35:00 -07001070 this.confidenceLevels = confidenceLevels;
Eric Laurente48188c2014-04-18 17:44:11 -07001071 }
Sandeep Siddhartha05589722014-07-17 16:21:54 -07001072
1073 public static final Parcelable.Creator<KeyphraseRecognitionExtra> CREATOR
1074 = new Parcelable.Creator<KeyphraseRecognitionExtra>() {
1075 public KeyphraseRecognitionExtra createFromParcel(Parcel in) {
1076 return KeyphraseRecognitionExtra.fromParcel(in);
1077 }
1078
1079 public KeyphraseRecognitionExtra[] newArray(int size) {
1080 return new KeyphraseRecognitionExtra[size];
1081 }
1082 };
1083
1084 private static KeyphraseRecognitionExtra fromParcel(Parcel in) {
1085 int id = in.readInt();
1086 int recognitionModes = in.readInt();
Eric Laurentd3b82232014-07-30 08:57:39 -07001087 int coarseConfidenceLevel = in.readInt();
Sandeep Siddhartha05589722014-07-17 16:21:54 -07001088 ConfidenceLevel[] confidenceLevels = in.createTypedArray(ConfidenceLevel.CREATOR);
Eric Laurentd3b82232014-07-30 08:57:39 -07001089 return new KeyphraseRecognitionExtra(id, recognitionModes, coarseConfidenceLevel,
1090 confidenceLevels);
Sandeep Siddhartha05589722014-07-17 16:21:54 -07001091 }
1092
1093 @Override
1094 public void writeToParcel(Parcel dest, int flags) {
1095 dest.writeInt(id);
1096 dest.writeInt(recognitionModes);
Eric Laurentd3b82232014-07-30 08:57:39 -07001097 dest.writeInt(coarseConfidenceLevel);
Sandeep Siddhartha68173372014-07-28 13:25:30 -07001098 dest.writeTypedArray(confidenceLevels, flags);
Sandeep Siddhartha05589722014-07-17 16:21:54 -07001099 }
1100
1101 @Override
1102 public int describeContents() {
1103 return 0;
1104 }
Sandeep Siddhartha68173372014-07-28 13:25:30 -07001105
1106 @Override
1107 public int hashCode() {
1108 final int prime = 31;
1109 int result = 1;
1110 result = prime * result + Arrays.hashCode(confidenceLevels);
1111 result = prime * result + id;
1112 result = prime * result + recognitionModes;
Eric Laurentd3b82232014-07-30 08:57:39 -07001113 result = prime * result + coarseConfidenceLevel;
Sandeep Siddhartha68173372014-07-28 13:25:30 -07001114 return result;
1115 }
1116
1117 @Override
1118 public boolean equals(Object obj) {
1119 if (this == obj)
1120 return true;
1121 if (obj == null)
1122 return false;
1123 if (getClass() != obj.getClass())
1124 return false;
1125 KeyphraseRecognitionExtra other = (KeyphraseRecognitionExtra) obj;
1126 if (!Arrays.equals(confidenceLevels, other.confidenceLevels))
1127 return false;
1128 if (id != other.id)
1129 return false;
1130 if (recognitionModes != other.recognitionModes)
1131 return false;
Eric Laurentd3b82232014-07-30 08:57:39 -07001132 if (coarseConfidenceLevel != other.coarseConfidenceLevel)
1133 return false;
Sandeep Siddhartha68173372014-07-28 13:25:30 -07001134 return true;
1135 }
1136
1137 @Override
1138 public String toString() {
1139 return "KeyphraseRecognitionExtra [id=" + id + ", recognitionModes=" + recognitionModes
Eric Laurentd3b82232014-07-30 08:57:39 -07001140 + ", coarseConfidenceLevel=" + coarseConfidenceLevel
Sandeep Siddhartha68173372014-07-28 13:25:30 -07001141 + ", confidenceLevels=" + Arrays.toString(confidenceLevels) + "]";
1142 }
Eric Laurente48188c2014-04-18 17:44:11 -07001143 }
1144
1145 /**
1146 * Specialized {@link RecognitionEvent} for a key phrase detection.
Philip P. Moltmanna5fd0292018-03-06 13:44:07 -08001147 *
1148 * @hide
Eric Laurente48188c2014-04-18 17:44:11 -07001149 */
Philip P. Moltmanna5fd0292018-03-06 13:44:07 -08001150 public static class KeyphraseRecognitionEvent extends RecognitionEvent implements Parcelable {
Eric Laurente48188c2014-04-18 17:44:11 -07001151 /** Indicates if the key phrase is present in the buffered audio available for capture */
Mathew Inwoodbcbe4402018-08-08 15:42:59 +01001152 @UnsupportedAppUsage
Sandeep Siddharthad4233c62014-06-12 18:31:19 -07001153 public final KeyphraseRecognitionExtra[] keyphraseExtras;
Eric Laurente48188c2014-04-18 17:44:11 -07001154
Mathew Inwoodbcbe4402018-08-08 15:42:59 +01001155 @UnsupportedAppUsage
Sandeep Siddhartha68173372014-07-28 13:25:30 -07001156 public KeyphraseRecognitionEvent(int status, int soundModelHandle, boolean captureAvailable,
Eric Laurentd3b82232014-07-30 08:57:39 -07001157 int captureSession, int captureDelayMs, int capturePreambleMs,
1158 boolean triggerInData, AudioFormat captureFormat, byte[] data,
1159 KeyphraseRecognitionExtra[] keyphraseExtras) {
Eric Laurent013f66b2014-07-06 16:35:00 -07001160 super(status, soundModelHandle, captureAvailable, captureSession, captureDelayMs,
Eric Laurentd3b82232014-07-30 08:57:39 -07001161 capturePreambleMs, triggerInData, captureFormat, data);
Sandeep Siddharthad4233c62014-06-12 18:31:19 -07001162 this.keyphraseExtras = keyphraseExtras;
Eric Laurente48188c2014-04-18 17:44:11 -07001163 }
Sandeep Siddhartha68173372014-07-28 13:25:30 -07001164
1165 public static final Parcelable.Creator<KeyphraseRecognitionEvent> CREATOR
1166 = new Parcelable.Creator<KeyphraseRecognitionEvent>() {
1167 public KeyphraseRecognitionEvent createFromParcel(Parcel in) {
Arunesh Mishraf47f1732016-02-18 16:16:12 -08001168 return KeyphraseRecognitionEvent.fromParcelForKeyphrase(in);
Sandeep Siddhartha68173372014-07-28 13:25:30 -07001169 }
1170
1171 public KeyphraseRecognitionEvent[] newArray(int size) {
1172 return new KeyphraseRecognitionEvent[size];
1173 }
1174 };
1175
Arunesh Mishraf47f1732016-02-18 16:16:12 -08001176 private static KeyphraseRecognitionEvent fromParcelForKeyphrase(Parcel in) {
Sandeep Siddhartha68173372014-07-28 13:25:30 -07001177 int status = in.readInt();
1178 int soundModelHandle = in.readInt();
1179 boolean captureAvailable = in.readByte() == 1;
1180 int captureSession = in.readInt();
1181 int captureDelayMs = in.readInt();
1182 int capturePreambleMs = in.readInt();
Eric Laurentd3b82232014-07-30 08:57:39 -07001183 boolean triggerInData = in.readByte() == 1;
1184 AudioFormat captureFormat = null;
Eric Laurent75b433f2014-09-12 15:45:47 -07001185 if (in.readByte() == 1) {
Eric Laurentd3b82232014-07-30 08:57:39 -07001186 int sampleRate = in.readInt();
1187 int encoding = in.readInt();
1188 int channelMask = in.readInt();
1189 captureFormat = (new AudioFormat.Builder())
Ryan Bavettaea04e8f2016-03-02 18:34:50 -08001190 .setChannelMask(channelMask)
1191 .setEncoding(encoding)
1192 .setSampleRate(sampleRate)
1193 .build();
Eric Laurentd3b82232014-07-30 08:57:39 -07001194 }
Sandeep Siddhartha68173372014-07-28 13:25:30 -07001195 byte[] data = in.readBlob();
Sandeep Siddhartha68173372014-07-28 13:25:30 -07001196 KeyphraseRecognitionExtra[] keyphraseExtras =
1197 in.createTypedArray(KeyphraseRecognitionExtra.CREATOR);
1198 return new KeyphraseRecognitionEvent(status, soundModelHandle, captureAvailable,
Eric Laurentd3b82232014-07-30 08:57:39 -07001199 captureSession, captureDelayMs, capturePreambleMs, triggerInData,
1200 captureFormat, data, keyphraseExtras);
Sandeep Siddhartha68173372014-07-28 13:25:30 -07001201 }
1202
1203 @Override
1204 public void writeToParcel(Parcel dest, int flags) {
1205 dest.writeInt(status);
1206 dest.writeInt(soundModelHandle);
1207 dest.writeByte((byte) (captureAvailable ? 1 : 0));
1208 dest.writeInt(captureSession);
1209 dest.writeInt(captureDelayMs);
1210 dest.writeInt(capturePreambleMs);
Eric Laurent75b433f2014-09-12 15:45:47 -07001211 dest.writeByte((byte) (triggerInData ? 1 : 0));
1212 if (captureFormat != null) {
Eric Laurentd3b82232014-07-30 08:57:39 -07001213 dest.writeByte((byte)1);
1214 dest.writeInt(captureFormat.getSampleRate());
1215 dest.writeInt(captureFormat.getEncoding());
1216 dest.writeInt(captureFormat.getChannelMask());
1217 } else {
1218 dest.writeByte((byte)0);
1219 }
Sandeep Siddhartha68173372014-07-28 13:25:30 -07001220 dest.writeBlob(data);
Sandeep Siddhartha68173372014-07-28 13:25:30 -07001221 dest.writeTypedArray(keyphraseExtras, flags);
1222 }
1223
1224 @Override
1225 public int describeContents() {
1226 return 0;
1227 }
1228
1229 @Override
1230 public int hashCode() {
1231 final int prime = 31;
1232 int result = super.hashCode();
1233 result = prime * result + Arrays.hashCode(keyphraseExtras);
Sandeep Siddhartha68173372014-07-28 13:25:30 -07001234 return result;
1235 }
1236
1237 @Override
1238 public boolean equals(Object obj) {
1239 if (this == obj)
1240 return true;
1241 if (!super.equals(obj))
1242 return false;
1243 if (getClass() != obj.getClass())
1244 return false;
1245 KeyphraseRecognitionEvent other = (KeyphraseRecognitionEvent) obj;
1246 if (!Arrays.equals(keyphraseExtras, other.keyphraseExtras))
1247 return false;
Sandeep Siddhartha68173372014-07-28 13:25:30 -07001248 return true;
1249 }
1250
1251 @Override
1252 public String toString() {
1253 return "KeyphraseRecognitionEvent [keyphraseExtras=" + Arrays.toString(keyphraseExtras)
Eric Laurentd3b82232014-07-30 08:57:39 -07001254 + ", status=" + status
Sandeep Siddhartha68173372014-07-28 13:25:30 -07001255 + ", soundModelHandle=" + soundModelHandle + ", captureAvailable="
1256 + captureAvailable + ", captureSession=" + captureSession + ", captureDelayMs="
1257 + captureDelayMs + ", capturePreambleMs=" + capturePreambleMs
Eric Laurentd3b82232014-07-30 08:57:39 -07001258 + ", triggerInData=" + triggerInData
1259 + ((captureFormat == null) ? "" :
1260 (", sampleRate=" + captureFormat.getSampleRate()))
1261 + ((captureFormat == null) ? "" :
1262 (", encoding=" + captureFormat.getEncoding()))
1263 + ((captureFormat == null) ? "" :
1264 (", channelMask=" + captureFormat.getChannelMask()))
Sandeep Siddhartha68173372014-07-28 13:25:30 -07001265 + ", data=" + (data == null ? 0 : data.length) + "]";
1266 }
Eric Laurente48188c2014-04-18 17:44:11 -07001267 }
1268
1269 /**
Arunesh Mishraa772e5f2016-01-25 10:33:11 -08001270 * Sub-class of RecognitionEvent specifically for sound-trigger based sound
1271 * models(non-keyphrase). Currently does not contain any additional fields.
Philip P. Moltmanna5fd0292018-03-06 13:44:07 -08001272 *
1273 * @hide
Arunesh Mishraa772e5f2016-01-25 10:33:11 -08001274 */
Philip P. Moltmanna5fd0292018-03-06 13:44:07 -08001275 public static class GenericRecognitionEvent extends RecognitionEvent implements Parcelable {
Mathew Inwoodbcbe4402018-08-08 15:42:59 +01001276 @UnsupportedAppUsage
Arunesh Mishraa772e5f2016-01-25 10:33:11 -08001277 public GenericRecognitionEvent(int status, int soundModelHandle,
1278 boolean captureAvailable, int captureSession, int captureDelayMs,
1279 int capturePreambleMs, boolean triggerInData, AudioFormat captureFormat,
1280 byte[] data) {
1281 super(status, soundModelHandle, captureAvailable, captureSession,
1282 captureDelayMs, capturePreambleMs, triggerInData, captureFormat,
1283 data);
1284 }
Arunesh Mishraf47f1732016-02-18 16:16:12 -08001285
1286 public static final Parcelable.Creator<GenericRecognitionEvent> CREATOR
1287 = new Parcelable.Creator<GenericRecognitionEvent>() {
1288 public GenericRecognitionEvent createFromParcel(Parcel in) {
1289 return GenericRecognitionEvent.fromParcelForGeneric(in);
1290 }
1291
1292 public GenericRecognitionEvent[] newArray(int size) {
1293 return new GenericRecognitionEvent[size];
1294 }
1295 };
1296
1297 private static GenericRecognitionEvent fromParcelForGeneric(Parcel in) {
1298 RecognitionEvent event = RecognitionEvent.fromParcel(in);
1299 return new GenericRecognitionEvent(event.status, event.soundModelHandle,
1300 event.captureAvailable, event.captureSession, event.captureDelayMs,
1301 event.capturePreambleMs, event.triggerInData, event.captureFormat, event.data);
1302 }
1303
1304 @Override
1305 public boolean equals(Object obj) {
1306 if (this == obj)
1307 return true;
1308 if (obj == null)
1309 return false;
1310 if (getClass() != obj.getClass()) return false;
1311 RecognitionEvent other = (RecognitionEvent) obj;
1312 return super.equals(obj);
1313 }
1314
1315 @Override
1316 public String toString() {
1317 return "GenericRecognitionEvent ::" + super.toString();
1318 }
Arunesh Mishraa772e5f2016-01-25 10:33:11 -08001319 }
1320
1321 /**
Eric Laurentd3b82232014-07-30 08:57:39 -07001322 * Status codes for {@link SoundModelEvent}
1323 */
Philip P. Moltmanna5fd0292018-03-06 13:44:07 -08001324 /**
1325 * Sound Model was updated
1326 *
1327 * @hide
1328 */
Eric Laurentd3b82232014-07-30 08:57:39 -07001329 public static final int SOUNDMODEL_STATUS_UPDATED = 0;
1330
1331 /**
1332 * A SoundModelEvent is provided by the
1333 * {@link StatusListener#onSoundModelUpdate(SoundModelEvent)}
1334 * callback when a sound model has been updated by the implementation
Philip P. Moltmanna5fd0292018-03-06 13:44:07 -08001335 *
1336 * @hide
Eric Laurentd3b82232014-07-30 08:57:39 -07001337 */
1338 public static class SoundModelEvent implements Parcelable {
1339 /** Status e.g {@link #SOUNDMODEL_STATUS_UPDATED} */
1340 public final int status;
1341 /** The updated sound model handle */
1342 public final int soundModelHandle;
1343 /** New sound model data */
1344 public final byte[] data;
1345
Mathew Inwoodbcbe4402018-08-08 15:42:59 +01001346 @UnsupportedAppUsage
Eric Laurentd3b82232014-07-30 08:57:39 -07001347 SoundModelEvent(int status, int soundModelHandle, byte[] data) {
1348 this.status = status;
1349 this.soundModelHandle = soundModelHandle;
1350 this.data = data;
1351 }
1352
1353 public static final Parcelable.Creator<SoundModelEvent> CREATOR
1354 = new Parcelable.Creator<SoundModelEvent>() {
1355 public SoundModelEvent createFromParcel(Parcel in) {
1356 return SoundModelEvent.fromParcel(in);
1357 }
1358
1359 public SoundModelEvent[] newArray(int size) {
1360 return new SoundModelEvent[size];
1361 }
1362 };
1363
1364 private static SoundModelEvent fromParcel(Parcel in) {
1365 int status = in.readInt();
1366 int soundModelHandle = in.readInt();
1367 byte[] data = in.readBlob();
1368 return new SoundModelEvent(status, soundModelHandle, data);
1369 }
1370
1371 @Override
1372 public int describeContents() {
1373 return 0;
1374 }
1375
1376 @Override
1377 public void writeToParcel(Parcel dest, int flags) {
1378 dest.writeInt(status);
1379 dest.writeInt(soundModelHandle);
1380 dest.writeBlob(data);
1381 }
1382
1383 @Override
1384 public int hashCode() {
1385 final int prime = 31;
1386 int result = 1;
1387 result = prime * result + Arrays.hashCode(data);
1388 result = prime * result + soundModelHandle;
1389 result = prime * result + status;
1390 return result;
1391 }
1392
1393 @Override
1394 public boolean equals(Object obj) {
1395 if (this == obj)
1396 return true;
1397 if (obj == null)
1398 return false;
1399 if (getClass() != obj.getClass())
1400 return false;
1401 SoundModelEvent other = (SoundModelEvent) obj;
1402 if (!Arrays.equals(data, other.data))
1403 return false;
1404 if (soundModelHandle != other.soundModelHandle)
1405 return false;
1406 if (status != other.status)
1407 return false;
1408 return true;
1409 }
1410
1411 @Override
1412 public String toString() {
1413 return "SoundModelEvent [status=" + status + ", soundModelHandle=" + soundModelHandle
1414 + ", data=" + (data == null ? 0 : data.length) + "]";
1415 }
1416 }
1417
1418 /**
1419 * Native service state. {@link StatusListener#onServiceStateChange(int)}
1420 */
1421 // Keep in sync with system/core/include/system/sound_trigger.h
Philip P. Moltmanna5fd0292018-03-06 13:44:07 -08001422 /**
1423 * Sound trigger service is enabled
1424 *
1425 * @hide
1426 */
Eric Laurentd3b82232014-07-30 08:57:39 -07001427 public static final int SERVICE_STATE_ENABLED = 0;
Philip P. Moltmanna5fd0292018-03-06 13:44:07 -08001428 /**
1429 * Sound trigger service is disabled
1430 *
1431 * @hide
1432 */
Eric Laurentd3b82232014-07-30 08:57:39 -07001433 public static final int SERVICE_STATE_DISABLED = 1;
1434
1435 /**
Arunesh Mishraa772e5f2016-01-25 10:33:11 -08001436 * Returns a list of descriptors for all hardware modules loaded.
Eric Laurente48188c2014-04-18 17:44:11 -07001437 * @param modules A ModuleProperties array where the list will be returned.
1438 * @return - {@link #STATUS_OK} in case of success
1439 * - {@link #STATUS_ERROR} in case of unspecified error
1440 * - {@link #STATUS_PERMISSION_DENIED} if the caller does not have system permission
1441 * - {@link #STATUS_NO_INIT} if the native service cannot be reached
1442 * - {@link #STATUS_BAD_VALUE} if modules is null
1443 * - {@link #STATUS_DEAD_OBJECT} if the binder transaction to the native service fails
Philip P. Moltmanna5fd0292018-03-06 13:44:07 -08001444 *
1445 * @hide
Eric Laurente48188c2014-04-18 17:44:11 -07001446 */
Mathew Inwoodbcbe4402018-08-08 15:42:59 +01001447 @UnsupportedAppUsage
Eric Laurente48188c2014-04-18 17:44:11 -07001448 public static native int listModules(ArrayList <ModuleProperties> modules);
1449
1450 /**
1451 * Get an interface on a hardware module to control sound models and recognition on
1452 * this module.
1453 * @param moduleId Sound module system identifier {@link ModuleProperties#id}. mandatory.
1454 * @param listener {@link StatusListener} interface. Mandatory.
1455 * @param handler the Handler that will receive the callabcks. Can be null if default handler
1456 * is OK.
1457 * @return a valid sound module in case of success or null in case of error.
Philip P. Moltmanna5fd0292018-03-06 13:44:07 -08001458 *
1459 * @hide
Eric Laurente48188c2014-04-18 17:44:11 -07001460 */
Mathew Inwoodbcbe4402018-08-08 15:42:59 +01001461 @UnsupportedAppUsage
Eric Laurente48188c2014-04-18 17:44:11 -07001462 public static SoundTriggerModule attachModule(int moduleId,
1463 StatusListener listener,
1464 Handler handler) {
1465 if (listener == null) {
1466 return null;
1467 }
1468 SoundTriggerModule module = new SoundTriggerModule(moduleId, listener, handler);
1469 return module;
1470 }
1471
1472 /**
1473 * Interface provided by the client application when attaching to a {@link SoundTriggerModule}
1474 * to received recognition and error notifications.
Philip P. Moltmanna5fd0292018-03-06 13:44:07 -08001475 *
1476 * @hide
Eric Laurente48188c2014-04-18 17:44:11 -07001477 */
1478 public static interface StatusListener {
1479 /**
1480 * Called when recognition succeeds of fails
1481 */
1482 public abstract void onRecognition(RecognitionEvent event);
1483
1484 /**
Eric Laurentd3b82232014-07-30 08:57:39 -07001485 * Called when a sound model has been updated
1486 */
1487 public abstract void onSoundModelUpdate(SoundModelEvent event);
1488
1489 /**
1490 * Called when the sound trigger native service state changes.
1491 * @param state Native service state. One of {@link SoundTrigger#SERVICE_STATE_ENABLED},
1492 * {@link SoundTrigger#SERVICE_STATE_DISABLED}
1493 */
1494 public abstract void onServiceStateChange(int state);
1495
1496 /**
Eric Laurente48188c2014-04-18 17:44:11 -07001497 * Called when the sound trigger native service dies
1498 */
1499 public abstract void onServiceDied();
1500 }
1501}