Search in sources :

Example 21 with ShortcutInfo

use of android.content.pm.ShortcutInfo in project platform_frameworks_base by android.

the class ShortcutManagerTest1 method testAddDynamicShortcuts.

public void testAddDynamicShortcuts() {
    setCaller(CALLING_PACKAGE_1, USER_0);
    final ShortcutInfo si1 = makeShortcut("shortcut1");
    final ShortcutInfo si2 = makeShortcut("shortcut2");
    final ShortcutInfo si3 = makeShortcut("shortcut3");
    assertEquals(3, mManager.getRemainingCallCount());
    assertTrue(mManager.setDynamicShortcuts(list(si1)));
    assertEquals(2, mManager.getRemainingCallCount());
    assertShortcutIds(assertAllNotKeyFieldsOnly(mManager.getDynamicShortcuts()), "shortcut1");
    assertTrue(mManager.addDynamicShortcuts(list(si2, si3)));
    assertEquals(1, mManager.getRemainingCallCount());
    assertShortcutIds(assertAllNotKeyFieldsOnly(mManager.getDynamicShortcuts()), "shortcut1", "shortcut2", "shortcut3");
    // This should not crash.  It'll still consume the quota.
    assertTrue(mManager.addDynamicShortcuts(list()));
    assertEquals(0, mManager.getRemainingCallCount());
    assertShortcutIds(assertAllNotKeyFieldsOnly(mManager.getDynamicShortcuts()), "shortcut1", "shortcut2", "shortcut3");
    // reset
    mInjectedCurrentTimeMillis += INTERVAL;
    // Add with the same ID
    assertTrue(mManager.addDynamicShortcuts(list(makeShortcut("shortcut1"))));
    assertEquals(2, mManager.getRemainingCallCount());
    assertShortcutIds(assertAllNotKeyFieldsOnly(mManager.getDynamicShortcuts()), "shortcut1", "shortcut2", "shortcut3");
    // TODO Check max number
    // TODO Check fields.
    mRunningUsers.put(USER_10, true);
    runWithCaller(CALLING_PACKAGE_2, USER_10, () -> {
        assertTrue(mManager.addDynamicShortcuts(list(makeShortcut("s1"))));
    });
}
Also used : ShortcutInfo(android.content.pm.ShortcutInfo)

Example 22 with ShortcutInfo

use of android.content.pm.ShortcutInfo in project platform_frameworks_base by android.

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");
    });
}
Also used : ShortcutInfo(android.content.pm.ShortcutInfo) ComponentName(android.content.ComponentName)

Example 23 with ShortcutInfo

use of android.content.pm.ShortcutInfo in project platform_frameworks_base by android.

the class ShortcutManagerTest1 method testMaxShortcutCount_update.

