Search in sources :

Example 16 with ShortcutInfo

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

the class ShortcutManagerTestUtils method assertShortcutIds.

public static List<ShortcutInfo> assertShortcutIds(List<ShortcutInfo> actualShortcuts, String... expectedIds) {
    final SortedSet<String> expected = new TreeSet<>(list(expectedIds));
    final SortedSet<String> actual = new TreeSet<>();
    for (ShortcutInfo s : actualShortcuts) {
        actual.add(s.getId());
    }
    // Compare the sets.
    assertEquals(expected, actual);
    return actualShortcuts;
}
Also used : ShortcutInfo(android.content.pm.ShortcutInfo) TreeSet(java.util.TreeSet) Matchers.anyString(org.mockito.Matchers.anyString)

Example 17 with ShortcutInfo

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

the class ShortcutManagerTestUtils method assertShortcutIdsOrdered.

public static List<ShortcutInfo> assertShortcutIdsOrdered(List<ShortcutInfo> actualShortcuts, String... expectedIds) {
    final ArrayList<String> expected = new ArrayList<>(list(expectedIds));
    final ArrayList<String> actual = new ArrayList<>();
    for (ShortcutInfo s : actualShortcuts) {
        actual.add(s.getId());
    }
    assertEquals(expected, actual);
    return actualShortcuts;
}
Also used : ShortcutInfo(android.content.pm.ShortcutInfo) ArrayList(java.util.ArrayList) Matchers.anyString(org.mockito.Matchers.anyString)

Example 18 with ShortcutInfo

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

the class ShortcutManagerTestUtils method parceled.

public static ShortcutInfo parceled(ShortcutInfo si) {
    Parcel p = Parcel.obtain();
    p.writeParcelable(si, 0);
    p.setDataPosition(0);
    ShortcutInfo si2 = p.readParcelable(ShortcutManagerTestUtils.class.getClassLoader());
    p.recycle();
    return si2;
}
Also used : ShortcutInfo(android.content.pm.ShortcutInfo) Parcel(android.os.Parcel)

Example 19 with ShortcutInfo

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

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 20 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)

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