use of android.content.pm.ShortcutInfo in project android_frameworks_base by ResurrectionRemix.
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 android_frameworks_base by ResurrectionRemix.
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 android_frameworks_base by ResurrectionRemix.
the class ShortcutManagerTest1 method testPublishWithNoActivity.
public void testPublishWithNoActivity() {
// If activity is not explicitly set, use the default one.
mRunningUsers.put(USER_10, true);
runWithCaller(CALLING_PACKAGE_2, USER_10, () -> {
// s1 and s3 has no activities.
final ShortcutInfo si1 = new ShortcutInfo.Builder(mClientContext, "si1").setShortLabel("label1").setIntent(new Intent("action1")).build();
final ShortcutInfo si2 = new ShortcutInfo.Builder(mClientContext, "si2").setShortLabel("label2").setActivity(new ComponentName(getCallingPackage(), "abc")).setIntent(new Intent("action2")).build();
final ShortcutInfo si3 = new ShortcutInfo.Builder(mClientContext, "si3").setShortLabel("label3").setIntent(new Intent("action3")).build();
// Set test 1
assertTrue(mManager.setDynamicShortcuts(list(si1)));
assertWith(getCallerShortcuts()).haveIds("si1").forShortcutWithId("si1", si -> {
assertEquals(new ComponentName(getCallingPackage(), MAIN_ACTIVITY_CLASS), si.getActivity());
});
// Set test 2
assertTrue(mManager.setDynamicShortcuts(list(si2, si1)));
assertWith(getCallerShortcuts()).haveIds("si1", "si2").forShortcutWithId("si1", si -> {
assertEquals(new ComponentName(getCallingPackage(), MAIN_ACTIVITY_CLASS), si.getActivity());
}).forShortcutWithId("si2", si -> {
assertEquals(new ComponentName(getCallingPackage(), "abc"), si.getActivity());
});
// Set test 3
assertTrue(mManager.setDynamicShortcuts(list(si3, si1)));
assertWith(getCallerShortcuts()).haveIds("si1", "si3").forShortcutWithId("si1", si -> {
assertEquals(new ComponentName(getCallingPackage(), MAIN_ACTIVITY_CLASS), si.getActivity());
}).forShortcutWithId("si3", si -> {
assertEquals(new ComponentName(getCallingPackage(), MAIN_ACTIVITY_CLASS), si.getActivity());
});
// reset throttling
mInjectedCurrentTimeMillis += INTERVAL;
// Add test 1
mManager.removeAllDynamicShortcuts();
assertTrue(mManager.addDynamicShortcuts(list(si1)));
assertWith(getCallerShortcuts()).haveIds("si1").forShortcutWithId("si1", si -> {
assertEquals(new ComponentName(getCallingPackage(), MAIN_ACTIVITY_CLASS), si.getActivity());
});
// Add test 2
mManager.removeAllDynamicShortcuts();
assertTrue(mManager.addDynamicShortcuts(list(si2, si1)));
assertWith(getCallerShortcuts()).haveIds("si1", "si2").forShortcutWithId("si1", si -> {
assertEquals(new ComponentName(getCallingPackage(), MAIN_ACTIVITY_CLASS), si.getActivity());
}).forShortcutWithId("si2", si -> {
assertEquals(new ComponentName(getCallingPackage(), "abc"), si.getActivity());
});
// Add test 3
mManager.removeAllDynamicShortcuts();
assertTrue(mManager.addDynamicShortcuts(list(si3, si1)));
assertWith(getCallerShortcuts()).haveIds("si1", "si3").forShortcutWithId("si1", si -> {
assertEquals(new ComponentName(getCallingPackage(), MAIN_ACTIVITY_CLASS), si.getActivity());
}).forShortcutWithId("si3", si -> {
assertEquals(new ComponentName(getCallingPackage(), MAIN_ACTIVITY_CLASS), si.getActivity());
});
});
}
use of android.content.pm.ShortcutInfo in project android_frameworks_base by ResurrectionRemix.
the class ShortcutManagerTest2 method testShortcutInfoSaveAndLoad_forBackup.
public void testShortcutInfoSaveAndLoad_forBackup() {
setCaller(CALLING_PACKAGE_1, USER_0);
final Icon bmp32x32 = Icon.createWithBitmap(BitmapFactory.decodeResource(getTestContext().getResources(), R.drawable.black_32x32));
PersistableBundle pb = new PersistableBundle();
pb.putInt("k", 1);
ShortcutInfo sorig = new ShortcutInfo.Builder(mClientContext).setId("id").setActivity(new ComponentName(mClientContext, ShortcutActivity2.class)).setIcon(bmp32x32).setTitle("title").setText("text").setDisabledMessage("dismes").setCategories(set(ShortcutInfo.SHORTCUT_CATEGORY_CONVERSATION, "xyz")).setIntent(makeIntent("action", ShortcutActivity.class, "key", "val")).setRank(123).setExtras(pb).build();
ShortcutInfo sorig2 = new ShortcutInfo.Builder(mClientContext).setId("id2").setTitle("x").setActivity(new ComponentName(mClientContext, ShortcutActivity2.class)).setIntent(makeIntent("action", ShortcutActivity.class, "key", "val")).setRank(456).build();
mManager.addDynamicShortcuts(list(sorig, sorig2));
// Dynamic shortcuts won't be backed up, so we need to pin it.
setCaller(LAUNCHER_1, USER_0);
mLauncherApps.pinShortcuts(CALLING_PACKAGE_1, list("id", "id2"), HANDLE_USER_0);
// Do backup & restore.
backupAndRestore();
// Load user-0.
mService.handleUnlockUser(USER_0);
ShortcutInfo si;
si = mService.getPackageShortcutForTest(CALLING_PACKAGE_1, "id", USER_0);
assertEquals(CALLING_PACKAGE_1, si.getPackage());
assertEquals("id", si.getId());
assertEquals(ShortcutActivity2.class.getName(), si.getActivity().getClassName());
assertEquals(null, si.getIcon());
assertEquals("title", si.getTitle());
assertEquals("text", si.getText());
assertEquals("dismes", si.getDisabledMessage());
assertEquals(set(ShortcutInfo.SHORTCUT_CATEGORY_CONVERSATION, "xyz"), si.getCategories());
assertEquals("action", si.getIntent().getAction());
assertEquals("val", si.getIntent().getStringExtra("key"));
assertEquals(0, si.getRank());
assertEquals(1, si.getExtras().getInt("k"));
assertEquals(ShortcutInfo.FLAG_PINNED | ShortcutInfo.FLAG_STRINGS_RESOLVED, si.getFlags());
// No icon.
assertNull(si.getBitmapPath());
assertEquals(0, si.getIconResourceId());
// Note when restored from backup, it's no longer dynamic, so shouldn't have a rank.
si = mService.getPackageShortcutForTest(CALLING_PACKAGE_1, "id2", USER_0);
assertEquals(0, si.getRank());
}
use of android.content.pm.ShortcutInfo in project android_frameworks_base by ResurrectionRemix.
the class ShortcutManagerTest2 method testShortcutInfoParcel.
public void testShortcutInfoParcel() {
setCaller(CALLING_PACKAGE_1, USER_10);
ShortcutInfo si = parceled(new ShortcutInfo.Builder(mClientContext).setId("id").setTitle("title").setIntent(makeIntent("action", ShortcutActivity.class)).build());
assertEquals(mClientContext.getPackageName(), si.getPackage());
assertEquals(USER_10, si.getUserId());
assertEquals(HANDLE_USER_10, si.getUserHandle());
assertEquals("id", si.getId());
assertEquals("title", si.getTitle());
assertEquals("action", si.getIntent().getAction());
PersistableBundle pb = new PersistableBundle();
pb.putInt("k", 1);
si = new ShortcutInfo.Builder(getTestContext()).setId("id").setActivity(new ComponentName("a", "b")).setIcon(Icon.createWithResource(mClientContext, 123)).setTitle("title").setText("text").setDisabledMessage("dismes").setIntent(makeIntent("action", ShortcutActivity.class, "key", "val")).setCategories(set(ShortcutInfo.SHORTCUT_CATEGORY_CONVERSATION, "xyz")).setRank(123).setExtras(pb).build();
si.addFlags(ShortcutInfo.FLAG_PINNED);
si.setBitmapPath("abc");
si.setIconResourceId(456);
si = parceled(si);
assertEquals(getTestContext().getPackageName(), si.getPackage());
assertEquals("id", si.getId());
assertEquals(new ComponentName("a", "b"), si.getActivity());
assertEquals(123, si.getIcon().getResId());
assertEquals("title", si.getTitle());
assertEquals("text", si.getText());
assertEquals("dismes", si.getDisabledMessage());
assertEquals(set(ShortcutInfo.SHORTCUT_CATEGORY_CONVERSATION, "xyz"), si.getCategories());
assertEquals("action", si.getIntent().getAction());
assertEquals("val", si.getIntent().getStringExtra("key"));
assertEquals(123, si.getRank());
assertEquals(1, si.getExtras().getInt("k"));
assertEquals(ShortcutInfo.FLAG_PINNED, si.getFlags());
assertEquals("abc", si.getBitmapPath());
assertEquals(456, si.getIconResourceId());
assertEquals(0, si.getTitleResId());
assertEquals(null, si.getTitleResName());
assertEquals(0, si.getTextResId());
assertEquals(null, si.getTextResName());
assertEquals(0, si.getDisabledMessageResourceId());
assertEquals(null, si.getDisabledMessageResName());
}
Aggregations