Search in sources :

Example 81 with ShortcutInfo

use of android.content.pm.ShortcutInfo in project android_frameworks_base by ResurrectionRemix.

the class ShortcutManagerTest2 method testShortcutInfoClone_resId.

public void testShortcutInfoClone_resId() {
    setCaller(CALLING_PACKAGE_1, USER_11);
    PersistableBundle pb = new PersistableBundle();
    pb.putInt("k", 1);
    ShortcutInfo sorig = new ShortcutInfo.Builder(mClientContext).setId("id").setActivity(new ComponentName("a", "b")).setIcon(Icon.createWithResource(mClientContext, 123)).setTitleResId(10).setTextResId(11).setDisabledMessageResId(12).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 = sorig.clone(/* clone flags*/
    0);
    assertEquals(USER_11, si.getUserId());
    assertEquals(HANDLE_USER_11, si.getUserHandle());
    assertEquals(mClientContext.getPackageName(), si.getPackage());
    assertEquals("id", si.getId());
    assertEquals(new ComponentName("a", "b"), si.getActivity());
    assertEquals(123, si.getIcon().getResId());
    assertEquals(10, si.getTitleResId());
    assertEquals("r10", si.getTitleResName());
    assertEquals(11, si.getTextResId());
    assertEquals("r11", si.getTextResName());
    assertEquals(12, si.getDisabledMessageResourceId());
    assertEquals("r12", si.getDisabledMessageResName());
    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("string/r456", si.getIconResName());
    si = sorig.clone(ShortcutInfo.CLONE_REMOVE_FOR_CREATOR);
    assertEquals(mClientContext.getPackageName(), si.getPackage());
    assertEquals("id", si.getId());
    assertEquals(new ComponentName("a", "b"), si.getActivity());
    assertEquals(null, si.getIcon());
    assertEquals(10, si.getTitleResId());
    assertEquals(null, si.getTitleResName());
    assertEquals(11, si.getTextResId());
    assertEquals(null, si.getTextResName());
    assertEquals(12, si.getDisabledMessageResourceId());
    assertEquals(null, si.getDisabledMessageResName());
    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(null, si.getBitmapPath());
    assertEquals(456, si.getIconResourceId());
    assertEquals(null, si.getIconResName());
    si = sorig.clone(ShortcutInfo.CLONE_REMOVE_FOR_LAUNCHER);
    assertEquals(mClientContext.getPackageName(), si.getPackage());
    assertEquals("id", si.getId());
    assertEquals(new ComponentName("a", "b"), si.getActivity());
    assertEquals(null, si.getIcon());
    assertEquals(10, si.getTitleResId());
    assertEquals(null, si.getTitleResName());
    assertEquals(11, si.getTextResId());
    assertEquals(null, si.getTextResName());
    assertEquals(12, si.getDisabledMessageResourceId());
    assertEquals(null, si.getDisabledMessageResName());
    assertEquals(set(ShortcutInfo.SHORTCUT_CATEGORY_CONVERSATION, "xyz"), si.getCategories());
    assertEquals(null, si.getIntent());
    assertEquals(123, si.getRank());
    assertEquals(1, si.getExtras().getInt("k"));
    assertEquals(ShortcutInfo.FLAG_PINNED, si.getFlags());
    assertEquals(null, si.getBitmapPath());
    assertEquals(456, si.getIconResourceId());
    assertEquals(null, si.getIconResName());
    si = sorig.clone(ShortcutInfo.CLONE_REMOVE_NON_KEY_INFO);
    assertEquals(mClientContext.getPackageName(), si.getPackage());
    assertEquals("id", si.getId());
    assertEquals(new ComponentName("a", "b"), si.getActivity());
    assertEquals(null, si.getIcon());
    assertEquals(0, si.getTitleResId());
    assertEquals(null, si.getTitleResName());
    assertEquals(0, si.getTextResId());
    assertEquals(null, si.getTextResName());
    assertEquals(0, si.getDisabledMessageResourceId());
    assertEquals(null, si.getDisabledMessageResName());
    assertEquals(null, si.getCategories());
    assertEquals(null, si.getIntent());
    assertEquals(0, si.getRank());
    assertEquals(null, si.getExtras());
    assertEquals(ShortcutInfo.FLAG_PINNED | ShortcutInfo.FLAG_KEY_FIELDS_ONLY, si.getFlags());
    assertEquals(null, si.getBitmapPath());
    assertEquals(456, si.getIconResourceId());
    assertEquals(null, si.getIconResName());
}
Also used : PersistableBundle(android.os.PersistableBundle) ShortcutInfo(android.content.pm.ShortcutInfo) ComponentName(android.content.ComponentName)

