Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit d3df7050 authored by Peter Cai's avatar Peter Cai
Browse files

wizard: Make sure bitmaps are recycled properly



Co-authored-by: default avatarsepts <github@septs.pw>
parent 53f9459a
Loading
Loading
Loading
Loading
+6 −9
Original line number Diff line number Diff line
@@ -44,17 +44,14 @@ class DownloadWizardMethodSelectFragment : DownloadWizardActivity.DownloadWizard

            lifecycleScope.launch(Dispatchers.IO) {
                runCatching {
                    requireContext().contentResolver.openInputStream(result)?.let { input ->
                        val bmp = BitmapFactory.decodeStream(input)
                        input.close()

                    requireContext().contentResolver.openInputStream(result)?.use { input ->
                        BitmapFactory.decodeStream(input).use { bmp ->
                            decodeQrFromBitmap(bmp)?.let {
                                withContext(Dispatchers.Main) {
                                    processLpaString(it)
                                }
                            }

                        bmp.recycle()
                        }
                    }
                }
            }
+7 −0
Original line number Diff line number Diff line
@@ -86,6 +86,13 @@ suspend fun connectSEService(context: Context): SEService = suspendCoroutine { c
    }
}

inline fun <T> Bitmap.use(f: (Bitmap) -> T): T =
    try {
        f(this)
    } finally {
        recycle()
    }

fun decodeQrFromBitmap(bmp: Bitmap): String? =
     runCatching {
        val pixels = IntArray(bmp.width * bmp.height)