Search in sources :

Example 1 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 2 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)

Example 3 with ShortcutInfo

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

the class ShortcutManagerTest1 method testStartShortcut.

public void testStartShortcut() {
    // Create some shortcuts.
    runWithCaller(CALLING_PACKAGE_1, USER_0, () -> {
        final ShortcutInfo s1_1 = makeShortcut("s1", "Title 1", makeComponent(ShortcutActivity.class), /* icon =*/
        null, new Intent[] { makeIntent(Intent.ACTION_ASSIST, ShortcutActivity2.class, "key1", "val1", "nest", makeBundle("key", 123)).setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK), new Intent("act2").setFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION) }, /* rank */
        10);
        final ShortcutInfo s1_2 = makeShortcut("s2", "Title 2", /* activity */
        null, /* icon =*/
        null, makeIntent(Intent.ACTION_ASSIST, ShortcutActivity3.class), /* rank */
        12);
        final ShortcutInfo s1_3 = makeShortcut("s3");
        assertTrue(mManager.setDynamicShortcuts(list(s1_1, s1_2, s1_3)));
    });
    runWithCaller(CALLING_PACKAGE_2, USER_0, () -> {
        final ShortcutInfo s2_1 = makeShortcut("s1", "ABC", makeComponent(ShortcutActivity.class), /* icon =*/
        null, makeIntent(Intent.ACTION_ANSWER, ShortcutActivity.class, "key1", "val1", "nest", makeBundle("key", 123)), /* weight */
        10);
        assertTrue(mManager.setDynamicShortcuts(list(s2_1)));
    });
    // Pin some.
    runWithCaller(LAUNCHER_1, USER_0, () -> {
        mLauncherApps.pinShortcuts(CALLING_PACKAGE_1, list("s1", "s2"), getCallingUser());
        mLauncherApps.pinShortcuts(CALLING_PACKAGE_2, list("s1"), getCallingUser());
    });
    // Just to make it complicated, delete some.
    runWithCaller(CALLING_PACKAGE_1, USER_0, () -> {
        mManager.removeDynamicShortcuts(list("s2"));
    });
    runWithCaller(LAUNCHER_1, USER_0, () -> {
        final Intent[] intents = launchShortcutAndGetIntents(CALLING_PACKAGE_1, "s1", USER_0);
        assertEquals(ShortcutActivity2.class.getName(), intents[0].getComponent().getClassName());
        assertEquals(Intent.ACTION_ASSIST, intents[0].getAction());
        assertEquals(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK, intents[0].getFlags());
        assertEquals("act2", intents[1].getAction());
        assertEquals(Intent.FLAG_ACTIVITY_NO_ANIMATION, intents[1].getFlags());
        assertEquals(ShortcutActivity3.class.getName(), launchShortcutAndGetIntent(CALLING_PACKAGE_1, "s2", USER_0).getComponent().getClassName());
        assertEquals(ShortcutActivity.class.getName(), launchShortcutAndGetIntent(CALLING_PACKAGE_2, "s1", USER_0).getComponent().getClassName());
        assertShortcutLaunchable(CALLING_PACKAGE_1, "s3", USER_0);
        assertShortcutNotLaunched("no-such-package", "s2", USER_0);
        assertShortcutNotLaunched(CALLING_PACKAGE_1, "xxxx", USER_0);
    });
    // LAUNCHER_1 is no longer the default launcher
    setDefaultLauncherChecker((pkg, userId) -> false);
    runWithCaller(LAUNCHER_1, USER_0, () -> {
        // Not the default launcher, but pinned shortcuts are still lauchable.
        final Intent[] intents = launchShortcutAndGetIntents(CALLING_PACKAGE_1, "s1", USER_0);
        assertEquals(ShortcutActivity2.class.getName(), intents[0].getComponent().getClassName());
        assertEquals(Intent.ACTION_ASSIST, intents[0].getAction());
        assertEquals(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK, intents[0].getFlags());
        assertEquals("act2", intents[1].getAction());
        assertEquals(Intent.FLAG_ACTIVITY_NO_ANIMATION, intents[1].getFlags());
        assertEquals(ShortcutActivity3.class.getName(), launchShortcutAndGetIntent(CALLING_PACKAGE_1, "s2", USER_0).getComponent().getClassName());
        assertEquals(ShortcutActivity.class.getName(), launchShortcutAndGetIntent(CALLING_PACKAGE_2, "s1", USER_0).getComponent().getClassName());
    // Not pinned, so not lauchable.
    });
    // Test inner errors.
    runWithCaller(LAUNCHER_1, USER_0, () -> {
        // Not launchable.
        doReturn(ActivityManager.START_CLASS_NOT_FOUND).when(mMockActivityManagerInternal).startActivitiesAsPackage(anyString(), anyInt(), any(Intent[].class), any(Bundle.class));
        assertStartShortcutThrowsException(CALLING_PACKAGE_1, "s1", USER_0, ActivityNotFoundException.class);
        // Still not launchable.
        doReturn(ActivityManager.START_CLASS_NOT_FOUND).when(mMockActivityManagerInternal).startActivitiesAsPackage(anyString(), anyInt(), any(Intent[].class), any(Bundle.class));
        assertStartShortcutThrowsException(CALLING_PACKAGE_1, "s1", USER_0, ActivityNotFoundException.class);
    });
