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

Unverified Commit d958a11c authored by Michael W's avatar Michael W Committed by Michael Bestas
Browse files

Recorder: Prevent crash when starting and stopping too fast

Change-Id: I82b73cbc5ba5fe04e109e5a0c4f1fc43061bd769
parent 6c218367
Loading
Loading
Loading
Loading
+8 −2
Original line number Diff line number Diff line
@@ -50,8 +50,14 @@ public class GoodQualityRecorder implements SoundRecording {
            mRecorder.resume();
        }

        // needed to prevent app crash when starting and stopping too fast
        try {
            mRecorder.stop();
        } catch (RuntimeException rte) {
            return false;
        } finally {
            mRecorder.release();
        }
        return true;
    }

+9 −4
Original line number Diff line number Diff line
@@ -76,10 +76,15 @@ public class HighQualityRecorder implements SoundRecording {
            Log.e(TAG, "Interrupted thread", e);
        }

        // needed to prevent app crash when starting and stopping too fast
        try {
            mRecord.stop();
        mRecord.release();

            PcmConverter.convertToWave(mFile, BUFFER_SIZE);
        } catch (RuntimeException rte) {
            return false;
        } finally {
            mRecord.release();
        }
        return true;
    }

+7 −0
Original line number Diff line number Diff line
@@ -180,6 +180,7 @@ public class SoundRecorderService extends Service {

        boolean success = mRecorder.stopRecording();
        if (!success || mRecordFile == null) {
            onRecordFailed();
            return START_NOT_STICKY;
        }

@@ -263,6 +264,12 @@ public class SoundRecorderService extends Service {
        Utils.setStatus(this, Utils.UiStatus.NOTHING);
    }

    private void onRecordFailed() {
        mNotificationManager.cancel(NOTIFICATION_ID);
        stopForeground(true);
        Utils.setStatus(this, Utils.UiStatus.NOTHING);
    }

    private void createNotificationChannel() {
        CharSequence name = getString(R.string.sound_channel_title);
        String description = getString(R.string.sound_channel_desc);