summaryrefslogtreecommitdiffstats
path: root/src/com/android/launcher3/model/WidgetsModel.java
diff options
context:
space:
mode:
authorSunny Goyal <sunnygoyal@google.com>2017-06-02 13:46:55 -0700
committerSunny Goyal <sunnygoyal@google.com>2017-06-02 14:27:29 -0700
commitc6e97692e4144a6fc33eb74fabb73b1aae9ff908 (patch)
tree4eeec70c61cab02f800b0693ed53be237240bf1e /src/com/android/launcher3/model/WidgetsModel.java
parentccb25a3da88a0e68039f8fa15c9709b181f4e2e8 (diff)
downloadandroid_packages_apps_Trebuchet-c6e97692e4144a6fc33eb74fabb73b1aae9ff908.tar.gz
android_packages_apps_Trebuchet-c6e97692e4144a6fc33eb74fabb73b1aae9ff908.tar.bz2
android_packages_apps_Trebuchet-c6e97692e4144a6fc33eb74fabb73b1aae9ff908.zip
Moving LoaderTask static
Will move it to a separate file in a followup cl. This simplifies dependencies between LauncherModel and LoaderTask which and making it easier to start the loader before Launcher activity is created (as the Callbacks in LauncherModel can change while loader is running). Bug: 34112546 Bug: 37616877 Change-Id: Ie9619c6b0de0e3eb60657c04ae1b58d946c829e9
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