Merge pull request #4530 from k9mail/strictmode

Tune StrictMode warnings
This commit is contained in:
cketti 2020-02-13 18:07:34 +01:00 committed by GitHub
commit 8a96435c55
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 41 additions and 2 deletions

View file

@ -7,7 +7,6 @@ import android.content.IntentFilter
import android.content.pm.PackageManager
import android.os.Handler
import android.os.Looper
import android.os.StrictMode
import com.fsck.k9.job.K9JobManager
import com.fsck.k9.mail.internet.BinaryTempFileBody
import com.fsck.k9.service.BootReceiver
@ -29,7 +28,7 @@ object Core : EarlyInit {
*/
fun earlyInit(context: Context) {
if (K9.DEVELOPER_MODE) {
StrictMode.enableDefaults()
enableStrictMode()
}
val packageName = context.packageName

View file

@ -0,0 +1,40 @@
package com.fsck.k9
import android.os.Build
import android.os.StrictMode
import android.os.StrictMode.ThreadPolicy
import android.os.StrictMode.VmPolicy
fun enableStrictMode() {
StrictMode.setThreadPolicy(createThreadPolicy())
StrictMode.setVmPolicy(createVmPolicy())
}
private fun createThreadPolicy(): ThreadPolicy {
return ThreadPolicy.Builder()
.detectAll()
.penaltyLog()
.build()
}
private fun createVmPolicy(): VmPolicy {
return VmPolicy.Builder()
.detectActivityLeaks()
.detectLeakedClosableObjects()
.detectLeakedRegistrationObjects()
.detectFileUriExposure()
.detectLeakedSqlLiteObjects()
.apply {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
detectContentUriWithoutPermission()
// Disabled because we currently don't use tagged sockets; so this would generate a lot of noise
// detectUntaggedSockets()
}
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
detectCredentialProtectedWhileLocked()
}
}
.penaltyLog()
.build()
}