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.flipper.plugins.sharedpreferences.SharedPreferencesFlipperPlugin
import com.facebook.soloader.SoLoader import com.facebook.soloader.SoLoader
import leakcanary.AppWatcher import leakcanary.AppWatcher
import org.tasks.data.CRASH_ON_MAIN_THREAD
import org.tasks.preferences.Preferences import org.tasks.preferences.Preferences
import timber.log.Timber import timber.log.Timber
import timber.log.Timber.DebugTree import timber.log.Timber.DebugTree
@ -24,6 +25,7 @@ class BuildSetup @Inject constructor(
fun setup() { fun setup() {
Timber.plant(DebugTree()) Timber.plant(DebugTree())
SoLoader.init(context, false) 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)) { if (preferences.getBoolean(R.string.p_leakcanary, false)) {
AppWatcher.manualInstall(context) AppWatcher.manualInstall(context)
} }

@ -27,7 +27,7 @@ class Debug : InjectingPreferenceFragment() {
R.string.p_flipper, R.string.p_flipper,
R.string.p_strict_mode_vm, R.string.p_strict_mode_vm,
R.string.p_strict_mode_thread, R.string.p_strict_mode_thread,
R.string.p_debug_main_queries R.string.p_crash_main_queries
)) { )) {
findPreference(pref) findPreference(pref)
.setOnPreferenceChangeListener { _: Preference?, _: Any? -> .setOnPreferenceChangeListener { _: Preference?, _: Any? ->

@ -13,5 +13,5 @@
<string name="debug_themes">debug_themes</string> <string name="debug_themes">debug_themes</string>
<string name="debug_tasker">debug_tasker</string> <string name="debug_tasker">debug_tasker</string>
<string name="debug_reset_ssl">Reset SSL certificates</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> </resources>

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

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

@ -26,7 +26,7 @@ internal class ProductionModule {
fun getAppDatabase(@ApplicationContext context: Context, preferences: Preferences): Database { fun getAppDatabase(@ApplicationContext context: Context, preferences: Preferences): Database {
val builder = Room.databaseBuilder(context, Database::class.java, Database.NAME) val builder = Room.databaseBuilder(context, Database::class.java, Database.NAME)
.addMigrations(*Migrations.MIGRATIONS) .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() builder.allowMainThreadQueries()
} }
return builder.build() return builder.build()

@ -330,7 +330,7 @@
<string name="p_leakcanary">p_leakcanary</string> <string name="p_leakcanary">p_leakcanary</string>
<string name="p_flipper">p_flipper</string> <string name="p_flipper">p_flipper</string>
<string name="p_debug_pro">debug_pro</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="warned_play_services">warned_play_services</string>
<string name="p_background_sync_unmetered_only">background_sync_unmetered_only</string> <string name="p_background_sync_unmetered_only">background_sync_unmetered_only</string>
<string name="p_sync_ongoing">sync_ongoing</string> <string name="p_sync_ongoing">sync_ongoing</string>

Loading…
Cancel
Save