summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSunny Goyal <sunnygoyal@google.com>2014-10-13 18:33:11 (GMT)
committerDanesh M <daneshm90@gmail.com>2015-09-27 22:50:03 (GMT)
commit3637cce5b38f166b6b144bf90cb69b354ab06706 (patch)
tree8565d782c20344d9c43c36f1ab37752876884fe4
parentb5f2e0aab7ba3a3e9eb129820b162ba03974ef7f (diff)
downloadandroid_packages_apps_Trebuchet-3637cce5b38f166b6b144bf90cb69b354ab06706.zip
android_packages_apps_Trebuchet-3637cce5b38f166b6b144bf90cb69b354ab06706.tar.gz
android_packages_apps_Trebuchet-3637cce5b38f166b6b144bf90cb69b354ab06706.tar.bz2
Updating ItemInfo objects in the worker thread
> Launcher was making non-trivial updates to ItemInfo objects on UI thread. These updates were getting skipped when the Activity gets destroyed (possibly due to onConfigurationChange) > Unregistering SessionCallback on application onTerminate, rather than activity onDestroy Bug: 17941096 Change-Id: Iad4a50871fe09470f26139b44a2e9886833032f1
-rw-r--r--src/com/android/launcher3/DragController.java17
-rw-r--r--src/com/android/launcher3/Launcher.java53
-rw-r--r--src/com/android/launcher3/LauncherAppState.java2
-rw-r--r--src/com/android/launcher3/LauncherModel.java211
-rw-r--r--src/com/android/launcher3/Workspace.java193
5 files changed, 195 insertions, 281 deletions
diff --git a/src/com/android/launcher3/DragController.java b/src/com/android/launcher3/DragController.java
index 6d0a2be..480dce9 100644
--- a/src/com/android/launcher3/DragController.java
+++ b/src/com/android/launcher3/DragController.java
@@ -26,10 +26,16 @@ import android.graphics.Rect;
import android.os.Handler;
import android.os.IBinder;
import android.util.Log;
-import android.view.*;
+import android.view.HapticFeedbackConstants;
+import android.view.KeyEvent;
+import android.view.MotionEvent;
+import android.view.VelocityTracker;
+import android.view.View;
+import android.view.ViewConfiguration;
import android.view.inputmethod.InputMethodManager;
import java.util.ArrayList;
+import java.util.HashSet;
/**
* Class for initiating a drag within a view or across multiple views.
@@ -318,18 +324,17 @@ public class DragController {
}
endDrag();
}
- public void onAppsRemoved(final ArrayList<String> packageNames, ArrayList<AppInfo> appInfos) {
+ public void onAppsRemoved(final ArrayList<String> packageNames, HashSet<ComponentName> cns) {
// Cancel the current drag if we are removing an app that we are dragging
if (mDragObject != null) {
Object rawDragInfo = mDragObject.dragInfo;
if (rawDragInfo instanceof ShortcutInfo) {
ShortcutInfo dragInfo = (ShortcutInfo) rawDragInfo;
- for (AppInfo info : appInfos) {
+ for (ComponentName componentName : cns) {
// Added null checks to prevent NPE we've seen in the wild
- if (dragInfo != null &&
- dragInfo.intent != null && info != null) {
+ if (dragInfo != null && dragInfo.intent != null) {
ComponentName cn = dragInfo.intent.getComponent();
- boolean isSameComponent = cn != null && (cn.equals(info.componentName) ||
+ boolean isSameComponent = cn != null && (cn.equals(componentName) ||
packageNames.contains(cn.getPackageName()));
if (isSameComponent) {
cancelDrag();
diff --git a/src/com/android/launcher3/Launcher.java b/src/com/android/launcher3/Launcher.java
index 5236ede..2af40c4 100644
--- a/src/com/android/launcher3/Launcher.java
+++ b/src/com/android/launcher3/Launcher.java
@@ -143,6 +143,7 @@ import java.util.ArrayList;
import java.util.Collection;
import java.util.Date;
import java.util.HashMap;
+import java.util.HashSet;
import java.util.List;
import java.util.concurrent.atomic.AtomicInteger;
@@ -2417,7 +2418,6 @@ public class Launcher extends Activity
mWorkspace = null;
mDragController = null;
- PackageInstallerCompat.getInstance(this).onStop();
LauncherAnimUtils.onDestroyActivity();
if (mLauncherCallbacks != null) {
@@ -5579,10 +5579,6 @@ public class Launcher extends Activity
return;
}
- if (mWorkspace != null) {
- mWorkspace.updateShortcutsAndWidgets(apps);
- }
-
if (!LauncherAppState.isDisableAllApps() &&
mAppsCustomizeContent != null) {
mAppsCustomizeContent.updateApps(apps);
@@ -5602,10 +5598,19 @@ public class Launcher extends Activity
if (waitUntilResume(r)) {
return;
}
+ }
- if (mWorkspace != null) {
- mWorkspace.updateShortcutsAndWidgets(apps);
+ @Override
+ public void bindWidgetsRestored(final ArrayList<LauncherAppWidgetInfo> widgets) {
+ Runnable r = new Runnable() {
+ public void run() {
+ bindWidgetsRestored(widgets);
+ }
+ };
+ if (waitUntilResume(r)) {
+ return;
}
+ mWorkspace.widgetsRestored(widgets);
}
/**
@@ -5613,18 +5618,30 @@ public class Launcher extends Activity
*
* Implementation of the method from LauncherModel.Callbacks.
*/
- public void bindShortcutsUpdated(final ArrayList<ShortcutInfo> shortcuts) {
+ @Override
+ public void bindShortcutsChanged(final ArrayList<ShortcutInfo> updated,
+ final ArrayList<ShortcutInfo> removed, final UserHandleCompat user) {
Runnable r = new Runnable() {
public void run() {
- bindShortcutsUpdated(shortcuts);
+ bindShortcutsChanged(updated, removed, user);
}
};
if (waitUntilResume(r)) {
return;
}
- if (mWorkspace != null) {
- mWorkspace.updateShortcuts(shortcuts);
+ if (!updated.isEmpty()) {
+ mWorkspace.updateShortcuts(updated);
+ }
+
+ if (!removed.isEmpty()) {
+ HashSet<ComponentName> removedComponents = new HashSet<ComponentName>();
+ for (ShortcutInfo si : removed) {
+ removedComponents.add(si.getTargetComponent());
+ }
+ mWorkspace.removeItemsByComponentName(removedComponents, user);
+ // Notify the drag controller
+ mDragController.onAppsRemoved(new ArrayList<String>(), removedComponents);
}
}
@@ -5675,19 +5692,23 @@ public class Launcher extends Activity
}
if (reason == 0) {
+ HashSet<ComponentName> removedComponents = new HashSet<ComponentName>();
+ for (AppInfo info : appInfos) {
+ removedComponents.add(info.componentName);
+ }
if (!packageNames.isEmpty()) {
mWorkspace.removeItemsByPackageName(packageNames, user);
}
- if (!appInfos.isEmpty()) {
- mWorkspace.removeItemsByApplicationInfo(appInfos, user);
+ if (!removedComponents.isEmpty()) {
+ mWorkspace.removeItemsByComponentName(removedComponents, user);
}
+ // Notify the drag controller
+ mDragController.onAppsRemoved(packageNames, removedComponents);
+
} else {
mWorkspace.disableShortcutsByPackageName(packageNames, user, reason);
}
- // Notify the drag controller
- mDragController.onAppsRemoved(packageNames, appInfos);
-
// Update AllApps
if (!LauncherAppState.isDisableAllApps() &&
mAppsCustomizeContent != null) {
diff --git a/src/com/android/launcher3/LauncherAppState.java b/src/com/android/launcher3/LauncherAppState.java
index 67a5bc3..82e64e1 100644
--- a/src/com/android/launcher3/LauncherAppState.java
+++ b/src/com/android/launcher3/LauncherAppState.java
@@ -29,6 +29,7 @@ import android.os.Handler;
import android.util.Log;
import com.android.launcher3.compat.LauncherAppsCompat;
+import com.android.launcher3.compat.PackageInstallerCompat;
import com.android.launcher3.compat.PackageInstallerCompat.PackageInstallInfo;
import java.lang.ref.WeakReference;
@@ -134,6 +135,7 @@ public class LauncherAppState implements DeviceProfile.DeviceProfileCallbacks {
sContext.unregisterReceiver(mModel);
final LauncherAppsCompat launcherApps = LauncherAppsCompat.getInstance(sContext);
launcherApps.removeOnAppsChangedCallback(mModel);
+ PackageInstallerCompat.getInstance(sContext).onStop();
ContentResolver resolver = sContext.getContentResolver();
resolver.unregisterContentObserver(mFavoritesObserver);
diff --git a/src/com/android/launcher3/LauncherModel.java b/src/com/android/launcher3/LauncherModel.java
index 2d44909..fe1399b 100644
--- a/src/com/android/launcher3/LauncherModel.java
+++ b/src/com/android/launcher3/LauncherModel.java
@@ -205,9 +205,11 @@ public class LauncherModel extends BroadcastReceiver
ArrayList<ItemInfo> addNotAnimated,
ArrayList<ItemInfo> addAnimated,
ArrayList<AppInfo> addedApps);
- public void bindAppsUpdated(ArrayList<AppInfo> apps);
public void bindAppsRestored(ArrayList<AppInfo> apps);
- public void bindShortcutsUpdated(ArrayList<ShortcutInfo> shortcuts);
+ public void bindAppsUpdated(ArrayList<AppInfo> apps);
+ public void bindShortcutsChanged(ArrayList<ShortcutInfo> updated,
+ ArrayList<ShortcutInfo> removed, UserHandleCompat user);
+ public void bindWidgetsRestored(ArrayList<LauncherAppWidgetInfo> widgets);
public void updatePackageState(ArrayList<PackageInstallInfo> installInfo);
public void updatePackageBadge(String packageName);
public void bindComponentsRemoved(ArrayList<String> packageNames,
@@ -433,15 +435,6 @@ public class LauncherModel extends BroadcastReceiver
return;
}
- final ArrayList<AppInfo> restoredAppsFinal = new ArrayList<AppInfo>();
- Iterator<AppInfo> iter = allAppsApps.iterator();
- while (iter.hasNext()) {
- ItemInfo a = iter.next();
- if (LauncherModel.appWasPromise(ctx, a.getIntent(), a.user)) {
- restoredAppsFinal.add((AppInfo) a);
- }
- }
-
// Process the newly added applications and add them to the database first
Runnable r = new Runnable() {
public void run() {
@@ -449,16 +442,6 @@ public class LauncherModel extends BroadcastReceiver
public void run() {
Callbacks cb = mCallbacks != null ? mCallbacks.get() : null;
if (callbacks == cb && cb != null) {
- if (!restoredAppsFinal.isEmpty()) {
- for (AppInfo info : restoredAppsFinal) {
- final Intent intent = info.getIntent();
- if (intent != null) {
- mIconCache.deletePreloadedIcon(intent.getComponent(),
- info.user);
- }
- }
- callbacks.bindAppsUpdated(restoredAppsFinal);
- }
callbacks.bindAppsAdded(null, null, null, allAppsApps);
}
}
@@ -483,7 +466,6 @@ public class LauncherModel extends BroadcastReceiver
public void run() {
final ArrayList<ItemInfo> addedShortcutsFinal = new ArrayList<ItemInfo>();
final ArrayList<Long> addedWorkspaceScreensFinal = new ArrayList<Long>();
- final ArrayList<AppInfo> restoredAppsFinal = new ArrayList<AppInfo>();
// Get the list of workspace screens. We need to append to this list and
// can not use sBgWorkspaceScreens because loadWorkspace() may not have been
@@ -503,12 +485,7 @@ public class LauncherModel extends BroadcastReceiver
final Intent launchIntent = a.getIntent();
// Short-circuit this logic if the icon exists somewhere on the workspace
- if (LauncherModel.shortcutExists(context, name, launchIntent)) {
- // Only InstallShortcutReceiver sends us shortcutInfos, ignore them
- if (a instanceof AppInfo &&
- LauncherModel.appWasPromise(context, launchIntent, a.user)) {
- restoredAppsFinal.add((AppInfo) a);
- }
+ if (shortcutExists(context, name, launchIntent)) {
continue;
}
@@ -584,9 +561,6 @@ public class LauncherModel extends BroadcastReceiver
}
callbacks.bindAppsAdded(addedWorkspaceScreensFinal,
addNotAnimated, addAnimated, null);
- if (!restoredAppsFinal.isEmpty()) {
- callbacks.bindAppsUpdated(restoredAppsFinal);
- }
}
}
});
@@ -950,8 +924,8 @@ public class LauncherModel extends BroadcastReceiver
intentWithoutPkg = intent;
}
Cursor c = cr.query(LauncherSettings.Favorites.CONTENT_URI,
- new String[] { "title", "intent" }, "title=? and (intent=? or intent=?)",
- new String[] { title, intentWithPkg.toUri(0), intentWithoutPkg.toUri(0) }, null);
+ new String[]{"title", "intent"}, "title=? and (intent=? or intent=?)",
+ new String[]{title, intentWithPkg.toUri(0), intentWithoutPkg.toUri(0) }, null);
boolean result = false;
try {
result = c.moveToFirst();
@@ -962,17 +936,6 @@ public class LauncherModel extends BroadcastReceiver
}
/**
- * Returns true if the promise shortcuts with the same package name exists on the workspace.
- */
- static boolean appWasPromise(Context context, Intent intent, UserHandleCompat user) {
- final ComponentName component = intent.getComponent();
- if (component == null) {
- return false;
- }
- return !getItemsByPackageName(component.getPackageName(), user).isEmpty();
- }
-
- /**
* Returns an ItemInfo array containing all the items in the LauncherModel.
* The ItemInfo.id is not set through this function.
*/
@@ -1028,7 +991,7 @@ public class LauncherModel extends BroadcastReceiver
final ContentResolver cr = context.getContentResolver();
Cursor c = cr.query(LauncherSettings.Favorites.CONTENT_URI, null,
"_id=? and (itemType=? or itemType=?)",
- new String[] { String.valueOf(id),
+ new String[]{String.valueOf(id),
String.valueOf(LauncherSettings.Favorites.ITEM_TYPE_FOLDER)}, null);
try {
@@ -1186,7 +1149,7 @@ public class LauncherModel extends BroadcastReceiver
* @param context
* @param item
*/
- static void deleteItemsFromDatabase(final Context context, final ArrayList<ItemInfo> items) {
+ static void deleteItemsFromDatabase(final Context context, final ArrayList<? extends ItemInfo> items) {
final ContentResolver cr = context.getContentResolver();
Runnable r = new Runnable() {
@@ -3446,6 +3409,9 @@ public class LauncherModel extends BroadcastReceiver
return;
}
+ final HashMap<ComponentName, AppInfo> addedOrUpdatedApps =
+ new HashMap<ComponentName, AppInfo>();
+
if (added != null) {
// Ensure that we add all the workspace applications to the db
if (LauncherAppState.isDisableAllApps()) {
@@ -3454,23 +3420,15 @@ public class LauncherModel extends BroadcastReceiver
} else {
addAppsToAllApps(context, added);
}
+ for (AppInfo ai : added) {
+ addedOrUpdatedApps.put(ai.componentName, ai);
+ }
}
if (modified != null) {
final ArrayList<AppInfo> modifiedFinal = modified;
-
- // Update the launcher db to reflect the changes
- for (AppInfo a : modifiedFinal) {
- ArrayList<ItemInfo> infos =
- getItemInfoForComponentName(a.componentName, mUser);
- for (ItemInfo i : infos) {
- if (i instanceof ShortcutInfo && isShortcutAppTarget((ShortcutInfo) i)) {
- ShortcutInfo info = (ShortcutInfo) i;
- info.title = a.title.toString();
- info.contentDescription = a.contentDescription;
- updateItemInDatabase(context, info);
- }
- }
+ for (AppInfo ai : modified) {
+ addedOrUpdatedApps.put(ai.componentName, ai);
}
mHandler.post(new Runnable() {
@@ -3483,37 +3441,128 @@ public class LauncherModel extends BroadcastReceiver
});
}
- // Update shortcuts which use an iconResource
+ // Update shortcut infos
if (mOp == OP_ADD || mOp == OP_UPDATE) {
- final ArrayList<ShortcutInfo> iconsChanged = new ArrayList<ShortcutInfo>();
+ final ArrayList<ShortcutInfo> updatedShortcuts = new ArrayList<ShortcutInfo>();
+ final ArrayList<ShortcutInfo> removedShortcuts = new ArrayList<ShortcutInfo>();
+ final ArrayList<LauncherAppWidgetInfo> widgets = new ArrayList<LauncherAppWidgetInfo>();
+
HashSet<String> packageSet = new HashSet<String>(Arrays.asList(packages));
- // We need to iterate over the items here, so that we can avoid new Bitmap
- // creation on the UI thread.
synchronized (sBgLock) {
- for (ItemInfo info : sBgWorkspaceItems) {
+ for (ItemInfo info : sBgItemsIdMap.values()) {
if (info instanceof ShortcutInfo && mUser.equals(info.user)) {
ShortcutInfo si = (ShortcutInfo) info;
+ boolean infoUpdated = false;
+ boolean shortcutUpdated = false;
+
+ // Update shortcuts which use iconResource.
if ((si.iconResource != null)
- && packageSet.contains(si.getTargetComponent().getPackageName())){
+ && packageSet.contains(si.iconResource.packageName)) {
Bitmap icon = Utilities.createIconBitmap(si.iconResource.packageName,
si.iconResource.resourceName, mIconCache, context);
if (icon != null) {
si.setIcon(icon);
si.usingFallbackIcon = false;
- iconsChanged.add(si);
- updateItemInDatabase(context, si);
+ infoUpdated = true;
+ }
+ }
+
+ ComponentName cn = si.getTargetComponent();
+ if (cn != null && packageSet.contains(cn.getPackageName())) {
+ AppInfo appInfo = addedOrUpdatedApps.get(cn);
+
+ if (si.isPromise()) {
+ mIconCache.deletePreloadedIcon(cn, mUser);
+ if (si.hasStatusFlag(ShortcutInfo.FLAG_AUTOINTALL_ICON)) {
+ // Auto install icon
+ PackageManager pm = context.getPackageManager();
+ ResolveInfo matched = pm.resolveActivity(
+ new Intent(Intent.ACTION_MAIN)
+ .setComponent(cn).addCategory(Intent.CATEGORY_LAUNCHER),
+ PackageManager.MATCH_DEFAULT_ONLY);
+ if (matched == null) {
+ // Try to find the best match activity.
+ Intent intent = pm.getLaunchIntentForPackage(
+ cn.getPackageName());
+ if (intent != null) {
+ cn = intent.getComponent();
+ appInfo = addedOrUpdatedApps.get(cn);
+ }
+
+ if ((intent == null) || (appInfo == null)) {
+ removedShortcuts.add(si);
+ continue;
+ }
+ si.promisedIntent = intent;
+ }
+ }
+
+ // Restore the shortcut.
+ si.intent = si.promisedIntent;
+ si.promisedIntent = null;
+ si.status &= ~ShortcutInfo.FLAG_RESTORED_ICON
+ & ~ShortcutInfo.FLAG_AUTOINTALL_ICON
+ & ~ShortcutInfo.FLAG_INSTALL_SESSION_ACTIVE;
+
+ infoUpdated = true;
+ si.updateIcon(mIconCache);
}
+
+ if (appInfo != null && Intent.ACTION_MAIN.equals(si.intent.getAction())
+ && si.itemType == LauncherSettings.Favorites.ITEM_TYPE_APPLICATION) {
+ si.updateIcon(mIconCache);
+ si.title = appInfo.title.toString();
+ si.contentDescription = appInfo.contentDescription;
+ infoUpdated = true;
+ }
+
+ if ((si.isDisabled & ShortcutInfo.FLAG_DISABLED_NOT_AVAILABLE) != 0) {
+ // Since package was just updated, the target must be available now.
+ si.isDisabled &= ~ShortcutInfo.FLAG_DISABLED_NOT_AVAILABLE;
+ shortcutUpdated = true;
+ }
+ }
+
+ if (infoUpdated || shortcutUpdated) {
+ updatedShortcuts.add(si);
+ }
+ if (infoUpdated) {
+ updateItemInDatabase(context, si);
+ }
+ } else if (info instanceof LauncherAppWidgetInfo) {
+ LauncherAppWidgetInfo widgetInfo = (LauncherAppWidgetInfo) info;
+ if (mUser.equals(widgetInfo.user)
+ && widgetInfo.hasRestoreFlag(LauncherAppWidgetInfo.FLAG_PROVIDER_NOT_READY)
+ && packageSet.contains(widgetInfo.providerName.getPackageName())) {
+ widgetInfo.restoreStatus &= ~LauncherAppWidgetInfo.FLAG_PROVIDER_NOT_READY;
+ widgets.add(widgetInfo);
+ updateItemInDatabase(context, widgetInfo);
}
}
}
}
- if (!iconsChanged.isEmpty()) {
+ if (!updatedShortcuts.isEmpty() || !removedShortcuts.isEmpty()) {
mHandler.post(new Runnable() {
+
public void run() {
Callbacks cb = mCallbacks != null ? mCallbacks.get() : null;
if (callbacks == cb && cb != null) {
- callbacks.bindShortcutsUpdated(iconsChanged);
+ callbacks.bindShortcutsChanged(
+ updatedShortcuts, removedShortcuts, mUser);
+ }
+ }
+ });
+ if (!removedShortcuts.isEmpty()) {
+ deleteItemsFromDatabase(context, removedShortcuts);
+ }
+ }
+ if (!widgets.isEmpty()) {
+ mHandler.post(new Runnable() {
+ public void run() {
+ Callbacks cb = mCallbacks != null ? mCallbacks.get() : null;
+ if (callbacks == cb && cb != null) {
+ callbacks.bindWidgetsRestored(widgets);
}
}
});
@@ -3674,11 +3723,11 @@ public class LauncherModel extends BroadcastReceiver
static Intent getMarketIntent(String packageName) {
return new Intent(Intent.ACTION_VIEW)
- .setData(new Uri.Builder()
- .scheme("market")
- .authority("details")
- .appendQueryParameter("id", packageName)
- .build());
+ .setData(new Uri.Builder()
+ .scheme("market")
+ .authority("details")
+ .appendQueryParameter("id", packageName)
+ .build());
}
/**
@@ -3813,20 +3862,6 @@ public class LauncherModel extends BroadcastReceiver
}
/**
- * @return true if the ShortcutInfo points to an app shortcut target, i.e. it has been added by
- * dragging from AllApps list.
- */
- public static boolean isShortcutAppTarget(ShortcutInfo info) {
- // We need to check for ACTION_MAIN otherwise getComponent() might
- // return null for some shortcuts (for instance, for shortcuts to
- // web pages.)
- Intent intent = info.promisedIntent != null ? info.promisedIntent : info.intent;
- ComponentName name = intent.getComponent();
- return info.itemType == LauncherSettings.Favorites.ITEM_TYPE_APPLICATION &&
- Intent.ACTION_MAIN.equals(intent.getAction()) && name != null;
- }
-
- /**
* Make an ShortcutInfo object for a shortcut that isn't an application.
*/
private ShortcutInfo getShortcutInfo(Cursor c, Context context,
diff --git a/src/com/android/launcher3/Workspace.java b/src/com/android/launcher3/Workspace.java
index db997db..6020017 100644
--- a/src/com/android/launcher3/Workspace.java
+++ b/src/com/android/launcher3/Workspace.java
@@ -4896,20 +4896,11 @@ public class Workspace extends SmoothPagedView
removeItemsByComponentName(cns, user);
}
- // Removes items that match the application info specified, when applications are removed
- // as a part of an update, this is called to ensure that other widgets and application
- // shortcuts are not removed.
- void removeItemsByApplicationInfo(final ArrayList<AppInfo> appInfos, UserHandleCompat user) {
- // Just create a hash table of all the specific components that this will affect
- HashSet<ComponentName> cns = new HashSet<ComponentName>();
- for (AppInfo info : appInfos) {
- cns.add(info.componentName);
- }
-
- // Remove all the things
- removeItemsByComponentName(cns, user);
- }
-
+ /**
+ * Removes items that match the item info specified. When applications are removed
+ * as a part of an update, this is called to ensure that other widgets and application
+ * shortcuts are not removed.
+ */
void removeItemsByComponentName(final HashSet<ComponentName> componentNames,
final UserHandleCompat user) {
ArrayList<CellLayout> cellLayouts = getWorkspaceAndHotseatCellLayouts();
@@ -5030,7 +5021,6 @@ public class Workspace extends SmoothPagedView
}
}
-
void updateShortcuts(ArrayList<ShortcutInfo> shortcuts) {
final HashSet<ShortcutInfo> updates = new HashSet<ShortcutInfo>(shortcuts);
mapOverItems(MAP_RECURSE, new ItemOperator() {
@@ -5038,9 +5028,12 @@ public class Workspace extends SmoothPagedView
public boolean evaluate(ItemInfo info, View v, View parent) {
if (info instanceof ShortcutInfo && v instanceof BubbleTextView &&
updates.contains(info)) {
- ShortcutInfo shortcutInfo = (ShortcutInfo) info;
+ ShortcutInfo si = (ShortcutInfo) info;
BubbleTextView shortcut = (BubbleTextView) v;
- shortcut.applyFromShortcutInfo(shortcutInfo, mIconCache, true, false);
+ boolean oldPromiseState = shortcut.getCompoundDrawables()[1]
+ instanceof PreloadIconDrawable;
+ shortcut.applyFromShortcutInfo(si, mIconCache, true,
+ si.isPromise() != oldPromiseState);
if (parent != null) {
parent.invalidate();
@@ -5052,125 +5045,6 @@ public class Workspace extends SmoothPagedView
});
}
- void updateShortcutsAndWidgets(ArrayList<AppInfo> apps) {
- // Break the appinfo list per user
- final HashMap<UserHandleCompat, ArrayList<AppInfo>> appsPerUser =
- new HashMap<UserHandleCompat, ArrayList<AppInfo>>();
- for (AppInfo info : apps) {
- ArrayList<AppInfo> filtered = appsPerUser.get(info.user);
- if (filtered == null) {
- filtered = new ArrayList<AppInfo>();
- appsPerUser.put(info.user, filtered);
- }
- filtered.add(info);
- }
-
- for (Map.Entry<UserHandleCompat, ArrayList<AppInfo>> entry : appsPerUser.entrySet()) {
- updateShortcutsAndWidgetsPerUser(entry.getValue(), entry.getKey());
- }
- }
-
- private void updateShortcutsAndWidgetsPerUser(ArrayList<AppInfo> apps,
- final UserHandleCompat user) {
- // Create a map of the apps to test against
- final HashMap<ComponentName, AppInfo> appsMap = new HashMap<ComponentName, AppInfo>();
- final HashSet<String> pkgNames = new HashSet<String>();
- for (AppInfo ai : apps) {
- appsMap.put(ai.componentName, ai);
- pkgNames.add(ai.componentName.getPackageName());
- }
- final HashSet<ComponentName> iconsToRemove = new HashSet<ComponentName>();
-
- mapOverItems(MAP_RECURSE, new ItemOperator() {
- @Override
- public boolean evaluate(ItemInfo info, View v, View parent) {
- if (info instanceof ShortcutInfo && v instanceof BubbleTextView) {
- ShortcutInfo shortcutInfo = (ShortcutInfo) info;
- ComponentName cn = shortcutInfo.getTargetComponent();
- AppInfo appInfo = appsMap.get(cn);
- if (user.equals(shortcutInfo.user) && cn != null
- && pkgNames.contains(cn.getPackageName())) {
- boolean promiseStateChanged = false;
- boolean infoUpdated = false;
- if (shortcutInfo.isPromise()) {
- if (shortcutInfo.hasStatusFlag(ShortcutInfo.FLAG_AUTOINTALL_ICON)) {
- // Auto install icon
- PackageManager pm = getContext().getPackageManager();
- ResolveInfo matched = pm.resolveActivity(
- new Intent(Intent.ACTION_MAIN)
- .setComponent(cn).addCategory(Intent.CATEGORY_LAUNCHER),
- PackageManager.MATCH_DEFAULT_ONLY);
- if (matched == null) {
- // Try to find the best match activity.
- Intent intent = pm.getLaunchIntentForPackage(
- cn.getPackageName());
- if (intent != null) {
- cn = intent.getComponent();
- appInfo = appsMap.get(cn);
- }
-
- if ((intent == null) || (appsMap == null)) {
- // Could not find a default activity. Remove this item.
- iconsToRemove.add(shortcutInfo.getTargetComponent());
-
- // process next shortcut.
- return false;
- }
- shortcutInfo.promisedIntent = intent;
- }
- }
-
- // Restore the shortcut.
- shortcutInfo.intent = shortcutInfo.promisedIntent;
- shortcutInfo.promisedIntent = null;
- shortcutInfo.status &= ~ShortcutInfo.FLAG_RESTORED_ICON
- & ~ShortcutInfo.FLAG_AUTOINTALL_ICON
- & ~ShortcutInfo.FLAG_INSTALL_SESSION_ACTIVE;
-
- promiseStateChanged = true;
- infoUpdated = true;
- shortcutInfo.updateIcon(mIconCache);
- LauncherModel.updateItemInDatabase(getContext(), shortcutInfo);
- }
-
- if ((shortcutInfo.isDisabled & ShortcutInfo.FLAG_DISABLED_NOT_AVAILABLE) != 0) {
- // Since package was just updated, the target must be available now.
- shortcutInfo.isDisabled &= ~ShortcutInfo.FLAG_DISABLED_NOT_AVAILABLE;
- infoUpdated = true;
- }
-
- // Only update the icon and labels if the shortcuts points to an app target
- if ((appInfo != null) && LauncherModel.isShortcutAppTarget(shortcutInfo)) {
- shortcutInfo.updateIcon(mIconCache);
- shortcutInfo.title = appInfo.title.toString();
- shortcutInfo.contentDescription = appInfo.contentDescription;
- infoUpdated = true;
- }
-
- if (infoUpdated) {
- BubbleTextView shortcut = (BubbleTextView) v;
- shortcut.applyFromShortcutInfo(shortcutInfo,
- mIconCache, true, promiseStateChanged);
-
- if (parent != null) {
- parent.invalidate();
- }
- }
- }
- }
- // process all the shortcuts
- return false;
- }
- });
-
- if (!iconsToRemove.isEmpty()) {
- removeItemsByComponentName(iconsToRemove, user);
- }
- if (user.equals(UserHandleCompat.myUserHandle())) {
- restorePendingWidgets(pkgNames);
- }
- }
-
public void removeAbandonedPromise(String packageName, UserHandleCompat user) {
ArrayList<String> packages = new ArrayList<String>(1);
packages.add(packageName);
@@ -5211,9 +5085,11 @@ public class Workspace extends SmoothPagedView
}
public void updatePackageState(ArrayList<PackageInstallInfo> installInfos) {
- HashSet<String> completedPackages = new HashSet<String>();
-
for (final PackageInstallInfo installInfo : installInfos) {
+ if (installInfo.state == PackageInstallerCompat.STATUS_INSTALLED) {
+ continue;
+ }
+
mapOverItems(MAP_RECURSE, new ItemOperator() {
@Override
public boolean evaluate(ItemInfo info, View v, View parent) {
@@ -5241,42 +5117,10 @@ public class Workspace extends SmoothPagedView
return false;
}
});
-
- if (installInfo.state == PackageInstallerCompat.STATUS_INSTALLED) {
- completedPackages.add(installInfo.packageName);
- }
- }
-
- // Note that package states are sent only for myUser
- if (!completedPackages.isEmpty()) {
- restorePendingWidgets(completedPackages);
}
}
- private void restorePendingWidgets(final Set<String> installedPackaged) {
- final ArrayList<LauncherAppWidgetInfo> changedInfo = new ArrayList<LauncherAppWidgetInfo>();
-
- // Iterate non recursively as widgets can't be inside a folder.
- mapOverItems(MAP_NO_RECURSE, new ItemOperator() {
-
- @Override
- public boolean evaluate(ItemInfo info, View v, View parent) {
- if (info instanceof LauncherAppWidgetInfo) {
- LauncherAppWidgetInfo widgetInfo = (LauncherAppWidgetInfo) info;
- if (widgetInfo.hasRestoreFlag(LauncherAppWidgetInfo.FLAG_PROVIDER_NOT_READY)
- && installedPackaged.contains(widgetInfo.providerName.getPackageName())) {
-
- changedInfo.add(widgetInfo);
-
- // Remove the provider not ready flag
- widgetInfo.restoreStatus &= ~LauncherAppWidgetInfo.FLAG_PROVIDER_NOT_READY;
- LauncherModel.updateItemInDatabase(getContext(), widgetInfo);
- }
- }
- // process all the widget
- return false;
- }
- });
+ void widgetsRestored(ArrayList<LauncherAppWidgetInfo> changedInfo) {
if (!changedInfo.isEmpty()) {
DeferredWidgetRefresh widgetRefresh = new DeferredWidgetRefresh(changedInfo,
mLauncher.getAppWidgetHost());
@@ -5286,6 +5130,13 @@ public class Workspace extends SmoothPagedView
widgetRefresh.run();
} else {
// widgetRefresh will automatically run when the packages are updated.
+ // For now just update the progress bars
+ for (LauncherAppWidgetInfo info : changedInfo) {
+ if (info.hostView instanceof PendingAppWidgetHostView) {
+ info.installProgress = 100;
+ ((PendingAppWidgetHostView) info.hostView).applyState();
+ }
+ }
}
}
}