Fix some of the StrictMode violations (#1931)

Mostly it's disk reads/writes.

Conscrypt reads own version on startup which reads from disk multiple
times. There's no solution for it right now.

SharedPreferences which are used in BaseActivity also read from disk
and pretty early but it shouldn't be a problem.
main
Ivan Kupalov 4 years ago committed by Alibek Omarov
parent 9a182f6a68
commit e617b361c3
  1. 8
      app/src/main/java/com/keylesspalace/tusky/MainActivity.kt
  2. 39
      app/src/main/java/com/keylesspalace/tusky/TuskyApplication.kt

@ -84,6 +84,7 @@ import com.uber.autodispose.android.lifecycle.autoDispose
import dagger.android.DispatchingAndroidInjector import dagger.android.DispatchingAndroidInjector
import dagger.android.HasAndroidInjector import dagger.android.HasAndroidInjector
import io.reactivex.android.schedulers.AndroidSchedulers import io.reactivex.android.schedulers.AndroidSchedulers
import io.reactivex.schedulers.Schedulers
import kotlinx.android.synthetic.main.activity_main.* import kotlinx.android.synthetic.main.activity_main.*
import retrofit2.Call import retrofit2.Call
import retrofit2.Callback import retrofit2.Callback
@ -235,9 +236,10 @@ class MainActivity : BottomSheetActivity(), ActionButtonActivity, HasAndroidInje
} }
} }
// Flush old media that was cached for sharing Schedulers.io().scheduleDirect {
deleteStaleCachedMedia(applicationContext.getExternalFilesDir("Husky")) // Flush old media that was cached for sharing
} deleteStaleCachedMedia(applicationContext.getExternalFilesDir("Husky"))
}
private fun initPullNotifications() { private fun initPullNotifications() {
if (NotificationHelper.areNotificationsEnabled(this, accountManager)) { if (NotificationHelper.areNotificationsEnabled(this, accountManager)) {

@ -29,11 +29,15 @@ import com.github.piasy.biv.loader.glide.GlideCustomImageLoader
import com.keylesspalace.tusky.components.notifications.NotificationWorkerFactory import com.keylesspalace.tusky.components.notifications.NotificationWorkerFactory
import com.keylesspalace.tusky.di.AppInjector import com.keylesspalace.tusky.di.AppInjector
import com.keylesspalace.tusky.settings.PrefKeys import com.keylesspalace.tusky.settings.PrefKeys
import com.keylesspalace.tusky.util.* import com.keylesspalace.tusky.util.EmojiCompatFont
import com.keylesspalace.tusky.util.LocaleManager
import com.keylesspalace.tusky.util.ThemeUtils
import com.uber.autodispose.AutoDisposePlugins import com.uber.autodispose.AutoDisposePlugins
import dagger.Lazy
import dagger.android.DispatchingAndroidInjector import dagger.android.DispatchingAndroidInjector
import dagger.android.HasAndroidInjector import dagger.android.HasAndroidInjector
import io.reactivex.plugins.RxJavaPlugins import io.reactivex.plugins.RxJavaPlugins
import io.reactivex.schedulers.Schedulers
import org.conscrypt.Conscrypt import org.conscrypt.Conscrypt
import java.security.Security import java.security.Security
import javax.inject.Inject import javax.inject.Inject
@ -42,11 +46,21 @@ class TuskyApplication : Application(), HasAndroidInjector {
@Inject @Inject
lateinit var androidInjector: DispatchingAndroidInjector<Any> lateinit var androidInjector: DispatchingAndroidInjector<Any>
@Inject @Inject
lateinit var notificationWorkerFactory: NotificationWorkerFactory lateinit var notificationWorkerFactory: Lazy<NotificationWorkerFactory>
override fun onCreate() { override fun onCreate() {
// Uncomment me to get StrictMode violation logs
// if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) {
// StrictMode.setThreadPolicy(StrictMode.ThreadPolicy.Builder()
// .detectDiskReads()
// .detectDiskWrites()
// .detectNetwork()
// .detectUnbufferedIo()
// .penaltyLog()
// .build())
// }
super.onCreate() super.onCreate()
Security.insertProviderAt(Conscrypt.newProvider(), 1) Security.insertProviderAt(Conscrypt.newProvider(), 1)
@ -68,19 +82,22 @@ class TuskyApplication : Application(), HasAndroidInjector {
val theme = preferences.getString("appTheme", ThemeUtils.APP_THEME_DEFAULT) val theme = preferences.getString("appTheme", ThemeUtils.APP_THEME_DEFAULT)
ThemeUtils.setAppNightMode(theme) ThemeUtils.setAppNightMode(theme)
WorkManager.initialize(
this,
androidx.work.Configuration.Builder()
.setWorkerFactory(notificationWorkerFactory)
.build()
)
RxJavaPlugins.setErrorHandler { RxJavaPlugins.setErrorHandler {
Log.w("RxJava", "undeliverable exception", it) Log.w("RxJava", "undeliverable exception", it)
} }
SubsamplingScaleImageView.setPreferredBitmapConfig(Bitmap.Config.ARGB_8888) SubsamplingScaleImageView.setPreferredBitmapConfig(Bitmap.Config.ARGB_8888)
BigImageViewer.initialize(GlideCustomImageLoader.with(this)) BigImageViewer.initialize(GlideCustomImageLoader.with(this))
// This will initialize the whole network stack and cache so we don't wan to wait for it
Schedulers.computation().scheduleDirect {
WorkManager.initialize(
this,
androidx.work.Configuration.Builder()
.setWorkerFactory(notificationWorkerFactory.get())
.build()
)
}
} }
override fun attachBaseContext(base: Context) { override fun attachBaseContext(base: Context) {
@ -99,4 +116,4 @@ class TuskyApplication : Application(), HasAndroidInjector {
@JvmStatic @JvmStatic
lateinit var localeManager: LocaleManager lateinit var localeManager: LocaleManager
} }
} }

Loading…
Cancel
Save