Search in sources :

Example 51 with ShortcutInfo

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

the class BaseShortcutManagerTest method assertAllHaveIconResId.

public static List<ShortcutInfo> assertAllHaveIconResId(List<ShortcutInfo> actualShortcuts) {
    for (ShortcutInfo s : actualShortcuts) {
        assertTrue("ID " + s.getId() + " not have icon res ID", s.hasIconResource());
        assertFalse("ID " + s.getId() + " shouldn't have icon FD", s.hasIconFile());
    }
    return actualShortcuts;
}
Also used : ShortcutInfo(android.content.pm.ShortcutInfo)

Example 52 with ShortcutInfo

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

the class BaseShortcutManagerTest method makeShortcutWithExtras.

/**
     * Make a shortcut with details.
     */
protected ShortcutInfo makeShortcutWithExtras(String id, Intent intent, PersistableBundle extras) {
    final ShortcutInfo.Builder b = new ShortcutInfo.Builder(mClientContext, id).setActivity(new ComponentName(mClientContext.getPackageName(), "dummy")).setShortLabel("title-" + id).setExtras(extras).setIntent(intent);
    final ShortcutInfo s = b.build();
    // HACK
    s.setTimestamp(mInjectedCurrentTimeMillis);
    return s;
}
Also used : ShortcutInfo(android.content.pm.ShortcutInfo) ComponentName(android.content.ComponentName)

Example 53 with ShortcutInfo

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

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

Example 54 with ShortcutInfo

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

the class BaseShortcutManagerTest method makeShortcut.

/**
     * Make a shortcut with details.
     */
protected ShortcutInfo makeShortcut(String id, String title, ComponentName activity, Icon icon, Intent intent, int rank) {
    final ShortcutInfo.Builder b = new ShortcutInfo.Builder(mClientContext, id).setActivity(new ComponentName(mClientContext.getPackageName(), "dummy")).setShortLabel(title).setRank(rank).setIntent(intent);
    if (icon != null) {
        b.setIcon(icon);
    }
    if (activity != null) {
        b.setActivity(activity);
    }
    final ShortcutInfo s = b.build();
    // HACK
    s.setTimestamp(mInjectedCurrentTimeMillis);
    return s;
}
Also used : ShortcutInfo(android.content.pm.ShortcutInfo) ComponentName(android.content.ComponentName)

Example 55 with ShortcutInfo

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

the class ShortcutManagerTest1 method testShortcutsPushedOutByManifest.

public void testShortcutsPushedOutByManifest() {
    // 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 = makeShortcutWithActivityAndRank("s11", a1, 4);
        final ShortcutInfo s1_2 = makeShortcutWithActivityAndRank("s12", a1, 3);
        final ShortcutInfo s1_3 = makeShortcutWithActivityAndRank("s13", a1, 2);
        final ShortcutInfo s1_4 = makeShortcutWithActivityAndRank("s14", a1, 1);
        final ShortcutInfo s1_5 = makeShortcutWithActivityAndRank("s15", a1, 0);
        final ShortcutInfo s2_1 = makeShortcutWithActivityAndRank("s21", a2, 0);
        final ShortcutInfo s2_2 = makeShortcutWithActivityAndRank("s22", a2, 1);
        final ShortcutInfo s2_3 = makeShortcutWithActivityAndRank("s23", a2, 2);
        final ShortcutInfo s2_4 = makeShortcutWithActivityAndRank("s24", a2, 3);
        final ShortcutInfo s2_5 = makeShortcutWithActivityAndRank("s25", a2, 4);
        // Initial state.
        mManager.setDynamicShortcuts(list(s1_1, s1_2, s1_3, s2_1, s2_2, s2_3));
        runWithCaller(LAUNCHER_1, USER_0, () -> {
            mLauncherApps.pinShortcuts(CALLING_PACKAGE_1, list("s11", "s12", "s21", "s22"), HANDLE_USER_0);
        });
        mManager.setDynamicShortcuts(list(s1_2, s1_3, s1_4, s2_2, s2_3, s2_4));
        assertShortcutIds(assertAllEnabled(mManager.getDynamicShortcuts()), "s12", "s13", "s14", "s22", "s23", "s24");
        assertShortcutIds(assertAllEnabled(mManager.getPinnedShortcuts()), "s11", "s12", "s21", "s22");
        // Add 1 manifest shortcut to a1.
        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));
        assertEquals(1, mManager.getManifestShortcuts().size());
        // s12 removed.
        assertShortcutIds(assertAllEnabled(mManager.getDynamicShortcuts()), "s13", "s14", "s22", "s23", "s24");
        assertShortcutIds(assertAllEnabled(mManager.getPinnedShortcuts()), "s11", "s12", "s21", "s22");
        // Add more manifest shortcuts.
        addManifestShortcutResource(new ComponentName(CALLING_PACKAGE_1, ShortcutActivity.class.getName()), R.xml.shortcut_2);
        addManifestShortcutResource(new ComponentName(CALLING_PACKAGE_1, ShortcutActivity2.class.getName()), R.xml.shortcut_1_alt);
        updatePackageVersion(CALLING_PACKAGE_1, 1);
        mService.mPackageMonitor.onReceive(getTestContext(), genPackageAddIntent(CALLING_PACKAGE_1, USER_0));
        assertEquals(3, mManager.getManifestShortcuts().size());
        // Note the ones with the highest rank values (== least important) will be removed.
        assertShortcutIds(assertAllEnabled(mManager.getDynamicShortcuts()), "s14", "s22", "s23");
        assertShortcutIds(assertAllEnabled(mManager.getPinnedShortcuts()), "s11", "s12", "s21", "s22");
        // Add more manifest shortcuts.
        addManifestShortcutResource(new ComponentName(CALLING_PACKAGE_1, ShortcutActivity.class.getName()), R.xml.shortcut_2);
        addManifestShortcutResource(new ComponentName(CALLING_PACKAGE_1, ShortcutActivity2.class.getName()), // manifest has 5, but max is 3, so a2 will have 3.
        R.xml.shortcut_5_alt);
        updatePackageVersion(CALLING_PACKAGE_1, 1);
        mService.mPackageMonitor.onReceive(getTestContext(), genPackageAddIntent(CALLING_PACKAGE_1, USER_0));
        assertEquals(5, mManager.getManifestShortcuts().size());
        assertShortcutIds(assertAllEnabled(mManager.getDynamicShortcuts()), // a1 has 1 dynamic
        "s14");
        // a2 has no dynamic
        assertShortcutIds(assertAllEnabled(mManager.getPinnedShortcuts()), "s11", "s12", "s21", "s22");
        // Update, no manifest shortucts.  This doesn't affect anything.
        addManifestShortcutResource(new ComponentName(CALLING_PACKAGE_1, ShortcutActivity.class.getName()), R.xml.shortcut_0);
        addManifestShortcutResource(new ComponentName(CALLING_PACKAGE_1, ShortcutActivity2.class.getName()), R.xml.shortcut_0);
        updatePackageVersion(CALLING_PACKAGE_1, 1);
        mService.mPackageMonitor.onReceive(getTestContext(), genPackageAddIntent(CALLING_PACKAGE_1, USER_0));
        assertEquals(0, mManager.getManifestShortcuts().size());
        assertShortcutIds(assertAllEnabled(mManager.getDynamicShortcuts()), "s14");
        assertShortcutIds(assertAllEnabled(mManager.getPinnedShortcuts()), "s11", "s12", "s21", "s22");
    });
}
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