public void testMaxShortcutCount_update() {
    // 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 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");
        // Trying to move s11 from a1 to a2 should fail.
        assertDynamicShortcutCountExceeded(() -> {
            mManager.updateShortcuts(list(makeShortcutWithActivity("s11", a2)));
        });
        assertShortcutIds(mManager.getDynamicShortcuts(), "s11", "s12", "s13", "s21", "s22", "s23");
        // Trying to move s21 from a2 to a1 should also fail.
        assertDynamicShortcutCountExceeded(() -> {
            mManager.updateShortcuts(list(makeShortcutWithActivity("s21", a1)));
        });
        assertShortcutIds(mManager.getDynamicShortcuts(), "s11", "s12", "s13", "s21", "s22", "s23");
        // But, if we do these two at the same time, it should work.
        mManager.updateShortcuts(list(makeShortcutWithActivity("s11", a2), makeShortcutWithActivity("s21", a1)));
        assertShortcutIds(mManager.getDynamicShortcuts(), "s11", "s12", "s13", "s21", "s22", "s23");
        assertShortcutIds(filterByActivity(mManager.getDynamicShortcuts(), a1), "s21", "s12", "s13");
        assertShortcutIds(filterByActivity(mManager.getDynamicShortcuts(), a2), "s11", "s22", "s23");
        // Then reset.
        mManager.setDynamicShortcuts(list(s1_1, s1_2, s1_3, s2_1, s2_2, s2_3));
        assertShortcutIds(mManager.getDynamicShortcuts(), "s11", "s12", "s13", "s21", "s22", "s23");
        // Pin some to have more shortcuts for a1.
        runWithCaller(LAUNCHER_1, USER_0, () -> {
            mLauncherApps.pinShortcuts(CALLING_PACKAGE_1, list("s11", "s12", "s13"), HANDLE_USER_0);
        });
        mManager.setDynamicShortcuts(list(s1_4, s1_5, s2_1, s2_2, s2_3));
        assertShortcutIds(mManager.getDynamicShortcuts(), "s14", "s15", "s21", "s22", "s23");
        assertShortcutIds(mManager.getPinnedShortcuts(), "s11", "s12", "s13");
        // a1 already has 2 dynamic shortcuts (and 3 pinned shortcuts that used to belong on it)
        // But that doesn't matter for update -- the following should still work.
        mManager.updateShortcuts(list(makeShortcutWithActivityAndTitle("s11", a1, "xxx1"), makeShortcutWithActivityAndTitle("s12", a1, "xxx2"), makeShortcutWithActivityAndTitle("s13", a1, "xxx3"), makeShortcutWithActivityAndTitle("s14", a1, "xxx4"), makeShortcutWithActivityAndTitle("s15", a1, "xxx5")));
        // All the shortcuts should still exist they all belong on same activities,
        // with the updated titles.
        assertShortcutIds(mManager.getDynamicShortcuts(), "s14", "s15", "s21", "s22", "s23");
        assertShortcutIds(mManager.getPinnedShortcuts(), "s11", "s12", "s13");
        assertShortcutIds(filterByActivity(mManager.getDynamicShortcuts(), a1), "s14", "s15");
        assertShortcutIds(filterByActivity(mManager.getDynamicShortcuts(), a2), "s21", "s22", "s23");
        assertEquals("xxx1", getCallerShortcut("s11").getTitle());
        assertEquals("xxx2", getCallerShortcut("s12").getTitle());
        assertEquals("xxx3", getCallerShortcut("s13").getTitle());
        assertEquals("xxx4", getCallerShortcut("s14").getTitle());
        assertEquals("xxx5", getCallerShortcut("s15").getTitle());
    });
}
Also used : ShortcutInfo(android.content.pm.ShortcutInfo) ComponentName(android.content.ComponentName)

Example 24 with ShortcutInfo

use of android.content.pm.ShortcutInfo in project platform_frameworks_base by android.

the class ShortcutManagerTest1 method testDeleteDynamicShortcuts.

public void testDeleteDynamicShortcuts() {
    final ShortcutInfo si1 = makeShortcut("shortcut1");
    final ShortcutInfo si2 = makeShortcut("shortcut2");
    final ShortcutInfo si3 = makeShortcut("shortcut3");
    final ShortcutInfo si4 = makeShortcut("shortcut4");
    assertTrue(mManager.setDynamicShortcuts(list(si1, si2, si3, si4)));
    assertShortcutIds(assertAllNotKeyFieldsOnly(mManager.getDynamicShortcuts()), "shortcut1", "shortcut2", "shortcut3", "shortcut4");
    assertEquals(2, mManager.getRemainingCallCount());
    mManager.removeDynamicShortcuts(list("shortcut1"));
    assertShortcutIds(assertAllNotKeyFieldsOnly(mManager.getDynamicShortcuts()), "shortcut2", "shortcut3", "shortcut4");
    mManager.removeDynamicShortcuts(list("shortcut1"));
    assertShortcutIds(assertAllNotKeyFieldsOnly(mManager.getDynamicShortcuts()), "shortcut2", "shortcut3", "shortcut4");
    mManager.removeDynamicShortcuts(list("shortcutXXX"));
    assertShortcutIds(assertAllNotKeyFieldsOnly(mManager.getDynamicShortcuts()), "shortcut2", "shortcut3", "shortcut4");
    mManager.removeDynamicShortcuts(list("shortcut2", "shortcut4"));
    assertShortcutIds(assertAllNotKeyFieldsOnly(mManager.getDynamicShortcuts()), "shortcut3");
    mManager.removeDynamicShortcuts(list("shortcut3"));
    assertShortcutIds(assertAllNotKeyFieldsOnly(mManager.getDynamicShortcuts()));
    // Still 2 calls left.
    assertEquals(2, mManager.getRemainingCallCount());
}
Also used : ShortcutInfo(android.content.pm.ShortcutInfo)