// TODO Check extra, etc
}
Also used : ShortcutInfo(android.content.pm.ShortcutInfo) Bundle(android.os.Bundle) ShortcutManagerTestUtils.makeBundle(com.android.server.pm.shortcutmanagertest.ShortcutManagerTestUtils.makeBundle) Intent(android.content.Intent)

Example 4 with ShortcutInfo

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

the class ShortcutManagerTest1 method testGetShortcutInfo.

// TODO resource
public void testGetShortcutInfo() {
    // Create shortcuts.
    setCaller(CALLING_PACKAGE_1);
    final ShortcutInfo s1_1 = makeShortcut("s1", "Title 1", makeComponent(ShortcutActivity.class), /* icon =*/
    null, makeIntent(Intent.ACTION_ASSIST, ShortcutActivity2.class, "key1", "val1", "nest", makeBundle("key", 123)), /* weight */
    10);
    final ShortcutInfo s1_2 = makeShortcut("s2", "Title 2", /* activity */
    null, /* icon =*/
    null, makeIntent(Intent.ACTION_ASSIST, ShortcutActivity3.class), /* weight */
    12);
    assertTrue(mManager.setDynamicShortcuts(list(s1_1, s1_2)));
    dumpsysOnLogcat();
    setCaller(CALLING_PACKAGE_2);
    final ShortcutInfo s2_1 = makeShortcut("s1", "ABC", makeComponent(ShortcutActivity2.class), /* icon =*/
    null, makeIntent(Intent.ACTION_ANSWER, ShortcutActivity2.class, "key1", "val1", "nest", makeBundle("key", 123)), /* weight */
    10);
    assertTrue(mManager.setDynamicShortcuts(list(s2_1)));
    dumpsysOnLogcat();
    // Pin some.
    setCaller(LAUNCHER_1);
    mLauncherApps.pinShortcuts(CALLING_PACKAGE_1, list("s2"), getCallingUser());
    dumpsysOnLogcat();
    // Delete some.
    setCaller(CALLING_PACKAGE_1);
    assertShortcutIds(mManager.getPinnedShortcuts(), "s2");
    mManager.removeDynamicShortcuts(list("s2"));
    assertShortcutIds(mManager.getPinnedShortcuts(), "s2");
    dumpsysOnLogcat();
    setCaller(LAUNCHER_1);
    List<ShortcutInfo> list;
    // Note we don't guarantee the orders.
    list = assertShortcutIds(assertAllHaveTitle(assertAllNotHaveIntents(assertAllNotKeyFieldsOnly(mLauncherApps.getShortcutInfo(CALLING_PACKAGE_1, list("s2", "s1", "s3", null), getCallingUser())))), "s1", "s2");
    assertEquals("Title 1", findById(list, "s1").getTitle());
    assertEquals("Title 2", findById(list, "s2").getTitle());
    assertShortcutIds(assertAllHaveTitle(assertAllNotHaveIntents(mLauncherApps.getShortcutInfo(CALLING_PACKAGE_1, list("s3"), getCallingUser()))));
    list = assertShortcutIds(assertAllHaveTitle(assertAllNotHaveIntents(mLauncherApps.getShortcutInfo(CALLING_PACKAGE_2, list("s1", "s2", "s3"), getCallingUser()))), "s1");
    assertEquals("ABC", findById(list, "s1").getTitle());
}
Also used : ShortcutInfo(android.content.pm.ShortcutInfo)

Example 5 with ShortcutInfo

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

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)

Aggregations

ShortcutInfo (android.content.pm.ShortcutInfo)388 ComponentName (android.content.ComponentName)151 Intent (android.content.Intent)81 ArrayList (java.util.ArrayList)64 PersistableBundle (android.os.PersistableBundle)48 Icon (android.graphics.drawable.Icon)40 ShortcutManager (android.content.pm.ShortcutManager)37 List (java.util.List)18 Test (org.junit.Test)18 Matchers.anyString (org.mockito.Matchers.anyString)16 File (java.io.File)15 ResolveInfo (android.content.pm.ResolveInfo)14 LocaleList (android.os.LocaleList)12 ActivityInfo (android.content.pm.ActivityInfo)11 Resources (android.content.res.Resources)10 Bundle (android.os.Bundle)10 ShortcutQuery (android.content.pm.LauncherApps.ShortcutQuery)9 ArrayMap (android.util.ArrayMap)9 Nullable (android.annotation.Nullable)8 Bitmap (android.graphics.Bitmap)8