Merge "Adds ShortcutServiceInternal#isSharingShortcut()" into rvc-dev am: 6ddae0c22b

Change-Id: I571e5c88f0dc435fda3f2ebde70988b884ff7c1b
This commit is contained in:
Mehdi Alizadeh
2020-04-02 01:50:02 +00:00
committed by Automerger Merge Worker
3 changed files with 90 additions and 0 deletions

View File

@@ -109,4 +109,8 @@ public abstract class ShortcutServiceInternal {
*/
public abstract String getShortcutIconUri(int launcherUserId, @NonNull String launcherPackage,
@NonNull String packageName, @NonNull String shortcutId, int userId);
public abstract boolean isSharingShortcut(int callingUserId, @NonNull String callingPackage,
@NonNull String packageName, @NonNull String shortcutId, int userId,
@NonNull IntentFilter filter);
}

View File

@@ -2385,6 +2385,30 @@ public class ShortcutService extends IShortcutService.Stub {
}
}
public boolean isSharingShortcut(int callingUserId, @NonNull String callingPackage,
@NonNull String packageName, @NonNull String shortcutId, int userId,
@NonNull IntentFilter filter) {
verifyCaller(callingPackage, callingUserId);
enforceCallingOrSelfPermission(android.Manifest.permission.MANAGE_APP_PREDICTIONS,
"isSharingShortcut");
synchronized (mLock) {
throwIfUserLockedL(userId);
throwIfUserLockedL(callingUserId);
final List<ShortcutManager.ShareShortcutInfo> matchedTargets =
getPackageShortcutsLocked(packageName, userId)
.getMatchingShareTargets(filter);
final int matchedSize = matchedTargets.size();
for (int i = 0; i < matchedSize; i++) {
if (matchedTargets.get(i).getShortcutInfo().getId().equals(shortcutId)) {
return true;
}
}
}
return false;
}
@GuardedBy("mLock")
private ParceledListSlice<ShortcutInfo> getShortcutsWithQueryLocked(@NonNull String packageName,
@UserIdInt int userId, int cloneFlags, @NonNull Predicate<ShortcutInfo> query) {
@@ -2969,6 +2993,18 @@ public class ShortcutService extends IShortcutService.Stub {
callingPackage, intentFilter, userId).getList();
}
@Override
public boolean isSharingShortcut(int callingUserId, @NonNull String callingPackage,
@NonNull String packageName, @NonNull String shortcutId, int userId,
@NonNull IntentFilter filter) {
Preconditions.checkStringNotEmpty(callingPackage, "callingPackage");
Preconditions.checkStringNotEmpty(packageName, "packageName");
Preconditions.checkStringNotEmpty(shortcutId, "shortcutId");
return ShortcutService.this.isSharingShortcut(callingUserId, callingPackage,
packageName, shortcutId, userId, filter);
}
private void updateCachedShortcutsInternal(int launcherUserId,
@NonNull String callingPackage, @NonNull String packageName,
@NonNull List<String> shortcutIds, int userId, boolean doCache) {

View File

@@ -8595,6 +8595,56 @@ public class ShortcutManagerTest1 extends BaseShortcutManagerTest {
}
}
public void testIsSharingShortcut() 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));
setCaller(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 = makeShortcut("s3");
assertTrue(mManager.setDynamicShortcuts(list(s1, s2, s3)));
assertShortcutIds(assertAllNotKeyFieldsOnly(mManager.getDynamicShortcuts()),
"s1", "s2", "s3");
IntentFilter filter_cat1 = new IntentFilter();
filter_cat1.addDataType("text/plain");
IntentFilter filter_cat5 = new IntentFilter();
filter_cat5.addDataType("video/*");
IntentFilter filter_any = new IntentFilter();
filter_any.addDataType("*/*");
setCaller(LAUNCHER_1, USER_0);
mCallerPermissions.add(permission.MANAGE_APP_PREDICTIONS);
assertTrue(mInternal.isSharingShortcut(USER_0, LAUNCHER_1, CALLING_PACKAGE_1, "s1", USER_0,
filter_cat1));
assertFalse(mInternal.isSharingShortcut(USER_0, LAUNCHER_1, CALLING_PACKAGE_1, "s1", USER_0,
filter_cat5));
assertTrue(mInternal.isSharingShortcut(USER_0, LAUNCHER_1, CALLING_PACKAGE_1, "s1", USER_0,
filter_any));
assertFalse(mInternal.isSharingShortcut(USER_0, LAUNCHER_1, CALLING_PACKAGE_1, "s2", USER_0,
filter_cat1));
assertTrue(mInternal.isSharingShortcut(USER_0, LAUNCHER_1, CALLING_PACKAGE_1, "s2", USER_0,
filter_cat5));
assertTrue(mInternal.isSharingShortcut(USER_0, LAUNCHER_1, CALLING_PACKAGE_1, "s2", USER_0,
filter_any));
assertFalse(mInternal.isSharingShortcut(USER_0, LAUNCHER_1, CALLING_PACKAGE_1, "s3", USER_0,
filter_any));
assertFalse(mInternal.isSharingShortcut(USER_0, LAUNCHER_1, CALLING_PACKAGE_1, "s4", 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.