From f2db25398a029b6f13afccbec331e35c8007dde6 Mon Sep 17 00:00:00 2001 From: Sunny Goyal Date: Wed, 1 Mar 2017 17:27:16 -0800 Subject: [PATCH] Fixing wrong check being used for application status Earlier we were relying on activity list to check is an app is installed or not. It fails if the app only exposes widgets and no visible activity. Hence dragging an icon to AppInfo sometimes causes the icon to get disappear. Bug: 33241335 Change-Id: Ieb71e298a0930dd0a831cf09bd1e998514a427fd --- src/com/android/launcher3/AllAppsList.java | 10 ---------- src/com/android/launcher3/UninstallDropTarget.java | 8 +++++--- .../android/launcher3/compat/LauncherAppsCompatVL.java | 3 ++- .../android/launcher3/compat/LauncherAppsCompatVO.java | 3 ++- 4 files changed, 9 insertions(+), 15 deletions(-) diff --git a/src/com/android/launcher3/AllAppsList.java b/src/com/android/launcher3/AllAppsList.java index 9cce9b188e..5b42cad963 100644 --- a/src/com/android/launcher3/AllAppsList.java +++ b/src/com/android/launcher3/AllAppsList.java @@ -207,16 +207,6 @@ public class AllAppsList { return false; } - /** - * Query the launcher apps service for whether the supplied package has - * MAIN/LAUNCHER activities in the supplied package. - */ - static boolean packageHasActivities(Context context, String packageName, - UserHandle user) { - final LauncherAppsCompat launcherApps = LauncherAppsCompat.getInstance(context); - return launcherApps.getActivityList(packageName, user).size() > 0; - } - /** * Returns whether apps contains component. */ diff --git a/src/com/android/launcher3/UninstallDropTarget.java b/src/com/android/launcher3/UninstallDropTarget.java index e68a5b0302..0fac29f30a 100644 --- a/src/com/android/launcher3/UninstallDropTarget.java +++ b/src/com/android/launcher3/UninstallDropTarget.java @@ -5,6 +5,7 @@ import android.content.Context; import android.content.Intent; import android.content.pm.ApplicationInfo; import android.content.pm.LauncherActivityInfo; +import android.content.pm.PackageManager; import android.net.Uri; import android.os.Bundle; import android.os.UserHandle; @@ -139,9 +140,10 @@ public class UninstallDropTarget extends ButtonDropTarget { final Runnable checkIfUninstallWasSuccess = new Runnable() { @Override public void run() { - String packageName = cn.getPackageName(); - boolean uninstallSuccessful = !AllAppsList.packageHasActivities( - launcher, packageName, user); + // We use MATCH_UNINSTALLED_PACKAGES as the app can be on SD card as well. + boolean uninstallSuccessful = LauncherAppsCompat.getInstance(launcher) + .getApplicationInfo(cn.getPackageName(), + PackageManager.MATCH_UNINSTALLED_PACKAGES, user) == null; callback.onDragObjectRemoved(uninstallSuccessful); } }; diff --git a/src/com/android/launcher3/compat/LauncherAppsCompatVL.java b/src/com/android/launcher3/compat/LauncherAppsCompatVL.java index e5517a6c65..4590173923 100644 --- a/src/com/android/launcher3/compat/LauncherAppsCompatVL.java +++ b/src/com/android/launcher3/compat/LauncherAppsCompatVL.java @@ -81,7 +81,8 @@ public class LauncherAppsCompatVL extends LauncherAppsCompat { mContext.getPackageManager().getApplicationInfo(packageName, flags); // There is no way to check if the app is installed for managed profile. But for // primary profile, we can still have this check. - if (isPrimaryUser && ((info.flags & ApplicationInfo.FLAG_INSTALLED) == 0)) { + if (isPrimaryUser && ((info.flags & ApplicationInfo.FLAG_INSTALLED) == 0) + || !info.enabled) { return null; } return info; diff --git a/src/com/android/launcher3/compat/LauncherAppsCompatVO.java b/src/com/android/launcher3/compat/LauncherAppsCompatVO.java index c0f80d01c1..27433796aa 100644 --- a/src/com/android/launcher3/compat/LauncherAppsCompatVO.java +++ b/src/com/android/launcher3/compat/LauncherAppsCompatVO.java @@ -37,7 +37,8 @@ public class LauncherAppsCompatVO extends LauncherAppsCompatVL { @Override public ApplicationInfo getApplicationInfo(String packageName, int flags, UserHandle user) { ApplicationInfo info = mLauncherApps.getApplicationInfo(packageName, flags, user); - return info == null || (info.flags & ApplicationInfo.FLAG_INSTALLED) == 0 ? null : info; + return info == null || (info.flags & ApplicationInfo.FLAG_INSTALLED) == 0 || !info.enabled + ? null : info; } @Override