summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Mehdi Alizadeh <mett@google.com> 2020-04-16 18:24:40 -0700
committer Mehdi Alizadeh <mett@google.com> 2020-04-23 18:37:08 -0700
commite65b53e5d70bdefcc3ad2ab61a6d4baba53e71c7 (patch)
treeee9a5b1d3361171a6d40b12a9bcce7cf154e1eac
parent4695d593ee03027f43ad41412d32a2c4ab83ec01 (diff)
Include cache-only and pinned-only shortcuts as Sharing shortcuts as well
Bug: 154249544 Test: atest com.android.server.pm.ShortcutManagerTest1 com.android.server.pm.ShortcutManagerTest2 com.android.server.pm.ShortcutManagerTest3 com.android.server.pm.ShortcutManagerTest4 com.android.server.pm.ShortcutManagerTest5 com.android.server.pm.ShortcutManagerTest6 com.android.server.pm.ShortcutManagerTest7 com.android.server.pm.ShortcutManagerTest8 com.android.server.pm.ShortcutManagerTest9 com.android.server.pm.ShortcutManagerTest10 Change-Id: Iacbca104e0fee91d80768bd0280db252aca2c5c0
-rw-r--r--core/java/android/content/pm/ShortcutInfo.java6
-rw-r--r--services/core/java/com/android/server/pm/ShortcutPackage.java5
-rw-r--r--services/tests/servicestests/src/com/android/server/pm/ShortcutManagerTest1.java70
3 files changed, 79 insertions, 2 deletions
diff --git a/core/java/android/content/pm/ShortcutInfo.java b/core/java/android/content/pm/ShortcutInfo.java
index 8d8776f1bc23..41f9a6e4a274 100644
--- a/core/java/android/content/pm/ShortcutInfo.java
+++ b/core/java/android/content/pm/ShortcutInfo.java
@@ -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.
diff --git a/services/core/java/com/android/server/pm/ShortcutPackage.java b/services/core/java/com/android/server/pm/ShortcutPackage.java
index 1fc0a38e1ed3..65f466f1ea6d 100644
--- a/services/core/java/com/android/server/pm/ShortcutPackage.java
+++ b/services/core/java/com/android/server/pm/ShortcutPackage.java
@@ -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<>();
@@ -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++) {
diff --git a/services/tests/servicestests/src/com/android/server/pm/ShortcutManagerTest1.java b/services/tests/servicestests/src/com/android/server/pm/ShortcutManagerTest1.java
index 06b344b3b94f..efa25bd7721b 100644
--- a/services/tests/servicestests/src/com/android/server/pm/ShortcutManagerTest1.java
+++ b/services/tests/servicestests/src/com/android/server/pm/ShortcutManagerTest1.java
@@ -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);
@@ -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.