Example 25 with ShortcutInfo

use of android.content.pm.ShortcutInfo in project platform_frameworks_base by android.

the class ShortcutManagerTest1 method testHandlePackageUpdate_resIdChanged.

/**
     * Test the case where an updated app has resource IDs changed.
     */
public void testHandlePackageUpdate_resIdChanged() throws Exception {
    final Icon icon1 = Icon.createWithResource(getTestContext(), /* res ID */
    1000);
    final Icon icon2 = Icon.createWithResource(getTestContext(), /* res ID */
    1001);
    // Set up shortcuts.
    runWithCaller(CALLING_PACKAGE_1, USER_0, () -> {
        // Note resource strings are not officially supported (they're hidden), but
        // should work.
        final ShortcutInfo s1 = new ShortcutInfo.Builder(mClientContext).setId("s1").setActivity(makeComponent(ShortcutActivity.class)).setIntent(new Intent(Intent.ACTION_VIEW)).setIcon(icon1).setTitleResId(10000).setTextResId(10001).setDisabledMessageResId(10002).build();
        final ShortcutInfo s2 = new ShortcutInfo.Builder(mClientContext).setId("s2").setActivity(makeComponent(ShortcutActivity.class)).setIntent(new Intent(Intent.ACTION_VIEW)).setIcon(icon2).setTitleResId(20000).build();
        assertTrue(mManager.setDynamicShortcuts(list(s1, s2)));
    });
    // Verify.
    runWithCaller(CALLING_PACKAGE_1, USER_0, () -> {
        final ShortcutInfo s1 = getCallerShortcut("s1");
        final ShortcutInfo s2 = getCallerShortcut("s2");
        assertEquals(1000, s1.getIconResourceId());
        assertEquals(10000, s1.getTitleResId());
        assertEquals(10001, s1.getTextResId());
        assertEquals(10002, s1.getDisabledMessageResourceId());
        assertEquals(1001, s2.getIconResourceId());
        assertEquals(20000, s2.getTitleResId());
        assertEquals(0, s2.getTextResId());
        assertEquals(0, s2.getDisabledMessageResourceId());
    });
    mService.saveDirtyInfo();
    initService();
    // Set up the mock resources again, with an "adjustment".
    // When the package is updated, the service will fetch the updated res-IDs with res-names,
    // and the new IDs will have this offset.
    setUpAppResources(10);
    // Update the package.
    updatePackageVersion(CALLING_PACKAGE_1, 1);
    mService.mPackageMonitor.onReceive(getTestContext(), genPackageUpdateIntent(CALLING_PACKAGE_1, USER_0));
    runWithCaller(CALLING_PACKAGE_1, USER_0, () -> {
        final ShortcutInfo s1 = getCallerShortcut("s1");
        final ShortcutInfo s2 = getCallerShortcut("s2");
        assertEquals(1010, s1.getIconResourceId());
        assertEquals(10010, s1.getTitleResId());
        assertEquals(10011, s1.getTextResId());
        assertEquals(10012, s1.getDisabledMessageResourceId());
        assertEquals(1011, s2.getIconResourceId());
        assertEquals(20010, s2.getTitleResId());
        assertEquals(0, s2.getTextResId());
        assertEquals(0, s2.getDisabledMessageResourceId());
    });
}
Also used : ShortcutInfo(android.content.pm.ShortcutInfo) Intent(android.content.Intent) Icon(android.graphics.drawable.Icon)

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