diff options
| author | 2020-06-15 18:19:38 -0700 | |
|---|---|---|
| committer | 2020-06-18 14:54:17 -0700 | |
| commit | 4e775a33acf60ee91f247e8e70234ce613b8796f (patch) | |
| tree | eac59d6c823fed67469bb55f475dfbac0b9c0066 | |
| parent | c5c35fc376e604a1f12f7d5aff3fef363bfe8a7b (diff) | |
Remove BubbleEntity via IDs
The contents of the BubbleEntity could differ
so should compare via IDs
Fixes: 159041180
Test: atest BubbleVolatileRepositoryTest
Change-Id: I6470a484657710cff3b2cdc0787cd0afcfdbb6ad
2 files changed, 18 insertions, 2 deletions
diff --git a/packages/SystemUI/src/com/android/systemui/bubbles/storage/BubbleVolatileRepository.kt b/packages/SystemUI/src/com/android/systemui/bubbles/storage/BubbleVolatileRepository.kt index bdeb714b568c..894970f903ac 100644 --- a/packages/SystemUI/src/com/android/systemui/bubbles/storage/BubbleVolatileRepository.kt +++ b/packages/SystemUI/src/com/android/systemui/bubbles/storage/BubbleVolatileRepository.kt @@ -60,7 +60,8 @@ class BubbleVolatileRepository @Inject constructor( // Verify the size of given bubbles is within capacity, otherwise trim down to capacity val bubblesInRange = bubbles.takeLast(capacity) // To ensure natural ordering of the bubbles, removes bubbles which already exist - val uniqueBubbles = bubblesInRange.filterNot { entities.remove(it) } + val uniqueBubbles = bubblesInRange.filterNot { b: BubbleEntity -> + entities.removeIf { e: BubbleEntity -> b.key == e.key } } val overflowCount = entities.size + bubblesInRange.size - capacity if (overflowCount > 0) { // Uncache ShortcutInfo of bubbles that will be removed due to capacity @@ -72,7 +73,9 @@ class BubbleVolatileRepository @Inject constructor( } @Synchronized - fun removeBubbles(bubbles: List<BubbleEntity>) = uncache(bubbles.filter { entities.remove(it) }) + fun removeBubbles(bubbles: List<BubbleEntity>) = + uncache(bubbles.filter { b: BubbleEntity -> + entities.removeIf { e: BubbleEntity -> b.key == e.key } }) private fun cache(bubbles: List<BubbleEntity>) { bubbles.groupBy { ShortcutKey(it.userId, it.packageName) }.forEach { (key, bubbles) -> diff --git a/packages/SystemUI/tests/src/com/android/systemui/bubbles/storage/BubbleVolatileRepositoryTest.kt b/packages/SystemUI/tests/src/com/android/systemui/bubbles/storage/BubbleVolatileRepositoryTest.kt index 76c58339726c..7ea611c9c6a9 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/bubbles/storage/BubbleVolatileRepositoryTest.kt +++ b/packages/SystemUI/tests/src/com/android/systemui/bubbles/storage/BubbleVolatileRepositoryTest.kt @@ -102,6 +102,19 @@ class BubbleVolatileRepositoryTest : SysuiTestCase() { eq(listOf("alice and bob")), eq(user10), eq(LauncherApps.FLAG_CACHE_BUBBLE_SHORTCUTS)) } + + @Test + fun testAddBubbleMatchesByKey() { + val bubble = BubbleEntity(0, "com.example.pkg", "shortcut-id", "key", 120, 0, "title") + repository.addBubbles(listOf(bubble)) + assertEquals(bubble, repository.bubbles.get(0)) + + // Same key as first bubble but different entry + val bubbleModified = BubbleEntity(0, "com.example.pkg", "shortcut-id", "key", 120, 0, + "different title") + repository.addBubbles(listOf(bubbleModified)) + assertEquals(bubbleModified, repository.bubbles.get(0)) + } } private const val PKG_MESSENGER = "com.example.messenger" |