use of android.content.pm.ShortcutInfo in project platform_frameworks_base by android.
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 platform_frameworks_base by android.
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());
}
use of android.content.pm.ShortcutInfo in project platform_frameworks_base by android.
the class ShortcutManagerTest2 method testShortcutInfoCopyNonNullFieldsFrom.
public void testShortcutInfoCopyNonNullFieldsFrom() throws InterruptedException {
PersistableBundle pb = new PersistableBundle();
pb.putInt("k", 1);
ShortcutInfo sorig = new ShortcutInfo.Builder(getTestContext()).setId("id").setActivity(new ComponentName("a", "b")).setIcon(Icon.createWithResource(mClientContext, 123)).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();
sorig.addFlags(ShortcutInfo.FLAG_PINNED);
sorig.setBitmapPath("abc");
sorig.setIconResourceId(456);
lookupAndFillInResourceNames(sorig);
ShortcutInfo si;
si = sorig.clone(/* flags=*/
0);
si.copyNonNullFieldsFrom(new ShortcutInfo.Builder(getTestContext()).setId("id").setActivity(new ComponentName("x", "y")).build());
assertEquals("text", si.getText());
assertEquals(123, si.getRank());
assertEquals(new ComponentName("x", "y"), si.getActivity());
si = sorig.clone(/* flags=*/
0);
si.copyNonNullFieldsFrom(new ShortcutInfo.Builder(getTestContext()).setId("id").setIcon(Icon.createWithResource(mClientContext, 456)).build());
assertEquals("text", si.getText());
assertEquals(456, si.getIcon().getResId());
assertEquals(0, si.getIconResourceId());
assertEquals(null, si.getIconResName());
assertEquals(null, si.getBitmapPath());
si = sorig.clone(/* flags=*/
0);
si.copyNonNullFieldsFrom(new ShortcutInfo.Builder(getTestContext()).setId("id").setTitle("xyz").build());
assertEquals("text", si.getText());
assertEquals("xyz", si.getTitle());
assertEquals(0, si.getTitleResId());
si = sorig.clone(/* flags=*/
0);
si.copyNonNullFieldsFrom(new ShortcutInfo.Builder(getTestContext()).setId("id").setTitleResId(123).build());
assertEquals("text", si.getText());
assertEquals(null, si.getTitle());
assertEquals(123, si.getTitleResId());
si = sorig.clone(/* flags=*/
0);
si.copyNonNullFieldsFrom(new ShortcutInfo.Builder(getTestContext()).setId("id").setText("xxx").build());
assertEquals(123, si.getRank());
assertEquals("xxx", si.getText());
assertEquals(0, si.getTextResId());
si = sorig.clone(/* flags=*/
0);
si.copyNonNullFieldsFrom(new ShortcutInfo.Builder(getTestContext()).setId("id").setTextResId(1111).build());
assertEquals(123, si.getRank());
assertEquals(null, si.getText());
assertEquals(1111, si.getTextResId());
si = sorig.clone(/* flags=*/
0);
si.copyNonNullFieldsFrom(new ShortcutInfo.Builder(getTestContext()).setId("id").setDisabledMessage("xxx").build());
assertEquals(123, si.getRank());
assertEquals("xxx", si.getDisabledMessage());
assertEquals(0, si.getDisabledMessageResourceId());
si = sorig.clone(/* flags=*/
0);
si.copyNonNullFieldsFrom(new ShortcutInfo.Builder(getTestContext()).setId("id").setDisabledMessageResId(11111).build());
assertEquals(123, si.getRank());
assertEquals(null, si.getDisabledMessage());
assertEquals(11111, si.getDisabledMessageResourceId());
si = sorig.clone(/* flags=*/
0);
si.copyNonNullFieldsFrom(new ShortcutInfo.Builder(getTestContext()).setId("id").setCategories(set()).build());
assertEquals("text", si.getText());
assertEquals(set(), si.getCategories());
si = sorig.clone(/* flags=*/
0);
si.copyNonNullFieldsFrom(new ShortcutInfo.Builder(getTestContext()).setId("id").setCategories(set("x")).build());
assertEquals("text", si.getText());
assertEquals(set("x"), si.getCategories());
si = sorig.clone(/* flags=*/
0);
si.copyNonNullFieldsFrom(new ShortcutInfo.Builder(getTestContext()).setId("id").setIntent(makeIntent("action2", ShortcutActivity.class)).build());
assertEquals("text", si.getText());
assertEquals("action2", si.getIntent().getAction());
assertEquals(null, si.getIntent().getStringExtra("key"));
si = sorig.clone(/* flags=*/
0);
si.copyNonNullFieldsFrom(new ShortcutInfo.Builder(getTestContext()).setId("id").setIntent(makeIntent("action3", ShortcutActivity.class, "key", "x")).build());
assertEquals("text", si.getText());
assertEquals("action3", si.getIntent().getAction());
assertEquals("x", si.getIntent().getStringExtra("key"));
si = sorig.clone(/* flags=*/
0);
si.copyNonNullFieldsFrom(new ShortcutInfo.Builder(getTestContext()).setId("id").setRank(999).build());
assertEquals("text", si.getText());
assertEquals(999, si.getRank());
PersistableBundle pb2 = new PersistableBundle();
pb2.putInt("x", 99);
si = sorig.clone(/* flags=*/
0);
si.copyNonNullFieldsFrom(new ShortcutInfo.Builder(getTestContext()).setId("id").setExtras(pb2).build());
assertEquals("text", si.getText());
assertEquals(99, si.getExtras().getInt("x"));
}
use of android.content.pm.ShortcutInfo in project platform_frameworks_base by android.
the class ShortcutManagerTest2 method testThrottling_rewind.
public void testThrottling_rewind() {
final ShortcutInfo si1 = makeShortcut("shortcut1");
assertTrue(mManager.setDynamicShortcuts(list(si1)));
assertEquals(2, mManager.getRemainingCallCount());
assertEquals(START_TIME + INTERVAL, mManager.getRateLimitResetTime());
// Clock reset!
mInjectedCurrentTimeMillis = 12345;
// Since the clock looks invalid, the counter shouldn't have reset.
assertEquals(2, mManager.getRemainingCallCount());
assertEquals(START_TIME + INTERVAL, mManager.getRateLimitResetTime());
// Forward again. Still haven't reset yet.
mInjectedCurrentTimeMillis = START_TIME + INTERVAL - 1;
assertEquals(2, mManager.getRemainingCallCount());
assertEquals(START_TIME + INTERVAL, mManager.getRateLimitResetTime());
// Now rewind -- this will reset the counters.
mInjectedCurrentTimeMillis = START_TIME - 100000;
assertEquals(3, mManager.getRemainingCallCount());
assertTrue(mManager.setDynamicShortcuts(list(si1)));
assertEquals(2, mManager.getRemainingCallCount());
// Forward again, should be reset now.
mInjectedCurrentTimeMillis += INTERVAL;
assertEquals(3, mManager.getRemainingCallCount());
}
use of android.content.pm.ShortcutInfo in project platform_frameworks_base by android.
the class BaseShortcutManagerTest method makeShortcut.
/**
* Make a shortcut with details.
*/
protected ShortcutInfo makeShortcut(String id, String title, ComponentName activity, Icon icon, Intent[] intents, int rank) {
final ShortcutInfo.Builder b = new ShortcutInfo.Builder(mClientContext, id).setActivity(new ComponentName(mClientContext.getPackageName(), "dummy")).setShortLabel(title).setRank(rank).setIntents(intents);
if (icon != null) {
b.setIcon(icon);
}
if (activity != null) {
b.setActivity(activity);
}
final ShortcutInfo s = b.build();
// HACK
s.setTimestamp(mInjectedCurrentTimeMillis);
return s;
}
Aggregations