diff options
author | Charles Chen <clchen@google.com> | 2009-12-11 13:54:11 -0800 |
---|---|---|
committer | Charles Chen <clchen@google.com> | 2009-12-11 13:54:11 -0800 |
commit | ab089078b1d42f8ecf549669847b47c0c2c5854b (patch) | |
tree | d504450706f15074cea04bd62baccec1aa629ee2 /packages | |
parent | 6ddcf01a9033ee7ff4230efd117d7bcc8b5b3cc1 (diff) | |
download | frameworks_base-ab089078b1d42f8ecf549669847b47c0c2c5854b.zip frameworks_base-ab089078b1d42f8ecf549669847b47c0c2c5854b.tar.gz frameworks_base-ab089078b1d42f8ecf549669847b47c0c2c5854b.tar.bz2 |
Fix for a race condition that can occur if an utterance
is stopped right when it completes.
Diffstat (limited to 'packages')
-rwxr-xr-x | packages/TtsService/src/android/tts/TtsService.java | 37 |
1 files changed, 21 insertions, 16 deletions
diff --git a/packages/TtsService/src/android/tts/TtsService.java b/packages/TtsService/src/android/tts/TtsService.java index 217d3bb..5c4bbb8 100755 --- a/packages/TtsService/src/android/tts/TtsService.java +++ b/packages/TtsService/src/android/tts/TtsService.java @@ -596,22 +596,27 @@ public class TtsService extends Service implements OnCompletionListener { } } - public void onCompletion(MediaPlayer arg0) { - String callingApp = mCurrentSpeechItem.mCallingApp; - ArrayList<String> params = mCurrentSpeechItem.mParams; - String utteranceId = ""; - if (params != null){ - for (int i = 0; i < params.size() - 1; i = i + 2){ - String param = params.get(i); - if (param.equals(TextToSpeech.Engine.KEY_PARAM_UTTERANCE_ID)){ - utteranceId = params.get(i+1); - } - } - } - if (utteranceId.length() > 0){ - dispatchUtteranceCompletedCallback(utteranceId, callingApp); - } - processSpeechQueue(); + public void onCompletion(MediaPlayer arg0) {
+ // mCurrentSpeechItem may become null if it is stopped at the same
+ // time it completes.
+ SpeechItem currentSpeechItemCopy = mCurrentSpeechItem;
+ if (currentSpeechItemCopy != null) {
+ String callingApp = currentSpeechItemCopy.mCallingApp;
+ ArrayList<String> params = currentSpeechItemCopy.mParams;
+ String utteranceId = "";
+ if (params != null) {
+ for (int i = 0; i < params.size() - 1; i = i + 2) {
+ String param = params.get(i);
+ if (param.equals(TextToSpeech.Engine.KEY_PARAM_UTTERANCE_ID)) {
+ utteranceId = params.get(i + 1);
+ }
+ }
+ }
+ if (utteranceId.length() > 0) {
+ dispatchUtteranceCompletedCallback(utteranceId, callingApp);
+ }
+ }
+ processSpeechQueue();
} private int playSilence(String callingApp, long duration, int queueMode, |