summaryrefslogtreecommitdiffstats
path: root/src/com/android/launcher3/UninstallDropTarget.java
diff options
context:
space:
mode:
authorSunny Goyal <sunnygoyal@google.com>2016-10-10 10:41:41 -0700
committerSunny Goyal <sunnygoyal@google.com>2016-10-10 20:58:56 +0000
commit8e0e1d76095badc58a3178917c43642065ace37c (patch)
tree86ca5bfe89825614f3cc42674679fd317cacc6fb /src/com/android/launcher3/UninstallDropTarget.java
parent5fe414f9a425d9d7c2d5010fa476bc9faf440aed (diff)
downloadandroid_packages_apps_Trebuchet-8e0e1d76095badc58a3178917c43642065ace37c.tar.gz
android_packages_apps_Trebuchet-8e0e1d76095badc58a3178917c43642065ace37c.tar.bz2
android_packages_apps_Trebuchet-8e0e1d76095badc58a3178917c43642065ace37c.zip
Moving come helper methods to corresponding classes
> Moving isPackageEnabled to InstallShortcutReceiver > Moving the deep shortcut map to the data model > Removing appInfo.flags. Instead fetching the flags when needed Change-Id: I654dd8acefa7b7d183b0419afbe112bef001d536
Diffstat (limited to 'src/com/android/launcher3/UninstallDropTarget.java')
-rw-r--r--src/com/android/launcher3/UninstallDropTarget.java40
1 files changed, 26 insertions, 14 deletions
diff --git a/src/com/android/launcher3/UninstallDropTarget.java b/src/com/android/launcher3/UninstallDropTarget.java
index 91539439c..7ea9aca7c 100644
--- a/src/com/android/launcher3/UninstallDropTarget.java
+++ b/src/com/android/launcher3/UninstallDropTarget.java
@@ -4,6 +4,7 @@ import android.annotation.TargetApi;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
+import android.content.pm.ApplicationInfo;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
@@ -12,6 +13,8 @@ import android.util.AttributeSet;
import android.util.Pair;
import android.widget.Toast;
+import com.android.launcher3.compat.LauncherActivityInfoCompat;
+import com.android.launcher3.compat.LauncherAppsCompat;
import com.android.launcher3.compat.UserHandleCompat;
public class UninstallDropTarget extends ButtonDropTarget {
@@ -49,23 +52,34 @@ public class UninstallDropTarget extends ButtonDropTarget {
}
}
- Pair<ComponentName, Integer> componentInfo = getAppInfoFlags(info);
- return componentInfo != null && (componentInfo.second & AppInfo.DOWNLOADED_FLAG) != 0;
+ return getUninstallTarget(context, info) != null;
}
/**
- * @return the component name and flags if {@param info} is an AppInfo or an app shortcut.
+ * @return the component name that should be uninstalled or null.
*/
- private static Pair<ComponentName, Integer> getAppInfoFlags(Object item) {
+ private static ComponentName getUninstallTarget(Context context, Object item) {
+ Intent intent = null;
+ UserHandleCompat user = null;
if (item instanceof AppInfo) {
AppInfo info = (AppInfo) item;
- return Pair.create(info.componentName, info.flags);
+ intent = info.intent;
+ user = info.user;
} else if (item instanceof ShortcutInfo) {
ShortcutInfo info = (ShortcutInfo) item;
- ComponentName component = info.getTargetComponent();
- if (info.itemType == LauncherSettings.BaseLauncherColumns.ITEM_TYPE_APPLICATION
- && component != null) {
- return Pair.create(component, info.flags);
+ if (info.itemType == LauncherSettings.BaseLauncherColumns.ITEM_TYPE_APPLICATION) {
+ // Do not use restore/target intent here as we cannot uninstall an app which is
+ // being installed/restored.
+ intent = info.intent;
+ user = info.user;
+ }
+ }
+ if (intent != null) {
+ LauncherActivityInfoCompat info = LauncherAppsCompat.getInstance(context)
+ .resolveActivity(intent, user);
+ if (info != null
+ && (info.getApplicationInfo().flags & ApplicationInfo.FLAG_SYSTEM) == 0) {
+ return info.getComponentName();
}
}
return null;
@@ -93,11 +107,10 @@ public class UninstallDropTarget extends ButtonDropTarget {
public static boolean startUninstallActivity(
final Launcher launcher, ItemInfo info, DropTargetResultCallback callback) {
- Pair<ComponentName, Integer> componentInfo = getAppInfoFlags(info);
- ComponentName cn = componentInfo.first;
+ final ComponentName cn = getUninstallTarget(launcher, info);
final boolean isUninstallable;
- if ((componentInfo.second & AppInfo.DOWNLOADED_FLAG) == 0) {
+ if (cn == null) {
// System applications cannot be installed. For now, show a toast explaining that.
// We may give them the option of disabling apps this way.
Toast.makeText(launcher, R.string.uninstall_system_app_text, Toast.LENGTH_SHORT).show();
@@ -112,8 +125,7 @@ public class UninstallDropTarget extends ButtonDropTarget {
isUninstallable = true;
}
if (callback != null) {
- sendUninstallResult(
- launcher, isUninstallable, componentInfo.first, info.user, callback);
+ sendUninstallResult(launcher, isUninstallable, cn, info.user, callback);
}
return isUninstallable;
}