diff options
author | Sandeep Siddhartha <sansid@google.com> | 2014-07-16 23:55:41 -0700 |
---|---|---|
committer | Sandeep Siddhartha <sansid@google.com> | 2014-07-17 18:44:12 -0700 |
commit | 7444c906faef1f7a9a6e6f7a443ba156f1e856be (patch) | |
tree | d422b62cbc7a5aa67a6edeb1c3d1bc3505f1f9bb /services | |
parent | ca58ddf7c82dd0857de0c3d49d7eb87a842ee4ce (diff) | |
download | frameworks_base-7444c906faef1f7a9a6e6f7a443ba156f1e856be.zip frameworks_base-7444c906faef1f7a9a6e6f7a443ba156f1e856be.tar.gz frameworks_base-7444c906faef1f7a9a6e6f7a443ba156f1e856be.tar.bz2 |
Test hotword flow
- Also fix a few StrictMode violations in DatabaseHelper
Change-Id: I93f27407dae34cc0dca5e9f891d4ca718d6010a5
Diffstat (limited to 'services')
-rw-r--r-- | services/voiceinteraction/java/com/android/server/voiceinteraction/DatabaseHelper.java | 18 |
1 files changed, 11 insertions, 7 deletions
diff --git a/services/voiceinteraction/java/com/android/server/voiceinteraction/DatabaseHelper.java b/services/voiceinteraction/java/com/android/server/voiceinteraction/DatabaseHelper.java index bed85fc..27bec9f 100644 --- a/services/voiceinteraction/java/com/android/server/voiceinteraction/DatabaseHelper.java +++ b/services/voiceinteraction/java/com/android/server/voiceinteraction/DatabaseHelper.java @@ -105,17 +105,18 @@ public class DatabaseHelper extends SQLiteOpenHelper { if (db.insertWithOnConflict( SoundModelContract.TABLE, null, values, SQLiteDatabase.CONFLICT_REPLACE) != -1) { for (Keyphrase keyphrase : soundModel.keyphrases) { - status &= addOrUpdateKeyphrase(soundModel.uuid, keyphrase); + status &= addOrUpdateKeyphrase(db, soundModel.uuid, keyphrase); } + db.close(); return status; } else { Slog.w(TAG, "Failed to persist sound model to database"); + db.close(); return false; } } - private boolean addOrUpdateKeyphrase(UUID modelId, Keyphrase keyphrase) { - SQLiteDatabase db = getWritableDatabase(); + private boolean addOrUpdateKeyphrase(SQLiteDatabase db, UUID modelId, Keyphrase keyphrase) { ContentValues values = new ContentValues(); values.put(KeyphraseContract.KEY_ID, keyphrase.id); values.put(KeyphraseContract.KEY_RECOGNITION_MODES, keyphrase.recognitionModeFlags); @@ -148,6 +149,7 @@ public class DatabaseHelper extends SQLiteOpenHelper { Slog.w(TAG, "No keyphrases deleted from the database"); status = false; } + db.close(); return status; } @@ -157,7 +159,7 @@ public class DatabaseHelper extends SQLiteOpenHelper { public List<KeyphraseSoundModel> getKephraseSoundModels() { List<KeyphraseSoundModel> models = new ArrayList<>(); String selectQuery = "SELECT * FROM " + SoundModelContract.TABLE; - SQLiteDatabase db = this.getReadableDatabase(); + SQLiteDatabase db = getReadableDatabase(); Cursor c = db.rawQuery(selectQuery, null); // looping through all rows and adding to list @@ -172,17 +174,18 @@ public class DatabaseHelper extends SQLiteOpenHelper { byte[] data = c.getBlob(c.getColumnIndex(SoundModelContract.KEY_DATA)); // Get all the keyphrases for this this sound model. models.add(new KeyphraseSoundModel( - UUID.fromString(id), data, getKeyphrasesForSoundModel(id))); + UUID.fromString(id), data, getKeyphrasesForSoundModel(db, id))); } while (c.moveToNext()); } + c.close(); + db.close(); return models; } - private Keyphrase[] getKeyphrasesForSoundModel(String modelId) { + private Keyphrase[] getKeyphrasesForSoundModel(SQLiteDatabase db, String modelId) { List<Keyphrase> keyphrases = new ArrayList<>(); String selectQuery = "SELECT * FROM " + KeyphraseContract.TABLE + " WHERE " + KeyphraseContract.KEY_SOUND_MODEL_ID + " = '" + modelId + "'"; - SQLiteDatabase db = this.getReadableDatabase(); Cursor c = db.rawQuery(selectQuery, null); // looping through all rows and adding to list @@ -199,6 +202,7 @@ public class DatabaseHelper extends SQLiteOpenHelper { } Keyphrase[] keyphraseArr = new Keyphrase[keyphrases.size()]; keyphrases.toArray(keyphraseArr); + c.close(); return keyphraseArr; } } |