Skip to content

Commit

Permalink
RecorderThread: Add incoming/outgoing tag to filenames
Browse files Browse the repository at this point in the history
This only works on Android 10+.

Issue: #3
Signed-off-by: Andrew Gunnerson <chillermillerlong@hotmail.com>
  • Loading branch information
chenxiaolong committed May 22, 2022
1 parent 100b1f0 commit 1090613
Showing 1 changed file with 26 additions and 6 deletions.
32 changes: 26 additions & 6 deletions app/src/main/java/com/chiller3/bcr/RecorderThread.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import android.net.Uri
import android.os.Build
import android.os.ParcelFileDescriptor
import android.telecom.Call
import android.telecom.PhoneAccount
import android.util.Log
import androidx.documentfile.provider.DocumentFile
import java.io.FileOutputStream
Expand Down Expand Up @@ -40,11 +41,35 @@ class RecorderThread(
@Volatile private var isCancelled = false
private var captureFailed = false
private val handleUri: Uri = call.details.handle
private val direction: String? = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
when (call.details.callDirection) {
Call.Details.DIRECTION_INCOMING -> "in"
Call.Details.DIRECTION_OUTGOING -> "out"
else -> null
}
} else {
null
}

init {
Log.i(TAG, "[${id}] Created thread for call: $call")
}

private fun getFilename(): String =
buildString {
append(FORMATTER.format(ZonedDateTime.now()))

if (direction != null) {
append('_')
append(direction)
}

if (handleUri.scheme == PhoneAccount.SCHEME_TEL) {
append('_')
append(handleUri.schemeSpecificPart)
}
}

override fun run() {
var success = false
var resultUri: Uri? = null
Expand All @@ -55,12 +80,7 @@ class RecorderThread(
if (isCancelled) {
Log.i(TAG, "[${id}] Recording cancelled before it began")
} else {
var filename = FORMATTER.format(ZonedDateTime.now())
if (handleUri.scheme == "tel") {
filename += "_${handleUri.schemeSpecificPart}"
}

val (uri, pfd) = openOutputFile(filename)
val (uri, pfd) = openOutputFile(getFilename())
resultUri = uri

pfd.use {
Expand Down

0 comments on commit 1090613

Please sign in to comment.