From da82c370efa3c42fc7612f9536c4984f086603c9 Mon Sep 17 00:00:00 2001 From: Andrew Gunnerson Date: Tue, 27 Dec 2022 20:36:03 -0500 Subject: [PATCH] Add new option for starting the recording in the paused state This commit adds a new "initially paused" option to BCR's UI. If it's disabled, then BCR works as it always has: calls are recorded as soon as they enter the connected state. If the option is enabled, then the recording starts in the paused state. The user can choose to resume via BCR's persistent notification. If the recording is never resumed, then the empty output file is deleted and no success notification will be shown. This new option is disabled by default. Issue: #198 Signed-off-by: Andrew Gunnerson --- .../main/java/com/chiller3/bcr/Preferences.kt | 8 +++++ .../com/chiller3/bcr/RecorderInCallService.kt | 10 ++++-- .../java/com/chiller3/bcr/RecorderThread.kt | 32 +++++++++++++------ app/src/main/res/values/strings.xml | 4 +++ app/src/main/res/xml/root_preferences.xml | 7 ++++ 5 files changed, 49 insertions(+), 12 deletions(-) diff --git a/app/src/main/java/com/chiller3/bcr/Preferences.kt b/app/src/main/java/com/chiller3/bcr/Preferences.kt index 289397e1a..01268978a 100644 --- a/app/src/main/java/com/chiller3/bcr/Preferences.kt +++ b/app/src/main/java/com/chiller3/bcr/Preferences.kt @@ -12,6 +12,7 @@ import java.io.File class Preferences(private val context: Context) { companion object { const val PREF_CALL_RECORDING = "call_recording" + const val PREF_INITIALLY_PAUSED = "initially_paused" const val PREF_OUTPUT_DIR = "output_dir" const val PREF_OUTPUT_FORMAT = "output_format" const val PREF_INHIBIT_BATT_OPT = "inhibit_batt_opt" @@ -147,6 +148,13 @@ class Preferences(private val context: Context) { get() = prefs.getBoolean(PREF_CALL_RECORDING, false) set(enabled) = prefs.edit { putBoolean(PREF_CALL_RECORDING, enabled) } + /** + * Whether the recording should initially start in the paused state. + */ + var initiallyPaused: Boolean + get() = prefs.getBoolean(PREF_INITIALLY_PAUSED, false) + set(enabled) = prefs.edit { putBoolean(PREF_INITIALLY_PAUSED, enabled) } + /** * The saved output format. * diff --git a/app/src/main/java/com/chiller3/bcr/RecorderInCallService.kt b/app/src/main/java/com/chiller3/bcr/RecorderInCallService.kt index a15899cfa..693cd3d8b 100644 --- a/app/src/main/java/com/chiller3/bcr/RecorderInCallService.kt +++ b/app/src/main/java/com/chiller3/bcr/RecorderInCallService.kt @@ -295,12 +295,16 @@ class RecorderInCallService : InCallService(), RecorderThread.OnRecordingComplet updateForegroundState() } - override fun onRecordingCompleted(thread: RecorderThread, file: OutputFile) { - Log.i(TAG, "Recording completed: ${thread.id}: ${file.redacted}") + override fun onRecordingCompleted(thread: RecorderThread, file: OutputFile?) { + Log.i(TAG, "Recording completed: ${thread.id}: ${file?.redacted}") handler.post { onThreadExited() - notifySuccess(file) + // If the recording was initially paused and the user never resumed it, there's no + // output file, so nothing needs to be shown. + if (file != null) { + notifySuccess(file) + } } } diff --git a/app/src/main/java/com/chiller3/bcr/RecorderThread.kt b/app/src/main/java/com/chiller3/bcr/RecorderThread.kt index 7a1b8cd8d..e1b2544e8 100644 --- a/app/src/main/java/com/chiller3/bcr/RecorderThread.kt +++ b/app/src/main/java/com/chiller3/bcr/RecorderThread.kt @@ -62,11 +62,16 @@ class RecorderThread( private var captureFailed = false // Pause state - @Volatile var isPaused = false - set(result) { - Log.d(tag, "Pause state updated: $isPaused") - field = result + @Volatile var isPaused = prefs.initiallyPaused + set(value) { + field = value + if (!value) { + wasEverResumed = true + } + + Log.d(tag, "Pause state updated: $value") } + private var wasEverResumed = !isPaused // Timestamp private lateinit var callTimestamp: ZonedDateTime @@ -90,6 +95,7 @@ class RecorderThread( init { Log.i(tag, "Created thread for call: $call") + Log.i(tag, "Initially paused: $isPaused") onCallDetailsChanged(call.details) @@ -258,8 +264,14 @@ class RecorderThread( } } - tryMoveToUserDir(outputFile)?.let { - resultUri = it.uri + if (wasEverResumed) { + tryMoveToUserDir(outputFile)?.let { + resultUri = it.uri + } + } else { + Log.i(tag, "Deleting because recording was never resumed: ${redact(finalFilename)}") + outputFile.delete() + resultUri = null } processRetention() @@ -292,7 +304,7 @@ class RecorderThread( val outputFile = resultUri?.let { OutputFile(it, redact(it), format.mimeTypeContainer) } if (success) { - listener.onRecordingCompleted(this, outputFile!!) + listener.onRecordingCompleted(this, outputFile) } else { listener.onRecordingFailed(this, errorMsg, outputFile) } @@ -711,9 +723,11 @@ class RecorderThread( interface OnRecordingCompletedListener { /** - * Called when the recording completes successfully. [file] is the output file. + * Called when the recording completes successfully. [file] is the output file. If [file] is + * null, then the recording was started in the paused state and the output file was deleted + * because the user never resumed it. */ - fun onRecordingCompleted(thread: RecorderThread, file: OutputFile) + fun onRecordingCompleted(thread: RecorderThread, file: OutputFile?) /** * Called when an error occurs during recording. If [file] is not null, it points to the diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 4c73d7ea7..0a806f07c 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -10,6 +10,10 @@ Call recording Record incoming and outgoing phone calls. Microphone and notification permissions are required for recording in the background. + Initially paused + Start recording in the paused state. If the recording is never resumed, then the empty output file won\'t be saved. + Start recording immediately when a call connects. To pause or resume, tap on the button in the notification during a call. + Output directory Pick a directory to store recordings. diff --git a/app/src/main/res/xml/root_preferences.xml b/app/src/main/res/xml/root_preferences.xml index d961ac5c6..d1463f9ba 100644 --- a/app/src/main/res/xml/root_preferences.xml +++ b/app/src/main/res/xml/root_preferences.xml @@ -9,6 +9,13 @@ app:summary="@string/pref_call_recording_desc" app:iconSpaceReserved="false" /> + +