Search in sources :

Example 41 with ShortcutInfo

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

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 42 with ShortcutInfo

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

the class ShortcutManagerTest1 method testDisableAndEnableShortcuts.

/**
     * This is similar to the above test, except it used "disable" instead of "remove".  It also
     * does "enable".
     */
public void testDisableAndEnableShortcuts() {
    runWithCaller(CALLING_PACKAGE_1, USER_0, () -> {
        final ShortcutInfo s1_1 = makeShortcutWithTimestamp("s1", 1000);
        final ShortcutInfo s1_2 = makeShortcutWithTimestamp("s2", 2000);
        assertTrue(mManager.setDynamicShortcuts(list(s1_1, s1_2)));
    });
    runWithCaller(CALLING_PACKAGE_2, USER_0, () -> {
        final ShortcutInfo s2_2 = makeShortcutWithTimestamp("s2", 1500);
        final ShortcutInfo s2_3 = makeShortcutWithTimestamp("s3", 3000);
        final ShortcutInfo s2_4 = makeShortcutWithTimestamp("s4", 500);
        assertTrue(mManager.setDynamicShortcuts(list(s2_2, s2_3, s2_4)));
    });
    runWithCaller(CALLING_PACKAGE_3, USER_0, () -> {
        final ShortcutInfo s3_2 = makeShortcutWithTimestamp("s2", 1000);
        assertTrue(mManager.setDynamicShortcuts(list(s3_2)));
    });
    // Pin some.
    runWithCaller(LAUNCHER_1, USER_0, () -> {
        mLauncherApps.pinShortcuts(CALLING_PACKAGE_1, list("s2", "s3"), getCallingUser());
        mLauncherApps.pinShortcuts(CALLING_PACKAGE_2, list("s3", "s4", "s5"), getCallingUser());
        mLauncherApps.pinShortcuts(CALLING_PACKAGE_3, list("s3"), // Note ID doesn't exist
        getCallingUser());
    });
    // Disable some.
    runWithCaller(CALLING_PACKAGE_1, USER_0, () -> {
        assertShortcutIds(mManager.getPinnedShortcuts(), "s2");
        mManager.disableShortcuts(list("s2"));
        assertShortcutIds(mManager.getPinnedShortcuts(), "s2");
        assertShortcutIds(mManager.getDynamicShortcuts(), "s1");
    });
    runWithCaller(CALLING_PACKAGE_2, USER_0, () -> {
        assertShortcutIds(mManager.getPinnedShortcuts(), "s3", "s4");
        // disable should work even if a shortcut is not dynamic, so try calling "remove" first
        // here.
        mManager.removeDynamicShortcuts(list("s3"));
        mManager.disableShortcuts(list("s3"));
        assertShortcutIds(mManager.getPinnedShortcuts(), "s3", "s4");
        assertShortcutIds(mManager.getDynamicShortcuts(), "s2", "s4");
    });
    runWithCaller(CALLING_PACKAGE_3, USER_0, () -> {
        assertShortcutIds(mManager.getPinnedShortcuts());
        mManager.disableShortcuts(list("s2"));
        assertShortcutIds(mManager.getPinnedShortcuts());
        assertEmpty(mManager.getDynamicShortcuts());
        assertEmpty(getCallerShortcuts());
    });
    // Get pinned shortcuts from launcher
    runWithCaller(LAUNCHER_1, USER_0, () -> {
        // CALLING_PACKAGE_1 deleted s2, but it's pinned, so it still exists, and disabled.
        assertWith(mLauncherApps.getShortcuts(buildQuery(/* time =*/
        0, CALLING_PACKAGE_1, /* activity =*/
        null, ShortcutQuery.FLAG_GET_PINNED), getCallingUser())).haveIds("s2").areAllPinned().areAllNotWithKeyFieldsOnly().areAllDisabled();
        assertStartShortcutThrowsException(CALLING_PACKAGE_1, "s2", USER_0, ActivityNotFoundException.class);
        // Here, s4 is still enabled and launchable, but s3 is disabled.
        assertWith(mLauncherApps.getShortcuts(buildQuery(/* time =*/
        0, CALLING_PACKAGE_2, /* activity =*/
        null, ShortcutQuery.FLAG_GET_PINNED), getCallingUser())).haveIds("s3", "s4").areAllPinned().areAllNotWithKeyFieldsOnly().selectByIds("s3").areAllDisabled().revertToOriginalList().selectByIds("s4").areAllEnabled();
        assertStartShortcutThrowsException(CALLING_PACKAGE_2, "s3", USER_0, ActivityNotFoundException.class);
        assertShortcutLaunchable(CALLING_PACKAGE_2, "s4", USER_0);
        assertShortcutIds(assertAllPinned(assertAllNotKeyFieldsOnly(assertAllEnabled(mLauncherApps.getShortcuts(buildQuery(/* time =*/
        0, CALLING_PACKAGE_3, /* activity =*/
        null, ShortcutQuery.FLAG_GET_PINNED), getCallingUser())))));
    });
    runWithCaller(CALLING_PACKAGE_1, USER_0, () -> {
        mManager.enableShortcuts(list("s2"));
        assertShortcutIds(mManager.getPinnedShortcuts(), "s2");
        assertShortcutIds(mManager.getDynamicShortcuts(), "s1");
    });
    runWithCaller(LAUNCHER_1, USER_0, () -> {
        // CALLING_PACKAGE_1 deleted s2, but it's pinned, so it still exists.
        assertShortcutIds(assertAllPinned(assertAllNotKeyFieldsOnly(assertAllEnabled(mLauncherApps.getShortcuts(buildQuery(/* time =*/
        0, CALLING_PACKAGE_1, /* activity =*/
        null, ShortcutQuery.FLAG_GET_PINNED), getCallingUser())))), "s2");
        assertShortcutLaunchable(CALLING_PACKAGE_1, "s2", USER_0);
    });
}
Also used : ShortcutInfo(android.content.pm.ShortcutInfo)

