use of android.content.pm.ShortcutInfo in project platform_frameworks_base by android.
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 platform_frameworks_base by android.
the class ShortcutManagerTest1 method testManifestShortcuts_localeChange.
public void testManifestShortcuts_localeChange() throws InterruptedException {
mService.handleUnlockUser(USER_0);
// Package 1 updated, which has one valid manifest shortcut and one invalid.
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));
runWithCaller(CALLING_PACKAGE_1, USER_0, () -> {
mManager.setDynamicShortcuts(list(makeShortcutWithTitle("s1", "title")));
assertShortcutIds(assertAllManifest(assertAllImmutable(assertAllEnabled(mManager.getManifestShortcuts()))), "ms1", "ms2");
// check first shortcut.
ShortcutInfo si = getCallerShortcut("ms1");
assertEquals("ms1", si.getId());
assertEquals("string-com.android.test.1-user:0-res:" + R.string.shortcut_title1 + "/en", si.getTitle());
assertEquals("string-com.android.test.1-user:0-res:" + R.string.shortcut_text1 + "/en", si.getText());
assertEquals("string-com.android.test.1-user:0-res:" + R.string.shortcut_disabled_message1 + "/en", si.getDisabledMessage());
assertEquals(START_TIME, si.getLastChangedTimestamp());
// check another
si = getCallerShortcut("ms2");
assertEquals("ms2", si.getId());
assertEquals("string-com.android.test.1-user:0-res:" + R.string.shortcut_title2 + "/en", si.getTitle());
assertEquals("string-com.android.test.1-user:0-res:" + R.string.shortcut_text2 + "/en", si.getText());
assertEquals("string-com.android.test.1-user:0-res:" + R.string.shortcut_disabled_message2 + "/en", si.getDisabledMessage());
assertEquals(START_TIME, si.getLastChangedTimestamp());
// Check the dynamic one.
si = getCallerShortcut("s1");
assertEquals("s1", si.getId());
assertEquals("title", si.getTitle());
assertEquals(null, si.getText());
assertEquals(null, si.getDisabledMessage());
assertEquals(START_TIME, si.getLastChangedTimestamp());
});
mInjectedCurrentTimeMillis++;
// Change the locale and send the broadcast, make sure the launcher gets a callback too.
mInjectedLocale = Locale.JAPANESE;
setCaller(LAUNCHER_1, USER_0);
assertForLauncherCallback(mLauncherApps, () -> {
mService.mReceiver.onReceive(mServiceContext, new Intent(Intent.ACTION_LOCALE_CHANGED));
}).assertCallbackCalledForPackageAndUser(CALLING_PACKAGE_1, HANDLE_USER_0).haveIds("ms1", "ms2", "s1");
runWithCaller(CALLING_PACKAGE_1, USER_0, () -> {
// check first shortcut.
ShortcutInfo si = getCallerShortcut("ms1");
assertEquals("ms1", si.getId());
assertEquals("string-com.android.test.1-user:0-res:" + R.string.shortcut_title1 + "/ja", si.getTitle());
assertEquals("string-com.android.test.1-user:0-res:" + R.string.shortcut_text1 + "/ja", si.getText());
assertEquals("string-com.android.test.1-user:0-res:" + R.string.shortcut_disabled_message1 + "/ja", si.getDisabledMessage());
assertEquals(START_TIME + 1, si.getLastChangedTimestamp());
// check another
si = getCallerShortcut("ms2");
assertEquals("ms2", si.getId());
assertEquals("string-com.android.test.1-user:0-res:" + R.string.shortcut_title2 + "/ja", si.getTitle());
assertEquals("string-com.android.test.1-user:0-res:" + R.string.shortcut_text2 + "/ja", si.getText());
assertEquals("string-com.android.test.1-user:0-res:" + R.string.shortcut_disabled_message2 + "/ja", si.getDisabledMessage());
assertEquals(START_TIME + 1, si.getLastChangedTimestamp());
// Check the dynamic one. (locale change shouldn't affect.)
si = getCallerShortcut("s1");
assertEquals("s1", si.getId());
assertEquals("title", si.getTitle());
assertEquals(null, si.getText());
assertEquals(null, si.getDisabledMessage());
// Not changed.
assertEquals(START_TIME, si.getLastChangedTimestamp());
});
}
use of android.content.pm.ShortcutInfo in project platform_frameworks_base by android.
the class ShortcutManagerTest1 method testManifestShortcuts_updateAndDisabled_pinned.
public void testManifestShortcuts_updateAndDisabled_pinned() {
mService.handleUnlockUser(USER_0);
// First, just publish a manifest shortcut.
addManifestShortcutResource(new ComponentName(CALLING_PACKAGE_1, ShortcutActivity.class.getName()), R.xml.shortcut_1);
updatePackageVersion(CALLING_PACKAGE_1, 1);
mService.mPackageMonitor.onReceive(getTestContext(), genPackageAddIntent(CALLING_PACKAGE_1, USER_0));
// Only the valid one is published.
runWithCaller(CALLING_PACKAGE_1, USER_0, () -> {
assertShortcutIds(assertAllManifest(assertAllImmutable(assertAllEnabled(mManager.getManifestShortcuts()))), "ms1");
assertEmpty(mManager.getPinnedShortcuts());
// Make sure there's no other dangling shortcuts.
assertShortcutIds(getCallerShortcuts(), "ms1");
});
runWithCaller(LAUNCHER_1, USER_0, () -> {
mLauncherApps.pinShortcuts(CALLING_PACKAGE_1, list("ms1"), HANDLE_USER_0);
});
// Now upgrade, the manifest shortcut is disabled now.
addManifestShortcutResource(new ComponentName(CALLING_PACKAGE_1, ShortcutActivity.class.getName()), R.xml.shortcut_1_disable);
updatePackageVersion(CALLING_PACKAGE_1, 1);
mService.mPackageMonitor.onReceive(getTestContext(), genPackageAddIntent(CALLING_PACKAGE_1, USER_0));
// Because shortcut 1 was pinned, it'll still exist as pinned, but disabled.
runWithCaller(CALLING_PACKAGE_1, USER_0, () -> {
assertEmpty(mManager.getManifestShortcuts());
assertShortcutIds(assertAllNotManifest(assertAllImmutable(assertAllDisabled(mManager.getPinnedShortcuts()))), "ms1");
// Make sure the fields are updated.
ShortcutInfo si = getCallerShortcut("ms1");
assertEquals("ms1", si.getId());
assertEquals(R.drawable.icon2, si.getIconResourceId());
assertEquals(R.string.shortcut_title2, si.getTitleResId());
assertEquals(R.string.shortcut_text2, si.getTextResId());
assertEquals(R.string.shortcut_disabled_message2, si.getDisabledMessageResourceId());
assertEquals(Intent.ACTION_VIEW, si.getIntent().getAction());
// Make sure there's no other dangling shortcuts.
assertShortcutIds(getCallerShortcuts(), "ms1");
});
}
use of android.content.pm.ShortcutInfo in project platform_frameworks_base by android.
the class ShortcutManagerTest2 method testShortcutInfoSaveAndLoad.
public void testShortcutInfoSaveAndLoad() throws InterruptedException {
mRunningUsers.put(USER_10, true);
setCaller(CALLING_PACKAGE_1, USER_10);
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();
sorig.setTimestamp(mInjectedCurrentTimeMillis);
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();
sorig2.setTimestamp(mInjectedCurrentTimeMillis);
mManager.addDynamicShortcuts(list(sorig, sorig2));
mInjectedCurrentTimeMillis += 1;
final long now = mInjectedCurrentTimeMillis;
mInjectedCurrentTimeMillis += 1;
dumpsysOnLogcat("before save");
// Save and load.
mService.saveDirtyInfo();
initService();
mService.handleUnlockUser(USER_10);
dumpUserFile(USER_10);
dumpsysOnLogcat("after load");
ShortcutInfo si;
si = mService.getPackageShortcutForTest(CALLING_PACKAGE_1, "id", USER_10);
assertEquals(USER_10, si.getUserId());
assertEquals(HANDLE_USER_10, si.getUserHandle());
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_DYNAMIC | ShortcutInfo.FLAG_HAS_ICON_FILE | ShortcutInfo.FLAG_STRINGS_RESOLVED, si.getFlags());
// Something should be set.
assertNotNull(si.getBitmapPath());
assertEquals(0, si.getIconResourceId());
assertTrue(si.getLastChangedTimestamp() < now);
// Make sure ranks are saved too. Because of the auto-adjusting, we need two shortcuts
// to test it.
si = mService.getPackageShortcutForTest(CALLING_PACKAGE_1, "id2", USER_10);
assertEquals(1, si.getRank());
dumpUserFile(USER_10);
}
use of android.content.pm.ShortcutInfo in project platform_frameworks_base by android.
the class BaseShortcutManagerTest method assertAllHaveIconFile.
public static List<ShortcutInfo> assertAllHaveIconFile(List<ShortcutInfo> actualShortcuts) {
for (ShortcutInfo s : actualShortcuts) {
assertFalse("ID " + s.getId() + " shouldn't have icon res ID", s.hasIconResource());
assertTrue("ID " + s.getId() + " not have icon FD", s.hasIconFile());
}
return actualShortcuts;
}
Aggregations