Merge "Ensuring disabled packages remove all components on the workspace. (Bug 11172454)" into jb-ub-now-jetsonic
This commit is contained in:
@@ -16,6 +16,7 @@
|
||||
|
||||
package com.android.launcher3;
|
||||
|
||||
import android.content.ComponentName;
|
||||
import android.content.Context;
|
||||
import android.content.res.Resources;
|
||||
import android.graphics.Bitmap;
|
||||
@@ -25,14 +26,8 @@ import android.graphics.Rect;
|
||||
import android.os.Handler;
|
||||
import android.os.IBinder;
|
||||
import android.util.Log;
|
||||
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.*;
|
||||
import android.view.inputmethod.InputMethodManager;
|
||||
|
||||
import com.android.launcher3.R;
|
||||
|
||||
import java.util.ArrayList;
|
||||
@@ -323,7 +318,7 @@ public class DragController {
|
||||
}
|
||||
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
|
||||
if (mDragObject != null) {
|
||||
Object rawDragInfo = mDragObject.dragInfo;
|
||||
@@ -333,8 +328,9 @@ public class DragController {
|
||||
// Added null checks to prevent NPE we've seen in the wild
|
||||
if (dragInfo != null &&
|
||||
dragInfo.intent != null) {
|
||||
boolean isSameComponent =
|
||||
dragInfo.intent.getComponent().equals(info.componentName);
|
||||
ComponentName cn = dragInfo.intent.getComponent();
|
||||
boolean isSameComponent = cn.equals(info.componentName) ||
|
||||
packageNames.contains(cn.getPackageName());
|
||||
if (isSameComponent) {
|
||||
cancelDrag();
|
||||
return;
|
||||
|
||||
@@ -108,6 +108,9 @@ public class InstallShortcutReceiver extends BroadcastReceiver {
|
||||
|
||||
public static void removeFromInstallQueue(SharedPreferences sharedPrefs,
|
||||
ArrayList<String> packageNames) {
|
||||
if (packageNames.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
synchronized(sLock) {
|
||||
Set<String> strings = sharedPrefs.getStringSet(APPS_PENDING_INSTALL, null);
|
||||
if (DBG) {
|
||||
|
||||
@@ -3971,26 +3971,27 @@ public class Launcher extends Activity
|
||||
* Implementation of the method from LauncherModel.Callbacks.
|
||||
*/
|
||||
public void bindComponentsRemoved(final ArrayList<String> packageNames,
|
||||
final ArrayList<AppInfo> appInfos,
|
||||
final boolean packageRemoved) {
|
||||
final ArrayList<AppInfo> appInfos) {
|
||||
Runnable r = new Runnable() {
|
||||
public void run() {
|
||||
bindComponentsRemoved(packageNames, appInfos, packageRemoved);
|
||||
bindComponentsRemoved(packageNames, appInfos);
|
||||
}
|
||||
};
|
||||
if (waitUntilResume(r)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (packageRemoved) {
|
||||
if (!packageNames.isEmpty()) {
|
||||
mWorkspace.removeItemsByPackageName(packageNames);
|
||||
} else {
|
||||
}
|
||||
if (!appInfos.isEmpty()) {
|
||||
mWorkspace.removeItemsByApplicationInfo(appInfos);
|
||||
}
|
||||
|
||||
// Notify the drag controller
|
||||
mDragController.onAppsRemoved(appInfos, this);
|
||||
mDragController.onAppsRemoved(packageNames, appInfos);
|
||||
|
||||
// Update AllApps
|
||||
if (!AppsCustomizePagedView.DISABLE_ALL_APPS &&
|
||||
mAppsCustomizeContent != null) {
|
||||
mAppsCustomizeContent.removeApps(appInfos);
|
||||
@@ -4007,7 +4008,6 @@ public class Launcher extends Activity
|
||||
mWidgetsAndShortcuts = null;
|
||||
}
|
||||
};
|
||||
|
||||
public void bindPackagesUpdated(final ArrayList<Object> widgetsAndShortcuts) {
|
||||
if (waitUntilResume(mBindPackagesUpdatedRunnable, true)) {
|
||||
mWidgetsAndShortcuts = widgetsAndShortcuts;
|
||||
|
||||
@@ -165,8 +165,7 @@ public class LauncherModel extends BroadcastReceiver {
|
||||
ArrayList<AppInfo> addedApps);
|
||||
public void bindAppsUpdated(ArrayList<AppInfo> apps);
|
||||
public void bindComponentsRemoved(ArrayList<String> packageNames,
|
||||
ArrayList<AppInfo> appInfos,
|
||||
boolean matchPackageNamesOnly);
|
||||
ArrayList<AppInfo> appInfos);
|
||||
public void bindPackagesUpdated(ArrayList<Object> widgetsAndShortcuts);
|
||||
public void bindSearchablesChanged();
|
||||
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
|
||||
if (packageRemoved) {
|
||||
for (String pn : removedPackageNames) {
|
||||
ArrayList<ItemInfo> infos = getItemInfoForPackageName(pn);
|
||||
for (ItemInfo i : infos) {
|
||||
deleteItemFromDatabase(context, i);
|
||||
}
|
||||
}
|
||||
|
||||
// Remove any queued items from the install queue
|
||||
String spKey = LauncherAppState.getSharedPreferencesKey();
|
||||
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);
|
||||
}
|
||||
final ArrayList<String> removedPackageNames =
|
||||
new ArrayList<String>();
|
||||
if (mOp == OP_REMOVE) {
|
||||
// Mark all packages in the broadcast to be removed
|
||||
removedPackageNames.addAll(Arrays.asList(packages));
|
||||
} 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++) {
|
||||
if (isPackageDisabled(pm, packages[i])) {
|
||||
removedPackageNames.add(packages[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() {
|
||||
public void run() {
|
||||
Callbacks cb = mCallbacks != null ? mCallbacks.get() : null;
|
||||
if (callbacks == cb && cb != null) {
|
||||
callbacks.bindComponentsRemoved(removedPackageNames,
|
||||
removedApps, packageRemoved);
|
||||
callbacks.bindComponentsRemoved(removedPackageNames, removedApps);
|
||||
}
|
||||
}
|
||||
});
|
||||
@@ -2631,19 +2634,26 @@ public class LauncherModel extends BroadcastReceiver {
|
||||
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) {
|
||||
if (cn == null) {
|
||||
return false;
|
||||
}
|
||||
if (isPackageDisabled(pm, cn.getPackageName())) {
|
||||
return false;
|
||||
}
|
||||
|
||||
try {
|
||||
// Skip if the application is disabled
|
||||
PackageInfo pi = pm.getPackageInfo(cn.getPackageName(), 0);
|
||||
if (!pi.applicationInfo.enabled) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Check the activity
|
||||
PackageInfo pi = pm.getPackageInfo(cn.getPackageName(), 0);
|
||||
return (pm.getActivityInfo(cn, 0) != null);
|
||||
} catch (NameNotFoundException e) {
|
||||
return false;
|
||||
|
||||
Reference in New Issue
Block a user