Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 5608dc52 authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Automerger Merge Worker
Browse files

Merge "Remove BubbleEntity via IDs" into rvc-dev am: 853ee379 am: 9c0ada28...

Merge "Remove BubbleEntity via IDs" into rvc-dev am: 853ee379 am: 9c0ada28 am: dafdfb6e am: 83ef0b8e

Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/11914976

Change-Id: I3878b9308b41f069548f987382021f19679c2aed
parents b77c0d78 83ef0b8e
Loading
Loading
Loading
Loading
+5 −2
Original line number Original line Diff line number Diff line
@@ -60,7 +60,8 @@ class BubbleVolatileRepository @Inject constructor(
        // Verify the size of given bubbles is within capacity, otherwise trim down to capacity
        // Verify the size of given bubbles is within capacity, otherwise trim down to capacity
        val bubblesInRange = bubbles.takeLast(capacity)
        val bubblesInRange = bubbles.takeLast(capacity)
        // To ensure natural ordering of the bubbles, removes bubbles which already exist
        // 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
        val overflowCount = entities.size + bubblesInRange.size - capacity
        if (overflowCount > 0) {
        if (overflowCount > 0) {
            // Uncache ShortcutInfo of bubbles that will be removed due to capacity
            // Uncache ShortcutInfo of bubbles that will be removed due to capacity
@@ -72,7 +73,9 @@ class BubbleVolatileRepository @Inject constructor(
    }
    }


    @Synchronized
    @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>) {
    private fun cache(bubbles: List<BubbleEntity>) {
        bubbles.groupBy { ShortcutKey(it.userId, it.packageName) }.forEach { (key, bubbles) ->
        bubbles.groupBy { ShortcutKey(it.userId, it.packageName) }.forEach { (key, bubbles) ->
+13 −0
Original line number Original line Diff line number Diff line
@@ -102,6 +102,19 @@ class BubbleVolatileRepositoryTest : SysuiTestCase() {
                eq(listOf("alice and bob")), eq(user10),
                eq(listOf("alice and bob")), eq(user10),
                eq(LauncherApps.FLAG_CACHE_BUBBLE_SHORTCUTS))
                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"
private const val PKG_MESSENGER = "com.example.messenger"