From 2f5bb169154d25bc8c164f057117fb056ad2de96 Mon Sep 17 00:00:00 2001 From: Tony Wickham Date: Fri, 24 Mar 2017 11:31:12 -0700 Subject: De-dupe shortcuts with the same id as the main notification. - Pass NotificationKeyData, which includes the shortcut id, instead of just the notification key from NotificationListener - Remove the shortcut with the same shortcut id as the first notification, if it has one, in PopupPopulator#sortAndFilterShorcuts() - Add some unit tests Bug: 36571718 Change-Id: I308941b34c525b34686583476e3f82ccb8b7e2d8 --- .../launcher3/popup/PopupPopulatorTest.java | 32 +++++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) (limited to 'tests/src/com/android') diff --git a/tests/src/com/android/launcher3/popup/PopupPopulatorTest.java b/tests/src/com/android/launcher3/popup/PopupPopulatorTest.java index 0843d9b59..2ad9b35ae 100644 --- a/tests/src/com/android/launcher3/popup/PopupPopulatorTest.java +++ b/tests/src/com/android/launcher3/popup/PopupPopulatorTest.java @@ -58,11 +58,34 @@ public class PopupPopulatorTest { MAX_ITEMS - NUM_DYNAMIC, NUM_DYNAMIC); } + @Test + public void testDeDupeShortcutId() { + // Successfully remove one of the shortcuts + filterShortcutsAndAssertNumStaticAndDynamic(createShortcutsList(3, 0), 2, 0, generateId(true, 1)); + filterShortcutsAndAssertNumStaticAndDynamic(createShortcutsList(0, 3), 0, 2, generateId(false, 1)); + filterShortcutsAndAssertNumStaticAndDynamic(createShortcutsList(2, 2), 2, 1, generateId(false, 1)); + filterShortcutsAndAssertNumStaticAndDynamic(createShortcutsList(2, 2), 1, 2, generateId(true, 1)); + // Successfully keep all shortcuts when id doesn't exist + filterShortcutsAndAssertNumStaticAndDynamic(createShortcutsList(3, 0), 3, 0, generateId(false, 1)); + filterShortcutsAndAssertNumStaticAndDynamic(createShortcutsList(3, 0), 3, 0, generateId(true, 4)); + filterShortcutsAndAssertNumStaticAndDynamic(createShortcutsList(2, 2), 2, 2, generateId(false, 4)); + filterShortcutsAndAssertNumStaticAndDynamic(createShortcutsList(2, 2), 2, 2, generateId(true, 4)); + } + + private String generateId(boolean isStatic, int rank) { + return (isStatic ? "static" : "dynamic") + rank; + } + private void filterShortcutsAndAssertNumStaticAndDynamic( List shortcuts, int expectedStatic, int expectedDynamic) { + filterShortcutsAndAssertNumStaticAndDynamic(shortcuts, expectedStatic, expectedDynamic, null); + } + + private void filterShortcutsAndAssertNumStaticAndDynamic(List shortcuts, + int expectedStatic, int expectedDynamic, String shortcutIdToRemove) { Collections.shuffle(shortcuts); List filteredShortcuts = PopupPopulator.sortAndFilterShortcuts( - shortcuts); + shortcuts, shortcutIdToRemove); assertIsSorted(filteredShortcuts); int numStatic = 0; @@ -113,6 +136,7 @@ public class PopupPopulatorTest { private class Shortcut extends ShortcutInfoCompat { private boolean mIsStatic; private int mRank; + private String mId; public Shortcut(ShortcutInfo shortcutInfo) { super(shortcutInfo); @@ -122,6 +146,7 @@ public class PopupPopulatorTest { this(null); mIsStatic = isStatic; mRank = rank; + mId = generateId(isStatic, rank); } @Override @@ -138,5 +163,10 @@ public class PopupPopulatorTest { public int getRank() { return mRank; } + + @Override + public String getId() { + return mId; + } } } \ No newline at end of file -- cgit v1.2.3