diff options
author | Valentin Kravtsov <valentink@google.com> | 2010-02-05 16:26:04 +0000 |
---|---|---|
committer | Valentin Kravtsov <valentink@google.com> | 2010-02-08 14:04:18 +0000 |
commit | 7a3c9d31bbc57f76d18d465eca605f28dc206f00 (patch) | |
tree | a7fea163a1e2eba3fc45fbfbd889da69176e9bd8 /core | |
parent | 1009e82ef2985a55f0afcbfa7f31bddb73039982 (diff) | |
download | frameworks_base-7a3c9d31bbc57f76d18d465eca605f28dc206f00.zip frameworks_base-7a3c9d31bbc57f76d18d465eca605f28dc206f00.tar.gz frameworks_base-7a3c9d31bbc57f76d18d465eca605f28dc206f00.tar.bz2 |
Fixing a bug when installing VoiceSearch cause error
Reinstalling VoiceIME created a problem because RecognitionService expected the first command to be setListener, in this version, such command is added
if the connection is broken.
Change-Id: Ia102fc1843053e2bdd330b380c2685a1227081b2
Diffstat (limited to 'core')
-rw-r--r-- | core/java/android/speech/RecognitionManager.java | 27 |
1 files changed, 18 insertions, 9 deletions
diff --git a/core/java/android/speech/RecognitionManager.java b/core/java/android/speech/RecognitionManager.java index 0d25b2f..7915208 100644 --- a/core/java/android/speech/RecognitionManager.java +++ b/core/java/android/speech/RecognitionManager.java @@ -216,7 +216,6 @@ public class RecognitionManager { throw new IllegalArgumentException("intent must not be null"); } checkIsCalledFromMainThread(); - checkIsCommandAllowed(); if (mConnection == null) { // first time connection mConnection = new Connection(); if (!mContext.bindService(new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH), @@ -243,7 +242,6 @@ public class RecognitionManager { */ public void stopListening() { checkIsCalledFromMainThread(); - checkIsCommandAllowed(); putMessage(Message.obtain(mHandler, MSG_STOP)); } @@ -254,7 +252,6 @@ public class RecognitionManager { */ public void cancel() { checkIsCalledFromMainThread(); - checkIsCommandAllowed(); putMessage(Message.obtain(mHandler, MSG_CANCEL)); } @@ -265,12 +262,6 @@ public class RecognitionManager { } } - private void checkIsCommandAllowed() { - if (mService == null && mPendingTasks.isEmpty()) { // setListener message must be there - throw new IllegalStateException("Listener must be set before any command is called"); - } - } - private void putMessage(Message msg) { if (mService == null) { mPendingTasks.offer(msg); @@ -281,6 +272,9 @@ public class RecognitionManager { /** sends the actual message to the service */ private void handleStartListening(Intent recognizerIntent) { + if (!checkOpenConnection()) { + return; + } try { mService.startListening(recognizerIntent, mListener); if (DBG) Log.d(TAG, "service start listening command succeded"); @@ -292,6 +286,9 @@ public class RecognitionManager { /** sends the actual message to the service */ private void handleStopMessage() { + if (!checkOpenConnection()) { + return; + } try { mService.stopListening(mListener); if (DBG) Log.d(TAG, "service stop listening command succeded"); @@ -303,6 +300,9 @@ public class RecognitionManager { /** sends the actual message to the service */ private void handleCancelMessage() { + if (!checkOpenConnection()) { + return; + } try { mService.cancel(mListener); if (DBG) Log.d(TAG, "service cancel command succeded"); @@ -311,6 +311,15 @@ public class RecognitionManager { mListener.onError(ERROR_CLIENT); } } + + private boolean checkOpenConnection() { + if (mService != null) { + return true; + } + mListener.onError(ERROR_CLIENT); + Log.e(TAG, "not connected to the recognition service"); + return false; + } /** changes the listener */ private void handleChangeListener(RecognitionListener listener) { |