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

Commit 0430aab3 authored by Przemyslaw Szczepaniak's avatar Przemyslaw Szczepaniak Committed by Android Git Automerger
Browse files

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

* commit '091d56ca':
  Fix double call to TTS connection disconnect() on reconnect
parents 30e7d762 091d56ca
Loading
Loading
Loading
Loading
+20 −9
Original line number Diff line number Diff line
@@ -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,17 +1319,25 @@ 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) {
                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) {
@@ -1338,6 +1348,7 @@ public class TextToSpeech {
                }
            }
        }
    }

    private interface Action<R> {
        R run(ITextToSpeechService service) throws RemoteException;