Use strict mode to crash app

pull/1061/head
Alex Baker 4 years ago
parent ef432e296c
commit ca42c718b9

@ -11,8 +11,9 @@ import com.facebook.flipper.plugins.inspector.InspectorFlipperPlugin
import com.facebook.flipper.plugins.network.NetworkFlipperPlugin
import com.facebook.flipper.plugins.sharedpreferences.SharedPreferencesFlipperPlugin
import com.facebook.soloader.SoLoader
import com.todoroo.andlib.utility.AndroidUtilities.atLeastOreo
import com.todoroo.andlib.utility.AndroidUtilities.atLeastQ
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
@ -25,7 +26,6 @@ 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)
}
@ -38,21 +38,29 @@ class BuildSetup @Inject constructor(
client.start()
}
if (preferences.getBoolean(R.string.p_strict_mode_thread, false)) {
StrictMode.setThreadPolicy(
StrictMode.ThreadPolicy.Builder()
.detectDiskReads()
.detectDiskWrites()
.detectNetwork()
.penaltyLog()
.build())
val builder = StrictMode.ThreadPolicy.Builder().detectAll().penaltyLog()
if (preferences.getBoolean(R.string.p_crash_main_queries, false)) {
builder.penaltyDeath()
}
StrictMode.setThreadPolicy(builder.build())
}
if (preferences.getBoolean(R.string.p_strict_mode_vm, false)) {
StrictMode.setVmPolicy(
VmPolicy.Builder()
.detectLeakedSqlLiteObjects()
.detectLeakedClosableObjects()
.penaltyLog()
.build())
val builder = VmPolicy.Builder()
.detectActivityLeaks()
.detectLeakedSqlLiteObjects()
.detectLeakedRegistrationObjects()
.detectLeakedClosableObjects()
.detectFileUriExposure()
.penaltyLog()
if (atLeastOreo()) {
builder.detectContentUriWithoutPermission()
}
if (atLeastQ()) {
builder
.detectCredentialProtectedWhileLocked()
.detectImplicitDirectBoot()
}
StrictMode.setVmPolicy(builder.build())
}
}
}

@ -14,5 +14,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">Crash queries on main thread</string>
<string name="debug_main_queries">Crash on violation</string>
</resources>

@ -9,14 +9,14 @@
android:key="@string/p_flipper"
android:title="@string/debug_flipper"/>
<SwitchPreferenceCompat
android:key="@string/p_strict_mode_thread"
android:title="@string/debug_strict_mode_thread"/>
<SwitchPreferenceCompat
android:key="@string/p_strict_mode_vm"
android:title="@string/debug_strict_mode_vm"/>
<SwitchPreferenceCompat
android:key="@string/p_strict_mode_thread"
android:title="@string/debug_strict_mode_thread"/>
<SwitchPreferenceCompat
android:defaultValue="false"
android:key="@string/p_crash_main_queries"

@ -5,9 +5,9 @@
*/
package com.todoroo.astrid.alarms
import kotlinx.coroutines.runBlocking
import org.tasks.data.Alarm
import org.tasks.data.AlarmDao
import org.tasks.data.runBlocking
import org.tasks.jobs.AlarmEntry
import org.tasks.jobs.NotificationQueue
import java.util.*

@ -13,10 +13,10 @@ import com.google.api.services.tasks.model.TaskList
import com.google.api.services.tasks.model.TaskLists
import dagger.hilt.android.qualifiers.ApplicationContext
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.runBlocking
import kotlinx.coroutines.withContext
import org.tasks.BuildConfig
import org.tasks.DebugNetworkInterceptor
import org.tasks.data.runBlocking
import org.tasks.gtasks.GoogleAccountManager
import org.tasks.preferences.Preferences
import timber.log.Timber

@ -3,8 +3,8 @@ package com.todoroo.astrid.service
import com.todoroo.andlib.utility.DateUtilities
import com.todoroo.astrid.dao.TaskDao
import com.todoroo.astrid.data.Task
import kotlinx.coroutines.runBlocking
import org.tasks.data.GoogleTaskDao
import org.tasks.data.runBlocking
import timber.log.Timber
import javax.inject.Inject

