use of android.hardware.soundtrigger.SoundTrigger.GenericSoundModel in project android_frameworks_base by crdroidandroid.
the class GenericSoundModelTest method new_sound_model.
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);
}
use of android.hardware.soundtrigger.SoundTrigger.GenericSoundModel in project android_frameworks_base by crdroidandroid.
the class GenericSoundModelTest method testTriggerGenericSoundModel.
@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.uuid);
soundTriggerService.startRecognition(new ParcelUuid(model.uuid), spyCallback, config);
// Send trigger to stub HAL
Socket socket = new Socket(InetAddress.getLocalHost(), 14035);
DataOutputStream out = new DataOutputStream(socket.getOutputStream());
out.writeBytes("trig " + model.uuid.toString() + "\r\n");
out.flush();
socket.close();
// Verify trigger was received
verify(spyCallback, timeout(100)).onGenericSoundTriggerDetected(any());
}
use of android.hardware.soundtrigger.SoundTrigger.GenericSoundModel in project android_frameworks_base by crdroidandroid.
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;
}
use of android.hardware.soundtrigger.SoundTrigger.GenericSoundModel in project android_frameworks_base by crdroidandroid.
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();
}
}
}
Aggregations