Merge pull request #4530 from k9mail/strictmode
Tune StrictMode warnings
This commit is contained in:
commit
8a96435c55
2 changed files with 41 additions and 2 deletions
|
@ -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
|
||||
|
|
40
app/core/src/main/java/com/fsck/k9/StrictMode.kt
Normal file
40
app/core/src/main/java/com/fsck/k9/StrictMode.kt
Normal 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()
|
||||
}
|
Loading…
Reference in a new issue