|
47 | 47 | import java.util.Objects;
|
48 | 48 | import java.util.Optional;
|
49 | 49 | import java.util.Set;
|
| 50 | +import java.util.function.Function; |
| 51 | +import java.util.function.Predicate; |
50 | 52 | import java.util.stream.Collectors;
|
51 | 53 |
|
52 | 54 | /**
|
@@ -110,20 +112,21 @@ public void getSuggestedFolderName(Context context,
|
110 | 112 | Log.d(TAG, "getSuggestedFolderName:" + nameInfos.toString());
|
111 | 113 | }
|
112 | 114 |
|
| 115 | + // A shallow copy tring to avoid ConcurrentModificationException |
| 116 | + final ArrayList<WorkspaceItemInfo> candidates = new ArrayList<>(workspaceItemInfos); |
113 | 117 | // If all the icons are from work profile,
|
114 | 118 | // 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) |
116 | 120 | .collect(Collectors.toSet());
|
117 | 121 | if (users.size() == 1 && !users.contains(Process.myUserHandle())) {
|
118 | 122 | setAsLastSuggestion(nameInfos, getWorkFolderName(context));
|
119 | 123 | }
|
120 | 124 |
|
121 | 125 | // If all the icons are from same package (e.g., main icon, shortcut, shortcut)
|
122 | 126 | // 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()) |
127 | 130 | .collect(Collectors.toSet());
|
128 | 131 |
|
129 | 132 | if (packageNames.size() == 1) {
|
|
0 commit comments