From 558c4541cda322a7ec426ba3164e4569ce99c506 Mon Sep 17 00:00:00 2001 From: Jorge Martin Espinosa Date: Fri, 2 Oct 2026 10:05:08 +0200 Subject: [PATCH] Fix `StrictMode` config (#7837) Remove `penaltyDialog()` as it makes the app unusable even in debug builds --- .../element/android/x/ElementXApplication.kt | 26 +++++++++---------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/app/src/main/kotlin/io/element/android/x/ElementXApplication.kt b/app/src/main/kotlin/io/element/android/x/ElementXApplication.kt index 228fac342b..b39dc353fc 100644 --- a/app/src/main/kotlin/io/element/android/x/ElementXApplication.kt +++ b/app/src/main/kotlin/io/element/android/x/ElementXApplication.kt @@ -40,19 +40,7 @@ class ElementXApplication : Application(), DependencyInjectionGraphOwner, Config override fun onCreate() { super.onCreate() - // Workaround to avoid NetworkOnMainThreadException when using the network on the main thread. - // This is a temporary solution to rustls doing the certificate verification using blocking network requests. - // It should be removed once the underlying issue is fixed. - // Also, we only want to enable it on nightly and release builds so we can debug the issue on debug builds. - if (!BuildConfig.DEBUG) { - StrictMode.setThreadPolicy( - StrictMode.ThreadPolicy.Builder() - .detectNetwork() - .penaltyLog() - .penaltyDialog() - .build() - ) - } + enableStrictMode() AppInitializer.getInstance(this).apply { initializeComponent(CrashInitializer::class.java) @@ -67,4 +55,16 @@ class ElementXApplication : Application(), DependencyInjectionGraphOwner, Config // Remove once https://issuetracker.google.com/issues/477038695 is fixed. isAnchoredDraggableComponentsStrictOffsetCheckEnabled = false } + + private fun enableStrictMode() { + // Workaround to avoid NetworkOnMainThreadException when using the network on the main thread. + // This is a temporary solution to rustls doing the certificate verification using blocking network requests. + // It should be removed once the underlying issue is fixed. + StrictMode.setThreadPolicy( + StrictMode.ThreadPolicy.Builder() + .detectNetwork() + .penaltyLog() + .build() + ) + } }