From 5ed93adaecbd47337c7d030ed1644bccceea639c Mon Sep 17 00:00:00 2001 From: David Allison <62114487+david-allison@users.noreply.github.com> Date: Thu, 2 May 2024 20:12:26 +0100 Subject: [PATCH] fix(audio-recorder): crash if saving immediately ` if (isRecording || isRecordingPaused) {` returned true so `clearRecording` was called even though `stop()` has been called which crashed. ``` Done -> stopAndSaveRecording() then -> done() -> onViewFocusChanged() ``` We fix this by setting the state to CLEARED after stopAndSaveRecording Cause: cad603ef08a3a0d7ef4f54a8260e3cc7409c3d27 I missed that `stopAndSaveRecording` was public Fixes 16321 --- .../main/java/com/ichi2/audio/AudioRecordingController.kt | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/AnkiDroid/src/main/java/com/ichi2/audio/AudioRecordingController.kt b/AnkiDroid/src/main/java/com/ichi2/audio/AudioRecordingController.kt index cb63ebeaa330..97ded4566301 100644 --- a/AnkiDroid/src/main/java/com/ichi2/audio/AudioRecordingController.kt +++ b/AnkiDroid/src/main/java/com/ichi2/audio/AudioRecordingController.kt @@ -43,6 +43,7 @@ import com.ichi2.anki.showThemedToast import com.ichi2.anki.snackbar.showSnackbar import com.ichi2.anki.utils.elapsed import com.ichi2.anki.utils.formatAsString +import com.ichi2.annotations.NeedsTest import com.ichi2.audio.AudioRecordingController.RecordingState.AppendToRecording import com.ichi2.audio.AudioRecordingController.RecordingState.ImmediatePlayback import com.ichi2.compat.CompatHelper @@ -276,6 +277,8 @@ class AudioRecordingController : } } + /** Called on pause, and when 'done' is pressed */ + @NeedsTest("16321: record -> 'done' without pressing save") fun onViewFocusChanged() { Timber.i("activity paused: stopping recording/resetting player") if (isRecording || isRecordingPaused) { @@ -434,7 +437,6 @@ class AudioRecordingController : fun toggleSave(vibrate: Boolean = true) { Timber.i("recording completed") if (vibrate) CompatHelper.compat.vibrate(context, 20) - setUiState(state.afterSave()) stopAndSaveRecording() // show this snackbar only in the edit field/multimedia activity if (inEditField) (context as Activity).showSnackbar(context.resources.getString(R.string.audio_saved)) @@ -571,6 +573,7 @@ class AudioRecordingController : } isRecording = false isAudioRecordingSaved = true + setUiState(state.afterSave()) // save recording only in the edit field not in the reviewer but save it temporarily if (inEditField) saveRecording() }