fix(IconOptions): add maximum custom image size limit

Images that are too large cause issues when creating bitmaps, causing an OOM.
This commit is contained in:
rushiiMachine 2025-04-13 22:12:08 -07:00
parent a8ce6952c1
commit f8dbee6597
No known key found for this signature in database
GPG key ID: DCBE5952BB3B6420
2 changed files with 18 additions and 1 deletions

View file

@ -2,6 +2,7 @@ package com.aliucord.manager.ui.screens.iconopts
import android.app.Application
import android.net.Uri
import android.provider.OpenableColumns
import android.util.Log
import androidx.compose.runtime.*
import androidx.compose.ui.graphics.Color
@ -39,6 +40,21 @@ class IconOptionsModel(
fun changeSelectedImageUri(uri: Uri) = screenModelScope.launchBlock {
try {
// Check file size first
val query = application.contentResolver.query(uri, null, null, null, null)
?: throw IOException("Failed to query selected image uri")
val size = query.use { cursor ->
cursor.moveToFirst()
cursor.getLong(cursor.getColumnIndexOrThrow(OpenableColumns.SIZE))
}
if (size > 1024 * 256) { // 256KiB
application.showToast(R.string.iconopts_failed_image_too_big)
return@launchBlock
}
// Read file bytes
val bytes = application.contentResolver
.openInputStream(uri)
?.use { it.readBytes() }

View file

@ -171,7 +171,7 @@
<string name="iconopts_variant_desc_discord">Does not alter the original icon, instead only adding the missing monochrome icon to the APK.</string>
<string name="iconopts_variant_desc_aliucord">Changes the original icon color to Aliucord\'s branding.</string>
<string name="iconopts_variant_desc_color">Select a custom icon background color.</string>
<string name="iconopts_variant_desc_image">Select a custom replacement image. Note that the image must have sufficient padding as per the Adaptive Icon foreground guidelines. Android 8+ only.</string>
<string name="iconopts_variant_desc_image">Select a custom replacement image. Note that the image must have sufficient padding as per the Adaptive Icon foreground guidelines. Android 8+ only. Maximum image size is 256KiB.</string>
<string name="iconopts_colorpicker_title">Hue &amp; Saturation</string>
<string name="iconopts_colorpicker_desc">The main HSV color components.</string>
<string name="iconopts_lightness_title">Lightness</string>
@ -179,6 +179,7 @@
<string name="iconopts_hex_title">Hex Color</string>
<string name="iconopts_hex_desc">Manually enter the RGB hex value of the color. Transparency is ignored!</string>
<string name="iconopts_failed_image">Failed to open image</string>
<string name="iconopts_failed_image_too_big">Image size exceeds maximum of 256KiB</string>
<string name="iconopts_btn_open_selection">Select Image</string>
<string name="iconopts_btn_open_example_image">Example image</string>
<string name="iconopts_image_preview_title">Preview</string>