am 125be9c8: Merge "Fixing a race condition in RecognitionService" into gingerbread

* commit '125be9c85a3bf71add2841d4195905c1e681a83e':
  Fixing a race condition in RecognitionService
This commit is contained in:
Valentin Kravtsov
2011-03-18 09:04:33 -07:00
committed by Android Git Automerger

View File

@@ -68,6 +68,8 @@ public abstract class RecognitionService extends Service {
private static final int MSG_CANCEL = 3;
private static final int MSG_RESET = 4;
private final Handler mHandler = new Handler() {
@Override
public void handleMessage(Message msg) {
@@ -81,6 +83,10 @@ public abstract class RecognitionService extends Service {
break;
case MSG_CANCEL:
dispatchCancel((IRecognitionListener) msg.obj);
break;
case MSG_RESET:
dispatchClearCallback();
break;
}
}
};
@@ -128,6 +134,10 @@ public abstract class RecognitionService extends Service {
}
}
private void dispatchClearCallback() {
mCurrentCallback = null;
}
private class StartListeningArgs {
public final Intent mIntent;
@@ -241,7 +251,7 @@ public abstract class RecognitionService extends Service {
* @param error code is defined in {@link SpeechRecognizer}
*/
public void error(int error) throws RemoteException {
mCurrentCallback = null;
Message.obtain(mHandler, MSG_RESET).sendToTarget();
mListener.onError(error);
}
@@ -278,7 +288,7 @@ public abstract class RecognitionService extends Service {
* {@link SpeechRecognizer#RESULTS_RECOGNITION} as a parameter
*/
public void results(Bundle results) throws RemoteException {
mCurrentCallback = null;
Message.obtain(mHandler, MSG_RESET).sendToTarget();
mListener.onResults(results);
}