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

Commit 0445f98e authored by Diogo Ferreira's avatar Diogo Ferreira Committed by Ricardo Cerqueira
Browse files

tracks: Check track states before transitioning states

Prevents sporadic crashes when the user plugs/unplugs the headset
rapidly. These were caused by performing track operations such as start,
stop and record before checking whether the tracks had been stopped
before.

Change-Id: I54b5ba102ffbed4c453ee5f15533467e5f4771fd
Ticket: CYNGNOS-2775
parent 6c505f08
Loading
Loading
Loading
Loading
+7 −4
Original line number Diff line number Diff line
@@ -396,7 +396,7 @@ public class FmService extends Service implements FmRecorder.OnRecorderStateChan
           mAudioRecord.release();
           mAudioRecord = null;
       }
       if (mAudioTrack != null) {
       if (mAudioTrack != null && mAudioTrack.getState() == AudioTrack.STATE_INITIALIZED) {
           mAudioTrack.stop();
           mAudioTrack.release();
           mAudioTrack = null;
@@ -448,7 +448,8 @@ public class FmService extends Service implements FmRecorder.OnRecorderStateChan
    }

    private void startAudioTrack() {
        if (mAudioTrack.getPlayState() == AudioTrack.PLAYSTATE_STOPPED) {
        if (mAudioTrack.getState() == AudioTrack.STATE_INITIALIZED
                && mAudioTrack.getPlayState() == AudioTrack.PLAYSTATE_STOPPED) {
            ArrayList<AudioPatch> patches = new ArrayList<AudioPatch>();
            mAudioManager.listAudioPatches(patches);
            mAudioTrack.play();
@@ -477,11 +478,13 @@ public class FmService extends Service implements FmRecorder.OnRecorderStateChan
                        // Speaker mode or BT a2dp mode will come here and keep reading and writing.
                        // If we want FM sound output from speaker or BT a2dp, we must record data
                        // to AudioRecrd and write data to AudioTrack.
                        if (mAudioRecord.getRecordingState() == AudioRecord.RECORDSTATE_STOPPED) {
                        if (mAudioRecord.getRecordingState() == AudioRecord.RECORDSTATE_STOPPED
                                && mAudioRecord.getState() == AudioRecord.STATE_INITIALIZED) {
                            mAudioRecord.startRecording();
                        }

                        if (mAudioTrack.getPlayState() == AudioTrack.PLAYSTATE_STOPPED) {
                        if (mAudioTrack.getPlayState() == AudioTrack.PLAYSTATE_STOPPED
                                && mAudioTrack.getState() == AudioTrack.STATE_INITIALIZED) {
                            mAudioTrack.play();
                        }
                        int size = mAudioRecord.read(buffer, 0, RECORD_BUF_SIZE);