Search in sources :

Example 11 with GenericSoundModel

use of android.hardware.soundtrigger.SoundTrigger.GenericSoundModel in project android_frameworks_base by DirtyUnicorns.

the class SoundTriggerTestService method reloadModel.

public synchronized void reloadModel(UUID modelUuid) {
    ModelInfo modelInfo = mModelInfoMap.get(modelUuid);
    if (modelInfo == null) {
        postError("Could not find model for: " + modelUuid.toString());
        return;
    }
    postMessage("Reloading model: " + modelInfo.name);
    GenericSoundModel soundModel = mSoundTriggerUtil.getSoundModel(modelUuid);
    if (soundModel == null) {
        postErrorToast("Sound model not found for " + modelInfo.name + "!");
        return;
    }
    GenericSoundModel updated = createNewSoundModel(modelInfo);
    boolean status = mSoundTriggerUtil.addOrUpdateSoundModel(updated);
    if (status) {
        postToast("Successfully reloaded " + modelInfo.name + ", UUID=" + modelInfo.modelUuid);
        setModelState(modelInfo, "Reloaded");
    } else {
        postErrorToast("Failed to reload " + modelInfo.name + ", UUID=" + modelInfo.modelUuid + "!");
        setModelState(modelInfo, "Failed to reload");
    }
}
Also used : GenericSoundModel(android.hardware.soundtrigger.SoundTrigger.GenericSoundModel)

Example 12 with GenericSoundModel

use of android.hardware.soundtrigger.SoundTrigger.GenericSoundModel in project android_frameworks_base by DirtyUnicorns.

the class GenericSoundModelTest method testDeleteGenericSoundModel.

@SmallTest
public void testDeleteGenericSoundModel() throws Exception {
    GenericSoundModel model = new_sound_model();
    // Update sound model
    soundTriggerService.updateSoundModel(model);
    loadedModelUuids.add(model.uuid);
    // Delete sound model
    soundTriggerService.deleteSoundModel(new ParcelUuid(model.uuid));
    loadedModelUuids.remove(model.uuid);
    // Confirm it was deleted
    GenericSoundModel returnedModel = soundTriggerService.getSoundModel(new ParcelUuid(model.uuid));
    assertEquals(null, returnedModel);
}
Also used : ParcelUuid(android.os.ParcelUuid) GenericSoundModel(android.hardware.soundtrigger.SoundTrigger.GenericSoundModel) SmallTest(android.test.suitebuilder.annotation.SmallTest)

Example 13 with GenericSoundModel

use of android.hardware.soundtrigger.SoundTrigger.GenericSoundModel in project android_frameworks_base by ResurrectionRemix.

the class SoundTriggerDbHelper method getGenericSoundModel.

public GenericSoundModel getGenericSoundModel(UUID model_uuid) {
    synchronized (this) {
        // Find the corresponding sound model ID for the keyphrase.
        String selectQuery = "SELECT  * FROM " + GenericSoundModelContract.TABLE + " WHERE " + GenericSoundModelContract.KEY_MODEL_UUID + "= '" + model_uuid + "'";
        SQLiteDatabase db = getReadableDatabase();
        Cursor c = db.rawQuery(selectQuery, null);
        try {
            if (c.moveToFirst()) {
                do {
                    byte[] data = c.getBlob(c.getColumnIndex(GenericSoundModelContract.KEY_DATA));
                    String vendor_uuid = c.getString(c.getColumnIndex(GenericSoundModelContract.KEY_VENDOR_UUID));
                    return new GenericSoundModel(model_uuid, UUID.fromString(vendor_uuid), data);
                } while (c.moveToNext());
            }
        } finally {
            c.close();
            db.close();
        }
    }
    return null;
}
Also used : GenericSoundModel(android.hardware.soundtrigger.SoundTrigger.GenericSoundModel) SQLiteDatabase(android.database.sqlite.SQLiteDatabase) Cursor(android.database.Cursor)

Example 14 with GenericSoundModel

use of android.hardware.soundtrigger.SoundTrigger.GenericSoundModel in project android_frameworks_base by ResurrectionRemix.

the class SoundTriggerTestService method reloadModel.

public synchronized void reloadModel(UUID modelUuid) {
    ModelInfo modelInfo = mModelInfoMap.get(modelUuid);
    if (modelInfo == null) {
        postError("Could not find model for: " + modelUuid.toString());
        return;
    }
    postMessage("Reloading model: " + modelInfo.name);
    GenericSoundModel soundModel = mSoundTriggerUtil.getSoundModel(modelUuid);
    if (soundModel == null) {
        postErrorToast("Sound model not found for " + modelInfo.name + "!");
        return;
    }
    GenericSoundModel updated = createNewSoundModel(modelInfo);
    boolean status = mSoundTriggerUtil.addOrUpdateSoundModel(updated);
    if (status) {
        postToast("Successfully reloaded " + modelInfo.name + ", UUID=" + modelInfo.modelUuid);
        setModelState(modelInfo, "Reloaded");
    } else {
        postErrorToast("Failed to reload " + modelInfo.name + ", UUID=" + modelInfo.modelUuid + "!");
        setModelState(modelInfo, "Failed to reload");
    }
}
Also used : GenericSoundModel(android.hardware.soundtrigger.SoundTrigger.GenericSoundModel)

