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 | |
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
-rw-r--r-- | services/voiceinteraction/java/com/android/server/voiceinteraction/DatabaseHelper.java | 18 | ||||
-rw-r--r-- | tests/VoiceInteraction/src/com/android/test/voiceinteraction/MainInteractionService.java | 46 |
2 files changed, 57 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; } } diff --git a/tests/VoiceInteraction/src/com/android/test/voiceinteraction/MainInteractionService.java b/tests/VoiceInteraction/src/com/android/test/voiceinteraction/MainInteractionService.java index ab2e8ac..edb28ea 100644 --- a/tests/VoiceInteraction/src/com/android/test/voiceinteraction/MainInteractionService.java +++ b/tests/VoiceInteraction/src/com/android/test/voiceinteraction/MainInteractionService.java @@ -18,6 +18,8 @@ package com.android.test.voiceinteraction; import android.content.Intent; import android.os.Bundle; +import android.service.voice.AlwaysOnHotwordDetector; +import android.service.voice.AlwaysOnHotwordDetector.Callback; import android.service.voice.VoiceInteractionService; import android.util.Log; @@ -26,6 +28,25 @@ import java.util.Arrays; public class MainInteractionService extends VoiceInteractionService { static final String TAG = "MainInteractionService"; + private final Callback mHotwordCallback = new Callback() { + @Override + public void onDetected(byte[] data) { + Log.i(TAG, "onDetected"); + } + + @Override + public void onDetectionStarted() { + Log.i(TAG, "onDetectionStarted"); + } + + @Override + public void onDetectionStopped() { + Log.i(TAG, "onDetectionStopped"); + } + }; + + private AlwaysOnHotwordDetector mHotwordDetector; + @Override public void onReady() { super.onReady(); @@ -33,6 +54,31 @@ public class MainInteractionService extends VoiceInteractionService { Log.i(TAG, "Keyphrase enrollment error? " + getKeyphraseEnrollmentInfo().getParseError()); Log.i(TAG, "Keyphrase enrollment meta-data: " + Arrays.toString(getKeyphraseEnrollmentInfo().listKeyphraseMetadata())); + + mHotwordDetector = getAlwaysOnHotwordDetector("Hello There", "en-US", mHotwordCallback); + int availability = mHotwordDetector.getAvailability(); + Log.i(TAG, "Hotword availability = " + availability); + + switch (availability) { + case AlwaysOnHotwordDetector.KEYPHRASE_HARDWARE_UNAVAILABLE: + Log.i(TAG, "KEYPHRASE_HARDWARE_UNAVAILABLE"); + break; + case AlwaysOnHotwordDetector.KEYPHRASE_UNSUPPORTED: + Log.i(TAG, "KEYPHRASE_UNSUPPORTED"); + break; + case AlwaysOnHotwordDetector.KEYPHRASE_UNENROLLED: + Log.i(TAG, "KEYPHRASE_UNENROLLED"); + Intent enroll = mHotwordDetector.getManageIntent( + AlwaysOnHotwordDetector.MANAGE_ACTION_ENROLL); + Log.i(TAG, "Need to enroll with " + enroll); + break; + case AlwaysOnHotwordDetector.KEYPHRASE_ENROLLED: + Log.i(TAG, "KEYPHRASE_ENROLLED"); + int status = mHotwordDetector.startRecognition( + AlwaysOnHotwordDetector.RECOGNITION_FLAG_NONE); + Log.i(TAG, "startRecognition status = " + status); + break; + } } @Override |