Ensure widgets from WidgetSections.xml are included in suggestions

Additionally, let only prediction system provide suggestions, since the
UI surface has been there for a while, adding locally filtered widgets
from app package isn't required.

Bug: 345520128
Test: Unit tests
Flag: EXEMPT bugfix
Change-Id: Ia97f0743fefeae750e07a694bb19d24a5cc11ffe
This commit is contained in:
Shamali P authored and Shamali Patwa committed 2024-06-06 22:23:35 +00:00
1 parent f2a232acc5
commit d69e21f8fe
3 files changed
+29 -31

No files matched your search

@@ -19,6 +19,7 @@ import static com.android.launcher3.Flags.enableCategorizedWidgetSuggestions;
import static com.android.launcher3.LauncherSettings.Favorites.CONTAINER_WIDGETS_PREDICTION;
import android.app.prediction.AppTarget;
import android.content.ComponentName;
import android.content.Context;
import android.text.TextUtils;
@@ -29,7 +30,6 @@ import com.android.launcher3.model.BgDataModel.FixedContainerItems;
import com.android.launcher3.model.QuickstepModelDelegate.PredictorState;
import com.android.launcher3.model.data.ItemInfo;
import com.android.launcher3.util.ComponentKey;
import com.android.launcher3.util.PackageUserKey;
import com.android.launcher3.widget.PendingAddWidgetInfo;
import com.android.launcher3.widget.picker.WidgetRecommendationCategoryProvider;
@@ -64,36 +64,24 @@ public final class WidgetsPredictionUpdateTask implements ModelUpdateTask {
widget -> new ComponentKey(widget.providerName, widget.user)).collect(
Collectors.toSet());
Predicate<WidgetItem> notOnWorkspace = w -> !widgetsInWorkspace.contains(w);
Map<PackageUserKey, List<WidgetItem>> allWidgets =
dataModel.widgetsModel.getAllWidgetsWithoutShortcuts();
Map<ComponentKey, WidgetItem> allWidgets =
dataModel.widgetsModel.getAllWidgetComponentsWithoutShortcuts();
List<WidgetItem> servicePredictedItems = new ArrayList<>();
List<WidgetItem> localFilteredWidgets = new ArrayList<>();
for (AppTarget app : mTargets) {
PackageUserKey packageUserKey = new PackageUserKey(app.getPackageName(), app.getUser());
List<WidgetItem> widgets = allWidgets.get(packageUserKey);
if (widgets == null || widgets.isEmpty()) {
ComponentKey componentKey = new ComponentKey(
new ComponentName(app.getPackageName(), app.getClassName()), app.getUser());
WidgetItem widget = allWidgets.get(componentKey);
if (widget == null) {
continue;
}
String className = app.getClassName();
if (!TextUtils.isEmpty(className)) {
WidgetItem item = widgets.stream()
.filter(w -> className.equals(w.componentName.getClassName()))
.filter(notOnWorkspace)
.findFirst()
.orElse(null);
if (item != null) {
servicePredictedItems.add(item);
continue;
if (notOnWorkspace.test(widget)) {
servicePredictedItems.add(widget);
}
}
// No widget was added by the service, try local filtering
widgets.stream().filter(notOnWorkspace).findFirst()
.ifPresent(localFilteredWidgets::add);
}
if (servicePredictedItems.isEmpty()) {
servicePredictedItems.addAll(localFilteredWidgets);
}
List<ItemInfo> items;