am 091d56ca: Fix double call to TTS connection disconnect() on reconnect

* commit '091d56cab8f6f6a3460fbb596f99b1a262948e96':
  Fix double call to TTS connection disconnect() on reconnect
This commit is contained in:
Przemyslaw Szczepaniak
2012-08-20 09:01:04 -07:00
committed by Android Git Automerger

View File

@@ -1282,6 +1282,7 @@ public class TextToSpeech {
}
};
@Override
public void onServiceConnected(ComponentName name, IBinder service) {
Log.i(TAG, "Connected to " + name);
synchronized(mStartLock) {
@@ -1305,6 +1306,7 @@ public class TextToSpeech {
return mCallback;
}
@Override
public void onServiceDisconnected(ComponentName name) {
synchronized(mStartLock) {
mService = null;
@@ -1317,24 +1319,33 @@ public class TextToSpeech {
public void disconnect() {
mContext.unbindService(this);
synchronized (mStartLock) {
mService = null;
// If this is the active connection, clear it
if (mServiceConnection == this) {
mServiceConnection = null;
}
}
}
public <R> R runAction(Action<R> action, R errorResult, String method, boolean reconnect) {
try {
synchronized (mStartLock) {
synchronized (mStartLock) {
try {
if (mService == null) {
Log.w(TAG, method + " failed: not connected to TTS engine");
return errorResult;
}
return action.run(mService);
} catch (RemoteException ex) {
Log.e(TAG, method + " failed", ex);
if (reconnect) {
disconnect();
initTts();
}
return errorResult;
}
} catch (RemoteException ex) {
Log.e(TAG, method + " failed", ex);
if (reconnect) {
disconnect();
initTts();
}
return errorResult;
}
}
}