Updating ItemInfoMatcher to work with java streams

Adding support for bulk removing items from a folder icon.
This fixes workspace item removal when a folder gets replaced
to an icon during the delete operation.

- Lets say user has a folder with the same app twice.
- User disables that app.
- Launcher removes all shorcuts of that app

However, because we call "replaceFolderWithFinalItem" during
this removal, we end up creating a new shortcut that does
not get tracked by the removal, so the user is left with
an enabled icon of the disabled app.

Bug: 162378169
Test: manual test, repo steps in bug
Change-Id: Iaf6550894c156b3b5ec2a5aa58bab76a4a28819e
This commit is contained in:
Sunny Goyal
2021-01-27 15:16:59 -08:00
parent f1db62cc98
commit bfc0c38157
6 changed files with 52 additions and 72 deletions

View File

@@ -20,10 +20,7 @@ import android.content.ComponentName;
import android.os.UserHandle;
import com.android.launcher3.LauncherSettings.Favorites;
import com.android.launcher3.model.data.FolderInfo;
import com.android.launcher3.model.data.ItemInfo;
import com.android.launcher3.model.data.LauncherAppWidgetInfo;
import com.android.launcher3.model.data.WorkspaceItemInfo;
import com.android.launcher3.shortcuts.ShortcutKey;
import java.util.HashSet;
@@ -37,34 +34,15 @@ public interface ItemInfoMatcher {
boolean matches(ItemInfo info, ComponentName cn);
/**
* Filters {@param infos} to those satisfying the {@link #matches(ItemInfo, ComponentName)}.
* Returns true if the itemInfo matches this check
*/
default HashSet<ItemInfo> filterItemInfos(Iterable<ItemInfo> infos) {
HashSet<ItemInfo> filtered = new HashSet<>();
for (ItemInfo i : infos) {
if (i instanceof WorkspaceItemInfo) {
WorkspaceItemInfo info = (WorkspaceItemInfo) i;
ComponentName cn = info.getTargetComponent();
if (cn != null && matches(info, cn)) {
filtered.add(info);
}
} else if (i instanceof FolderInfo) {
FolderInfo info = (FolderInfo) i;
for (WorkspaceItemInfo s : info.contents) {
ComponentName cn = s.getTargetComponent();
if (cn != null && matches(s, cn)) {
filtered.add(s);
}
}
} else if (i instanceof LauncherAppWidgetInfo) {
LauncherAppWidgetInfo info = (LauncherAppWidgetInfo) i;
ComponentName cn = info.providerName;
if (cn != null && matches(info, cn)) {
filtered.add(info);
}
}
default boolean matchesInfo(ItemInfo info) {
if (info != null) {
ComponentName cn = info.getTargetComponent();
return cn != null && matches(info, cn);
} else {
return false;
}
return filtered;
}
/**
@@ -96,7 +74,7 @@ public interface ItemInfoMatcher {
return (info, cn) -> components.contains(cn) && info.user.equals(user);
}
static ItemInfoMatcher ofPackages(HashSet<String> packageNames, UserHandle user) {
static ItemInfoMatcher ofPackages(Set<String> packageNames, UserHandle user) {
return (info, cn) -> packageNames.contains(cn.getPackageName()) && info.user.equals(user);
}