Add internal preference to disable ANR induced crashing.

This commit is contained in:
Cody Henthorne
2026-05-06 13:08:37 -04:00
committed by Greyson Parrelli
parent 2fdb712b38
commit 56803a8850
3 changed files with 13 additions and 1 deletions
@@ -321,7 +321,7 @@ public class ApplicationContext extends Application implements AppForegroundObse
* This is so we can capture ANR's that happen on boot before the foreground event.
*/
private void startAnrDetector() {
AnrDetector.start(TimeUnit.SECONDS.toMillis(5), RemoteConfig::internalUser, (dumps) -> {
AnrDetector.start(TimeUnit.SECONDS.toMillis(5), () -> RemoteConfig.internalUser() && SignalStore.internal().getAnrDetectionCrashes(), (dumps) -> {
LogDatabase.getInstance(this).anrs().save(System.currentTimeMillis(), dumps);
return Unit.INSTANCE;
});
@@ -370,6 +370,14 @@ class InternalSettingsFragment : DSLSettingsFragment(R.string.preferences__inter
}
)
switchPref(
title = DSLSettingsText.from("Enable ANR-induced crashing"),
isChecked = SignalStore.internal.anrDetectionCrashes,
onClick = {
SignalStore.internal.anrDetectionCrashes = !SignalStore.internal.anrDetectionCrashes
}
)
dividerPref()
sectionHeaderPref(DSLSettingsText.from("Logging"))
@@ -36,6 +36,7 @@ class InternalValues internal constructor(store: KeyValueStore) : SignalStoreVal
const val INCLUDE_DEBUGLOG_IN_BACKUP: String = "internal.include_debuglog_in_backup"
const val IMPORTED_BACKUP_DEBUG_INFO: String = "internal.imported_backup_debug_info"
const val USE_NEW_MEDIA_ACTIVITY: String = "internal.use_new_media_activity"
const val ANR_DETECTION_CRASH: String = "internal.anr_detection_crash"
}
public override fun onFirstEverAppLaunch() = Unit
@@ -184,6 +185,9 @@ class InternalValues internal constructor(store: KeyValueStore) : SignalStoreVal
/** Any [BackupDebugInfo] that was imported during the last backup restore, if any. */
var importedBackupDebugInfo: BackupDebugInfo? by protoValue(IMPORTED_BACKUP_DEBUG_INFO, BackupDebugInfo.ADAPTER).defaultForExternalUsers()
/** Enable ANR detector forcing a crash. */
var anrDetectionCrashes by booleanValue(ANR_DETECTION_CRASH, true).falseForExternalUsers()
private fun <T> SignalStoreValueDelegate<T>.defaultForExternalUsers(): SignalStoreValueDelegate<T> {
return this.withPrecondition { RemoteConfig.internalUser }
}