summaryrefslogtreecommitdiffstats
path: root/src/com/android/launcher3/model/WidgetsModel.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/com/android/launcher3/model/WidgetsModel.java')
-rw-r--r--src/com/android/launcher3/model/WidgetsModel.java41
1 files changed, 18 insertions, 23 deletions
diff --git a/src/com/android/launcher3/model/WidgetsModel.java b/src/com/android/launcher3/model/WidgetsModel.java
index 827675a83..ed900bf35 100644
--- a/src/com/android/launcher3/model/WidgetsModel.java
+++ b/src/com/android/launcher3/model/WidgetsModel.java
@@ -38,36 +38,26 @@ public class WidgetsModel {
private static final boolean DEBUG = false;
/* Map of widgets and shortcuts that are tracked per package. */
- private final MultiHashMap<PackageItemInfo, WidgetItem> mWidgetsList;
+ private final MultiHashMap<PackageItemInfo, WidgetItem> mWidgetsList = new MultiHashMap<>();
- private final IconCache mIconCache;
- private final AppFilter mAppFilter;
+ private AppFilter mAppFilter;
- public WidgetsModel(IconCache iconCache, AppFilter appFilter) {
- mIconCache = iconCache;
- mAppFilter = appFilter;
- mWidgetsList = new MultiHashMap<>();
- }
-
- public MultiHashMap<PackageItemInfo, WidgetItem> getWidgetsMap() {
- return mWidgetsList;
- }
-
- public boolean isEmpty() {
- return mWidgetsList.isEmpty();
+ public synchronized MultiHashMap<PackageItemInfo, WidgetItem> getWidgetsMap() {
+ return mWidgetsList.clone();
}
/**
* @param packageUser If null, all widgets and shortcuts are updated and returned, otherwise
* only widgets and shortcuts associated with the package/user are.
*/
- public ArrayList<WidgetItem> update(Context context, @Nullable PackageUserKey packageUser) {
+ public void update(LauncherAppState app, @Nullable PackageUserKey packageUser) {
Preconditions.assertWorkerThread();
+ Context context = app.getContext();
final ArrayList<WidgetItem> widgetsAndShortcuts = new ArrayList<>();
try {
PackageManager pm = context.getPackageManager();
- InvariantDeviceProfile idp = LauncherAppState.getIDP(context);
+ InvariantDeviceProfile idp = app.getInvariantDeviceProfile();
// Widgets
AppWidgetManagerCompat widgetManager = AppWidgetManagerCompat.getInstance(context);
@@ -81,7 +71,7 @@ public class WidgetsModel {
.getCustomShortcutActivityList(packageUser)) {
widgetsAndShortcuts.add(new WidgetItem(info));
}
- setWidgetsAndShortcuts(widgetsAndShortcuts, context, packageUser);
+ setWidgetsAndShortcuts(widgetsAndShortcuts, app, packageUser);
} catch (Exception e) {
if (!FeatureFlags.IS_DOGFOOD_BUILD && Utilities.isBinderSizeError(e)) {
// the returned value may be incomplete and will not be refreshed until the next
@@ -92,11 +82,12 @@ public class WidgetsModel {
throw e;
}
}
- return widgetsAndShortcuts;
+
+ app.getWidgetCache().removeObsoletePreviews(widgetsAndShortcuts, packageUser);
}
- private void setWidgetsAndShortcuts(ArrayList<WidgetItem> rawWidgetsShortcuts,
- Context context, @Nullable PackageUserKey packageUser) {
+ private synchronized void setWidgetsAndShortcuts(ArrayList<WidgetItem> rawWidgetsShortcuts,
+ LauncherAppState app, @Nullable PackageUserKey packageUser) {
if (DEBUG) {
Log.d(TAG, "addWidgetsAndShortcuts, widgetsShortcuts#=" + rawWidgetsShortcuts.size());
}
@@ -133,7 +124,7 @@ public class WidgetsModel {
}
}
- InvariantDeviceProfile idp = LauncherAppState.getIDP(context);
+ InvariantDeviceProfile idp = app.getInvariantDeviceProfile();
UserHandle myUser = Process.myUserHandle();
// add and update.
@@ -152,6 +143,9 @@ public class WidgetsModel {
}
}
+ if (mAppFilter == null) {
+ mAppFilter = AppFilter.newInstance(app.getContext());
+ }
if (!mAppFilter.shouldShowApp(item.componentName)) {
if (DEBUG) {
Log.d(TAG, String.format("%s is filtered and not added to the widget tray.",
@@ -174,8 +168,9 @@ public class WidgetsModel {
}
// Update each package entry
+ IconCache iconCache = app.getIconCache();
for (PackageItemInfo p : tmpPackageItemInfos.values()) {
- mIconCache.getTitleAndIconForApp(p, true /* userLowResIcon */);
+ iconCache.getTitleAndIconForApp(p, true /* userLowResIcon */);
}
}
} \ No newline at end of file