Example 82 with ShortcutInfo

use of android.content.pm.ShortcutInfo in project android_frameworks_base by ResurrectionRemix.

the class ShortcutManagerTest2 method testShortcutInfoClone.

public void testShortcutInfoClone() {
    setCaller(CALLING_PACKAGE_1, USER_11);
    PersistableBundle pb = new PersistableBundle();
    pb.putInt("k", 1);
    ShortcutInfo sorig = new ShortcutInfo.Builder(mClientContext).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 = sorig.clone(/* clone flags*/
    0);
    assertEquals(USER_11, si.getUserId());
    assertEquals(HANDLE_USER_11, si.getUserHandle());
    assertEquals(mClientContext.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("string/r456", si.getIconResName());
    si = sorig.clone(ShortcutInfo.CLONE_REMOVE_FOR_CREATOR);
    assertEquals(mClientContext.getPackageName(), si.getPackage());
    assertEquals("id", si.getId());
    assertEquals(new ComponentName("a", "b"), si.getActivity());
    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(123, si.getRank());
    assertEquals(1, si.getExtras().getInt("k"));
    assertEquals(ShortcutInfo.FLAG_PINNED, si.getFlags());
    assertEquals(null, si.getBitmapPath());
    assertEquals(456, si.getIconResourceId());
    assertEquals(null, si.getIconResName());
    si = sorig.clone(ShortcutInfo.CLONE_REMOVE_FOR_LAUNCHER);
    assertEquals(mClientContext.getPackageName(), si.getPackage());
    assertEquals("id", si.getId());
    assertEquals(new ComponentName("a", "b"), si.getActivity());
    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(null, si.getIntent());
    assertEquals(123, si.getRank());
    assertEquals(1, si.getExtras().getInt("k"));
    assertEquals(ShortcutInfo.FLAG_PINNED, si.getFlags());
    assertEquals(null, si.getBitmapPath());
    assertEquals(456, si.getIconResourceId());
    assertEquals(null, si.getIconResName());
    si = sorig.clone(ShortcutInfo.CLONE_REMOVE_NON_KEY_INFO);
    assertEquals(mClientContext.getPackageName(), si.getPackage());
    assertEquals("id", si.getId());
    assertEquals(new ComponentName("a", "b"), si.getActivity());
    assertEquals(null, si.getIcon());
    assertEquals(null, si.getTitle());
    assertEquals(null, si.getText());
    assertEquals(null, si.getDisabledMessage());
    assertEquals(null, si.getCategories());
    assertEquals(null, si.getIntent());
    assertEquals(0, si.getRank());
    assertEquals(null, si.getExtras());
    assertEquals(ShortcutInfo.FLAG_PINNED | ShortcutInfo.FLAG_KEY_FIELDS_ONLY, si.getFlags());
    assertEquals(null, si.getBitmapPath());
    assertEquals(456, si.getIconResourceId());
    assertEquals(null, si.getIconResName());
}
Also used : PersistableBundle(android.os.PersistableBundle) ShortcutInfo(android.content.pm.ShortcutInfo) ComponentName(android.content.ComponentName)

Example 83 with ShortcutInfo

use of android.content.pm.ShortcutInfo in project android_frameworks_base by ResurrectionRemix.

the class ShortcutManagerTest2 method testShortcutInfoMissingMandatoryFields.

// ShortcutInfo tests
public void testShortcutInfoMissingMandatoryFields() {
    // Disable throttling.
    mService.updateConfigurationLocked(ShortcutService.ConfigConstants.KEY_MAX_UPDATES_PER_INTERVAL + "=99999999," + ShortcutService.ConfigConstants.KEY_MAX_SHORTCUTS + "=99999999");
    assertExpectException(IllegalArgumentException.class, "ID must be provided", () -> new ShortcutInfo.Builder(getTestContext()).build());
    assertExpectException(RuntimeException.class, "id cannot be empty", () -> new ShortcutInfo.Builder(getTestContext(), null));
    assertExpectException(RuntimeException.class, "id cannot be empty", () -> new ShortcutInfo.Builder(getTestContext(), ""));
    assertExpectException(RuntimeException.class, "intents cannot contain null", () -> new ShortcutInfo.Builder(getTestContext(), "id").setIntent(null));
    assertExpectException(RuntimeException.class, "action must be set", () -> new ShortcutInfo.Builder(getTestContext(), "id").setIntent(new Intent()));
    assertExpectException(RuntimeException.class, "action must be set", () -> new ShortcutInfo.Builder(getTestContext(), "id").setIntents(new Intent[] { new Intent("action"), new Intent() }));
    assertExpectException(RuntimeException.class, "activity cannot be null", () -> new ShortcutInfo.Builder(getTestContext(), "id").setActivity(null));
    assertExpectException(RuntimeException.class, "shortLabel cannot be empty", () -> new ShortcutInfo.Builder(getTestContext(), "id").setShortLabel(null));
    assertExpectException(RuntimeException.class, "shortLabel cannot be empty", () -> new ShortcutInfo.Builder(getTestContext(), "id").setShortLabel(""));
    assertExpectException(RuntimeException.class, "longLabel cannot be empty", () -> new ShortcutInfo.Builder(getTestContext(), "id").setLongLabel(null));
    assertExpectException(RuntimeException.class, "longLabel cannot be empty", () -> new ShortcutInfo.Builder(getTestContext(), "id").setLongLabel(""));
    assertExpectException(RuntimeException.class, "disabledMessage cannot be empty", () -> new ShortcutInfo.Builder(getTestContext(), "id").setDisabledMessage(null));
    assertExpectException(RuntimeException.class, "disabledMessage cannot be empty", () -> new ShortcutInfo.Builder(getTestContext(), "id").setDisabledMessage(""));
    assertExpectException(NullPointerException.class, "action must be set", () -> new ShortcutInfo.Builder(getTestContext(), "id").setIntent(new Intent()));
    assertExpectException(IllegalArgumentException.class, "Short label must be provided", () -> {
        ShortcutInfo si = new ShortcutInfo.Builder(getTestContext(), "id").setActivity(new ComponentName(getTestContext().getPackageName(), "s")).build();
        assertTrue(getManager().setDynamicShortcuts(list(si)));
    });
    // same for add.
    assertExpectException(IllegalArgumentException.class, "Short label must be provided", () -> {
        ShortcutInfo si = new ShortcutInfo.Builder(getTestContext(), "id").setActivity(new ComponentName(getTestContext().getPackageName(), "s")).build();
        assertTrue(getManager().addDynamicShortcuts(list(si)));
    });
    assertExpectException(NullPointerException.class, "Intent must be provided", () -> {
        ShortcutInfo si = new ShortcutInfo.Builder(getTestContext(), "id").setActivity(new ComponentName(getTestContext().getPackageName(), "s")).setShortLabel("x").build();
        assertTrue(getManager().setDynamicShortcuts(list(si)));
    });
    // same for add.
    assertExpectException(NullPointerException.class, "Intent must be provided", () -> {
        ShortcutInfo si = new ShortcutInfo.Builder(getTestContext(), "id").setActivity(new ComponentName(getTestContext().getPackageName(), "s")).setShortLabel("x").build();
        assertTrue(getManager().addDynamicShortcuts(list(si)));
    });
    assertExpectException(IllegalStateException.class, "does not belong to package", () -> {
        ShortcutInfo si = new ShortcutInfo.Builder(getTestContext(), "id").setActivity(new ComponentName("xxx", "s")).build();
        assertTrue(getManager().setDynamicShortcuts(list(si)));
    });
    // same for add.
    assertExpectException(IllegalStateException.class, "does not belong to package", () -> {
        ShortcutInfo si = new ShortcutInfo.Builder(getTestContext(), "id").setActivity(new ComponentName("xxx", "s")).build();
        assertTrue(getManager().addDynamicShortcuts(list(si)));
    });
    // Now all activities are not main.
    mMainActivityChecker = (component, userId) -> false;
    assertExpectException(IllegalStateException.class, "is not main", () -> {
        ShortcutInfo si = new ShortcutInfo.Builder(getTestContext(), "id").setActivity(new ComponentName(getTestContext(), "s")).build();
        assertTrue(getManager().setDynamicShortcuts(list(si)));
    });
    // For add
    assertExpectException(IllegalStateException.class, "is not main", () -> {
        ShortcutInfo si = new ShortcutInfo.Builder(getTestContext(), "id").setActivity(new ComponentName(getTestContext(), "s")).build();
        assertTrue(getManager().addDynamicShortcuts(list(si)));
    });
    // For update
    assertExpectException(IllegalStateException.class, "is not main", () -> {
        ShortcutInfo si = new ShortcutInfo.Builder(getTestContext(), "id").setActivity(new ComponentName(getTestContext(), "s")).build();
        assertTrue(getManager().updateShortcuts(list(si)));
    });
}
Also used : ShortcutInfo(android.content.pm.ShortcutInfo) Intent(android.content.Intent) ComponentName(android.content.ComponentName)

Example 84 with ShortcutInfo

use of android.content.pm.ShortcutInfo in project android_frameworks_base by ResurrectionRemix.

the class ShortcutManagerTest1 method testUpdateShortcuts.

public void testUpdateShortcuts() {
    runWithCaller(CALLING_PACKAGE_1, UserHandle.USER_SYSTEM, () -> {
        assertTrue(mManager.setDynamicShortcuts(list(makeShortcut("s1"), makeShortcut("s2"), makeShortcut("s3"), makeShortcut("s4"), makeShortcut("s5"))));
    });
    runWithCaller(CALLING_PACKAGE_2, UserHandle.USER_SYSTEM, () -> {
        assertTrue(mManager.setDynamicShortcuts(list(makeShortcut("s1"), makeShortcut("s2"), makeShortcut("s3"), makeShortcut("s4"), makeShortcut("s5"))));
    });
    runWithCaller(LAUNCHER_1, UserHandle.USER_SYSTEM, () -> {
        mLauncherApps.pinShortcuts(CALLING_PACKAGE_1, list("s2", "s3"), getCallingUser());
        mLauncherApps.pinShortcuts(CALLING_PACKAGE_2, list("s4", "s5"), getCallingUser());
    });
    runWithCaller(CALLING_PACKAGE_1, UserHandle.USER_SYSTEM, () -> {
        mManager.removeDynamicShortcuts(list("s1"));
        mManager.removeDynamicShortcuts(list("s2"));
    });
    runWithCaller(CALLING_PACKAGE_2, UserHandle.USER_SYSTEM, () -> {
        mManager.removeDynamicShortcuts(list("s1"));
        mManager.removeDynamicShortcuts(list("s3"));
        mManager.removeDynamicShortcuts(list("s5"));
    });
    runWithCaller(CALLING_PACKAGE_1, UserHandle.USER_SYSTEM, () -> {
        assertShortcutIds(assertAllDynamic(mManager.getDynamicShortcuts()), "s3", "s4", "s5");
        assertShortcutIds(assertAllPinned(mManager.getPinnedShortcuts()), "s2", "s3");
    });
    runWithCaller(CALLING_PACKAGE_2, UserHandle.USER_SYSTEM, () -> {
        assertShortcutIds(assertAllDynamic(mManager.getDynamicShortcuts()), "s2", "s4");
        assertShortcutIds(assertAllPinned(mManager.getPinnedShortcuts()), "s4", "s5");
    });
    runWithCaller(CALLING_PACKAGE_1, UserHandle.USER_SYSTEM, () -> {
        ShortcutInfo s2 = makeShortcutBuilder().setId("s2").setIcon(Icon.createWithResource(getTestContext(), R.drawable.black_32x32)).build();
        ShortcutInfo s4 = makeShortcutBuilder().setId("s4").setTitle("new title").build();
        mManager.updateShortcuts(list(s2, s4));
    });
    runWithCaller(CALLING_PACKAGE_2, UserHandle.USER_SYSTEM, () -> {
        ShortcutInfo s2 = makeShortcutBuilder().setId("s2").setIntent(makeIntent(Intent.ACTION_ANSWER, ShortcutActivity.class, "key1", "val1")).build();
        ShortcutInfo s4 = makeShortcutBuilder().setId("s4").setIntent(new Intent(Intent.ACTION_ALL_APPS)).build();
        mManager.updateShortcuts(list(s2, s4));
    });
    runWithCaller(CALLING_PACKAGE_1, UserHandle.USER_SYSTEM, () -> {
        assertShortcutIds(assertAllDynamic(mManager.getDynamicShortcuts()), "s3", "s4", "s5");
        assertShortcutIds(assertAllPinned(mManager.getPinnedShortcuts()), "s2", "s3");
        ShortcutInfo s = getCallerShortcut("s2");
        assertTrue(s.hasIconResource());
        assertEquals(R.drawable.black_32x32, s.getIconResourceId());
        assertEquals("string/r" + R.drawable.black_32x32, s.getIconResName());
        assertEquals("Title-s2", s.getTitle());
        s = getCallerShortcut("s4");
        assertFalse(s.hasIconResource());
        assertEquals(0, s.getIconResourceId());
        assertEquals("new title", s.getTitle());
    });
    runWithCaller(CALLING_PACKAGE_2, UserHandle.USER_SYSTEM, () -> {
        assertShortcutIds(assertAllDynamic(mManager.getDynamicShortcuts()), "s2", "s4");
        assertShortcutIds(assertAllPinned(mManager.getPinnedShortcuts()), "s4", "s5");
        ShortcutInfo s = getCallerShortcut("s2");
        assertFalse(s.hasIconResource());
        assertEquals(0, s.getIconResourceId());
        assertEquals("Title-s2", s.getTitle());
        assertEquals(Intent.ACTION_ANSWER, s.getIntent().getAction());
        assertEquals(1, s.getIntent().getExtras().size());
        s = getCallerShortcut("s4");
        assertFalse(s.hasIconResource());
        assertEquals(0, s.getIconResourceId());
        assertEquals("Title-s4", s.getTitle());
        assertEquals(Intent.ACTION_ALL_APPS, s.getIntent().getAction());
        assertBundleEmpty(s.getIntent().getExtras());
    });
    // TODO Check with other fields too.
    // TODO Check bitmap removal too.
    mRunningUsers.put(USER_11, true);
    runWithCaller(CALLING_PACKAGE_2, USER_11, () -> {
        mManager.updateShortcuts(list());
    });
}
Also used : ShortcutInfo(android.content.pm.ShortcutInfo) Intent(android.content.Intent)

Example 85 with ShortcutInfo

use of android.content.pm.ShortcutInfo in project android_frameworks_base by ResurrectionRemix.

the class ShortcutManagerTest1 method testMaxShortcutCount_add.

public void testMaxShortcutCount_add() {
    // 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 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.addDynamicShortcuts(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.addDynamicShortcuts(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.addDynamicShortcuts(list(s1_1, s1_2, s1_3, s2_1, s2_2, s2_3, s2_4));
        });
        assertEmpty(mManager.getDynamicShortcuts());
        // First, set 3.  Then add 1 more, which should be ignored.
        mManager.setDynamicShortcuts(list(s1_1, s1_2, s1_3));
        assertShortcutIds(mManager.getDynamicShortcuts(), "s11", "s12", "s13");
        assertDynamicShortcutCountExceeded(() -> {
            mManager.addDynamicShortcuts(list(s1_4, s2_1));
        });
        assertShortcutIds(mManager.getDynamicShortcuts(), "s11", "s12", "s13");
        // Update existing one, which should work.
        mManager.addDynamicShortcuts(list(makeShortcutWithActivityAndTitle("s11", a1, "xxx"), s2_1));
        assertShortcutIds(mManager.getDynamicShortcuts(), "s11", "s12", "s13", "s21");
        assertEquals("xxx", getCallerShortcut("s11").getTitle());
        // Make sure pinned shortcuts won't affect.
        // - Pin s11 - s13, and remove all dynamic.
        runWithCaller(LAUNCHER_1, USER_0, () -> {
            mLauncherApps.pinShortcuts(CALLING_PACKAGE_1, list("s11", "s12", "s13"), HANDLE_USER_0);
        });
        mManager.removeAllDynamicShortcuts();
        assertEmpty(mManager.getDynamicShortcuts());
        assertShortcutIds(mManager.getPinnedShortcuts(), "s11", "s12", "s13");
        // Then add dynamic.
        mManager.addDynamicShortcuts(list(s1_4, s2_1, s2_2, s2_3));
        assertShortcutIds(mManager.getDynamicShortcuts(), "s14", "s21", "s22", "s23");
        assertShortcutIds(mManager.getPinnedShortcuts(), "s11", "s12", "s13");
        // Adding "s11" and "s12" back, should work
        mManager.addDynamicShortcuts(list(s1_1, s1_2));
        assertShortcutIds(mManager.getDynamicShortcuts(), "s14", "s11", "s12", "s21", "s22", "s23");
        assertShortcutIds(mManager.getPinnedShortcuts(), "s11", "s12", "s13");
        // Adding back s13 doesn't work.
        assertDynamicShortcutCountExceeded(() -> {
            mManager.addDynamicShortcuts(list(s1_3));
        });
        assertShortcutIds(filterByActivity(mManager.getDynamicShortcuts(), a1), "s11", "s12", "s14");
        assertShortcutIds(filterByActivity(mManager.getDynamicShortcuts(), a2), "s21", "s22", "s23");
        // Now swap the activities.
        mManager.updateShortcuts(list(makeShortcutWithActivity("s11", a2), makeShortcutWithActivity("s21", a1)));
        assertShortcutIds(filterByActivity(mManager.getDynamicShortcuts(), a1), "s21", "s12", "s14");
        assertShortcutIds(filterByActivity(mManager.getDynamicShortcuts(), a2), "s11", "s22", "s23");
        // 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());
        // Adding one shortcut to activity 1 works fine.
        mManager.addDynamicShortcuts(list(s1_1, s2_1, s2_2, s2_3));
        assertShortcutIds(mManager.getDynamicShortcuts(), "s11", "s21", "s22", "s23");
        assertEquals(2, mManager.getManifestShortcuts().size());
        // But adding one more doesn't.
        assertDynamicShortcutCountExceeded(() -> {
            mManager.addDynamicShortcuts(list(s1_4, s2_1));
        });
        assertShortcutIds(mManager.getDynamicShortcuts(), "s11", "s21", "s22", "s23");
        assertEquals(2, mManager.getManifestShortcuts().size());
    });
}
Also used : ShortcutInfo(android.content.pm.ShortcutInfo) ComponentName(android.content.ComponentName)

Aggregations

ShortcutInfo (android.content.pm.ShortcutInfo)324 ComponentName (android.content.ComponentName)144 PersistableBundle (android.os.PersistableBundle)48 ArrayList (java.util.ArrayList)46 Intent (android.content.Intent)44 Icon (android.graphics.drawable.Icon)32 List (java.util.List)17 Matchers.anyString (org.mockito.Matchers.anyString)16 LocaleList (android.os.LocaleList)12 File (java.io.File)12 Nullable (android.annotation.Nullable)8 ShortcutQuery (android.content.pm.LauncherApps.ShortcutQuery)8 Resources (android.content.res.Resources)8 Bundle (android.os.Bundle)8 ArrayMap (android.util.ArrayMap)8 PackageWithUser (com.android.server.pm.ShortcutUser.PackageWithUser)8 ShortcutManagerTestUtils.makeBundle (com.android.server.pm.shortcutmanagertest.ShortcutManagerTestUtils.makeBundle)8 IOException (java.io.IOException)8 ArraySet (android.util.ArraySet)5 Manifest.permission (android.Manifest.permission)4