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

Commit 26d17d6e authored by Niels Egberts's avatar Niels Egberts Committed by Android (Google) Code Review
Browse files

Merge "Small refactoring for FileSynthesisCallback."

parents 00851b1d 453c13f7
Loading
Loading
Loading
Loading
+7 −15
Original line number Diff line number Diff line
@@ -15,6 +15,7 @@
 */
package android.speech.tts;

import android.annotation.NonNull;
import android.media.AudioFormat;
import android.speech.tts.TextToSpeechService.UtteranceProgressDispatcher;
import android.util.Log;
@@ -46,7 +47,6 @@ class FileSynthesisCallback extends AbstractSynthesisCallback {
    private FileChannel mFileChannel;

    private final UtteranceProgressDispatcher mDispatcher;
    private final Object mCallerIdentity;

    private boolean mStarted = false;
    private boolean mDone = false;
@@ -54,12 +54,11 @@ class FileSynthesisCallback extends AbstractSynthesisCallback {
    /** Status code of synthesis */
    protected int mStatusCode;

    FileSynthesisCallback(FileChannel fileChannel, UtteranceProgressDispatcher dispatcher,
            Object callerIdentity, boolean clientIsUsingV2) {
    FileSynthesisCallback(@NonNull FileChannel fileChannel,
            @NonNull UtteranceProgressDispatcher dispatcher, boolean clientIsUsingV2) {
        super(clientIsUsingV2);
        mFileChannel = fileChannel;
        mDispatcher = dispatcher;
        mCallerIdentity = callerIdentity;
        mStatusCode = TextToSpeech.SUCCESS;
    }

@@ -75,11 +74,9 @@ class FileSynthesisCallback extends AbstractSynthesisCallback {

            mStatusCode = TextToSpeech.STOPPED;
            cleanUp();
            if (mDispatcher != null) {
            mDispatcher.dispatchOnStop();
        }
    }
    }

    /**
     * Must be called while holding the monitor on {@link #mStateLock}.
@@ -134,9 +131,7 @@ class FileSynthesisCallback extends AbstractSynthesisCallback {
            mAudioFormat = audioFormat;
            mChannelCount = channelCount;

            if (mDispatcher != null) {
            mDispatcher.dispatchOnStart();
            }
            fileChannel = mFileChannel;
        }

@@ -214,8 +209,7 @@ class FileSynthesisCallback extends AbstractSynthesisCallback {
                if (DBG) Log.d(TAG, "Request has been aborted.");
                return errorCodeOnStop();
            }
            if (mDispatcher != null && mStatusCode != TextToSpeech.SUCCESS &&
                    mStatusCode != TextToSpeech.STOPPED) {
            if (mStatusCode != TextToSpeech.SUCCESS && mStatusCode != TextToSpeech.STOPPED) {
                mDispatcher.dispatchOnError(mStatusCode);
                return TextToSpeech.ERROR;
            }
@@ -239,9 +233,7 @@ class FileSynthesisCallback extends AbstractSynthesisCallback {

            synchronized (mStateLock) {
                closeFile();
                if (mDispatcher != null) {
                mDispatcher.dispatchOnSuccess();
                }
                return TextToSpeech.SUCCESS;
            }
        } catch (IOException ex) {
+1 −2
Original line number Diff line number Diff line
@@ -1032,8 +1032,7 @@ public abstract class TextToSpeechService extends Service {

        @Override
        protected AbstractSynthesisCallback createSynthesisCallback() {
            return new FileSynthesisCallback(mFileOutputStream.getChannel(),
                    this, getCallerIdentity(), false);
            return new FileSynthesisCallback(mFileOutputStream.getChannel(), this, false);
        }

        @Override