am 42bfb12c: am 6d00d54e: Merge "Ensuring disabled packages remove all components on the workspace. (Bug 11172454)" into jb-ub-now-jetsonic

* commit '42bfb12c548fcd6c791a903c12d072988bfaa28c':
  Ensuring disabled packages remove all components on the workspace. (Bug 11172454)
This commit is contained in:
Winson Chung
2014-02-14 20:37:05 +00:00
committed by Android Git Automerger
4 changed files with 64 additions and 55 deletions
+6 -10
View File
@@ -16,6 +16,7 @@
package com.android.launcher3; package com.android.launcher3;
import android.content.ComponentName;
import android.content.Context; import android.content.Context;
import android.content.res.Resources; import android.content.res.Resources;
import android.graphics.Bitmap; import android.graphics.Bitmap;
@@ -25,14 +26,8 @@ import android.graphics.Rect;
import android.os.Handler; import android.os.Handler;
import android.os.IBinder; import android.os.IBinder;
import android.util.Log; import android.util.Log;
import android.view.HapticFeedbackConstants; import android.view.*;
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 android.view.inputmethod.InputMethodManager;
import com.android.launcher3.R; import com.android.launcher3.R;
import java.util.ArrayList; import java.util.ArrayList;
@@ -323,7 +318,7 @@ public class DragController {
} }
endDrag(); endDrag();
} }
public void onAppsRemoved(ArrayList<AppInfo> appInfos, Context context) { public void onAppsRemoved(final ArrayList<String> packageNames, ArrayList<AppInfo> appInfos) {
// Cancel the current drag if we are removing an app that we are dragging // Cancel the current drag if we are removing an app that we are dragging
if (mDragObject != null) { if (mDragObject != null) {
Object rawDragInfo = mDragObject.dragInfo; Object rawDragInfo = mDragObject.dragInfo;
@@ -333,8 +328,9 @@ public class DragController {
// Added null checks to prevent NPE we've seen in the wild // Added null checks to prevent NPE we've seen in the wild
if (dragInfo != null && if (dragInfo != null &&
dragInfo.intent != null) { dragInfo.intent != null) {
boolean isSameComponent = ComponentName cn = dragInfo.intent.getComponent();
dragInfo.intent.getComponent().equals(info.componentName); boolean isSameComponent = cn.equals(info.componentName) ||
packageNames.contains(cn.getPackageName());
if (isSameComponent) { if (isSameComponent) {
cancelDrag(); cancelDrag();
return; return;
@@ -108,6 +108,9 @@ public class InstallShortcutReceiver extends BroadcastReceiver {
public static void removeFromInstallQueue(SharedPreferences sharedPrefs, public static void removeFromInstallQueue(SharedPreferences sharedPrefs,
ArrayList<String> packageNames) { ArrayList<String> packageNames) {
if (packageNames.isEmpty()) {
return;
}
synchronized(sLock) { synchronized(sLock) {
Set<String> strings = sharedPrefs.getStringSet(APPS_PENDING_INSTALL, null); Set<String> strings = sharedPrefs.getStringSet(APPS_PENDING_INSTALL, null);
if (DBG) { if (DBG) {
+7 -7
View File
@@ -3971,26 +3971,27 @@ public class Launcher extends Activity
* Implementation of the method from LauncherModel.Callbacks. * Implementation of the method from LauncherModel.Callbacks.
*/ */
public void bindComponentsRemoved(final ArrayList<String> packageNames, public void bindComponentsRemoved(final ArrayList<String> packageNames,
final ArrayList<AppInfo> appInfos, final ArrayList<AppInfo> appInfos) {
final boolean packageRemoved) {
Runnable r = new Runnable() { Runnable r = new Runnable() {
public void run() { public void run() {
bindComponentsRemoved(packageNames, appInfos, packageRemoved); bindComponentsRemoved(packageNames, appInfos);
} }
}; };
if (waitUntilResume(r)) { if (waitUntilResume(r)) {
return; return;
} }
if (packageRemoved) { if (!packageNames.isEmpty()) {
mWorkspace.removeItemsByPackageName(packageNames); mWorkspace.removeItemsByPackageName(packageNames);
} else { }
if (!appInfos.isEmpty()) {
mWorkspace.removeItemsByApplicationInfo(appInfos); mWorkspace.removeItemsByApplicationInfo(appInfos);
} }
// Notify the drag controller // Notify the drag controller
mDragController.onAppsRemoved(appInfos, this); mDragController.onAppsRemoved(packageNames, appInfos);
// Update AllApps
if (!AppsCustomizePagedView.DISABLE_ALL_APPS && if (!AppsCustomizePagedView.DISABLE_ALL_APPS &&
mAppsCustomizeContent != null) { mAppsCustomizeContent != null) {
mAppsCustomizeContent.removeApps(appInfos); mAppsCustomizeContent.removeApps(appInfos);
@@ -4007,7 +4008,6 @@ public class Launcher extends Activity
mWidgetsAndShortcuts = null; mWidgetsAndShortcuts = null;
} }
}; };
public void bindPackagesUpdated(final ArrayList<Object> widgetsAndShortcuts) { public void bindPackagesUpdated(final ArrayList<Object> widgetsAndShortcuts) {
if (waitUntilResume(mBindPackagesUpdatedRunnable, true)) { if (waitUntilResume(mBindPackagesUpdatedRunnable, true)) {
mWidgetsAndShortcuts = widgetsAndShortcuts; mWidgetsAndShortcuts = widgetsAndShortcuts;
+48 -38
View File
@@ -165,8 +165,7 @@ public class LauncherModel extends BroadcastReceiver {
ArrayList<AppInfo> addedApps); ArrayList<AppInfo> addedApps);
public void bindAppsUpdated(ArrayList<AppInfo> apps); public void bindAppsUpdated(ArrayList<AppInfo> apps);
public void bindComponentsRemoved(ArrayList<String> packageNames, public void bindComponentsRemoved(ArrayList<String> packageNames,
ArrayList<AppInfo> appInfos, ArrayList<AppInfo> appInfos);
boolean matchPackageNamesOnly);
public void bindPackagesUpdated(ArrayList<Object> widgetsAndShortcuts); public void bindPackagesUpdated(ArrayList<Object> widgetsAndShortcuts);
public void bindSearchablesChanged(); public void bindSearchablesChanged();
public boolean isAllAppsButtonRank(int rank); public boolean isAllAppsButtonRank(int rank);
@@ -2553,43 +2552,47 @@ public class LauncherModel extends BroadcastReceiver {
} }
}); });
} }
// If a package has been removed, or an app has been removed as a result of
// an update (for example), make the removed callback.
if (mOp == OP_REMOVE || !removedApps.isEmpty()) {
final boolean packageRemoved = (mOp == OP_REMOVE);
final ArrayList<String> removedPackageNames =
new ArrayList<String>(Arrays.asList(packages));
// Update the launcher db to reflect the removal of apps final ArrayList<String> removedPackageNames =
if (packageRemoved) { new ArrayList<String>();
for (String pn : removedPackageNames) { if (mOp == OP_REMOVE) {
ArrayList<ItemInfo> infos = getItemInfoForPackageName(pn); // Mark all packages in the broadcast to be removed
for (ItemInfo i : infos) { removedPackageNames.addAll(Arrays.asList(packages));
deleteItemFromDatabase(context, i); } else if (mOp == OP_UPDATE) {
} // Mark disabled packages in the broadcast to be removed
} final PackageManager pm = context.getPackageManager();
for (int i=0; i<N; i++) {
// Remove any queued items from the install queue if (isPackageDisabled(pm, packages[i])) {
String spKey = LauncherAppState.getSharedPreferencesKey(); removedPackageNames.add(packages[i]);
SharedPreferences sp =
context.getSharedPreferences(spKey, Context.MODE_PRIVATE);
InstallShortcutReceiver.removeFromInstallQueue(sp, removedPackageNames);
} else {
for (AppInfo a : removedApps) {
ArrayList<ItemInfo> infos =
getItemInfoForComponentName(a.componentName);
for (ItemInfo i : infos) {
deleteItemFromDatabase(context, i);
}
} }
} }
}
// Remove all the components associated with this package
for (String pn : removedPackageNames) {
ArrayList<ItemInfo> infos = getItemInfoForPackageName(pn);
for (ItemInfo i : infos) {
deleteItemFromDatabase(context, i);
}
}
// Remove all the specific components
for (AppInfo a : removedApps) {
ArrayList<ItemInfo> infos = getItemInfoForComponentName(a.componentName);
for (ItemInfo i : infos) {
deleteItemFromDatabase(context, i);
}
}
if (!removedPackageNames.isEmpty() || !removedApps.isEmpty()) {
// Remove any queued items from the install queue
String spKey = LauncherAppState.getSharedPreferencesKey();
SharedPreferences sp =
context.getSharedPreferences(spKey, Context.MODE_PRIVATE);
InstallShortcutReceiver.removeFromInstallQueue(sp, removedPackageNames);
// Call the components-removed callback
mHandler.post(new Runnable() { mHandler.post(new Runnable() {
public void run() { public void run() {
Callbacks cb = mCallbacks != null ? mCallbacks.get() : null; Callbacks cb = mCallbacks != null ? mCallbacks.get() : null;
if (callbacks == cb && cb != null) { if (callbacks == cb && cb != null) {
callbacks.bindComponentsRemoved(removedPackageNames, callbacks.bindComponentsRemoved(removedPackageNames, removedApps);
removedApps, packageRemoved);
} }
} }
}); });
@@ -2631,19 +2634,26 @@ public class LauncherModel extends BroadcastReceiver {
return widgetsAndShortcuts; return widgetsAndShortcuts;
} }
private boolean isPackageDisabled(PackageManager pm, String packageName) {
try {
PackageInfo pi = pm.getPackageInfo(packageName, 0);
return !pi.applicationInfo.enabled;
} catch (NameNotFoundException e) {
// Fall through
}
return false;
}
private boolean isValidPackageComponent(PackageManager pm, ComponentName cn) { private boolean isValidPackageComponent(PackageManager pm, ComponentName cn) {
if (cn == null) { if (cn == null) {
return false; return false;
} }
if (isPackageDisabled(pm, cn.getPackageName())) {
return false;
}
try { try {
// Skip if the application is disabled
PackageInfo pi = pm.getPackageInfo(cn.getPackageName(), 0);
if (!pi.applicationInfo.enabled) {
return false;
}
// Check the activity // Check the activity
PackageInfo pi = pm.getPackageInfo(cn.getPackageName(), 0);
return (pm.getActivityInfo(cn, 0) != null); return (pm.getActivityInfo(cn, 0) != null);
} catch (NameNotFoundException e) { } catch (NameNotFoundException e) {
return false; return false;