Skip to content

Commit

Permalink
sample: Extract StrictMode's setup into its own function
Browse files Browse the repository at this point in the history
  • Loading branch information
saket committed Jul 19, 2024
1 parent 934e5f5 commit 8e66fc8
Showing 1 changed file with 21 additions and 19 deletions.
40 changes: 21 additions & 19 deletions sample/src/main/kotlin/me/saket/telephoto/sample/SampleActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ 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 @@ -29,24 +28,7 @@ import java.util.concurrent.Executor
class SampleActivity : AppCompatActivity() {

override fun onCreate(savedInstanceState: Bundle?) {
StrictMode.setThreadPolicy(
StrictMode.ThreadPolicy.Builder()
.detectAll()
.penaltyDeath()
.build()
)
StrictMode.setVmPolicy(
StrictMode.VmPolicy.Builder()
.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()
)

enableStrictMode()
enableEdgeToEdge()
setupImmersiveMode()
super.onCreate(savedInstanceState)
Expand Down Expand Up @@ -101,6 +83,26 @@ class SampleActivity : AppCompatActivity() {
}
}

private fun enableStrictMode() {
StrictMode.setThreadPolicy(
StrictMode.ThreadPolicy.Builder()
.detectAll()
.penaltyDeath()
.build()
)
StrictMode.setVmPolicy(
StrictMode.VmPolicy.Builder()
.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()
)
}

private fun setupImmersiveMode() {
// Draw behind display cutouts.
window.attributes.layoutInDisplayCutoutMode = LAYOUT_IN_DISPLAY_CUTOUT_MODE_ALWAYS
Expand Down

0 comments on commit 8e66fc8

Please sign in to comment.