use of android.hardware.soundtrigger.SoundTrigger.KeyphraseSoundModel in project android_frameworks_base by ResurrectionRemix.
the class TestEnrollmentActivity method onReEnrollButtonClicked.
/**
* Called when the user clicks the re-enroll button.
* Uses the previously enrolled sound model and makes changes to it before pushing it back.
*/
public void onReEnrollButtonClicked(View v) {
KeyphraseSoundModel soundModel = mEnrollmentUtil.getSoundModel(KEYPHRASE_ID, BCP47_LOCALE);
if (soundModel == null) {
Toast.makeText(this, "Sound model not found!!!", Toast.LENGTH_SHORT).show();
return;
}
// Generate a fake model to push.
byte[] data = new byte[2048];
mRandom.nextBytes(data);
KeyphraseSoundModel updated = new KeyphraseSoundModel(soundModel.uuid, soundModel.vendorUuid, data, soundModel.keyphrases);
boolean status = mEnrollmentUtil.addOrUpdateSoundModel(updated);
if (status) {
Toast.makeText(this, "Successfully re-enrolled, model UUID=" + updated.uuid, Toast.LENGTH_SHORT).show();
} else {
Toast.makeText(this, "Failed to re-enroll!!!", Toast.LENGTH_SHORT).show();
}
}
use of android.hardware.soundtrigger.SoundTrigger.KeyphraseSoundModel in project android_frameworks_base by ResurrectionRemix.
the class TestEnrollmentActivity method onUnEnrollButtonClicked.
/**
* Called when the user clicks the un-enroll button.
* Clears the enrollment information for the user.
*/
public void onUnEnrollButtonClicked(View v) {
KeyphraseSoundModel soundModel = mEnrollmentUtil.getSoundModel(KEYPHRASE_ID, BCP47_LOCALE);
if (soundModel == null) {
Toast.makeText(this, "Sound model not found!!!", Toast.LENGTH_SHORT).show();
return;
}
boolean status = mEnrollmentUtil.deleteSoundModel(KEYPHRASE_ID, BCP47_LOCALE);
if (status) {
Toast.makeText(this, "Successfully un-enrolled, model UUID=" + soundModel.uuid, Toast.LENGTH_SHORT).show();
} else {
Toast.makeText(this, "Failed to un-enroll!!!", Toast.LENGTH_SHORT).show();
}
}
use of android.hardware.soundtrigger.SoundTrigger.KeyphraseSoundModel in project android_frameworks_base by crdroidandroid.
the class TestEnrollmentActivity method onReEnrollButtonClicked.
/**
* Called when the user clicks the re-enroll button.
* Uses the previously enrolled sound model and makes changes to it before pushing it back.
*/
public void onReEnrollButtonClicked(View v) {
KeyphraseSoundModel soundModel = mEnrollmentUtil.getSoundModel(KEYPHRASE_ID, BCP47_LOCALE);
if (soundModel == null) {
Toast.makeText(this, "Sound model not found!!!", Toast.LENGTH_SHORT).show();
return;
}
// Generate a fake model to push.
byte[] data = new byte[2048];
mRandom.nextBytes(data);
KeyphraseSoundModel updated = new KeyphraseSoundModel(soundModel.uuid, soundModel.vendorUuid, data, soundModel.keyphrases);
boolean status = mEnrollmentUtil.addOrUpdateSoundModel(updated);
if (status) {
Toast.makeText(this, "Successfully re-enrolled, model UUID=" + updated.uuid, Toast.LENGTH_SHORT).show();
} else {
Toast.makeText(this, "Failed to re-enroll!!!", Toast.LENGTH_SHORT).show();
}
}
use of android.hardware.soundtrigger.SoundTrigger.KeyphraseSoundModel in project android_frameworks_base by crdroidandroid.
the class DatabaseHelper method deleteKeyphraseSoundModel.
/**
* Deletes the sound model and associated keyphrases.
*/
public boolean deleteKeyphraseSoundModel(int keyphraseId, int userHandle, String bcp47Locale) {
// Sanitize the locale to guard against SQL injection.
bcp47Locale = Locale.forLanguageTag(bcp47Locale).toLanguageTag();
synchronized (this) {
KeyphraseSoundModel soundModel = getKeyphraseSoundModel(keyphraseId, userHandle, bcp47Locale);
if (soundModel == null) {
return false;
}
// Delete all sound models for the given keyphrase and specified user.
SQLiteDatabase db = getWritableDatabase();
String soundModelClause = SoundModelContract.KEY_MODEL_UUID + "='" + soundModel.uuid.toString() + "'";
try {
return db.delete(SoundModelContract.TABLE, soundModelClause, null) != 0;
} finally {
db.close();
}
}
}
use of android.hardware.soundtrigger.SoundTrigger.KeyphraseSoundModel in project android_frameworks_base by crdroidandroid.
the class DatabaseHelper method getKeyphraseSoundModel.
/**
* Returns a matching {@link KeyphraseSoundModel} for the keyphrase ID.
* Returns null if a match isn't found.
*
* TODO: We only support one keyphrase currently.
*/
public KeyphraseSoundModel getKeyphraseSoundModel(int keyphraseId, int userHandle, String bcp47Locale) {
// Sanitize the locale to guard against SQL injection.
bcp47Locale = Locale.forLanguageTag(bcp47Locale).toLanguageTag();
synchronized (this) {
// Find the corresponding sound model ID for the keyphrase.
String selectQuery = "SELECT * FROM " + SoundModelContract.TABLE + " WHERE " + SoundModelContract.KEY_KEYPHRASE_ID + "= '" + keyphraseId + "' AND " + SoundModelContract.KEY_LOCALE + "='" + bcp47Locale + "'";
SQLiteDatabase db = getReadableDatabase();
Cursor c = db.rawQuery(selectQuery, null);
try {
if (c.moveToFirst()) {
do {
int type = c.getInt(c.getColumnIndex(SoundModelContract.KEY_TYPE));
if (type != SoundTrigger.SoundModel.TYPE_KEYPHRASE) {
if (DBG) {
Slog.w(TAG, "Ignoring SoundModel since it's type is incorrect");
}
continue;
}
String modelUuid = c.getString(c.getColumnIndex(SoundModelContract.KEY_MODEL_UUID));
if (modelUuid == null) {
Slog.w(TAG, "Ignoring SoundModel since it doesn't specify an ID");
continue;
}
String vendorUuidString = null;
int vendorUuidColumn = c.getColumnIndex(SoundModelContract.KEY_VENDOR_UUID);
if (vendorUuidColumn != -1) {
vendorUuidString = c.getString(vendorUuidColumn);
}
byte[] data = c.getBlob(c.getColumnIndex(SoundModelContract.KEY_DATA));
int recognitionModes = c.getInt(c.getColumnIndex(SoundModelContract.KEY_RECOGNITION_MODES));
int[] users = getArrayForCommaSeparatedString(c.getString(c.getColumnIndex(SoundModelContract.KEY_USERS)));
String modelLocale = c.getString(c.getColumnIndex(SoundModelContract.KEY_LOCALE));
String text = c.getString(c.getColumnIndex(SoundModelContract.KEY_HINT_TEXT));
// Only add keyphrases meant for the current user.
if (users == null) {
// No users present in the keyphrase.
Slog.w(TAG, "Ignoring SoundModel since it doesn't specify users");
continue;
}
boolean isAvailableForCurrentUser = false;
for (int user : users) {
if (userHandle == user) {
isAvailableForCurrentUser = true;
break;
}
}
if (!isAvailableForCurrentUser) {
if (DBG) {
Slog.w(TAG, "Ignoring SoundModel since user handles don't match");
}
continue;
} else {
if (DBG)
Slog.d(TAG, "Found a SoundModel for user: " + userHandle);
}
Keyphrase[] keyphrases = new Keyphrase[1];
keyphrases[0] = new Keyphrase(keyphraseId, recognitionModes, modelLocale, text, users);
UUID vendorUuid = null;
if (vendorUuidString != null) {
vendorUuid = UUID.fromString(vendorUuidString);
}
KeyphraseSoundModel model = new KeyphraseSoundModel(UUID.fromString(modelUuid), vendorUuid, data, keyphrases);
if (DBG) {
Slog.d(TAG, "Found SoundModel for the given keyphrase/locale/user: " + model);
}
return model;
} while (c.moveToNext());
}
Slog.w(TAG, "No SoundModel available for the given keyphrase");
} finally {
c.close();
db.close();
}
return null;
}
}
Aggregations