Skip to content

Commit

Permalink
Re-enable death penalty for leaking closable object violations
Browse files Browse the repository at this point in the history
  • Loading branch information
saket committed Apr 27, 2024
1 parent 32ad7c1 commit d872cae
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions sample/src/main/kotlin/me/saket/telephoto/sample/SampleActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package me.saket.telephoto.sample

import android.os.Bundle
import android.os.StrictMode
import android.os.strictmode.Violation
import android.view.WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS
import android.view.WindowManager.LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_MODE_ALWAYS
import androidx.activity.compose.setContent
Expand All @@ -23,20 +24,26 @@ import coil.decode.ImageDecoderDecoder
import com.google.accompanist.systemuicontroller.rememberSystemUiController
import me.saket.telephoto.sample.gallery.MediaAlbum
import me.saket.telephoto.sample.gallery.MediaItem
import java.util.concurrent.Executor

class SampleActivity : AppCompatActivity() {

override fun onCreate(savedInstanceState: Bundle?) {
StrictMode.setThreadPolicy(
StrictMode.ThreadPolicy.Builder()
.detectAll()
.penaltyLog()
.penaltyDeath()
.build()
)
StrictMode.setVmPolicy(
StrictMode.VmPolicy.Builder()
.detectAll()
.penaltyLog() // Can't use penaltyDeath() due to https://stackoverflow.com/q/67444092.
.detectLeakedClosableObjects()
.penaltyListener(Executor(Runnable::run)) {
// https://github.com/aosp-mirror/platform_frameworks_base/commit/e7ae30f76788bcec4457c4e0b0c9cbff2cf892f3
if (!it.stackTraceToString().contains("sun.nio.fs.UnixSecureDirectoryStream.finalize")) {
throw it
}
}
.build()
)

Expand Down

0 comments on commit d872cae

Please sign in to comment.