Search in sources :

Example 31 with ShortcutInfo

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

the class ShortcutManagerTest2 method testShortcutInfoParcel_resId.

public void testShortcutInfoParcel_resId() {
    setCaller(CALLING_PACKAGE_1, USER_10);
    ShortcutInfo si;
    PersistableBundle pb = new PersistableBundle();
    pb.putInt("k", 1);
    si = new ShortcutInfo.Builder(getTestContext()).setId("id").setActivity(new ComponentName("a", "b")).setIcon(Icon.createWithResource(mClientContext, 123)).setTitleResId(10).setTextResId(11).setDisabledMessageResId(12).setIntent(makeIntent("action", ShortcutActivity.class, "key", "val")).setCategories(set(ShortcutInfo.SHORTCUT_CATEGORY_CONVERSATION, "xyz")).setRank(123).setExtras(pb).build();
    si.addFlags(ShortcutInfo.FLAG_PINNED);
    si.setBitmapPath("abc");
    si.setIconResourceId(456);
    lookupAndFillInResourceNames(si);
    si = parceled(si);
    assertEquals(getTestContext().getPackageName(), si.getPackage());
    assertEquals("id", si.getId());
    assertEquals(new ComponentName("a", "b"), si.getActivity());
    assertEquals(123, si.getIcon().getResId());
    assertEquals(10, si.getTitleResId());
    assertEquals("r10", si.getTitleResName());
    assertEquals(11, si.getTextResId());
    assertEquals("r11", si.getTextResName());
    assertEquals(12, si.getDisabledMessageResourceId());
    assertEquals("r12", si.getDisabledMessageResName());
    assertEquals(set(ShortcutInfo.SHORTCUT_CATEGORY_CONVERSATION, "xyz"), si.getCategories());
    assertEquals("action", si.getIntent().getAction());
    assertEquals("val", si.getIntent().getStringExtra("key"));
    assertEquals(123, si.getRank());
    assertEquals(1, si.getExtras().getInt("k"));
    assertEquals(ShortcutInfo.FLAG_PINNED, si.getFlags());
    assertEquals("abc", si.getBitmapPath());
    assertEquals(456, si.getIconResourceId());
    assertEquals("string/r456", si.getIconResName());
}
Also used : PersistableBundle(android.os.PersistableBundle) ShortcutInfo(android.content.pm.ShortcutInfo) ComponentName(android.content.ComponentName)

Example 32 with ShortcutInfo

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

the class ShortcutManagerTest2 method testShortcutInfoSaveAndLoad_forBackup_resId.

public void testShortcutInfoSaveAndLoad_forBackup_resId() {
    setCaller(CALLING_PACKAGE_1, USER_0);
    final Icon res32x32 = Icon.createWithResource(mClientContext, R.drawable.black_32x32);
    PersistableBundle pb = new PersistableBundle();
    pb.putInt("k", 1);
    ShortcutInfo sorig = new ShortcutInfo.Builder(mClientContext).setId("id").setActivity(new ComponentName(mClientContext, ShortcutActivity2.class)).setIcon(res32x32).setTitleResId(10).setTextResId(11).setDisabledMessageResId(12).setCategories(set(ShortcutInfo.SHORTCUT_CATEGORY_CONVERSATION, "xyz")).setIntent(makeIntent("action", ShortcutActivity.class, "key", "val")).setRank(123).setExtras(pb).build();
    ShortcutInfo sorig2 = new ShortcutInfo.Builder(mClientContext).setId("id2").setTitle("x").setActivity(new ComponentName(mClientContext, ShortcutActivity2.class)).setIntent(makeIntent("action", ShortcutActivity.class, "key", "val")).setRank(456).build();
    mManager.addDynamicShortcuts(list(sorig, sorig2));
    // Dynamic shortcuts won't be backed up, so we need to pin it.
    setCaller(LAUNCHER_1, USER_0);
    mLauncherApps.pinShortcuts(CALLING_PACKAGE_1, list("id", "id2"), HANDLE_USER_0);
    // Do backup & restore.
    backupAndRestore();
    // Load user-0.
    mService.handleUnlockUser(USER_0);
    ShortcutInfo si;
    si = mService.getPackageShortcutForTest(CALLING_PACKAGE_1, "id", USER_0);
    assertEquals(CALLING_PACKAGE_1, si.getPackage());
    assertEquals("id", si.getId());
    assertEquals(ShortcutActivity2.class.getName(), si.getActivity().getClassName());
    assertEquals(null, si.getIcon());
    assertEquals(10, si.getTitleResId());
    assertEquals("r10", si.getTitleResName());
    assertEquals(11, si.getTextResId());
    assertEquals("r11", si.getTextResName());
    assertEquals(12, si.getDisabledMessageResourceId());
    assertEquals("r12", si.getDisabledMessageResName());
    assertEquals(set(ShortcutInfo.SHORTCUT_CATEGORY_CONVERSATION, "xyz"), si.getCategories());
    assertEquals("action", si.getIntent().getAction());
    assertEquals("val", si.getIntent().getStringExtra("key"));
    assertEquals(0, si.getRank());
    assertEquals(1, si.getExtras().getInt("k"));
    assertEquals(ShortcutInfo.FLAG_PINNED | ShortcutInfo.FLAG_STRINGS_RESOLVED, si.getFlags());
    // No icon.
    assertNull(si.getBitmapPath());
    assertEquals(0, si.getIconResourceId());
    assertEquals(null, si.getIconResName());
    // Note when restored from backup, it's no longer dynamic, so shouldn't have a rank.
    si = mService.getPackageShortcutForTest(CALLING_PACKAGE_1, "id2", USER_0);
    assertEquals(0, si.getRank());
}
Also used : PersistableBundle(android.os.PersistableBundle) ShortcutInfo(android.content.pm.ShortcutInfo) ComponentName(android.content.ComponentName) Icon(android.graphics.drawable.Icon)