Example 43 with ShortcutInfo

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

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)

Example 44 with ShortcutInfo

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

the class ShortcutManagerTest1 method testDisableAndEnableShortcuts.

/**
     * This is similar to the above test, except it used "disable" instead of "remove".  It also
     * does "enable".
     */
public void testDisableAndEnableShortcuts() {
    runWithCaller(CALLING_PACKAGE_1, USER_0, () -> {
        final ShortcutInfo s1_1 = makeShortcutWithTimestamp("s1", 1000);
        final ShortcutInfo s1_2 = makeShortcutWithTimestamp("s2", 2000);
        assertTrue(mManager.setDynamicShortcuts(list(s1_1, s1_2)));
    });
    runWithCaller(CALLING_PACKAGE_2, USER_0, () -> {
        final ShortcutInfo s2_2 = makeShortcutWithTimestamp("s2", 1500);
        final ShortcutInfo s2_3 = makeShortcutWithTimestamp("s3", 3000);
        final ShortcutInfo s2_4 = makeShortcutWithTimestamp("s4", 500);
        assertTrue(mManager.setDynamicShortcuts(list(s2_2, s2_3, s2_4)));
    });
    runWithCaller(CALLING_PACKAGE_3, USER_0, () -> {
        final ShortcutInfo s3_2 = makeShortcutWithTimestamp("s2", 1000);
        assertTrue(mManager.setDynamicShortcuts(list(s3_2)));
    });
    // Pin some.
    runWithCaller(LAUNCHER_1, USER_0, () -> {
        mLauncherApps.pinShortcuts(CALLING_PACKAGE_1, list("s2", "s3"), getCallingUser());
        mLauncherApps.pinShortcuts(CALLING_PACKAGE_2, list("s3", "s4", "s5"), getCallingUser());
        mLauncherApps.pinShortcuts(CALLING_PACKAGE_3, list("s3"), // Note ID doesn't exist
        getCallingUser());
    });
    // Disable some.
    runWithCaller(CALLING_PACKAGE_1, USER_0, () -> {
        assertShortcutIds(mManager.getPinnedShortcuts(), "s2");
        mManager.disableShortcuts(list("s2"));
        assertShortcutIds(mManager.getPinnedShortcuts(), "s2");
        assertShortcutIds(mManager.getDynamicShortcuts(), "s1");
    });
    runWithCaller(CALLING_PACKAGE_2, USER_0, () -> {
        assertShortcutIds(mManager.getPinnedShortcuts(), "s3", "s4");
        // disable should work even if a shortcut is not dynamic, so try calling "remove" first
        // here.
        mManager.removeDynamicShortcuts(list("s3"));
        mManager.disableShortcuts(list("s3"));
        assertShortcutIds(mManager.getPinnedShortcuts(), "s3", "s4");
        assertShortcutIds(mManager.getDynamicShortcuts(), "s2", "s4");
    });
    runWithCaller(CALLING_PACKAGE_3, USER_0, () -> {
        assertShortcutIds(mManager.getPinnedShortcuts());
        mManager.disableShortcuts(list("s2"));
        assertShortcutIds(mManager.getPinnedShortcuts());
        assertEmpty(mManager.getDynamicShortcuts());
        assertEmpty(getCallerShortcuts());
    });
    // Get pinned shortcuts from launcher
    runWithCaller(LAUNCHER_1, USER_0, () -> {
        // CALLING_PACKAGE_1 deleted s2, but it's pinned, so it still exists, and disabled.
        assertWith(mLauncherApps.getShortcuts(buildQuery(/* time =*/
        0, CALLING_PACKAGE_1, /* activity =*/
        null, ShortcutQuery.FLAG_GET_PINNED), getCallingUser())).haveIds("s2").areAllPinned().areAllNotWithKeyFieldsOnly().areAllDisabled();
        assertStartShortcutThrowsException(CALLING_PACKAGE_1, "s2", USER_0, ActivityNotFoundException.class);
        // Here, s4 is still enabled and launchable, but s3 is disabled.
        assertWith(mLauncherApps.getShortcuts(buildQuery(/* time =*/
        0, CALLING_PACKAGE_2, /* activity =*/
        null, ShortcutQuery.FLAG_GET_PINNED), getCallingUser())).haveIds("s3", "s4").areAllPinned().areAllNotWithKeyFieldsOnly().selectByIds("s3").areAllDisabled().revertToOriginalList().selectByIds("s4").areAllEnabled();
        assertStartShortcutThrowsException(CALLING_PACKAGE_2, "s3", USER_0, ActivityNotFoundException.class);
        assertShortcutLaunchable(CALLING_PACKAGE_2, "s4", USER_0);
        assertShortcutIds(assertAllPinned(assertAllNotKeyFieldsOnly(assertAllEnabled(mLauncherApps.getShortcuts(buildQuery(/* time =*/
        0, CALLING_PACKAGE_3, /* activity =*/
        null, ShortcutQuery.FLAG_GET_PINNED), getCallingUser())))));
    });
    runWithCaller(CALLING_PACKAGE_1, USER_0, () -> {
        mManager.enableShortcuts(list("s2"));
        assertShortcutIds(mManager.getPinnedShortcuts(), "s2");
        assertShortcutIds(mManager.getDynamicShortcuts(), "s1");
    });
    runWithCaller(LAUNCHER_1, USER_0, () -> {
        // CALLING_PACKAGE_1 deleted s2, but it's pinned, so it still exists.
        assertShortcutIds(assertAllPinned(assertAllNotKeyFieldsOnly(assertAllEnabled(mLauncherApps.getShortcuts(buildQuery(/* time =*/
        0, CALLING_PACKAGE_1, /* activity =*/
        null, ShortcutQuery.FLAG_GET_PINNED), getCallingUser())))), "s2");
        assertShortcutLaunchable(CALLING_PACKAGE_1, "s2", USER_0);
    });
}
Also used : ShortcutInfo(android.content.pm.ShortcutInfo)

