Skip to content

Commit

Permalink
Avoid rendering bitmaps above 100MB
Browse files Browse the repository at this point in the history
  • Loading branch information
Rawa committed Apr 4, 2024
1 parent de14699 commit a346218
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import net.mullvad.mullvadvpn.R
import net.mullvad.mullvadvpn.compose.component.SpacedColumn
import net.mullvad.mullvadvpn.compose.util.isBelowMaxBitmapSize
import net.mullvad.mullvadvpn.lib.theme.AppTheme
import net.mullvad.mullvadvpn.lib.theme.Dimens
import net.mullvad.mullvadvpn.lib.theme.color.Alpha40
Expand Down Expand Up @@ -75,7 +76,9 @@ fun SplitTunnelingCell(
LaunchedEffect(packageName) {
launch(Dispatchers.IO) {
val bitmap = onResolveIcon(packageName ?: "")
icon = bitmap?.asImageBitmap()
if (bitmap != null && bitmap.isBelowMaxBitmapSize()) {
icon = bitmap.asImageBitmap()
}
}
}
BaseCell(
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package net.mullvad.mullvadvpn.compose.util

import android.graphics.Bitmap

private const val MAX_BITMAP_SIZE_BYTES = 100 * 1024 * 1024

fun Bitmap.isBelowMaxBitmapSize(): Boolean = byteCount < MAX_BITMAP_SIZE_BYTES

0 comments on commit a346218

Please sign in to comment.