Add toggle for runBlocking crash

pull/1051/head
Alex Baker 4 years ago
parent 7e1a1b22d3
commit 0c3c10a66a

@ -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)
}

@ -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? ->

@ -13,5 +13,5 @@
<string name="debug_themes">debug_themes</string>
<string name="debug_tasker">debug_tasker</string>
<string name="debug_reset_ssl">Reset SSL certificates</string>
<string name="debug_main_queries">Allow queries on main thread</string>
<string name="debug_main_queries">Crash queries on main thread</string>
</resources>

@ -18,8 +18,8 @@
android:title="@string/debug_strict_mode_vm"/>
<SwitchPreferenceCompat
android:defaultValue="true"
android:key="@string/p_debug_main_queries"
android:defaultValue="false"
android:key="@string/p_crash_main_queries"
android:title="@string/debug_main_queries" />
<SwitchPreferenceCompat

@ -5,9 +5,13 @@ import kotlinx.coroutines.CoroutineScope
import kotlin.coroutines.CoroutineContext
import kotlin.coroutines.EmptyCoroutineContext
var CRASH_ON_MAIN_THREAD = false
@Throws(InterruptedException::class)
fun <T> runBlocking(context: CoroutineContext = EmptyCoroutineContext, block: suspend CoroutineScope.() -> T): T {
assertNotMainThread()
if (CRASH_ON_MAIN_THREAD) {
assertNotMainThread()
}
return kotlinx.coroutines.runBlocking(context, block)
}

@ -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()

@ -330,7 +330,7 @@
<string name="p_leakcanary">p_leakcanary</string>
<string name="p_flipper">p_flipper</string>
<string name="p_debug_pro">debug_pro</string>
<string name="p_debug_main_queries">debug_main_queries</string>
<string name="p_crash_main_queries">debug_crash_main_queries</string>
<string name="warned_play_services">warned_play_services</string>
<string name="p_background_sync_unmetered_only">background_sync_unmetered_only</string>
<string name="p_sync_ongoing">sync_ongoing</string>

Loading…
Cancel
Save