diff --git a/app/src/debug/java/org/tasks/BuildSetup.kt b/app/src/debug/java/org/tasks/BuildSetup.kt index b4c7bd3e3..2a8a04069 100644 --- a/app/src/debug/java/org/tasks/BuildSetup.kt +++ b/app/src/debug/java/org/tasks/BuildSetup.kt @@ -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()) } } } \ No newline at end of file diff --git a/app/src/debug/res/values/keys.xml b/app/src/debug/res/values/keys.xml index ac09c8b1b..a455a5e0c 100644 --- a/app/src/debug/res/values/keys.xml +++ b/app/src/debug/res/values/keys.xml @@ -14,5 +14,5 @@ debug_themes debug_tasker Reset SSL certificates - Crash queries on main thread + Crash on violation \ 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 648ced1ac..b5a2c663e 100644 --- a/app/src/debug/res/xml/preferences_debug.xml +++ b/app/src/debug/res/xml/preferences_debug.xml @@ -9,14 +9,14 @@ android:key="@string/p_flipper" android:title="@string/debug_flipper"/> - - + + runBlocking(context: CoroutineContext = EmptyCoroutineContext, block: suspend CoroutineScope.() -> T): T { - if (CRASH_ON_MAIN_THREAD) { - assertNotMainThread() - } - - return kotlinx.coroutines.runBlocking(context, block) -} - diff --git a/app/src/main/java/org/tasks/data/TagDataDaoBlocking.kt b/app/src/main/java/org/tasks/data/TagDataDaoBlocking.kt index 865c795cc..d4accdab8 100644 --- a/app/src/main/java/org/tasks/data/TagDataDaoBlocking.kt +++ b/app/src/main/java/org/tasks/data/TagDataDaoBlocking.kt @@ -1,6 +1,7 @@ package org.tasks.data import androidx.lifecycle.LiveData +import kotlinx.coroutines.runBlocking import javax.inject.Inject @Deprecated("use coroutines") diff --git a/app/src/main/java/org/tasks/data/UserActivityDaoBlocking.kt b/app/src/main/java/org/tasks/data/UserActivityDaoBlocking.kt index e82b6ed3b..8c7549811 100644 --- a/app/src/main/java/org/tasks/data/UserActivityDaoBlocking.kt +++ b/app/src/main/java/org/tasks/data/UserActivityDaoBlocking.kt @@ -1,5 +1,6 @@ package org.tasks.data +import kotlinx.coroutines.runBlocking import javax.inject.Inject @Deprecated("use coroutines") diff --git a/app/src/main/java/org/tasks/jobs/CleanupWork.kt b/app/src/main/java/org/tasks/jobs/CleanupWork.kt index 4627f3ed0..38264a7d3 100644 --- a/app/src/main/java/org/tasks/jobs/CleanupWork.kt +++ b/app/src/main/java/org/tasks/jobs/CleanupWork.kt @@ -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 diff --git a/app/src/main/java/org/tasks/notifications/NotificationDaoBlocking.kt b/app/src/main/java/org/tasks/notifications/NotificationDaoBlocking.kt index bb700b823..b7beaad42 100644 --- a/app/src/main/java/org/tasks/notifications/NotificationDaoBlocking.kt +++ b/app/src/main/java/org/tasks/notifications/NotificationDaoBlocking.kt @@ -1,6 +1,6 @@ package org.tasks.notifications -import org.tasks.data.runBlocking +import kotlinx.coroutines.runBlocking import javax.inject.Inject @Deprecated("use coroutines") diff --git a/app/src/main/java/org/tasks/preferences/DefaultFilterProvider.kt b/app/src/main/java/org/tasks/preferences/DefaultFilterProvider.kt index 612013431..ec9fbf11b 100644 --- a/app/src/main/java/org/tasks/preferences/DefaultFilterProvider.kt +++ b/app/src/main/java/org/tasks/preferences/DefaultFilterProvider.kt @@ -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.*