Repository: skyline-emu/skyline
File: app/src/main/java/emu/skyline/EmulationActivity.kt (Kotlin)

Code before:
        item = AppItem(romFile.takeIf { it.valid }!!.appEntry)
    }

    @SuppressLint("SetTextI18n", "ClickableViewAccessibility")
    override fun onCreate(savedInstanceState : Bundle?) {
        super.onCreate(savedInstanceState)
        populateAppItem()
        emulationSettings = EmulationSettings.forEmulation(item.titleId ?: item.key())

        requestedOrientation = emulationSettings.orientation
        window.attributes.layoutInDisplayCutoutMode = WindowManager.LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_MODE_SHORT_EDGES
        inputHandler = InputHandler(inputManager, emulationSettings)
        setContentView(binding.root)

        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
            // Android might not allow child views to overlap the system bars
            // Override this behavior and force content to extend into the cutout area
            window.setDecorFitsSystemWindows(false)

            window.insetsController?.let {
                it.systemBarsBehavior = WindowInsetsController.BEHAVIOR_SHOW_TRANSIENT_BARS_BY_SWIPE
                it.hide(WindowInsets.Type.systemBars())
            }
        }

        if (emulationSettings.respectDisplayCutout) {
            binding.perfStats.setOnApplyWindowInsetsListener(insetsOrMarginHandler)
            binding.onScreenControllerToggle.setOnApplyWindowInsetsListener(insetsOrMarginHandler)
        }

        binding.gameView.holder.addCallback(this)

        binding.gameView.setAspectRatio(
            when (emulationSettings.aspectRatio) {
                0 -> Rational(16, 9)
                1 -> Rational(21, 9)
                else -> null
            }
        )

        if (emulationSettings.perfStats) {
            if (emulationSettings.disableFrameThrottling)
                binding.perfStats.setTextColor(getColor(R.color.colorPerfStatsSecondary))

            binding.perfStats.apply {
                postDelayed(object : Runnable {
                    override fun run() {
                        updatePerformanceStatistics()
                        text = "$fps FPS\n${"%.1f".format(averageFrametime)}±${"%.2f".format(averageFrametimeDeviation)}ms"
                        postDelayed(this, 250)
                    }

Review comment (suggestion):
```suggestion
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S)
            setPictureInPictureParams(PictureInPictureParams.Builder().setAutoEnterEnabled(true).build())
```

Code after:
        emulationThread!!.start()
    }

    /**
     * Populates the [item] member with data from the intent
     */
    private fun populateAppItem() {
        val intentItem = intent.getSerializableExtra(AppItemTag) as AppItem?
        if (intentItem != null) {
            item = intentItem
            return
        }

        // The intent did not contain an app item, fall back to the data URI
        val uri = intent.data!!
        val romFormat = getRomFormat(uri, contentResolver)
        val romFile = RomFile(this, romFormat, uri, EmulationSettings.global.systemLanguage)

        item = AppItem(romFile.takeIf { it.valid }!!.appEntry)
    }

    @SuppressLint("SetTextI18n", "ClickableViewAccessibility")
    override fun onCreate(savedInstanceState : Bundle?) {
        super.onCreate(savedInstanceState)
        populateAppItem()
        emulationSettings = EmulationSettings.forEmulation(item.titleId ?: item.key())

        requestedOrientation = emulationSettings.orientation
        window.attributes.layoutInDisplayCutoutMode = WindowManager.LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_MODE_SHORT_EDGES
        inputHandler = InputHandler(inputManager, emulationSettings)
        setContentView(binding.root)

        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
            // Android might not allow child views to overlap the system bars
            // Override this behavior and force content to extend into the cutout area
            window.setDecorFitsSystemWindows(false)

            window.insetsController?.let {
                it.systemBarsBehavior = WindowInsetsController.BEHAVIOR_SHOW_TRANSIENT_BARS_BY_SWIPE
                it.hide(WindowInsets.Type.systemBars())
            }
        }

        if (emulationSettings.respectDisplayCutout) {
            binding.perfStats.setOnApplyWindowInsetsListener(insetsOrMarginHandler)
            binding.onScreenControllerToggle.setOnApplyWindowInsetsListener(insetsOrMarginHandler)
        }

        pictureInPictureParamsBuilder = getPictureInPictureBuilder()
        setPictureInPictureParams(pictureInPictureParamsBuilder.build())