Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit ab089078 authored by Charles Chen's avatar Charles Chen
Browse files

Fix for a race condition that can occur if an utterance

is stopped right when it completes.
parent 6ddcf01a
Loading
Loading
Loading
Loading
+21 −16
Original line number Diff line number Diff line
@@ -597,8 +597,12 @@ public class TtsService extends Service implements OnCompletionListener {
    }

    public void onCompletion(MediaPlayer arg0) {
        String callingApp = mCurrentSpeechItem.mCallingApp;
        ArrayList<String> params = mCurrentSpeechItem.mParams;
        // 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) {
@@ -611,6 +615,7 @@ public class TtsService extends Service implements OnCompletionListener {
            if (utteranceId.length() > 0) {
                dispatchUtteranceCompletedCallback(utteranceId, callingApp);
            }
        }
        processSpeechQueue();
    }