View Folders and files
Add test Add test
This commit is contained in:
parent
6a0e038cb5
commit
5fa396d616
35 changed files with 1817 additions and 15 deletions
|
|
@ -28,6 +28,7 @@ import dagger.assisted.Assisted
|
|||
import dagger.assisted.AssistedInject
|
||||
import io.element.android.anvilannotations.ContributesNode
|
||||
import io.element.android.features.rageshake.api.bugreport.BugReportEntryPoint
|
||||
import io.element.android.features.rageshake.api.reporter.BugReporter
|
||||
import io.element.android.libraries.androidutils.system.toast
|
||||
import io.element.android.libraries.di.AppScope
|
||||
import io.element.android.libraries.ui.strings.CommonStrings
|
||||
|
|
@ -37,7 +38,12 @@ class BugReportNode @AssistedInject constructor(
|
|||
@Assisted buildContext: BuildContext,
|
||||
@Assisted plugins: List<Plugin>,
|
||||
private val presenter: BugReportPresenter,
|
||||
private val bugReporter: BugReporter,
|
||||
) : Node(buildContext, plugins = plugins) {
|
||||
private fun onViewLogs(basePath: String) {
|
||||
plugins<BugReportEntryPoint.Callback>().forEach { it.onViewLogs(basePath) }
|
||||
}
|
||||
|
||||
@Composable
|
||||
override fun View(modifier: Modifier) {
|
||||
val state = presenter.present()
|
||||
|
|
@ -50,6 +56,11 @@ class BugReportNode @AssistedInject constructor(
|
|||
activity?.toast(CommonStrings.common_report_submitted)
|
||||
onDone()
|
||||
},
|
||||
onViewLogs = {
|
||||
// Force a logcat dump
|
||||
bugReporter.saveLogCat()
|
||||
onViewLogs(bugReporter.logDirectory().absolutePath)
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -43,6 +43,7 @@ import io.element.android.libraries.designsystem.components.form.textFieldState
|
|||
import io.element.android.libraries.designsystem.components.preferences.PreferencePage
|
||||
import io.element.android.libraries.designsystem.components.preferences.PreferenceRow
|
||||
import io.element.android.libraries.designsystem.components.preferences.PreferenceSwitch
|
||||
import io.element.android.libraries.designsystem.components.preferences.PreferenceText
|
||||
import io.element.android.libraries.designsystem.preview.ElementPreview
|
||||
import io.element.android.libraries.designsystem.preview.PreviewsDayNight
|
||||
import io.element.android.libraries.designsystem.preview.debugPlaceholderBackground
|
||||
|
|
@ -55,6 +56,7 @@ import io.element.android.libraries.ui.strings.CommonStrings
|
|||
@Composable
|
||||
fun BugReportView(
|
||||
state: BugReportState,
|
||||
onViewLogs: () -> Unit,
|
||||
onDone: () -> Unit,
|
||||
onBackPressed: () -> Unit,
|
||||
modifier: Modifier = Modifier,
|
||||
|
|
@ -97,6 +99,11 @@ fun BugReportView(
|
|||
)
|
||||
}
|
||||
Spacer(modifier = Modifier.height(16.dp))
|
||||
PreferenceText(
|
||||
title = stringResource(id = R.string.screen_bug_report_view_logs),
|
||||
enabled = isFormEnabled,
|
||||
onClick = onViewLogs,
|
||||
)
|
||||
PreferenceSwitch(
|
||||
isChecked = state.formState.sendLogs,
|
||||
onCheckedChange = { eventSink(BugReportEvents.SetSendLog(it)) },
|
||||
|
|
@ -169,5 +176,6 @@ internal fun BugReportViewPreview(@PreviewParameter(BugReportStateProvider::clas
|
|||
state = state,
|
||||
onDone = {},
|
||||
onBackPressed = {},
|
||||
onViewLogs = {},
|
||||
)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -94,6 +94,8 @@ class DefaultBugReporter @Inject constructor(
|
|||
private val logcatCommandDebug = arrayOf("logcat", "-d", "-v", "threadtime", "*:*")
|
||||
private var currentTracingFilter: String? = null
|
||||
|
||||
private val logCatErrFile = File(logDirectory().absolutePath, LOG_CAT_FILENAME)
|
||||
|
||||
override suspend fun sendBugReport(
|
||||
withDevicesLogs: Boolean,
|
||||
withCrashLogs: Boolean,
|
||||
|
|
@ -130,8 +132,8 @@ class DefaultBugReporter @Inject constructor(
|
|||
}
|
||||
|
||||
if (!isCancelled && (withCrashLogs || withDevicesLogs)) {
|
||||
val gzippedLogcat = saveLogCat()
|
||||
|
||||
saveLogCat()
|
||||
val gzippedLogcat = compressFile(logCatErrFile)
|
||||
if (null != gzippedLogcat) {
|
||||
if (gzippedFiles.size == 0) {
|
||||
gzippedFiles.add(gzippedLogcat)
|
||||
|
|
@ -321,7 +323,9 @@ class DefaultBugReporter @Inject constructor(
|
|||
}
|
||||
|
||||
override fun logDirectory(): File {
|
||||
return File(context.cacheDir, LOG_DIRECTORY_NAME)
|
||||
return File(context.cacheDir, LOG_DIRECTORY_NAME).apply {
|
||||
mkdirs()
|
||||
}
|
||||
}
|
||||
|
||||
override fun cleanLogDirectoryIfNeeded() {
|
||||
|
|
@ -381,30 +385,19 @@ class DefaultBugReporter @Inject constructor(
|
|||
*
|
||||
* @return the file if the operation succeeds
|
||||
*/
|
||||
private fun saveLogCat(): File? {
|
||||
val logCatErrFile = File(context.cacheDir.absolutePath, LOG_CAT_FILENAME)
|
||||
|
||||
override fun saveLogCat() {
|
||||
if (logCatErrFile.exists()) {
|
||||
logCatErrFile.safeDelete()
|
||||
}
|
||||
|
||||
try {
|
||||
logCatErrFile.writer().use {
|
||||
getLogCatError(it)
|
||||
}
|
||||
|
||||
return compressFile(logCatErrFile)
|
||||
} catch (error: OutOfMemoryError) {
|
||||
Timber.e(error, "## saveLogCat() : fail to write logcat OOM")
|
||||
} catch (e: Exception) {
|
||||
Timber.e(e, "## saveLogCat() : fail to write logcat")
|
||||
} finally {
|
||||
if (logCatErrFile.exists()) {
|
||||
logCatErrFile.safeDelete()
|
||||
}
|
||||
}
|
||||
|
||||
return null
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -11,5 +11,6 @@
|
|||
<string name="screen_bug_report_include_logs">"Allow logs"</string>
|
||||
<string name="screen_bug_report_include_screenshot">"Send screenshot"</string>
|
||||
<string name="screen_bug_report_logs_description">"Logs will be included with your message to make sure that everything is working properly. To send your message without logs, turn off this setting."</string>
|
||||
<string name="screen_bug_report_view_logs">"View logs"</string>
|
||||
<string name="screen_bug_report_rash_logs_alert_title">"%1$s crashed the last time it was used. Would you like to share a crash report with us?"</string>
|
||||
</resources>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue