summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSandeep Siddhartha <sansid@google.com>2014-08-07 19:07:32 +0000
committerAndroid Git Automerger <android-git-automerger@android.com>2014-08-07 19:07:32 +0000
commit4d72ebe6427bf1e7b85dd0772fc6fb78385fcea9 (patch)
treedc45c8dc6996e93d4975dd106a7c29a8a8e4282a
parent6c10af5c2c546c6a43c5e24028cba922cb113535 (diff)
parente849e4aaec26d94d4ca8bdd80031a4c966b81ab4 (diff)
downloadframeworks_base-4d72ebe6427bf1e7b85dd0772fc6fb78385fcea9.zip
frameworks_base-4d72ebe6427bf1e7b85dd0772fc6fb78385fcea9.tar.gz
frameworks_base-4d72ebe6427bf1e7b85dd0772fc6fb78385fcea9.tar.bz2
am 7e0e4515: am e931a72d: Handle same keyphrase for multiple users
* commit '7e0e4515db07858254c04a2a347b4758689d4615': Handle same keyphrase for multiple users
-rw-r--r--services/voiceinteraction/java/com/android/server/voiceinteraction/DatabaseHelper.java112
-rw-r--r--services/voiceinteraction/java/com/android/server/voiceinteraction/VoiceInteractionManagerService.java13
2 files changed, 69 insertions, 56 deletions
diff --git a/services/voiceinteraction/java/com/android/server/voiceinteraction/DatabaseHelper.java b/services/voiceinteraction/java/com/android/server/voiceinteraction/DatabaseHelper.java
index b4c221f..f0ecafe 100644
--- a/services/voiceinteraction/java/com/android/server/voiceinteraction/DatabaseHelper.java
+++ b/services/voiceinteraction/java/com/android/server/voiceinteraction/DatabaseHelper.java
@@ -41,12 +41,12 @@ public class DatabaseHelper extends SQLiteOpenHelper {
static final boolean DBG = true;
private static final String NAME = "sound_model.db";
- private static final int VERSION = 3;
+ private static final int VERSION = 4;
public static interface SoundModelContract {
public static final String TABLE = "sound_model";
- public static final String KEY_KEYPHRASE_ID = "keyphrase_id";
public static final String KEY_MODEL_UUID = "model_uuid";
+ public static final String KEY_KEYPHRASE_ID = "keyphrase_id";
public static final String KEY_TYPE = "type";
public static final String KEY_DATA = "data";
public static final String KEY_RECOGNITION_MODES = "recognition_modes";
@@ -58,8 +58,8 @@ public class DatabaseHelper extends SQLiteOpenHelper {
// Table Create Statement
private static final String CREATE_TABLE_SOUND_MODEL = "CREATE TABLE "
+ SoundModelContract.TABLE + "("
- + SoundModelContract.KEY_KEYPHRASE_ID + " INTEGER PRIMARY KEY,"
- + SoundModelContract.KEY_MODEL_UUID + " TEXT,"
+ + SoundModelContract.KEY_MODEL_UUID + " TEXT PRIMARY KEY,"
+ + SoundModelContract.KEY_KEYPHRASE_ID + " INTEGER,"
+ SoundModelContract.KEY_TYPE + " INTEGER,"
+ SoundModelContract.KEY_DATA + " BLOB,"
+ SoundModelContract.KEY_RECOGNITION_MODES + " INTEGER,"
@@ -122,10 +122,16 @@ public class DatabaseHelper extends SQLiteOpenHelper {
/**
* Deletes the sound model and associated keyphrases.
*/
- public boolean deleteKeyphraseSoundModel(int keyphraseId) {
+ public boolean deleteKeyphraseSoundModel(UUID modelUuid) {
+ if (modelUuid == null) {
+ Slog.w(TAG, "Model UUID must be specified for deletion");
+ return false;
+ }
+
synchronized(this) {
SQLiteDatabase db = getWritableDatabase();
- String soundModelClause = SoundModelContract.KEY_KEYPHRASE_ID + "=" + keyphraseId;
+ String soundModelClause = SoundModelContract.KEY_MODEL_UUID + "="
+ + modelUuid.toString();
try {
return db.delete(SoundModelContract.TABLE, soundModelClause, null) != 0;
@@ -151,52 +157,56 @@ public class DatabaseHelper extends SQLiteOpenHelper {
try {
if (c.moveToFirst()) {
- int type = c.getInt(c.getColumnIndex(SoundModelContract.KEY_TYPE));
- if (type != SoundTrigger.SoundModel.TYPE_KEYPHRASE) {
- Slog.w(TAG, "No KeyphraseSoundModel available for the given keyphrase");
- return null;
- }
-
- String modelUuid = c.getString(
- c.getColumnIndex(SoundModelContract.KEY_MODEL_UUID));
- if (modelUuid == null) {
- Slog.w(TAG, "Ignoring sound model since it doesn't specify an ID");
- return null;
- }
-
- 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 locale = 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 keyphrase since it doesn't specify users");
- return null;
- }
- boolean isAvailableForCurrentUser = false;
- int currentUser = mUserManager.getUserHandle();
- for (int user : users) {
- if (currentUser == user) {
- isAvailableForCurrentUser = true;
- break;
+ do {
+ int type = c.getInt(c.getColumnIndex(SoundModelContract.KEY_TYPE));
+ if (type != SoundTrigger.SoundModel.TYPE_KEYPHRASE) {
+ Slog.w(TAG, "Ignoring sound model since it's type is incorrect");
+ continue;
+ }
+
+ String modelUuid = c.getString(
+ c.getColumnIndex(SoundModelContract.KEY_MODEL_UUID));
+ if (modelUuid == null) {
+ Slog.w(TAG, "Ignoring sound model since it doesn't specify an ID");
+ continue;
}
- }
- if (!isAvailableForCurrentUser) {
- Slog.w(TAG, "Ignoring keyphrase since it's not for the current user");
- return null;
- }
-
- Keyphrase[] keyphrases = new Keyphrase[1];
- keyphrases[0] = new Keyphrase(
- keyphraseId, recognitionModes, locale, text, users);
- return new KeyphraseSoundModel(UUID.fromString(modelUuid),
- null /* FIXME use vendor UUID */, data, keyphrases);
+
+ 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 locale = 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 keyphrase since it doesn't specify users");
+ continue;
+ }
+
+ boolean isAvailableForCurrentUser = false;
+ int currentUser = mUserManager.getUserHandle();
+ for (int user : users) {
+ if (currentUser == user) {
+ isAvailableForCurrentUser = true;
+ break;
+ }
+ }
+ if (!isAvailableForCurrentUser) {
+ Slog.w(TAG, "Ignoring keyphrase since it's not for the current user");
+ continue;
+ }
+
+ Keyphrase[] keyphrases = new Keyphrase[1];
+ keyphrases[0] = new Keyphrase(
+ keyphraseId, recognitionModes, locale, text, users);
+ return new KeyphraseSoundModel(UUID.fromString(modelUuid),
+ null /* FIXME use vendor UUID */, data, keyphrases);
+ } while (c.moveToNext());
}
Slog.w(TAG, "No SoundModel available for the given keyphrase");
} finally {
diff --git a/services/voiceinteraction/java/com/android/server/voiceinteraction/VoiceInteractionManagerService.java b/services/voiceinteraction/java/com/android/server/voiceinteraction/VoiceInteractionManagerService.java
index 75d41aa..eda7bd2 100644
--- a/services/voiceinteraction/java/com/android/server/voiceinteraction/VoiceInteractionManagerService.java
+++ b/services/voiceinteraction/java/com/android/server/voiceinteraction/VoiceInteractionManagerService.java
@@ -301,19 +301,22 @@ public class VoiceInteractionManagerService extends SystemService {
}
final long caller = Binder.clearCallingIdentity();
+ boolean deleted = false;
try {
- if (mDbHelper.deleteKeyphraseSoundModel(keyphraseId)) {
+ KeyphraseSoundModel soundModel = mDbHelper.getKeyphraseSoundModel(keyphraseId);
+ if (soundModel != null) {
+ deleted = mDbHelper.deleteKeyphraseSoundModel(soundModel.uuid);
+ }
+ return deleted ? SoundTriggerHelper.STATUS_OK : SoundTriggerHelper.STATUS_ERROR;
+ } finally {
+ if (deleted) {
synchronized (this) {
// Notify the voice interaction service of a change in sound models.
if (mImpl != null && mImpl.mService != null) {
mImpl.notifySoundModelsChangedLocked();
}
}
- return SoundTriggerHelper.STATUS_OK;
- } else {
- return SoundTriggerHelper.STATUS_ERROR;
}
- } finally {
Binder.restoreCallingIdentity(caller);
}
}