Example 33 with ShortcutInfo

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

the class ShortcutManagerTest2 method testShortcutInfoClone_resId.

public void testShortcutInfoClone_resId() {
    setCaller(CALLING_PACKAGE_1, USER_11);
    PersistableBundle pb = new PersistableBundle();
    pb.putInt("k", 1);
    ShortcutInfo sorig = new ShortcutInfo.Builder(mClientContext).setId("id").setActivity(new ComponentName("a", "b")).setIcon(Icon.createWithResource(mClientContext, 123)).setTitleResId(10).setTextResId(11).setDisabledMessageResId(12).setCategories(set(ShortcutInfo.SHORTCUT_CATEGORY_CONVERSATION, "xyz")).setIntent(makeIntent("action", ShortcutActivity.class, "key", "val")).setRank(123).setExtras(pb).build();
    sorig.addFlags(ShortcutInfo.FLAG_PINNED);
    sorig.setBitmapPath("abc");
    sorig.setIconResourceId(456);
    lookupAndFillInResourceNames(sorig);
    ShortcutInfo si = sorig.clone(/* clone flags*/
    0);
    assertEquals(USER_11, si.getUserId());
    assertEquals(HANDLE_USER_11, si.getUserHandle());
    assertEquals(mClientContext.getPackageName(), si.getPackage());
    assertEquals("id", si.getId());
    assertEquals(new ComponentName("a", "b"), si.getActivity());
    assertEquals(123, si.getIcon().getResId());
    assertEquals(10, si.getTitleResId());
    assertEquals("r10", si.getTitleResName());
    assertEquals(11, si.getTextResId());
    assertEquals("r11", si.getTextResName());
    assertEquals(12, si.getDisabledMessageResourceId());
    assertEquals("r12", si.getDisabledMessageResName());
    assertEquals(set(ShortcutInfo.SHORTCUT_CATEGORY_CONVERSATION, "xyz"), si.getCategories());
    assertEquals("action", si.getIntent().getAction());
    assertEquals("val", si.getIntent().getStringExtra("key"));
    assertEquals(123, si.getRank());
    assertEquals(1, si.getExtras().getInt("k"));
    assertEquals(ShortcutInfo.FLAG_PINNED, si.getFlags());
    assertEquals("abc", si.getBitmapPath());
    assertEquals(456, si.getIconResourceId());
    assertEquals("string/r456", si.getIconResName());
    si = sorig.clone(ShortcutInfo.CLONE_REMOVE_FOR_CREATOR);
    assertEquals(mClientContext.getPackageName(), si.getPackage());
    assertEquals("id", si.getId());
    assertEquals(new ComponentName("a", "b"), si.getActivity());
    assertEquals(null, si.getIcon());
    assertEquals(10, si.getTitleResId());
    assertEquals(null, si.getTitleResName());
    assertEquals(11, si.getTextResId());
    assertEquals(null, si.getTextResName());
    assertEquals(12, si.getDisabledMessageResourceId());
    assertEquals(null, si.getDisabledMessageResName());
    assertEquals(set(ShortcutInfo.SHORTCUT_CATEGORY_CONVERSATION, "xyz"), si.getCategories());
    assertEquals("action", si.getIntent().getAction());
    assertEquals("val", si.getIntent().getStringExtra("key"));
    assertEquals(123, si.getRank());
    assertEquals(1, si.getExtras().getInt("k"));
    assertEquals(ShortcutInfo.FLAG_PINNED, si.getFlags());
    assertEquals(null, si.getBitmapPath());
    assertEquals(456, si.getIconResourceId());
    assertEquals(null, si.getIconResName());
    si = sorig.clone(ShortcutInfo.CLONE_REMOVE_FOR_LAUNCHER);
    assertEquals(mClientContext.getPackageName(), si.getPackage());
    assertEquals("id", si.getId());
    assertEquals(new ComponentName("a", "b"), si.getActivity());
    assertEquals(null, si.getIcon());
    assertEquals(10, si.getTitleResId());
    assertEquals(null, si.getTitleResName());
    assertEquals(11, si.getTextResId());
    assertEquals(null, si.getTextResName());
    assertEquals(12, si.getDisabledMessageResourceId());
    assertEquals(null, si.getDisabledMessageResName());
    assertEquals(set(ShortcutInfo.SHORTCUT_CATEGORY_CONVERSATION, "xyz"), si.getCategories());
    assertEquals(null, si.getIntent());
    assertEquals(123, si.getRank());
    assertEquals(1, si.getExtras().getInt("k"));
    assertEquals(ShortcutInfo.FLAG_PINNED, si.getFlags());
    assertEquals(null, si.getBitmapPath());
    assertEquals(456, si.getIconResourceId());
    assertEquals(null, si.getIconResName());
    si = sorig.clone(ShortcutInfo.CLONE_REMOVE_NON_KEY_INFO);
    assertEquals(mClientContext.getPackageName(), si.getPackage());
    assertEquals("id", si.getId());
    assertEquals(new ComponentName("a", "b"), si.getActivity());
    assertEquals(null, si.getIcon());
    assertEquals(0, si.getTitleResId());
    assertEquals(null, si.getTitleResName());
    assertEquals(0, si.getTextResId());
    assertEquals(null, si.getTextResName());
    assertEquals(0, si.getDisabledMessageResourceId());
    assertEquals(null, si.getDisabledMessageResName());
    assertEquals(null, si.getCategories());
    assertEquals(null, si.getIntent());
    assertEquals(0, si.getRank());
    assertEquals(null, si.getExtras());
    assertEquals(ShortcutInfo.FLAG_PINNED | ShortcutInfo.FLAG_KEY_FIELDS_ONLY, si.getFlags());
    assertEquals(null, si.getBitmapPath());
    assertEquals(456, si.getIconResourceId());
    assertEquals(null, si.getIconResName());
}
Also used : PersistableBundle(android.os.PersistableBundle) ShortcutInfo(android.content.pm.ShortcutInfo) ComponentName(android.content.ComponentName)

