diff options
author | Sunny Goyal <sunnygoyal@google.com> | 2016-10-10 10:41:41 -0700 |
---|---|---|
committer | Sunny Goyal <sunnygoyal@google.com> | 2016-10-10 20:58:56 +0000 |
commit | 8e0e1d76095badc58a3178917c43642065ace37c (patch) | |
tree | 86ca5bfe89825614f3cc42674679fd317cacc6fb | |
parent | 5fe414f9a425d9d7c2d5010fa476bc9faf440aed (diff) | |
download | android_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
-rw-r--r-- | src/com/android/launcher3/AllAppsList.java | 7 | ||||
-rw-r--r-- | src/com/android/launcher3/AppInfo.java | 20 | ||||
-rw-r--r-- | src/com/android/launcher3/InstallShortcutReceiver.java | 3 | ||||
-rw-r--r-- | src/com/android/launcher3/LauncherModel.java | 73 | ||||
-rw-r--r-- | src/com/android/launcher3/LauncherProvider.java | 2 | ||||
-rw-r--r-- | src/com/android/launcher3/ShortcutInfo.java | 9 | ||||
-rw-r--r-- | src/com/android/launcher3/UninstallDropTarget.java | 40 | ||||
-rw-r--r-- | src/com/android/launcher3/model/BgDataModel.java | 40 |
8 files changed, 81 insertions, 113 deletions
diff --git a/src/com/android/launcher3/AllAppsList.java b/src/com/android/launcher3/AllAppsList.java index c427ddc93..0e465a41e 100644 --- a/src/com/android/launcher3/AllAppsList.java +++ b/src/com/android/launcher3/AllAppsList.java @@ -33,7 +33,7 @@ import java.util.List; /** * Stores the list of all applications for the all apps view. */ -class AllAppsList { +public class AllAppsList { public static final int DEFAULT_APPLICATIONS_NUMBER = 42; /** The list off all apps. */ @@ -112,8 +112,7 @@ class AllAppsList { final List<AppInfo> data = this.data; for (int i = data.size() - 1; i >= 0; i--) { AppInfo info = data.get(i); - final ComponentName component = info.intent.getComponent(); - if (info.user.equals(user) && packageName.equals(component.getPackageName())) { + if (info.user.equals(user) && packageName.equals(info.componentName.getPackageName())) { removed.add(info); data.remove(i); } @@ -127,7 +126,7 @@ class AllAppsList { final List<AppInfo> data = this.data; for (int i = data.size() - 1; i >= 0; i--) { AppInfo info = data.get(i); - if (matcher.matches(info, info.intent.getComponent())) { + if (matcher.matches(info, info.componentName)) { info.isDisabled = op.apply(info.isDisabled); modified.add(info); } diff --git a/src/com/android/launcher3/AppInfo.java b/src/com/android/launcher3/AppInfo.java index 4c4d67c59..3b22f46f2 100644 --- a/src/com/android/launcher3/AppInfo.java +++ b/src/com/android/launcher3/AppInfo.java @@ -52,11 +52,6 @@ public class AppInfo extends ItemInfo { public ComponentName componentName; - static final int DOWNLOADED_FLAG = 1; - static final int UPDATED_SYSTEM_APP_FLAG = 2; - - int flags = 0; - /** * {@see ShortcutInfo#isDisabled} */ @@ -88,7 +83,6 @@ public class AppInfo extends ItemInfo { IconCache iconCache, boolean quietModeEnabled) { this.componentName = info.getComponentName(); this.container = ItemInfo.NO_ID; - flags = initFlags(info); if (PackageManagerHelper.isAppSuspended(info.getApplicationInfo())) { isDisabled |= ShortcutInfo.FLAG_DISABLED_SUSPENDED; } @@ -101,25 +95,11 @@ public class AppInfo extends ItemInfo { this.user = user; } - public static int initFlags(LauncherActivityInfoCompat info) { - int appFlags = info.getApplicationInfo().flags; - int flags = 0; - if ((appFlags & android.content.pm.ApplicationInfo.FLAG_SYSTEM) == 0) { - flags |= DOWNLOADED_FLAG; - - if ((appFlags & android.content.pm.ApplicationInfo.FLAG_UPDATED_SYSTEM_APP) != 0) { - flags |= UPDATED_SYSTEM_APP_FLAG; - } - } - return flags; - } - public AppInfo(AppInfo info) { super(info); componentName = info.componentName; title = Utilities.trim(info.title); intent = new Intent(info.intent); - flags = info.flags; isDisabled = info.isDisabled; iconBitmap = info.iconBitmap; } diff --git a/src/com/android/launcher3/InstallShortcutReceiver.java b/src/com/android/launcher3/InstallShortcutReceiver.java index d8e58d829..bd20e324b 100644 --- a/src/com/android/launcher3/InstallShortcutReceiver.java +++ b/src/com/android/launcher3/InstallShortcutReceiver.java @@ -226,7 +226,8 @@ public class InstallShortcutReceiver extends BroadcastReceiver { String packageName = pendingInfo.getTargetPackage(); if (!TextUtils.isEmpty(packageName)) { UserHandleCompat myUserHandle = UserHandleCompat.myUserHandle(); - if (!LauncherModel.isValidPackage(context, packageName, myUserHandle)) { + if (!LauncherAppsCompat.getInstance(context) + .isPackageEnabledForProfile(packageName, myUserHandle)) { if (DBG) Log.d(TAG, "Ignoring shortcut for absent package: " + pendingInfo.launchIntent); continue; diff --git a/src/com/android/launcher3/LauncherModel.java b/src/com/android/launcher3/LauncherModel.java index 4afff1898..3f9c2a324 100644 --- a/src/com/android/launcher3/LauncherModel.java +++ b/src/com/android/launcher3/LauncherModel.java @@ -93,7 +93,6 @@ import java.util.HashSet; import java.util.Iterator; import java.util.List; import java.util.Map; -import java.util.Map.Entry; import java.util.Set; import java.util.concurrent.Executor; @@ -145,9 +144,6 @@ public class LauncherModel extends BroadcastReceiver // Entire list of widgets. private final WidgetsModel mBgWidgetsModel; - // Maps all launcher activities to the id's of their shortcuts (if they have any). - private final MultiHashMap<ComponentKey, String> mBgDeepShortcutMap = new MultiHashMap<>(); - private boolean mHasShortcutHostPermission; // Runnable to check if the shortcuts permission has changed. private final Runnable mShortcutPermissionCheckRunnable = new Runnable() { @@ -316,15 +312,7 @@ public class LauncherModel extends BroadcastReceiver ComponentName cn = si.getTargetComponent(); if (si.isPromise() && (cn != null) && packageName.equals(cn.getPackageName())) { - if (si.hasStatusFlag(ShortcutInfo.FLAG_AUTOINTALL_ICON)) { - // For auto install apps update the icon as well as label. - mIconCache.getTitleAndIcon(si, - si.promisedIntent, user, - si.shouldUseLowResIcon()); - } else { - // Only update the icon for restored apps. - si.updateIcon(mIconCache); - } + si.updateIcon(mIconCache); updates.add(si); } } @@ -2647,14 +2635,14 @@ public class LauncherModel extends BroadcastReceiver Log.d(TAG, "loadAndBindDeepShortcuts mDeepShortcutsLoaded=" + mDeepShortcutsLoaded); } if (!mDeepShortcutsLoaded) { - mBgDeepShortcutMap.clear(); + sBgDataModel.deepShortcutMap.clear(); mHasShortcutHostPermission = mDeepShortcutManager.hasHostPermission(); if (mHasShortcutHostPermission) { for (UserHandleCompat user : mUserManager.getUserProfiles()) { if (mUserManager.isUserUnlocked(user)) { List<ShortcutInfoCompat> shortcuts = mDeepShortcutManager .queryForAllShortcuts(user); - updateDeepShortcutMap(null, user, shortcuts); + sBgDataModel.updateDeepShortcutMap(null, user, shortcuts); } } } @@ -2678,36 +2666,9 @@ public class LauncherModel extends BroadcastReceiver } } - /** - * Clear all the shortcuts for the given package, and re-add the new shortcuts. - */ - private void updateDeepShortcutMap( - String packageName, UserHandleCompat user, List<ShortcutInfoCompat> shortcuts) { - if (packageName != null) { - Iterator<ComponentKey> keysIter = mBgDeepShortcutMap.keySet().iterator(); - while (keysIter.hasNext()) { - ComponentKey next = keysIter.next(); - if (next.componentName.getPackageName().equals(packageName) - && next.user.equals(user)) { - keysIter.remove(); - } - } - } - - // Now add the new shortcuts to the map. - for (ShortcutInfoCompat shortcut : shortcuts) { - boolean shouldShowInContainer = shortcut.isEnabled() - && (shortcut.isDeclaredInManifest() || shortcut.isDynamic()); - if (shouldShowInContainer) { - ComponentKey targetComponent - = new ComponentKey(shortcut.getActivity(), shortcut.getUserHandle()); - mBgDeepShortcutMap.addToList(targetComponent, shortcut.getId()); - } - } - } - public void bindDeepShortcuts() { - final MultiHashMap<ComponentKey, String> shortcutMapCopy = mBgDeepShortcutMap.clone(); + final MultiHashMap<ComponentKey, String> shortcutMapCopy = + sBgDataModel.deepShortcutMap.clone(); Runnable r = new Runnable() { @Override public void run() { @@ -2989,11 +2950,6 @@ public class LauncherModel extends BroadcastReceiver } } - // Restore the shortcut. - if (appInfo != null) { - si.flags = appInfo.flags; - } - si.intent = si.promisedIntent; si.promisedIntent = null; si.status = ShortcutInfo.DEFAULT; @@ -3221,7 +3177,7 @@ public class LauncherModel extends BroadcastReceiver if (mUpdateIdMap) { // Update the deep shortcut map if the list of ids has changed for an activity. - updateDeepShortcutMap(mPackageName, mUser, mShortcuts); + sBgDataModel.updateDeepShortcutMap(mPackageName, mUser, mShortcuts); bindDeepShortcuts(); } } @@ -3289,7 +3245,7 @@ public class LauncherModel extends BroadcastReceiver } // Remove shortcut id map for that user - Iterator<ComponentKey> keysIter = mBgDeepShortcutMap.keySet().iterator(); + Iterator<ComponentKey> keysIter = sBgDataModel.deepShortcutMap.keySet().iterator(); while (keysIter.hasNext()) { if (keysIter.next().user.equals(mUser)) { keysIter.remove(); @@ -3297,7 +3253,8 @@ public class LauncherModel extends BroadcastReceiver } if (isUserUnlocked) { - updateDeepShortcutMap(null, mUser, mDeepShortcutManager.queryForAllShortcuts(mUser)); + sBgDataModel.updateDeepShortcutMap( + null, mUser, mDeepShortcutManager.queryForAllShortcuts(mUser)); } bindDeepShortcuts(); } @@ -3338,15 +3295,6 @@ public class LauncherModel extends BroadcastReceiver return !launcherApps.isPackageEnabledForProfile(packageName, user); } - public static boolean isValidPackage(Context context, String packageName, - UserHandleCompat user) { - if (packageName == null) { - return false; - } - final LauncherAppsCompat launcherApps = LauncherAppsCompat.getInstance(context); - return launcherApps.isPackageEnabledForProfile(packageName, user); - } - /** * Make an ShortcutInfo object for a restored application or shortcut item that points * to a package that is not yet installed on the system. @@ -3454,9 +3402,6 @@ public class LauncherModel extends BroadcastReceiver info.itemType = LauncherSettings.Favorites.ITEM_TYPE_APPLICATION; info.user = user; info.contentDescription = mUserManager.getBadgedLabelForUser(info.title, info.user); - if (lai != null) { - info.flags = AppInfo.initFlags(lai); - } return info; } diff --git a/src/com/android/launcher3/LauncherProvider.java b/src/com/android/launcher3/LauncherProvider.java index e1ff6dbc1..229dd9cba 100644 --- a/src/com/android/launcher3/LauncherProvider.java +++ b/src/com/android/launcher3/LauncherProvider.java @@ -1014,7 +1014,7 @@ public class LauncherProvider extends ContentProvider { public void checkId(String table, ContentValues values) { long id = values.getAsLong(LauncherSettings.BaseLauncherColumns._ID); - if (table == WorkspaceScreens.TABLE_NAME) { + if (WorkspaceScreens.TABLE_NAME.equals(table)) { mMaxScreenId = Math.max(id, mMaxScreenId); } else { mMaxItemId = Math.max(id, mMaxItemId); diff --git a/src/com/android/launcher3/ShortcutInfo.java b/src/com/android/launcher3/ShortcutInfo.java index ce0629136..9a9287234 100644 --- a/src/com/android/launcher3/ShortcutInfo.java +++ b/src/com/android/launcher3/ShortcutInfo.java @@ -148,11 +148,6 @@ public class ShortcutInfo extends ItemInfo { private int mInstallProgress; /** - * TODO move this to {@link #status} - */ - int flags = 0; - - /** * If this shortcut is a placeholder, then intent will be a market intent for the package, and * this will hold the original intent from the database. Otherwise, null. * Refer {@link #FLAG_RESTORED_ICON}, {@link #FLAG_AUTOINTALL_ICON} @@ -189,7 +184,6 @@ public class ShortcutInfo extends ItemInfo { intent = new Intent(info.intent); iconResource = info.iconResource; mIcon = info.mIcon; // TODO: should make a copy here. maybe we don't need this ctor at all - flags = info.flags; status = info.status; mInstallProgress = info.mInstallProgress; isDisabled = info.isDisabled; @@ -201,7 +195,6 @@ public class ShortcutInfo extends ItemInfo { super(info); title = Utilities.trim(info.title); intent = new Intent(info.intent); - flags = info.flags; isDisabled = info.isDisabled; } @@ -212,7 +205,6 @@ public class ShortcutInfo extends ItemInfo { .getBadgedLabelForUser(info.getLabel(), info.getUser()); intent = AppInfo.makeLaunchIntent(context, info, info.getUser()); itemType = LauncherSettings.Favorites.ITEM_TYPE_APPLICATION; - flags = AppInfo.initFlags(info); } /** @@ -222,7 +214,6 @@ public class ShortcutInfo extends ItemInfo { public ShortcutInfo(ShortcutInfoCompat shortcutInfo, Context context) { user = shortcutInfo.getUserHandle(); itemType = LauncherSettings.Favorites.ITEM_TYPE_DEEP_SHORTCUT; - flags = 0; updateFromDeepShortcutInfo(shortcutInfo, context); } 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; } diff --git a/src/com/android/launcher3/model/BgDataModel.java b/src/com/android/launcher3/model/BgDataModel.java index 2b7039928..c18eeef3d 100644 --- a/src/com/android/launcher3/model/BgDataModel.java +++ b/src/com/android/launcher3/model/BgDataModel.java @@ -24,13 +24,19 @@ import com.android.launcher3.LauncherAppState; import com.android.launcher3.LauncherAppWidgetInfo; import com.android.launcher3.LauncherSettings; import com.android.launcher3.ShortcutInfo; +import com.android.launcher3.compat.UserHandleCompat; import com.android.launcher3.config.ProviderConfig; +import com.android.launcher3.shortcuts.ShortcutInfoCompat; import com.android.launcher3.shortcuts.ShortcutKey; +import com.android.launcher3.util.ComponentKey; import com.android.launcher3.util.LongArrayMap; +import com.android.launcher3.util.MultiHashMap; import java.util.ArrayList; import java.util.Arrays; import java.util.HashMap; +import java.util.Iterator; +import java.util.List; import java.util.Map; /** @@ -73,6 +79,11 @@ public class BgDataModel { public final Map<ShortcutKey, MutableInt> pinnedShortcutCounts = new HashMap<>(); /** + * Maps all launcher activities to the id's of their shortcuts (if they have any). + */ + public final MultiHashMap<ComponentKey, String> deepShortcutMap = new MultiHashMap<>(); + + /** * Clears all the data */ public synchronized void clear() { @@ -82,6 +93,7 @@ public class BgDataModel { itemsIdMap.clear(); workspaceScreens.clear(); pinnedShortcutCounts.clear(); + deepShortcutMap.clear(); } public synchronized void removeItem(ItemInfo... items) { @@ -194,4 +206,32 @@ public class BgDataModel { } return folderInfo; } + + /** + * Clear all the deep shortcuts for the given package, and re-add the new shortcuts. + */ + public synchronized void updateDeepShortcutMap( + String packageName, UserHandleCompat user, List<ShortcutInfoCompat> shortcuts) { + if (packageName != null) { + Iterator<ComponentKey> keysIter = deepShortcutMap.keySet().iterator(); + while (keysIter.hasNext()) { + ComponentKey next = keysIter.next(); + if (next.componentName.getPackageName().equals(packageName) + && next.user.equals(user)) { + keysIter.remove(); + } + } + } + + // Now add the new shortcuts to the map. + for (ShortcutInfoCompat shortcut : shortcuts) { + boolean shouldShowInContainer = shortcut.isEnabled() + && (shortcut.isDeclaredInManifest() || shortcut.isDynamic()); + if (shouldShowInContainer) { + ComponentKey targetComponent + = new ComponentKey(shortcut.getActivity(), shortcut.getUserHandle()); + deepShortcutMap.addToList(targetComponent, shortcut.getId()); + } + } + } } |