use of android.content.pm.ShortcutInfo in project platform_frameworks_base by android.
the class ShortcutManagerTestUtils method assertShortcutIds.
public static List<ShortcutInfo> assertShortcutIds(List<ShortcutInfo> actualShortcuts, String... expectedIds) {
final SortedSet<String> expected = new TreeSet<>(list(expectedIds));
final SortedSet<String> actual = new TreeSet<>();
for (ShortcutInfo s : actualShortcuts) {
actual.add(s.getId());
}
// Compare the sets.
assertEquals(expected, actual);
return actualShortcuts;
}
use of android.content.pm.ShortcutInfo in project platform_frameworks_base by android.
the class ShortcutManagerTestUtils method assertShortcutIdsOrdered.
public static List<ShortcutInfo> assertShortcutIdsOrdered(List<ShortcutInfo> actualShortcuts, String... expectedIds) {
final ArrayList<String> expected = new ArrayList<>(list(expectedIds));
final ArrayList<String> actual = new ArrayList<>();
for (ShortcutInfo s : actualShortcuts) {
actual.add(s.getId());
}
assertEquals(expected, actual);
return actualShortcuts;
}
use of android.content.pm.ShortcutInfo in project platform_frameworks_base by android.
the class ShortcutManagerTestUtils method parceled.
public static ShortcutInfo parceled(ShortcutInfo si) {
Parcel p = Parcel.obtain();
p.writeParcelable(si, 0);
p.setDataPosition(0);
ShortcutInfo si2 = p.readParcelable(ShortcutManagerTestUtils.class.getClassLoader());
p.recycle();
return si2;
}
use of android.content.pm.ShortcutInfo in project platform_frameworks_base by android.
the class ShortcutManagerTest1 method testStartShortcut.
public void testStartShortcut() {
// Create some shortcuts.
runWithCaller(CALLING_PACKAGE_1, USER_0, () -> {
final ShortcutInfo s1_1 = makeShortcut("s1", "Title 1", makeComponent(ShortcutActivity.class), /* icon =*/
null, new Intent[] { makeIntent(Intent.ACTION_ASSIST, ShortcutActivity2.class, "key1", "val1", "nest", makeBundle("key", 123)).setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK), new Intent("act2").setFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION) }, /* rank */
10);
final ShortcutInfo s1_2 = makeShortcut("s2", "Title 2", /* activity */
null, /* icon =*/
null, makeIntent(Intent.ACTION_ASSIST, ShortcutActivity3.class), /* rank */
12);
final ShortcutInfo s1_3 = makeShortcut("s3");
assertTrue(mManager.setDynamicShortcuts(list(s1_1, s1_2, s1_3)));
});
runWithCaller(CALLING_PACKAGE_2, USER_0, () -> {
final ShortcutInfo s2_1 = makeShortcut("s1", "ABC", makeComponent(ShortcutActivity.class), /* icon =*/
null, makeIntent(Intent.ACTION_ANSWER, ShortcutActivity.class, "key1", "val1", "nest", makeBundle("key", 123)), /* weight */
10);
assertTrue(mManager.setDynamicShortcuts(list(s2_1)));
});
// Pin some.
runWithCaller(LAUNCHER_1, USER_0, () -> {
mLauncherApps.pinShortcuts(CALLING_PACKAGE_1, list("s1", "s2"), getCallingUser());
mLauncherApps.pinShortcuts(CALLING_PACKAGE_2, list("s1"), getCallingUser());
});
// Just to make it complicated, delete some.
runWithCaller(CALLING_PACKAGE_1, USER_0, () -> {
mManager.removeDynamicShortcuts(list("s2"));
});
runWithCaller(LAUNCHER_1, USER_0, () -> {
final Intent[] intents = launchShortcutAndGetIntents(CALLING_PACKAGE_1, "s1", USER_0);
assertEquals(ShortcutActivity2.class.getName(), intents[0].getComponent().getClassName());
assertEquals(Intent.ACTION_ASSIST, intents[0].getAction());
assertEquals(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK, intents[0].getFlags());
assertEquals("act2", intents[1].getAction());
assertEquals(Intent.FLAG_ACTIVITY_NO_ANIMATION, intents[1].getFlags());
assertEquals(ShortcutActivity3.class.getName(), launchShortcutAndGetIntent(CALLING_PACKAGE_1, "s2", USER_0).getComponent().getClassName());
assertEquals(ShortcutActivity.class.getName(), launchShortcutAndGetIntent(CALLING_PACKAGE_2, "s1", USER_0).getComponent().getClassName());
assertShortcutLaunchable(CALLING_PACKAGE_1, "s3", USER_0);
assertShortcutNotLaunched("no-such-package", "s2", USER_0);
assertShortcutNotLaunched(CALLING_PACKAGE_1, "xxxx", USER_0);
});
// LAUNCHER_1 is no longer the default launcher
setDefaultLauncherChecker((pkg, userId) -> false);
runWithCaller(LAUNCHER_1, USER_0, () -> {
// Not the default launcher, but pinned shortcuts are still lauchable.
final Intent[] intents = launchShortcutAndGetIntents(CALLING_PACKAGE_1, "s1", USER_0);
assertEquals(ShortcutActivity2.class.getName(), intents[0].getComponent().getClassName());
assertEquals(Intent.ACTION_ASSIST, intents[0].getAction());
assertEquals(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK, intents[0].getFlags());
assertEquals("act2", intents[1].getAction());
assertEquals(Intent.FLAG_ACTIVITY_NO_ANIMATION, intents[1].getFlags());
assertEquals(ShortcutActivity3.class.getName(), launchShortcutAndGetIntent(CALLING_PACKAGE_1, "s2", USER_0).getComponent().getClassName());
assertEquals(ShortcutActivity.class.getName(), launchShortcutAndGetIntent(CALLING_PACKAGE_2, "s1", USER_0).getComponent().getClassName());
// Not pinned, so not lauchable.
});
// Test inner errors.
runWithCaller(LAUNCHER_1, USER_0, () -> {
// Not launchable.
doReturn(ActivityManager.START_CLASS_NOT_FOUND).when(mMockActivityManagerInternal).startActivitiesAsPackage(anyString(), anyInt(), any(Intent[].class), any(Bundle.class));
assertStartShortcutThrowsException(CALLING_PACKAGE_1, "s1", USER_0, ActivityNotFoundException.class);
// Still not launchable.
doReturn(ActivityManager.START_CLASS_NOT_FOUND).when(mMockActivityManagerInternal).startActivitiesAsPackage(anyString(), anyInt(), any(Intent[].class), any(Bundle.class));
assertStartShortcutThrowsException(CALLING_PACKAGE_1, "s1", USER_0, ActivityNotFoundException.class);
});
// TODO Check extra, etc
}
use of android.content.pm.ShortcutInfo in project platform_frameworks_base by android.
the class ShortcutManagerTest1 method testAddDynamicShortcuts.
public void testAddDynamicShortcuts() {
setCaller(CALLING_PACKAGE_1, USER_0);
final ShortcutInfo si1 = makeShortcut("shortcut1");
final ShortcutInfo si2 = makeShortcut("shortcut2");
final ShortcutInfo si3 = makeShortcut("shortcut3");
assertEquals(3, mManager.getRemainingCallCount());
assertTrue(mManager.setDynamicShortcuts(list(si1)));
assertEquals(2, mManager.getRemainingCallCount());
assertShortcutIds(assertAllNotKeyFieldsOnly(mManager.getDynamicShortcuts()), "shortcut1");
assertTrue(mManager.addDynamicShortcuts(list(si2, si3)));
assertEquals(1, mManager.getRemainingCallCount());
assertShortcutIds(assertAllNotKeyFieldsOnly(mManager.getDynamicShortcuts()), "shortcut1", "shortcut2", "shortcut3");
// This should not crash. It'll still consume the quota.
assertTrue(mManager.addDynamicShortcuts(list()));
assertEquals(0, mManager.getRemainingCallCount());
assertShortcutIds(assertAllNotKeyFieldsOnly(mManager.getDynamicShortcuts()), "shortcut1", "shortcut2", "shortcut3");
// reset
mInjectedCurrentTimeMillis += INTERVAL;
// Add with the same ID
assertTrue(mManager.addDynamicShortcuts(list(makeShortcut("shortcut1"))));
assertEquals(2, mManager.getRemainingCallCount());
assertShortcutIds(assertAllNotKeyFieldsOnly(mManager.getDynamicShortcuts()), "shortcut1", "shortcut2", "shortcut3");
// TODO Check max number
// TODO Check fields.
mRunningUsers.put(USER_10, true);
runWithCaller(CALLING_PACKAGE_2, USER_10, () -> {
assertTrue(mManager.addDynamicShortcuts(list(makeShortcut("s1"))));
});
}
Aggregations