Example 34 with ShortcutInfo

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

the class ShortcutManagerTest2 method testShortcutInfoClone_minimum.

public void testShortcutInfoClone_minimum() {
    PersistableBundle pb = new PersistableBundle();
    pb.putInt("k", 1);
    ShortcutInfo sorig = new ShortcutInfo.Builder(getTestContext()).setId("id").setTitle("title").setIntent(makeIntent("action", ShortcutActivity.class)).build();
    ShortcutInfo si = sorig.clone(/* clone flags*/
    0);
    assertEquals(getTestContext().getPackageName(), si.getPackage());
    assertEquals("id", si.getId());
    assertEquals("title", si.getTitle());
    assertEquals("action", si.getIntent().getAction());
    assertEquals(null, si.getCategories());
    si = sorig.clone(ShortcutInfo.CLONE_REMOVE_FOR_CREATOR);
    assertEquals(getTestContext().getPackageName(), si.getPackage());
    assertEquals("id", si.getId());
    assertEquals("title", si.getTitle());
    assertEquals("action", si.getIntent().getAction());
    assertEquals(null, si.getCategories());
    si = sorig.clone(ShortcutInfo.CLONE_REMOVE_FOR_LAUNCHER);
    assertEquals(getTestContext().getPackageName(), si.getPackage());
    assertEquals("id", si.getId());
    assertEquals("title", si.getTitle());
    assertEquals(null, si.getIntent());
    assertEquals(null, si.getCategories());
    si = sorig.clone(ShortcutInfo.CLONE_REMOVE_NON_KEY_INFO);
    assertEquals(getTestContext().getPackageName(), si.getPackage());
    assertEquals("id", si.getId());
    assertEquals(null, si.getTitle());
    assertEquals(null, si.getIntent());
    assertEquals(null, si.getCategories());
}
Also used : PersistableBundle(android.os.PersistableBundle) ShortcutInfo(android.content.pm.ShortcutInfo)

