Removing ShortcutInfoCompat and directly using ShortcutInfo
Change-Id: I2842689e192a206c0d31558c8126eae1c7904598
This commit is contained in:
parent
8b0cb4113f
commit
6bbf6004f8
|
@ -18,6 +18,7 @@ package com.android.launcher3.shortcuts;
|
|||
|
||||
import android.content.ComponentName;
|
||||
import android.content.Context;
|
||||
import android.content.pm.ShortcutInfo;
|
||||
import android.graphics.Rect;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.os.Bundle;
|
||||
|
@ -55,7 +56,7 @@ public class DeepShortcutManager {
|
|||
return false;
|
||||
}
|
||||
|
||||
public void onShortcutsChanged(List<ShortcutInfoCompat> shortcuts) {
|
||||
public void onShortcutsChanged(List<ShortcutInfo> shortcuts) {
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -64,7 +65,7 @@ public class DeepShortcutManager {
|
|||
* This method is intended to get the full details for shortcuts when they are added or updated,
|
||||
* because we only get "key" fields in onShortcutsChanged().
|
||||
*/
|
||||
public List<ShortcutInfoCompat> queryForFullDetails(String packageName,
|
||||
public List<ShortcutInfo> queryForFullDetails(String packageName,
|
||||
List<String> shortcutIds, UserHandle user) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
@ -73,7 +74,7 @@ public class DeepShortcutManager {
|
|||
* Gets all the manifest and dynamic shortcuts associated with the given package and user,
|
||||
* to be displayed in the shortcuts container on long press.
|
||||
*/
|
||||
public List<ShortcutInfoCompat> queryForShortcutsContainer(ComponentName activity,
|
||||
public List<ShortcutInfo> queryForShortcutsContainer(ComponentName activity,
|
||||
UserHandle user) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
@ -96,7 +97,7 @@ public class DeepShortcutManager {
|
|||
Bundle startActivityOptions, UserHandle user) {
|
||||
}
|
||||
|
||||
public Drawable getShortcutIconDrawable(ShortcutInfoCompat shortcutInfo, int density) {
|
||||
public Drawable getShortcutIconDrawable(ShortcutInfo shortcutInfo, int density) {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
@ -105,16 +106,16 @@ public class DeepShortcutManager {
|
|||
*
|
||||
* If packageName is null, returns all pinned shortcuts regardless of package.
|
||||
*/
|
||||
public List<ShortcutInfoCompat> queryForPinnedShortcuts(String packageName, UserHandle user) {
|
||||
public List<ShortcutInfo> queryForPinnedShortcuts(String packageName, UserHandle user) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
public List<ShortcutInfoCompat> queryForPinnedShortcuts(String packageName,
|
||||
public List<ShortcutInfo> queryForPinnedShortcuts(String packageName,
|
||||
List<String> shortcutIds, UserHandle user) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
public List<ShortcutInfoCompat> queryForAllShortcuts(UserHandle user) {
|
||||
public List<ShortcutInfo> queryForAllShortcuts(UserHandle user) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
|
|
|
@ -76,7 +76,7 @@
|
|||
<string name="wallpaper_picker_package" translatable="false"></string>
|
||||
|
||||
<!-- Whitelisted package to retrieve packagename for badge. Can be empty. -->
|
||||
<string name="shortcutinfocompat_badgepkg_whitelist" translatable="false"></string>
|
||||
<string name="shortcutinfo_badgepkg_whitelist" translatable="false"></string>
|
||||
|
||||
<!-- View ID to use for QSB widget -->
|
||||
<item type="id" name="qsb_widget" />
|
||||
|
|
|
@ -22,7 +22,6 @@ public class FlagOverrideSampleTest {
|
|||
public final FlagOverrideRule flags = new FlagOverrideRule();
|
||||
|
||||
@FlagOverride(key = "EXAMPLE_FLAG", value = true)
|
||||
@FlagOverride(key = "QUICK_SWITCH", value = false)
|
||||
@Test
|
||||
public void withFlagOn() {
|
||||
assertTrue(FeatureFlags.EXAMPLE_FLAG.get());
|
||||
|
|
|
@ -10,8 +10,8 @@ import android.graphics.Point;
|
|||
|
||||
import com.android.launcher3.InvariantDeviceProfile;
|
||||
import com.android.launcher3.LauncherSettings;
|
||||
import com.android.launcher3.config.FeatureFlags;
|
||||
import com.android.launcher3.config.FlagOverrideRule;
|
||||
import com.android.launcher3.config.FlagOverrideRule.FlagOverride;
|
||||
import com.android.launcher3.model.GridSizeMigrationTask.MultiStepMigrationTask;
|
||||
import com.android.launcher3.util.IntArray;
|
||||
|
||||
|
@ -210,9 +210,11 @@ public class GridSizeMigrationTaskTest extends BaseGridChangesTestCase {
|
|||
}});
|
||||
}
|
||||
|
||||
@FlagOverride(key = "QSB_ON_FIRST_SCREEN", value = true)
|
||||
@Test
|
||||
public void testWorkspace_first_row_blocked() throws Exception {
|
||||
if (!FeatureFlags.QSB_ON_FIRST_SCREEN) {
|
||||
return;
|
||||
}
|
||||
// The first screen has one item on the 4th column which needs moving, as the first row
|
||||
// will be kept empty.
|
||||
int[][][] ids = createGrid(new int[][][]{{
|
||||
|
@ -236,9 +238,11 @@ public class GridSizeMigrationTaskTest extends BaseGridChangesTestCase {
|
|||
}});
|
||||
}
|
||||
|
||||
@FlagOverride(key = "QSB_ON_FIRST_SCREEN", value = true)
|
||||
@Test
|
||||
public void testWorkspace_items_moved_to_empty_first_row() throws Exception {
|
||||
if (!FeatureFlags.QSB_ON_FIRST_SCREEN) {
|
||||
return;
|
||||
}
|
||||
// Items will get moved to the next screen to keep the first screen empty.
|
||||
int[][][] ids = createGrid(new int[][][]{{
|
||||
{ -1, -1, -1, -1},
|
||||
|
|
|
@ -22,16 +22,15 @@ import static com.android.launcher3.popup.PopupPopulator.NUM_DYNAMIC;
|
|||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.mockito.Mockito.doReturn;
|
||||
import static org.mockito.Mockito.spy;
|
||||
|
||||
import android.content.pm.ShortcutInfo;
|
||||
|
||||
import androidx.test.filters.SmallTest;
|
||||
import androidx.test.runner.AndroidJUnit4;
|
||||
|
||||
import com.android.launcher3.shortcuts.ShortcutInfoCompat;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.robolectric.RobolectricTestRunner;
|
||||
import org.robolectric.RuntimeEnvironment;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
|
@ -40,8 +39,7 @@ import java.util.List;
|
|||
/**
|
||||
* Tests the sorting and filtering of shortcuts in {@link PopupPopulator}.
|
||||
*/
|
||||
@SmallTest
|
||||
@RunWith(AndroidJUnit4.class)
|
||||
@RunWith(RobolectricTestRunner.class)
|
||||
public class PopupPopulatorTest {
|
||||
|
||||
@Test
|
||||
|
@ -81,20 +79,20 @@ public class PopupPopulatorTest {
|
|||
}
|
||||
|
||||
private void filterShortcutsAndAssertNumStaticAndDynamic(
|
||||
List<ShortcutInfoCompat> shortcuts, int expectedStatic, int expectedDynamic) {
|
||||
List<ShortcutInfo> shortcuts, int expectedStatic, int expectedDynamic) {
|
||||
filterShortcutsAndAssertNumStaticAndDynamic(shortcuts, expectedStatic, expectedDynamic, null);
|
||||
}
|
||||
|
||||
private void filterShortcutsAndAssertNumStaticAndDynamic(List<ShortcutInfoCompat> shortcuts,
|
||||
private void filterShortcutsAndAssertNumStaticAndDynamic(List<ShortcutInfo> shortcuts,
|
||||
int expectedStatic, int expectedDynamic, String shortcutIdToRemove) {
|
||||
Collections.shuffle(shortcuts);
|
||||
List<ShortcutInfoCompat> filteredShortcuts = PopupPopulator.sortAndFilterShortcuts(
|
||||
List<ShortcutInfo> filteredShortcuts = PopupPopulator.sortAndFilterShortcuts(
|
||||
shortcuts, shortcutIdToRemove);
|
||||
assertIsSorted(filteredShortcuts);
|
||||
|
||||
int numStatic = 0;
|
||||
int numDynamic = 0;
|
||||
for (ShortcutInfoCompat shortcut : filteredShortcuts) {
|
||||
for (ShortcutInfo shortcut : filteredShortcuts) {
|
||||
if (shortcut.isDeclaredInManifest()) {
|
||||
numStatic++;
|
||||
}
|
||||
|
@ -106,11 +104,11 @@ public class PopupPopulatorTest {
|
|||
assertEquals(expectedDynamic, numDynamic);
|
||||
}
|
||||
|
||||
private void assertIsSorted(List<ShortcutInfoCompat> shortcuts) {
|
||||
private void assertIsSorted(List<ShortcutInfo> shortcuts) {
|
||||
int lastStaticRank = -1;
|
||||
int lastDynamicRank = -1;
|
||||
boolean hasSeenDynamic = false;
|
||||
for (ShortcutInfoCompat shortcut : shortcuts) {
|
||||
for (ShortcutInfo shortcut : shortcuts) {
|
||||
int rank = shortcut.getRank();
|
||||
if (shortcut.isDeclaredInManifest()) {
|
||||
assertFalse("Static shortcuts should come before all dynamic shortcuts.",
|
||||
|
@ -126,51 +124,24 @@ public class PopupPopulatorTest {
|
|||
}
|
||||
}
|
||||
|
||||
private List<ShortcutInfoCompat> createShortcutsList(int numStatic, int numDynamic) {
|
||||
List<ShortcutInfoCompat> shortcuts = new ArrayList<>();
|
||||
private List<ShortcutInfo> createShortcutsList(int numStatic, int numDynamic) {
|
||||
List<ShortcutInfo> shortcuts = new ArrayList<>();
|
||||
for (int i = 0; i < numStatic; i++) {
|
||||
shortcuts.add(new Shortcut(true, i));
|
||||
shortcuts.add(createInfo(true, i));
|
||||
}
|
||||
for (int i = 0; i < numDynamic; i++) {
|
||||
shortcuts.add(new Shortcut(false, i));
|
||||
shortcuts.add(createInfo(false, i));
|
||||
}
|
||||
return shortcuts;
|
||||
}
|
||||
|
||||
private class Shortcut extends ShortcutInfoCompat {
|
||||
private boolean mIsStatic;
|
||||
private int mRank;
|
||||
private String mId;
|
||||
|
||||
public Shortcut(ShortcutInfo shortcutInfo) {
|
||||
super(shortcutInfo);
|
||||
}
|
||||
|
||||
public Shortcut(boolean isStatic, int rank) {
|
||||
this(null);
|
||||
mIsStatic = isStatic;
|
||||
mRank = rank;
|
||||
mId = generateId(isStatic, rank);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isDeclaredInManifest() {
|
||||
return mIsStatic;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isDynamic() {
|
||||
return !mIsStatic;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getRank() {
|
||||
return mRank;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getId() {
|
||||
return mId;
|
||||
}
|
||||
private ShortcutInfo createInfo(boolean isStatic, int rank) {
|
||||
ShortcutInfo info = spy(new ShortcutInfo.Builder(
|
||||
RuntimeEnvironment.application, generateId(isStatic, rank))
|
||||
.setRank(rank)
|
||||
.build());
|
||||
doReturn(isStatic).when(info).isDeclaredInManifest();
|
||||
doReturn(!isStatic).when(info).isDynamic();
|
||||
return info;
|
||||
}
|
||||
}
|
|
@ -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;
|
||||
|
|
|
@ -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());
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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()) {
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
}
|
|
@ -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());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -74,17 +74,13 @@ public class DeepShortcutManager {
|
|||
return mWasLastCallSuccess;
|
||||
}
|
||||
|
||||
public void onShortcutsChanged(List<ShortcutInfoCompat> shortcuts) {
|
||||
// mShortcutCache.removeShortcuts(shortcuts);
|
||||
}
|
||||
|
||||
/**
|
||||
* Queries for the shortcuts with the package name and provided ids.
|
||||
*
|
||||
* This method is intended to get the full details for shortcuts when they are added or updated,
|
||||
* because we only get "key" fields in onShortcutsChanged().
|
||||
*/
|
||||
public List<ShortcutInfoCompat> queryForFullDetails(String packageName,
|
||||
public List<ShortcutInfo> queryForFullDetails(String packageName,
|
||||
List<String> shortcutIds, UserHandle user) {
|
||||
return query(FLAG_GET_ALL, packageName, null, shortcutIds, user);
|
||||
}
|
||||
|
@ -93,7 +89,7 @@ public class DeepShortcutManager {
|
|||
* Gets all the manifest and dynamic shortcuts associated with the given package and user,
|
||||
* to be displayed in the shortcuts container on long press.
|
||||
*/
|
||||
public List<ShortcutInfoCompat> queryForShortcutsContainer(ComponentName activity,
|
||||
public List<ShortcutInfo> queryForShortcutsContainer(ComponentName activity,
|
||||
UserHandle user) {
|
||||
return query(ShortcutQuery.FLAG_MATCH_MANIFEST | ShortcutQuery.FLAG_MATCH_DYNAMIC,
|
||||
activity.getPackageName(), activity, null, user);
|
||||
|
@ -149,10 +145,9 @@ public class DeepShortcutManager {
|
|||
}
|
||||
}
|
||||
|
||||
public Drawable getShortcutIconDrawable(ShortcutInfoCompat shortcutInfo, int density) {
|
||||
public Drawable getShortcutIconDrawable(ShortcutInfo shortcutInfo, int density) {
|
||||
try {
|
||||
Drawable icon = mLauncherApps.getShortcutIconDrawable(
|
||||
shortcutInfo.getShortcutInfo(), density);
|
||||
Drawable icon = mLauncherApps.getShortcutIconDrawable(shortcutInfo, density);
|
||||
mWasLastCallSuccess = true;
|
||||
return icon;
|
||||
} catch (SecurityException|IllegalStateException e) {
|
||||
|
@ -167,22 +162,22 @@ public class DeepShortcutManager {
|
|||
*
|
||||
* If packageName is null, returns all pinned shortcuts regardless of package.
|
||||
*/
|
||||
public List<ShortcutInfoCompat> queryForPinnedShortcuts(String packageName, UserHandle user) {
|
||||
public List<ShortcutInfo> queryForPinnedShortcuts(String packageName, UserHandle user) {
|
||||
return queryForPinnedShortcuts(packageName, null, user);
|
||||
}
|
||||
|
||||
public List<ShortcutInfoCompat> queryForPinnedShortcuts(String packageName,
|
||||
public List<ShortcutInfo> queryForPinnedShortcuts(String packageName,
|
||||
List<String> shortcutIds, UserHandle user) {
|
||||
return query(ShortcutQuery.FLAG_MATCH_PINNED, packageName, null, shortcutIds, user);
|
||||
}
|
||||
|
||||
public List<ShortcutInfoCompat> queryForAllShortcuts(UserHandle user) {
|
||||
public List<ShortcutInfo> queryForAllShortcuts(UserHandle user) {
|
||||
return query(FLAG_GET_ALL, null, null, null, user);
|
||||
}
|
||||
|
||||
private List<String> extractIds(List<ShortcutInfoCompat> shortcuts) {
|
||||
private List<String> extractIds(List<ShortcutInfo> shortcuts) {
|
||||
List<String> shortcutIds = new ArrayList<>(shortcuts.size());
|
||||
for (ShortcutInfoCompat shortcut : shortcuts) {
|
||||
for (ShortcutInfo shortcut : shortcuts) {
|
||||
shortcutIds.add(shortcut.getId());
|
||||
}
|
||||
return shortcutIds;
|
||||
|
@ -194,7 +189,7 @@ public class DeepShortcutManager {
|
|||
*
|
||||
* TODO: Use the cache to optimize this so we don't make an RPC every time.
|
||||
*/
|
||||
private List<ShortcutInfoCompat> query(int flags, String packageName,
|
||||
private List<ShortcutInfo> query(int flags, String packageName,
|
||||
ComponentName activity, List<String> shortcutIds, UserHandle user) {
|
||||
ShortcutQuery q = new ShortcutQuery();
|
||||
q.setQueryFlags(flags);
|
||||
|
@ -214,11 +209,7 @@ public class DeepShortcutManager {
|
|||
if (shortcutInfos == null) {
|
||||
return Collections.EMPTY_LIST;
|
||||
}
|
||||
List<ShortcutInfoCompat> shortcutInfoCompats = new ArrayList<>(shortcutInfos.size());
|
||||
for (ShortcutInfo shortcutInfo : shortcutInfos) {
|
||||
shortcutInfoCompats.add(new ShortcutInfoCompat(shortcutInfo));
|
||||
}
|
||||
return shortcutInfoCompats;
|
||||
return shortcutInfos;
|
||||
}
|
||||
|
||||
public boolean hasHostPermission() {
|
||||
|
|
Loading…
Reference in New Issue