@@ -40,7 +40,6 @@ import androidx.compose.runtime.saveable.rememberSaveable
4040import androidx.compose.ui.Alignment
4141import androidx.compose.ui.Modifier
4242import androidx.compose.ui.draw.clip
43- import androidx.compose.ui.graphics.ImageBitmap
4443import androidx.compose.ui.layout.ContentScale
4544import androidx.compose.ui.platform.LocalContext
4645import androidx.compose.ui.res.stringResource
@@ -49,6 +48,7 @@ import androidx.compose.ui.text.style.TextOverflow
4948import androidx.compose.ui.unit.dp
5049import androidx.compose.material.icons.Icons
5150import androidx.compose.material.icons.filled.*
51+ import coil.compose.rememberAsyncImagePainter
5252import kotlinx.coroutines.Dispatchers
5353import kotlinx.coroutines.launch
5454import kotlinx.coroutines.withContext
@@ -101,8 +101,7 @@ data class AppData(
101101 val isSystem : Boolean ,
102102 val isInstalled : Boolean ,
103103 val isDisabled : Boolean ,
104- val safetyLevel : SafetyLevel ,
105- val icon : ImageBitmap ? = null
104+ val safetyLevel : SafetyLevel
106105)
107106
108107data class ConfirmAction (
@@ -779,6 +778,17 @@ fun AppListItem(
779778 onUninstall : (AppData ) -> Unit ,
780779 onRestore : (AppData ) -> Unit
781780) {
781+ val context = LocalContext .current
782+ val appIcon by produceState< android.graphics.drawable.Drawable ? > (
783+ initialValue = null ,
784+ key1 = appData.packageName
785+ ) {
786+ value = withContext(Dispatchers .IO ) {
787+ runCatching { context.packageManager.getApplicationIcon(appData.packageName) }
788+ .getOrNull()
789+ }
790+ }
791+
782792 Surface (
783793 modifier = Modifier
784794 .fillMaxWidth()
@@ -797,9 +807,9 @@ fun AppListItem(
797807 modifier = Modifier .size(40 .dp),
798808 contentAlignment = Alignment .Center
799809 ) {
800- if (appData.icon != null ) {
810+ if (appIcon != null ) {
801811 Image (
802- bitmap = appData.icon ,
812+ painter = rememberAsyncImagePainter(appIcon) ,
803813 contentDescription = null ,
804814 modifier = Modifier .size(40 .dp),
805815 contentScale = ContentScale .Fit
@@ -998,9 +1008,7 @@ private suspend fun loadAllAppDataWithIcons(
9981008 } ? : false ,
9991009 isDisabled = appInfo?.enabled == false ,
10001010 isInstalled = isInstalled,
1001- safetyLevel = SafetyClassifier .classify(pkg.packageName),
1002- // Avoid eagerly decoding every app icon into memory to prevent startup OOM crashes.
1003- icon = null
1011+ safetyLevel = SafetyClassifier .classify(pkg.packageName)
10041012 )
10051013 }
10061014 .sortedWith(compareBy(String .CASE_INSENSITIVE_ORDER ) { it.appName })
0 commit comments