use of android.content.pm.ShortcutInfo in project android_frameworks_base by ResurrectionRemix.
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 android_frameworks_base by ResurrectionRemix.
the class ShortcutManagerTest1 method testGetShortcutInfo.
// TODO resource
public void testGetShortcutInfo() {
// Create shortcuts.
setCaller(CALLING_PACKAGE_1);
final ShortcutInfo s1_1 = makeShortcut("s1", "Title 1", makeComponent(ShortcutActivity.class), /* icon =*/
null, makeIntent(Intent.ACTION_ASSIST, ShortcutActivity2.class, "key1", "val1", "nest", makeBundle("key", 123)), /* weight */
10);
final ShortcutInfo s1_2 = makeShortcut("s2", "Title 2", /* activity */
null, /* icon =*/
null, makeIntent(Intent.ACTION_ASSIST, ShortcutActivity3.class), /* weight */
12);
assertTrue(mManager.setDynamicShortcuts(list(s1_1, s1_2)));
dumpsysOnLogcat();
setCaller(CALLING_PACKAGE_2);
final ShortcutInfo s2_1 = makeShortcut("s1", "ABC", makeComponent(ShortcutActivity2.class), /* icon =*/
null, makeIntent(Intent.ACTION_ANSWER, ShortcutActivity2.class, "key1", "val1", "nest", makeBundle("key", 123)), /* weight */
10);
assertTrue(mManager.setDynamicShortcuts(list(s2_1)));
dumpsysOnLogcat();
// Pin some.
setCaller(LAUNCHER_1);
mLauncherApps.pinShortcuts(CALLING_PACKAGE_1, list("s2"), getCallingUser());
dumpsysOnLogcat();
// Delete some.
setCaller(CALLING_PACKAGE_1);
assertShortcutIds(mManager.getPinnedShortcuts(), "s2");
mManager.removeDynamicShortcuts(list("s2"));
assertShortcutIds(mManager.getPinnedShortcuts(), "s2");
dumpsysOnLogcat();
setCaller(LAUNCHER_1);
List<ShortcutInfo> list;
// Note we don't guarantee the orders.
list = assertShortcutIds(assertAllHaveTitle(assertAllNotHaveIntents(assertAllNotKeyFieldsOnly(mLauncherApps.getShortcutInfo(CALLING_PACKAGE_1, list("s2", "s1", "s3", null), getCallingUser())))), "s1", "s2");
assertEquals("Title 1", findById(list, "s1").getTitle());
assertEquals("Title 2", findById(list, "s2").getTitle());
assertShortcutIds(assertAllHaveTitle(assertAllNotHaveIntents(mLauncherApps.getShortcutInfo(CALLING_PACKAGE_1, list("s3"), getCallingUser()))));
list = assertShortcutIds(assertAllHaveTitle(assertAllNotHaveIntents(mLauncherApps.getShortcutInfo(CALLING_PACKAGE_2, list("s1", "s2", "s3"), getCallingUser()))), "s1");
assertEquals("ABC", findById(list, "s1").getTitle());
}
use of android.content.pm.ShortcutInfo in project android_frameworks_base by ResurrectionRemix.
the class ShortcutManagerTest1 method testManifestShortcuts_duplicateInSingleActivity.
public void testManifestShortcuts_duplicateInSingleActivity() {
mService.handleUnlockUser(USER_0);
// The XML has two shortcuts with the same ID.
addManifestShortcutResource(new ComponentName(CALLING_PACKAGE_1, ShortcutActivity.class.getName()), R.xml.shortcut_2_duplicate);
updatePackageVersion(CALLING_PACKAGE_1, 1);
mService.mPackageMonitor.onReceive(getTestContext(), genPackageAddIntent(CALLING_PACKAGE_1, USER_0));
runWithCaller(CALLING_PACKAGE_1, USER_0, () -> {
assertShortcutIds(assertAllManifest(assertAllImmutable(assertAllEnabled(mManager.getManifestShortcuts()))), "ms1");
// Make sure the first one has survived. (the second one has a different title.)
ShortcutInfo si = getCallerShortcut("ms1");
assertEquals(R.string.shortcut_title1, si.getTitleResId());
// Make sure there's no other dangling shortcuts.
assertShortcutIds(getCallerShortcuts(), "ms1");
});
}
use of android.content.pm.ShortcutInfo in project android_frameworks_base by ResurrectionRemix.
the class BaseShortcutManagerTest method makeShortcutWithTimestampWithActivity.
/**
* Make a shortcut with an ID, a timestamp and an activity component
*/
protected ShortcutInfo makeShortcutWithTimestampWithActivity(String id, long timestamp, ComponentName activity) {
final ShortcutInfo s = makeShortcut(id, "Title-" + id, activity, /* icon =*/
null, makeIntent(Intent.ACTION_VIEW, ShortcutActivity.class), /* rank =*/
0);
s.setTimestamp(timestamp);
return s;
}
use of android.content.pm.ShortcutInfo in project android_frameworks_base by ResurrectionRemix.
the class ShortcutManagerTest1 method testMaxShortcutCount_set.
public void testMaxShortcutCount_set() {
// Change the max number of shortcuts.
mService.updateConfigurationLocked(ConfigConstants.KEY_MAX_SHORTCUTS + "=3");
runWithCaller(CALLING_PACKAGE_1, USER_0, () -> {
final ComponentName a1 = new ComponentName(mClientContext, ShortcutActivity.class);
final ComponentName a2 = new ComponentName(mClientContext, ShortcutActivity2.class);
final ShortcutInfo s1_1 = makeShortcutWithActivity("s11", a1);
final ShortcutInfo s1_2 = makeShortcutWithActivity("s12", a1);
final ShortcutInfo s1_3 = makeShortcutWithActivity("s13", a1);
final ShortcutInfo s1_4 = makeShortcutWithActivity("s14", a1);
final ShortcutInfo s1_5 = makeShortcutWithActivity("s15", a1);
final ShortcutInfo s1_6 = makeShortcutWithActivity("s16", a1);
final ShortcutInfo s2_1 = makeShortcutWithActivity("s21", a2);
final ShortcutInfo s2_2 = makeShortcutWithActivity("s22", a2);
final ShortcutInfo s2_3 = makeShortcutWithActivity("s23", a2);
final ShortcutInfo s2_4 = makeShortcutWithActivity("s24", a2);
// 3 shortcuts for 2 activities -> okay
mManager.setDynamicShortcuts(list(s1_1, s1_2, s1_3, s2_1, s2_2, s2_3));
assertShortcutIds(mManager.getDynamicShortcuts(), "s11", "s12", "s13", "s21", "s22", "s23");
mManager.removeAllDynamicShortcuts();
// 4 shortcut for activity 1 -> too many.
assertDynamicShortcutCountExceeded(() -> {
mManager.setDynamicShortcuts(list(s1_1, s1_2, s1_3, s1_4, s2_1, s2_2, s2_3));
});
assertEmpty(mManager.getDynamicShortcuts());
// 4 shortcut for activity 2 -> too many.
assertDynamicShortcutCountExceeded(() -> {
mManager.setDynamicShortcuts(list(s1_1, s1_2, s1_3, s2_1, s2_2, s2_3, s2_4));
});
assertEmpty(mManager.getDynamicShortcuts());
// First, set 3. Then set 4, which should be ignored.
mManager.setDynamicShortcuts(list(s1_1, s1_2, s1_3));
assertShortcutIds(mManager.getDynamicShortcuts(), "s11", "s12", "s13");
assertDynamicShortcutCountExceeded(() -> {
mManager.setDynamicShortcuts(list(s2_1, s2_2, s2_3, s2_4));
});
assertShortcutIds(mManager.getDynamicShortcuts(), "s11", "s12", "s13");
// Set will remove the old dynamic set, unlike add, so the following should pass.
mManager.setDynamicShortcuts(list(s1_1, s1_2, s1_3));
assertShortcutIds(mManager.getDynamicShortcuts(), "s11", "s12", "s13");
mManager.setDynamicShortcuts(list(s1_4, s1_5, s1_6));
assertShortcutIds(mManager.getDynamicShortcuts(), "s14", "s15", "s16");
// Now, test with 2 manifest shortcuts.
mManager.removeAllDynamicShortcuts();
addManifestShortcutResource(new ComponentName(CALLING_PACKAGE_1, ShortcutActivity.class.getName()), R.xml.shortcut_2);
updatePackageVersion(CALLING_PACKAGE_1, 1);
mService.mPackageMonitor.onReceive(getTestContext(), genPackageAddIntent(CALLING_PACKAGE_1, USER_0));
assertEquals(2, mManager.getManifestShortcuts().size());
// Setting 1 to activity 1 will work.
mManager.setDynamicShortcuts(list(s1_1, s2_1, s2_2, s2_3));
assertShortcutIds(mManager.getDynamicShortcuts(), "s11", "s21", "s22", "s23");
assertEquals(2, mManager.getManifestShortcuts().size());
// But setting 2 will not.
mManager.removeAllDynamicShortcuts();
assertDynamicShortcutCountExceeded(() -> {
mManager.setDynamicShortcuts(list(s1_1, s1_2, s2_1, s2_2, s2_3));
});
assertEmpty(mManager.getDynamicShortcuts());
assertEquals(2, mManager.getManifestShortcuts().size());
});
}
Aggregations