Example 15 with GenericSoundModel

use of android.hardware.soundtrigger.SoundTrigger.GenericSoundModel in project android_frameworks_base by crdroidandroid.

the class GenericSoundModelTest method testFuzzGenericSoundModel.

/**
     * 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<ModelInfo>();
    for (int i = 0; i < numModels; i++) {
        // Create sound model
        byte[] data = new byte[1024];
        predictableRandom.nextBytes(data);
        UUID modelUuid = UUID.randomUUID();
        UUID mVendorUuid = UUID.randomUUID();
        GenericSoundModel model = new GenericSoundModel(modelUuid, mVendorUuid, data);
        ModelInfo modelInfo = new ModelInfo(model, STATUS_UNLOADED);
        modelInfos.add(modelInfo);
    }
    boolean captureTriggerAudio = true;
    boolean allowMultipleTriggers = true;
    RecognitionConfig config = new RecognitionConfig(captureTriggerAudio, allowMultipleTriggers, null, null);
    TestRecognitionStatusCallback spyCallback = spy(new TestRecognitionStatusCallback());
    int numOperationsToRun = 100;
    for (int i = 0; i < numOperationsToRun; i++) {
        // Select a random model
        int modelInfoIndex = predictableRandom.nextInt(modelInfos.size());
        ModelInfo modelInfo = (ModelInfo) modelInfos.get(modelInfoIndex);
        // Perform a random operation
        int operation = predictableRandom.nextInt(5);
        if (operation == 0 && modelInfo.status == STATUS_UNLOADED) {
            // Update and start sound model
            soundTriggerService.updateSoundModel(modelInfo.model);
            loadedModelUuids.add(modelInfo.model.uuid);
            modelInfo.status = STATUS_LOADED;
        } else if (operation == 1 && modelInfo.status == STATUS_LOADED) {
            // Start the sound model
            int r = soundTriggerService.startRecognition(new ParcelUuid(modelInfo.model.uuid), spyCallback, config);
            assertEquals("Could Not Start Recognition with code: " + r, android.hardware.soundtrigger.SoundTrigger.STATUS_OK, r);
            modelInfo.status = STATUS_STARTED;
        } else if (operation == 2 && modelInfo.status == STATUS_STARTED) {
            // Send trigger to stub HAL
            Socket socket = new Socket(InetAddress.getLocalHost(), 14035);
            DataOutputStream out = new DataOutputStream(socket.getOutputStream());
            out.writeBytes("trig " + modelInfo.model.uuid + "\r\n");
            out.flush();
            socket.close();
            // Verify trigger was received
            verify(spyCallback, timeout(100)).onGenericSoundTriggerDetected(any());
            reset(spyCallback);
        } else if (operation == 3 && modelInfo.status == STATUS_STARTED) {
            // Stop recognition
            int r = soundTriggerService.stopRecognition(new ParcelUuid(modelInfo.model.uuid), spyCallback);
            assertEquals("Could Not Stop Recognition with code: " + r, android.hardware.soundtrigger.SoundTrigger.STATUS_OK, r);
            modelInfo.status = STATUS_LOADED;
        } else if (operation == 4 && modelInfo.status != STATUS_UNLOADED) {
            // Delete sound model
            soundTriggerService.deleteSoundModel(new ParcelUuid(modelInfo.model.uuid));
            loadedModelUuids.remove(modelInfo.model.uuid);
            // Confirm it was deleted
            GenericSoundModel returnedModel = soundTriggerService.getSoundModel(new ParcelUuid(modelInfo.model.uuid));
            assertEquals(null, returnedModel);
            modelInfo.status = STATUS_UNLOADED;
        }
    }
}
Also used : ParcelUuid(android.os.ParcelUuid) DataOutputStream(java.io.DataOutputStream) ArrayList(java.util.ArrayList) GenericSoundModel(android.hardware.soundtrigger.SoundTrigger.GenericSoundModel) Random(java.util.Random) RecognitionConfig(android.hardware.soundtrigger.SoundTrigger.RecognitionConfig) UUID(java.util.UUID) Socket(java.net.Socket) LargeTest(android.test.suitebuilder.annotation.LargeTest)

Aggregations

GenericSoundModel (android.hardware.soundtrigger.SoundTrigger.GenericSoundModel)44 ParcelUuid (android.os.ParcelUuid)20 RecognitionConfig (android.hardware.soundtrigger.SoundTrigger.RecognitionConfig)12 LargeTest (android.test.suitebuilder.annotation.LargeTest)12 SQLiteDatabase (android.database.sqlite.SQLiteDatabase)8 SmallTest (android.test.suitebuilder.annotation.SmallTest)8 DataOutputStream (java.io.DataOutputStream)8 Socket (java.net.Socket)8 UUID (java.util.UUID)8 Cursor (android.database.Cursor)4 ArrayList (java.util.ArrayList)4 Random (java.util.Random)4