@ -3,6 +3,7 @@ package com.todoroo.astrid.service
import com.todoroo.astrid.api.Filter
import com.todoroo.astrid.data.Task
import kotlinx.collections.immutable.persistentListOf
import kotlinx.coroutines.runBlocking
import org.tasks.LocalBroadcastManager
import org.tasks.data.*
import org.tasks.db.QueryUtils

@ -19,13 +19,13 @@ import com.todoroo.astrid.activity.TaskListFragment
import com.todoroo.astrid.api.CaldavFilter
import com.todoroo.astrid.helper.UUIDHelper
import com.todoroo.astrid.service.TaskDeleter
import kotlinx.coroutines.runBlocking
import org.tasks.R
import org.tasks.Strings.isNullOrEmpty
import org.tasks.activities.BaseListSettingsActivity
import org.tasks.data.CaldavAccount
import org.tasks.data.CaldavCalendar
import org.tasks.data.CaldavDao
import org.tasks.data.runBlocking
import org.tasks.ui.DisplayableException
import java.net.ConnectException
import javax.inject.Inject

@ -2,11 +2,11 @@ package org.tasks.caldav
import android.os.Bundle
import dagger.hilt.android.AndroidEntryPoint
import kotlinx.coroutines.runBlocking
import org.tasks.R
import org.tasks.data.CaldavAccount
import org.tasks.data.CaldavCalendar
import org.tasks.data.CaldavDao
import org.tasks.data.runBlocking
@AndroidEntryPoint
class LocalListSettingsActivity : BaseCaldavCalendarSettingsActivity() {

@ -1,6 +1,7 @@
package org.tasks.data
import androidx.lifecycle.LiveData
import kotlinx.coroutines.runBlocking
import javax.inject.Inject
@Deprecated("use coroutines")

@ -3,6 +3,7 @@ package org.tasks.data
import android.database.Cursor
import androidx.sqlite.db.SupportSQLiteQuery
import com.todoroo.astrid.data.Task
import kotlinx.coroutines.runBlocking
import javax.inject.Inject
@Deprecated("use coroutines")

@ -1,6 +1,7 @@
package org.tasks.data
import androidx.lifecycle.LiveData
import kotlinx.coroutines.runBlocking
import javax.inject.Inject
@Deprecated("use coroutines")

@ -1,6 +1,7 @@
package org.tasks.data
import androidx.lifecycle.LiveData
import kotlinx.coroutines.runBlocking
import javax.inject.Inject
@Deprecated("use coroutines")

@ -1,18 +0,0 @@
package org.tasks.data
import com.todoroo.andlib.utility.AndroidUtilities.assertNotMainThread
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 {
if (CRASH_ON_MAIN_THREAD) {
assertNotMainThread()
}
return kotlinx.coroutines.runBlocking(context, block)
}

@ -1,6 +1,7 @@
package org.tasks.data
import androidx.lifecycle.LiveData
import kotlinx.coroutines.runBlocking
import javax.inject.Inject
@Deprecated("use coroutines")

@ -1,5 +1,6 @@
package org.tasks.data
import kotlinx.coroutines.runBlocking
import javax.inject.Inject
@Deprecated("use coroutines")

@ -7,6 +7,7 @@ import androidx.work.WorkerParameters
import com.todoroo.astrid.alarms.AlarmService
import com.todoroo.astrid.reminders.ReminderService
import com.todoroo.astrid.timers.TimerPlugin
import kotlinx.coroutines.runBlocking
import org.tasks.analytics.Firebase
import org.tasks.data.*
import org.tasks.files.FileHelper

@ -1,6 +1,6 @@
package org.tasks.notifications
import org.tasks.data.runBlocking
import kotlinx.coroutines.runBlocking
import javax.inject.Inject
@Deprecated("use coroutines")

@ -7,6 +7,7 @@ import com.todoroo.astrid.core.BuiltInFilterExposer
import com.todoroo.astrid.core.BuiltInFilterExposer.Companion.getMyTasksFilter
import com.todoroo.astrid.data.Task
import dagger.hilt.android.qualifiers.ApplicationContext
import kotlinx.coroutines.runBlocking
import org.tasks.R
import org.tasks.Strings.isNullOrEmpty
import org.tasks.data.*

Loading…
Cancel
Save