From cd81073eac537e9f85eeee14588d513ea8a56e17 Mon Sep 17 00:00:00 2001 From: Winson Chung Date: Mon, 18 Jun 2012 16:45:43 -0700 Subject: Decoupling launcher/workspace package cleanup from the application list (Bug 6602756) - Fixes issues where shortcuts created by wallpaper/widget-only apps are uninstalled. Change-Id: I94c9d1d71fc34aa2fb7f0660534e616a82ac6f36 --- src/com/android/launcher2/AllAppsView.java | 48 ---------------------- .../android/launcher2/AppsCustomizePagedView.java | 46 ++++++++++----------- src/com/android/launcher2/DragController.java | 10 ++--- src/com/android/launcher2/Launcher.java | 17 +++----- src/com/android/launcher2/LauncherModel.java | 23 +++++------ src/com/android/launcher2/Workspace.java | 7 +--- 6 files changed, 45 insertions(+), 106 deletions(-) delete mode 100644 src/com/android/launcher2/AllAppsView.java diff --git a/src/com/android/launcher2/AllAppsView.java b/src/com/android/launcher2/AllAppsView.java deleted file mode 100644 index e8ca61fb3..000000000 --- a/src/com/android/launcher2/AllAppsView.java +++ /dev/null @@ -1,48 +0,0 @@ -/* - * Copyright (C) 2008 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.android.launcher2; - -import java.util.ArrayList; - -public interface AllAppsView { - public interface Watcher { - public void zoomed(float zoom); - } - - public void setup(Launcher launcher, DragController dragController); - - public void zoom(float zoom, boolean animate); - - public boolean isVisible(); - - public boolean isAnimating(); - - public void setApps(ArrayList list); - - public void addApps(ArrayList list); - - public void removeApps(ArrayList list); - - public void updateApps(ArrayList list); - - // Resets the AllApps page to the front - public void reset(); - - public void dumpState(); - - public void surrender(); -} diff --git a/src/com/android/launcher2/AppsCustomizePagedView.java b/src/com/android/launcher2/AppsCustomizePagedView.java index ef3327295..11ae8f239 100644 --- a/src/com/android/launcher2/AppsCustomizePagedView.java +++ b/src/com/android/launcher2/AppsCustomizePagedView.java @@ -231,7 +231,7 @@ class RectCache extends WeakReferenceThreadLocal { * The Apps/Customize page that displays all the applications, widgets, and shortcuts. */ public class AppsCustomizePagedView extends PagedViewWithDraggableItems implements - AllAppsView, View.OnClickListener, View.OnKeyListener, DragSource, + View.OnClickListener, View.OnKeyListener, DragSource, PagedViewIcon.PressedCallback, PagedViewWidget.ShortPressListener, LauncherTransitionable { static final String TAG = "AppsCustomizePagedView"; @@ -1668,23 +1668,10 @@ public class AppsCustomizePagedView extends PagedViewWithDraggableItems implemen /* * AllAppsView implementation */ - @Override public void setup(Launcher launcher, DragController dragController) { mLauncher = launcher; mDragController = dragController; } - @Override - public void zoom(float zoom, boolean animate) { - // TODO-APPS_CUSTOMIZE: Call back to mLauncher.zoomed() - } - @Override - public boolean isVisible() { - return (getVisibility() == VISIBLE); - } - @Override - public boolean isAnimating() { - return false; - } /** * We should call thise method whenever the core data changes (mApps, mWidgets) so that we can @@ -1703,7 +1690,6 @@ public class AppsCustomizePagedView extends PagedViewWithDraggableItems implemen } } - @Override public void setApps(ArrayList list) { mApps = list; Collections.sort(mApps, LauncherModel.APP_NAME_COMPARATOR); @@ -1721,7 +1707,6 @@ public class AppsCustomizePagedView extends PagedViewWithDraggableItems implemen } } } - @Override public void addApps(ArrayList list) { addAppsWithoutInvalidate(list); updatePageCounts(); @@ -1738,6 +1723,16 @@ public class AppsCustomizePagedView extends PagedViewWithDraggableItems implemen } return -1; } + private int findAppByPackage(List list, String packageName) { + int length = list.size(); + for (int i = 0; i < length; ++i) { + ApplicationInfo info = list.get(i); + if (ItemInfo.getPackageName(info.intent).equals(packageName)) { + return i; + } + } + return -1; + } private void removeAppsWithoutInvalidate(ArrayList list) { // loop through all the apps and remove apps that have the same component int length = list.size(); @@ -1749,13 +1744,21 @@ public class AppsCustomizePagedView extends PagedViewWithDraggableItems implemen } } } - @Override - public void removeApps(ArrayList list) { - removeAppsWithoutInvalidate(list); + private void removeAppsWithPackageNameWithoutInvalidate(ArrayList packageNames) { + // loop through all the package names and remove apps that have the same package name + for (String pn : packageNames) { + int removeIndex = findAppByPackage(mApps, pn); + while (removeIndex > -1) { + mApps.remove(removeIndex); + removeIndex = findAppByPackage(mApps, pn); + } + } + } + public void removeApps(ArrayList packageNames) { + removeAppsWithPackageNameWithoutInvalidate(packageNames); updatePageCounts(); invalidateOnDataChange(); } - @Override public void updateApps(ArrayList list) { // We remove and re-add the updated applications list because it's properties may have // changed (ie. the title), and this will ensure that the items will be in their proper @@ -1766,7 +1769,6 @@ public class AppsCustomizePagedView extends PagedViewWithDraggableItems implemen invalidateOnDataChange(); } - @Override public void reset() { // If we have reset, then we should not continue to restore the previous state mSaveInstanceStateItemIndex = -1; @@ -1788,7 +1790,6 @@ public class AppsCustomizePagedView extends PagedViewWithDraggableItems implemen return (AppsCustomizeTabHost) mLauncher.findViewById(R.id.apps_customize_pane); } - @Override public void dumpState() { // TODO: Dump information related to current list of Applications, Widgets, etc. ApplicationInfo.dumpApplicationInfoList(TAG, "mApps", mApps); @@ -1813,7 +1814,6 @@ public class AppsCustomizePagedView extends PagedViewWithDraggableItems implemen } } - @Override public void surrender() { // TODO: If we are in the middle of any process (ie. for holographic outlines, etc) we // should stop this now. diff --git a/src/com/android/launcher2/DragController.java b/src/com/android/launcher2/DragController.java index 84f151581..4c4295319 100644 --- a/src/com/android/launcher2/DragController.java +++ b/src/com/android/launcher2/DragController.java @@ -326,19 +326,17 @@ public class DragController { } endDrag(); } - public void onAppsRemoved(ArrayList apps, Context context) { + public void onAppsRemoved(ArrayList packageNames, Context context) { // 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 (ApplicationInfo info : apps) { + for (String pn : packageNames) { // Added null checks to prevent NPE we've seen in the wild if (dragInfo != null && - dragInfo.intent != null && - info.intent != null) { - boolean isSamePackage = dragInfo.getPackageName().equals( - info.getPackageName()); + dragInfo.intent != null) { + boolean isSamePackage = dragInfo.getPackageName().equals(pn); if (isSamePackage) { cancelDrag(); return; diff --git a/src/com/android/launcher2/Launcher.java b/src/com/android/launcher2/Launcher.java index 415ccacfb..123155876 100644 --- a/src/com/android/launcher2/Launcher.java +++ b/src/com/android/launcher2/Launcher.java @@ -116,7 +116,7 @@ import java.util.Set; */ public final class Launcher extends Activity implements View.OnClickListener, OnLongClickListener, LauncherModel.Callbacks, - AllAppsView.Watcher, View.OnTouchListener { + View.OnTouchListener { static final String TAG = "Launcher"; static final boolean LOGD = false; @@ -2261,13 +2261,6 @@ public final class Launcher extends Activity return mHotseat.isAllAppsButtonRank(rank); } - // AllAppsView.Watcher - public void zoomed(float zoom) { - if (zoom == 1.0f) { - mWorkspace.setVisibility(View.GONE); - } - } - /** * Helper method for the cameraZoomIn/cameraZoomOut animations * @param view The view being animated @@ -3481,17 +3474,17 @@ public final class Launcher extends Activity * * Implementation of the method from LauncherModel.Callbacks. */ - public void bindAppsRemoved(ArrayList apps, boolean permanent) { + public void bindAppsRemoved(ArrayList packageNames, boolean permanent) { if (permanent) { - mWorkspace.removeItems(apps); + mWorkspace.removeItems(packageNames); } if (mAppsCustomizeContent != null) { - mAppsCustomizeContent.removeApps(apps); + mAppsCustomizeContent.removeApps(packageNames); } // Notify the drag controller - mDragController.onAppsRemoved(apps, this); + mDragController.onAppsRemoved(packageNames, this); } /** diff --git a/src/com/android/launcher2/LauncherModel.java b/src/com/android/launcher2/LauncherModel.java index fc1a26d4b..bada5cbb2 100644 --- a/src/com/android/launcher2/LauncherModel.java +++ b/src/com/android/launcher2/LauncherModel.java @@ -135,7 +135,7 @@ public class LauncherModel extends BroadcastReceiver { public void bindAllApplications(ArrayList apps); public void bindAppsAdded(ArrayList apps); public void bindAppsUpdated(ArrayList apps); - public void bindAppsRemoved(ArrayList apps, boolean permanent); + public void bindAppsRemoved(ArrayList packageNames, boolean permanent); public void bindPackagesUpdated(); public boolean isAllAppsVisible(); public boolean isAllAppsButtonRank(int rank); @@ -1623,25 +1623,25 @@ public class LauncherModel extends BroadcastReceiver { } ArrayList added = null; - ArrayList removed = null; ArrayList modified = null; if (mAllAppsList.added.size() > 0) { added = mAllAppsList.added; mAllAppsList.added = new ArrayList(); } - if (mAllAppsList.removed.size() > 0) { - removed = mAllAppsList.removed; - mAllAppsList.removed = new ArrayList(); - for (ApplicationInfo info: removed) { - mIconCache.remove(info.intent.getComponent()); - } - } if (mAllAppsList.modified.size() > 0) { modified = mAllAppsList.modified; mAllAppsList.modified = new ArrayList(); } + // We may be removing packages that have no associated launcher application, so we + // pass through the removed package names directly. + // NOTE: We flush the icon cache aggressively in removePackage() above. + final ArrayList removedPackageNames = new ArrayList(); + for (int i = 0; i < N; ++i) { + removedPackageNames.add(packages[i]); + } + final Callbacks callbacks = mCallbacks != null ? mCallbacks.get() : null; if (callbacks == null) { Log.w(TAG, "Nobody to tell about the new app. Launcher is probably loading."); @@ -1670,14 +1670,13 @@ public class LauncherModel extends BroadcastReceiver { } }); } - if (removed != null) { + if (!removedPackageNames.isEmpty()) { final boolean permanent = mOp != OP_UNAVAILABLE; - final ArrayList removedFinal = removed; mHandler.post(new Runnable() { public void run() { Callbacks cb = mCallbacks != null ? mCallbacks.get() : null; if (callbacks == cb && cb != null) { - callbacks.bindAppsRemoved(removedFinal, permanent); + callbacks.bindAppsRemoved(removedPackageNames, permanent); } } }); diff --git a/src/com/android/launcher2/Workspace.java b/src/com/android/launcher2/Workspace.java index 174d23b4d..5a4a52316 100644 --- a/src/com/android/launcher2/Workspace.java +++ b/src/com/android/launcher2/Workspace.java @@ -3545,12 +3545,9 @@ public class Workspace extends SmoothPagedView } } - void removeItems(final ArrayList apps) { + void removeItems(final ArrayList packages) { final HashSet packageNames = new HashSet(); - final int appCount = apps.size(); - for (int i = 0; i < appCount; i++) { - packageNames.add(apps.get(i).componentName.getPackageName()); - } + packageNames.addAll(packages); ArrayList cellLayouts = getWorkspaceAndHotseatCellLayouts(); for (final CellLayout layoutParent: cellLayouts) { -- cgit v1.2.3