diff options
author | Sunny Goyal <sunnygoyal@google.com> | 2019-04-17 18:38:52 -0700 |
---|---|---|
committer | Sunny Goyal <sunnygoyal@google.com> | 2019-04-22 15:39:40 -0700 |
commit | 6bbf6004f8c746cc50c622ec1759f77ea76af9ef (patch) | |
tree | 0740c52b700f0f8bd96505db8b5c10acb434d81e /src/com/android | |
parent | 8b0cb4113fc34ced9a9de71e40f448615ec8210d (diff) | |
download | android_packages_apps_Trebuchet-6bbf6004f8c746cc50c622ec1759f77ea76af9ef.tar.gz android_packages_apps_Trebuchet-6bbf6004f8c746cc50c622ec1759f77ea76af9ef.tar.bz2 android_packages_apps_Trebuchet-6bbf6004f8c746cc50c622ec1759f77ea76af9ef.zip |
Removing ShortcutInfoCompat and directly using ShortcutInfo
Change-Id: I2842689e192a206c0d31558c8126eae1c7904598
Diffstat (limited to 'src/com/android')
19 files changed, 103 insertions, 211 deletions
diff --git a/src/com/android/launcher3/InstallShortcutReceiver.java b/src/com/android/launcher3/InstallShortcutReceiver.java index 418f1e485..e9b932aaf 100644 --- a/src/com/android/launcher3/InstallShortcutReceiver.java +++ b/src/com/android/launcher3/InstallShortcutReceiver.java @@ -25,6 +25,7 @@ import android.content.SharedPreferences; import android.content.pm.ActivityInfo; import android.content.pm.LauncherActivityInfo; import android.content.pm.PackageManager; +import android.content.pm.ShortcutInfo; import android.graphics.Bitmap; import android.graphics.BitmapFactory; import android.os.Handler; @@ -44,7 +45,6 @@ import com.android.launcher3.icons.BitmapInfo; import com.android.launcher3.icons.GraphicsUtils; import com.android.launcher3.icons.LauncherIcons; import com.android.launcher3.shortcuts.DeepShortcutManager; -import com.android.launcher3.shortcuts.ShortcutInfoCompat; import com.android.launcher3.shortcuts.ShortcutKey; import com.android.launcher3.util.PackageManagerHelper; import com.android.launcher3.util.Preconditions; @@ -253,7 +253,7 @@ public class InstallShortcutReceiver extends BroadcastReceiver { return (WorkspaceItemInfo) (new PendingInstallShortcutInfo(info, context).getItemInfo().first); } - public static void queueShortcut(ShortcutInfoCompat info, Context context) { + public static void queueShortcut(ShortcutInfo info, Context context) { queuePendingShortcutInfo(new PendingInstallShortcutInfo(info, context), context); } @@ -327,7 +327,7 @@ public class InstallShortcutReceiver extends BroadcastReceiver { private static class PendingInstallShortcutInfo { final LauncherActivityInfo activityInfo; - final ShortcutInfoCompat shortcutInfo; + final ShortcutInfo shortcutInfo; final AppWidgetProviderInfo providerInfo; final Intent data; @@ -372,7 +372,7 @@ public class InstallShortcutReceiver extends BroadcastReceiver { /** * Initializes a PendingInstallShortcutInfo to represent a launcher target. */ - public PendingInstallShortcutInfo(ShortcutInfoCompat info, Context context) { + public PendingInstallShortcutInfo(ShortcutInfo info, Context context) { activityInfo = null; shortcutInfo = info; providerInfo = null; @@ -381,7 +381,7 @@ public class InstallShortcutReceiver extends BroadcastReceiver { mContext = context; user = info.getUserHandle(); - launchIntent = info.makeIntent(); + launchIntent = ShortcutKey.makeIntent(info); label = info.getShortLabel().toString(); } @@ -537,10 +537,10 @@ public class InstallShortcutReceiver extends BroadcastReceiver { return info == null ? null : new PendingInstallShortcutInfo(info, context); } else if (decoder.optBoolean(DEEPSHORTCUT_TYPE_KEY)) { DeepShortcutManager sm = DeepShortcutManager.getInstance(context); - List<ShortcutInfoCompat> si = sm.queryForFullDetails( + List<ShortcutInfo> si = sm.queryForFullDetails( decoder.launcherIntent.getPackage(), Arrays.asList(decoder.launcherIntent.getStringExtra( - ShortcutInfoCompat.EXTRA_SHORTCUT_ID)), + ShortcutKey.EXTRA_SHORTCUT_ID)), decoder.user); if (si.isEmpty()) { return null; diff --git a/src/com/android/launcher3/LauncherModel.java b/src/com/android/launcher3/LauncherModel.java index dfbe0fe01..e7b4ff4fe 100644 --- a/src/com/android/launcher3/LauncherModel.java +++ b/src/com/android/launcher3/LauncherModel.java @@ -22,6 +22,7 @@ import static com.android.launcher3.config.FeatureFlags.IS_DOGFOOD_BUILD; import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent; +import android.content.pm.ShortcutInfo; import android.os.Handler; import android.os.HandlerThread; import android.os.Looper; @@ -48,7 +49,6 @@ import com.android.launcher3.model.PackageUpdatedTask; import com.android.launcher3.model.ShortcutsChangedTask; import com.android.launcher3.model.UserLockStateChangedTask; import com.android.launcher3.shortcuts.DeepShortcutManager; -import com.android.launcher3.shortcuts.ShortcutInfoCompat; import com.android.launcher3.util.ComponentKey; import com.android.launcher3.util.IntArray; import com.android.launcher3.util.ItemInfoMatcher; @@ -267,12 +267,12 @@ public class LauncherModel extends BroadcastReceiver } @Override - public void onShortcutsChanged(String packageName, List<ShortcutInfoCompat> shortcuts, + public void onShortcutsChanged(String packageName, List<ShortcutInfo> shortcuts, UserHandle user) { enqueueModelUpdateTask(new ShortcutsChangedTask(packageName, shortcuts, user, true)); } - public void updatePinnedShortcuts(String packageName, List<ShortcutInfoCompat> shortcuts, + public void updatePinnedShortcuts(String packageName, List<ShortcutInfo> shortcuts, UserHandle user) { enqueueModelUpdateTask(new ShortcutsChangedTask(packageName, shortcuts, user, false)); } @@ -530,7 +530,7 @@ public class LauncherModel extends BroadcastReceiver } - public void updateAndBindWorkspaceItem(WorkspaceItemInfo si, ShortcutInfoCompat info) { + public void updateAndBindWorkspaceItem(WorkspaceItemInfo si, ShortcutInfo info) { updateAndBindWorkspaceItem(() -> { si.updateFromDeepShortcutInfo(info, mApp.getContext()); LauncherIcons li = LauncherIcons.obtain(mApp.getContext()); diff --git a/src/com/android/launcher3/Utilities.java b/src/com/android/launcher3/Utilities.java index fd4b5086b..9a3f346f8 100644 --- a/src/com/android/launcher3/Utilities.java +++ b/src/com/android/launcher3/Utilities.java @@ -32,6 +32,7 @@ import android.content.pm.PackageInfo; import android.content.pm.PackageManager; import android.content.pm.PackageManager.NameNotFoundException; import android.content.pm.ResolveInfo; +import android.content.pm.ShortcutInfo; import android.content.res.Resources; import android.graphics.Matrix; import android.graphics.Paint; @@ -66,7 +67,6 @@ import com.android.launcher3.dragndrop.FolderAdaptiveIcon; import com.android.launcher3.folder.FolderIcon; import com.android.launcher3.shortcuts.DeepShortcutManager; import com.android.launcher3.shortcuts.DeepShortcutView; -import com.android.launcher3.shortcuts.ShortcutInfoCompat; import com.android.launcher3.shortcuts.ShortcutKey; import com.android.launcher3.util.IntArray; import com.android.launcher3.widget.PendingAddShortcutInfo; @@ -626,7 +626,7 @@ public final class Utilities { /** * Returns the full drawable for {@param info}. * @param outObj this is set to the internal data associated with {@param info}, - * eg {@link LauncherActivityInfo} or {@link ShortcutInfoCompat}. + * eg {@link LauncherActivityInfo} or {@link ShortcutInfo}. */ public static Drawable getFullDrawable(Launcher launcher, ItemInfo info, int width, int height, boolean flattenDrawable, Object[] outObj) { @@ -646,7 +646,7 @@ public final class Utilities { } ShortcutKey key = ShortcutKey.fromItemInfo(info); DeepShortcutManager sm = DeepShortcutManager.getInstance(launcher); - List<ShortcutInfoCompat> si = sm.queryForFullDetails( + List<ShortcutInfo> si = sm.queryForFullDetails( key.componentName.getPackageName(), Arrays.asList(key.getId()), key.user); if (si.isEmpty()) { return null; diff --git a/src/com/android/launcher3/WorkspaceItemInfo.java b/src/com/android/launcher3/WorkspaceItemInfo.java index d0e887311..5a2373b99 100644 --- a/src/com/android/launcher3/WorkspaceItemInfo.java +++ b/src/com/android/launcher3/WorkspaceItemInfo.java @@ -19,11 +19,12 @@ package com.android.launcher3; import android.content.ComponentName; import android.content.Context; import android.content.Intent; +import android.content.pm.ShortcutInfo; import android.text.TextUtils; import com.android.launcher3.LauncherSettings.Favorites; import com.android.launcher3.icons.IconCache; -import com.android.launcher3.shortcuts.ShortcutInfoCompat; +import com.android.launcher3.shortcuts.ShortcutKey; import com.android.launcher3.util.ContentWriter; /** @@ -107,9 +108,9 @@ public class WorkspaceItemInfo extends ItemInfoWithIcon { } /** - * Creates a {@link WorkspaceItemInfo} from a {@link ShortcutInfoCompat}. + * Creates a {@link WorkspaceItemInfo} from a {@link ShortcutInfo}. */ - public WorkspaceItemInfo(ShortcutInfoCompat shortcutInfo, Context context) { + public WorkspaceItemInfo(ShortcutInfo shortcutInfo, Context context) { user = shortcutInfo.getUserHandle(); itemType = Favorites.ITEM_TYPE_DEEP_SHORTCUT; updateFromDeepShortcutInfo(shortcutInfo, context); @@ -158,9 +159,9 @@ public class WorkspaceItemInfo extends ItemInfoWithIcon { status |= FLAG_INSTALL_SESSION_ACTIVE; } - public void updateFromDeepShortcutInfo(ShortcutInfoCompat shortcutInfo, Context context) { - // {@link ShortcutInfoCompat#getActivity} can change during an update. Recreate the intent - intent = shortcutInfo.makeIntent(); + public void updateFromDeepShortcutInfo(ShortcutInfo shortcutInfo, Context context) { + // {@link ShortcutInfo#getActivity} can change during an update. Recreate the intent + intent = ShortcutKey.makeIntent(shortcutInfo); title = shortcutInfo.getShortLabel(); CharSequence label = shortcutInfo.getLongLabel(); @@ -179,7 +180,7 @@ public class WorkspaceItemInfo extends ItemInfoWithIcon { /** Returns the WorkspaceItemInfo id associated with the deep shortcut. */ public String getDeepShortcutId() { return itemType == Favorites.ITEM_TYPE_DEEP_SHORTCUT ? - getIntent().getStringExtra(ShortcutInfoCompat.EXTRA_SHORTCUT_ID) : null; + getIntent().getStringExtra(ShortcutKey.EXTRA_SHORTCUT_ID) : null; } @Override diff --git a/src/com/android/launcher3/compat/LauncherAppsCompat.java b/src/com/android/launcher3/compat/LauncherAppsCompat.java index e7d467968..4275f312b 100644 --- a/src/com/android/launcher3/compat/LauncherAppsCompat.java +++ b/src/com/android/launcher3/compat/LauncherAppsCompat.java @@ -21,12 +21,12 @@ import android.content.Context; import android.content.Intent; import android.content.pm.ApplicationInfo; import android.content.pm.LauncherActivityInfo; +import android.content.pm.ShortcutInfo; import android.graphics.Rect; import android.os.Bundle; import android.os.UserHandle; import com.android.launcher3.Utilities; -import com.android.launcher3.shortcuts.ShortcutInfoCompat; import com.android.launcher3.util.PackageUserKey; import java.util.List; @@ -43,7 +43,7 @@ public abstract class LauncherAppsCompat { void onPackagesUnavailable(String[] packageNames, UserHandle user, boolean replacing); void onPackagesSuspended(String[] packageNames, UserHandle user); void onPackagesUnsuspended(String[] packageNames, UserHandle user); - void onShortcutsChanged(String packageName, List<ShortcutInfoCompat> shortcuts, + void onShortcutsChanged(String packageName, List<ShortcutInfo> shortcuts, UserHandle user); } diff --git a/src/com/android/launcher3/compat/LauncherAppsCompatVL.java b/src/com/android/launcher3/compat/LauncherAppsCompatVL.java index b6413918f..fc48ba756 100644 --- a/src/com/android/launcher3/compat/LauncherAppsCompatVL.java +++ b/src/com/android/launcher3/compat/LauncherAppsCompatVL.java @@ -32,7 +32,6 @@ import android.os.UserHandle; import android.util.ArrayMap; import com.android.launcher3.compat.ShortcutConfigActivityInfo.ShortcutConfigActivityInfoVL; -import com.android.launcher3.shortcuts.ShortcutInfoCompat; import com.android.launcher3.util.PackageUserKey; import java.util.ArrayList; @@ -179,12 +178,7 @@ public class LauncherAppsCompatVL extends LauncherAppsCompat { public void onShortcutsChanged(@NonNull String packageName, @NonNull List<ShortcutInfo> shortcuts, @NonNull UserHandle user) { - List<ShortcutInfoCompat> shortcutInfoCompats = new ArrayList<>(shortcuts.size()); - for (ShortcutInfo shortcutInfo : shortcuts) { - shortcutInfoCompats.add(new ShortcutInfoCompat(shortcutInfo)); - } - - mCallback.onShortcutsChanged(packageName, shortcutInfoCompats, user); + mCallback.onShortcutsChanged(packageName, shortcuts, user); } } diff --git a/src/com/android/launcher3/compat/LauncherAppsCompatVO.java b/src/com/android/launcher3/compat/LauncherAppsCompatVO.java index b64fff49a..6e7a1bdcf 100644 --- a/src/com/android/launcher3/compat/LauncherAppsCompatVO.java +++ b/src/com/android/launcher3/compat/LauncherAppsCompatVO.java @@ -24,6 +24,7 @@ import android.content.pm.LauncherActivityInfo; import android.content.pm.LauncherApps; import android.content.pm.LauncherApps.PinItemRequest; import android.content.pm.PackageManager; +import android.content.pm.ShortcutInfo; import android.os.Build; import android.os.Parcelable; import android.os.Process; @@ -34,7 +35,6 @@ import com.android.launcher3.LauncherModel; import com.android.launcher3.WorkspaceItemInfo; import com.android.launcher3.compat.ShortcutConfigActivityInfo.ShortcutConfigActivityInfoVO; import com.android.launcher3.icons.LauncherIcons; -import com.android.launcher3.shortcuts.ShortcutInfoCompat; import com.android.launcher3.util.LooperExecutor; import com.android.launcher3.util.PackageUserKey; @@ -135,14 +135,14 @@ public class LauncherAppsCompatVO extends LauncherAppsCompatVL { }); } - ShortcutInfoCompat compat = new ShortcutInfoCompat(request.getShortcutInfo()); - WorkspaceItemInfo info = new WorkspaceItemInfo(compat, context); + ShortcutInfo si = request.getShortcutInfo(); + WorkspaceItemInfo info = new WorkspaceItemInfo(si, context); // Apply the unbadged icon and fetch the actual icon asynchronously. LauncherIcons li = LauncherIcons.obtain(context); - info.applyFrom(li.createShortcutIcon(compat, false /* badged */)); + info.applyFrom(li.createShortcutIcon(si, false /* badged */)); li.recycle(); LauncherAppState.getInstance(context).getModel() - .updateAndBindWorkspaceItem(info, compat); + .updateAndBindWorkspaceItem(info, si); return info; } else { return null; diff --git a/src/com/android/launcher3/dragndrop/AddItemActivity.java b/src/com/android/launcher3/dragndrop/AddItemActivity.java index 5ac986787..a72089d7c 100644 --- a/src/com/android/launcher3/dragndrop/AddItemActivity.java +++ b/src/com/android/launcher3/dragndrop/AddItemActivity.java @@ -52,7 +52,6 @@ import com.android.launcher3.R; import com.android.launcher3.compat.AppWidgetManagerCompat; import com.android.launcher3.compat.LauncherAppsCompatVO; import com.android.launcher3.model.WidgetItem; -import com.android.launcher3.shortcuts.ShortcutInfoCompat; import com.android.launcher3.userevent.nano.LauncherLogProto.Action; import com.android.launcher3.userevent.nano.LauncherLogProto.ContainerType; import com.android.launcher3.util.InstantAppResolver; @@ -250,8 +249,7 @@ public class AddItemActivity extends BaseActivity implements OnLongClickListener */ public void onPlaceAutomaticallyClick(View v) { if (mRequest.getRequestType() == PinItemRequest.REQUEST_TYPE_SHORTCUT) { - InstallShortcutReceiver.queueShortcut( - new ShortcutInfoCompat(mRequest.getShortcutInfo()), this); + InstallShortcutReceiver.queueShortcut(mRequest.getShortcutInfo(), this); logCommand(Action.Command.CONFIRM); mRequest.accept(); finish(); diff --git a/src/com/android/launcher3/dragndrop/DragView.java b/src/com/android/launcher3/dragndrop/DragView.java index bdbea2992..3ab97b0d9 100644 --- a/src/com/android/launcher3/dragndrop/DragView.java +++ b/src/com/android/launcher3/dragndrop/DragView.java @@ -24,6 +24,7 @@ import android.animation.FloatArrayEvaluator; import android.animation.ValueAnimator; import android.animation.ValueAnimator.AnimatorUpdateListener; import android.annotation.TargetApi; +import android.content.pm.ShortcutInfo; import android.graphics.Bitmap; import android.graphics.Canvas; import android.graphics.Color; @@ -54,7 +55,6 @@ import com.android.launcher3.Utilities; import com.android.launcher3.FirstFrameAnimatorHelper; import com.android.launcher3.anim.Interpolators; import com.android.launcher3.icons.LauncherIcons; -import com.android.launcher3.shortcuts.ShortcutInfoCompat; import com.android.launcher3.util.Themes; import com.android.launcher3.util.Thunk; @@ -321,11 +321,11 @@ public class DragView extends View { boolean iconBadged = (info instanceof ItemInfoWithIcon) && (((ItemInfoWithIcon) info).runtimeStatusFlags & FLAG_ICON_BADGED) > 0; if ((info.id == ItemInfo.NO_ID && !iconBadged) - || !(obj instanceof ShortcutInfoCompat)) { + || !(obj instanceof ShortcutInfo)) { // The item is not yet added on home screen. return new FixedSizeEmptyDrawable(iconSize); } - ShortcutInfoCompat si = (ShortcutInfoCompat) obj; + ShortcutInfo si = (ShortcutInfo) obj; LauncherIcons li = LauncherIcons.obtain(appState.getContext()); Bitmap badge = li.getShortcutInfoBadge(si, appState.getIconCache()).iconBitmap; li.recycle(); diff --git a/src/com/android/launcher3/icons/LauncherIcons.java b/src/com/android/launcher3/icons/LauncherIcons.java index 75f76d93c..5c4af1fe6 100644 --- a/src/com/android/launcher3/icons/LauncherIcons.java +++ b/src/com/android/launcher3/icons/LauncherIcons.java @@ -19,6 +19,7 @@ package com.android.launcher3.icons; import android.content.ComponentName; import android.content.Context; import android.content.Intent; +import android.content.pm.ShortcutInfo; import android.graphics.Bitmap; import android.graphics.drawable.Drawable; import android.os.Process; @@ -28,9 +29,9 @@ import com.android.launcher3.FastBitmapDrawable; import com.android.launcher3.InvariantDeviceProfile; import com.android.launcher3.ItemInfoWithIcon; import com.android.launcher3.LauncherAppState; +import com.android.launcher3.R; import com.android.launcher3.model.PackageItemInfo; import com.android.launcher3.shortcuts.DeepShortcutManager; -import com.android.launcher3.shortcuts.ShortcutInfoCompat; import com.android.launcher3.util.Themes; import java.util.function.Supplier; @@ -43,6 +44,8 @@ import androidx.annotation.Nullable; */ public class LauncherIcons extends BaseIconFactory implements AutoCloseable { + private static final String EXTRA_BADGEPKG = "badge_package"; + private static final Object sPoolSync = new Object(); private static LauncherIcons sPool; private static int sPoolId = 0; @@ -106,15 +109,15 @@ public class LauncherIcons extends BaseIconFactory implements AutoCloseable { // below methods should also migrate to BaseIconFactory - public BitmapInfo createShortcutIcon(ShortcutInfoCompat shortcutInfo) { + public BitmapInfo createShortcutIcon(ShortcutInfo shortcutInfo) { return createShortcutIcon(shortcutInfo, true /* badged */); } - public BitmapInfo createShortcutIcon(ShortcutInfoCompat shortcutInfo, boolean badged) { + public BitmapInfo createShortcutIcon(ShortcutInfo shortcutInfo, boolean badged) { return createShortcutIcon(shortcutInfo, badged, null); } - public BitmapInfo createShortcutIcon(ShortcutInfoCompat shortcutInfo, + public BitmapInfo createShortcutIcon(ShortcutInfo shortcutInfo, boolean badged, @Nullable Supplier<ItemInfoWithIcon> fallbackIconProvider) { Drawable unbadgedDrawable = DeepShortcutManager.getInstance(mContext) .getShortcutIconDrawable(shortcutInfo, mFillResIconDpi); @@ -155,9 +158,9 @@ public class LauncherIcons extends BaseIconFactory implements AutoCloseable { return result; } - public ItemInfoWithIcon getShortcutInfoBadge(ShortcutInfoCompat shortcutInfo, IconCache cache) { + public ItemInfoWithIcon getShortcutInfoBadge(ShortcutInfo shortcutInfo, IconCache cache) { ComponentName cn = shortcutInfo.getActivity(); - String badgePkg = shortcutInfo.getBadgePackage(mContext); + String badgePkg = getBadgePackage(shortcutInfo); boolean hasBadgePkgSet = !badgePkg.equals(shortcutInfo.getPackage()); if (cn != null && !hasBadgePkgSet) { // Get the app info for the source activity. @@ -175,4 +178,13 @@ public class LauncherIcons extends BaseIconFactory implements AutoCloseable { return pkgInfo; } } + + private String getBadgePackage(ShortcutInfo si) { + String whitelistedPkg = mContext.getString(R.string.shortcutinfo_badgepkg_whitelist); + if (whitelistedPkg.equals(si.getPackage()) + && si.getExtras().containsKey(EXTRA_BADGEPKG)) { + return si.getExtras().getString(EXTRA_BADGEPKG); + } + return si.getPackage(); + } } diff --git a/src/com/android/launcher3/model/BgDataModel.java b/src/com/android/launcher3/model/BgDataModel.java index b0cc87b30..8f0cd08a9 100644 --- a/src/com/android/launcher3/model/BgDataModel.java +++ b/src/com/android/launcher3/model/BgDataModel.java @@ -16,6 +16,7 @@ package com.android.launcher3.model; import android.content.Context; +import android.content.pm.ShortcutInfo; import android.os.UserHandle; import android.text.TextUtils; import android.util.Log; @@ -34,7 +35,6 @@ import com.android.launcher3.model.nano.LauncherDumpProto; import com.android.launcher3.model.nano.LauncherDumpProto.ContainerType; import com.android.launcher3.model.nano.LauncherDumpProto.DumpTarget; import com.android.launcher3.shortcuts.DeepShortcutManager; -import com.android.launcher3.shortcuts.ShortcutInfoCompat; import com.android.launcher3.shortcuts.ShortcutKey; import com.android.launcher3.util.ComponentKey; import com.android.launcher3.util.IntArray; @@ -366,7 +366,7 @@ public class BgDataModel { * Clear all the deep shortcut counts for the given package, and re-add the new shortcut counts. */ public synchronized void updateDeepShortcutCounts( - String packageName, UserHandle user, List<ShortcutInfoCompat> shortcuts) { + String packageName, UserHandle user, List<ShortcutInfo> shortcuts) { if (packageName != null) { Iterator<ComponentKey> keysIter = deepShortcutMap.keySet().iterator(); while (keysIter.hasNext()) { @@ -379,7 +379,7 @@ public class BgDataModel { } // Now add the new shortcuts to the map. - for (ShortcutInfoCompat shortcut : shortcuts) { + for (ShortcutInfo shortcut : shortcuts) { boolean shouldShowInContainer = shortcut.isEnabled() && (shortcut.isDeclaredInManifest() || shortcut.isDynamic()); if (shouldShowInContainer) { diff --git a/src/com/android/launcher3/model/LoaderTask.java b/src/com/android/launcher3/model/LoaderTask.java index f8c48ed5f..0138572d0 100644 --- a/src/com/android/launcher3/model/LoaderTask.java +++ b/src/com/android/launcher3/model/LoaderTask.java @@ -30,6 +30,7 @@ import android.content.IntentFilter; import android.content.pm.LauncherActivityInfo; import android.content.pm.PackageInstaller; import android.content.pm.PackageInstaller.SessionInfo; +import android.content.pm.ShortcutInfo; import android.os.Handler; import android.os.Process; import android.os.UserHandle; @@ -66,7 +67,6 @@ import com.android.launcher3.icons.cache.IconCacheUpdateHandler; import com.android.launcher3.logging.FileLog; import com.android.launcher3.provider.ImportDataTask; import com.android.launcher3.shortcuts.DeepShortcutManager; -import com.android.launcher3.shortcuts.ShortcutInfoCompat; import com.android.launcher3.shortcuts.ShortcutKey; import com.android.launcher3.util.ComponentKey; import com.android.launcher3.util.LooperIdleLock; @@ -285,7 +285,7 @@ public class LoaderTask implements Runnable { mPackageInstaller.updateAndGetActiveSessionCache(); mFirstScreenBroadcast = new FirstScreenBroadcast(installingPkgs); - Map<ShortcutKey, ShortcutInfoCompat> shortcutKeyToPinnedShortcuts = new HashMap<>(); + Map<ShortcutKey, ShortcutInfo> shortcutKeyToPinnedShortcuts = new HashMap<>(); final LoaderCursor c = new LoaderCursor(contentResolver.query( LauncherSettings.Favorites.CONTENT_URI, null, null, null, null), mApp); @@ -317,10 +317,10 @@ public class LoaderTask implements Runnable { // We can only query for shortcuts when the user is unlocked. if (userUnlocked) { - List<ShortcutInfoCompat> pinnedShortcuts = + List<ShortcutInfo> pinnedShortcuts = mShortcutManager.queryForPinnedShortcuts(null, user); if (mShortcutManager.wasLastCallSuccess()) { - for (ShortcutInfoCompat shortcut : pinnedShortcuts) { + for (ShortcutInfo shortcut : pinnedShortcuts) { shortcutKeyToPinnedShortcuts.put(ShortcutKey.fromInfo(shortcut), shortcut); } @@ -473,7 +473,7 @@ public class LoaderTask implements Runnable { ShortcutKey key = ShortcutKey.fromIntent(intent, c.user); if (unlockedUsers.get(c.serialNumber)) { - ShortcutInfoCompat pinnedShortcut = + ShortcutInfo pinnedShortcut = shortcutKeyToPinnedShortcuts.get(key); if (pinnedShortcut == null) { // The shortcut is no longer valid. @@ -839,7 +839,7 @@ public class LoaderTask implements Runnable { if (mBgDataModel.hasShortcutHostPermission) { for (UserHandle user : mUserManager.getUserProfiles()) { if (mUserManager.isUserUnlocked(user)) { - List<ShortcutInfoCompat> shortcuts = + List<ShortcutInfo> shortcuts = mShortcutManager.queryForAllShortcuts(user); mBgDataModel.updateDeepShortcutCounts(null, user, shortcuts); } diff --git a/src/com/android/launcher3/model/PackageUpdatedTask.java b/src/com/android/launcher3/model/PackageUpdatedTask.java index 671dc542c..c37ed9952 100644 --- a/src/com/android/launcher3/model/PackageUpdatedTask.java +++ b/src/com/android/launcher3/model/PackageUpdatedTask.java @@ -18,6 +18,7 @@ package com.android.launcher3.model; import android.content.ComponentName; import android.content.Context; import android.content.Intent; +import android.content.pm.ShortcutInfo; import android.os.Process; import android.os.UserHandle; import android.util.Log; @@ -42,7 +43,6 @@ import com.android.launcher3.icons.BitmapInfo; import com.android.launcher3.icons.LauncherIcons; import com.android.launcher3.logging.FileLog; import com.android.launcher3.shortcuts.DeepShortcutManager; -import com.android.launcher3.shortcuts.ShortcutInfoCompat; import com.android.launcher3.util.FlagOp; import com.android.launcher3.util.IntSparseArrayMap; import com.android.launcher3.util.ItemInfoMatcher; @@ -213,7 +213,7 @@ public class PackageUpdatedTask extends BaseModelUpdateTask { if (si.isPromise() && isNewApkAvailable) { boolean isTargetValid = true; if (si.itemType == Favorites.ITEM_TYPE_DEEP_SHORTCUT) { - List<ShortcutInfoCompat> shortcut = DeepShortcutManager + List<ShortcutInfo> shortcut = DeepShortcutManager .getInstance(context).queryForPinnedShortcuts( cn.getPackageName(), Arrays.asList(si.getDeepShortcutId()), mUser); diff --git a/src/com/android/launcher3/model/ShortcutsChangedTask.java b/src/com/android/launcher3/model/ShortcutsChangedTask.java index 6adcc6e55..8528228f2 100644 --- a/src/com/android/launcher3/model/ShortcutsChangedTask.java +++ b/src/com/android/launcher3/model/ShortcutsChangedTask.java @@ -16,6 +16,7 @@ package com.android.launcher3.model; import android.content.Context; +import android.content.pm.ShortcutInfo; import android.os.UserHandle; import com.android.launcher3.AllAppsList; @@ -25,7 +26,6 @@ import com.android.launcher3.LauncherSettings; import com.android.launcher3.WorkspaceItemInfo; import com.android.launcher3.icons.LauncherIcons; import com.android.launcher3.shortcuts.DeepShortcutManager; -import com.android.launcher3.shortcuts.ShortcutInfoCompat; import com.android.launcher3.shortcuts.ShortcutKey; import com.android.launcher3.util.ItemInfoMatcher; import com.android.launcher3.util.MultiHashMap; @@ -40,11 +40,11 @@ import java.util.List; public class ShortcutsChangedTask extends BaseModelUpdateTask { private final String mPackageName; - private final List<ShortcutInfoCompat> mShortcuts; + private final List<ShortcutInfo> mShortcuts; private final UserHandle mUser; private final boolean mUpdateIdMap; - public ShortcutsChangedTask(String packageName, List<ShortcutInfoCompat> shortcuts, + public ShortcutsChangedTask(String packageName, List<ShortcutInfo> shortcuts, UserHandle user, boolean updateIdMap) { mPackageName = packageName; mShortcuts = shortcuts; @@ -56,7 +56,6 @@ public class ShortcutsChangedTask extends BaseModelUpdateTask { public void execute(LauncherAppState app, BgDataModel dataModel, AllAppsList apps) { final Context context = app.getContext(); DeepShortcutManager deepShortcutManager = DeepShortcutManager.getInstance(context); - deepShortcutManager.onShortcutsChanged(mShortcuts); // Find WorkspaceItemInfo's that have changed on the workspace. HashSet<ShortcutKey> removedKeys = new HashSet<>(); @@ -76,9 +75,9 @@ public class ShortcutsChangedTask extends BaseModelUpdateTask { final ArrayList<WorkspaceItemInfo> updatedWorkspaceItemInfos = new ArrayList<>(); if (!keyToShortcutInfo.isEmpty()) { // Update the workspace to reflect the changes to updated shortcuts residing on it. - List<ShortcutInfoCompat> shortcuts = deepShortcutManager.queryForFullDetails( + List<ShortcutInfo> shortcuts = deepShortcutManager.queryForFullDetails( mPackageName, new ArrayList<>(allIds), mUser); - for (ShortcutInfoCompat fullDetails : shortcuts) { + for (ShortcutInfo fullDetails : shortcuts) { ShortcutKey key = ShortcutKey.fromInfo(fullDetails); List<WorkspaceItemInfo> workspaceItemInfos = keyToShortcutInfo.remove(key); if (!fullDetails.isPinned()) { diff --git a/src/com/android/launcher3/model/UserLockStateChangedTask.java b/src/com/android/launcher3/model/UserLockStateChangedTask.java index 478800e44..2cb256e09 100644 --- a/src/com/android/launcher3/model/UserLockStateChangedTask.java +++ b/src/com/android/launcher3/model/UserLockStateChangedTask.java @@ -18,6 +18,7 @@ package com.android.launcher3.model; import static com.android.launcher3.ItemInfoWithIcon.FLAG_DISABLED_LOCKED_USER; import android.content.Context; +import android.content.pm.ShortcutInfo; import android.os.UserHandle; import com.android.launcher3.AllAppsList; @@ -28,7 +29,6 @@ import com.android.launcher3.WorkspaceItemInfo; import com.android.launcher3.compat.UserManagerCompat; import com.android.launcher3.icons.LauncherIcons; import com.android.launcher3.shortcuts.DeepShortcutManager; -import com.android.launcher3.shortcuts.ShortcutInfoCompat; import com.android.launcher3.shortcuts.ShortcutKey; import com.android.launcher3.util.ComponentKey; import com.android.launcher3.util.ItemInfoMatcher; @@ -56,12 +56,12 @@ public class UserLockStateChangedTask extends BaseModelUpdateTask { boolean isUserUnlocked = UserManagerCompat.getInstance(context).isUserUnlocked(mUser); DeepShortcutManager deepShortcutManager = DeepShortcutManager.getInstance(context); - HashMap<ShortcutKey, ShortcutInfoCompat> pinnedShortcuts = new HashMap<>(); + HashMap<ShortcutKey, ShortcutInfo> pinnedShortcuts = new HashMap<>(); if (isUserUnlocked) { - List<ShortcutInfoCompat> shortcuts = + List<ShortcutInfo> shortcuts = deepShortcutManager.queryForPinnedShortcuts(null, mUser); if (deepShortcutManager.wasLastCallSuccess()) { - for (ShortcutInfoCompat shortcut : shortcuts) { + for (ShortcutInfo shortcut : shortcuts) { pinnedShortcuts.put(ShortcutKey.fromInfo(shortcut), shortcut); } } else { @@ -82,7 +82,7 @@ public class UserLockStateChangedTask extends BaseModelUpdateTask { WorkspaceItemInfo si = (WorkspaceItemInfo) itemInfo; if (isUserUnlocked) { ShortcutKey key = ShortcutKey.fromItemInfo(si); - ShortcutInfoCompat shortcut = pinnedShortcuts.get(key); + ShortcutInfo shortcut = pinnedShortcuts.get(key); // We couldn't verify the shortcut during loader. If its no longer available // (probably due to clear data), delete the workspace item as well if (shortcut == null) { diff --git a/src/com/android/launcher3/popup/PopupPopulator.java b/src/com/android/launcher3/popup/PopupPopulator.java index 2b55405c0..dbfe9882f 100644 --- a/src/com/android/launcher3/popup/PopupPopulator.java +++ b/src/com/android/launcher3/popup/PopupPopulator.java @@ -17,6 +17,7 @@ package com.android.launcher3.popup; import android.content.ComponentName; +import android.content.pm.ShortcutInfo; import android.os.Handler; import android.os.UserHandle; import android.service.notification.StatusBarNotification; @@ -29,7 +30,6 @@ import com.android.launcher3.notification.NotificationInfo; import com.android.launcher3.notification.NotificationKeyData; import com.android.launcher3.shortcuts.DeepShortcutManager; import com.android.launcher3.shortcuts.DeepShortcutView; -import com.android.launcher3.shortcuts.ShortcutInfoCompat; import com.android.launcher3.util.PackageUserKey; import java.util.ArrayList; @@ -54,10 +54,10 @@ public class PopupPopulator { /** * Sorts shortcuts in rank order, with manifest shortcuts coming before dynamic shortcuts. */ - private static final Comparator<ShortcutInfoCompat> SHORTCUT_RANK_COMPARATOR - = new Comparator<ShortcutInfoCompat>() { + private static final Comparator<ShortcutInfo> SHORTCUT_RANK_COMPARATOR + = new Comparator<ShortcutInfo>() { @Override - public int compare(ShortcutInfoCompat a, ShortcutInfoCompat b) { + public int compare(ShortcutInfo a, ShortcutInfo b) { if (a.isDeclaredInManifest() && !b.isDeclaredInManifest()) { return -1; } @@ -76,11 +76,11 @@ public class PopupPopulator { * @param shortcutIdToRemoveFirst An id that should be filtered out first, if any. * @return a subset of shortcuts, in sorted order, with size <= MAX_SHORTCUTS. */ - public static List<ShortcutInfoCompat> sortAndFilterShortcuts( - List<ShortcutInfoCompat> shortcuts, @Nullable String shortcutIdToRemoveFirst) { + public static List<ShortcutInfo> sortAndFilterShortcuts( + List<ShortcutInfo> shortcuts, @Nullable String shortcutIdToRemoveFirst) { // Remove up to one specific shortcut before sorting and doing somewhat fancy filtering. if (shortcutIdToRemoveFirst != null) { - Iterator<ShortcutInfoCompat> shortcutIterator = shortcuts.iterator(); + Iterator<ShortcutInfo> shortcutIterator = shortcuts.iterator(); while (shortcutIterator.hasNext()) { if (shortcutIterator.next().getId().equals(shortcutIdToRemoveFirst)) { shortcutIterator.remove(); @@ -96,11 +96,11 @@ public class PopupPopulator { // The list of shortcuts is now sorted with static shortcuts followed by dynamic // shortcuts. We want to preserve this order, but only keep MAX_SHORTCUTS. - List<ShortcutInfoCompat> filteredShortcuts = new ArrayList<>(MAX_SHORTCUTS); + List<ShortcutInfo> filteredShortcuts = new ArrayList<>(MAX_SHORTCUTS); int numDynamic = 0; int size = shortcuts.size(); for (int i = 0; i < size; i++) { - ShortcutInfoCompat shortcut = shortcuts.get(i); + ShortcutInfo shortcut = shortcuts.get(i); int filteredSize = filteredShortcuts.size(); if (filteredSize < MAX_SHORTCUTS) { // Always add the first MAX_SHORTCUTS to the filtered list. @@ -140,13 +140,13 @@ public class PopupPopulator { uiHandler.post(() -> container.applyNotificationInfos(infos)); } - List<ShortcutInfoCompat> shortcuts = DeepShortcutManager.getInstance(launcher) + List<ShortcutInfo> shortcuts = DeepShortcutManager.getInstance(launcher) .queryForShortcutsContainer(activity, user); String shortcutIdToDeDupe = notificationKeys.isEmpty() ? null : notificationKeys.get(0).shortcutId; shortcuts = PopupPopulator.sortAndFilterShortcuts(shortcuts, shortcutIdToDeDupe); for (int i = 0; i < shortcuts.size() && i < shortcutViews.size(); i++) { - final ShortcutInfoCompat shortcut = shortcuts.get(i); + final ShortcutInfo shortcut = shortcuts.get(i); final WorkspaceItemInfo si = new WorkspaceItemInfo(shortcut, launcher); // Use unbadged icon for the menu. LauncherIcons li = LauncherIcons.obtain(launcher); diff --git a/src/com/android/launcher3/shortcuts/DeepShortcutView.java b/src/com/android/launcher3/shortcuts/DeepShortcutView.java index 199d9c808..9274d442b 100644 --- a/src/com/android/launcher3/shortcuts/DeepShortcutView.java +++ b/src/com/android/launcher3/shortcuts/DeepShortcutView.java @@ -17,6 +17,7 @@ package com.android.launcher3.shortcuts; import android.content.Context; +import android.content.pm.ShortcutInfo; import android.graphics.Point; import android.text.TextUtils; import android.util.AttributeSet; @@ -43,7 +44,7 @@ public class DeepShortcutView extends FrameLayout { private View mDivider; private WorkspaceItemInfo mInfo; - private ShortcutInfoCompat mDetail; + private ShortcutInfo mDetail; public DeepShortcutView(Context context) { this(context, null, 0); @@ -93,7 +94,7 @@ public class DeepShortcutView extends FrameLayout { } /** package private **/ - public void applyShortcutInfo(WorkspaceItemInfo info, ShortcutInfoCompat detail, + public void applyShortcutInfo(WorkspaceItemInfo info, ShortcutInfo detail, PopupContainerWithArrow container) { mInfo = info; mDetail = detail; @@ -130,7 +131,7 @@ public class DeepShortcutView extends FrameLayout { return mIconView; } - public ShortcutInfoCompat getDetail() { + public ShortcutInfo getDetail() { return mDetail; } } diff --git a/src/com/android/launcher3/shortcuts/ShortcutInfoCompat.java b/src/com/android/launcher3/shortcuts/ShortcutInfoCompat.java deleted file mode 100644 index 5ec199714..000000000 --- a/src/com/android/launcher3/shortcuts/ShortcutInfoCompat.java +++ /dev/null @@ -1,125 +0,0 @@ -/* - * Copyright (C) 2016 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.android.launcher3.shortcuts; - -import android.content.ComponentName; -import android.content.Context; -import android.content.Intent; -import android.content.pm.ShortcutInfo; -import android.os.UserHandle; - -import com.android.launcher3.R; -import com.android.launcher3.WorkspaceItemInfo; - -/** - * Wrapper class for {@link android.content.pm.ShortcutInfo}, representing deep shortcuts into apps. - * - * Not to be confused with {@link WorkspaceItemInfo}. - */ -public class ShortcutInfoCompat { - private static final String INTENT_CATEGORY = "com.android.launcher3.DEEP_SHORTCUT"; - private static final String EXTRA_BADGEPKG = "badge_package"; - public static final String EXTRA_SHORTCUT_ID = "shortcut_id"; - private ShortcutInfo mShortcutInfo; - - public ShortcutInfoCompat(ShortcutInfo shortcutInfo) { - mShortcutInfo = shortcutInfo; - } - - public Intent makeIntent() { - return new Intent(Intent.ACTION_MAIN) - .addCategory(INTENT_CATEGORY) - .setComponent(getActivity()) - .setPackage(getPackage()) - .setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED) - .putExtra(EXTRA_SHORTCUT_ID, getId()); - } - - public ShortcutInfo getShortcutInfo() { - return mShortcutInfo; - } - - public String getPackage() { - return mShortcutInfo.getPackage(); - } - - public String getBadgePackage(Context context) { - String whitelistedPkg = context.getString(R.string.shortcutinfocompat_badgepkg_whitelist); - if (whitelistedPkg.equals(getPackage()) - && mShortcutInfo.getExtras().containsKey(EXTRA_BADGEPKG)) { - return mShortcutInfo.getExtras().getString(EXTRA_BADGEPKG); - } - return getPackage(); - } - - public String getId() { - return mShortcutInfo.getId(); - } - - public CharSequence getShortLabel() { - return mShortcutInfo.getShortLabel(); - } - - public CharSequence getLongLabel() { - return mShortcutInfo.getLongLabel(); - } - - public long getLastChangedTimestamp() { - return mShortcutInfo.getLastChangedTimestamp(); - } - - public ComponentName getActivity() { - return mShortcutInfo.getActivity(); - } - - public UserHandle getUserHandle() { - return mShortcutInfo.getUserHandle(); - } - - public boolean hasKeyFieldsOnly() { - return mShortcutInfo.hasKeyFieldsOnly(); - } - - public boolean isPinned() { - return mShortcutInfo.isPinned(); - } - - public boolean isDeclaredInManifest() { - return mShortcutInfo.isDeclaredInManifest(); - } - - public boolean isEnabled() { - return mShortcutInfo.isEnabled(); - } - - public boolean isDynamic() { - return mShortcutInfo.isDynamic(); - } - - public int getRank() { - return mShortcutInfo.getRank(); - } - - public CharSequence getDisabledMessage() { - return mShortcutInfo.getDisabledMessage(); - } - - @Override - public String toString() { - return mShortcutInfo.toString(); - } -} diff --git a/src/com/android/launcher3/shortcuts/ShortcutKey.java b/src/com/android/launcher3/shortcuts/ShortcutKey.java index cbef85a82..70665ca28 100644 --- a/src/com/android/launcher3/shortcuts/ShortcutKey.java +++ b/src/com/android/launcher3/shortcuts/ShortcutKey.java @@ -2,6 +2,7 @@ package com.android.launcher3.shortcuts; import android.content.ComponentName; import android.content.Intent; +import android.content.pm.ShortcutInfo; import android.os.UserHandle; import com.android.launcher3.ItemInfo; @@ -12,6 +13,9 @@ import com.android.launcher3.util.ComponentKey; */ public class ShortcutKey extends ComponentKey { + public static final String EXTRA_SHORTCUT_ID = "shortcut_id"; + private static final String INTENT_CATEGORY = "com.android.launcher3.DEEP_SHORTCUT"; + public ShortcutKey(String packageName, UserHandle user, String id) { // Use the id as the class name. super(new ComponentName(packageName, id), user); @@ -25,18 +29,26 @@ public class ShortcutKey extends ComponentKey { return componentName.getClassName(); } - public static ShortcutKey fromInfo(ShortcutInfoCompat shortcutInfo) { + public static ShortcutKey fromInfo(ShortcutInfo shortcutInfo) { return new ShortcutKey(shortcutInfo.getPackage(), shortcutInfo.getUserHandle(), shortcutInfo.getId()); } public static ShortcutKey fromIntent(Intent intent, UserHandle user) { - String shortcutId = intent.getStringExtra( - ShortcutInfoCompat.EXTRA_SHORTCUT_ID); + String shortcutId = intent.getStringExtra(EXTRA_SHORTCUT_ID); return new ShortcutKey(intent.getPackage(), user, shortcutId); } public static ShortcutKey fromItemInfo(ItemInfo info) { return fromIntent(info.getIntent(), info.user); } + + public static Intent makeIntent(ShortcutInfo si) { + return new Intent(Intent.ACTION_MAIN) + .addCategory(INTENT_CATEGORY) + .setComponent(si.getActivity()) + .setPackage(si.getPackage()) + .setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED) + .putExtra(EXTRA_SHORTCUT_ID, si.getId()); + } } |