Skip to content

Commit e56261f

Browse files
shawnlinboyneobuddy89
authored andcommitted
Launcher3: Fix potential ConcurrentModificationException
The workspaceItemInfos passed in may be modified elsewhere at the same time as this executor is running, we can introduce a new ArrayList object initialized with all original workspaceItemInfos to avoid ConcurrentModificationException as a tricky workaround. Bug: 271324475 Test: atest Change-Id: I087e2b780a35743b8f9cb1371dd13fa241737f8c Signed-off-by: Pranav Vashi <[email protected]>
1 parent aa87f2a commit e56261f

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

src/com/android/launcher3/folder/FolderNameProvider.java

+8-5
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@
4747
import java.util.Objects;
4848
import java.util.Optional;
4949
import java.util.Set;
50+
import java.util.function.Function;
51+
import java.util.function.Predicate;
5052
import java.util.stream.Collectors;
5153

5254
/**
@@ -110,20 +112,21 @@ public void getSuggestedFolderName(Context context,
110112
Log.d(TAG, "getSuggestedFolderName:" + nameInfos.toString());
111113
}
112114

115+
// A shallow copy tring to avoid ConcurrentModificationException
116+
final ArrayList<WorkspaceItemInfo> candidates = new ArrayList<>(workspaceItemInfos);
113117
// If all the icons are from work profile,
114118
// Then, suggest "Work" as the folder name
115-
Set<UserHandle> users = workspaceItemInfos.stream().map(w -> w.user)
119+
Set<UserHandle> users = candidates.stream().map(w -> w.user)
116120
.collect(Collectors.toSet());
117121
if (users.size() == 1 && !users.contains(Process.myUserHandle())) {
118122
setAsLastSuggestion(nameInfos, getWorkFolderName(context));
119123
}
120124

121125
// If all the icons are from same package (e.g., main icon, shortcut, shortcut)
122126
// Then, suggest the package's title as the folder name
123-
Set<String> packageNames = workspaceItemInfos.stream()
124-
.map(WorkspaceItemInfo::getTargetComponent)
125-
.filter(Objects::nonNull)
126-
.map(ComponentName::getPackageName)
127+
Set<String> packageNames = candidates.stream()
128+
.filter(workspaceItemInfo -> workspaceItemInfo.getTargetComponent() != null)
129+
.map(workspaceItemInfo -> workspaceItemInfo.getTargetComponent().getPackageName())
127130
.collect(Collectors.toSet());
128131

129132
if (packageNames.size() == 1) {

0 commit comments

Comments
 (0)