From fcbf433f39c88e96f4fdf18d9c795a3480939730 Mon Sep 17 00:00:00 2001 From: caizhixing Date: Thu, 5 Nov 2026 22:05:10 -0800 Subject: [PATCH] fix(folder): crash when opening a folder with an empty preview (#7482) getAnimationData() read itemsInPreview[0] to derive the base icon size. The preview list can be empty when the folder has no bound child views yet, which made opening the folder crash with an IndexOutOfBoundsException. Fall back to the device profile icon size when the list is empty; the normal path is unchanged. Co-authored-by: caizhixing <17589399+caizhixing03@user.noreply.gitee.com> --- src/com/android/launcher3/folder/FolderAnimationData.kt | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/com/android/launcher3/folder/FolderAnimationData.kt b/src/com/android/launcher3/folder/FolderAnimationData.kt index 36efa9f046..d25dbde00d 100644 --- a/src/com/android/launcher3/folder/FolderAnimationData.kt +++ b/src/com/android/launcher3/folder/FolderAnimationData.kt @@ -74,7 +74,11 @@ data class FolderAnimationData( folderIconWorkspacePosition, ) val scaledFolderRadius: Int = previewBackground.scaledRadius - val baseIconSize: Float = getBubbleTextView(itemsInPreview[0]).iconSize.toFloat() + // The preview can be empty when the folder has no bound child views yet. Fall back + // to the device profile icon size so that opening the folder does not crash. + val baseIconSize: Float = + itemsInPreview.firstOrNull()?.let { getBubbleTextView(it).iconSize.toFloat() } + ?: mActivityContext.deviceProfile.iconSizePx.toFloat() val initialFolderSize = (scaledFolderRadius * 2) * scaleRelativeToDragLayer val initialFolderScale = previewSize / baseIconSize * scaleRelativeToDragLayer