Example 35 with ShortcutInfo

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

the class ShortcutManagerTest2 method testThrottling.

public void testThrottling() {
    final ShortcutInfo si1 = makeShortcut("shortcut1");
    assertTrue(mManager.setDynamicShortcuts(list(si1)));
    assertEquals(2, mManager.getRemainingCallCount());
    assertEquals(START_TIME + INTERVAL, mManager.getRateLimitResetTime());
    mInjectedCurrentTimeMillis++;
    assertTrue(mManager.setDynamicShortcuts(list(si1)));
    assertEquals(1, mManager.getRemainingCallCount());
    assertEquals(START_TIME + INTERVAL, mManager.getRateLimitResetTime());
    mInjectedCurrentTimeMillis++;
    assertTrue(mManager.setDynamicShortcuts(list(si1)));
    assertEquals(0, mManager.getRemainingCallCount());
    assertEquals(START_TIME + INTERVAL, mManager.getRateLimitResetTime());
    // Reached the max
    mInjectedCurrentTimeMillis++;
    assertFalse(mManager.setDynamicShortcuts(list(si1)));
    assertEquals(0, mManager.getRemainingCallCount());
    assertEquals(START_TIME + INTERVAL, mManager.getRateLimitResetTime());
    // Still throttled
    mInjectedCurrentTimeMillis = START_TIME + INTERVAL - 1;
    assertFalse(mManager.setDynamicShortcuts(list(si1)));
    assertEquals(0, mManager.getRemainingCallCount());
    assertEquals(START_TIME + INTERVAL, mManager.getRateLimitResetTime());
    // Now it should work.
    mInjectedCurrentTimeMillis++;
    // fail
    assertTrue(mManager.setDynamicShortcuts(list(si1)));
    assertEquals(2, mManager.getRemainingCallCount());
    assertEquals(START_TIME + INTERVAL * 2, mManager.getRateLimitResetTime());
    mInjectedCurrentTimeMillis++;
    assertTrue(mManager.setDynamicShortcuts(list(si1)));
    assertEquals(1, mManager.getRemainingCallCount());
    assertEquals(START_TIME + INTERVAL * 2, mManager.getRateLimitResetTime());
    mInjectedCurrentTimeMillis++;
    assertTrue(mManager.setDynamicShortcuts(list(si1)));
    assertEquals(0, mManager.getRemainingCallCount());
    assertEquals(START_TIME + INTERVAL * 2, mManager.getRateLimitResetTime());
    mInjectedCurrentTimeMillis++;
    assertFalse(mManager.setDynamicShortcuts(list(si1)));
    assertEquals(0, mManager.getRemainingCallCount());
    assertEquals(START_TIME + INTERVAL * 2, mManager.getRateLimitResetTime());
    // 4 hours later...
    mInjectedCurrentTimeMillis = START_TIME + 4 * INTERVAL;
    assertTrue(mManager.setDynamicShortcuts(list(si1)));
    assertEquals(2, mManager.getRemainingCallCount());
    assertEquals(START_TIME + INTERVAL * 5, mManager.getRateLimitResetTime());
    mInjectedCurrentTimeMillis++;
    assertTrue(mManager.setDynamicShortcuts(list(si1)));
    assertEquals(1, mManager.getRemainingCallCount());
    assertEquals(START_TIME + INTERVAL * 5, mManager.getRateLimitResetTime());
    // Make sure getRemainingCallCount() itself gets reset without calling setDynamicShortcuts().
    mInjectedCurrentTimeMillis = START_TIME + 8 * INTERVAL;
    assertEquals(3, mManager.getRemainingCallCount());
    assertEquals(START_TIME + INTERVAL * 9, mManager.getRateLimitResetTime());
    mInjectedCurrentTimeMillis++;
    assertTrue(mManager.setDynamicShortcuts(list(si1)));
    assertEquals(2, mManager.getRemainingCallCount());
    assertEquals(START_TIME + INTERVAL * 9, mManager.getRateLimitResetTime());
}
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