Search in sources :

Example 76 with ShortcutInfo

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

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

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

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

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

the class ShortcutManagerTest1 method testPublishWithNoActivity.

public void testPublishWithNoActivity() {
    // If activity is not explicitly set, use the default one.
    mRunningUsers.put(USER_10, true);
    runWithCaller(CALLING_PACKAGE_2, USER_10, () -> {
        // s1 and s3 has no activities.
        final ShortcutInfo si1 = new ShortcutInfo.Builder(mClientContext, "si1").setShortLabel("label1").setIntent(new Intent("action1")).build();
        final ShortcutInfo si2 = new ShortcutInfo.Builder(mClientContext, "si2").setShortLabel("label2").setActivity(new ComponentName(getCallingPackage(), "abc")).setIntent(new Intent("action2")).build();
        final ShortcutInfo si3 = new ShortcutInfo.Builder(mClientContext, "si3").setShortLabel("label3").setIntent(new Intent("action3")).build();
        // Set test 1
        assertTrue(mManager.setDynamicShortcuts(list(si1)));
        assertWith(getCallerShortcuts()).haveIds("si1").forShortcutWithId("si1", si -> {
            assertEquals(new ComponentName(getCallingPackage(), MAIN_ACTIVITY_CLASS), si.getActivity());
        });
        // Set test 2
        assertTrue(mManager.setDynamicShortcuts(list(si2, si1)));
        assertWith(getCallerShortcuts()).haveIds("si1", "si2").forShortcutWithId("si1", si -> {
            assertEquals(new ComponentName(getCallingPackage(), MAIN_ACTIVITY_CLASS), si.getActivity());
        }).forShortcutWithId("si2", si -> {
            assertEquals(new ComponentName(getCallingPackage(), "abc"), si.getActivity());
        });
        // Set test 3
        assertTrue(mManager.setDynamicShortcuts(list(si3, si1)));
        assertWith(getCallerShortcuts()).haveIds("si1", "si3").forShortcutWithId("si1", si -> {
            assertEquals(new ComponentName(getCallingPackage(), MAIN_ACTIVITY_CLASS), si.getActivity());
        }).forShortcutWithId("si3", si -> {
            assertEquals(new ComponentName(getCallingPackage(), MAIN_ACTIVITY_CLASS), si.getActivity());
        });
        // reset throttling
        mInjectedCurrentTimeMillis += INTERVAL;
        // Add test 1
        mManager.removeAllDynamicShortcuts();
        assertTrue(mManager.addDynamicShortcuts(list(si1)));
        assertWith(getCallerShortcuts()).haveIds("si1").forShortcutWithId("si1", si -> {
            assertEquals(new ComponentName(getCallingPackage(), MAIN_ACTIVITY_CLASS), si.getActivity());
        });
        // Add test 2
        mManager.removeAllDynamicShortcuts();
        assertTrue(mManager.addDynamicShortcuts(list(si2, si1)));
        assertWith(getCallerShortcuts()).haveIds("si1", "si2").forShortcutWithId("si1", si -> {
            assertEquals(new ComponentName(getCallingPackage(), MAIN_ACTIVITY_CLASS), si.getActivity());
        }).forShortcutWithId("si2", si -> {
            assertEquals(new ComponentName(getCallingPackage(), "abc"), si.getActivity());
        });
        // Add test 3
        mManager.removeAllDynamicShortcuts();
        assertTrue(mManager.addDynamicShortcuts(list(si3, si1)));
        assertWith(getCallerShortcuts()).haveIds("si1", "si3").forShortcutWithId("si1", si -> {
            assertEquals(new ComponentName(getCallingPackage(), MAIN_ACTIVITY_CLASS), si.getActivity());
        }).forShortcutWithId("si3", si -> {
            assertEquals(new ComponentName(getCallingPackage(), MAIN_ACTIVITY_CLASS), si.getActivity());
        });
    });
}
Also used : ShortcutManagerTestUtils.filterByActivity(com.android.server.pm.shortcutmanagertest.ShortcutManagerTestUtils.filterByActivity) ShortcutManagerTestUtils.assertAllManifest(com.android.server.pm.shortcutmanagertest.ShortcutManagerTestUtils.assertAllManifest) Bundle(android.os.Bundle) Uri(android.net.Uri) ConfigConstants(com.android.server.pm.ShortcutService.ConfigConstants) Process(android.os.Process) ShortcutManagerTestUtils.assertAllHaveIntents(com.android.server.pm.shortcutmanagertest.ShortcutManagerTestUtils.assertAllHaveIntents) ShortcutManagerTestUtils.set(com.android.server.pm.shortcutmanagertest.ShortcutManagerTestUtils.set) ShortcutManagerTestUtils.assertWith(com.android.server.pm.shortcutmanagertest.ShortcutManagerTestUtils.assertWith) Matchers.eq(org.mockito.Matchers.eq) Locale(java.util.Locale) ShortcutManagerTestUtils.assertAllDynamicOrPinned(com.android.server.pm.shortcutmanagertest.ShortcutManagerTestUtils.assertAllDynamicOrPinned) Handler(android.os.Handler) Looper(android.os.Looper) Matchers.anyInt(org.mockito.Matchers.anyInt) R(com.android.frameworks.servicestests.R) ShortcutManagerTestUtils.assertAllDisabled(com.android.server.pm.shortcutmanagertest.ShortcutManagerTestUtils.assertAllDisabled) Mockito.doReturn(org.mockito.Mockito.doReturn) ShortcutManagerTestUtils.assertAllNotManifest(com.android.server.pm.shortcutmanagertest.ShortcutManagerTestUtils.assertAllNotManifest) Log(android.util.Log) ShortcutManagerTestUtils.assertAllEnabled(com.android.server.pm.shortcutmanagertest.ShortcutManagerTestUtils.assertAllEnabled) ShortcutManagerTestUtils.assertAllNotHaveIntents(com.android.server.pm.shortcutmanagertest.ShortcutManagerTestUtils.assertAllNotHaveIntents) ShortcutManagerTestUtils.assertCallbackNotReceived(com.android.server.pm.shortcutmanagertest.ShortcutManagerTestUtils.assertCallbackNotReceived) FileOutputStreamWithPath(com.android.server.pm.ShortcutService.FileOutputStreamWithPath) ShortcutManagerTestUtils.waitOnMainThread(com.android.server.pm.shortcutmanagertest.ShortcutManagerTestUtils.waitOnMainThread) Matchers.any(org.mockito.Matchers.any) LauncherApps(android.content.pm.LauncherApps) SparseArray(android.util.SparseArray) List(java.util.List) ShortcutManagerTestUtils.assertDynamicOnly(com.android.server.pm.shortcutmanagertest.ShortcutManagerTestUtils.assertDynamicOnly) ShortcutManagerTestUtils.findShortcut(com.android.server.pm.shortcutmanagertest.ShortcutManagerTestUtils.findShortcut) ActivityNotFoundException(android.content.ActivityNotFoundException) ShortcutQuery(android.content.pm.LauncherApps.ShortcutQuery) ShortcutManagerTestUtils.assertDynamicAndPinned(com.android.server.pm.shortcutmanagertest.ShortcutManagerTestUtils.assertDynamicAndPinned) ApplicationInfo(android.content.pm.ApplicationInfo) ShortcutManagerTestUtils.assertAllUnique(com.android.server.pm.shortcutmanagertest.ShortcutManagerTestUtils.assertAllUnique) Mockito.mock(org.mockito.Mockito.mock) ShortcutManagerTestUtils.assertForLauncherCallback(com.android.server.pm.shortcutmanagertest.ShortcutManagerTestUtils.assertForLauncherCallback) ActivityManager(android.app.ActivityManager) SmallTest(android.test.suitebuilder.annotation.SmallTest) ShortcutManagerTestUtils.assertAllNotHaveTitle(com.android.server.pm.shortcutmanagertest.ShortcutManagerTestUtils.assertAllNotHaveTitle) Intent(android.content.Intent) BitmapFactory(android.graphics.BitmapFactory) ShortcutManagerTestUtils.pfdToBitmap(com.android.server.pm.shortcutmanagertest.ShortcutManagerTestUtils.pfdToBitmap) ShortcutManagerTestUtils.assertDynamicShortcutCountExceeded(com.android.server.pm.shortcutmanagertest.ShortcutManagerTestUtils.assertDynamicShortcutCountExceeded) PackageWithUser(com.android.server.pm.ShortcutUser.PackageWithUser) ShortcutManagerTestUtils.assertEmpty(com.android.server.pm.shortcutmanagertest.ShortcutManagerTestUtils.assertEmpty) Matchers.anyString(org.mockito.Matchers.anyString) ShortcutManagerTestUtils.assertExpectException(com.android.server.pm.shortcutmanagertest.ShortcutManagerTestUtils.assertExpectException) ArgumentCaptor(org.mockito.ArgumentCaptor) ShortcutManagerTestUtils.assertBitmapSize(com.android.server.pm.shortcutmanagertest.ShortcutManagerTestUtils.assertBitmapSize) UserHandle(android.os.UserHandle) ShortcutManagerTestUtils.assertAllDynamic(com.android.server.pm.shortcutmanagertest.ShortcutManagerTestUtils.assertAllDynamic) ShortcutManagerTestUtils.assertCallbackReceived(com.android.server.pm.shortcutmanagertest.ShortcutManagerTestUtils.assertCallbackReceived) ShortcutManagerTestUtils.resetAll(com.android.server.pm.shortcutmanagertest.ShortcutManagerTestUtils.resetAll) Icon(android.graphics.drawable.Icon) ShortcutManagerTestUtils.assertAllImmutable(com.android.server.pm.shortcutmanagertest.ShortcutManagerTestUtils.assertAllImmutable) ShortcutManagerTestUtils.assertShortcutIds(com.android.server.pm.shortcutmanagertest.ShortcutManagerTestUtils.assertShortcutIds) ShortcutManagerTestUtils.assertAllHaveTitle(com.android.server.pm.shortcutmanagertest.ShortcutManagerTestUtils.assertAllHaveTitle) ShortcutManagerTestUtils.list(com.android.server.pm.shortcutmanagertest.ShortcutManagerTestUtils.list) ComponentName(android.content.ComponentName) ShortcutInfo(android.content.pm.ShortcutInfo) ShortcutManagerTestUtils.makeBundle(com.android.server.pm.shortcutmanagertest.ShortcutManagerTestUtils.makeBundle) Mockito.times(org.mockito.Mockito.times) IOException(java.io.IOException) ShortcutManagerTestUtils.assertAllNotKeyFieldsOnly(com.android.server.pm.shortcutmanagertest.ShortcutManagerTestUtils.assertAllNotKeyFieldsOnly) File(java.io.File) Mockito.verify(org.mockito.Mockito.verify) ShortcutManagerTestUtils.assertBundleEmpty(com.android.server.pm.shortcutmanagertest.ShortcutManagerTestUtils.assertBundleEmpty) ShortcutManagerTestUtils.assertAllPinned(com.android.server.pm.shortcutmanagertest.ShortcutManagerTestUtils.assertAllPinned) ShortcutManagerTestUtils.hashSet(com.android.server.pm.shortcutmanagertest.ShortcutManagerTestUtils.hashSet) ShortcutManagerTestUtils.assertCannotUpdateImmutable(com.android.server.pm.shortcutmanagertest.ShortcutManagerTestUtils.assertCannotUpdateImmutable) Bitmap(android.graphics.Bitmap) CompressFormat(android.graphics.Bitmap.CompressFormat) Manifest.permission(android.Manifest.permission) ShortcutManagerTestUtils.assertAllKeyFieldsOnly(com.android.server.pm.shortcutmanagertest.ShortcutManagerTestUtils.assertAllKeyFieldsOnly) Mockito.reset(org.mockito.Mockito.reset) ShortcutInfo(android.content.pm.ShortcutInfo) Intent(android.content.Intent) ComponentName(android.content.ComponentName)

