Merge "Fix issue when QUEUE_DESTROY arrive at the same time." into nyc-dev
am: e767e1b
* commit 'e767e1bc17eeb4302ef503bcc83ed8697db91433':
Fix issue when QUEUE_DESTROY arrive at the same time.
Change-Id: Ic1d42d8b74ec27be4a3d57c3df8c221d5907c739
This commit is contained in:
@@ -457,8 +457,17 @@ public abstract class TextToSpeechService extends Service {
|
|||||||
private class SynthHandler extends Handler {
|
private class SynthHandler extends Handler {
|
||||||
private SpeechItem mCurrentSpeechItem = null;
|
private SpeechItem mCurrentSpeechItem = null;
|
||||||
|
|
||||||
private ArrayList<Object> mFlushedObjects = new ArrayList<Object>();
|
// When a message with QUEUE_FLUSH arrives we add the caller identity to the List and when a
|
||||||
private boolean mFlushAll;
|
// message with QUEUE_DESTROY arrives we increment mFlushAll. Then a message is added to the
|
||||||
|
// handler queue that removes the caller identify from the list and decrements the mFlushAll
|
||||||
|
// counter. This is so that when a message is processed and the caller identity is in the
|
||||||
|
// list or mFlushAll is not zero, we know that the message should be flushed.
|
||||||
|
// It's important that mFlushedObjects is a List and not a Set, and that mFlushAll is an
|
||||||
|
// int and not a bool. This is because when multiple messages arrive with QUEUE_FLUSH or
|
||||||
|
// QUEUE_DESTROY, we want to keep flushing messages until we arrive at the last QUEUE_FLUSH
|
||||||
|
// or QUEUE_DESTROY message.
|
||||||
|
private List<Object> mFlushedObjects = new ArrayList<>();
|
||||||
|
private int mFlushAll = 0;
|
||||||
|
|
||||||
public SynthHandler(Looper looper) {
|
public SynthHandler(Looper looper) {
|
||||||
super(looper);
|
super(looper);
|
||||||
@@ -467,7 +476,7 @@ public abstract class TextToSpeechService extends Service {
|
|||||||
private void startFlushingSpeechItems(Object callerIdentity) {
|
private void startFlushingSpeechItems(Object callerIdentity) {
|
||||||
synchronized (mFlushedObjects) {
|
synchronized (mFlushedObjects) {
|
||||||
if (callerIdentity == null) {
|
if (callerIdentity == null) {
|
||||||
mFlushAll = true;
|
mFlushAll += 1;
|
||||||
} else {
|
} else {
|
||||||
mFlushedObjects.add(callerIdentity);
|
mFlushedObjects.add(callerIdentity);
|
||||||
}
|
}
|
||||||
@@ -476,7 +485,7 @@ public abstract class TextToSpeechService extends Service {
|
|||||||
private void endFlushingSpeechItems(Object callerIdentity) {
|
private void endFlushingSpeechItems(Object callerIdentity) {
|
||||||
synchronized (mFlushedObjects) {
|
synchronized (mFlushedObjects) {
|
||||||
if (callerIdentity == null) {
|
if (callerIdentity == null) {
|
||||||
mFlushAll = false;
|
mFlushAll -= 1;
|
||||||
} else {
|
} else {
|
||||||
mFlushedObjects.remove(callerIdentity);
|
mFlushedObjects.remove(callerIdentity);
|
||||||
}
|
}
|
||||||
@@ -484,7 +493,7 @@ public abstract class TextToSpeechService extends Service {
|
|||||||
}
|
}
|
||||||
private boolean isFlushed(SpeechItem speechItem) {
|
private boolean isFlushed(SpeechItem speechItem) {
|
||||||
synchronized (mFlushedObjects) {
|
synchronized (mFlushedObjects) {
|
||||||
return mFlushAll || mFlushedObjects.contains(speechItem.getCallerIdentity());
|
return mFlushAll > 0 || mFlushedObjects.contains(speechItem.getCallerIdentity());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user