Search in sources :

Example 6 with GenericSoundModel

use of android.hardware.soundtrigger.SoundTrigger.GenericSoundModel in project platform_frameworks_base by android.

the class SoundTriggerTestService method unloadModel.

public synchronized void unloadModel(UUID modelUuid) {
    ModelInfo modelInfo = mModelInfoMap.get(modelUuid);
    if (modelInfo == null) {
        postError("Could not find model for: " + modelUuid.toString());
        return;
    }
    postMessage("Unloading model: " + modelInfo.name);
    GenericSoundModel soundModel = mSoundTriggerUtil.getSoundModel(modelUuid);
    if (soundModel == null) {
        postErrorToast("Sound model not found for " + modelInfo.name + "!");
        return;
    }
    modelInfo.detector = null;
    boolean status = mSoundTriggerUtil.deleteSoundModel(modelUuid);
    if (status) {
        postToast("Successfully unloaded " + modelInfo.name + ", UUID=" + soundModel.uuid);
        setModelState(modelInfo, "Unloaded");
    } else {
        postErrorToast("Failed to unload " + modelInfo.name + ", UUID=" + soundModel.uuid + "!");
        setModelState(modelInfo, "Failed to unload");
    }
}
Also used : GenericSoundModel(android.hardware.soundtrigger.SoundTrigger.GenericSoundModel)

Example 7 with GenericSoundModel

use of android.hardware.soundtrigger.SoundTrigger.GenericSoundModel in project platform_frameworks_base by android.

the class SoundTriggerDbHelper method deleteGenericSoundModel.

public boolean deleteGenericSoundModel(UUID model_uuid) {
    synchronized (this) {
        GenericSoundModel soundModel = getGenericSoundModel(model_uuid);
        if (soundModel == null) {
            return false;
        }
        // Delete all sound models for the given keyphrase and specified user.
        SQLiteDatabase db = getWritableDatabase();
        String soundModelClause = GenericSoundModelContract.KEY_MODEL_UUID + "='" + soundModel.uuid.toString() + "'";
        try {
            return db.delete(GenericSoundModelContract.TABLE, soundModelClause, null) != 0;
        } finally {
            db.close();
        }
    }
}
Also used : GenericSoundModel(android.hardware.soundtrigger.SoundTrigger.GenericSoundModel) SQLiteDatabase(android.database.sqlite.SQLiteDatabase)

Example 8 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 9 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 10 with GenericSoundModel

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

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)

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