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

Commit dd80507c authored by Stefan Andonian's avatar Stefan Andonian
Browse files

Upload Perfetto Trace and Screen Recording as Unique Files when

recording an issue.

This is part of the RecordIssueTile. These files are not all openable
within solely the winscope web ui. Particularly, the perfetto file is
not useful in winscope, but has it's own ui. The screen recording
likewise can individually be opened in buganizer without the need to
pull all traces into winscope.

Also fixed issue where crash would happen if traces.get was null
(which happens if share notification is clicked more than once).

Bug: 305049544
Test: Tested this locally on device.
Flag: ACONFIG record_issue_qs_tile STAGING
Change-Id: Ib45005c1755e6bccd26d34eee29b72685cda3b50
parent 771a4e9b
Loading
Loading
Loading
Loading
+21 −18
Original line number Diff line number Diff line
@@ -47,6 +47,7 @@ import java.util.concurrent.Executor
import java.util.zip.ZipEntry
import java.util.zip.ZipOutputStream
import javax.inject.Inject
import kotlin.jvm.optionals.getOrElse

class IssueRecordingService
@Inject
@@ -140,15 +141,25 @@ constructor(
    }

    private fun shareRecording(screenRecording: Uri?) {
        val sharableUri: Uri =
            zipAndPackageRecordings(
                TraceUtils.traceDump(contentResolver, TRACE_FILE_NAME).get(),
                screenRecording
        val traces =
            TraceUtils.traceDump(contentResolver, TRACE_FILE_NAME).getOrElse {
                Log.v(
                    TAG,
                    "Traces were not present. This can happen if users double" +
                        "click on share notification. Traces are cleaned up after sharing" +
                        "so they won't be present for the 2nd share attempt."
                )
                ?: return
                return
            }
        val perfetto = FileProvider.getUriForFile(this, AUTHORITY, traces.first())
        val urisToShare = mutableListOf(perfetto)
        traces.removeFirst()

        getZipWinscopeFileUri(traces)?.let { urisToShare.add(it) }
        screenRecording?.let { urisToShare.add(it) }

        val sendIntent =
            FileSender.buildSendIntent(this, listOf(sharableUri))
                .addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
            FileSender.buildSendIntent(this, urisToShare).addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)

        // TODO: Debug why the notification shade isn't closing upon starting the BetterBug activity
        mKeyguardDismissUtil.executeWhenUnlocked(
@@ -161,7 +172,7 @@ constructor(
        )
    }

    private fun zipAndPackageRecordings(traceFiles: List<File>, screenRecording: Uri?): Uri? {
    private fun getZipWinscopeFileUri(traceFiles: List<File>): Uri? {
        try {
            externalCacheDir?.mkdirs()
            val outZip: File = File.createTempFile(TEMP_FILE_PREFIX, ZIP_SUFFIX, externalCacheDir)
@@ -171,13 +182,6 @@ constructor(
                    Files.copy(file.toPath(), os)
                    os.closeEntry()
                }
                if (screenRecording != null) {
                    contentResolver.openInputStream(screenRecording)?.use {
                        os.putNextEntry(ZipEntry(SCREEN_RECORDING_ZIP_LABEL))
                        it.transferTo(os)
                        os.closeEntry()
                    }
                }
            }
            return FileProvider.getUriForFile(this, AUTHORITY, outZip)
        } catch (e: Exception) {
@@ -192,8 +196,7 @@ constructor(
        private const val EXTRA_SCREEN_RECORD = "extra_screenRecord"
        private const val EXTRA_WINSCOPE_TRACING = "extra_winscopeTracing"
        private const val ZIP_SUFFIX = ".zip"
        private const val TEMP_FILE_PREFIX = "issue_recording"
        private const val SCREEN_RECORDING_ZIP_LABEL = "screen-recording.mp4"
        private const val TEMP_FILE_PREFIX = "winscope_recordings"

        private val DEFAULT_TRACE_TAGS = listOf<String>()
        private const val DEFAULT_BUFFER_SIZE = 16384