Loading core/java/android/content/pm/ShortcutInfo.java +6 −0 Original line number Diff line number Diff line Loading @@ -1759,6 +1759,12 @@ public final class ShortcutInfo implements Parcelable { return isDeclaredInManifest() && isVisibleToPublisher(); } /** @hide */ public boolean isNonManifestVisible() { return !isDeclaredInManifest() && isVisibleToPublisher() && (isPinned() || isCached() || isDynamic()); } /** * Return if a shortcut is immutable, in which case it cannot be modified with any of * {@link ShortcutManager} APIs. Loading services/core/java/com/android/server/pm/ShortcutPackage.java +3 −2 Original line number Diff line number Diff line Loading @@ -762,7 +762,7 @@ class ShortcutPackage extends ShortcutPackageItem { // Get the list of all dynamic shortcuts in this package. final ArrayList<ShortcutInfo> shortcuts = new ArrayList<>(); findAll(shortcuts, ShortcutInfo::isDynamicVisible, findAll(shortcuts, ShortcutInfo::isNonManifestVisible, ShortcutInfo.CLONE_REMOVE_FOR_APP_PREDICTION); final List<ShortcutManager.ShareShortcutInfo> result = new ArrayList<>(); Loading Loading @@ -807,7 +807,8 @@ class ShortcutPackage extends ShortcutPackageItem { // Get the list of all dynamic shortcuts in this package final ArrayList<ShortcutInfo> shortcuts = new ArrayList<>(); findAll(shortcuts, ShortcutInfo::isDynamicVisible, ShortcutInfo.CLONE_REMOVE_FOR_LAUNCHER); findAll(shortcuts, ShortcutInfo::isNonManifestVisible, ShortcutInfo.CLONE_REMOVE_FOR_LAUNCHER); int sharingShortcutCount = 0; for (int i = 0; i < shortcuts.size(); i++) { Loading services/tests/servicestests/src/com/android/server/pm/ShortcutManagerTest1.java +70 −0 Original line number Diff line number Diff line Loading @@ -6734,6 +6734,21 @@ public class ShortcutManagerTest1 extends BaseShortcutManagerTest { mManager.hasShareTargets(CALLING_PACKAGE_1); } public void testisSharingShortcut_permission() throws IntentFilter.MalformedMimeTypeException { setCaller(LAUNCHER_1, USER_0); IntentFilter filter_any = new IntentFilter(); filter_any.addDataType("*/*"); assertExpectException(SecurityException.class, "Missing permission", () -> mInternal.isSharingShortcut(USER_0, LAUNCHER_1, CALLING_PACKAGE_1, "s1", USER_0, filter_any)); // Has permission, now it should pass. mCallerPermissions.add(permission.MANAGE_APP_PREDICTIONS); mManager.hasShareTargets(CALLING_PACKAGE_1); } public void testDumpsys_crossProfile() { prepareCrossProfileDataSet(); dumpsysOnLogcat("test1", /* force= */ true); Loading Loading @@ -8645,6 +8660,61 @@ public class ShortcutManagerTest1 extends BaseShortcutManagerTest { filter_any)); } public void testIsSharingShortcut_PinnedAndCachedOnlyShortcuts() throws IntentFilter.MalformedMimeTypeException { addManifestShortcutResource( new ComponentName(CALLING_PACKAGE_1, ShortcutActivity.class.getName()), R.xml.shortcut_share_targets); updatePackageVersion(CALLING_PACKAGE_1, 1); mService.mPackageMonitor.onReceive(getTestContext(), genPackageAddIntent(CALLING_PACKAGE_1, USER_0)); final ShortcutInfo s1 = makeShortcutWithCategory("s1", set("com.test.category.CATEGORY1", "com.test.category.CATEGORY2")); final ShortcutInfo s2 = makeShortcutWithCategory("s2", set("com.test.category.CATEGORY5", "com.test.category.CATEGORY6")); final ShortcutInfo s3 = makeShortcutWithCategory("s3", set("com.test.category.CATEGORY5", "com.test.category.CATEGORY6")); s1.setLongLived(); s2.setLongLived(); runWithCaller(CALLING_PACKAGE_1, USER_0, () -> { assertTrue(mManager.setDynamicShortcuts(list(s1, s2, s3))); assertShortcutIds(assertAllNotKeyFieldsOnly(mManager.getDynamicShortcuts()), "s1", "s2", "s3"); }); IntentFilter filter_any = new IntentFilter(); filter_any.addDataType("*/*"); setCaller(LAUNCHER_1, USER_0); mCallerPermissions.add(permission.MANAGE_APP_PREDICTIONS); // Assert all are sharing shortcuts assertTrue(mInternal.isSharingShortcut(USER_0, LAUNCHER_1, CALLING_PACKAGE_1, "s1", USER_0, filter_any)); assertTrue(mInternal.isSharingShortcut(USER_0, LAUNCHER_1, CALLING_PACKAGE_1, "s2", USER_0, filter_any)); assertTrue(mInternal.isSharingShortcut(USER_0, LAUNCHER_1, CALLING_PACKAGE_1, "s3", USER_0, filter_any)); mLauncherApps.cacheShortcuts(CALLING_PACKAGE_1, list("s1", "s2"), HANDLE_USER_0); mLauncherApps.pinShortcuts(CALLING_PACKAGE_1, list("s3"), HANDLE_USER_0); runWithCaller(CALLING_PACKAGE_1, USER_0, () -> { // Remove one cached shortcut, and leave one cached-only and pinned-only shortcuts. mManager.removeLongLivedShortcuts(list("s1")); mManager.removeDynamicShortcuts(list("s2, s3")); }); assertFalse(mInternal.isSharingShortcut(USER_0, LAUNCHER_1, CALLING_PACKAGE_1, "s1", USER_0, filter_any)); assertTrue(mInternal.isSharingShortcut(USER_0, LAUNCHER_1, CALLING_PACKAGE_1, "s2", USER_0, filter_any)); assertTrue(mInternal.isSharingShortcut(USER_0, LAUNCHER_1, CALLING_PACKAGE_1, "s3", USER_0, filter_any)); } private Uri getFileUriFromResource(String fileName, int resId) throws IOException { File file = new File(getTestContext().getFilesDir(), fileName); // Make sure we are not leaving phantom files behind. Loading Loading
core/java/android/content/pm/ShortcutInfo.java +6 −0 Original line number Diff line number Diff line Loading @@ -1759,6 +1759,12 @@ public final class ShortcutInfo implements Parcelable { return isDeclaredInManifest() && isVisibleToPublisher(); } /** @hide */ public boolean isNonManifestVisible() { return !isDeclaredInManifest() && isVisibleToPublisher() && (isPinned() || isCached() || isDynamic()); } /** * Return if a shortcut is immutable, in which case it cannot be modified with any of * {@link ShortcutManager} APIs. Loading
services/core/java/com/android/server/pm/ShortcutPackage.java +3 −2 Original line number Diff line number Diff line Loading @@ -762,7 +762,7 @@ class ShortcutPackage extends ShortcutPackageItem { // Get the list of all dynamic shortcuts in this package. final ArrayList<ShortcutInfo> shortcuts = new ArrayList<>(); findAll(shortcuts, ShortcutInfo::isDynamicVisible, findAll(shortcuts, ShortcutInfo::isNonManifestVisible, ShortcutInfo.CLONE_REMOVE_FOR_APP_PREDICTION); final List<ShortcutManager.ShareShortcutInfo> result = new ArrayList<>(); Loading Loading @@ -807,7 +807,8 @@ class ShortcutPackage extends ShortcutPackageItem { // Get the list of all dynamic shortcuts in this package final ArrayList<ShortcutInfo> shortcuts = new ArrayList<>(); findAll(shortcuts, ShortcutInfo::isDynamicVisible, ShortcutInfo.CLONE_REMOVE_FOR_LAUNCHER); findAll(shortcuts, ShortcutInfo::isNonManifestVisible, ShortcutInfo.CLONE_REMOVE_FOR_LAUNCHER); int sharingShortcutCount = 0; for (int i = 0; i < shortcuts.size(); i++) { Loading
services/tests/servicestests/src/com/android/server/pm/ShortcutManagerTest1.java +70 −0 Original line number Diff line number Diff line Loading @@ -6734,6 +6734,21 @@ public class ShortcutManagerTest1 extends BaseShortcutManagerTest { mManager.hasShareTargets(CALLING_PACKAGE_1); } public void testisSharingShortcut_permission() throws IntentFilter.MalformedMimeTypeException { setCaller(LAUNCHER_1, USER_0); IntentFilter filter_any = new IntentFilter(); filter_any.addDataType("*/*"); assertExpectException(SecurityException.class, "Missing permission", () -> mInternal.isSharingShortcut(USER_0, LAUNCHER_1, CALLING_PACKAGE_1, "s1", USER_0, filter_any)); // Has permission, now it should pass. mCallerPermissions.add(permission.MANAGE_APP_PREDICTIONS); mManager.hasShareTargets(CALLING_PACKAGE_1); } public void testDumpsys_crossProfile() { prepareCrossProfileDataSet(); dumpsysOnLogcat("test1", /* force= */ true); Loading Loading @@ -8645,6 +8660,61 @@ public class ShortcutManagerTest1 extends BaseShortcutManagerTest { filter_any)); } public void testIsSharingShortcut_PinnedAndCachedOnlyShortcuts() throws IntentFilter.MalformedMimeTypeException { addManifestShortcutResource( new ComponentName(CALLING_PACKAGE_1, ShortcutActivity.class.getName()), R.xml.shortcut_share_targets); updatePackageVersion(CALLING_PACKAGE_1, 1); mService.mPackageMonitor.onReceive(getTestContext(), genPackageAddIntent(CALLING_PACKAGE_1, USER_0)); final ShortcutInfo s1 = makeShortcutWithCategory("s1", set("com.test.category.CATEGORY1", "com.test.category.CATEGORY2")); final ShortcutInfo s2 = makeShortcutWithCategory("s2", set("com.test.category.CATEGORY5", "com.test.category.CATEGORY6")); final ShortcutInfo s3 = makeShortcutWithCategory("s3", set("com.test.category.CATEGORY5", "com.test.category.CATEGORY6")); s1.setLongLived(); s2.setLongLived(); runWithCaller(CALLING_PACKAGE_1, USER_0, () -> { assertTrue(mManager.setDynamicShortcuts(list(s1, s2, s3))); assertShortcutIds(assertAllNotKeyFieldsOnly(mManager.getDynamicShortcuts()), "s1", "s2", "s3"); }); IntentFilter filter_any = new IntentFilter(); filter_any.addDataType("*/*"); setCaller(LAUNCHER_1, USER_0); mCallerPermissions.add(permission.MANAGE_APP_PREDICTIONS); // Assert all are sharing shortcuts assertTrue(mInternal.isSharingShortcut(USER_0, LAUNCHER_1, CALLING_PACKAGE_1, "s1", USER_0, filter_any)); assertTrue(mInternal.isSharingShortcut(USER_0, LAUNCHER_1, CALLING_PACKAGE_1, "s2", USER_0, filter_any)); assertTrue(mInternal.isSharingShortcut(USER_0, LAUNCHER_1, CALLING_PACKAGE_1, "s3", USER_0, filter_any)); mLauncherApps.cacheShortcuts(CALLING_PACKAGE_1, list("s1", "s2"), HANDLE_USER_0); mLauncherApps.pinShortcuts(CALLING_PACKAGE_1, list("s3"), HANDLE_USER_0); runWithCaller(CALLING_PACKAGE_1, USER_0, () -> { // Remove one cached shortcut, and leave one cached-only and pinned-only shortcuts. mManager.removeLongLivedShortcuts(list("s1")); mManager.removeDynamicShortcuts(list("s2, s3")); }); assertFalse(mInternal.isSharingShortcut(USER_0, LAUNCHER_1, CALLING_PACKAGE_1, "s1", USER_0, filter_any)); assertTrue(mInternal.isSharingShortcut(USER_0, LAUNCHER_1, CALLING_PACKAGE_1, "s2", USER_0, filter_any)); assertTrue(mInternal.isSharingShortcut(USER_0, LAUNCHER_1, CALLING_PACKAGE_1, "s3", USER_0, filter_any)); } private Uri getFileUriFromResource(String fileName, int resId) throws IOException { File file = new File(getTestContext().getFilesDir(), fileName); // Make sure we are not leaving phantom files behind. Loading