Only clear widgets list upon all widgets & shortcuts update

Test: Install BBC News. Then, quickly go to all widgets tray.
      BBC News widgets is added to the all widgets tray without
      removing other widgets.

Bug: 182897740
Change-Id: I17b50f5128e24c346354b8fb7817a318a94efb62
This commit is contained in:
Steven Ng 2021-03-16 19:30:04 +00:00
parent a79c7e4227
commit 1a4670eeff
1 changed files with 8 additions and 4 deletions

View File

@ -132,7 +132,7 @@ public class WidgetsModel {
widgetsAndShortcuts.add(new WidgetItem(info, app.getIconCache(), pm));
updatedItems.add(info);
}
setWidgetsAndShortcuts(widgetsAndShortcuts, app);
setWidgetsAndShortcuts(widgetsAndShortcuts, app, packageUser);
} catch (Exception e) {
if (!FeatureFlags.IS_STUDIO_BUILD && Utilities.isBinderSizeError(e)) {
// the returned value may be incomplete and will not be refreshed until the next
@ -149,7 +149,7 @@ public class WidgetsModel {
}
private synchronized void setWidgetsAndShortcuts(ArrayList<WidgetItem> rawWidgetsShortcuts,
LauncherAppState app) {
LauncherAppState app, @Nullable PackageUserKey packageUser) {
if (DEBUG) {
Log.d(TAG, "addWidgetsAndShortcuts, widgetsShortcuts#=" + rawWidgetsShortcuts.size());
}
@ -158,8 +158,12 @@ public class WidgetsModel {
// {@link mPackageItemInfos} to locate the key to be used for {@link #mWidgetsList}
HashMap<PackageUserKey, PackageItemInfo> tmpPackageItemInfos = new HashMap<>();
// clear the lists.
mWidgetsList.clear();
// Clear the lists only if this is an update on all widgets and shortcuts. If packageUser
// isn't null, only updates the shortcuts and widgets for the app represented in
// packageUser.
if (packageUser == null) {
mWidgetsList.clear();
}
// add and update.
mWidgetsList.putAll(rawWidgetsShortcuts.stream()
.filter(new WidgetValidityCheck(app))