diff --git a/services/tests/voiceinteractiontests/src/com/android/server/soundtrigger/ConversionUtilTest.java b/services/tests/voiceinteractiontests/src/com/android/server/soundtrigger/ConversionUtilTest.java
new file mode 100644
index 0000000000000..ff2ce15a79466
--- /dev/null
+++ b/services/tests/voiceinteractiontests/src/com/android/server/soundtrigger/ConversionUtilTest.java
@@ -0,0 +1,99 @@
+/*
+ * Copyright (C) 2023 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.server.soundtrigger;
+
+import static android.hardware.soundtrigger.ConversionUtil.aidl2apiAudioFormatWithDefault;
+import static android.hardware.soundtrigger.ConversionUtil.aidl2apiPhrase;
+import static android.hardware.soundtrigger.ConversionUtil.aidl2apiRecognitionConfig;
+import static android.hardware.soundtrigger.ConversionUtil.api2aidlPhrase;
+import static android.hardware.soundtrigger.ConversionUtil.api2aidlRecognitionConfig;
+import static android.hardware.soundtrigger.ConversionUtil.byteArrayToSharedMemory;
+import static android.hardware.soundtrigger.ConversionUtil.sharedMemoryToByteArray;
+import static android.hardware.soundtrigger.SoundTrigger.ConfidenceLevel;
+import static android.hardware.soundtrigger.SoundTrigger.RECOGNITION_MODE_GENERIC;
+import static android.hardware.soundtrigger.SoundTrigger.RECOGNITION_MODE_USER_AUTHENTICATION;
+import static android.hardware.soundtrigger.SoundTrigger.RECOGNITION_MODE_USER_IDENTIFICATION;
+import static android.hardware.soundtrigger.SoundTrigger.RECOGNITION_MODE_VOICE_TRIGGER;
+
+import static org.junit.Assert.assertArrayEquals;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+
+import android.hardware.soundtrigger.ConversionUtil;
+import android.hardware.soundtrigger.SoundTrigger;
+
+import androidx.test.runner.AndroidJUnit4;
+
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+import java.util.Locale;
+
+@RunWith(AndroidJUnit4.class)
+public class ConversionUtilTest {
+ private static final String TAG = "ConversionUtilTest";
+
+ @Test
+ public void testDefaultAudioFormatConstruction() {
+ // This method should generate a real format when passed null
+ final var format = aidl2apiAudioFormatWithDefault(
+ null /** exercise default **/,
+ true /** isInput **/
+ );
+ assertNotNull(format);
+ }
+
+ @Test
+ public void testRecognitionConfigRoundTrip() {
+ final int flags = SoundTrigger.ModuleProperties.AUDIO_CAPABILITY_ECHO_CANCELLATION
+ | SoundTrigger.ModuleProperties.AUDIO_CAPABILITY_NOISE_SUPPRESSION;
+ final var data = new byte[] {0x11, 0x22};
+ final var keyphrases = new SoundTrigger.KeyphraseRecognitionExtra[2];
+ keyphrases[0] = new SoundTrigger.KeyphraseRecognitionExtra(99,
+ RECOGNITION_MODE_VOICE_TRIGGER | RECOGNITION_MODE_USER_IDENTIFICATION, 13,
+ new ConfidenceLevel[] {new ConfidenceLevel(9999, 50),
+ new ConfidenceLevel(5000, 80)});
+ keyphrases[1] = new SoundTrigger.KeyphraseRecognitionExtra(101,
+ RECOGNITION_MODE_GENERIC, 8, new ConfidenceLevel[] {
+ new ConfidenceLevel(7777, 30),
+ new ConfidenceLevel(2222, 60)});
+
+ var apiconfig = new SoundTrigger.RecognitionConfig(true, false /** must be false **/,
+ keyphrases, data, flags);
+ assertEquals(apiconfig, aidl2apiRecognitionConfig(api2aidlRecognitionConfig(apiconfig)));
+ }
+
+ @Test
+ public void testByteArraySharedMemRoundTrip() {
+ final var data = new byte[] { 0x11, 0x22, 0x33, 0x44,
+ (byte) 0xde, (byte) 0xad, (byte) 0xbe, (byte) 0xef };
+ assertArrayEquals(data, sharedMemoryToByteArray(byteArrayToSharedMemory(data, "name"),
+ 10000000));
+
+ }
+
+ @Test
+ public void testPhraseRoundTrip() {
+ final var users = new int[] {10001, 10002};
+ final var apiphrase = new SoundTrigger.Keyphrase(17 /** id **/,
+ RECOGNITION_MODE_VOICE_TRIGGER | RECOGNITION_MODE_USER_AUTHENTICATION,
+ Locale.forLanguageTag("no_NO"),
+ "Hello Android", /** keyphrase **/
+ users);
+ assertEquals(apiphrase, aidl2apiPhrase(api2aidlPhrase(apiphrase)));
+ }
+}
diff --git a/tests/SoundTriggerTests/src/android/hardware/soundtrigger/SoundTriggerTest.java b/services/tests/voiceinteractiontests/src/com/android/server/soundtrigger/SoundTriggerTest.java
similarity index 90%
rename from tests/SoundTriggerTests/src/android/hardware/soundtrigger/SoundTriggerTest.java
rename to services/tests/voiceinteractiontests/src/com/android/server/soundtrigger/SoundTriggerTest.java
index f49d9c9f1431c..e6a1be8f018df 100644
--- a/tests/SoundTriggerTests/src/android/hardware/soundtrigger/SoundTriggerTest.java
+++ b/services/tests/voiceinteractiontests/src/com/android/server/soundtrigger/SoundTriggerTest.java
@@ -14,7 +14,7 @@
* limitations under the License.
*/
-package android.hardware.soundtrigger;
+package com.android.server.soundtrigger;
import android.hardware.soundtrigger.SoundTrigger.ConfidenceLevel;
import android.hardware.soundtrigger.SoundTrigger.Keyphrase;
@@ -22,6 +22,7 @@ import android.hardware.soundtrigger.SoundTrigger.KeyphraseRecognitionEvent;
import android.hardware.soundtrigger.SoundTrigger.KeyphraseRecognitionExtra;
import android.hardware.soundtrigger.SoundTrigger.KeyphraseSoundModel;
import android.hardware.soundtrigger.SoundTrigger.RecognitionEvent;
+import android.hardware.soundtrigger.SoundTrigger;
import android.media.AudioFormat;
import android.os.Parcel;
import android.test.InstrumentationTestCase;
@@ -50,10 +51,7 @@ public class SoundTriggerTest extends InstrumentationTestCase {
Keyphrase unparceled = Keyphrase.CREATOR.createFromParcel(parcel);
// Verify that they are the same
- assertEquals(keyphrase.getId(), unparceled.getId());
- assertNull(unparceled.getUsers());
- assertEquals(keyphrase.getLocale(), unparceled.getLocale());
- assertEquals(keyphrase.getText(), unparceled.getText());
+ assertEquals(keyphrase, unparceled);
}
@SmallTest
@@ -115,10 +113,7 @@ public class SoundTriggerTest extends InstrumentationTestCase {
KeyphraseSoundModel unparceled = KeyphraseSoundModel.CREATOR.createFromParcel(parcel);
// Verify that they are the same
- assertEquals(ksm.getUuid(), unparceled.getUuid());
- assertNull(unparceled.getData());
- assertEquals(ksm.getType(), unparceled.getType());
- assertTrue(Arrays.equals(keyphrases, unparceled.getKeyphrases()));
+ assertEquals(ksm, unparceled);
}
@SmallTest
@@ -162,10 +157,7 @@ public class SoundTriggerTest extends InstrumentationTestCase {
KeyphraseSoundModel unparceled = KeyphraseSoundModel.CREATOR.createFromParcel(parcel);
// Verify that they are the same
- assertEquals(ksm.getUuid(), unparceled.getUuid());
- assertEquals(ksm.getType(), unparceled.getType());
- assertNull(unparceled.getKeyphrases());
- assertTrue(Arrays.equals(ksm.getData(), unparceled.getData()));
+ assertEquals(ksm, unparceled);
}
@SmallTest
@@ -226,7 +218,11 @@ public class SoundTriggerTest extends InstrumentationTestCase {
3 /* captureDelayMs */,
4 /* capturePreambleMs */,
false /* triggerInData */,
- null /* captureFormat */,
+ new AudioFormat.Builder()
+ .setSampleRate(16000)
+ .setEncoding(AudioFormat.ENCODING_PCM_16BIT)
+ .setChannelMask(AudioFormat.CHANNEL_IN_MONO)
+ .build(),
null /* data */,
12345678 /* halEventReceivedMillis */);
@@ -251,7 +247,11 @@ public class SoundTriggerTest extends InstrumentationTestCase {
3 /* captureDelayMs */,
4 /* capturePreambleMs */,
false /* triggerInData */,
- null /* captureFormat */,
+ new AudioFormat.Builder()
+ .setSampleRate(16000)
+ .setEncoding(AudioFormat.ENCODING_PCM_16BIT)
+ .setChannelMask(AudioFormat.CHANNEL_IN_MONO)
+ .build(),
new byte[1] /* data */,
12345678 /* halEventReceivedMillis */);
@@ -278,7 +278,11 @@ public class SoundTriggerTest extends InstrumentationTestCase {
3 /* captureDelayMs */,
4 /* capturePreambleMs */,
false /* triggerInData */,
- null /* captureFormat */,
+ new AudioFormat.Builder()
+ .setSampleRate(16000)
+ .setEncoding(AudioFormat.ENCODING_PCM_16BIT)
+ .setChannelMask(AudioFormat.CHANNEL_IN_MONO)
+ .build(),
data,
12345678 /* halEventReceivedMillis */);
@@ -335,7 +339,11 @@ public class SoundTriggerTest extends InstrumentationTestCase {
3 /* captureDelayMs */,
4 /* capturePreambleMs */,
false /* triggerInData */,
- null /* captureFormat */,
+ new AudioFormat.Builder()
+ .setSampleRate(16000)
+ .setEncoding(AudioFormat.ENCODING_PCM_16BIT)
+ .setChannelMask(AudioFormat.CHANNEL_IN_MONO)
+ .build(),
null /* data */,
null /* keyphraseExtras */,
12345678 /* halEventReceivedMillis */);
@@ -364,7 +372,11 @@ public class SoundTriggerTest extends InstrumentationTestCase {
3 /* captureDelayMs */,
4 /* capturePreambleMs */,
false /* triggerInData */,
- null /* captureFormat */,
+ new AudioFormat.Builder()
+ .setSampleRate(16000)
+ .setEncoding(AudioFormat.ENCODING_PCM_16BIT)
+ .setChannelMask(AudioFormat.CHANNEL_IN_MONO)
+ .build(),
new byte[1] /* data */,
kpExtra,
12345678 /* halEventReceivedMillis */);
@@ -409,7 +421,11 @@ public class SoundTriggerTest extends InstrumentationTestCase {
3 /* captureDelayMs */,
4 /* capturePreambleMs */,
false /* triggerInData */,
- null /* captureFormat */,
+ new AudioFormat.Builder()
+ .setSampleRate(16000)
+ .setEncoding(AudioFormat.ENCODING_PCM_16BIT)
+ .setChannelMask(AudioFormat.CHANNEL_IN_MONO)
+ .build(),
data,
kpExtra,
12345678 /* halEventReceivedMillis */);
diff --git a/services/tests/voiceinteractiontests/src/com/android/server/soundtrigger_middleware/ConversionUtilTest.java b/services/tests/voiceinteractiontests/src/com/android/server/soundtrigger_middleware/ConversionUtilTest.java
index 5661b1288345c..7b7a0a3f0285e 100644
--- a/services/tests/voiceinteractiontests/src/com/android/server/soundtrigger_middleware/ConversionUtilTest.java
+++ b/services/tests/voiceinteractiontests/src/com/android/server/soundtrigger_middleware/ConversionUtilTest.java
@@ -16,36 +16,18 @@
package com.android.server.soundtrigger_middleware;
-import static android.hardware.soundtrigger.ConversionUtil.aidl2apiAudioFormatWithDefault;
-import static android.hardware.soundtrigger.ConversionUtil.aidl2apiPhrase;
-import static android.hardware.soundtrigger.ConversionUtil.aidl2apiRecognitionConfig;
-import static android.hardware.soundtrigger.ConversionUtil.api2aidlPhrase;
-import static android.hardware.soundtrigger.ConversionUtil.api2aidlRecognitionConfig;
-import static android.hardware.soundtrigger.ConversionUtil.byteArrayToSharedMemory;
-import static android.hardware.soundtrigger.ConversionUtil.sharedMemoryToByteArray;
-import static android.hardware.soundtrigger.SoundTrigger.ConfidenceLevel;
-import static android.hardware.soundtrigger.SoundTrigger.RECOGNITION_MODE_GENERIC;
-import static android.hardware.soundtrigger.SoundTrigger.RECOGNITION_MODE_USER_AUTHENTICATION;
-import static android.hardware.soundtrigger.SoundTrigger.RECOGNITION_MODE_USER_IDENTIFICATION;
-import static android.hardware.soundtrigger.SoundTrigger.RECOGNITION_MODE_VOICE_TRIGGER;
-
-import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
import android.hardware.audio.common.V2_0.Uuid;
-import android.hardware.soundtrigger.SoundTrigger;
import androidx.test.runner.AndroidJUnit4;
import org.junit.Test;
import org.junit.runner.RunWith;
-import java.util.Locale;
-
@RunWith(AndroidJUnit4.class)
public class ConversionUtilTest {
- private static final String TAG = "ConversionUtilTest";
+ private static final String TAG = "SoundTriggerMiddlewareConversionUtilTest";
@Test
public void testUuidRoundTrip() {
@@ -62,54 +44,4 @@ public class ConversionUtilTest {
Uuid reconstructed = ConversionUtil.aidl2hidlUuid(aidl);
assertEquals(hidl, reconstructed);
}
-
- @Test
- public void testDefaultAudioFormatConstruction() {
- // This method should generate a real format when passed null
- final var format = aidl2apiAudioFormatWithDefault(
- null /** exercise default **/,
- true /** isInput **/
- );
- assertNotNull(format);
- }
-
- @Test
- public void testRecognitionConfigRoundTrip() {
- final int flags = SoundTrigger.ModuleProperties.AUDIO_CAPABILITY_ECHO_CANCELLATION
- | SoundTrigger.ModuleProperties.AUDIO_CAPABILITY_NOISE_SUPPRESSION;
- final var data = new byte[] {0x11, 0x22};
- final var keyphrases = new SoundTrigger.KeyphraseRecognitionExtra[2];
- keyphrases[0] = new SoundTrigger.KeyphraseRecognitionExtra(99,
- RECOGNITION_MODE_VOICE_TRIGGER | RECOGNITION_MODE_USER_IDENTIFICATION, 13,
- new ConfidenceLevel[] {new ConfidenceLevel(9999, 50),
- new ConfidenceLevel(5000, 80)});
- keyphrases[1] = new SoundTrigger.KeyphraseRecognitionExtra(101,
- RECOGNITION_MODE_GENERIC, 8, new ConfidenceLevel[] {
- new ConfidenceLevel(7777, 30),
- new ConfidenceLevel(2222, 60)});
-
- var apiconfig = new SoundTrigger.RecognitionConfig(true, false /** must be false **/,
- keyphrases, data, flags);
- assertEquals(apiconfig, aidl2apiRecognitionConfig(api2aidlRecognitionConfig(apiconfig)));
- }
-
- @Test
- public void testByteArraySharedMemRoundTrip() {
- final var data = new byte[] { 0x11, 0x22, 0x33, 0x44,
- (byte) 0xde, (byte) 0xad, (byte) 0xbe, (byte) 0xef };
- assertArrayEquals(data, sharedMemoryToByteArray(byteArrayToSharedMemory(data, "name"),
- 10000000));
-
- }
-
- @Test
- public void testPhraseRoundTrip() {
- final var users = new int[] {10001, 10002};
- final var apiphrase = new SoundTrigger.Keyphrase(17 /** id **/,
- RECOGNITION_MODE_VOICE_TRIGGER | RECOGNITION_MODE_USER_AUTHENTICATION,
- Locale.forLanguageTag("no_NO"),
- "Hello Android", /** keyphrase **/
- users);
- assertEquals(apiphrase, aidl2apiPhrase(api2aidlPhrase(apiphrase)));
- }
}
diff --git a/tests/SoundTriggerTests/Android.mk b/tests/SoundTriggerTests/Android.mk
deleted file mode 100644
index cc0fa1cd08403..0000000000000
--- a/tests/SoundTriggerTests/Android.mk
+++ /dev/null
@@ -1,39 +0,0 @@
-#
-# Copyright (C) 2014 The Android Open Source Project
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-#
-LOCAL_PATH:= $(call my-dir)
-include $(CLEAR_VARS)
-
-LOCAL_MODULE_TAGS := tests
-
-ifeq ($(SOUND_TRIGGER_USE_STUB_MODULE), 1)
- LOCAL_SRC_FILES := $(call all-subdir-java-files)
- LOCAL_PRIVILEGED_MODULE := true
- LOCAL_CERTIFICATE := platform
- TARGET_OUT_DATA_APPS_PRIVILEGED := $(TARGET_OUT_DATA)/priv-app
-else
- LOCAL_SRC_FILES := src/android/hardware/soundtrigger/SoundTriggerTest.java
-endif
-
-LOCAL_STATIC_JAVA_LIBRARIES := mockito-target
-LOCAL_JAVA_LIBRARIES := android.test.runner android.test.base
-
-LOCAL_PACKAGE_NAME := SoundTriggerTests
-LOCAL_LICENSE_KINDS := SPDX-license-identifier-Apache-2.0
-LOCAL_LICENSE_CONDITIONS := notice
-LOCAL_NOTICE_FILE := $(LOCAL_PATH)/../../NOTICE
-LOCAL_PRIVATE_PLATFORM_APIS := true
-
-include $(BUILD_PACKAGE)
diff --git a/tests/SoundTriggerTests/AndroidManifest.xml b/tests/SoundTriggerTests/AndroidManifest.xml
deleted file mode 100644
index f7454c752b7d7..0000000000000
--- a/tests/SoundTriggerTests/AndroidManifest.xml
+++ /dev/null
@@ -1,29 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/tests/SoundTriggerTests/OWNERS b/tests/SoundTriggerTests/OWNERS
deleted file mode 100644
index 1e41886fe716e..0000000000000
--- a/tests/SoundTriggerTests/OWNERS
+++ /dev/null
@@ -1 +0,0 @@
-include /media/java/android/media/soundtrigger/OWNERS
diff --git a/tests/SoundTriggerTests/src/android/hardware/soundtrigger/stubhal/GenericSoundModelTest.java b/tests/SoundTriggerTests/src/android/hardware/soundtrigger/stubhal/GenericSoundModelTest.java
deleted file mode 100644
index 2c3592c640bce..0000000000000
--- a/tests/SoundTriggerTests/src/android/hardware/soundtrigger/stubhal/GenericSoundModelTest.java
+++ /dev/null
@@ -1,293 +0,0 @@
-/*
- * Copyright (C) 2014 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package android.hardware.soundtrigger;
-
-import static org.mockito.Matchers.any;
-import static org.mockito.Mockito.reset;
-import static org.mockito.Mockito.spy;
-import static org.mockito.Mockito.timeout;
-import static org.mockito.Mockito.verify;
-
-import android.content.Context;
-import android.hardware.soundtrigger.SoundTrigger.GenericRecognitionEvent;
-import android.hardware.soundtrigger.SoundTrigger.GenericSoundModel;
-import android.hardware.soundtrigger.SoundTrigger.KeyphraseRecognitionEvent;
-import android.hardware.soundtrigger.SoundTrigger.RecognitionConfig;
-import android.media.soundtrigger.SoundTriggerManager;
-import android.os.ParcelUuid;
-import android.os.ServiceManager;
-import android.test.AndroidTestCase;
-import android.test.suitebuilder.annotation.LargeTest;
-import android.test.suitebuilder.annotation.SmallTest;
-
-import com.android.internal.app.ISoundTriggerService;
-
-import org.mockito.MockitoAnnotations;
-
-import java.io.DataOutputStream;
-import java.net.InetAddress;
-import java.net.Socket;
-import java.util.ArrayList;
-import java.util.HashSet;
-import java.util.Random;
-import java.util.UUID;
-
-public class GenericSoundModelTest extends AndroidTestCase {
- static final int MSG_DETECTION_ERROR = -1;
- static final int MSG_DETECTION_RESUME = 0;
- static final int MSG_DETECTION_PAUSE = 1;
- static final int MSG_KEYPHRASE_TRIGGER = 2;
- static final int MSG_GENERIC_TRIGGER = 4;
-
- private Random random = new Random();
- private HashSet loadedModelUuids;
- private ISoundTriggerService soundTriggerService;
- private SoundTriggerManager soundTriggerManager;
-
- @Override
- public void setUp() throws Exception {
- super.setUp();
- MockitoAnnotations.initMocks(this);
-
- Context context = getContext();
- soundTriggerService = ISoundTriggerService.Stub.asInterface(
- ServiceManager.getService(Context.SOUND_TRIGGER_SERVICE));
- soundTriggerManager = (SoundTriggerManager) context.getSystemService(
- Context.SOUND_TRIGGER_SERVICE);
-
- loadedModelUuids = new HashSet();
- }
-
- @Override
- public void tearDown() throws Exception {
- for (UUID modelUuid : loadedModelUuids) {
- soundTriggerService.deleteSoundModel(new ParcelUuid(modelUuid));
- }
- super.tearDown();
- }
-
- GenericSoundModel new_sound_model() {
- // Create sound model
- byte[] data = new byte[1024];
- random.nextBytes(data);
- UUID modelUuid = UUID.randomUUID();
- UUID mVendorUuid = UUID.randomUUID();
- return new GenericSoundModel(modelUuid, mVendorUuid, data);
- }
-
- @SmallTest
- public void testUpdateGenericSoundModel() throws Exception {
- GenericSoundModel model = new_sound_model();
-
- // Update sound model
- soundTriggerService.updateSoundModel(model);
- loadedModelUuids.add(model.getUuid());
-
- // Confirm it was updated
- GenericSoundModel returnedModel =
- soundTriggerService.getSoundModel(new ParcelUuid(model.getUuid()));
- assertEquals(model, returnedModel);
- }
-
- @SmallTest
- public void testDeleteGenericSoundModel() throws Exception {
- GenericSoundModel model = new_sound_model();
-
- // Update sound model
- soundTriggerService.updateSoundModel(model);
- loadedModelUuids.add(model.getUuid());
-
- // Delete sound model
- soundTriggerService.deleteSoundModel(new ParcelUuid(model.getUuid()));
- loadedModelUuids.remove(model.getUuid());
-
- // Confirm it was deleted
- GenericSoundModel returnedModel =
- soundTriggerService.getSoundModel(new ParcelUuid(model.getUuid()));
- assertEquals(null, returnedModel);
- }
-
- @LargeTest
- public void testStartStopGenericSoundModel() throws Exception {
- GenericSoundModel model = new_sound_model();
-
- boolean captureTriggerAudio = true;
- boolean allowMultipleTriggers = true;
- RecognitionConfig config = new RecognitionConfig(captureTriggerAudio, allowMultipleTriggers,
- null, null);
- TestRecognitionStatusCallback spyCallback = spy(new TestRecognitionStatusCallback());
-
- // Update and start sound model recognition
- soundTriggerService.updateSoundModel(model);
- loadedModelUuids.add(model.getUuid());
- int r = soundTriggerService.startRecognition(new ParcelUuid(model.getUuid()), spyCallback,
- config);
- assertEquals("Could Not Start Recognition with code: " + r,
- android.hardware.soundtrigger.SoundTrigger.STATUS_OK, r);
-
- // Stop recognition
- r = soundTriggerService.stopRecognition(new ParcelUuid(model.getUuid()), spyCallback);
- assertEquals("Could Not Stop Recognition with code: " + r,
- android.hardware.soundtrigger.SoundTrigger.STATUS_OK, r);
- }
-
- @LargeTest
- public void testTriggerGenericSoundModel() throws Exception {
- GenericSoundModel model = new_sound_model();
-
- boolean captureTriggerAudio = true;
- boolean allowMultipleTriggers = true;
- RecognitionConfig config = new RecognitionConfig(captureTriggerAudio, allowMultipleTriggers,
- null, null);
- TestRecognitionStatusCallback spyCallback = spy(new TestRecognitionStatusCallback());
-
- // Update and start sound model
- soundTriggerService.updateSoundModel(model);
- loadedModelUuids.add(model.getUuid());
- soundTriggerService.startRecognition(new ParcelUuid(model.getUuid()), spyCallback, config);
-
- // Send trigger to stub HAL
- Socket socket = new Socket(InetAddress.getLocalHost(), 14035);
- DataOutputStream out = new DataOutputStream(socket.getOutputStream());
- out.writeBytes("trig " + model.getUuid().toString() + "\r\n");
- out.flush();
- socket.close();
-
- // Verify trigger was received
- verify(spyCallback, timeout(100)).onGenericSoundTriggerDetected(any());
- }
-
- /**
- * Tests a more complicated pattern of loading, unloading, triggering, starting and stopping
- * recognition. Intended to find unexpected errors that occur in unexpected states.
- */
- @LargeTest
- public void testFuzzGenericSoundModel() throws Exception {
- int numModels = 2;
-
- final int STATUS_UNLOADED = 0;
- final int STATUS_LOADED = 1;
- final int STATUS_STARTED = 2;
-
- class ModelInfo {
- int status;
- GenericSoundModel model;
-
- public ModelInfo(GenericSoundModel model, int status) {
- this.status = status;
- this.model = model;
- }
- }
-
- Random predictableRandom = new Random(100);
-
- ArrayList modelInfos = new ArrayList();
- for(int i=0; i