diff options
author | Mike LeBeau <mlebeau@android.com> | 2010-02-10 19:34:56 -0800 |
---|---|---|
committer | Mike LeBeau <mlebeau@android.com> | 2010-02-11 11:40:02 -0800 |
commit | 5d34e9b63d5305934dcedac11e8dd658ae23c174 (patch) | |
tree | 7a6c896c25efa8df5163d5ea4086cd1c3615e1e4 /packages/SettingsProvider | |
parent | 575c6710a38f608aca2c25e7784674a47d18a871 (diff) | |
download | frameworks_base-5d34e9b63d5305934dcedac11e8dd658ae23c174.zip frameworks_base-5d34e9b63d5305934dcedac11e8dd658ae23c174.tar.gz frameworks_base-5d34e9b63d5305934dcedac11e8dd658ae23c174.tar.bz2 |
Add new setting for the ComponentName of the service to be used
for voice recognition on the device. Right now this just queries
the package manager at boot and finds the (hopefully) single
available recognizer.
TODO: Add an attribute to let recognition services expose a settings
activity, and expose the settings activity of the chosen recognition
service in the system settings for voice input & output.
Diffstat (limited to 'packages/SettingsProvider')
-rw-r--r-- | packages/SettingsProvider/src/com/android/providers/settings/DatabaseHelper.java | 50 |
1 files changed, 49 insertions, 1 deletions
diff --git a/packages/SettingsProvider/src/com/android/providers/settings/DatabaseHelper.java b/packages/SettingsProvider/src/com/android/providers/settings/DatabaseHelper.java index 8b75b61..4e1e0a2 100644 --- a/packages/SettingsProvider/src/com/android/providers/settings/DatabaseHelper.java +++ b/packages/SettingsProvider/src/com/android/providers/settings/DatabaseHelper.java @@ -23,6 +23,8 @@ import android.content.Intent; import android.content.pm.ActivityInfo; import android.content.pm.PackageInfo; import android.content.pm.PackageManager; +import android.content.pm.ResolveInfo; +import android.content.pm.ServiceInfo; import android.content.res.Resources; import android.database.Cursor; import android.database.sqlite.SQLiteDatabase; @@ -36,6 +38,7 @@ import android.net.ConnectivityManager; import android.os.Environment; import android.os.SystemProperties; import android.provider.Settings; +import android.speech.RecognizerIntent; import android.text.TextUtils; import android.util.Config; import android.util.Log; @@ -72,7 +75,7 @@ public class DatabaseHelper extends SQLiteOpenHelper { // database gets upgraded properly. At a minimum, please confirm that 'upgradeVersion' // is properly propagated through your change. Not doing so will result in a loss of user // settings. - private static final int DATABASE_VERSION = 48; + private static final int DATABASE_VERSION = 49; private Context mContext; @@ -611,6 +614,23 @@ public class DatabaseHelper extends SQLiteOpenHelper { } upgradeVersion = 48; } + + if (upgradeVersion == 48) { + /* + * Adding a new setting for which voice recognition service to use. + */ + db.beginTransaction(); + try { + SQLiteStatement stmt = db.compileStatement("INSERT OR IGNORE INTO secure(name,value)" + + " VALUES(?,?);"); + loadVoiceRecognitionServiceSetting(stmt); + stmt.close(); + db.setTransactionSuccessful(); + } finally { + db.endTransaction(); + } + upgradeVersion = 49; + } if (upgradeVersion != currentVersion) { Log.w(TAG, "Got stuck trying to upgrade from version " + upgradeVersion @@ -955,6 +975,8 @@ public class DatabaseHelper extends SQLiteOpenHelper { loadBooleanSetting(stmt, Settings.Secure.MOUNT_UMS_NOTIFY_ENABLED, R.bool.def_mount_ums_notify_enabled); + + loadVoiceRecognitionServiceSetting(stmt); stmt.close(); } @@ -966,6 +988,32 @@ public class DatabaseHelper extends SQLiteOpenHelper { loadStringSetting(stmt, Settings.Secure.BACKUP_TRANSPORT, R.string.def_backup_transport); } + + /** + * Introduced in database version 49. + */ + private void loadVoiceRecognitionServiceSetting(SQLiteStatement stmt) { + String selectedService = null; + List<ResolveInfo> availableRecognitionServices = + mContext.getPackageManager().queryIntentServices( + new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH), 0); + int numAvailable = availableRecognitionServices.size(); + + if (numAvailable == 0) { + Log.w(TAG, "no available voice recognition services found"); + } else { + if (numAvailable > 1) { + Log.w(TAG, "more than one voice recognition service found, picking first"); + } + + ServiceInfo serviceInfo = availableRecognitionServices.get(0).serviceInfo; + selectedService = + new ComponentName(serviceInfo.packageName, serviceInfo.name).flattenToString(); + } + + loadSetting(stmt, Settings.Secure.VOICE_RECOGNITION_SERVICE, + selectedService == null ? "" : selectedService); + } private void loadSetting(SQLiteStatement stmt, String key, Object value) { stmt.bindString(1, key); |