Example 79 with ShortcutInfo

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

the class ShortcutManagerTest2 method testShortcutInfoSaveAndLoad_forBackup.

public void testShortcutInfoSaveAndLoad_forBackup() {
    setCaller(CALLING_PACKAGE_1, USER_0);
    final Icon bmp32x32 = Icon.createWithBitmap(BitmapFactory.decodeResource(getTestContext().getResources(), 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(bmp32x32).setTitle("title").setText("text").setDisabledMessage("dismes").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("title", si.getTitle());
    assertEquals("text", si.getText());
    assertEquals("dismes", si.getDisabledMessage());
    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());
    // 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 80 with ShortcutInfo

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

the class ShortcutManagerTest2 method testShortcutInfoParcel.

public void testShortcutInfoParcel() {
    setCaller(CALLING_PACKAGE_1, USER_10);
    ShortcutInfo si = parceled(new ShortcutInfo.Builder(mClientContext).setId("id").setTitle("title").setIntent(makeIntent("action", ShortcutActivity.class)).build());
    assertEquals(mClientContext.getPackageName(), si.getPackage());
    assertEquals(USER_10, si.getUserId());
    assertEquals(HANDLE_USER_10, si.getUserHandle());
    assertEquals("id", si.getId());
    assertEquals("title", si.getTitle());
    assertEquals("action", si.getIntent().getAction());
    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)).setTitle("title").setText("text").setDisabledMessage("dismes").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);
    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("title", si.getTitle());
    assertEquals("text", si.getText());
    assertEquals("dismes", si.getDisabledMessage());
    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(0, si.getTitleResId());
    assertEquals(null, si.getTitleResName());
    assertEquals(0, si.getTextResId());
    assertEquals(null, si.getTextResName());
    assertEquals(0, si.getDisabledMessageResourceId());
    assertEquals(null, si.getDisabledMessageResName());
}
Also used : PersistableBundle(android.os.PersistableBundle) 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