Bug 1975494 - Add debug drawer functionality to simulate crashes to produce the different crash report dialogs. r=android-reviewers,android-l10n-reviewers,matt-tighe,delphine

Differential Revision: https://phabricator.services.mozilla.com/D257738
This commit is contained in:
fmasalha authored and [email protected] committed 2025-07-28 20:21:34 +00:00
1 parent 7b7b46fc39
commit 12687540cc
5 files changed
+125

No files matched your search

@@ -0,0 +1,92 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
package org.mozilla.fenix.debugsettings.crashtools
import android.text.format.DateUtils
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.rememberScrollState
import androidx.compose.foundation.verticalScroll
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableLongStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.unit.dp
import kotlinx.coroutines.delay
import mozilla.components.compose.base.annotation.FlexibleWindowLightDarkPreview
import mozilla.components.compose.base.button.PrimaryButton
import org.mozilla.fenix.R
import org.mozilla.fenix.components.components
import org.mozilla.fenix.theme.FirefoxTheme
import org.mozilla.fenix.utils.Settings
private const val SECOND_IN_MILLISECOND = 1000L
@Composable
internal fun CrashTools(
settings: Settings = components.settings,
) {
var now = System.currentTimeMillis()
var genericDeferPeriod by remember { mutableLongStateOf(settings.crashReportDeferredUntil - now) }
LaunchedEffect(Unit) {
while (true) {
now = System.currentTimeMillis()
genericDeferPeriod = settings.crashReportDeferredUntil - now
delay(SECOND_IN_MILLISECOND)
}
}
Column(
modifier = Modifier
.padding(all = 16.dp)
.verticalScroll(state = rememberScrollState()),
) {
Text(
text = stringResource(
R.string.crash_debug_deferral_timer,
convertMillisToDHMS(maxOf(genericDeferPeriod, 0)),
),
style = FirefoxTheme.typography.body2,
)
PrimaryButton(
text = stringResource(R.string.crash_debug_deferral_button),
modifier = Modifier.fillMaxWidth(),
onClick = {
settings.crashReportDeferredUntil = 0L
genericDeferPeriod = 0L
},
)
Text(
text = stringResource(R.string.crash_debug_crash_app_warning),
color = FirefoxTheme.colors.actionCritical,
style = FirefoxTheme.typography.subtitle2,
)
PrimaryButton(
text = stringResource(R.string.crash_debug_generic_crash_trigger),
modifier = Modifier.fillMaxWidth(),
onClick = {
throw ArithmeticException("Cannot divide by zero.")
},
)
}
}
internal fun convertMillisToDHMS(milliseconds: Long): String {
return DateUtils.formatElapsedTime(milliseconds / SECOND_IN_MILLISECOND)
}
@FlexibleWindowLightDarkPreview
@Composable
private fun CrashToolsPreview() {
FirefoxTheme {
CrashTools(Settings(LocalContext.current))
}
}
@@ -16,6 +16,7 @@ import org.mozilla.fenix.debugsettings.addresses.AddressesDebugLocalesRepository
import org.mozilla.fenix.debugsettings.addresses.AddressesTools
import org.mozilla.fenix.debugsettings.cfrs.CfrToolsState
import org.mozilla.fenix.debugsettings.cfrs.CfrToolsStore
import org.mozilla.fenix.debugsettings.crashtools.CrashTools
import org.mozilla.fenix.debugsettings.gleandebugtools.GleanDebugToolsStore
import org.mozilla.fenix.debugsettings.gleandebugtools.ui.GleanDebugToolsScreen
import org.mozilla.fenix.debugsettings.logins.LoginsTools
@@ -64,6 +65,10 @@ enum class DebugDrawerRoute(val route: String, @param:StringRes val title: Int)
route = "addons_debug_tools",
title = R.string.debug_drawer_addons_tools_title,
),
CrashDebugTools(
route = "crash_debug_tools",
title = R.string.crash_debug_tools_title,
),
;
companion object {
@@ -167,6 +172,15 @@ enum class DebugDrawerRoute(val route: String, @param:StringRes val title: Int)
AddonsDebugToolsScreen()
}
}
CrashDebugTools -> {
onClick = {
debugDrawerStore.dispatch(DebugDrawerAction.NavigateTo.CrashDebugTools)
}
content = {
CrashTools()
}
}
}
DebugDrawerDestination(
@@ -72,6 +72,11 @@ sealed class DebugDrawerAction : Action {
* [NavigateTo] action fired when the debug drawer needs to navigate to [AddonsDebugToolsScreen].
*/
object AddonsDebugTools : NavigateTo()
/**
* [NavigateTo] action fired when the debug drawer needs to navigate to [CrashTools].
*/
object CrashDebugTools : NavigateTo()
}
/**
@@ -49,6 +49,8 @@ class DebugDrawerNavigationMiddleware(
navController.navigate(route = DebugDrawerRoute.RegionDebugTools.route)
is DebugDrawerAction.NavigateTo.AddonsDebugTools ->
navController.navigate(route = DebugDrawerRoute.AddonsDebugTools.route)
is DebugDrawerAction.NavigateTo.CrashDebugTools ->
navController.navigate(route = DebugDrawerRoute.CrashDebugTools.route)
is DebugDrawerAction.OnBackPressed -> navController.popBackStack()
is DebugDrawerAction.DrawerOpened, DebugDrawerAction.DrawerClosed -> Unit // no-op
}
@@ -213,4 +213,16 @@
<string name="glean_debug_tools_send_ping_button_text">Send Ping</string>
<!-- The send pings toast message. The first parameter is the type of ping -->
<string name="glean_debug_tools_send_ping_toast_message">Sent %1$s ping</string>
<!-- The title of the debug drawer tab to help debug the crash reporter-->
<string name="crash_debug_tools_title">Crash Debug Tools</string>
<!-- Button text to trigger a app parent process crash -->
<string name="crash_debug_generic_crash_trigger">Trigger Crash Report</string>
<!-- Button text to reset crash deferral period (the deferral period is set after clicking close on the dialog to 5 days in the settings) from it's future value to 0 -->
<string name="crash_debug_deferral_button">Reset deferral settings</string>
<!-- Subtitle warning text for crash button -->
<string name="crash_debug_crash_app_warning">This will crash the app to start crash reporting flow. Please also ensure that the crash report option is set to "Ask before sending" in the data collections settings if you want the dialog to pop up.</string>
<!-- Timer text for deferral period %s is the timer string -->
<string name="crash_debug_deferral_timer">Current deferral period: %s</string>
</resources>