Example 45 with ShortcutInfo

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

the class ShortcutManagerTest1 method testManifestShortcuts_duplicateInTwoActivities.

public void testManifestShortcuts_duplicateInTwoActivities() {
    mService.handleUnlockUser(USER_0);
    // ShortcutActivity has shortcut ms1
    addManifestShortcutResource(new ComponentName(CALLING_PACKAGE_1, ShortcutActivity.class.getName()), R.xml.shortcut_1);
    // ShortcutActivity2 has two shortcuts, ms1 and ms2.
    addManifestShortcutResource(new ComponentName(CALLING_PACKAGE_1, ShortcutActivity2.class.getName()), R.xml.shortcut_5);
    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", "ms2", "ms3", "ms4", "ms5");
        // ms1 should belong to ShortcutActivity.
        ShortcutInfo si = getCallerShortcut("ms1");
        assertEquals(R.string.shortcut_title1, si.getTitleResId());
        assertEquals(new ComponentName(CALLING_PACKAGE_1, ShortcutActivity.class.getName()), si.getActivity());
        assertEquals(0, si.getRank());
        // ms2 should belong to ShortcutActivity*2*.
        si = getCallerShortcut("ms2");
        assertEquals(R.string.shortcut_title2, si.getTitleResId());
        assertEquals(new ComponentName(CALLING_PACKAGE_1, ShortcutActivity2.class.getName()), si.getActivity());
        // Also check the ranks
        assertWith(getCallerShortcuts()).selectManifest().selectByActivity(new ComponentName(CALLING_PACKAGE_1, ShortcutActivity.class.getName())).haveRanksInOrder("ms1");
        assertWith(getCallerShortcuts()).selectManifest().selectByActivity(new ComponentName(CALLING_PACKAGE_1, ShortcutActivity2.class.getName())).haveRanksInOrder("ms2", "ms3", "ms4", "ms5");
        // Make sure there's no other dangling shortcuts.
        assertShortcutIds(getCallerShortcuts(), "ms1", "ms2", "ms3", "ms4", "ms5");
    });
}
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