From 0c3c10a66a41e2957953af7f5112286258869287 Mon Sep 17 00:00:00 2001 From: Alex Baker Date: Thu, 9 Jul 2020 10:22:50 -0500 Subject: [PATCH] Add toggle for runBlocking crash --- app/src/debug/java/org/tasks/BuildSetup.kt | 2 ++ app/src/debug/java/org/tasks/preferences/fragments/Debug.kt | 2 +- app/src/debug/res/values/keys.xml | 2 +- app/src/debug/res/xml/preferences_debug.xml | 4 ++-- app/src/main/java/org/tasks/data/RunBlocking.kt | 6 +++++- app/src/main/java/org/tasks/injection/ProductionModule.kt | 2 +- app/src/main/res/values/keys.xml | 2 +- 7 files changed, 13 insertions(+), 7 deletions(-) diff --git a/app/src/debug/java/org/tasks/BuildSetup.kt b/app/src/debug/java/org/tasks/BuildSetup.kt index 6165bdafb..b4c7bd3e3 100644 --- a/app/src/debug/java/org/tasks/BuildSetup.kt +++ b/app/src/debug/java/org/tasks/BuildSetup.kt @@ -12,6 +12,7 @@ import com.facebook.flipper.plugins.network.NetworkFlipperPlugin import com.facebook.flipper.plugins.sharedpreferences.SharedPreferencesFlipperPlugin import com.facebook.soloader.SoLoader import leakcanary.AppWatcher +import org.tasks.data.CRASH_ON_MAIN_THREAD import org.tasks.preferences.Preferences import timber.log.Timber import timber.log.Timber.DebugTree @@ -24,6 +25,7 @@ class BuildSetup @Inject constructor( fun setup() { Timber.plant(DebugTree()) SoLoader.init(context, false) + CRASH_ON_MAIN_THREAD = preferences.getBoolean(R.string.p_crash_main_queries, false) if (preferences.getBoolean(R.string.p_leakcanary, false)) { AppWatcher.manualInstall(context) } diff --git a/app/src/debug/java/org/tasks/preferences/fragments/Debug.kt b/app/src/debug/java/org/tasks/preferences/fragments/Debug.kt index 9f1fd140c..34622ec91 100644 --- a/app/src/debug/java/org/tasks/preferences/fragments/Debug.kt +++ b/app/src/debug/java/org/tasks/preferences/fragments/Debug.kt @@ -27,7 +27,7 @@ class Debug : InjectingPreferenceFragment() { R.string.p_flipper, R.string.p_strict_mode_vm, R.string.p_strict_mode_thread, - R.string.p_debug_main_queries + R.string.p_crash_main_queries )) { findPreference(pref) .setOnPreferenceChangeListener { _: Preference?, _: Any? -> diff --git a/app/src/debug/res/values/keys.xml b/app/src/debug/res/values/keys.xml index e45e9f6ca..dc0caf556 100644 --- a/app/src/debug/res/values/keys.xml +++ b/app/src/debug/res/values/keys.xml @@ -13,5 +13,5 @@ debug_themes debug_tasker Reset SSL certificates - Allow queries on main thread + Crash queries on main thread \ No newline at end of file diff --git a/app/src/debug/res/xml/preferences_debug.xml b/app/src/debug/res/xml/preferences_debug.xml index fd997c92f..648ced1ac 100644 --- a/app/src/debug/res/xml/preferences_debug.xml +++ b/app/src/debug/res/xml/preferences_debug.xml @@ -18,8 +18,8 @@ android:title="@string/debug_strict_mode_vm"/> runBlocking(context: CoroutineContext = EmptyCoroutineContext, block: suspend CoroutineScope.() -> T): T { - assertNotMainThread() + if (CRASH_ON_MAIN_THREAD) { + assertNotMainThread() + } return kotlinx.coroutines.runBlocking(context, block) } diff --git a/app/src/main/java/org/tasks/injection/ProductionModule.kt b/app/src/main/java/org/tasks/injection/ProductionModule.kt index abc088131..08b9c72f7 100644 --- a/app/src/main/java/org/tasks/injection/ProductionModule.kt +++ b/app/src/main/java/org/tasks/injection/ProductionModule.kt @@ -26,7 +26,7 @@ internal class ProductionModule { fun getAppDatabase(@ApplicationContext context: Context, preferences: Preferences): Database { val builder = Room.databaseBuilder(context, Database::class.java, Database.NAME) .addMigrations(*Migrations.MIGRATIONS) - if (!BuildConfig.DEBUG || preferences.getBoolean(R.string.p_debug_main_queries, true)) { + if (!BuildConfig.DEBUG || !preferences.getBoolean(R.string.p_crash_main_queries, false)) { builder.allowMainThreadQueries() } return builder.build() diff --git a/app/src/main/res/values/keys.xml b/app/src/main/res/values/keys.xml index 239a945d6..445a0154e 100644 --- a/app/src/main/res/values/keys.xml +++ b/app/src/main/res/values/keys.xml @@ -330,7 +330,7 @@ p_leakcanary p_flipper debug_pro - debug_main_queries + debug_crash_main_queries warned_play_services background_sync_unmetered_only sync_ongoing